Beispiel #1
0
        public static bool AreSurfacesEquivalent(ListSurface surface1, ListSurface surface2)
        {
            int[] triangles1 = surface1.GetTriangles();
            int[] triangles2 = surface2.GetTriangles();

            if (triangles1.Length != triangles2.Length)
            {
                return(false);
            }

            // Check triangles are valid
            if (triangles1.Length % 3 != 0)
            {
                return(false);
            }

            Vector3[] vertices1 = surface1.GetVertices();
            Vector3[] vertices2 = surface2.GetVertices();

            for (int tri1 = 0; tri1 < triangles1.Length / 3; tri1++)
            {
                // Linear search for matching triangle
                // TODO: Use Octrees to speed this up
                // O(n^2) is too slow
                bool found = false;
                for (int tri2 = 0; tri2 < triangles2.Length / 3; tri2++)
                {
                    // Gather triangles
                    Vector3[] triangle1 = new Vector3[3];
                    Vector3[] triangle2 = new Vector3[3];
                    for (int j = 0; j < 3; j++)
                    {
                        triangle1[j] = vertices1[triangles1[tri1 * 3 + j]];
                        triangle2[j] = vertices2[triangles2[tri2 * 3 + j]];
                    }

                    // Check if triangles match
                    if (AreTrianglesEqual(triangle1, triangle2))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
 public bool IsEquivalentTo(ListSurface s)
 {
     return(AreSurfacesEquivalent(this, s));
 }