private static Mesh CreateHullMesh(Mesh mesh, VertexCollecton sourceVertices) { // Get the convex hull for the mesh var cHVertexList = new List <CHVertex>(); foreach (var vertex in sourceVertices) { cHVertexList.Add(new CHVertex(vertex.Position)); } var convexHull = ConvexHull <CHVertex, CHFace> .Create(cHVertexList, .01); if (convexHull != null) { // create the mesh from the hull data Mesh hullMesh = new Mesh(); foreach (var face in convexHull.Faces) { List <IVertex> vertices = new List <IVertex>(); foreach (var vertex in face.Vertices) { var meshVertex = hullMesh.CreateVertex(new Vector3(vertex.Position[0], vertex.Position[1], vertex.Position[2])); vertices.Add(meshVertex); } hullMesh.CreateFace(vertices.ToArray()); } try { // make sure there is not currently a convex hull on this object if (mesh.PropertyBag.ContainsKey(ConvexHullMesh)) { mesh.PropertyBag.Remove(ConvexHullMesh); } // add the new hull mesh.PropertyBag.Add(ConvexHullMesh, hullMesh); // make sure we remove this hull if the mesh changes mesh.Changed += MeshChanged_RemoveConvexHull; // remove the marker that says we are building the hull if (mesh.PropertyBag.ContainsKey(CreatingConvexHullMesh)) { mesh.PropertyBag.Remove(CreatingConvexHullMesh); } return(hullMesh); } catch { } } return(null); }
private void RemoveVerticesMarkedForDeletion(HashSet <Vertex> markedForDeletion) { VertexCollecton NonDeleteVertices = new VertexCollecton(); for (int i = 0; i < Vertices.Count; i++) { Vertex vertexToCheck = Vertices[i]; if (!markedForDeletion.Contains(vertexToCheck)) { NonDeleteVertices.Add(vertexToCheck, SortOption.WillSortLater); } } // we put them in in the same order they were in, so we keep the state NonDeleteVertices.IsSorted = vertices.IsSorted; vertices = NonDeleteVertices; }
private void RemoveVerticesMarkedForDeletion(HashSet<Vertex> markedForDeletion) { VertexCollecton NonDeleteVertices = new VertexCollecton(); for (int i = 0; i < Vertices.Count; i++) { Vertex vertexToCheck = Vertices[i]; if (!markedForDeletion.Contains(vertexToCheck)) { NonDeleteVertices.Add(vertexToCheck, SortOption.WillSortLater); } } // we put them in in the same order they were in, so we keep the state NonDeleteVertices.IsSorted = vertices.IsSorted; vertices = NonDeleteVertices; }