Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify STL export to enable non-relative tolerancing and speed up export. #1432

Merged
merged 6 commits into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ def exportStl(
tolerance: float = 1e-3,
angularTolerance: float = 0.1,
ascii: bool = False,
relative: bool = True,
parallel: bool = True,
) -> bool:
"""
Exports a shape to a specified STL file.
Expand All @@ -428,17 +430,17 @@ def exportStl(
Default is 1e-3, which is a good starting point for a range of cases.
:param angularTolerance: Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
:param ascii: Export the file as ASCII (True) or binary (False) STL format. Default is binary.
:param relative: If True, tolerance will be scaled by the size of the edge being meshed. Default is True.
Setting this value to True may cause large features to become faceted, or small features dense.
:param parallel: If True, OCCT will use parallel processing to mesh the shape. Default is True.
"""

mesh = BRepMesh_IncrementalMesh(self.wrapped, tolerance, True, angularTolerance)
mesh.Perform()
# The constructor used here automatically calls mesh.Perform(). https://dev.opencascade.org/doc/refman/html/class_b_rep_mesh___incremental_mesh.html#a3a383b3afe164161a3aa59a492180ac6
BRepMesh_IncrementalMesh(
self.wrapped, tolerance, relative, angularTolerance, parallel
)

writer = StlAPI_Writer()

if ascii:
writer.ASCIIMode = True
else:
writer.ASCIIMode = False
writer.ASCIIMode = ascii

return writer.Write(self.wrapped, fileName)

Expand Down