Create new mesh with customized ON_MeshParameters (C++/Rhino 5)


Hello all,
I’m trying to figure out a following problem. I have some Brep that I need to create mesh for. This Brep is saved in document object or it could be created in memory only (with using AutoSweep2 method) from this saved surface.
And now I need to create a mesh for this brep. It does not depend it is analysis or render mesh, it serves just for some calculations. I need to create this brep with customized parameters as the best.
And now the problem raises, I could not make Rhino to create mesh using my custom ON_MeshParameters, at all. It is for Rhino 5 (and also maybe 4) and C++ SDK.

I tried it that way:

ON_Mesh* GetMesh3D(const ON_Brep* brep, ON_MeshParameters& mp)
    if (brep == NULL) { return NULL; }
    bool created = false;
    const CRhinoObject *obj = ObjectFromUUID(brep->ModelObjectId());
    if (obj == NULL)
    	obj = RhinoApp().ActiveDoc()->AddBrepObject(*brep);
    	created = true;
    if (obj == NULL) { return 

    ON_Mesh *result = NULL;
    RhinoObjectSetMeshParameters(obj, mp);
    ON_SimpleArray<const CRhinoObject*> objs(0);
    ON_SimpleArray<ON_Mesh*> meshes(0);
    //if (RhinoGetRenderMeshes(objs, meshes) > 0)
    if (brep->CreateMesh(mp, meshes) > 0)
        result = meshes[0]->Duplicate();
    if (created) { RhinoApp().ActiveDoc()->DeleteObject(obj); }
    return result;

and also this way:

const ON_BrepFace *face = GetBrepFace(object);
if (face == NULL) { return NULL; }
RhinoObjectSetMeshParameters(object, mp);
ON_SimpleArray<const CRhinoObject*> objs(0);
ON_ClassArray<CRhinoObjRef> meshes(0);
if (RhinoGetRenderMeshes(objs, meshes) > 0)
	ON_Mesh* result = meshes[0].Mesh()->Duplicate();
	return result;
return NULL;

The ON_MeshParameters are set as:

ON_MeshParameters mp = ON_MeshParameters::QualityRenderMesh;
mp.Set(Settings().AutoMeshParameter, 30.0);
//mp.m_bComputeCurvature = false;
mp.m_bCustomSettings = true;
#if defined(RHINO_V5_PLUGIN)
mp.m_bCustomSettingsEnabled = true;
//mp.m_bDoublePrecision = true;
//mp.m_bJaggedSeams = false;
mp.m_bRefine = true;
mp.m_bSimplePlanes = false;
mp.m_face_type = 1;
//mp.m_grid_angle = 0.0;
//mp.m_grid_amplification = 1.0;
//mp.m_grid_aspect_ratio = 0.0;
//mp.m_grid_max_count = 0;
//mp.m_grid_min_count = 0;
mp.m_max_edge_length = 150.0;
//mp.m_mesher = 1;
mp.m_min_edge_length = 30.0;
mp.m_tolerance = 2.0;
//mp.m_min_tolerance = 0.0;
//mp.m_relative_tolerance = 0.5;
mp.m_refine_angle = ON_DEGREES_TO_RADIANS * 70.0;
//mp.m_texture_range = 2;

I don’t think I have understood ON_MeshParameters structure very well, because it seems confusing to me.
Can you please help me with correct settings of ON_MeshParameters and the right way how to call that to create a custom mesh for brep in document and/or just in memory?
I have found maybe 3 different ways how it should be able to create meshes (or at least select which type of mesh is going to be created) but no one works for me.

Thank you in advance,

(Dale Fugier) #2

Here are a couple of samples that create meshes from Breps using a custom ON_MeshParameters object

Doe this help?


Hi Dale, thank you for your answer. Yes, it helped, but…

This solution does not react on Density parameter anyhow. I try to set it by

ui.m_mp.m_relative_tolerance = 0.5; // Density

but the result mesh is already the same. The next problem is, I can’t use this sample for breps which are created using Sweep2 with Refit option. Nothing or Rebuild is usable, but with Refit option it does not affect meshing process at all.

(Dale Fugier) #4

What are all of the other meshing parameters, and that Brep are you trying to mesh? Can you post these?