vex usd_childpath()

   3144   4   1
User Avatar
Member
23 posts
Joined: 9月 2021
オフライン
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.
User Avatar
スタッフ
1471 posts
Joined: 7月 2005
オフライン
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
Edited by rafal - 2021年10月19日 18:11:24
User Avatar
Member
23 posts
Joined: 9月 2021
オフライン
Cool!
Yeah we worked around with python - In general I prefer vex though, thanks for the RFE
User Avatar
スタッフ
4258 posts
Joined: 9月 2007
オフライン
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!
I'm o.d.d.
User Avatar
Member
9281 posts
Joined: 7月 2007
オフライン
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
Tomas Slancik
CG Supervisor
Framestore, NY
  • Quick Links