private void GenerateIndex(Mesh mesh) { TriangleArray triangles = mesh.GetSaneTriangles(0); for (int i = 0; i < triangles.Length; ++i) { IndexedTriangle triangle = triangles[i]; for (int j = 0; j < 3; ++j) { var edge = new IndexedEdge( triangle[j], triangle[(j + 1) % 3] ); edgeToTriangleMap.Add(edge, i); } } }
/// Gets neighbor triangle index private int GetNeighborTriangle(int intersectedEdge) { // Note the reverse order of start and end indices IndexedEdge edge = new IndexedEdge( CurrentTriangle[(intersectedEdge + 1) % 3], CurrentTriangle[intersectedEdge] ); int neighbor = meshIndex.FindTriangleByEdge(edge); #if UNITY_EDITOR if (debugDrawEnabled) { mesh.DrawTriangle(neighbor, Color.yellow); } #endif return(neighbor); }
public int FindTriangleByEdge(IndexedEdge edge) => edgeToTriangleMap[edge];