Brep mesh extraction

Hi everybody,

I am trying to quickly extract a mesh from a brep. My approach is in brief the one below:

	ON_Mesh* mesh = NULL;
	for(int i = 0; i < meshList.Count(); i++) {
		if(mesh == NULL)
			mesh = meshList[0];      
			else {

I need a really fast mesh extraction and this seems not to be a suitable way for my needs even with the DefaultFastMeshParameters. I assume a mesh is created for rendering purpose for each object of the document but also the dp.drawbrep method for temporary objects in the conduit seems to be more than 10x faster (am I wrong?) than the mesh extraction above. I guess somewhere in the SDK library must be a faster way to get a mesh, even if coarser. Anybody has a hint?


I may be wrong, but the fastest way seem to be to get renderMesh from brep.

Hi @gennaro,

When Rhino needs to draw a Brep, that are in the document, in some kind of shaded display, it just retrieves the render mesh that is cached on the Brep using ON_Brep::GetMesh.

If the Brep is newly added to the document, or it does not have a cached render mesh, then one is created as needed using ON_Brep::CreateMesh. This mesh is cached on the Brep for quick retrieval.

If you are creating Breps on the fly and want to draw them in a shaded way, then you really don’t have any choice but to create them using ON_Brep::CreateMesh.

Does any of this help?

– Dale

Thank you all!

The ON_Brep::GetMesh method totally helps. I have also noticed that for a temporary object I can get rendering mesh if I call before the CRhinoDisplayPipeline::DrawBrep in a conduit. This might be the workaround I needed because the two methods seem to be together faster than ON_Brep::CreateMesh method. Am I forgetting something which may cause a delay in this way?


It all depends on the MeshingParameters you provide to ON_Brep::CreateMesh, are you sure you are using the rendering mesh parameters?

Hi @gennaro,

Like I said before, ON_Brep::GetMesh gets cached meshes. If the Brep does not have cached meshes, you won’t get a mesh in return.

Also, CRhinoDisplayPipeline::DrawBrep draws mesh wires, not shared faces. It also will not generate meshes.

CRhinoDisplayPipeline::DrawShadedBrep will create a render mesh if needed, and cache it on the input Brep.

And of course, ON_Brep::CreateMesh will create meshes…

– Dale

Hi @dale,

Is there any way to get Brep render mesh from .NET OpenNURBS 6, similar to what you do in the example from c++? I can’t find any GetMesh method there.


Hi @qlabrosse,

If you are working from within a RhinoCommon plug-in and you have a Rhino Brep object, then you can use RhinoObject.GetMeshes.

If you just have a Brep, or you are using Rhino3dmIo, then you’ll need to iterate through the Brep’s faces and accumulate the meshes from each individual face using BrepFace.GetMesh.

Does this help?

– Dale

Yes perfect with BrepFace.GetMesh. Was it there before? I guess I just didn’t search right.
Thanks @dale !


also, is it possible to get a mesh from a brep that is coarser than the rendering mesh?
One way I see is to modify the mesh parameters when using the ON_Brep::CreateMesh, but I do not know if it is safe and if I would always get something satisfactory.
Furthermore, I am wondering if there are some factors that affect the size of the rendering mesh (e.g. zoom out or different units of measurement).
Thanks in advance,


Hi @gennaro,

ON_Brep::CreateMesh does not specifically create a render mesh (although you could use it for that purpose if you wanted). Rather, it is creating a mesh based on the input meshing parameters you provide. What effects the size of the resulting mesh is the parameters you provide as input.

– Dale

Hi Dale,

I was thinking that maybe it is possible to change something in the viewport parameters (?) which could affect the chached mesh created with CRhinoDisplayPipeline::DrawShadedBrep.
Also, I would be gratefeul if you had a tip on how to get a coarse mesh without losing the control on the outcome (getting a really ugly mesh).