# Stitching in Geometry Nodes - Best way to inset an edge on surface?

The Idea: I'm trying to build a procedural stitching setup for a Hat in Geometry Nodes that will take a vertex group like my edges below and inset them, acting as a rail for my stitching to follow:

The current setup:

The best way I've found to do this so far is by adding a semi-circle pipe to my current edges and then booleaning this with my hat panels to give me the inset edge at the particulat distance I'm wanting:

The Problem:

When the hat moves from my cloth simulation all the stitches begin to flicker or flip upside down which I assume has something to do with the boolean having to recalculate?

So I'm hoping to find a way to freeze these at the first frame if possible? or if anyone knows a better way of making this type of setup with an offset edge by surface?

Any help would be greatly appreciated, thank you!

• Why do you need a boolean operation? The GN stitching solutions I've seen use a curve that defines where the stitches should be. Commented Oct 31, 2023 at 17:04
• It's a cloth simulation, so a Boolean is the best way I've found to keep it procedural without having to re-orient curves etc.
– JaRa
Commented Nov 4, 2023 at 0:47
• Hello, JaRa, why does the GN modifier need to be live, at simulation time? Isn't this more like a modelling tool, which can be applied before further action? Commented Nov 4, 2023 at 9:09
• Hey Robin I'm importing the clothsim from another software (Marvelous Designer) so I need the GN to run after the mesh cache modifier if that makes sense? It's essentially the same issue I was trying to solve in the buoys example you responded too
– JaRa
Commented Nov 4, 2023 at 12:02
• The Wave Modifier causes the Resampling by Length not working properly. I suspected very tiny distances between some vertices so I applied a Merge by Distance, which seems to stop the stitches from flickering: i.sstatic.net/p3UUl.png . The 3rd and 4rth spline keep swapping indices during the animation. Overall the method of offsetting the stiches is not optimal. You should consider using the available UV map as way of offsetting using Sample UV Surface Node. Commented Nov 5, 2023 at 1:07

$$\hspace{15pt}$$The flickering and flipping occurs because the deformation changes the length and shape of the evaluated path of the Mesh Boolean node, which consequently affects the result of the Resample Curve node.

$$\hspace{15pt}$$To Solve that we need to calculate the mesh boolean path only on the first frame, and then for every frame get the deformed positions and normals. To get the deformed values we can use the Sample Nearest Surface node to get them from the deformed mesh, but we don't want the nearest deformed surface's deformed values, we want the nearest original surface's deformed values, so we first capture the mesh's position and normal, set it's position to the original and sample from the nearest surface the captured position and normal, capturing the normal on the path before setting the position.

$$\hspace{15pt}$$To do the above we first need to have the mesh boolean path and the original positions of the mesh, this is done using a Simulation Zone, which evaluates its inputs only one time, using the output of the previous frame as input for the next after:

$$\hspace{15pt}$$Then we capture the deformed mesh's positions and normals, set its positions to its originals, and sample the captured data from the nearest surface to the path, capturing the normal and setting the position. The normal is used for aligning the instances:

Full node tree:

$$\scriptsize{\text{Blender 3.6.5}}$$