我正在寻找有关如何解决以下问题的建议:
将STEP(ISO 10303,AP 203/214)转换为三角形网格,即转换为STL
显然,STEP支持一些平滑曲线的各种精确表示,例如NURBS,因此两者不是同构的,因此没有“平移”到另一个 .
到目前为止我所做的研究表明,要走的路是使用某种CAD软件,我做了 - 我用 PythonOCC
编写了以下简单的脚本:
def read_step(filename):
from OCC.STEPControl import STEPControl_Reader
from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
step_reader = STEPControl_Reader()
status = step_reader.ReadFile(filename)
if status == IFSelect_RetDone:
failsonly = False
step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
ok = step_reader.TransferRoot(1)
_nbs = step_reader.NbShapes()
return step_reader.Shape(1)
else:
raise ValueError('Cannot read the file')
def write_stl(shape, filename, def=0.1):
from OCC.StlAPI import StlAPI_Writer
import os
directory = os.path.split(__name__)[0]
stl_output_dir = os.path.abspath(directory)
assert os.path.isdir(stl_output_dir)
stl_file = os.path.join(stl_output_dir, filename)
stl_writer = StlAPI_Writer()
stl_writer.SetASCIIMode(False)
from OCC.BRepMesh import BRepMesh_IncrementalMesh
mesh = BRepMesh_IncrementalMesh(shape, def)
mesh.Perform()
assert mesh.IsDone()
stl_writer.Write(shape, stl_file)
assert os.path.isfile(stl_file)
...
这些功能能够完成这项工作 . 但是,结果并不总是非常令人满意,例如:
原始STEP文件 - 76K
结果STL文件,def = 0.9 - 16K
结果STL文件,def = 0.1 - 116K
显然,没有理由相信通用转换器是可以实现的,但我在这里要求更多的洞察力 . 我希望有关资源的提示可能有助于我解决这个问题 .
我想尝试实现以下结果:
-
希望它能够为尽可能多的模型工作
-
文件上没有太大的重量
我将不胜感激任何关于在哪里寻找的提示和建议!