You’re right, @maje90, I completely missed the concave hole issue.
Anyway, I’ve made some progress and learned 2 things:
-
Apparently there is an issue with
Point3d
precision, which can lead to unexpected results while performing operations on meshes. @Krzysztof described it in more detail in the following post:
Mesh Inclusion Error - #19 by Krzysztof
After roundingPoint3d
coordinates to 4 decimal places mesh triangulation works as expected. -
Rather than checking individual vertices for intersection with internal edges, I’m iterating over mesh faces and perform the inclusion test on their center points. This operation is split into 2 phases:
→ coarse, where we check against a bounding box of each curve
→ detailed, more expensive Curve.Contains method is used for precision
It works quite nicely, but still, we spend the majority of the time removing unwanted faces. Comparison to the most promising algorithm from @maje90’s previous post is a bit unfair, since his approach results in a corrupt mesh. I suspect this is related to the mesh precision issue mentioned above.
Questions:
- Is there a smarter way of changing precision of a
List<Point3d>
than iterating over the entire list and changing the individual coordinate of each point?
foreach(var pt in pCrv)
{
double x = Math.Round(pt.X, 4);
double y = Math.Round(pt.Y, 4);
double z = Math.Round(pt.Z, 4);
points.Add(new Point3d(x, y, z));
}
- How can I iterate over a list of faces in a thread safe way? The following code converted to a Parallel.For loop breaks the mesh:
List<BoundingBox> bBoxes = new List<BoundingBox>(); foreach(var crv in iCurves) { bBoxes.Add(crv.GetBoundingBox(false)); } Point3d center; List<int> faceIndex = new List<int>(); for (int i = 0; i < mesh.Faces.Count; i++) { center = mesh.Faces.GetFaceCenter(i); for (int j = 0; j < iCurves.Count; j++) { if (center.X > bBoxes[j].Min.X && center.X < bBoxes[j].Max.X && center.Y > bBoxes[j].Min.Y && center.Y < bBoxes[j].Max.Y) { if (iCurves[j].Contains(center, Plane.WorldXY, 0.01) == PointContainment.Inside) faceIndex.Add(i); } } } mesh.Faces.DeleteFaces(faceIndex);[meshing.gh|attachment]
meshing.gh (14.2 KB)