Simple Scripts create invalid Meshes since V6

Since V6 either my scripts (c# nodes) create invalid meshes, or rhino does not want to bake them anymore…
Right now i was writing a super simple node, it just moves vertices around and rebuilds the normals. Still it outputs an ‘Invalid Mesh’.

An ugly workaround i found for now is to run it through a ‘Smooth Mesh’ with iteration 0…

This mainly happens with imported objs - nothing fancy - a simple utha teapot, valid mesh according to rhinos checkmesh

attached is a minimal example with an internalised teapot (which passes all checks in rhino)

InvalidMesh.gh (129.3 KB)

The problem seems to be that the single and double precision vertex arrays no longer have the same length.
I’ve seen several invalid meshes with wonky double-precision issues as of late, there’s probably a bug somewhere.

Logged under RH-46728.

1 Like

thanks,
any idea for a workaround in code?

  private void RunScript(Mesh inMesh, ref object A)
  {
    Mesh result = inMesh.DuplicateMesh();

    Point3d[] vert = result.Vertices.ToPoint3dArray();
    for(int i = 0; i < vert.Length; i++)
      result.Vertices.SetVertex(i, vert[i] + Vector3d.ZAxis);

    result.RebuildNormals();

    A = result;
  }

Add a var before result on line 3

i meant more a general workaround
e.g. here is a MeshPipe component i wrote last year:
curveMesher01_PIPE_09_2017.gh (9.9 KB)

It builds a mesh from scratch, still it is invalid - in V5 it worked fine
this time the error is: Mesh: ON_Mesh.m_F[0] has degenerate double precision vertex locations.

Not sure if this is related or if in V6 the checks are more rigorous?

Sorry to bump this, but this bug is bad: pretty much all of my scripts that deal with meshes are not working anymore. Nearly every mesh that gets built in code is invalid… This forced me back to v5 for now…
I can imagine that many others are affected too.
And it is not always as visible - the invalid meshes throw no error and if they are part of a bigger program it is sometimes quite hard to find the problem…

Doesn’t solve your problem but since you mentioned mesh pipe, saw this new in R6 Rhinocommon. http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Mesh_CreateFromCurvePipe.htm

Yes, I too am having issues with this. Would love to hear if there are any updates on this.

If you go in the script from this discussion there are some rhinocommon command in c# to cure meshes. It works on some problems.

tried them all… nothing works.

Vertices.CombineIdentical(true, true); 
Faces.CullDegenerateFaces();
UnifyNormals();
RebuildNormals();
Compact();

at least we can bake the meshes now… But I still suspect there is some simple command / way to fix this

Have you tried the command testDestroyDoublePrecisionVertices
?

Really appreciate what David is doing, but I would like to see this issue getting some priority from McNeel. If I understand ON_Mesh itself has a fundamental bug, which makes all Mesh operations unpredictable. In my case simple mesh.Transform(…) made valid mesh invalid. I see that RH-46728 has been scheduled to be fixed only in Rhino 7, is there a reason why this can’t happen in Rhino 6? Thx.

1 Like

A fix for the original issue was just merged and might land somewhere in 8.5 or so. It was not a bug in ON_Mesh itself. If there is a way in which a valid non-squishy (Euclidean) Transform makes a valid ON_Mesh invalid, then that would be a separate issue.