I’m trying to check for equality of meshes in two ways:
Same (not only similar) Object instance and, at other times I want to check for
Similar Geometry
Geometric similarity is often given if Vertex.Count and Faces.Count are the same for both instances but at the language level the function Object.ReferenceEquals(A, A2) comparing the same instance in Rhino, returns false. That was not expected.
So, why are the same Rhino instances considered different instances in Grasshopper?
The mesh is duplicated in memory when it is imported from Rhino to avoid unwanted changes percolating either way. There’s also some casting involved when dealing specifically with c# components, because the assumption is that scripters will be even less worried about directly modifying the input data than component developers.
ReferenceEquals is the best way to check for instance equality. Value equality is much less well defined. Do the meshes have to be exactly alike, or can for example the vertex ordering be different?
If you’re trying to find out whether two meshes have both been referenced from the same Rhino mesh, then you can check their ReferenceIds. But note this information will probably be stripped as soon as the meshes are modified in any way.
Yes, I had already tried comparing the Guids for the Rhino references but it only returns something like “00000-0000-0000”…
ReferenceEquals works fine once I’ve got them inside the component (but then it’s too late in my case)
The equality check from the inputs doesn’t have to be super cheap (it’s done only once for a solutions which takes ~70ms anyway). Could running through the vertices in some kind of “non-commutative” way somehow identify the mesh as unique?
One can of course just compare the vertice lists. If they are different one can at least quit the comparison earlier than if they’re not…
If doesn’t work for you, then yes, to compare if two mesh values are equal, you have to do a lot of conditionals and in case they’re the same you’ll have compared all their shape data.
If you want to compare everything, as in, “these meshes must be the same in every way”, you can always serialise them to byte-arrays using GH_Convert.CommonObjectToByteArray() and compare those. Pretty heavy handed though…