From 4e4c09b9c05cd6af737667a9db4470800db8e827 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Mon, 15 Nov 2021 09:27:57 -0800 Subject: [PATCH] improving face direction --- .../BooleanProcessing.cs | 33 +++++-------------- Submodules/agg-sharp | 2 +- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/MatterControl.MeshOperations/BooleanProcessing.cs b/MatterControl.MeshOperations/BooleanProcessing.cs index 4385c4f4c..1bd80c13b 100644 --- a/MatterControl.MeshOperations/BooleanProcessing.cs +++ b/MatterControl.MeshOperations/BooleanProcessing.cs @@ -327,8 +327,7 @@ namespace MatterHackers.PolygonMesh var clipper = new Clipper(); clipper.AddPath(facePolygon, PolyType.ptSubject, true); clipper.AddPaths(totalSlice, PolyType.ptClip, true); - var faceWinding = facePolygon.GetWindingDirection2(); - var isSubtractFace = false; + var expectedFaceNormal = face.normal; switch (operation) { @@ -343,10 +342,8 @@ namespace MatterHackers.PolygonMesh } else { - isSubtractFace = true; + expectedFaceNormal *= -1; clipper.Execute(ClipType.ctIntersection, polygonShape); - // the face needs to be added reversed so flip the expected winding - faceWinding *= -1; } break; @@ -356,15 +353,6 @@ namespace MatterHackers.PolygonMesh break; } - // make sure the face we are adding is facing the right direction - foreach (var polygon in polygonShape) - { - if (polygon.GetWindingDirection2() != faceWinding) - { - polygon.Reverse(); - } - } - var faceCountPreAdd = resultsMesh.Faces.Count; if (polygonShape.Count == 1 @@ -373,15 +361,7 @@ namespace MatterHackers.PolygonMesh && facePolygon.Contains(polygonShape[0][1]) && facePolygon.Contains(polygonShape[0][2])) { - var newFace = resultsMesh.CopyFace(mesh1, faceIndex); - if (isSubtractFace) - { - // flip the face normal and winding - var hold = newFace.v0; - newFace.v0 = newFace.v2; - newFace.v2 = hold; - newFace.normal *= -1; - } + resultsMesh.AddFaceCopy(mesh1, faceIndex); } else { @@ -389,12 +369,17 @@ namespace MatterHackers.PolygonMesh polygonShape.Vertices().TriangulateFaces(null, resultsMesh, 0, flattenedMatrix.Inverted); } - if (false )//faceCountPreAdd < resultsMesh.Faces.Count) + if (resultsMesh.Faces.Count - faceCountPreAdd > 0) { // keep track of the adds so we can process the coplanar faces after for (int i = faceCountPreAdd; i < resultsMesh.Faces.Count; i++) { StoreFaceAdd(coPlanarFaces, cutPlane, mesh1Index, faceIndex, i); + // make sure our added faces are the right direction + if (resultsMesh.Faces[i].normal.Dot(expectedFaceNormal) < 0) + { + resultsMesh.FlipFace(i); + } } } else // we did not add any faces but we will still keep track of this polygons plan diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 7cc098c0c..2290fc4e2 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 7cc098c0cecc09b32471df85b80135e95f4724b9 +Subproject commit 2290fc4e2bf28e23d31a1e7724ea4b47f1e29725