I attached the gh file.
I have strange issue with mesh valid.
Basically I would like to change vertex position to other vertex position, but this causes invalid mesh
This one produces invalid mesh:
M.Vertices.SetVertex(n[j], M.Vertices[n].X, M.Vertices[n].Y, M.Vertices[n].Z);
And this one is a good mesh
M.Vertices.SetVertex(n[j], M.Vertices[n].X+0.01, M.Vertices[n].Y, M.Vertices[n].Z);
Why previous code line results in invalid mesh?
validity.gh (6.8 KB)
Because it gives a duplicate vertex. You should set all the faces that reference the vertex n[j] to reference n instead. Then, optionally, call
.CullUnusedVertices to remove any vertices that are no longer used in your mesh.
Thank you for a reply.
So instead using function set vertex.
- I have to get connected faces to vertex:
int f = M.Faces.GetConnectedFaces(n[j], 0, true);
- Loop through faces that contains that index
- and check which vertex is in that face
- finally change it
it is quite a lot of loops and checks
I also tried to unify mesh windings with weaverbird component. And after that setting the vertex does not produce invalid mesh.
What is the logic behind mesh unify windings? I know that after that mesh face vertex order is always anticlockwise. But how to achieve this and why this can solve my problem I do not have a clue.
a simple way to make an invalid mesh by changing vertex location is by collapsing an edge. Some cases like this are automatically fixed by Weaverbird. Also, the fact that unifying windings (logically the same as the _UnifyMeshNormals Rhino command) fixes it might just be pure chance. If an ABCD face has its order unified, it will become ADCB.