Skip to content

Commit c32c08e

Browse files
authored
Merge pull request #1066 from CadQuery/vrml
Added the ability for the user to adjust the tolerance and angular tolerance of VRML tessellation
2 parents d7724a8 + 077c48e commit c32c08e

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ simple.step
1919
simple.stp
2020
simple.xml
2121
test.brep
22+
nested.caf
23+
nested.glb
24+
nested.stp
25+
nested.wrl
26+
nested.xml
27+
nested.zip

cadquery/assembly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def save(
442442
elif exportType == "XML":
443443
exportCAF(self, path)
444444
elif exportType == "VRML":
445-
exportVRML(self, path)
445+
exportVRML(self, path, tolerance, angularTolerance)
446446
elif exportType == "GLTF":
447447
exportGLTF(self, path, True, tolerance, angularTolerance)
448448
elif exportType == "VTKJS":

cadquery/occ_impl/assembly.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def toVTK(
179179
loc: Location = Location(),
180180
color: Tuple[float, float, float, float] = (1.0, 1.0, 1.0, 1.0),
181181
tolerance: float = 1e-3,
182+
angularTolerance: float = 0.1,
182183
) -> vtkRenderer:
183184

184185
loc = loc * assy.loc
@@ -188,7 +189,9 @@ def toVTK(
188189
color = assy.color.toTuple()
189190

190191
if assy.shapes:
191-
data = Compound.makeCompound(assy.shapes).toVtkPolyData(tolerance)
192+
data = Compound.makeCompound(assy.shapes).toVtkPolyData(
193+
tolerance, angularTolerance
194+
)
192195

193196
mapper = vtkMapper()
194197
mapper.SetInputData(data)
@@ -203,7 +206,7 @@ def toVTK(
203206
renderer.AddActor(actor)
204207

205208
for child in assy.children:
206-
renderer = toVTK(child, renderer, loc, color, tolerance)
209+
renderer = toVTK(child, renderer, loc, color, tolerance, angularTolerance)
207210

208211
return renderer
209212

cadquery/occ_impl/exporters/assembly.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ def exportCAF(assy: AssemblyProtocol, path: str) -> bool:
7979
return status == PCDM_StoreStatus.PCDM_SS_OK
8080

8181

82-
def _vtkRenderWindow(assy: AssemblyProtocol) -> vtkRenderWindow:
82+
def _vtkRenderWindow(
83+
assy: AssemblyProtocol, tolerance: float = 1e-3, angularTolerance: float = 0.1
84+
) -> vtkRenderWindow:
8385
"""
8486
Convert an assembly to a vtkRenderWindow. Used by vtk based exporters.
8587
"""
8688

8789
renderer = vtkRenderer()
8890
renderWindow = vtkRenderWindow()
8991
renderWindow.AddRenderer(renderer)
90-
toVTK(assy, renderer)
92+
toVTK(assy, renderer, tolerance=tolerance, angularTolerance=angularTolerance)
9193

9294
renderer.ResetCamera()
9395
renderer.SetBackground(1, 1, 1)
@@ -111,14 +113,19 @@ def exportVTKJS(assy: AssemblyProtocol, path: str):
111113
make_archive(path, "zip", tmpdir)
112114

113115

114-
def exportVRML(assy: AssemblyProtocol, path: str):
116+
def exportVRML(
117+
assy: AssemblyProtocol,
118+
path: str,
119+
tolerance: float = 1e-3,
120+
angularTolerance: float = 0.1,
121+
):
115122
"""
116123
Export an assembly to a vrml file using vtk.
117124
"""
118125

119126
exporter = vtkVRMLExporter()
120127
exporter.SetFileName(path)
121-
exporter.SetRenderWindow(_vtkRenderWindow(assy))
128+
exporter.SetRenderWindow(_vtkRenderWindow(assy, tolerance, angularTolerance))
122129
exporter.Write()
123130

124131

0 commit comments

Comments
 (0)