From c80b073e82f2b1a0fb8c61e7ebff547d65df55e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Mon, 3 Aug 2020 16:55:51 +0200 Subject: [PATCH 1/2] Fix tessellate --- cadquery/occ_impl/shapes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 18777b9ca..105cb6dd7 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -822,7 +822,7 @@ def tessellate( # add triangles triangles += [ - tuple(el + offset for el in t.Get()) for t in poly.Triangles() + tuple(el + offset - 1 for el in t.Get()) for t in poly.Triangles() ] offset += poly.NbNodes() From 5120642ef3a96963a9cc1bff25de38be4cb545c1 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Tue, 4 Aug 2020 08:54:50 +0200 Subject: [PATCH 2/2] Winding fix --- cadquery/occ_impl/shapes.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 105cb6dd7..0f56db781 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -799,13 +799,13 @@ 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(): @@ -813,6 +813,11 @@ def tessellate( 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 += [ @@ -822,7 +827,18 @@ def tessellate( # add triangles triangles += [ - tuple(el + offset - 1 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()