//////////////////////////////////////// // deformExps.mel: autocreate expressions for deformer attributes //////////////////////////////////////// // names of new humanoid base attributes to create, // and their corresponding lattice ffd's (to change the envelope attribute of) global string $g_baseDeformers[]; $g_baseDeformers = { "r_chest=ffd4", "l_chest=ffd5", "hairTop=ffd1", "hairBack=ffd2", "hairSides=ffd3" }; global string $g_deformAttrs[]; $g_deformAttrs = { "chestSize:r_chest,l_chest", "hairLength:hairTop,hairBack,hairSides" }; //////////////////////////////////////// proc show(string $str, string $val) { print($str + "=" + $val + "\n"); } //////////////////////////////////////// // search LHSs of base deformer list global proc int isaBaseDeformer(string $name) { global string $g_baseDeformers[]; string $item; string $tokens[]; for($item in $g_baseDeformers) { tokenize($item, "=", $tokens); if(strcmp($tokens[0], $name)==0) { return 1; } } return 0; } //////////////////////////////////////// // given base attribute, find its associated ffd proc string findFFD(string $a) { //print("findFFD: "+$a+"\n"); global string $g_baseDeformers[]; string $defLine; string $tokens[]; for($defLine in $g_baseDeformers) { tokenize($defLine, "=", $tokens); if(strcmp($tokens[0],$a)==0) { return $tokens[1]; } } return(""); } //////////////////////////////////////// proc createBaseDefExp(string $attrName, string $ffd) { $exp = "expression -n "+$ffd+"_"+$attrName+" -s " + "\""+$ffd+".envelope = clamp(0, 1, (0.5 + " + "attrFunc(humanoid_1."+$attrName+", 0, .5, 1, -0.5, 0, .5)));\";"; //print($exp+"\n"); eval($exp); } //////////////////////////////////////// proc string find_ffd_from_base_att(string $attName) { global string $g_baseDeformers[]; string $line; for($line in $g_baseDeformers) { string $tokens[]; tokenize($line, "=", $tokens); if(strcmp($tokens[0], $attName)==0) { return $tokens[1]; } } print("ERROR: couldn't find "+$attName+" in find_ffd_from_base_att\n"); return ""; } //////////////////////////////////////// // subatts should contain a comma separated list of deformers to be modified // lo/def/hi should be the influence range of this zero centered parameter global proc appendToDeformExp(string $HL_attrName, string $subatts, float $lo, float $def, float $hi) { string $tokens[]; tokenize($subatts, ",", $tokens); string $subAttName; for($subAttName in $tokens) { // find ffd tied to each subatt name string $ffd = find_ffd_from_base_att($subAttName); // build name of previously created expression node string $expNode = $ffd+"_"+$subAttName; 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-3)); // hack off "));" // append new HL attribute to expression $exp += " + attrFunc(humanoid_1."+$HL_attrName+", 0, .5, 1, " + $lo+", "+$def+", "+$hi+")));"; // WAS: $exp += " + humanoid_1."+$HL_attrName+"));"; 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 humanoid attribute. // Creates expression in proper ffd to drive ffd's envelope attribute // using the new humanoid attribute. //////////////////////////////////////// proc createOneBaseDefAttr(string $defLine) { string $tokens[]; tokenize($defLine, "=", $tokens); string $attrName = $tokens[0]; string $ffd = $tokens[1]; string $exp = "addAttr -ln " + $attrName + " -at double -min 0 -max 1 -dv 0.5 humanoid_1;"; //print($exp+"\n"); eval($exp); $exp = "setAttr -e -keyable true humanoid_1." + $attrName + ";"; //print($exp+"\n"); eval($exp); createBaseDefExp($attrName, $ffd); } //////////////////////////////////////// // 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 createOneDefAttr(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); appendToDeformExp($attrName, $atts, -0.5, 0, 0.5); } //////////////////////////////////////// // create all deformation attributes and expressions //////////////////////////////////////// proc deformExps() { global string $g_baseDeformers[]; global string $g_deformAttrs[]; string $str = "select -r humanoid_1"; eval($str); string $defLine; for($defLine in $g_baseDeformers) { createOneBaseDefAttr($defLine); } for($defLine in $g_deformAttrs) { createOneDefAttr($defLine); } } //////////////////////////////////////// deformExps(); //////////////////////////////////////// ////////////////////////////////////////