What's wrong with my Vex?

   1297   4   1
User Avatar
Member
381 posts
Joined: 11月 2016
Offline
My prims have a ID attribute. I also have a uniqueIDs detail attribute which is an array of all unique values of @ID. I'm trying to create a group which will contain a single primitive of each unique @ID value.

In a 'for each prim' loop, I use the following vex in a prim wrangle:

int uniqueIDs[] = detail(0, 'uniqueIDs', 0);

if(removevalue(uniqueIDs, i@ID)){
    i@group_unique = 1;
    setdetailattrib(0, 'uniqueIDs', uniqueIDs);
    }

No luck, all prims end up in my group, and a single ID value is removed from my array. Any ideas? Or a simpler way to do it?
User Avatar
Member
8506 posts
Joined: 7月 2007
Offline
you should be able to run this on all your prims (not within foreach) in a prim wrangle:
int prim = findattribval(0, "prim", "ID", i@ID, 0);
i@group_unique = prim == @primnum;
which would find the first primitive of the same ID and if it's the same as current it'd be groupped
if you also want the detail attrib with all those prims you can do detail wrangle afterwards
i[]@uniqueIDs = expandprimgroup(0, "unique");
or if you want even extend the same prim wrangle
int prim = findattribval(0, "prim", "ID", i@ID, 0);
if (prim == @primnum){
    i@group_unique = 1;
    int prima[] = array(prim);
    setdetailattrib(0, "uniqueIDs", prima, "append");
}
Edited by tamte - 2021年2月25日 11:31:09
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
381 posts
Joined: 11月 2016
Offline
That works great tamte, thank you!

In case you have a few minutes, could I ask you if you might have an idea what was wrong in my setup?
User Avatar
Member
8506 posts
Joined: 7月 2007
Offline
what makes it not work for your approach is using for loop to iterate over primitives which creates several issues
- foreach loop in that mode merges individuals polygons in the end, which makes merging Detail attributes ambiguous and only one will be taken
you'd have to run over your whole geo in Feedback mode and limit your wrangle on only for a single prim based on iteration to get expected result, but that'd be way overcomplicated way to achieve what Wrangle does by default

- additionally foreach loop over primitives will split your geo into individual prims, which may change it's topology if they were fused before and may not be desirable
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
381 posts
Joined: 11月 2016
Offline
Makes sense, thank you!
  • Quick Links