Repository navigation
|
When working with assemblies, GLTF can be a export option, it's better to preserve a tree-like hierarchy, when exporting multiple parts in the same file, for example. |
Replies: 1 comment 1 reply
|
from cadquery.occ_impl.exporters.assembly import toCAF
from cadquery.occ_impl.geom import Location
from OCP.RWGltf import RWGltf_CafWriter
from OCP.TCollection import TCollection_AsciiString
from OCP.TColStd import TColStd_IndexedDataMapOfStringString
from OCP.Message import Message_ProgressRange
def export_gltf_mm(assy, path, tolerance=1e-3, angular_tolerance=0.1):
binary = not path.endswith(".gltf")
orig = assy.loc
assy.loc *= Location((0, 0, 0), (1, 0, 0), -90) # Z-up to glTF Y-up, same as cadquery does
_, doc = toCAF(assy, True, True, tolerance, angular_tolerance)
writer = RWGltf_CafWriter(TCollection_AsciiString(path), binary)
writer.ChangeCoordinateSystemConverter().SetInputLengthUnit(0.001) # model is in mm
ok = writer.Perform(doc, TColStd_IndexedDataMapOfStringString(), Message_ProgressRange())
assy.loc = orig
return okRan it on cadquery 2.8.0: a 100 mm box comes out as +-0.05, a sub-assembly placed at x=200 gets |
assy.export()doesn't take a unit option for glTF.exportGLTFhands the tessellated doc straight to OCCT'sRWGltf_CafWriterwith your mm values as-is (assembly.py). The writer can convert though, you just have to tell its coordinate converter what unit the input is in. Copy ofexportGLTFwith one extra line: