I have a set of points representing the contours of an object. The structure is List<List<Point3d>> where each List<Point3d> is a contour of an object. The goal is to have a 3d object where every contour has been subtracted from the first contour in the list and then extruded to a 3d object
The image shows how the desired result, where the lightning and the arrow has been subtracted from the outter most shape, please note that the outermost shape is no a product of subtracting a circle from a square, but that outer most shape is like that originally
I was wondering if there is a better solution than the one I currently have implemented RhinoExporter.cs (3.5 KB).
I have both tried to make each contour a polyline, then extrude them and then using boolean difference, but that has originally caused some problems with the extrution, since one of the contours was not solid. I got around that by making a function that remove small indents that would cause the shape to not be solid when made into a brep.
I also had to import the shapes to rhino and then retrieve them again before doing the boolean difference, since rhino apparently does something to the shapes that is needed for boolean difference. I looked at the attributes and suspect something with the solid orientation, since that seem to change when added and retrieved from Rhino.
I also tried Brep.CreatePlanarBreps(curveList)[0]; which makes a planar surface with the correct shape with holes, but I could not find a method in Rhinocommon that does the same as ExtrudeSrf in Rhino.
If you get brep(s) as result of Brep.CreatePlanarBreps() method you can use BrepFace.CreateExtrusion() method to create extrusion from any brep face that is part of your brep - the same as ExtrudeSrf Rhino command.
If you import shapes and if some of them are not closed curves than you will have problem if you expect to get closed brep (solid) as result of extrude operation of such not-closed-curve.
Generaly if you have closed curves/polylines following aproach should work
create breps as result of extrusion method(s) from curves/polylines, brep should be solid
from outer brep you substract (boolean difference) inner breps
maybe inner breps should be little âhigherâ (longer extrusion) to ensure boolean difference not fail
I got it to work with Brep.CreatePlanarBrep and then extruding the faces. The only problem I have is that while the curves are closed as seen on this picture .
There is a little overlap as seen on this picture. (which is a zoomed in version of the first picture)
This is a problem when I want to use CreatePlanarBrep as it wonât work when there is an overlapping piece as shown. What happens when using CreatePlanarBrep with a overlapping piece is that only the outer Brep is created, without the holes.
So what I do now is to go through each curve, and remove duplicate points to avoid this.
Do you know of a good way to make an âapproximateâ curve that avoids this in a good way?
Regarding the BooleanDifference method:
Here I also need to remove duplicate points, or the resulting brep will not be solid.
In my test example I have three breps, one outer and two holes. When I create them the outer brep has an inward solid orientation, while the two others are outward. After adding and retrieving from doc they are all outward. Could this be the problem? And if so, can I ensure that they will have a certain solid orientation?
Also, I set tolerance for the boolean difference to be doc.ModelAbsoluteTolerance, Incase that can be a problem.
I guess that your curve/polyline is not closed and if it is not closed then it can not produce âholeâ.
It would be good if you can upload such curve/polyline to try to locate âproblemâ and suggest solution.
At the begining of your post you write that you have List<List> where each List represents âcontour of an objectâ. It means that from List you can create Polyline and use all capabilities that Polyline Class has to achieve closed and valid polylineâŚ
As you can see in the 3d file, Rhino describes the lightning as a closed curve, but as soon as you extrude the curve it warns you that the lightning is self-intersecting, and if you extrude anyways, the small intersecting pieces are âcutâ from the lightning to make their own open poly surface
Rather than creating a Polyline from a raw point list, you might first run the points through the Point3d.SortAndCullPointList function. Perhaps this will help prevent segments that double back.
And you really donât need the NURB form of the polyoline. So instead of doing this:
var curve = new Polyline(Contour).ToNurbsCurve();
Do this:
var polyline = new Polyline(Contour);
var curve = new PolylineCurve(polyline);
On a side note, the curves in your model are incredibly poor. For example, the lightening bolt curve has 813 control points when it should only have 12. Poor curves create poor surfaces.
So it is obvious that your list of points is source of problems. So as Dale sugested prior to cosntructing polyline you should âclean upâ your list of points.
And there is so many points/segments for such a simple shape. If you can not control âqualityâ of points, maybe you could implement some algorithm to simplify polyline if your solution allows altering polyline.
i have digged further into the requirrements of what iâm building and it turns out that i didnât need the exported contours to be 3 dimensional after all. so what I ended up doing was to cull duplicates and then just creating polylines from the contours.
@dale, regarding the curves being very poor, there is no good way to change that, since the contours are generated from image files and thus will be jagged no matter what. However I am trying to combat that by using the smoothing function on the polyline.