Mesh RhinoCommon SetVertex


#1

Hi,

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[0]].X, M.Vertices[n[0]].Y, M.Vertices[n[0]].Z);

And this one is a good mesh

M.Vertices.SetVertex(n[j], M.Vertices[n[0]].X+0.01, M.Vertices[n[0]].Y, M.Vertices[n[0]].Z);

Why previous code line results in invalid mesh?

validity.gh (6.8 KB)


(Menno Deij - van Rijswijk) #2

Because it gives a duplicate vertex. You should set all the faces that reference the vertex n[j] to reference n[0] instead. Then, optionally, call .CullUnusedVertices to remove any vertices that are no longer used in your mesh.


#3

Thank you for a reply.

So instead using function set vertex.

  1. I have to get connected faces to vertex:
    int[] f = M.Faces.GetConnectedFaces(n[j], 0, true);
  2. Loop through faces that contains that index
  3. and check which vertex is in that face
  4. finally change it

it is quite a lot of loops and checks


#4

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.


(Menno Deij - van Rijswijk) #5

I do not have a clue

Me neither, sorry.


(Giulio Piacentino) #6

Hi @Petras_Vestartas

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.