Struggling with creating meshes from CRhinoBrepObject


(Gccdragoonkain) #1

Two questions.

One, when I run the code below for a simple cube polysurface, why do I get 6 meshes returned in the resultant meshes array???

Two, how do I set ON_MeshParameters to mirror the rhino “fewest polygons” slider settings when converting a polysurface to a mesh.

  else if(const auto brepObj = CRhinoBrepObject::Cast(rhObj))
  {
    auto brep = brepObj->Brep();

    ON_MeshParameters mp = ON_MeshParameters::DefaultMesh;
    ON_SimpleArray<ON_Mesh *> createdMeshes;
    ON_SimpleArray<const ON_Mesh *> meshes;

    mp.SetCustomSettings(true);
    mp.SetCustomSettingsEnabled(true);
    mp.SetFaceType(2);

    brep->CreateMesh(mp, createdMeshes);
    if(createdMeshes.SizeOfArray() >= 1)
    {
      meshes.Append(createdMeshes[0]);
    }

    result = runAlgorithm(meshes, false, context) ? CRhinoCommand::success : CRhinoCommand::failure;
    createdMeshes.Destroy();
  }

(Gccdragoonkain) #2

In short, what I’m trying to recreate is this result


and


(Nathan 'jesterKing' Letwory) #3

A poysurface cube exists of six surfaces (it is a polysurface after all).

If you want to end up with one Mesh at the end you should create a new, empty mesh. Then loop over the mesh array and append each part the new mesh you created.


(Gccdragoonkain) #4

Hmm okay. Thanks for the answer. regarding my second question: how do I set ON_MeshParameters to mirror the rhino “fewest polygons” slider settings when converting a polysurface to a mesh.


(Gccdragoonkain) #5

Answering my own question. ON_MeshParameters has a simple constructor where the first argument is the same as the silder value. Nice. I got my results I wanted with below

    auto mp = ON_MeshParameters(0, 0.0001f);

    brep->CreateMesh(mp, createdMeshes);
    if(createdMeshes.Count() > 1)
    {
      int appendCount = createdMeshes.Count()-1;
      createdMeshes[0]->Append(appendCount, &createdMeshes[1]);
    }
    if(createdMeshes.Count() >= 1)
    {
      meshes.Append(createdMeshes[0]);
    }