示例#1
0
        public void MeshFaceSplitAndUnspiltTests()
        {
            {
                //                              centerVertexTop (0, 0, 2)
                //
                //
                //
                //
                // leftVertexBottom (-1, 0, 0)  centerVertexBottom (0, 0, 0)  rightVertexBottom (1, 0, 0)

                // Test needs writable directory
                Environment.CurrentDirectory = TestContext.CurrentContext.WorkDirectory;

                Mesh    testMesh           = new Mesh();
                IVertex leftVertexBottom   = testMesh.CreateVertex(-1, 0, 0);
                IVertex centerVertexBottom = testMesh.CreateVertex(0, 0, 0);
                IVertex rightVertexBottom  = testMesh.CreateVertex(1, 0, 0);
                IVertex centerVertexTop    = testMesh.CreateVertex(0, 0, 1);
                Face    originalFace       = testMesh.CreateFace(new IVertex[] { leftVertexBottom, centerVertexBottom, rightVertexBottom, centerVertexTop });

                SaveDebugInfo(testMesh);
                //       *
                //      / \
                //     /   \
                //    /     \
                //   /       \
                //  *----*----*

                Assert.IsTrue(testMesh.FindMeshEdges(leftVertexBottom, centerVertexBottom).Count == 1);
                MeshEdge firstFaceEdgeMeshEdge = testMesh.FindMeshEdges(leftVertexBottom, centerVertexBottom)[0];
                Assert.IsTrue(originalFace.firstFaceEdge.MeshEdge == firstFaceEdgeMeshEdge);
                Assert.IsTrue(originalFace.NumVertices == 4, "The original face has 4 vertices.");
                MeshEdge edgeLeftCenter  = testMesh.FindMeshEdges(leftVertexBottom, centerVertexBottom)[0];
                MeshEdge edgeCenterRight = testMesh.FindMeshEdges(centerVertexBottom, rightVertexBottom)[0];
                MeshEdge edgeTopLeft     = testMesh.FindMeshEdges(centerVertexTop, leftVertexBottom)[0];
                MeshEdge edgeRightTop    = testMesh.FindMeshEdges(centerVertexTop, rightVertexBottom)[0];

                Assert.IsTrue(edgeTopLeft.NextMeshEdgeFromEnd[0] == edgeRightTop);
                Assert.IsTrue(edgeTopLeft.NextMeshEdgeFromEnd[1] == edgeLeftCenter);

                Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 2);

                string connectionInfoBeforeSplit = testMesh.GetConnectionInfoAsString();

                // split the face and test the result
                Face     faceCreatedDuringSplit;
                MeshEdge meshEdgeCreatedDuringSplit;
                testMesh.SplitFace(originalFace, centerVertexBottom, centerVertexTop, out meshEdgeCreatedDuringSplit, out faceCreatedDuringSplit);
                SaveDebugInfo(testMesh);
                //       *
                //      /|\
                //     / | \
                //    /  |  \
                //   /   |   \
                //  *----*----*

                testMesh.Validate();
                //Debug.Write(testMesh.GetConnectionInfoAsString());

                Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[0] == centerVertexBottom);
                Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[1] == centerVertexTop);
                Assert.IsTrue(edgeLeftCenter.NextMeshEdgeFromEnd[1] == meshEdgeCreatedDuringSplit);
                Assert.IsTrue(edgeTopLeft.NextMeshEdgeFromEnd[1] == edgeLeftCenter);
                Assert.IsTrue(originalFace.firstFaceEdge.MeshEdge == meshEdgeCreatedDuringSplit);
                Assert.IsTrue(originalFace.NumVertices == 3, "The original face now has 3 vertices.");
                Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 3);
                Assert.IsTrue(meshEdgeCreatedDuringSplit.GetNumFacesSharingEdge() == 2, "The edge we split on now has 2 faces attached to it.");
                Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
                Assert.IsTrue(centerVertexTop.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
                Assert.IsTrue(leftVertexBottom.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
                Assert.IsTrue(rightVertexBottom.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
                Assert.IsTrue(faceCreatedDuringSplit.NumVertices == 3, "The created now has 3 vertices.");

                // Unsplit the faces keeping the original face, and test the result.
                testMesh.UnsplitFace(originalFace, faceCreatedDuringSplit, meshEdgeCreatedDuringSplit);
                SaveDebugInfo(testMesh);
                //       *
                //      / \
                //     /   \
                //    /     \
                //   /       \
                //  *----*----*
                string connectionInfoAfterUnsplit = testMesh.GetConnectionInfoAsString();
                testMesh.Validate();
                foreach (FaceEdge faceEdge in originalFace.FaceEdges())
                {
                    // make sure none of them are connected to the deleted MeshEdge
                    Assert.IsTrue(faceEdge.MeshEdge != meshEdgeCreatedDuringSplit);
                    Assert.IsTrue(faceEdge.MeshEdge.NextMeshEdgeFromEnd[0] != meshEdgeCreatedDuringSplit);
                    Assert.IsTrue(faceEdge.MeshEdge.NextMeshEdgeFromEnd[1] != meshEdgeCreatedDuringSplit);
                }
                //Debug.Write(testMesh.GetConnectionInfoAsString());
                Assert.IsTrue(originalFace.NumVertices == 4, "The original face is back to 4 vertices.");
                Assert.IsTrue(meshEdgeCreatedDuringSplit.firstFaceEdge == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[0] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(meshEdgeCreatedDuringSplit.NextMeshEdgeFromEnd[0] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(meshEdgeCreatedDuringSplit.VertexOnEnd[1] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(meshEdgeCreatedDuringSplit.NextMeshEdgeFromEnd[1] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(faceCreatedDuringSplit.firstFaceEdge == null, "The data for the deleted face is all null to help debugging.");

                Assert.IsTrue(centerVertexBottom.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");
                Assert.IsTrue(centerVertexTop.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");
            }

            {
                Mesh    testMesh          = new Mesh();
                IVertex leftVertexBottom  = testMesh.CreateVertex(-1, 0, 0);
                IVertex rightVertexBottom = testMesh.CreateVertex(1, 0, 0);
                IVertex leftVertexCenter  = testMesh.CreateVertex(-1, 0, 1);
                IVertex rightVertexCenter = testMesh.CreateVertex(1, 0, 1);
                IVertex leftVertexTop     = testMesh.CreateVertex(-1, 0, 2);
                IVertex rightVertexTop    = testMesh.CreateVertex(1, 0, 2);
                Face    originalFace      = testMesh.CreateFace(new IVertex[] { rightVertexBottom, rightVertexCenter, rightVertexTop, leftVertexTop, leftVertexCenter, leftVertexBottom });
                SaveDebugInfo(testMesh);
                // *-------*
                // |       |
                // *       *
                // |       |
                // *-------*

                MeshEdge bottomEdge = testMesh.FindMeshEdges(leftVertexBottom, rightVertexBottom)[0];
                Assert.IsTrue(bottomEdge.GetNumFacesSharingEdge() == 1);
                Assert.IsTrue(originalFace.NumVertices == 6);

                // split the face and test the result
                Face     faceCreatedDuringSplit;
                MeshEdge edgeCreatedDuringSplit;
                testMesh.SplitFace(originalFace, rightVertexCenter, leftVertexCenter, out edgeCreatedDuringSplit, out faceCreatedDuringSplit);
                SaveDebugInfo(testMesh);
                // *-------*
                // |       |
                // *-------*
                // |       |
                // *-------*

                Assert.IsTrue(edgeCreatedDuringSplit.GetNumFacesSharingEdge() == 2, "The edge we split on now has 2 faces attached to it.");
                Assert.IsTrue(leftVertexCenter.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
                Assert.IsTrue(rightVertexCenter.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
                Assert.IsTrue(leftVertexBottom.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
                Assert.IsTrue(leftVertexTop.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
                Assert.IsTrue(rightVertexBottom.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
                Assert.IsTrue(rightVertexTop.GetConnectedMeshEdgesCount() == 2, "The original vertices should still have 2 mesh edges attached to them.");
                Assert.IsTrue(originalFace.NumVertices == 4, "The original face still has 4 vertices.");
                Assert.IsTrue(faceCreatedDuringSplit.NumVertices == 4, "The created face has 4 vertices.");

                // Unsplit the faces keeping the original face, and test the result.
                testMesh.UnsplitFace(originalFace, faceCreatedDuringSplit, edgeCreatedDuringSplit);
                SaveDebugInfo(testMesh);
                // *-------*
                // |       |
                // *       *
                // |       |
                // *-------*
                Assert.IsTrue(originalFace.NumVertices == 6, "The original face still has 4 vertices.");
                Assert.IsTrue(edgeCreatedDuringSplit.firstFaceEdge == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[0] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(edgeCreatedDuringSplit.NextMeshEdgeFromEnd[0] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(edgeCreatedDuringSplit.VertexOnEnd[1] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(edgeCreatedDuringSplit.NextMeshEdgeFromEnd[1] == null, "The data for the deleted edge is all null to help debugging.");
                Assert.IsTrue(faceCreatedDuringSplit.firstFaceEdge == null, "The data for the deleted face is all null to help debugging.");
                Assert.IsTrue(leftVertexCenter.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");
                Assert.IsTrue(rightVertexCenter.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");

                // split the face again and test the result
                testMesh.SplitFace(originalFace, rightVertexCenter, leftVertexCenter, out edgeCreatedDuringSplit, out faceCreatedDuringSplit);
                Assert.IsTrue(edgeCreatedDuringSplit.GetNumFacesSharingEdge() == 2, "The edge we split on now has 2 faces attached to it.");
                Assert.IsTrue(leftVertexCenter.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
                Assert.IsTrue(rightVertexCenter.GetConnectedMeshEdgesCount() == 3, "The vertex we split on should now have 3 mesh edges attached to it.");
                Assert.IsTrue(leftVertexBottom.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");
                Assert.IsTrue(rightVertexBottom.GetConnectedMeshEdgesCount() == 2, "The vertex we split on should now have 2 mesh edges attached to it.");

                // unsplit the faces keeping the face we created and test the result
                testMesh.UnsplitFace(faceCreatedDuringSplit, originalFace, edgeCreatedDuringSplit);
                Assert.IsTrue(faceCreatedDuringSplit.NumVertices == 6, "The created face has 4 vertices.");
            }
        }