Exemplo n.º 1
0
        public void MergeEdgesOnACube()
        {
            Mesh m = PrimitiveShapes.Cube();

            var e = m.HalfEdges.First();
            var a = e.Twin.End;
            var b = e.End;
            var x = m.GetVertex(new Vector3(0, 0, 100));

            Assert.AreEqual(9, m.Vertices.Count());
            Assert.AreEqual(24, m.HalfEdges.Count());
            Assert.AreEqual(6, m.Faces.Count());

            var e2 = e.Split(x);

            foreach (var face in m.Faces)
            {
                foreach (var edge in face.Edges)
                {
                    Assert.AreEqual(edge.End, edge.Next.Twin.End);
                }
            }

            Assert.AreEqual(e.End, b);
            Assert.AreEqual(e.Twin.End, x);
            Assert.AreEqual(e2.End, x);
            Assert.AreEqual(e2.Twin.End, a);

            Assert.AreEqual(9, m.Vertices.Count());
            Assert.AreEqual(26, m.HalfEdges.Count());
            Assert.AreEqual(6, m.Faces.Count());

            e2.Merge();

            foreach (var face in m.Faces)
            {
                foreach (var edge in face.Edges)
                {
                    Assert.AreEqual(edge.End, edge.Next.Twin.End);
                }
            }

            Assert.AreEqual(9, m.Vertices.Count());
            Assert.AreEqual(24, m.HalfEdges.Count());
            Assert.AreEqual(6, m.Faces.Count());

            foreach (var face in m.Faces)
            {
                Assert.AreEqual(4, face.Edges.Count());
                Assert.AreEqual(4, face.Vertices.Count());
                Assert.AreEqual(4, face.Neighbours.Count());
                Assert.IsFalse(face.Vertices.Contains(x));
            }

            m.CleanVertices();

            Assert.AreEqual(8, m.Vertices.Count());
            Assert.AreEqual(24, m.HalfEdges.Count());
            Assert.AreEqual(6, m.Faces.Count());
        }
Exemplo n.º 2
0
        public void VertexIndicesPreserved()
        {
            Mesh m = PrimitiveShapes.Cube();

            Face f = m.Faces.First();

            Vertex[] v1 = f.Vertices.ToArray();

            f.Delete();
            Face f2 = m.GetFace(v1);

            Vertex[] v2 = f2.Vertices.ToArray();

            Assert.AreEqual(v1.Length, v2.Length);

            for (int i = 0; i < v1.Length; i++)
            {
                Assert.AreEqual(v1[i], v2[i]);
            }
        }