Modify a mesh's topology

Hi Guys,

I’ve struggled with one mesh topology modification problem for a long time. My question is simple: modify an existing ON_Mesh object instead of replacing old mesh object with new mesh.
My persudo code is listed as following:
CRhinoMeshObject* pMeshObj;
m_pMesh = const_cast<ON_Mesh*>(pMeshObj->Mesh());
m_Topology = new ON_MeshTopology(m_pMesh->Topology());
My question is about the third line( it can’t pass compiling). I’ve searched opennurbs_mesh.h and found the copy construction and operator = overload functions are decleared as private.
In fact, I want to modify the mesh’s topology, so I need the raw topology firstly and also need add or remove some items in the topology to modify ON_Mesh (dynamically searching topology of ON_Mesh and modify ON_Mesh by the modified topology). But I can’t find a simple way to copy the mesh’s raw topology.
Any suggestion is welcome.

If you want to modify stuff in Rhino, you must:

1.) Get the object.
2.) Copy the object’s geometry.
2.) Modify the copied geometry.
3.) Replace the original object’s geometry with the copy.

By following this workflow, you will endure that you action is undo-able.

For example:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select mesh to modify");
  go.GetObjects(1, 1);
  if (go.CommandResult() == CRhinoCommand::success)
    const CRhinoObjRef& object_ref = go.Object(0);
    const ON_Mesh* mesh = object_ref.Mesh();
    if (mesh)
      ON_Mesh mesh_copy(*mesh);
      // TODO: Modify mesh_copy here
      context.m_doc.ReplaceObject(object_ref, mesh_copy);
  return CRhinoCommand::success;

Hi Dale,

Thank you for your reply.
In fact, I want to borrow the ON_MeshTopology from existing mesh( or copied mesh) and modify the ON_MeshTopology object and the copied mesh both. But the point is that ON_MeshTopology’s copy construction and operator = overload functions are decleared as private. So my question is how to copy a ON_MeshTopology object from a existing ON_MeshTopology object.


A mesh’s topology is generated from and is a reflection of the mesh itself. So doesn’t make sense to copy one mesh’s topology to another mesh.

Which leads to the question: What exactly are you you trying to do and why?

Hi Dale,

Thanks again for your reply. My mesh engine is based on pure triangle mesh but ON_Mesh supports mixed triangle and quad mesh. So If I convert ON_Mesh to my mesh, some information(color, texture, quad to triangle) may lost. Now, I have transfered some algorithm from my mesh to ON_Mesh, and I just want to use ON_MeshTopology as input but also make some modification during algorithm applying. After that, I will call ON_Mesh’s DestroyTopology to regenerate a new topology for the new ON_Mesh object.
Since you’ve told me that door is closed to me, and I will try to find some other solutions. Really, really, thank you for your patience and your help.


If you need triangles only, the make a copy of the mesh and then call ON_Mesh::ConvertQuadsToTriangles().

There is a sample that is a good demonstration of the workflow.