How to create point cloud data from mesh?

Hello everyone,

I am opening step file and getting its mesh. Now that I have mesh object I want to write/create point cloud from the mesh. How can I achieve this

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
      string stepFilePath = @"C:\Users\d\Downloads\cube.step";
     
      RhinoDoc.Open(stepFilePath, out bool t5);

      var activeDoc = RhinoDoc.ActiveDoc;

      IEnumerable<RhinoObject> brepObjects = activeDoc.Objects.GetObjectList(ObjectType.Brep).ToList();

      List<RhinoObject> brepObjectsList = brepObjects.ToList();

      foreach (var obj in brepObjectsList)
      {
          obj.Geometry.GetBoundingBox(true);
          RhinoApp.WriteLine($"Brep Object Id: {obj.Geometry.GetBoundingBox(true)}");
      }

      Mesh mesh = Mesh.CreateFromBrep(brepObjectsList[0].Geometry as Brep)[0];
      
      RhinoApp.WriteLine($"vertices count: { mesh.Vertices.Count()}");
      
      return Result.Success;
  }

Create a PointCloud Geometry with this constructor - see in the docs

public PointCloud(
IEnumerable<Point3d> points
)

→ “point cloud data”

or you can directly add the Pointcloud to the document - ObjectTable.AddPointCloud:

public Guid AddPointCloud(
IEnumerable<Point3d> points
)

not sure - is this what you where after ? hope it helps - kind regards - tom

Hey Tom,

thanks for replying. I should clarify more precisely. With this constructor and method it will create viewable point cloud. but this points we need to provide as input may be from vertices.

What I already know / have tried

  • Converting mesh vertices directly into a PointCloud (e.g. new PointCloud(mesh.Vertices)) is easy, but this produces a point distribution that depends heavily on tessellation and is not uniform.
  • For my use case, I need points sampled on mesh faces, ideally proportional to face area, with:
    • fixed point count
    • deterministic results (fixed seed)
    • independence from mesh vertex density

Current approach

Right now I’m manually:

  • iterating over mesh.Faces
  • computing face areas
  • sampling points inside faces using barycentric coordinates
  • adding those points to a PointCloud

This works, but I want to confirm whether this is the intended / recommended approach in RhinoCommon, or if there is an existing API or utility I may have missed.

My questions

  1. Is there any RhinoCommon-supported method or helper for uniform surface sampling of a mesh (not vertices)?
  2. If not, is manual face-area–weighted sampling the correct and stable approach?
  3. Are there any pitfalls with this approach in Rhino (performance, precision, edge cases)?
  4. Would you recommend sampling from:
  • the mesh directly, or
  • converting mesh → Brep and sampling from Brep faces?

there are some nice options for meshing / remeshing.
but not sure if @DanielPiker did ever expose it nicely in rhinocommon.

have a look at this topic.

What is the benefit of having a point cloud instead of nurbs?