Sorting and keep only the first item in geometry nodes

Hello !

I’m running into a problem a bit similar to my previous question but with a little twist :

Thanks to a post by @moshus, I discovered today a short nodegroup that you can grab here :
https://archive.blender.org/developer/F13120865/gn_sort.blend

The post from ChristopheMermoud !

This is working like a charm , looks like a super useful tool to have !

Now here is my problem :
I have different islands, I want to sort their point by some field, and I want to keep the first point of
the sorted list of each island. And I can’t figure out a way do to that.

I’ve build a simple test scene where each island is a plane, and I sort them by their X position.
My real scene is a bit more complex, there is an arbitrary number of points per island, ( it’s only points, not faces, edges) …
And I don’t sort them by their location.

So , my original mesh :

Sorting seems to work :

Now how would you manage to keep the first point of the list of each island ? ( and delete the others) Which in this case is for each island the point with the lower X value.

I’m pretty sure this shouldn’t be that complex, yet I can figure out anything …

Here is a test.blend :
sort_and_delete.blend (207.5 KB)

Thanks a lot in advance !

2 Likes

Use an Integer Accumulator set to 1 which takes the island index as Group Index and capture the trailing value on each point - this will generate indices starting at 0 for each island… you can then just delete points where this custom index isn’t 0.

3 Likes

Hello !

Thanks a lot ! I think I tried this one but it didn’t work because of the permuted index…

It might be not clear :

say the correct index I want to keep is 3.
the index 0 stay the same, but the permuted index will have 3 as a first value.

I pretty sure doing what you said will still keep the index 0 instead of the 3.

I’ll try again in a few hours to be sure !

You’ll need to do the Accumulation and Capture after the sort… :man_shrugging:

2 Likes

Ok I didn’t used capture , I’ll try again and report !
Thanks a lot !! You always save me !

1 Like

Have a look at the Group Attribute Statistic Node File. There i use a Nodegroup for this usecase:

or in this example

By the way i would use the group (topology) sort from the Group Attribute Statistic Node, which does essentially the same thing but is way faster and has a higher float precision. Have build that after i asked Christophe if i could use his search node for the Group Attribute Statistic Node. And he pointed me to the fact that the new (at that time) topology nodes could be used to implement the sort more efficiently.

3 Likes

Thanks a lot ! I’ll look into that as well !
I think I went too fast since I looked into that post to find about the sort node !

Thanks again for taking time to explain !

1 Like

Hey !

So I’ve tested your idea but I might have missed something !

It works if I translate the points :

But if I keep the object untouched I get that result :

I’ll try moshus’s solution and report here, at least I feel a bit relieved that it’s not an easy solution :smiley:

Realized that for for Float attributes, i have the accidentally stripped the “bag to group set node” from the file because i got over the upload limit of 5 MB. And removed examples to reduce the file size, while just compressing would have been the way smarter. :sweat_smile:

Here with the example for Floats:
group_attribute_statistics_FV.zip (640.7 KB)

Sorry for the circumstances, when i find time i will add the other examples to the original Thread. As i think this stuff could really benefit from better explanation.

Edit: The files are now updated (here and in the original thread). They now include the old examples. And a fix for min indices on the point domain (Sorry again to everyone who may have been send into the wrong direction).

2 Likes

Are you kidding !

That’s super kind to you to help me, that’s really appreciated !
I started to look at the files, it’s quite impressive !

For now I’m not 100% sure how to solve my actual problem yet, but I’ll keep testing !
In your example, you create the cubes and put them at the right place at the end of the tree.
Where in my case it would be simpler to delete the unwanted points. I don’t get how to do that yet, but that’s probably because I miss a bit of practice with your groups.

I’m not sure this is going to help, but here is basically my actual problem :


This is an island and the grey elements are castles.
The red spheres are the entrances of the castles and that’s what I’m trying to improve.

To place these entrance and make sure they aren’t at the edge of the island or just in front of another castle, I create these curves in green, and remove some of them based on different rules.

At the end I’m still left with a bunch of curves, and I initially kept the first of each groups ( castles).
It worked but sometimes it created weird stuff visually.

Now what I want to do is to add a rule to make sure the door is pointing toward the center of the island. I think it will work much better especially since I plan to add roads that goes from one castle to the other.

I think I managed to get the sorting done, and now I’m stuck with the removal :smiley:

Silly thing is that I wanted to work on these roads and I’m stuck on a tiny detail with these entrances since yesterday :smiley:

I’m questioning if this is the way to go and if I should look for a simpler solution :smiley:

Thanks for reading and I’d be really happy to have your thoughts on that !

1 Like

Okk !

I managed to solve my test case :

From there I should manage to get the final working !
It was quite straightforward in the end, but I think I get confused by trying different things !

The classic trying to take shortcuts to eventually spend 10x the time it would took normally !

So, again thanks a lot for the help and providing these grouped statistics nodes ! So cool and useful !

sort_and_delete_solved.blend (371.9 KB)

2 Likes

hah, that is very useful. Thanks sozap and whoever contibuted to the solution.

2 Likes

Yes indeed !

@moshus’s groups are amazingly useful ! It’s hard to believe how much technicalities are involved in such a mundane task :smiley: But opening that grouped statistics is quite an experience :smiley:

Hopefully loops might make these operation much simpler but in the meantime I think I’ll use these groups quite a lot !

2 Likes

yeah, normally I study nodegroups to understand, but in this case nope, I will just use it :joy:

loops would be great.

2 Likes

Had the same feelings when trying to understand, what was going on the original sort group from Christophe. At that time Jaques implementent the first visual feedback of attributes. That helped a lot to understand what was going on there. And as a consequence exploring and debugging node groups started to become more fun.

PS, Would love to see those castles come alive!

3 Likes

Me too… Sorry, could you not delete by the permuted index? Then you would not need the accumulator…

Just a suggestion: Would it make sense to start with the roads and end up with the doors?
Starting with some central point you could use shortest paths to create the road curves - terminating at random points on the edges of your “island” - then use these same points to be the doors - then generate the castle around the door… So, what I’m suggesting is to take your idea for generating the castles and flip the order of generation… Donno if that would work but it may be worth considering.

They are, right? Johnny Matthews had a native version implemented back in Dec 2021 and for some reason its still not been merged in :cry:

3 Likes

Hey !

I’m not sure how, I tried a few things … The permuted index is like 7,2,8,4,3,1… I didn’t manage to find a way to keep the first one of each group but since I understand half of what I’m doing… maybe it’s possible :smiley:

That’s quite interesting ! Right now the castles and the overall shape of the island are the two things we can setup manually by blocking out rough 3D shapes, I like to keep it that way so at least there is a bit of artistic control. But yeah if I had to start over I’d probably build it as you suggest.
Or I’d do something with even more control, and less automation…
I think I could have been much more organised from the start, but that’s probably what it takes to learn to do things the right way :smiley:

And yes ! I remember the patch from Johnny Matthews, I can’t recall why it didn’t work in the end, it’s too bad that some really important features can’t be grouped by default. Anyway thanks to the community powerful tools like this ones really help a lot to do even more crazy stuff !

2 Likes

Hahaha ! Yeah sure visual feedback is soo helpful, I also looked at Christophe ones, even with viewer, spreadsheet courage and coffee, frankly I don’t know what of these two gif express the best my feelings when opening these groups :

or that :

Suspicious Louisa Krause GIF by The Girlfriend Experience

I’ll send you a render so you can see how it looks, I wait a little more before posting publicly !

4 Likes

Me also too again … and of course @zeroskilz is right it should be possible by the permuted index … but while checking it and trying to do it i found i broke the permuted index. I do not transfer them from the domain specific groups to the general case at all.

Will fix that when i find time (not atm). You could pick the point domain specific group out of the general one and use that index for the meantime.

2 Likes

Ok this statement was not correct. Have Forgotten that i once stripped the permuted index from the group. Did that to reduce the complexity of it. And because no good use case came to my mind (only for sorting, where i would use the builtin Topo Group Sort node only. Which still gives you the permuted index). So the following output should not exists it was only forgotten to be removed:
Attribute_Stat_Group_fix_permuted

But still have broken something during that move. I accidently plugged the permuted index in the other indicies Field (“indicies min”). Which should just hold the same index for each group element pointing to the point with the minimum (for that group).

That output is meant to be used to get the the group minimas by index. This avoids ambiguties which could occure if you do it like Sozap did above. When you have group elements at the same spot. See how selecting by index is done below:

Sorry, again if that issue caused some trouble. Updated The file i linked above and in the original Thread. And added the examples back to the file.

1 Like