How to triangulate mesh in Open NURBS

Hello @dale,
I am converting a Rhino mesh object into Parasolid.
From Rhino I am getting a quadrangular mesh face. Now I want to Split each quadrangular mesh face into two triangles. I know that in Rhino thre is a command ‘TriangulateMesh’ whch can do this. But I am using Open NURBS SDK (C++) for converting Rhino model to Parasolid, so it will be helpful if you suggest us any API which can do the same.

Hi @psomesh94,

You might do something like the following:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select mesh to triangulate");
  go.SetGeometryFilter(CRhinoGetObject::mesh_object);
  go.EnableSubObjectSelect(false, false);
  go.GetObjects(1, 1);
  if (go.CommandResult() != CRhinoCommand::success)
    return go.CommandResult();

  const CRhinoObjRef& obj_ref = go.Object(0);
  const ON_Mesh* mesh = obj_ref.Mesh();
  if (nullptr == mesh)
    return CRhinoCommand::failure;

  ON_Mesh new_mesh(*mesh);
  new_mesh.RemoveAllNgons();
  new_mesh.ConvertQuadsToTriangles();
  new_mesh.CullDegenerateFaces();
  new_mesh.Compact();
  if (new_mesh.IsValid())
  {
    context.m_doc.ReplaceObject(obj_ref, new_mesh);
    context.m_doc.Redraw();
  }

  return CRhinoCommand::success;
}

– Dale

Thank you very much ! @dale.