Skip to content

Commit c4c5130

Browse files
committed
export glTF in right-handed +Y up coordinate space
1 parent e23f43d commit c4c5130

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cadquery/occ_impl/exporters/assembly.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from OCP.Interface import Interface_Static
2525

2626
from ..assembly import AssemblyProtocol, toCAF, toVTK
27-
27+
from ..geom import Location
2828

2929
def exportAssembly(assy: AssemblyProtocol, path: str, **kwargs) -> bool:
3030
"""
@@ -161,6 +161,11 @@ def exportGLTF(
161161
Export an assembly to a gltf file.
162162
"""
163163

164+
# map from CadQuery's right-handed +Z up coordinate system to glTF's right-handed +Y up coordinate system
165+
# https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#coordinate-system-and-units
166+
coordinate_system_relation = Location((0, 0, 0), (1, 0, 0), -90)
167+
assy.loc *= coordinate_system_relation
168+
164169
# mesh all the shapes
165170
for _, el in assy.traverse():
166171
for s in el.shapes:
@@ -169,6 +174,11 @@ def exportGLTF(
169174
_, doc = toCAF(assy, True)
170175

171176
writer = RWGltf_CafWriter(TCollection_AsciiString(path), binary)
172-
return writer.Perform(
177+
result = writer.Perform(
173178
doc, TColStd_IndexedDataMapOfStringString(), Message_ProgressRange()
174179
)
180+
181+
# restore coordinate system after exporting
182+
assy.loc *= coordinate_system_relation.inverse
183+
184+
return result

0 commit comments

Comments
 (0)