Beispiel #1
0
        public void AddTriangleFan_FanAdded_FanInMesh()
        {
            GeometryConstructor gc = new GeometryConstructor();

            Vector3[] vertices = new Vector3[]
            {
                Vector3.zero,
                new Vector3(-1, -1, 0),
                new Vector3(-1, 1, 0),
                new Vector3(1, 1, 0),
                new Vector3(1, -1, 0)
            };
            int[] indices = new int[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
            {
                indices[i] = gc.AddVertex(vertices[i]);
            }
            int[] outerVertexIndices = new int[indices.Length - 1];
            Array.Copy(indices, 1, outerVertexIndices, 0, indices.Length - 1);
            gc.AddTriangleFan(indices[0], outerVertexIndices);
            Mesh mesh = gc.ConstructMesh();

            // check
            Assert.AreEqual(gc.Vertices.ToArray(), vertices);
            int[] expectedTriangles = new int[]
            {
                0, 1, 2,
                0, 2, 3,
                0, 3, 4,
            };
            Assert.AreEqual(gc.Triangles.ToArray(), expectedTriangles);
            Assert.AreEqual(mesh.vertices, vertices);
            Assert.AreEqual(mesh.triangles, expectedTriangles);
        }
        /// <summary>
        /// Creates the rounded corner in the mesh constructor
        /// </summary>
        /// <param name="constructor">The mesh constructor to which the geometry of the corner should be added</param>
        /// <param name="innerVertex">The index of the inner vertex around which the corner is rotated</param>
        /// <param name="outerVertex1">The clockwise first outer vertex to which the rounded corner is connected</param>
        /// <param name="outerVertex2">The clockwise second outer vertex to which the rounded corner is connected</param>
        /// <param name="subdivisionCoordinates">The front coorindates of the vertices of the rounded corner</param>
        /// <param name="isBackFace">True if the back faces should be generated</param>
        private void CreateCorner(GeometryConstructor constructor, int innerVertex, int outerVertex1, int outerVertex2, Vector3[] subdivisionCoordinates, bool isBackFace)
        {
            // triangle fan must include existing endpoint vertices => two more entries in vertex indices
            int[] iCornerVertices = new int[subdivisions + 2];
            // determine at which depth the vertices should be placed
            Vector3 depthVector = isBackFace ? new Vector3(0, 0, depth) : Vector3.zero;

            // create the vertices and write the indices to the index array
            iCornerVertices[0] = outerVertex1;
            for (int i = 0; i < subdivisionCoordinates.Length; i++)
            {
                iCornerVertices[i + 1] = constructor.AddVertex(subdivisionCoordinates[i] + depthVector);
            }
            iCornerVertices[iCornerVertices.Length - 1] = outerVertex2;

            // create the triangle fan which represents the rounded corner
            constructor.AddTriangleFan(innerVertex, iCornerVertices, isBackFace);
        }