"Default" vertex.
Inheritance: IVertex
示例#1
0
    public static Mesh CreateConvexHull(Mesh mesh)
    {
        List <MIConvexHull.DefaultVertex> vertices = new List <DefaultVertex>();

        foreach (Vector3 vertex in mesh.vertices)
        {
            MIConvexHull.DefaultVertex mi_vertex = new MIConvexHull.DefaultVertex();
            mi_vertex.Position = new double[3] {
                vertex.x, vertex.y, vertex.z
            };
            vertices.Add(mi_vertex);
        }

        MIConvexHull.ConvexHull <
            MIConvexHull.DefaultVertex,
            MIConvexHull.DefaultConvexFace <MIConvexHull.DefaultVertex> > mi_hull =
            MIConvexHull.ConvexHull.Create(vertices);

        List <Vector3> hull_vertices = new List <Vector3>();

        foreach (MIConvexHull.DefaultVertex vertex in mi_hull.Points)
        {
            hull_vertices.Add(new Vector3((float)vertex.Position[0], (float)vertex.Position[1], (float)vertex.Position[2]));
        }

        IList <MIConvexHull.DefaultVertex> mi_hull_vertices = new List <MIConvexHull.DefaultVertex>(mi_hull.Points);
        List <int> triangles = new List <int>();

        foreach (MIConvexHull.DefaultConvexFace <MIConvexHull.DefaultVertex> face in mi_hull.Faces)
        {
            triangles.Add(mi_hull_vertices.IndexOf(face.Vertices[0]));
            triangles.Add(mi_hull_vertices.IndexOf(face.Vertices[1]));
            triangles.Add(mi_hull_vertices.IndexOf(face.Vertices[2]));
        }

        Mesh hull = new Mesh();

        hull.vertices  = hull_vertices.ToArray();
        hull.triangles = triangles.ToArray();
        hull.RecalculateNormals();

        return(hull);
    }
示例#2
0
 private Vector3 VertexToVector(MIConvexHull.DefaultVertex v)
 {
     return(new Vector3((float)v.Position[0], (float)v.Position[1], (float)v.Position[2]));
 }