BrepFace.GetMesh() sometimes fails

Hi,
I would like to use the analysis mesh of a BRep (as I do in Rhino via object->GetMeshes(ON::analysis_mesh, meshes):wink:
but in the following the renderMesh is always null. When I activate “mesh_type = MeshType.Render” instead I get a non-null renderMesh for the BRep param, but not for the deconstructed BRep - see the attached example.

private void RunScript(Brep x_brep, ref object A)
  {
    List<Mesh> meshes = new List<Mesh>();
    foreach (BrepFace face in x_brep.Faces)
    {
      //MeshType mesh_type = MeshType.Render;
      MeshType mesh_type = MeshType.Analysis;
      var renderMesh = face.GetMesh(mesh_type);
      if (renderMesh != null)
      {
        meshes.Add(renderMesh);
      }
    }
    A = meshes.Count;
  }

Thanks in advance for any hints,
Ute
GH_GetMeshFromBrep.gh (13.5 KB)

Indeed this is rather odd: added a face.GetMesh option - in the name of science - and results are … er … odd (and why the Brep Rebuild [not required here, mind] yields bananas?).

MeshFromBrep_EntryLevel_V0.3dm (556.0 KB) MeshFromBrep_EntryLevel_V0.gh (118.4 KB)

Not every BRep has an analysis mesh. An analysis mesh is used only for certain operations, like the Zebra Analysis or Curvature Analysis, and is computed at that time.
If you want to use any mesh you should generally always use the render mesh, as every BRep must have a render mesh at any time. But keep in mind that the quality of that mesh may depend on your display settings.

Yes, this is exactly what I am going to to: write an individual “Zebra” analysis for BRep. So how can I force to compute the analysis mesh if it is not available?

And: yes, I tried to use the render mesh instead but as my example shows it can not be got for a deconstructed BRep.

To answer your question, no, I don’t know how to force the computation of an analysis mesh, but I don’t think it’s necessary.

I downloaded your example and it worked just fine:

List<Mesh> meshes = new List<Mesh>();
foreach (BrepFace face in x_brep.Faces)
{
    MeshType mesh_type = MeshType.Render;
    var renderMesh = face.GetMesh(mesh_type);
    if (renderMesh != null)
    {
        meshes.Add(renderMesh);
    }
}
A = meshes.Count;

What exactly doesn’t work for you?

Load the GH_GetMeshFromBrep.gh file I attached to my first post. The C# Script output is the number of non-null meshes. It is always 0 for “mesh_type = MeshType.Analysis”.

Change the line to “mesh_type = MeshType.Render”: the output is 2 for the whole Brep:


but it is 0 if the list item is connected as input:

For creating an analysis component I would prefer the analysis mesh because it provides the needed discretization independently from the rendering settings, but I already would be glad to have the render mesh as a workaround.

In the first case you pass a brep, which has type Brep, in the second you pass a brep face, which has type Surface. I don’t know how to get a mesh from a surface, so I can’t offer any help there.
One simple solution to bypass the Deconstruct Brep component would be to add a number input to your C# Script and directly get the face:

List<Mesh> meshes = new List<Mesh>();
MeshType mesh_type = MeshType.Render;
var renderMesh = x_brep.Faces[index].GetMesh(mesh_type);
if (renderMesh != null)
{
    meshes.Add(renderMesh);
}
A = meshes.Count;

which, if you just want to return the mesh, can be simplified to:

A = x_brep.Faces[index].GetMesh(MeshType.Render);

Also, as to how to force the computation of an Analysis Mesh, perhaps @dale has some ideas.

I created the C# Script just for demonstration purpose, so changing its input mask does not solve the problem. I am writing an analysis component where the user (not myself) should be able to connect any Brep input to.

Thanks for attending to my issue.

Hi @UteW,

There is always this:

  private void RunScript(Brep brep, ref object A)
  {
    if (null != brep)
    {
      var mp = MeshingParameters.DefaultAnalysisMesh;
      var meshes = Mesh.CreateFromBrep(brep, mp);
      if (null != meshes && meshes.Length > 0)
        A = meshes;
    }
  }

– Dale

Hi Dale,

Thank You for your proposal. I thought I should prefer the BrepFace.GetMesh() method because - according to the documentation - it gives a reference to the mesh to me while the Mesh.CreateFromBrep() always newly creates the mesh as I understand. In case we have hundreds of faces we want to apply our analysis on, and just change some analysis parameters but not the brep, I do not like to recreate the mesh every time because of performance reasons.

  • Ute

Hi Ute,

Did you ever resolve your problem? (I’m trying to work through different meshing parameters and methods myself.)

Have you seen RhinoObject.CreateMeshes? This only works on items in the document, though; I’m not so familiar with Grasshopper’s needs and capabilities. (Then, the meshes are saved for later, if you don’t want to re-build them with new meshing parameters.)

Dan