Given a brep (typically in 3D) I’m creating a planar counterpart of the brep using this method:
var planarBreps = Brep.CreatePlanarBreps(brep.Trims, epsilon);
a 3D brep and it’s planar counterpart
I’m using the pair of these to create a planar mesh which represents the 3D brep. I populate the planar brep with vertices, using two approaches together:
- transferring on-surface points from the 3D brep to the planar brep
- subdividing the planar brep’s trims/edges into points
“transferring on-surface points” means get the UV on the 3D brep then construct a planar point using the same UV but now on the planar brep.
_ = brep3D.Faces[0].ClosestPoint(point, out var u, out var v);
return planarBrep.Faces[0].PointAt(u, v);
So you can see, I need the brep’s trims and projected points to be in the same 2D area. Here are the results of a unit sphere- All 3 of these properties of the planar brep do not align: trims, edges, projected points. (The projected points don’t even lie on the surface of the planar brep?) The domains appear to be the same scale, just mis-translated.
So I found one fix: transfer the domain from the 3D to the planar brep.
_ = planarBrep.Faces[0].SetDomain(0, brep3D.Faces[0].Domain(0));
_ = planarBrep.Faces[0].SetDomain(1, brep3D.Faces[0].Domain(1));
this aligns all 3: Trims, Edges, and projected points, all lie within the planar brep.
I thought I was done!- until I started working with breps formed via. a boolean difference operation. As it turns out this solution does not work with more complex breps.
Here is a sliced sphere (now we have two 3D breps, ignore the top circle face for now, I’ll only populate the spherical face)
before transferring the domains (as expected, nothing is aligned):
And now here is the result after applying the “fix” (transferring the 3D domain to the planar). What worked before with the sphere no longer works. The trims, edges, and projected points are not perfectly aligned (almost, but the scale is off).
In the case of these more complex breps, it feels like:
- before the “fix”: translation wrong, scale correct
- after the “fix”: translation correct, scale wrong.
After that lengthy description (thank you for reading this far) my question is: can someone suggest an alternate solution or help me amend my “fix”, the code copied again below.
_ = planarBrep.Faces[0].SetDomain(0, brep3D.Faces[0].Domain(0));
_ = planarBrep.Faces[0].SetDomain(1, brep3D.Faces[0].Domain(1));
I did try normalizing 3D brep domains, the same scale issue exists, only, it’s all bounded inside the 0…1 unit square. It’s almost like, the domain of the 3D face remembers its former domain before the boolean difference was performed, and is confused about what to pass along, or it gets corrupted in the transmission. Is there an operation to perform on a boolean-difference-brep to “clean up” its domain?
Thank you!