Skip to content

Commit

Permalink
Merge pull request #1211 from uki-dev/fix-gltf-coordinate-system
Browse files Browse the repository at this point in the history
fix incorrect coordinate system of glTF exports
  • Loading branch information
jmwright authored Dec 26, 2022
2 parents 1eb14fc + f27883d commit 4568e45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cadquery/occ_impl/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class AssemblyProtocol(Protocol):
def loc(self) -> Location:
...

@loc.setter
def loc(self, value: Location) -> None:
...

@property
def name(self) -> str:
...
Expand Down
13 changes: 12 additions & 1 deletion cadquery/occ_impl/exporters/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from OCP.Interface import Interface_Static

from ..assembly import AssemblyProtocol, toCAF, toVTK
from ..geom import Location


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

# map from CadQuery's right-handed +Z up coordinate system to glTF's right-handed +Y up coordinate system
# https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#coordinate-system-and-units
orig_loc = assy.loc
assy.loc *= Location((0, 0, 0), (1, 0, 0), -90)

# mesh all the shapes
for _, el in assy.traverse():
for s in el.shapes:
Expand All @@ -169,6 +175,11 @@ def exportGLTF(
_, doc = toCAF(assy, True)

writer = RWGltf_CafWriter(TCollection_AsciiString(path), binary)
return writer.Perform(
result = writer.Perform(
doc, TColStd_IndexedDataMapOfStringString(), Message_ProgressRange()
)

# restore coordinate system after exporting
assy.loc = orig_loc

return result

0 comments on commit 4568e45

Please sign in to comment.