예제 #1
0
        public void CanConvertTriangleStripToTriangleList()
        {
            // Arrange.
            Int32Collection indices = new Int32Collection(new[] { 0, 3, 1, 4, 2, 5 });

            // Act.
            Int32Collection newIndices = MeshUtility.ConvertTriangleStripToTriangleList(indices);

            // Assert.
            CollectionAssert.AreEqual(new[] { 0, 3, 1, 1, 3, 4, 1, 4, 2, 2, 4, 5 }, newIndices);
        }
예제 #2
0
        public override void Tessellate()
        {
            // Create vertices.
            Vector3D normal = new Vector3D(0, 1, 0);

            for (int z = 0; z < _length; ++z)
            {
                for (int x = 0; x < _width; ++x)
                {
                    AddVertex(new Point3D(x, 0, (_length - 1) - z), normal);                     // Invert z so that winding order is correct.
                }
            }
            // Create indices.
            for (int z = 0; z < _length - 1; ++z)
            {
                for (int x = 0; x < _width; ++x)
                {
                    // Create vertex for degenerate triangle.
                    if (x == 0 && z > 0)
                    {
                        AddIndex(((z + 0) * _width) + x);
                    }

                    AddIndex(((z + 0) * _width) + x);
                    AddIndex(((z + 1) * _width) + x);

                    // Create vertex for degenerate triangle.
                    if (x == _width - 1 && z < _length - 2)
                    {
                        AddIndex(((z + 1) * _width) + x);
                    }
                }
            }

            // It's easiest to define the plane in terms of a triangle strip,
            // and then convert it.
            Int32Collection newIndices = MeshUtility.ConvertTriangleStripToTriangleList(Indices);
            Indices.Clear();
            Indices.AddRange(newIndices);
        }