// SCALE THE SKELETON BY .1 .1 .1 // Program: // This file contains two functions for you to call: // 1. attach(using_local_bodies, using_wrist_hack). // This script attaches a set of locators from a .v file to a skeleton from a .vsk (use the vicon importer). // If using_wrist_hack is set to "1", the script with insert a wrist and give it the "twist" from the radius. // NOTE: this script scales the skeleton by .1 // 2. eulerfilter(). This may clean up some of the animation curves in global-body .v files. Call it after baking the keys to the joints. // // Usage: // 1. Import .vsk. Import .v // 2. Select skel root and locator root (parent). Source script. // 3. Run "attach(using_local_bodies, using_wrist_hack)" in the script editor to attach the skeleton to the locators. // Your three choices are: // attach(1,0) - local bodies, no wrist hack // attach(0,0) - global bodies, no wrist hack // attach(1,1) - global bodies, with super-cool wrist-twist extravaganza. // Don't try the fourth option because it won't work and your computer may explode. Maybe. // Other Usage: // 1. Source script. Run "eulerfilter" in script editor. // // Author: // Ronit Slyper, rys@cs.cmu.edu // // Date: // February 15, 2007 // ====================================== ATTACH JOINTS TO LOCATORS CODE =============================================== global proc attach(int $using_local_bodies, int $using_wrist_hack) { // grab the selected nodes $sel = `selectedNodes`; string $jointroot = $sel[0]; // get the skeleton root string $locatorroot = $sel[1]; // get the locator root $m = "Got jointroot " + $jointroot + " and locatorroot " + $locatorroot + "\n"; print $m; // scale the skeleton $c = "setAttr " + $jointroot + ".scale .1 .1 .1"; eval($c); // wrist hack if ($using_wrist_hack==1) { wrist_hack($using_local_bodies); select $jointroot $locatorroot; } // get a list of all the joints string $alljoints[] = `listRelatives -fullPath -type joint -children -allDescendents $jointroot`; // hook up each joint for ($joint in $alljoints) { // if wrist_hack has been implemented, // DO NOT attach the radius, wrist, and radiusControl joints - // they are the wrist_hack's responsibility if ($using_wrist_hack==1) { if (`joint -query -name $joint`== "lradius") { print "Found lradius! Yeah!\n"; continue; } else if (`joint -query -name $joint` == "lwrist" ) { print "Found lwrist! Yeah!\n"; continue; } else if (`joint -query -name $joint` == "lhand" ) { print "Found lhand! Yeah!\n"; continue; } else if (`joint -query -name $joint` == "lradiusControl" ) { print "Found lradiusControl! Yeah!\n"; continue; } else if (`joint -query -name $joint`== "rradius") { print "Found rradius! Yeah!\n"; continue; } else if (`joint -query -name $joint` == "rwrist" ) { print "Found rwrist! Yeah!\n"; continue; } else if (`joint -query -name $joint` == "rhand" ) { print "Found rhand! Yeah!\n"; continue; } else if (`joint -query -name $joint` == "rradiusControl" ) { print "Found rradiusControl! Yeah!\n"; continue; } } // clear selection select -cl; // construct the locator name $locator = `joint -query -name $joint`; $locator = $locatorroot + "|" + $locator; if ($using_local_bodies==1) { $locator = $locator + "_local"; } // print out a little debug $m = "Selecting locator " + $locator + "\n"; print $m; if (!objExists($locator)) { $m = "Skipping joint with no locator " + $locator + "\n"; print $m; continue; } // select the locator and the joint select $locator; select -add $joint; // constrain/connect attributes of the locator to the joint if ($using_local_bodies==1) { $j = "connectAttr -f " + $locator + ".rotate " + $joint + ".rotate"; eval($j); $j = "connectAttr -f " + $locator + ".translate " + $joint + ".translate"; eval($j); } else { pointConstraint; orientConstraint; } } } // ============================ EULER FILTER CODE =========================================== // For use with global-body v files. // Optional: Run this at the end, after baking the simulation, to (somewhat) clean up the animation curves, // which have significant Euler-angle-hitting-180 issues global proc eulerfilter() { select -all; string $selection[] = `ls -sl -o`; for($obj in $selection) { filterCurve $obj.rotateX $obj.rotateY $obj.rotateZ; } } // =============================================== WRIST HACK CODE =========================== // Usage: // select the skeleton root and the locator root (parent). Source this script and run wrist_hack() // The result should look weird: the wrist has popped out of the skeleton. Good. // Prerequisite: // Skeleton has a "radius" and a "humerus". global proc wrist_hack(int $using_local_bodies) { // get the selection, which MUST be the skeleton root and locator root $sel = `selectedNodes`; string $jointroot = $sel[0]; // get the skeleton root string $locatorroot = $sel[1]; // get the locator root // for convenience later, find the fully-qualified joint names by looping through all joints string $lradius_joint, $lhumerus_joint, $lhand_joint; string $rradius_joint, $rhumerus_joint, $rhand_joint; string $alljoints[] = `listRelatives -fullPath -type joint -children -allDescendents $jointroot`; for ($joint in $alljoints) { $temp = `joint -query -name $joint`; if ($temp=="lradius") { $lradius_joint = $joint; } else if ($temp=="lhumerus") { $lhumerus_joint = $joint; } else if ($temp=="lhand") { $lhand_joint = $joint; } else if ($temp=="rradius") { $rradius_joint = $joint; } else if ($temp=="rhumerus") { $rhumerus_joint = $joint; } else if ($temp=="rhand") { $rhand_joint = $joint; } } $lradius_locator = $locatorroot + "|lradius"; $lhand_locator = $locatorroot + "|lhand"; $rradius_locator = $locatorroot + "|rradius"; $rhand_locator = $locatorroot + "|rhand"; if ($using_local_bodies==1) { $lradius_locator = $lradius_locator + "_local"; $lhand_locator = $lhand_locator + "_local"; $rradius_locator = $rradius_locator + "_local"; $rhand_locator = $rhand_locator + "_local"; } // For global bodies, we create a "shadow" radius joint, which then feeds its relative rotations // to the radius and wrist if ($using_local_bodies != 1) { // create the radiusControl joint at the same place as the radius joint // left radiusControl ... $translation = "getAttr " + $lradius_joint + ".translate"; vector $p = eval($translation); select $lhumerus_joint; joint -name lradiusControl -relative -position ($p.x) ($p.y) ($p.z); // ... and right radiusControl $translation = "getAttr " + $rradius_joint + ".translate"; $p = eval($translation); select $rhumerus_joint; joint -name rradiusControl -relative -position ($p.x) ($p.y) ($p.z); // constrain the radiusControl joint to the radius locator select $lradius_locator lradiusControl; pointConstraint; orientConstraint; select $rradius_locator rradiusControl; pointConstraint; orientConstraint; // get the hand translation. // create a wrist joint halfway between the radius joint & hand joint // left wrist ... $translation = "getAttr " + $lhand_joint + ".translate"; $p = eval($translation); insertJoint $lradius_joint; rename lwrist; joint -edit -relative -position (($p.x)/2) (($p.y)/2) (($p.z)/2); // ... and right wrist $translation = "getAttr " + $rhand_joint + ".translate"; $p = eval($translation); insertJoint $rradius_joint; rename rwrist; joint -edit -relative -position (($p.x)/2) (($p.y)/2) (($p.z)/2); // set up the connections: // from radiusControl z -> wrist z // from radiusControl x & y -> radius x & y // the xform on the rotateOrder allows the rotations to be split up this way // left setup ... select lradiusControl; xform -p true -rotateOrder "zxy"; connectAttr -f lradiusControl.rotateZ lwrist.rotateZ; $c = "connectAttr -f lradiusControl.rotateX " + $lradius_joint + ".rotateX"; eval($c); $c = "connectAttr -f lradiusControl.rotateY " + $lradius_joint + ".rotateY"; eval($c); $c = "connectAttr -f lradiusControl.translate " + $lradius_joint + ".translate"; eval($c); $lhand_joint = $lradius_joint + "|lwrist|lhand"; select $lhand_locator $lhand_joint; pointConstraint; orientConstraint; // ... and right setup select rradiusControl; xform -p true -rotateOrder "zxy"; connectAttr -f rradiusControl.rotateZ rwrist.rotateZ; $c = "connectAttr -f rradiusControl.rotateX " + $rradius_joint + ".rotateX"; eval($c); $c = "connectAttr -f rradiusControl.rotateY " + $rradius_joint + ".rotateY"; eval($c); $c = "connectAttr -f rradiusControl.translate " + $rradius_joint + ".translate"; eval($c); $rhand_joint = $rradius_joint + "|rwrist|rhand"; select $rhand_locator $rhand_joint; pointConstraint; orientConstraint; } else { // For local bodies, we create a "shadow" radius locator, which then has its rotation order changed // and feeds its relative rotations to the radius and wrist // Create the wrist halfway between the radius and hand // Here it's simple to use the local locator position. // left wrist ... $translation = "getAttr " + $lhand_locator + ".translate"; vector $p = eval($translation); insertJoint $lradius_joint; rename lwrist; joint -edit -relative -position (($p.x)/2) (($p.y)/2) (($p.z)/2); $lhand_joint = $lradius_joint + "|lwrist|lhand"; // ... right wrist $translation = "getAttr " + $rhand_locator + ".translate"; vector $p = eval($translation); insertJoint $rradius_joint; rename rwrist; joint -edit -relative -position (($p.x)/2) (($p.y)/2) (($p.z)/2); $rhand_joint = $rradius_joint + "|rwrist|rhand"; // Create a radiusControl locator and hook it up (similarly to the global locator code above). // The xform does not work on the radiusControl when its attributes are hooked up to the radius locator directly, // so instead I point & orientConstrain the radiusControl to the radius locator. // The point of the hand code is not to attach the hand translate directly, but to set it to half what it was, // because the wrist is now in the middle. // left setup ... select $locatorroot; spaceLocator -name "lradiusControl" -p 0 0 0; select $lradius_locator lradiusControl; pointConstraint; orientConstraint; select lradiusControl; xform -p true -rotateOrder "zxy"; connectAttr -f lradiusControl.rotateZ lwrist.rotateZ; connectAttr -f lradiusControl.rotateX lradius.rotateX; connectAttr -f lradiusControl.rotateY lradius.rotateY; connectAttr -f lradius_local.translate lradius.translate; connectAttr -f lhand_local.rotate lhand.rotate; $t = $lhand_joint + ".translate"; setAttr $t (($p.x)/2) (($p.y)/2) (($p.z)/2); // ... and right setup select $locatorroot; spaceLocator -name "rradiusControl" -p 0 0 0; select $rradius_locator rradiusControl; pointConstraint; orientConstraint; select rradiusControl; xform -p true -rotateOrder "zxy"; connectAttr -f rradiusControl.rotateZ rwrist.rotateZ; connectAttr -f rradiusControl.rotateX rradius.rotateX; connectAttr -f rradiusControl.rotateY rradius.rotateY; connectAttr -f rradius_local.translate rradius.translate; connectAttr -f rhand_local.rotate rhand.rotate; $t = $rhand_joint + ".translate"; setAttr $t (($p.x)/2) (($p.y)/2) (($p.z)/2); } }