Invalid Meshes and Duplicate Vertices

I have found several threads with discussions about having invalid meshes due to duplicate vertices. In the old .NET sdk this was not the case. Duplicate vertices were allowed. My plugin creates meshes which I import and export as regular grids, that is I write rows of vertices and the number of rows and columns. This format is required for some of our simulations. The simulations handle duplicate vertices fine and this is how we deal with surfaces that come to a point. The restriction on duplicate vertices in Rhino6/RhinoCommon leaves me scratching my head about how to deal with this. No clean solutions come to mind.

This may blow up my plugin for RhinoCommon all together, since these type a if surfaces show up frequently.

Does anyone have any potential solutions for this? Removing duplicate vertices destroys the ordering of the vertices, which is critical.

Can you point us to these threads?

Duplicate vertices are allows. We call these unwelded meshes.

I don’t understand what problem you are trying to solve? Perhaps we need more information or some sample source code?

– Dale

Here are some threads:

I’ll try to better summarize my issue. I’m having trouble logging into discourse on my work computer, so I can’t post much code since I’m on my phone.

If I create a mesh object in C# with RhinoCommon that has a quad face where two of the vertices have identical values, this is an invalid mesh. This was not the case in the .NET sdk in Rhino 4 or 5.

I’ve been porting my plugin to RhinoCommon slowly and ran across this today. If I import some grid files that taper to a point (where a vertex is repeated in the vertex list) the Rhino Mesh Class flags them as invalid doc.Objects.AddMesh fails.

I can see that working interactively in Rhino I can drag a vertex onto another and everything is fine, but I cannot create one that way.

Sample code to produce invalid mesh:
Mesh mesh = new Mesh();
//mesh.IsValid is now false

Wow, that’s painful to type on an iPhone keyboard :roll_eyes:.

Any suggestions would be appreciated. Thanks, Dale.

I think you should be able to do mesh.Faces.AddFace(2,3,0,1) - as long as the last two are identical it should be ok. If not, you need to add a triangle: mesh.Faces.Add(2,3,0).

A more general approach for would be to first add all points to a spatial look-up structure like RTree, and search for duplicates. Then you prevent having duplicate vertices in the Mesh structure to begin with.

The problem is I’m representing an ordered grid with rows and columns of points. They files that get written and read have a list of points and the connectivity is inferred from the number of rows and columns. If I discard a vertex the ordering is shot. The above situation arises when you have something like a UV mesh on a triangular surface.

I need the duplicate vertices. This was legit in Rhino.NET. My plugin has been working there for about 13 years now.

In a Rhino 6 you can create these interactively and read them into RhinoCommon. You can create them in RhinoCommon. But since RhinoCommon considers them to be invalid, you can’t add them to the document from a plugin.

Hi @Brad_Campbell,

This isn’t a RhinoCommon issue. Both RhinoCommon and the legacy Rhino.NET assemblies are based on openNURBS. And openNURBS considers a mesh invalid if it’s finds degenerate vertex locations.

Can you provide some Rhino.NET code that works for you?

Also, a RhinoCommon can reference the Rhino_DotNet.dll assembly.


– Dale

Interesting, I also see that degenerate vertices result in an invalid mesh.

We also have structured grid functionality in Rhino using a plug-in, but then implemented as a custom mesh object. When you do that, it is possible to have degenerate vertices without errors.

Unfortunately, implementing a custom object is quite some work.

I had thought about a custom object type but haven’t really looked into it.

After poking a little more this morning, the fifth override for doc.Objects.AddMesh takes a Boolean value for whether or not to require the mesh to be valid. Setting this to false allows you to add an invalid mesh with degenerate vertices. This should be sufficient for my needs.

For others who come looking, you can add an invalid mesh like this:

doc.Objects.AddMesh(mesh, null, null, false, false)