Get mesh for any geometry object in 3dm file


for a creative coding project, I have to create 3d objects that can be rendered with the game engine Stride as traditional meshes. Is there anything like this javascript function: rview/SceneUtilities.js at master · mcneel/rview · GitHub but for C#?

Basically, create vertex (and index) buffer for any geometry in a 3dm file that also rasters all curves and so on… I’ve searched a bit on GitHub but couldn’t find a viewer example as there is for javascript.

The goal is to make a 3dm read/write library for vvvv gamma.


@luis - can you help with this?

I think I got a bit further: There is GetMesh() for Extrusion and BrepFace. And Brep has CreateFromSurface().

So can someone confirm that this should work?:

If Extrusion → GetMesh()
If Surface → Brep.CreateFromSurface()
Brep → foreach Face → GetMesh()

Or is there a better way?

Hi @tebjan,

Perhaps something like this:

public static Mesh GetGeometryMesh(GeometryBase geometry)
  Mesh rc = null;

  if (geometry is Mesh mesh)
    rc = mesh;
  else if (geometry is Extrusion extrusion)
    var extrusionMesh = extrusion.GetMesh(MeshType.Any);
    if (null != extrusionMesh)
      rc = extrusionMesh;
  else if (geometry is Brep brep)
    var brepMesh = new Mesh();
    foreach (var brepFace in brep.Faces)
      var brepFaceMesh = brepFace.GetMesh(MeshType.Any);
      if (null != brepFaceMesh)
    if (brepMesh.IsValid)
      rc = brepMesh;

  if (null != rc)
    if (!rc.IsValid)
      rc = null;

  return rc;

– Dale

Yes, have something working along those lines at the moment. Good point with Normals.ComputeNormals() and the IsValid checks. I’ll post a link to the GitHub repo as soon as I’ve pushed something.

Is there a way to get the world transformation for a specific geometry?

this is in rhino:

and this is how the meshes get generated:

as you can see, they all sit in the center… I guess there are some instance transformations. but how do I know whether the original mesh is visible or whether only the transformed instances of it should be visible?

At the moment your best way is to use the center of the bounding box for your geometry. Rhino geometry is always in world space. Rhino geometry at this time has no concept of object frame/origin.


Ok next up :slight_smile: Is there any way to optimize meshes or reduce polygons? Or re-mesh? At the moment some circular and round forms have extreme vertex counts that aren’t suitable for real-time rendering.

I found MeshingParameters but didn’t find a method to use it with or a way to re-process the existing meshes. Is this even possible?

Not in rhino3dm. Rhino itself has tools like you describe.

— Dale

Ok, got it, but can this be adjusted when saving the 3dm file in Rhino? So that the loaded meshes have fewer polygons?

Hi -

Not during saving. When you export a polysurface to a mesh format, you will get a dialog to adjust the polygon count as part of the saving procedure. That is not the case when you export a mesh.

Rhino has native QuadrangulateMesh, QuadRemesh, and ReduceMesh commands. Grasshopper also has additional native remeshing components and there are several plug-ins to edit meshes.

Ok, but then I am a bit confused or I wasn’t able to phrase my question correctly. What exactly controls the mesh resolution that is produced when calling brepFace.GetMesh() in the Rhino3dm library?

Hi -

I don’t do any coding but I can take a guess - someone will correct me when necessary.

To display a brep in a Rhino viewport, a display mesh is created and attached to the brep. There are controls in Rhino to make that mesh less or more detailed. This mesh is saved in the 3dm file and can be extracted without running Rhino. If display meshes are cleared in the Rhino file (with the ClearAllMeshes command or if all modeling has been done in wireframe mode), you won’t be able to extract a mesh from a brep in a 3dm file.

Thanks, that’s very good info!

File > Properties > Mesh

– Dale

1 Like