//////////////////////////////////////// // defpose.mel : handle postural attributes //////////////////////////////////////// setAttr "l_shoulder.rotateZ" 0; setAttr "r_shoulder.rotateZ" 0; global string $g_postureJnts[]; $g_postureJnts = { "skullbase", "vl5", "sacroiliac", "l_hip", "r_hip", "l_ankle", "r_ankle" }; global string $g_posture[]; $g_posture = { "backArch:skullbase;-10@0@15,vl5;20@0@-20,sacroiliac;-20@0@6,l_hip;20@0@2,r_hip;20@0@2,l_ankle;0@0@-5,r_ankle;0@0@-5", "pelvicTilt:sacroiliac;-20@0@35,l_hip;25@0@-40,r_hip;25@0@-40,l_ankle;-4@0@8,r_ankle;-4@0@8" }; //////////////////////////////////////// // search LHSs of base posture list global proc int isaPostureJnt(string $name) { global string $g_postureJnts[]; string $item; for($item in $g_postureJnts) { if(strcmp($item, $name)==0) { //print($name+" IS a posture joint\n"); return 1; } } //print($name+" is NOT a posture joint\n"); return 0; } //////////////////////////////////////// proc createPostureJntExp(string $jntName) { global string $g_postureJnts[]; string $exp = "expression -n "+$jntName+"_posture_exp -s \""; $exp += $jntName + ".rotateAxisX = 0;"; $exp += "\";"; //print($exp+"\n"); eval($exp); } //////////////////////////////////////// // subatts should contain a comma separated list of postures to be modified // lo/def/hi should be the influence range of this zero centered parameter global proc appendToPostureExp(string $HL_attrName, string $jnts, string $lo, string $def, string $hi) { //print("HL_attrName: "+$HL_attrName+" jnts: "+$jnts+" lo="+$lo+" def="+$def+" hi="+$hi+"\n"); string $jnt_tokens[]; tokenize($jnts, ",", $jnt_tokens); string $jntStr; for($jntStr in $jnt_tokens) { //print("jntStr="+$jntStr+"\n"); string $tokens[]; tokenize($jntStr, ";", $tokens); string $jntName = $tokens[0]; // sometimes limits encoded with jntname, but if not, use passed values string $limits = $tokens[1]; string $lo2 = $lo; string $def2=$def; string $hi2 = $hi; if(strcmp($limits, "")!=0) { tokenize($limits, "@", $tokens); $lo2 = $tokens[0]; $def2 = $tokens[1]; $hi2 = $tokens[2]; } // build name of previously created expression node string $expNode = $jntName+"_posture_exp"; string $subat = $expNode + ".expression"; // node's attribute to modify string $exp = getAttr($subat); // get the current expression string int $esize = size($exp); // find length of string to hack off end $exp = substring($exp,1,($esize-1)); // hack off ";" // append new HL attribute to expression $exp += " + attrFunc(humanoid_1."+$HL_attrName+", 0, .5, 1, " + $lo2+", "+$def2+", "+$hi2+");"; select -r $expNode; // grab the expression node by name string $cmd = "expression -e -s \"" + $exp + "\";"; // edit its expression //print($cmd+"\n"); eval($cmd); } } //////////////////////////////////////// // Creates a new "high level" humanoid attribute. // Creates or appends to expressions of other humanoid attributes to // drive them with this attribute's value. //////////////////////////////////////// proc createOnePostureAttr(string $defLine) { string $tokens[]; tokenize($defLine, ":", $tokens); string $attrName = $tokens[0]; string $atts = $tokens[1]; string $exp = "addAttr -ln " + $attrName + " -at double -min 0 -max 1 -dv .5 humanoid_1;"; //print($exp+"\n"); eval($exp); $exp = "setAttr -e -keyable true humanoid_1." + $attrName + ";"; //print($exp+"\n"); eval($exp); appendToPostureExp($attrName, $atts, 0, 0, 0); } //////////////////////////////////////// // create all posture attributes and expressions //////////////////////////////////////// proc createPostureExpressions() { global string $g_postureJnts[]; global string $g_posture[]; string $str = "select -r humanoid_1"; eval($str); string $defLine; for($defLine in $g_postureJnts) { createPostureJntExp($defLine); } for($defLine in $g_posture) { createOnePostureAttr($defLine); } } //////////////////////////////////////// global proc setUpBalanceIK() { select -cl; select -r l_hip.rotatePivot; select -add l_ankle.rotatePivot; ikHandle -s sticky -n "l_legIK"; select -r r_hip.rotatePivot; select -add r_ankle.rotatePivot; ikHandle -s sticky -n "r_legIK"; select -r l_ankle.rotatePivot; select -add l_toes.rotatePivot; ikHandle -s sticky -n "l_footIK"; select -r r_ankle.rotatePivot; select -add r_toes.rotatePivot; ikHandle -s sticky -n "r_footIK"; select -r humanoidRoot; expression -s "tz = (l_legIK.tz + r_legIK.tz) / 2.0 + ((((l_footIK.tz + r_footIK.tz) - (l_legIK.tz + r_legIK.tz)) / 2.0) * 0.25);" -o humanoidRoot -ae 1 -uc all; } //////////////////////////////////////// createPostureExpressions(); //setUpBalanceIK(); //////////////////////////////////////// ////////////////////////////////////////