2
$\begingroup$

I'm working on a Geometry Nodes setup and need to reorder the Mesh Island Index so that the indexing begin with the lowest minimum Z-coordinate.

The default Mesh Island index is based on vertex order, and I need a positional index for a different reveal effect.

My current setup

My endless conversations with different AIs always led to using sort elements node, but it does not work, because its output is geometry, but I need new order of the indexes.

$\endgroup$

2 Answers 2

2
$\begingroup$

Update: Thanks to filanek's answer I see now that since I've last used Geometry Nodes they have added attribute statistics nodes that work with fields (unlike Attribute Statistic node itself), so my setup below indeed is now unnecessarily convoluted but I'll leave it as the thought process might still be educational. This simple setup should get you what you wanted:

enter image description here


Old: I've been away from Geometry Nodes for a long while now so I don't know if this is a convoluted way to do it, but here goes:

enter image description here

What do we need to do? Find the lowest vertex in every island. Find the Position Z value of those vertices. Capture those Z values on every vertex of those islands so we can sort the islands using them.

Step by step:

enter image description here

  1. Using a Sort Elements node, sort indices so they start from the lowest vertex in every island. This sorts all indices, they don't reset at every island. It's just that for every island, the smallest index is the one with the lowest z position. So now our indices look like [0,1,2], [3,4,5,6], [7,8] etc.
  2. We'd like the indices in the islands to be grouped in a repeating pattern of some kind so we can distinguish between them, so let's reset the index counter whenever we step into a new island. A trailing Accumulate Field count grouped by Mesh Island would do that. Islands may have different amounts of vertices, but they'll all start counting from 0. Since we had sorted all vertices by their Z position in Step 1, all index0 vertices are also the lowest ones. Now we have a list of indices that goes like [0,1,2], [0,1,2,3], [0,1] and so on.
  3. With a Switch node in Float mode, we can say: if it's an index0 vertex [True]: keep its Z value, if not [False]: overwrite whatever value it has now with 0.00 because we don't want them.
  4. Using an Accumulate Field node's Total output, propogate this Z value to every other vertex of those islands. Since we zeroed out all the other values just now in Step 3, the total gives us only the lowest Z value we kept. Using the Mesh Island > Island Index as the Group ID lets us do this island by island. Our list of numbers looks something like this: [-7.03,-7.03,-7.03], [0.26,0.26,0.26,0.26], [4.38,4.38] and so on.
  5. Now when we Sort Elements again using these Z values, Mesh Island indices start from the lowest number and goes up, which corresponds to the lowest point vertex of each island.

$\endgroup$
0
$\begingroup$

It seems to me working when I sort elements on the point domain by island average Z height see below:

sort islands

$\endgroup$
2
  • 1
    $\begingroup$ Oh wow, TIL there are now field attribute statistics nodes! OP was asking for the "lowest minimum z" so using "Field Min & Max" instead of "Field Average" should do it in your setup. $\endgroup$ Commented 13 hours ago
  • $\begingroup$ @Kuboå, yes good point, I have not read the question carefuly for that reason used the average:/ $\endgroup$ Commented 13 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.