Sort Prims by Connectivity/Distance

   898   2   2
User Avatar
Member
33 posts
Joined: Nov. 2019
Offline
Hi,

I have s random primids of an object and I want to sort my prims ids based on connectivity/distance from a starting prim.


I want to sort prims like below:



My current setup:


I started with this vex code:

i@prims_nb = polyneighbours(0, 0);

for (int i =0;len(@prims_nb)>i;i++){
if (@primnum == @prims_nb && i@done !=1) {
i@done = 1;
i@primid = i+1;

}
}

/////

for (int i =0;len(i@prims_nb)>i;i++){

i@prims_nb2 = polyneighbours(0, @prims_nb);

if (@primnum == @prims_nb2 && i@done !=1) {
i@done = 1;
int prvprimd = prim(0,"primid",@prims_nb);
i@primid = prvprimd+i+1;

}
}

Thanks
Edited by seeplus - Aug. 18, 2022 05:08:32

Attachments:
ReorderPrimsByLocation.hip (244.4 KB)
Sort.jpg (95.4 KB)
Current Set Up.jpg (66.4 KB)

User Avatar
Member
4495 posts
Joined: Feb. 2012
Offline
Hi,

You can easily do this using Group Expand SOP -> Flood Fill and Step Attribute turned on and then use this step attribute in Sort SOP -> By Attribute (step).
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
33 posts
Joined: Nov. 2019
Offline
It works as I needed, thanks animatrix. I always like easy, yet efficient solutions.
  • Quick Links