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

Fix tessellate #420

Merged
merged 2 commits into from
Aug 4, 2020
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
24 changes: 20 additions & 4 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,20 +799,25 @@ def intersect(self, *toIntersect: "Shape") -> "Shape":

def tessellate(
self, tolerance: float
) -> Tuple[List[Vector], List[Tuple[int, ...]]]:
) -> Tuple[List[Vector], List[Tuple[int, int, int]]]:

if not BRepTools.Triangulation_s(self.wrapped, tolerance):
BRepMesh_IncrementalMesh(self.wrapped, tolerance, True)

vertices = []
triangles = []
vertices: List[Vector] = []
triangles: List[Tuple[int, int, int]] = []
offset = 0

for f in self.Faces():

loc = TopLoc_Location()
poly = BRep_Tool.Triangulation_s(f.wrapped, loc)
Trsf = loc.Transformation()
reverse = (
True
if f.wrapped.Orientation() == TopAbs_Orientation.TopAbs_REVERSED
else False
)

# add vertices
vertices += [
Expand All @@ -822,7 +827,18 @@ def tessellate(

# add triangles
triangles += [
tuple(el + offset for el in t.Get()) for t in poly.Triangles()
(
t.Value(1) + offset - 1,
t.Value(3) + offset - 1,
t.Value(2) + offset - 1,
)
if reverse
else (
t.Value(1) + offset - 1,
t.Value(2) + offset - 1,
t.Value(3) + offset - 1,
)
for t in poly.Triangles()
]

offset += poly.NbNodes()
Expand Down