[rhinocommon] Mesh.CreateFromBrep sometimes returns invalid meshes

Hi,

When creating meshes from a Brep I found that some geometry results in invalid meshes. The method IsValidWithLog reports some zero length normals.
I’ve added some code that seem to fix the mesh afterwards and I’m wondering if it’s always needed to check for repairs and what other possible fails I can expect.

Here’s a part of the code:

                    Mesh[] newMeshes = Mesh.CreateFromBrep(brep, CurrentMeshingParameters); // may result in some invalid meshes. 
                if (newMeshes == null) continue;

                //try fix any invalid meshes.
                int invalidMeshCount = 0;
                int fixedMeshes = 0;
                foreach (var mesh in newMeshes)
                {
                    if (mesh.IsValid) continue;

                    invalidMeshCount++;
                    mesh.UnifyNormals();
                    mesh.Normals.ComputeNormals();
                    mesh.Normals.UnitizeNormals();
                    mesh.FaceNormals.ComputeFaceNormals();
                    mesh.FaceNormals.UnitizeFaceNormals();
                    if (mesh.IsValid) fixedMeshes++;
                }
                if (fixedMeshes < invalidMeshCount )
                    Logger.Warning("Could not fix {0} out of {1} invalid meshes.", (invalidMeshCount-fixedMeshes), invalidMeshCount);
                else if (fixedMeshes > 0) Logger.Info("Fixed {0} invalid meshes.", fixedMeshes);

Can you post some geometry that create invalid meshes?

Hi Dale,

I’ve send you a private message with the geometry, because it’s confidential.

Regards,
Gerco