I was trying to make a little customization to the original MeshMachine code (by @DanielPiker) in python. The original code utilizes the plankton (by @will) library, which I managed to port into python and got it to work. While sometimes it fails when doing Pmesh.Compact() and ends up with a mesh missing several triangles. I couldn’t figured out what is happening under the hood.
Then I find that in Rhinocommon, the MeshTopologyEdgeList class has three similar methods, “CollapseEdge”, “SplitEdge” and “SwapEdge”. I would like to know how these methods affect the original indices for Vertices, TopologyVertices and TopologyEdges. For example, when a topologyEdge is collapsed, does the indices for the rest of the topolgyEdges shift ahead in order?
CollapseEdge looks like it might. I didn’t look at the other methods. Internally, all three of these functions are large and complicated. So there is a good chance the orders of mesh structures will change. But I cannot definitely say so.
The Rhino mesh is not conceived to be dynamic or remeshed. If you want the opinion of someone who has already been there, it worthwhile to make your own mesh to control your retopology and assuming the cost of converting the Rhino mesh. Or at least something in between, using your own methods of splitting or collapsing. Even if you figure out how Rhino’s methods do the reordering, you can simplify the code a lot by using a better structure for the mesh.
I believe the issue you are experiencing with the invalid mesh after Compact() might be caused by a bug in how the adjacency info is updated in the edge Collapse function of Plankton (which was a collaboration between me and Will).
I actually fixed this one Plankton bug fairly recently (https://github.com/meshmash/Plankton/commit/c3315f681bf00de3a14134936e12531466a582ec)
Are you using version 0.4.3?
MeshMachine was affected by this bug too, causing it to get the mesh into an invalid state and fail sometimes. I’ve been meaning to make some more tests and find out if this fix prevents that or if any other operations are affected or need updating.
You can do remeshing with the Rhino mesh class, and indeed the first remeshing demos I posted were done with this. The problem is though that the Rhino mesh structure stores only Faces and Vertices, and edges and connectivity info have to be found again whenever the mesh topology is updated, which makes it quite slow. This was in fact what lead me to create Plankton in the first place.