KINEFX Hierarchy "Path" Attribute

   2525   5   0
User Avatar
Member
6 posts
Joined: May 2016
Offline
Hello Magicians, I need to export a hierarchy "path" attribute in the KineFX using the @name attribute. I have created a hierarchy order by the id attribute. How to create a hierarchy "path" attr using "name" attr?

Attachments:
cloth_sim_transfer_v1.hip (592.8 KB)

User Avatar
Member
9271 posts
Joined: July 2007
Offline
since your "hierarchies" are a single primitive lines (no branching and no individual prim segments) you can possibly just do this in Primitive Wrangle:
string path = "";

int pts[] = primpoints(0, @primnum);
foreach(int pt; pts){
    string name = point(0, "name", pt);
    path += "/" + name;
    setpointattrib(0, "path", pt, path);
}

be aware though that some of your curves are reversed so their hierarchy flows bottom to top
Edited by tamte - Jan. 16, 2023 14:19:48
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
84 posts
Joined: July 2018
Offline
I'm not in front of my workstation at the moment, but if you load up the kinefx modules in VEX (start your code with):

#include <kinefx.h>

There's a command called getancestors() that lets you find the point numbers of all ancestors of the input pt number.

int[] getancestors(int geo; int pt; int maxdepth)

From there you can build your string by modifying Tomas' script above.

It's overkill in this case, but the benefit is that it will work in other setups where you have branching.
madebygeoff.com
User Avatar
Member
6 posts
Joined: May 2016
Offline
Thank you guys, all of your helps work like a charm

tamte's script is that's what I want.
getancestors function looks interesting. but I don't know how to use it. I'm still learning...
User Avatar
Member
16 posts
Joined: Nov. 2013
Offline
I just had the same issue. Here's a script using kinefx.h you can put in a point wrangle, assumes you already have the bone names in a name attrib:
#include <kinefx.h>

// Get all parent joints of the current point
int ancestors[] = getancestors(0, @ptnum, 10);

// Create a string array to hold all names in the hierarchy.
// The size is the number of parents plus the current point itself.
string names[];
resize(names, len(ancestors) + 1);

// Loop through the parents and store their names in the array
for(int i = 0; i < len(ancestors); i++) {
    names[i] = point(0, "name", ancestors[i]);
}

// Add the current point's name to the very end of the array
names[-1] = point(0, "name", @ptnum);

// Join all the names in the array into a single string,
// separated by a forward slash. This correctly handles all cases
// and will not produce a leading slash.
s@path = join(names, "/");
User Avatar
Member
1 posts
Joined: Jan. 2019
Offline
Handy script!

I was getting some weirdness in the path order and had to reverse the order of the names, like this-

for(int i = 0; i < len(ancestors); i++) {
int j = len(ancestors)-i;
names = point(0, "name", ancestors);
}

Otherwise very handy - thanks!
  • Quick Links