Creating a collection in vex

   Views 384   Replies 1   Subscribers 1
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
I'm trying to figure out how to make a collection of a subset of instances in an attrib wrangle...

I have it mainly working except for the logic part. This does nothing, but I know it's not totally broken because if I manually append a primpath to the includes array, that works...

string includes[] = {};
string collectionpath = usd_makecollectionpath(0, "/scene/geometry/tree_instancer", "everyOtherTree");

string name = usd_name(0, @primpath);
int num = opdigits(name);
if(num % 2 == 0) append(includes, @primpath);

usd_setcollectionincludes(0, collectionpath, includes);

On the other hand this works as I would expect - every other prim receives a value of 1, the others -1:
int var = -1;

string name = usd_name(0, @primpath);
int num = opdigits(name);
if(num % 2 == 0) var = 1;

i@primvars:num = var;

both are operating on the same set of prims - /scene/geometry/tree_instancer/tree*

Can anyone tell me where I'm going wrong?
User Avatar
Member
102 posts
Joined: 5月 2013
Offline
In case it's useful to anyone I realised my approach was wrong in that my attrib wrangle was running over a set of prims, so for each iteration it was setting the collection includes array correctly but that would contain either 1 path or be empty and on the last iteration it was empty.

In order to get it to work I ran it over the instancer itself and looped over the children so append their paths to the array.

string includes[] = {};

string children[] = usd_childnames(0, @primpath);
foreach(string c; children){
    string c_path = @primpath + '/' + c;
    if(usd_typename(0, c_path) == "Xform"){
        string name = usd_name(0, c_path);
        int num = opdigits(name);
        if(num % 2 == 0) {
            append(includes, c_path);
        }
    }
}
string collectionpath = usd_makecollectionpath(0, @primpath, "everyOtherTree");
usd_setcollectionincludes(0, collectionpath, includes);
  • Quick Links