diff --git a/Runtime/Triangulator.cs b/Runtime/Triangulator.cs index 156be1d..a43cb2b 100644 --- a/Runtime/Triangulator.cs +++ b/Runtime/Triangulator.cs @@ -3297,12 +3297,11 @@ private int FindInitPolygonHalfedge() private void ProcessBadTriangles() { - static void DisableHe(NativeList halfedges, int he) + static void DisableHe(NativeList halfedges, int he, int rId) { - var ohe = halfedges[he]; + var ohe = halfedges[3 * rId + he]; if (ohe != -1) { - halfedges[he] = -1; halfedges[ohe] = -1; } } @@ -3330,13 +3329,11 @@ static void AdaptHe(NativeList halfedges, int he, int rId, int wId) var constrainedHalfedges3 = constrainedHalfedges.AsArray().Reinterpret(1); var triangles3 = triangles.AsArray().Reinterpret(4); + // TODO: + // This is required for proper adapt heQueue, tQueue. + // This instruction, as well as, `BadTriangles` buffer + // will be eliminated in the future entirely. BadTriangles.Sort(); - foreach (var tId in BadTriangles) - { - DisableHe(halfedges, 3 * tId + 0); - DisableHe(halfedges, 3 * tId + 1); - DisableHe(halfedges, 3 * tId + 2); - } var wId = BadTriangles[0]; for (int rId = BadTriangles[0]; rId < triangles3.Length; rId++) @@ -3354,6 +3351,20 @@ static void AdaptHe(NativeList halfedges, int he, int rId, int wId) } wId++; } + else + { + DisableHe(halfedges, 0, rId); + DisableHe(halfedges, 1, rId); + DisableHe(halfedges, 2, rId); + + for (int i = 0; i < PathHalfedges.Length; i++) + { + if (PathHalfedges[i] > 3 * wId + 2) + { + PathHalfedges[i] -= 3; + } + } + } } // Trim the data to reflect removed triangles. @@ -3364,19 +3375,6 @@ static void AdaptHe(NativeList halfedges, int he, int rId, int wId) { Circles.Length = wId; } - - // Assume that BadTriangles is sorted. - for (int t = BadTriangles.Length - 1; t >= 0; t--) - { - var tId = BadTriangles[t]; - for (int i = 0; i < PathHalfedges.Length; i++) - { - if (PathHalfedges[i] > 3 * tId + 2) - { - PathHalfedges[i] -= 3; - } - } - } } private void BuildNewTrianglesForStar(int pId)