Skip to content

Commit 13344cd

Browse files
authored
Modify STL export to enable non-relative tolerancing and speed up export. (#1432)
* Add arguments to allow non-relative and parallel mesh computation (default behavior is the same) * Remove duplicate Perform() to approximately halve stl export time * Paint it black (tm) * Trust that `ascii` comes in as a bool * Rename isParallel --> parallel, default True. Fix docstrings * Rename `isToleranceRelative` to `relative`
1 parent e85f766 commit 13344cd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cadquery/occ_impl/shapes.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ def exportStl(
417417
tolerance: float = 1e-3,
418418
angularTolerance: float = 0.1,
419419
ascii: bool = False,
420+
relative: bool = True,
421+
parallel: bool = True,
420422
) -> bool:
421423
"""
422424
Exports a shape to a specified STL file.
@@ -428,17 +430,17 @@ def exportStl(
428430
Default is 1e-3, which is a good starting point for a range of cases.
429431
:param angularTolerance: Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
430432
:param ascii: Export the file as ASCII (True) or binary (False) STL format. Default is binary.
433+
:param relative: If True, tolerance will be scaled by the size of the edge being meshed. Default is True.
434+
Setting this value to True may cause large features to become faceted, or small features dense.
435+
:param parallel: If True, OCCT will use parallel processing to mesh the shape. Default is True.
431436
"""
432-
433-
mesh = BRepMesh_IncrementalMesh(self.wrapped, tolerance, True, angularTolerance)
434-
mesh.Perform()
437+
# The constructor used here automatically calls mesh.Perform(). https://dev.opencascade.org/doc/refman/html/class_b_rep_mesh___incremental_mesh.html#a3a383b3afe164161a3aa59a492180ac6
438+
BRepMesh_IncrementalMesh(
439+
self.wrapped, tolerance, relative, angularTolerance, parallel
440+
)
435441

436442
writer = StlAPI_Writer()
437-
438-
if ascii:
439-
writer.ASCIIMode = True
440-
else:
441-
writer.ASCIIMode = False
443+
writer.ASCIIMode = ascii
442444

443445
return writer.Write(self.wrapped, fileName)
444446

0 commit comments

Comments
 (0)