Пример #1
0
        public void MergeVertices(Vertex vertexToKeep, Vertex vertexToDelete, bool doActualDeletion = true)
        {
#if false // this check is relatively slow
            if (!Vertices.ContainsAVertexAtPosition(vertexToKeep) || !Vertices.ContainsAVertexAtPosition(vertexToDelete))
            {
                throw new Exception("Both vertexes have to be part of this mesh to be merged.");
            }
#endif
            // fix up the mesh edges
            List <MeshEdge> connectedMeshEdges = vertexToDelete.GetConnectedMeshEdges();
            foreach (MeshEdge meshEdgeToFix in connectedMeshEdges)
            {
                // fix up the face edges
                foreach (FaceEdge faceEdge in meshEdgeToFix.FaceEdgesSharingMeshEdge())
                {
                    if (faceEdge.firstVertex == vertexToDelete)
                    {
                        faceEdge.firstVertex = vertexToKeep;
                    }
                }

                // fix up the mesh edge
                if (meshEdgeToFix.VertexOnEnd[0] == vertexToDelete)
                {
                    meshEdgeToFix.VertexOnEnd[0] = vertexToKeep;
                }
                else if (meshEdgeToFix.VertexOnEnd[1] == vertexToDelete)
                {
                    meshEdgeToFix.VertexOnEnd[1] = vertexToKeep;
                }

                // make sure it is in the vertex edge loop
                meshEdgeToFix.AddToMeshEdgeLinksOfVertex(vertexToKeep);
            }

            // delete the vertex
            if (doActualDeletion)
            {
                Vertices.Remove(vertexToDelete);
            }
        }
Пример #2
0
		public void MergeVertices(Vertex vertexToKeep, Vertex vertexToDelete, bool doActualDeletion = true)
		{
#if false // this check is relatively slow
			if (!Vertices.ContainsAVertexAtPosition(vertexToKeep) || !Vertices.ContainsAVertexAtPosition(vertexToDelete))
			{
				throw new Exception("Both vertexes have to be part of this mesh to be merged.");
			}
#endif
			// fix up the mesh edges
			List<MeshEdge> connectedMeshEdges = vertexToDelete.GetConnectedMeshEdges();
			foreach (MeshEdge meshEdgeToFix in connectedMeshEdges)
			{
				// fix up the face edges
				foreach (FaceEdge faceEdge in meshEdgeToFix.FaceEdgesSharingMeshEdge())
				{
					if (faceEdge.firstVertex == vertexToDelete)
					{
						faceEdge.firstVertex = vertexToKeep;
					}
				}

				// fix up the mesh edge
				if (meshEdgeToFix.VertexOnEnd[0] == vertexToDelete)
				{
					meshEdgeToFix.VertexOnEnd[0] = vertexToKeep;
				}
				else if (meshEdgeToFix.VertexOnEnd[1] == vertexToDelete)
				{
					meshEdgeToFix.VertexOnEnd[1] = vertexToKeep;
				}

				// make sure it is in the vertex edge loop
				meshEdgeToFix.AddToMeshEdgeLinksOfVertex(vertexToKeep);
			}

			// delete the vertex
			if (doActualDeletion)
			{
				Vertices.Remove(vertexToDelete);
			}
		}