Search - User list
Full Version: vex usd_childpath()
Root » Solaris and Karma » vex usd_childpath()
marcosimonrbl
Hi,

I noticed there's a usd_parentpath() function but no usd_childpath()/usd_childrenpaths() function. I'm guessing this has to do with the wrangle being multithreading safe, but how would I go about the following problem otherwise:

All children prims hold an attribute (like polygon count) and I want to sum those up and write the sum as an attribute on the parent primitive.
rafal
I've added an RFE for the `usd_childrennames()` VEX function.

If you know the children names, you can form the child path by appending "/" and a child name to the parent's path.

Otherwise, as a workaround for this task, you can try the Python LOP.

EDIT: RFE number is 116741
marcosimonrbl
Cool!
Yeah we worked around with python - In general I prefer vex though, thanks for the RFE
goldleaf
Another alternative approach could use two wrangles. The first would run on each mesh prim, and put the count value in a unique attribute on an ancestor primitive. Then the second wrangle would iterate over those ancestor prims, and sum the values together.

First wrangle (here we're counting the meshes on the "grandparent" prim):

// Get Point Count
vector pts[] = usd_attrib(0, @primpath, "points");

// Get mesh prim's name, as well as parent prim's name, to
// place a unique attribute on the "grand-parent" prim.
string parent = usd_parentpath(0, @primpath);
string grandparent = usd_parentpath(0, parent);

// Add and set counter attribute on the grandparent prim
string attrib = "counter_"+usd_name(0,parent)+"_"+usd_name(0, @primpath);
usd_addattrib(0, grandparent, attrib, "int");
usd_setattrib(0, grandparent, attrib, len(pts));


Second wrangle:
string attribs[] = usd_attribnames(0, @primpath);
string prefix = "counter_";
int total = 0;

foreach(string attr; attribs)
{
    if (startswith(attr, prefix)==1)
    {
        total += usd_attrib(0, @primpath, attr);
    }
}
i@totalMeshCount= total;

Might be useful until getting child prims is possible!
tamte
Would also be cool if ust_setattrib() supported modes like "add", "append", ... Like setattrib() functions do
Then the second wrangle could be avoided in cases like this
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB