[SOLVED] Sorting by multiple attributes

   2679   4   1
User Avatar
Member
39 posts
Joined: Dec. 2018
Offline
Hi everybody,

I'm trying to understand what the Sort Geometry Node's help [www.sidefx.com] intends when it states:

By attribute
Uses the value of an attribute as a “key value” to sort by. For Vector3/Vector4 attributes, the node can only sort by a single component at a time. However, because the Sort SOP uses a stable sort, you can wire together multiple Sort nodes to sort by multiple components, or multiple attributes.
(the emphasis is mine)

Specifically I'd like to sort some points first according to a float attribute @a and then, when multiple points have the same @a value, according to a second float attribute @b.

How can this be done in line with what the help says?

Kind regards,

Manu
Edited by manu3d - July 23, 2019 07:21:19
User Avatar
Member
9243 posts
Joined: July 2007
Offline
manu3d
How can this be done in line with what the help says?
Sort by “b”
then Sort by “a”
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
39 posts
Joined: Dec. 2018
Offline
Hi Tomas,

thank you for your reply. What seems to be the obvious way for me to do it, in line with what you say, doesn't seem to work - see the simple attached scene.

What you will see is that the points can be (mentally) arranged by distance from the center, in four concentrical circles. What I am aiming for is for the point numbers in each circle to be consecutive AND radially sorted: i.e. the innermost circle should have points indexes from 0 to 11, increasing clockwise for example, the next circle from 12 to 23 also increasing clockwise, and so on.

Is this possible?

Kind regards,

Manu

Attachments:
SortingByTwoAttributes_v001_notWorking.hipnc (80.9 KB)

User Avatar
Member
9243 posts
Joined: July 2007
Offline
1. as I said sort by “b” first then by “a” so in your case by angle first then by radius
2. only if your radius have same values it will keep the CW ordering for points with the same value
with floats its deceiving as spreadsheet is rounding the values so they may seem the same, but it's minimal chance they actually are so you need to round them to make sure

Attachments:
SortingByTwoAttributes_v001_fix.hipnc (81.6 KB)

Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
39 posts
Joined: Dec. 2018
Offline
A-ha! I had tried changing the order of the sort nodes, but what got me is what you mention in point 2: the points -look- to be at the same distance from the center, but due to unseen differences they aren't and that was fooling the radius sort.

Once I understood the problem I fixed the polar radius attribute with floor() rather than the rint() you used, like so:

f@polarR = floor(sqrt(@P.x*@P.x+@P.z*@P.z)*100);

but it really is just doing the same thing.

Thank you Tomas! You were very helpful!

Kind regards,

Manu
  • Quick Links