예제 #1
0
        private static void CreateFacesForFace(
            int startIndex
            , int subdivisions
            , MyMatrix <double> vertices
            , IList <Face> faces)
        {
            var numberOfLines = (int)Math.Pow(2, subdivisions) + 1;

            var faceBuilder = new FaceBuilder();

            for (int lineNumber = 0, index = startIndex; lineNumber < numberOfLines - 1; ++lineNumber)
            {
                var numberOfVerticesInLine = lineNumber + 1;
                faceBuilder.Add(new int[] { index, index + numberOfVerticesInLine, index + numberOfVerticesInLine + 1 });
                faces.Add(faceBuilder.Build());
                for (var vertexNumberInLine = 0; vertexNumberInLine < numberOfVerticesInLine - 1; ++vertexNumberInLine)
                {
                    faceBuilder.Add(new int[] { index, index + numberOfVerticesInLine + 1, index + 1 });
                    faces.Add(faceBuilder.Build());
                    ++index;
                    faceBuilder.Add(new int[] { index, index + numberOfVerticesInLine, index + numberOfVerticesInLine + 1 });
                    faces.Add(faceBuilder.Build());
                }
                ++index;
            }
        }
예제 #2
0
 public Mesh(MyMatrix <int> faces, MyMatrix <double> vertices)
 {
     CheckNullFacesOrVertices(faces, vertices);
     if (faces.Height <= 0 || faces.Width < 3)
     {
         throw new ArgumentException(
                   "Wrong faces matrix size, height = " + faces.Height +
                   ", width = " + faces.Width
                   );
     }
     CheckVerticesShape(vertices);
     for (int i = 0; i < faces.Height; ++i)
     {
         var faceBuilder = new FaceBuilder();
         for (var j = 0; j < faces.Width; ++j)
         {
             faceBuilder.Add(faces[i, j]);
         }
         m_faces.Add(faceBuilder.Build());
     }
     m_vertices = vertices;
 }