Mesh contour to spiral: unstable slicing / point position

Hi, lately I’ve been working more with meshes in Grasshopper (mostly for generating 3D-printing toolpaths), so having a clean spiral as a single continuous path is really important to me, but I keep running into errors all the time.

My issue is that sometimes slicing/contouring the mesh into layers works OK, and other times the result is unpredictable and later, when building the spiral, everything breaks (the continuity/order of the path doesn’t come out correctly).

My base Brep is internalised, and the generated mesh is also internalised.

I’d really appreciate any tips on how to make mesh slicing repeatable/stable for further processing, and what “mesh hygiene” steps you typically do before contouring to avoid these kinds of problems.

Additionally: after slicing, is it possible to somehow “straighten”/align the points vertically so they sit perfectly flat like a solid cut by an ideal plane (i.e., truly level at a given Z), instead of being slightly “adapted” to the mesh geometry?

I’m attaching screenshots and the .gh file — thanks!

MESH_slice.gh (1,4 MB)

I think there are two problems, the first is the seam of each curve, the second is the division of a polyline in a given flat number of segments

after the Contour, you should be happy to have the output curves already organised by their height, I don’t see a real reason for flattening that tree…
not only it’s useful to have them organized by increasing height, but it’s also useful to see if a given branch contains more than one curve (which means those curves need to be connected into a closed single curve)

so, starting from here after the Contour, I would make sure they are joined and eventually closed, with a check to verify they are all closed ones:

then I would align the seams, in such a way each curve on each layer has the very same start point, maybe something like this:

last, I would divide each curve by its length, or a parameter based on its length, as you might want longer curves to be divided into more fragments… the point is, even if this shape still has some sort of circularity, it’s not a perfect cylinder… which means that each layer you want to start at height = H and proportioinally end at height = H + Layer_height, regardless of how many division points you have

this generates a spiral between each two contours, meaning that for 10 contours you will end up with 9 in-between curves

the main thing is, take each curve by its branch x, divide it into n points depending on its length, then for each point A, A’… find its closest point B, B’ on curve at branch x+1, those two points define the vector that will be used to create the incremental spiral

because we know in advance how many points each curve is divided into (which is in this case its length) we can give each vector a multiplier in range 0 to 1, depending on its position on the list: starting from 0 (beginning of the curve → beginning of a given layer) engind into 1 (end of each spiral curve → end of a given layer)

MESH_slice_inno.gh (1.4 MB)

Hey, @inno It worked very well. I also tested it on other models. Your advice is very useful, I will remember it. Thank you for your help and time, I am so grateful to you.

happy to help, just keep in mind that this kind of spiralization generally works pretty well when the model has a sort of axial simmetry (cilinder-like overall structure) and the length of the curves identifying neighbor layers are pretty similar in length

it won’t work that well if sudden changes in geometry are present, or neighbor layer curve-lengths are much different