How to procedurally set parent for joints?

   349   10   3
User Avatar
Member
15 posts
Joined: 1月 2013
オフライン
Hello

I would like to parent a lot of joints to specific joint based on point attribs. Can I do that?
I saw somewhere that setting parent attrib to ptnum of parent can work. But its not working on my side, maybe I am missing something there.

Thanks
User Avatar
Member
691 posts
Joined: 8月 2019
オフライン
Too little information... at which level? SOP Kinefx skeleton? APEX?

its not working on my side

http://www.catb.org/~esr/faqs/smart-questions.html [www.catb.org]
User Avatar
Member
15 posts
Joined: 1月 2013
オフライン
SOP KineFX skeleton. No APEX.

As shown below, I am looking to parent all floating bones to one bone.
And it needs to be done procedurally as the config of floating bones can change, including count and ptnum.

Edited by fragmentzero - 2025年9月26日 13:31:09

Attachments:
skeleton_parenting.png (645.5 KB)

User Avatar
Member
9269 posts
Joined: 7月 2007
オンライン
you can use Parent Joints SOP, where you can specify joint and parent groups

this offers certain level of proceduralism as the groups can be specified using attribute values
so if you know maximum number of parent bones and its a reasonable number you can use provided UI, however if you need large number of parent bones, you may want to either use additional for loop or have a look inside how it works to rebuild a custom version
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
15 posts
Joined: 1月 2013
オフライン
I see.
So its not as simple as just @parent = "ptnum of parent" in Point Wrangle.
I do want to avoid Parent Joints SOP, so I'll try out the 2nd/3rd approaches.

This is my first foray into KineFX tools, which I am pairing with Control Rig in Unreal. So trying to keep both ends as procedural as possible.

Thank you
User Avatar
Member
9269 posts
Joined: 7月 2007
オンライン
no need to avoid it since as I said you can run it in for loop for each unique value of your i@parent attrib

but if you want pure VEX solution, here is something ripped from inside of Parent Joints and adjusted to be able to use your i@parent attribute, just make sure any joint that you dont want to parent has @parent=-1

#include <kinefx_hierarchy.h>

int unparent_on_cycle = chi("unparent_on_cycle");

int joints[] = expandpointgroup( 0, "@parent!=-1" );

int success = 1;
int failed[];

foreach ( int joint; joints ){
    int parent = point( 0, "parent", joint );
    int _success = setparent(0, joint, parent, unparent_on_cycle);
    if(!_success)
        append(failed, joint);
    success &= _success;
}

if(!success)
    warning("One or more parenting operations has failed.\nPoints %d", failed);
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
15 posts
Joined: 1月 2013
オフライン
That worked like magic.
Thank you very much.


Attachments:
Before.png (719.4 KB)
After.png (379.8 KB)

User Avatar
Member
15 posts
Joined: 1月 2013
オフライン
Looks like this ended up in a cycle though.
Trying to traverse through the points myself.


Attachments:
Cycle_detected.png (111.7 KB)
Graph.png (163.9 KB)

User Avatar
Member
9269 posts
Joined: 7月 2007
オンライン
did you check Unparent on Cycle?
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
8062 posts
Joined: 7月 2005
オフライン
I wouldn't expect that code to produce a cycle though unless one of the child points is actually the parent itself. So maybe inside the loop, it just needs to continue/skip if joint == parent.
User Avatar
Member
15 posts
Joined: 1月 2013
オフライン
This got fixed by running vex in detail.
I guess doing it in point wrangle was causing the cycle issue as its looping over all joints (points) per point.

Its working without an issue now, tested with Rig Pose.

Thank you
  • Quick Links