I tried converting the mesh to a brep (Brep.CreateFromMesh), but without success. The mesh is successfully created to a brep, but then Brep.DuplicateNakedEdgeCurves simply threats both outer and hole naked edges as the same:
Running Brep.MergeCoplanarFaces before Brep.DuplicateNakedEdgeCurves - would solve the issue, but sadly that method does not exist in Rhino3dmNET.
At the moment, I am finding the longest naked polyline - and stating that: this is the outer one.
And all others are inner naked (hole) polylines.
I am an interested if there is another way, to extract the mesh holes? Maybe with a “topological” approach, instead of upper: longest polyline approach?
Something like this should work in rhino3dm (thanks to @DavidRutten for the tip). You will have to decide how to filter out the outer edge loop.
// mesh = your mesh
var edges = new List<Curve>();
for(int i = 0; i < mesh.TopologyEdges.Count; i ++ )
{
var faceCnt = mesh.TopologyEdges.GetConnectedFaces(i).Length;
if(faceCnt == 1)
edges.Add(mesh.TopologyEdges.EdgeLine(i).ToNurbsCurve());
}
var result = Curve.JoinCurves(edges);
Hi @fraguada ,
Thank you very much for the detailed reply and your help.
I thought that calling Brep.MergeCoplanarFaces before Brep.DuplicateNakedEdgeCurves, would enable me to differentiate between the outer naked, and inner hole lines.
But now I see that this does not work, even in Rhino, without using Rhino3dm.
It seems that RhinoCommon threats the inner hole lines: as only those, whose trim curves are not intersecting the BrepFace outer trim curves:
Of course, I always assume that: the longest joined curve in outerNaked_L is the outer one I need. While the other one in the same list - is a hole curve.
Thank you for this solution Luis. Indeed clever solution.
I was still puzzled that neither Brep nor Mesh RhinoCommmon objects having a method which can differentiate between an outer naked edge. And an inner naked edge (hole).
Hi @dale ,
Thank you very much for the suggestion.
If I understood you correctly, I have to check if trim loop, is outer/inner type?
If this is so, I still can’t extract the biggest hole curve:
The following code:
brepLoops = brep.Loops
brepEdges = brep.Edges
hole_L = []
for brepLoop in brepLoops:
if (brepLoop.LoopType == rg.BrepLoopType.Inner):
for brepTrim in brepLoop.Trims:
BEI = brepTrim.Edge.ComponentIndex().Index
BE = brepEdges[BEI]
BE_crv = BE.DuplicateCurve()
hole_L.append( BE_crv )