OpenNURBS C++ SDK export ON_Extrusion to mesh

Hi, I’m using OpenNURBS C++ SDK to export a ON_Extrusion object to mesh. The original model is:
image
Here’s my problems:
Firstly, I used const ON_Mesh* mesh = aExtrusion->Mesh(ON::any_mesh); , but the return value is nullptr.
Secondly, I used aExtrusion->BrepForm(brep); to get the brep form of the extrusion. The result showed as belows:
image
Can you tell me how to export the extrusion object to mesh correctly? Thanks a lot!

Hi @jiangz-a,

Are you using openNURBS from an application other than Rhino, or are you using openNURBS from a Rhino plug-in?

ON_Extrusion::Mesh returns a mesh that has been attached to the extrusion object. Rhino will attached a mesh to an extrusion object when you shade a viewport, for example. This function does not generate a new mesh from the extrusion.

Does this help?

– Dale

2curvesurface-tri-plan-拉伸体.3dm (329.5 KB)
I’m using Rhino6 to view the model. Do you mean the mesh was not been attached to the extrusion object in the original model? Can you help me comfirm it?
And why the BrepForm() returned brep object is not correct either?
Thank you!

Hi @jiangz-a,

It might help if you could share some sample code code that is not working for you.

Thanks,

– Dale

aExtrusion is ON_Extrusion* type casted from ON_Geromtry* type

  1. const ON_Mesh* mesh = aExtrusion->Mesh(ON::any_mesh);
    the mesh is NULL.
  2. ON_Brep* brep = aExtrusion->BrepForm(nullptr);
    ON_SimpleArray<const ON_Mesh*> meshs;
    int retValue = brep->GetMesh(ON::MeshType(4), meshs);
    the meshs is empty.

Hi @jiangz-a,

If you are writing a Rhino plug-in, and you want to export meshes from one or more objects, then you might consider using the RhinoMeshObjects SDK function. Here are a couple of C++ SDK samples that use this function:

cmdSampleCustomMeshObjects.cpp

This sample generates meshes using custom meshing parameters. But you could quickly modify it to use Rhino standard meshing parameters.

SampleExportMesh

This code is taken from a file export plug-in sample. In this example, Rhino’s standard meshing parameters is displayed.

Finally, if you just want to get to the render mesh that is cached onto Breps and Extrusions, then you can do something like what is in the attached sample:

cmdTestJiangz.cpp (2.4 KB)

Let me know if any of this helps.

– Dale

Thank you for your reply!
I’m trying to export geometry data of .3dm models to a file and load it with my own application to display it. I’m using OpenNURBS C++ API, not SDK for Rhino plug-ins. Maybe I’ve mistaken two of them.
And I tried the sample code you offered:

ON_SimpleArray<const ON_Mesh*> meshes(brep->m_F.Count());
const int mesh_count = brep->GetMesh(ON::render_mesh, meshes);

const ON_Mesh* mesh = extrusion->m_mesh_cache.Mesh(ON::render_mesh);

the problem is the GetMesh() operation returned NULL or an empty array. Can you help me find out how to fix this? Thank you!

Hi @jiangz-a,

Thank you for clarifying what you are working on.

Let me know if you find guide helpful:

Note, not all .3dm files contains cached render meshes. The user must choose to save 3dm files, from Rhino, with render meshes.

– Dale

Thank you Dale! I’v tried to resave my models, and in some models the ON_Extrusion object contained cached render meshed now. But some models still don’t contain render meshes. I’ll investigate this problem later.

If I want to evaluate the NurbsSurface in the ON_Brep object acquired from ON_Brep* brep = aExtrusion->BrepForm(nullptr); The result is:
image
How can I fix this?