# Geometry nodes, how to flat mesh islands on z axis

I have these mesh islands, I need these inner boundaries to be flat on the Z-axis, the Z position of each inner boundary should be an average of each island position.

I tried using Accumulate field and mesh island nodes, but something is missing

mesh islands:

(How to flat inner boundaries?)

(desired result)

Blender 3.6+

• I didn't get it because these nodes are controlling the purple islands, but in the 'desired result' image your are dislocating the green ones. Commented Sep 3, 2023 at 23:57
• I need both purple and the green around it to be flat as the "desired result" image. (my node setup isn't complete ) Commented Sep 4, 2023 at 0:10
• @GordonBrinkmann , aw no it's not flat, thanks for your time. Commented Sep 4, 2023 at 13:43

First, you need to mark the inner boundary. You're already doing it in your Select Inner Void zone:

It's a nice and clever solution (create two splines out of boundary edges, the longer one is outer), you should post it and apparently already posted (and suggested by you) here:

Geometry nodes, how to select the boundaries of mesh islands?

So once you have it, you need to transfer this information to the original mesh, calculate the mean $$z$$ coordinate of inner vertices, with a separate mean for each mesh island, and then set the $$z$$ of these inner vertices to their island's mean. Multiple means can be achieved by the simple pattern of Accumulate Field Total with accumulated value, divided by another Accumulate Field Total with accumulated $$1$$ of the selection (or accumulated selection, same thing):

Keep in mind your blue faces won't match, because Fill Curve is two-dimensional and sets all $$z = 0$$.

## Explanation

The "Capture Attribute" node's role is to calculate the boolean value once per each edge. Otherwise the value would have to be calculated 3 times, as that's how many times this field is used. Moreover, the CA node specifies the "Edge" domain, and so enforces the calculation to be done in this domain, whereas the "Accumulate Field" nodes (explicitly, chosen in options) and "Set Position" node (implicitly, always the case) use the "Point" domain: if you didn't use the CA node, you would need to replace it with "Evaluate on Domain" node in "Edge" mode.

"Position" → "Separate XYZ" → "Combine XYZ" are there to change only the $$z$$ coordinate and leave the rest.

"Math: Multiply" node wouldn't be needed if the "Accumulate Field" node had a "Selection" input - but it doesn't. So what I do is multiply the $$z$$ coordinates of all irrelevant vertices by $$0$$, therefore not contributing to the total $$z$$ coordinate. This is because irrelevant vertices hold False value, which translates into $$0$$ float value. Meanwhile True value translates into $$1$$ float value. Multiplying anything by $$1$$ does nothing, keeps it unchanged.

Upper "Accumulate Field" node sums up all relevant $$z$$ coordinates, and the other AF node sums up all $$1$$s (Trues) therefore counting the number of relevant vertices. Dividing a sum of values in a collection by the number values in a collection gives you an average value in that collection, and that's exactly what happens here.

...................

For blue zones, I [addition by Pooya heydari] added a bit more extra nodes:

• "It's a nice and clever solution (create two splines out of boundary edges, the longer one is outer)" ...This answer was already given: blender.stackexchange.com/a/299484/145249 Commented Sep 4, 2023 at 10:37
• @quellenform aaah you edited the original answer (the original being about the number of edge neighbors of a vertex). Maybe you should have added a separate answer since it's a separate approach. Commented Sep 4, 2023 at 11:24
• hm, you might be right though. I added it because the answer looked more like a "variant" of the existing solution to me. Commented Sep 4, 2023 at 12:07
• Yes, shout out to @quellenform, all my questions are kind of relative to each other. :D Commented Sep 4, 2023 at 13:50
• Thanks, @MarkusvonBroady This is a great answer, can you explain a bit about node setup? Why do we need to capture attribute, why use multiply node and ... :D Commented Sep 4, 2023 at 13:50