Dear McNeel team,
It seems that the mesh validation method in Rh7 is more strict than in Rh5 and Rh6, thus leading to disappearing meshes.
Please see the attached GH file with an internalized mesh opening perfectly fine in previous versions, but marked as invalid in Rh7 (default settings everywhere, file in mm) with the following log:
βON_Mesh.m_F[11914] has degenerate float precision vertex locations.β
Do you have a suggestion to avoid this issue? In our case it happens randomly when using Mesh.Transform, I suppose itβs related to precision / rounding in the test.
I also had the same issue with Cockroach plugin in C++ when computing normally not the most clean meshes using Poisson Surface Reconstruction, in Rhino 6 it works most of the time, while in Rhino 7 most of the time fails.
The workaround I have, is to rebuild mesh faces. And skip ones that have coincident vertices because mesh faces are usually very small from Poisson, adding to tolerance issue you were referring to.
As a solution I use this code:
if(!mesh.IsValid()){
mesh.CombineIdenticalVertices(true,true);
mesh.CullUnusedVertices();
mesh.Cleanup(true);
mesh.CullDegenerateFaces();
mesh.CullUnusedVertices();
ON_Mesh meshRebuilt(mesh.FaceCount(), mesh.VertexCount(), false, false);
for(int i = 0; i < mesh.VertexCount(); i++)
meshRebuilt.SetVertex(i,mesh.Vertex(i) );
for(int i = 0; i < mesh.FaceCount(); i++){
auto f = mesh.m_F[i];
int a = f.vi[0];
int b = f.vi[1];
int c = f.vi[2];
if (a != b && a != c && b != c)
meshRebuilt.SetTriangle(i, a, b, c);
}
if(meshRebuilt.IsValid()){
if(meshObj==NULL){
meshObj= context.m_doc.AddMeshObject(meshRebuilt);
objRef = CRhinoObjRef(meshObj);
RhinoApp().Print(L"Mesh Added End \n");
} else{
context.m_doc.ReplaceObject( objRef, meshRebuilt );
RhinoApp().Print(L"Mesh Replaced End \n");
}
context.m_doc.Redraw();
}