예제 #1
0
        public static List <int> CreateFaceIndices <VERTEX, EDGE, FACE>(HBMesh <VERTEX, EDGE, FACE> mesh, int faceVertices)
            where VERTEX : HBVertex, new()
            where EDGE : HBEdge, new()
            where FACE : HBFace, new()
        {
            int count = mesh.Faces.Count;
            int size  = mesh.Faces.Count * faceVertices;

            List <int> indices = new List <int>(size);

            for (int i = 0; i < count; i++)
            {
                int num = 0;
                foreach (var v in mesh.Faces[i].Edge.EnumerateVertices())
                {
                    int index = mesh.IndexOf(v);
                    if (index == -1)
                    {
                        continue;
                    }
                    indices.Add(index);
                    num++;
                }

                if (num != faceVertices)
                {
                    throw new InvalidOperationException("Face did not have the expected number of vertices.");
                }
            }

            return(indices);
        }
예제 #2
0
        public static List <int> CreateEdgeIndices <VERTEX, EDGE, FACE>(HBMesh <VERTEX, EDGE, FACE> mesh)
            where VERTEX : HBVertex, new()
            where EDGE : HBEdge, new()
            where FACE : HBFace, new()
        {
            int count = mesh.Edges.Count;

            List <int>       indices = new List <int>(count / 2);
            HashSet <HBEdge> set     = new HashSet <HBEdge>();

            for (int i = 0; i < count; i++)
            {
                var edge = mesh.Edges[i];
                if (edge.Opposite == null)
                {
                    continue;
                }
                if (set.Contains(edge))
                {
                    continue;
                }

                var v0 = edge.Vertex;
                var v1 = edge.Opposite.Vertex;

                int i0 = mesh.IndexOf(v0);
                int i1 = mesh.IndexOf(v1);
                if (i0 == -1 || i1 == -1)
                {
                    continue;
                }
                indices.Add(i0);
                indices.Add(i1);

                set.Add(edge.Opposite);
            }

            return(indices);
        }