5
$\begingroup$

I am wondering if it is possible to find index based on certain attributes, like "index of the longest edge" for example.

It is easy to create a selection from attributes, but I can't seem to figure out a way to get indexes out of them, which I would like to use to calculate further (in function nodes).

In addition, I would like to find such indexes among multiple islands of meshes, imagine a mix between accumulate field node and attribute statistics node.

$\endgroup$
3
  • $\begingroup$ Does this answer your question? How can I re-sort the points/indexes of an object in geometry nodes? $\endgroup$
    – quellenform
    Commented Jun 12, 2022 at 10:49
  • 1
    $\begingroup$ This could also be a solution: Find highest index value for each Mesh Island. With this technique you can easily find out the index with the highest or lowest value of your choice. $\endgroup$
    – quellenform
    Commented Jun 12, 2022 at 11:26
  • $\begingroup$ @quellenform I am aware of the sorting post but was trying to figure out a simpler solution to my problem (sorting is much more advanced), and my problem involves finding the longest segment in each spline in a curve (but I don't want the question to be exclusively about it so didn't mention that). Your second link sounds useful I will study it. $\endgroup$
    – Zhen Dai
    Commented Jun 12, 2022 at 13:43

3 Answers 3

8
$\begingroup$

The Attribute Statistics node is lacking an index output for things like the min/max values. Here's a technique i use frequently based on the Attribute Transfer node:

Basic min/max finding:

Grouped min/max:

  1. For the basic "Find index of min/max": Arrange points on the X axis using the search value. Subtract the minimum value so they all start at x = 0 (this also works for negative values).enter image description here
  2. Then use Transfer Attribute to find the closest point to (0,0,0). Since this will be the point with the smallest search value, we can use this to get the index attribute of that point. Notice the explicit Combine Vector input node, this is needed because we need to override the default input of Source Position (which would be the position of any point for which we evaluate this field).enter image description here
  3. This setup can return the maximum value as well by simply using Max output of the statistics node.

The technique can be extended to search in multiple sub-groups simultaneously. For that i separate the point group by spacing them out on the Y axis, in addition to the original X axis sorting.enter image description here The purpose of the spacing is to avoid accidentally getting the closest point from a different group. The statistics node's Range output is useful for that, i multiply it by 2 to be on the safe side.enter image description here In the attribute search the source positions are then similarly spaced out along the Y axis, to find the closest point in each group. I use a separate input value for this, which makes it easier to pick a single group or map min/max values from a different geometry. enter image description here One caveat: If a group is empty, this method will just pick the closest point from a neighboring group. You can add a final distance check to see if the nearest point is closer than the Y axis spacing to handle this case if necessary.

EDIT Here's a concrete solution for finding the longest section within each spline of a curve object:

First, lets compute the actual section lengths (point to point). This is more complicated than one might think, because if we just go to the next point it will jump to the next spline at the end and give us negative section lengths. I made a little utility node group to compute this.

enter image description here

Now we could use the attribute transfer technique to compute the longest section, grouped by spline index, but there are a few more hurdles to overcome.

First we need to compute the index of the spline for each point. Best way i found is to use the Index input node and capture it on the spline domain. When we then use this attribute for points it will get transferred automatically, so each point uses the spline index we captured. Call it a "domain transfer".

enter image description here

Next, we have to modify the min/max node group a bit. The version i made above searches for the minimum value, so we have to change it to using the maximum value.

Since we using curves we also have to fix the problem that "Transfer Attribute" only works on meshes. The node will show a little error icon:

enter image description here

To fix this we can set the curve resolution to 1 and then convert to points. We only need this during the search, it won't affect the output geometry.

enter image description here

And that, at long last, gives use the desired max length section index. Phew!

enter image description here

$\endgroup$
4
  • $\begingroup$ Great answer ‼️+1 $\endgroup$
    – Chris
    Commented Jun 12, 2022 at 11:55
  • $\begingroup$ (deleted my last comment due to me looking at an incorrect blend file; the group method works, accepting this answer) $\endgroup$
    – Zhen Dai
    Commented Jun 12, 2022 at 15:16
  • $\begingroup$ That's ok, my group was quite generic. Curves add other complications that don't really have to do with the searching bit, i've added another demo files that handles this particular case. $\endgroup$
    – user436
    Commented Jun 12, 2022 at 15:24
  • $\begingroup$ Thx Lukas, the third example clears it up a lot, my main problem was the index mismatch between different domains, it was not clear which domain I should capture my attributes in (such as edge length and segment length); normally we capture in edge domain but it won't work with this approach. $\endgroup$
    – Zhen Dai
    Commented Jun 12, 2022 at 16:33
1
$\begingroup$

enter image description here

here is a simple version using statistics node to get the longest edge with compare float.

https://blend-exchange.com/b/gbYOxbe5

$\endgroup$
0
$\begingroup$

you can use this node setup, to get the index:

enter image description here

To make the edge "visible", i added the delete geometry node to the tree. So if you unmute this node, you can "see" which edge it is. But if it is unmuted, you won't see it in the spreadsheet editor - of course - because it is deleted.

$\endgroup$
2
  • $\begingroup$ Difficulty here is how to get a single index value, instead of an attribute that only says if a value matches the minimum. You could follow this up by a Statistics node that sums up a value: index if value == min else 0. The outputs of the statistics node are all single values, which are compatible with any geometry. $\endgroup$
    – user436
    Commented Jun 12, 2022 at 11:56
  • $\begingroup$ Yes, you are right! I am still learning….😉 $\endgroup$
    – Chris
    Commented Jun 12, 2022 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .