Skip to content

Commit 4568e45

Browse files
authored
Merge pull request #1211 from uki-dev/fix-gltf-coordinate-system
fix incorrect coordinate system of glTF exports
2 parents 1eb14fc + f27883d commit 4568e45

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cadquery/occ_impl/assembly.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class AssemblyProtocol(Protocol):
8383
def loc(self) -> Location:
8484
...
8585

86+
@loc.setter
87+
def loc(self, value: Location) -> None:
88+
...
89+
8690
@property
8791
def name(self) -> str:
8892
...

cadquery/occ_impl/exporters/assembly.py

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

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

2829

2930
def exportAssembly(assy: AssemblyProtocol, path: str, **kwargs) -> bool:
@@ -161,6 +162,11 @@ def exportGLTF(
161162
Export an assembly to a gltf file.
162163
"""
163164

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

171177
writer = RWGltf_CafWriter(TCollection_AsciiString(path), binary)
172-
return writer.Perform(
178+
result = writer.Perform(
173179
doc, TColStd_IndexedDataMapOfStringString(), Message_ProgressRange()
174180
)
181+
182+
# restore coordinate system after exporting
183+
assy.loc = orig_loc
184+
185+
return result

0 commit comments

Comments
 (0)