cad step格式转换为threejs支持的json格式
生活随笔
收集整理的這篇文章主要介紹了
cad step格式转换为threejs支持的json格式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
step格式的文件在網頁端3D顯示的時候是不能直接加載的。因為threejs沒有提供step格式的加載器。所以如果需要在網頁端顯示step模型就需要先將step格式的文件進行轉換。有的技術方案是通過先轉化為stl然后轉換為別的gltf,這樣比較麻煩,而且多次轉換不知道精度會不會丟失太多。
這里我通過搜索各種資料找到了一種轉換的方法。直接將stp轉換為json格式。關鍵代碼如下:
def step2json(inputFile, outputFile): # STEP Filesstep_reader = STEPControl_Reader()status = step_reader.ReadFile(inputFile)if status == IFSelect_RetDone: # check statusfailsonly = Falsestep_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)step_reader.TransferRoot(1)_nbs = step_reader.NbShapes()_shape = step_reader.Shape(1)_tess = ShapeTesselator(_shape)_tess.Compute(compute_edges=False, mesh_quality=50)with open(outputFile, "w") as text_file:json = _tess.ExportShapeToThreejsJSONString(inputFile)json = json.replace("\\", "/")text_file.write(json)else:raise Exception("Error: can't read file - Method: _load_STEP_file")輸入是stp格式的文件,輸出為three.js支持的json文件
轉自?cad step格式轉換為threejs支持的json格式
總結
以上是生活随笔為你收集整理的cad step格式转换为threejs支持的json格式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 百度地图api之室内地图----reac
- 下一篇: 利用全局的fontSize实现适配