Skip to content

Commit fddf510

Browse files
authored
Fix VTK based assembly export rotation issue (#1078)
1 parent c57b849 commit fddf510

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

cadquery/assembly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ def save(
426426
427427
:param path: filepath
428428
:param exportType: export format (default: None, results in format being inferred form the path)
429-
:param tolerance: the deflection tolerance, in model units. Only used for GLTF. Default 0.1.
430-
:param angularTolerance: the angular tolerance, in radians. Only used for GLTF. Default 0.1.
429+
:param tolerance: the deflection tolerance, in model units. Only used for GLTF, VRML. Default 0.1.
430+
:param angularTolerance: the angular tolerance, in radians. Only used for GLTF, VRML. Default 0.1.
431431
"""
432432

433433
if exportType is None:

cadquery/occ_impl/assembly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Iterable, Tuple, Dict, overload, Optional, Any, List
22
from typing_extensions import Protocol
3+
from math import degrees
34

45
from OCP.TDocStd import TDocStd_Document
56
from OCP.TCollection import TCollection_ExtendedString
@@ -199,7 +200,7 @@ def toVTK(
199200
actor = vtkActor()
200201
actor.SetMapper(mapper)
201202
actor.SetPosition(*trans)
202-
actor.SetOrientation(*rot)
203+
actor.SetOrientation(*map(degrees, rot))
203204
actor.GetProperty().SetColor(*color[:3])
204205
actor.GetProperty().SetOpacity(color[3])
205206

cadquery/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def wrapped(*args, **kwargs):
6363

6464
if f_sig_params[self.name]:
6565
warn(
66-
f"Kwarg <{self.name}> will be removed. Plase use <{self.new_name}>",
66+
f"Kwarg <{self.name}> will be removed. Please use <{self.new_name}>",
6767
FutureWarning,
6868
)
6969

tests/test_exporters.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# core modules
55
import sys
66
import io
7+
from pathlib import Path
8+
import re
79

810
# my modules
911
from cadquery import *
@@ -214,3 +216,29 @@ def testTypeHandling(self):
214216

215217
with self.assertRaises(ValueError):
216218
exporters.export(self._box(), "out.stl", "STP")
219+
220+
221+
def test_assy_vtk_rotation(tmp_path_factory):
222+
tmpdir = tmp_path_factory.mktemp("out")
223+
224+
v0 = Vertex.makeVertex(1, 0, 0)
225+
226+
assy = Assembly()
227+
assy.add(
228+
v0, name="v0", loc=Location(Vector(0, 0, 0), Vector(1, 0, 0), 90),
229+
)
230+
231+
fwrl = Path(tmpdir, "v0.wrl")
232+
assert not fwrl.exists()
233+
assy.save(str(fwrl), "VRML")
234+
assert fwrl.exists()
235+
236+
matched_rot = False
237+
with open(fwrl) as f:
238+
pat_rot = re.compile("""rotation 1 0 0 1.5707963267""")
239+
for line in f:
240+
if m := re.search(pat_rot, line):
241+
matched_rot = True
242+
break
243+
244+
assert matched_rot

0 commit comments

Comments
 (0)