自己手绑个角色 结果边绑边写,写了一堆MEL。可以提下速度

来源:互联网 发布:直男癌 知乎 编辑:程序博客网 时间:2024/04/30 18:13

存下也许以后用的上大笑




//==============================================================================================//==============================================================================================//20130422 自己手绑个角色。结果边绑边写,写了一堆MEL。可以提下速度//============================== 数据层 =============================//----------------------检查对象类型----------------------proc string checkObjectType(string $objName){    string $relatives[] = `listRelatives -shapes $objName`;    if (`size $relatives` == 0 )    {        return `objectType $objName`;    }    return `objectType $relatives[0]`;}//---------------------获取joint长度--------------------------proc float getJointLength(string $jnt1, string $jnt2){//get jnt1 worldspace positionfloat $jnt1Pos[] = `xform -q -ws -t $jnt1`;//get jnt2 worldspace positionfloat $jnt2Pos[] = `xform -q -ws -t $jnt2`;//calculate the vector between themfloat $xcomp = $jnt2Pos[0] -$jnt1Pos[0];float $ycomp = $jnt2Pos[1] -$jnt1Pos[1];float $zcomp = $jnt2Pos[2] -$jnt1Pos[2];vector $tmp = << $xcomp, $ycomp, $zcomp>>;//get the vector lengthfloat $res = mag($tmp);return $res;}//-----------------------获取joint链长度---------------------------------proc float getJointChainLength(string $jntStart, string $jntEnd){string $temp[0];float $len = 0;do{$temp = `listRelatives -p $jntEnd`;$len += getJointLength($temp[0], $jntEnd);$jntEnd = $temp[0];}while ($jntEnd != $jntStart);return $len;}//---------------------获取通道栏中选中的属性--------------------------proc string getSelectedChannelBoxAttr(){string $sel[0] = `ls -sl`;select -r $sel[0];global string $gChannelBoxName; string $attrList[] = `channelBox -q -sma $gChannelBoxName`;return ($sel[0] + "." +$attrList[0]);}//===============================================功能================================================//----------------------------对齐骨头----------------------------------proc int alignJointX(string $rootJoint){string $children[] = `listRelatives -c $rootJoint`;float $p[] = `xform -q -ws -t $rootJoint`;int $i,$count = size($children);for ($i = 0 ; $i < $count; $i++ ){move -a -ws -x $p[0] 0 0 $children[$i];if (size(`listRelatives -c $children[$i]`) > 0){alignJointX($children[$i]);}}return 1;}//----------------------------对位极向量约束----------------------------proc int locPole(string $joint1, string $joint2, string $joint3, string $pole)//要求$joint3的父级为 膝盖,pole控制器在世界原点{string $temp[];//极向量约束定位    $tempLoc1=`spaceLocator`;    $tempConstraint=`pointConstraint $joint1 $joint3 $tempLoc1[0]`;    delete $tempConstraint[0];//$temp = `listRelatives -p $joint3`;//要求$joint3的父级为 膝盖    $tempConstraint=`aimConstraint -aimVector 1 0 0 $joint2 $tempLoc1[0]`;    $tempLoc2=`spaceLocator`;    parent $tempLoc2[0] $tempLoc1[0];    setAttr -type float3 ($tempLoc2[0]+".translate") (getJointLength($joint1,$joint3)) 0 0;    $tempFloat=`xform -q -ws -t $tempLoc2[0]`;$temp = `listRelatives -p $pole`;//group ($pole+"_grp") $pole;//要求 pole控制器 在世界原点(不在的话,执行后记得手动归零)    xform -ws -t $tempFloat[0] $tempFloat[1] $tempFloat[2] $temp[0];    delete $tempLoc1;return 1;}//----------------设置驱动关键帧 属性类型 float ----------------proc int setDK(string $driverAttr, float $driverValue, string $drivenAttr, float $drivenValue){$temp1 = `getAttr $driverAttr`;$temp2 = `getAttr $drivenAttr`;setAttr $driverAttr $driverValue;setAttr $drivenAttr $drivenValue;setDrivenKeyframe -itt "linear" -ott "linear" -cd $driverAttr $drivenAttr;setAttr $driverAttr $temp1;setAttr $drivenAttr $temp2;return 1;}//----------------------------重置 jointOrient----------------------------------proc int resetJointOrient(string $rootJoint){string $children[] = `listRelatives -f -c $rootJoint`;int $i,$count = size($children);for ($i = 0 ; $i < $count; $i++ ){if (size(`listRelatives -c $children[$i]`) > 0){resetJointOrient($children[$i]);}if(size(`ls ("|"+(match("[^|]*$",$children[$i])))`) != 0){error "世界空间上有一个与当前同名的对象,请处理下!";}string $parentName[] = `listRelatives -p $children[$i]`;string $myName[] = `parent -w $children[$i]`;setAttr ($myName[0] + ".jointOrient") 0 0 0;setAttr ($myName[0] + ".r") 0 0 0;parent $myName[0]  $parentName[0];}return 1;}//--------------------------插入层级---------------------------proc int insertHierarchy(string $insert ,string $current,int $mo)//maintain offset{string $temp[];//把要插入的对象,移动到 当前对象处,与当前对齐。if ($mo != 1){$temp = `parentConstraint -weight 1 $current $insert`;delete $temp[0];}//如果 当前 在世界 直接p, 如果不在 else$temp = `listRelatives -f -p $current`;parent $current $insert;if (size($temp)==1){parent $insert $temp[0];}return 1;}//----------------------------创建 0 1 融合功能----------------------------proc string createConstraintBlend(string $w0, string $w1, string $constraint,string $blend,int $ar)//O , 1, 约束名称,控制融合的 对象.属性,交换输出{string $setRange,$constrWeightAttrName[],$blend_ctrl_attr[];float $attrMaxValue[];//获取约束上的两个权重属性$constrWeightAttrName = `listAttr -ud $constraint`;if (`tokenize $blend "." $blend_ctrl_attr` != 2){error "blend attr error";}//查出 控制融合的属性最大值,以便将其 0-1 区间化。$attrMaxValue = `attributeQuery -node $blend_ctrl_attr[0] -max $blend_ctrl_attr[1]`;//创建 setRange 节点。用于实现 属性值的区间化和 0,1 互换输出。$setRange = `shadingNode -au -n ($blend_ctrl_attr[0] +"_" +"setRange") setRange`;setAttr ($setRange+".minX") 1;setAttr ($setRange+".maxY") 1;setAttr ($setRange+".oldMaxX") $attrMaxValue[0];setAttr ($setRange+".oldMaxY") $attrMaxValue[0];connectAttr -force $blend ($setRange+".valueX");connectAttr -force $blend ($setRange+".valueY");if ($ar == 0){connectAttr -force ($setRange+".outValueX") ($constraint+"."+$constrWeightAttrName[0]);connectAttr -force ($setRange+".outValueY") ($constraint+"."+$constrWeightAttrName[1]);}else{connectAttr -force ($setRange+".outValueX") ($constraint+"."+$constrWeightAttrName[1]);connectAttr -force ($setRange+".outValueY") ($constraint+"."+$constrWeightAttrName[0]);}return $setRange;}//----------------------------设置 0 1 融合功能----------------------------proc string setConstraintBlend(string $setRange, string $w0, string $w1, string $constraint,int $ar)//O , 1, 约束名称,控制融合的 对象.属性,交换输出{string $setRange,$constrWeightAttrName[],$blend_ctrl_attr[];//获取约束上的两个权重属性$constrWeightAttrName = `listAttr -ud $constraint`;if ($ar == 0){connectAttr -force ($setRange+".outValueX") ($constraint+"."+$constrWeightAttrName[0]);connectAttr -force ($setRange+".outValueY") ($constraint+"."+$constrWeightAttrName[1]);}else{connectAttr -force ($setRange+".outValueX") ($constraint+"."+$constrWeightAttrName[1]);connectAttr -force ($setRange+".outValueY") ($constraint+"."+$constrWeightAttrName[0]);}return $setRange;}//----------------------------创建  融合节点----------------------------proc int createBlendNode(string $attr0, string $attr1, string $targetAttr,string $ctrlAttr){string $blendColorsName,$obj0[],$obj1[],$ctrl[];float $num1,$num2,$num3;$num1 = `tokenize $attr0 "," $obj0`;$num2 = `tokenize $attr1 "," $obj1`;$num3 = `tokenize $ctrlAttr "," $ctrl`;$blendColorsName = `shadingNode -au -n ($obj0[0] + $obj0[1]  + "lock_blendColors") blendColors`;connectAttr -force $ctrlAttr ($blendColorsName+".blender");connectAttr -force $attr0 ($blendColorsName+".color1R");connectAttr -force $attr1 ($blendColorsName+".color2R");connectAttr -force ($blendColorsName+".outputR") $targetAttr;return 1;}//--------------------------- 创建 测量节点 返回 位移与形节点 ----------------------------proc string createDistance(string $prefix){string $distance = `shadingNode -au distanceDimShape`;    string $distances[] = `listRelatives -p $distance`;    $distance = rename($distances[0],($prefix+"_distance"));    $distances = `listRelatives -c $distance`;return $distances[0];}//------------------------联接属性用setRange 处理的一个范围值--------------------------proc int connectAttrRangeX(string $setRange,string $attr0,string $attr1,float $minX,float $maxX,float $oldMinX,float $oldMaxX){//判断 setRange 节点    if (!`objExists $setRange`)    {//创建 setRange 节点。用于实现 属性值的区间化和 0,1 互换输出。$setRange = `shadingNode -au -n $setRange setRange`;}setAttr ($setRange+".minX") $minX;setAttr ($setRange+".maxX") $maxX;setAttr ($setRange+".oldMinX") $oldMinX;setAttr ($setRange+".oldMaxX") $oldMaxX;connectAttr -force $attr0 ($setRange+".valueX");connectAttr -force ($setRange+".outValueX") $attr1;return 1;}//------------------------属性A 用setRange 交替控制属性B,C --------------------------proc int  attrA_switch_attrBattrC(string $attrA,string $attrB,string $attrC){if (size(`listConnections $attrB`) > 0){delete `listConnections $attrB`;}if (size(`listConnections $attrC`) > 0){delete `listConnections $attrC`;}string $attrAname[2],$attrBname[2],$attrCname[2],$attrMaxValue[2];//创建 setRange 节点。用于实现 属性值的区间化和 0,1 互换输出。if (size(`tokenize $attrA "." $attrAname`) != 2){error "objName.attr";}if (size(`tokenize $attrB "." $attrBname`) != 2){error "objName.attr";}if (size(`tokenize $attrC "." $attrCname`) != 2){error "objName.attr";}$attrMaxValue = `attributeQuery -node $attrAname[0] -max $attrAname[1]`;$setRange = `shadingNode -au -n ($attrBname[0] + "_"+$attrCname[0] + "_setRange") setRange`;setAttr ($setRange+".minX") 0;setAttr ($setRange+".maxX") 1;setAttr ($setRange+".oldMinX") $attrMaxValue[0];setAttr ($setRange+".oldMaxX") $attrMaxValue[0];setAttr ($setRange+".minY") 1;setAttr ($setRange+".maxY") 0;setAttr ($setRange+".oldMinY") $attrMaxValue[0];setAttr ($setRange+".oldMaxY") $attrMaxValue[0];connectAttr -force $attrA ($setRange+".valueX");connectAttr -force $attrA ($setRange+".valueY");connectAttr -force ($setRange+".outValueX") $attrB;connectAttr -force ($setRange+".outValueY") $attrC;return 1;}proc int  attrA_switch_attrBattrC_UI(){if (`window -ex attrA_switch_attrBattrC_win` == true)    {        deleteUI -window attrA_switch_attrBattrC_win;    }     window -t "attrA ==> attrB, attrC  by Jerry" -wh 300 200 attrA_switch_attrBattrC_win; columnLayout -adj true ;separator -st "none" -h 10;$tfg1 = `textFieldButtonGrp -adj 1 -l "Attr A :" -bl "Load Sel"`;$tfg2 = `textFieldButtonGrp -adj 1 -l "Attr B :" -bl "Load Sel"`;$tfg3 = `textFieldButtonGrp -adj 1 -l "Attr C :" -bl "Load Sel"`;button -l "Go" -h 35 -c ("attrA_switch_attrBattrC " + ` textFieldButtonGrp -q -tx $tfg1` + " " + ` textFieldButtonGrp -q -tx  $tfg2` + " " + ` textFieldButtonGrp -q -tx $tfg3`);textFieldButtonGrp -e -bc ("textFieldButtonGrp -e -tx (getSelectedChannelBoxAttr()) " + $tfg1) $tfg1;textFieldButtonGrp -e -bc ("textFieldButtonGrp -e -tx (getSelectedChannelBoxAttr()) " + $tfg2) $tfg2;textFieldButtonGrp -e -bc ("textFieldButtonGrp -e -tx (getSelectedChannelBoxAttr()) " + $tfg3) $tfg3;showWindow attrA_switch_attrBattrC_win;    window -e -wh 420 150 attrA_switch_attrBattrC_win;return 1;}//-------------------------把属性A,反转连接给B们-----------------------proc int attrA_reverse_01_to_attrB(string $attrA,string $attrB){string $reverseName,$attrAs[], $attrBs[],$ctrl_attr[];float $attrMaxValue[],$attrMinValue[];//拆出名称和属性,然后查属性的最大值tokenize $attrA "." $attrAs;$attrMaxValue = `attributeQuery -node $attrAs[0] -max $attrAs[1]`;$attrMinValue = `attributeQuery -node $attrAs[0] -min $attrAs[1]`;$setRange = `shadingNode -au -n ($attrA + "_setRange") setRange`;setAttr ($setRange+".minX") 1;setAttr ($setRange+".maxX") 0;setAttr ($setRange+".oldMinX") $attrMinValue[0];setAttr ($setRange+".oldMaxX") $attrMaxValue[0];connectAttr -force $attrA ($setRange+".valueX");//连给所有目标tokenize $attrB "," $attrBs;for ($attr in $attrBs){if (`tokenize $attr "." $ctrl_attr` == 2){connectAttr -force ($setRange+".outValueX") $attr;}}return 1;}proc int  attrA_reverse_01_to_attrB_UI(){if (`window -ex attrA_reverse_01_to_attrB_win` == true)    {        deleteUI -window attrA_reverse_01_to_attrB_win;    }     window -t "attrA reverse 0,1 to attrB by Jerry" -wh 300 200 attrA_reverse_01_to_attrB_win; columnLayout -adj true ;separator -st "none" -h 10;$tfg1 = `textFieldButtonGrp -adj 1 -l "Attr A :" -bl "Load Sel"`;$tfg2 = `textFieldButtonGrp -adj 1 -l "Attr B :" -bl "Load Sel"`;button -l "Go" -h 35 -c ("attrA_reverse_01_to_attrB " + ` textFieldButtonGrp -q -tx $tfg1` + " " + ` textFieldButtonGrp -q -tx  $tfg2`);textFieldButtonGrp -e -bc ("textFieldButtonGrp -q -tx textFieldButtonGrp -e -tx (getSelectedChannelBoxAttr()) " + $tfg1) $tfg1;textFieldButtonGrp -e -bc ("textFieldButtonGrp -e -tx (getSelectedChannelBoxAttr()) " + $tfg2) $tfg2;showWindow attrA_reverse_01_to_attrB_win;    window -e -wh 420 130 attrA_reverse_01_to_attrB_win;return 1;}//===============================功能分块================================//----------------------控制器 快速取名----------------------//选一个控制曲线,再选一个被控对象,执行proc int renameCtrls(string $selected[], string $suffix, string $parent){    string $p,$c,$ctrlName,$temp[]; int $con;    $c = `textField -q -tx ctrlName`;if (size(`listRelatives -c $c`) > 1){warning ("jerryWarning>> More than one children under the ctrl: " + $c);}//将所选对象存到 node节点 属性上,再遍历。    //创建一个 空节点    $node = `createNode unknown`;    //添加属性 selObjects    addAttr -ln "selObjects" -at message -multi -im 0;    //遍历所选 与节点创建连接    for ($obj in $selected)    {        connectAttr -na ($obj + ".message") ($node + ".selObjects");    }    //获取连接上的对象个数,然后遍历 打组    $con = size(`listConnections ($node + ".selObjects")`);    for ($i = 0; $i < $con; $i++)    {        //取出第一个对象        string $tmp[0] = `listConnections ($node + ".selObjects["+$i+"]")`;$sel = $tmp[0];        $ctrlName = rename(`duplicate -rr $c`,(match("[^|]*$",$sel) + "_" + $suffix));//(match(".*_",match("[^|]*$",$sel)) + "ctrl"));        group -n ($ctrlName+"_grp") $ctrlName;        string $temp[] = `parentConstraint -w 1 $sel ($ctrlName+"_grp") `;        delete $temp[0];if ( $parent == 1){$temp = `listRelatives -f -p $sel`;parent $sel ($sel + "_" + $suffix);if (size($temp)==1){parent ($sel + "_" + $suffix + "_grp") $temp[0];}//insertHierarchy($ctrlName,$sel,0);//insertHierarchy(($ctrlName+"_grp"),$ctrlName,0);}    }    select -r `listConnections ($node + ".selObjects")`;//清除 空节点    delete $node;    return 1;}proc int renameCtrlsUI(){    if (`window -ex renameCtrls_win` == true)    {        deleteUI -window renameCtrls_win;    }     window -t "Rename Ctrl by Jerry" -wh 300 200 renameCtrls_win;        columnLayout -adj 1 -co "both" 5;        string $rcLayout = `rowColumnLayout -nc 2 -cw 1 195 -cw 2 80`;            string $ctrlName= `textField -h 40 -tx " " ctrlName`;            string $getCtrlName= `button -h 40 -l "getCtrlName" -c "string $selected[] = `ls -sl`;textField -e -tx $selected[0] ctrlName;" $getCtrlName`;        setParent ..;checkBoxGrp -ncb 1 -l "parent" -v1 1 parentCheckBoxGrp;        button -l "Move and Rename Ctrls" -h 100 -c "renameCtrls(`ls -sl`,\"ctrl\",`checkBoxGrp -q -v1 parentCheckBoxGrp`)";    showWindow renameCtrls_win;    window -e -wh 300 200 renameCtrls_win;     return 1;}//----------------------- 对象打组 保护数据 --------------------------//可以选多个,创建一个空节点。把所选对象都连到它的自定属性selObjects上。//这样就不怕父级打组后原本子物体路径失效了。proc string[] grp_selectedObjs(string $selection[],string $suffix){    string $grpName,$grpNames[],$tempGrpNames[],$temParent[];//,$suffix = "_grp";    int $con;    //创建一个 空节点    $node = `createNode unknown`;    //添加属性 selObjects    addAttr -ln "selObjects" -at message -multi -im 0;    //遍历所选 与节点创建连接    for ($obj in $selection)    {        connectAttr -na ($obj + ".message") ($node + ".selObjects");    }    //获取连接上的对象个数,然后遍历 打组    $con = size(`listConnections ($node + ".selObjects")`);    for ($i = 0; $i < $con; $i++)    {        //取出第一个对象        string $tmp[0] = `listConnections ($node + ".selObjects["+$i+"]")`;        //用它的名字加 _grp 后缀创建组,如果当前对象已经是本后缀了,那就给它加序号        if (match(($suffix+"[0-9]*$"),$tmp[0]) != "")        {            $suffix += (int)match("[0-9]*$",$tmp[0]) + 1;        }         $grpName = (substitute("_[^_]*$",match("[^|]*$",$tmp[0]), "" ) + $suffix);        $tempGrpNames = `listRelatives -p -f $tmp[0]`;        int $j,$n = 0;        if (match("[^|]*$",$tempGrpNames[0]) == $grpName) //print ($grpName+ $suffix)        {             $grpName = (substitute("_[^_]*$",match("[^|]*$",$tmp[0]), "" ) + $suffix+"_0");            //$grpName += ($suffix+"_0");        }//创建组        $grpName = `group -em -n $grpName`;        //把组P组 物体        parent(("|"+$grpName),$tmp[0]) ;        //清除 位移、旋转、缩放 值        setAttr ".t" 0 0 0;        setAttr ".r" 0 0 0;        setAttr ".s" 1 1 1;        //再把 组 解出来,到世界空间        parent -w ($tmp[0]+"|"+ $grpName);        //如果当前物体,不在世界空间,那先把它的组P给它的父级。$temParent = `listRelatives -p -f $tmp[0]`;        if (size($temParent) != 0)        {$tempGrpNames =  parent(("|"+$grpName),$temParent[0]);$grpName = $tempGrpNames[0];        }        //把物体P给,它的组。        parent $tmp[0] $grpName;        //将本次创建的组存入 数组 备用。        $grpNames[$i] = $grpName;    }    //清除 空节点    delete $node;    //选中所有创建出来的组    select -r $grpNames;     return $grpNames;}//----------------------- 创建 RPsolver IK 目标是用于手臂----------------------- proc int createArmIkRPsolver(string $ctrlName,string $ctrlPole,string $sj,string $ej){    //createIK     string $handle[2];    $handle = `ikHandle -sj $sj -ee $ej -solver "ikRPsolver" -n ($ctrlName+"_ikHandle")`;    $handle[1] = `rename $handle[1] ($ctrlName + "_effector")`;    pointConstraint -mo -weight 1 $ctrlName $handle[0];orientConstraint -offset 0 0 0 -weight 1 $ctrlName $ej;    poleVectorConstraint $ctrlPole $handle[0];    //请理、打组    if (`objExists "ikHandle_grp"`)    {        parent $handle[0] "ikHandle_grp";    }else    {        group -n "ikHandle_grp" $handle[0];xform -os -piv 0 0 0;    }setAttr "ikHandle_grp.v" 0;select -r $ctrlName;    return 1;}proc int createArmIkRPsolverUI(){string $selected[] = `ls -sl`;createArmIkRPsolver($selected[0],$selected[1],$selected[2],$selected[3]);    return 1;}//----------------------- 创建 RPsolver IK 目标是用于腿。----------------------- proc int createLegIkRPsolver(string $ctrlName,string $ctrlPole,string $sj,string $ej){    //createIK    string $handle[2];    $handle = `ikHandle -sj $sj -ee $ej -solver "ikRPsolver" -n ($ctrlName+"_ikHandle")`;    $handle[1] = `rename $handle[1] ($ctrlName + "_effector")`;    pointConstraint -mo -w 1 $ctrlName $handle[0];    poleVectorConstraint $ctrlPole $handle[0];    //请理、打组    if (`objExists "ikHandle_grp"`)    {        parent $handle[0] "ikHandle_grp";    }else    {        group -n "ikHandle_grp" $handle[0];xform -os -piv 0 0 0;    }setAttr "ikHandle_grp.v" 0;select -r $ctrlName;    return 1;}proc int createLegIkRPsolverUI(){string $selected[] = `ls -sl`;createLegIkRPsolver($selected[0],$selected[1],$selected[2],$selected[3]);return 1;}//--------------------------------创建 IK 拉伸 膝肘锁定-------------------------------proc int ikStretchy(string $ctrlName,string $ctrlPole,string $jntStart,string $jntMid,string $jntEnd,string $worldSpace,string $worldScaleAxis, string $jntScaleAxis)//$ctrlName:IKctrl, $jntStart:armJoint, $jntEnd:WristJoint, $ws:worldscale{//-----------------------声明变量----------------------    //辅助变量string $loc[0], $preSuffix = $ctrlName;//locator 和 distance 三组.//用于定位三个关节位置,并实时获取长度,用于处理拉伸string $startLoc,$midLoc,$endLoc,$arm_DS,$shoulder_DS,$elbow_DS;//condition 条件节点一个//判断,如果定位器距离大于默认长度,输出测得长度,用于拉伸string $stretchy_CD; // multiplyDivide 剩除节点四个//测得长度 / 原始长度 = 缩放比例string $stretchy_MD,$global_MD,$lockShoulder_MD,$lockElbowl_MD;//blendColors 混合节点四个//混合 stretchy与lock 转换, stretchy开关string $lockShoulder_BC,$lockElbow_BC,$stretchyShoulder_BC,$stretchyElbow_BC;//setRange 设置范围节点两个 //lock,stretchy属性值为0-10,转成0-1输出.  反转min和max,可以反转出结果string $lock_SR, $stretchy_SR;//-----------------------清理沉余----------------------//if (`objExists ($ctrlName+"_startLoc")`) delete($ctrlName+"_startLoc");//如果骨骼属性已经被关联,清理它if (size(`listConnections ($jntStart+".sx")`) > 0){delete `listConnections ($jntStart+".sx")`;setAttr ($jntStart+".sx") 1;}if (size(`listConnections ($jntMid+".sx")`) > 0){delete `listConnections ($jntMid+".sx")`;setAttr ($jntMid+".sx") 1;}//-------------检查 锁定属性是否存在。不在就创建--------------if (!`attributeExists "stretchy" $ctrlName`){catch(`addAttr -ln "stretchy" -at double  -min 0 -max 10 -dv 0 $ctrlName`);catch(`setAttr -e -keyable true ($ctrlName+".stretchy")`);}if (!`attributeExists "lock" $ctrlPole`){catch(`addAttr -ln "lock" -at double  -min 0 -max 10 -dv 0 $ctrlPole`);catch(`setAttr -e -keyable true ($ctrlPole+".lock")`);}//-----------------------统一 创建节点----------------------//创建locator 三个    $loc = `spaceLocator -n ($preSuffix+"_startLoc")`;    $startLoc = $loc[0];    $loc = `spaceLocator -n ($preSuffix+"_midLoc")`;    $midLoc = $loc[0];$loc = `spaceLocator -n ($preSuffix+"_endLoc")`;    $endLoc = $loc[0];    //约束 定位器    pointConstraint $jntStart  $startLoc;    pointConstraint $ctrlPole  $midLoc;    pointConstraint $ctrlName  $endLoc;//创建拉伸测量工具,并重命名$arm_DS = createDistance($preSuffix+"_arm");$shoulder_DS = createDistance($preSuffix+"_shoulder");$elbow_DS = createDistance($preSuffix+"_elbow");//创建 条件节点    $stretchy_CD = `shadingNode -au -n ($preSuffix+"_condition") condition`;//创建 multiplyDivide 乘除节点    $stretchy_MD = `shadingNode -au -n ($preSuffix +"_stretchy_MD") multiplyDivide`;$global_MD = `shadingNode -au -n ($preSuffix +"_global_MD") multiplyDivide`;$lockShoulder_MD = `shadingNode -au -n ($preSuffix +"_lockShoulder_MD") multiplyDivide`;$lockElbowl_MD = `shadingNode -au -n ($preSuffix +"_lockElbowl_MD") multiplyDivide`;//创建  blendColors 混合节点四个    $lockShoulder_BC = `shadingNode -au -n ($preSuffix +"_lockShoulder_BC") blendColors`;    $lockElbow_BC = `shadingNode -au -n ($preSuffix +"_lockElbow_BC") blendColors`;$stretchyShoulder_BC = `shadingNode -au -n ($preSuffix +"_stretchyShoulder_BC") blendColors`;$stretchyElbow_BC = `shadingNode -au -n ($preSuffix +"_stretchyElbow_BC") blendColors`;//setRange 设置范围节点两个 $lock_SR = `shadingNode -au -n ($preSuffix +"_stretchy_SR") setRange`;$stretchy_SR = `shadingNode -au -n ($preSuffix +"_stretchy_SR") setRange`;//-----------------------统一 开始设置-----------------------//--------------设置、联接节点------------//loc 连给测量工具    connectAttr ($startLoc + ".worldPosition[0]") ($arm_DS + ".startPoint");    connectAttr ($endLoc + ".worldPosition[0]") ($arm_DS + ".endPoint");connectAttr ($midLoc + ".worldPosition[0]") ($elbow_DS + ".startPoint");connectAttr ($midLoc + ".worldPosition[0]") ($shoulder_DS + ".endPoint");connectAttr ($startLoc + ".worldPosition[0]") ($shoulder_DS + ".startPoint");connectAttr ($endLoc + ".worldPosition[0]") ($elbow_DS + ".endPoint");//测量工具 连给 条件节点    connectAttr ($arm_DS + ".distance") ($stretchy_CD+ ".firstTerm");    connectAttr ($arm_DS + ".distance") ($stretchy_CD+ ".colorIfTrueR");//设置测量节点    setAttr ($stretchy_CD+ ".operation") 2;    setAttr ($stretchy_CD+ ".secondTerm") (getJointChainLength($jntStart, $jntEnd));    setAttr ($stretchy_CD+ ".colorIfFalseR") (getJointChainLength($jntStart, $jntEnd));//测量节点 连给 手臂拉伸乘除节点。设置为除,除数为默认长度setAttr ($stretchy_MD + ".operation") 2;    setAttr ($stretchy_MD + ".input2X") (getJointChainLength($jntStart, $jntEnd));    connectAttr ($stretchy_CD+ ".outColorR") ($stretchy_MD + ".input1X");//上臂测量长度连给 lock shoulder 乘除节点。设置为除,除数为默认长度    setAttr ($lockShoulder_MD + ".operation") 2;setAttr ($lockShoulder_MD + ".input2X") (getJointLength($jntStart, $jntMid));    connectAttr ($shoulder_DS + ".distance") ($lockShoulder_MD + ".input1X");//前臂测量长度连给 lock elbow 乘除节点。设置为除,除数为默认长度    setAttr ($lockElbowl_MD + ".operation") 2;setAttr ($lockElbowl_MD + ".input2X") (getJointLength($jntEnd, $jntMid));    connectAttr ($elbow_DS + ".distance") ($lockElbowl_MD + ".input1X");//lock 开关,连给 setRange 转为 0-1再连给 blendersetAttr ($lock_SR + ".minX") 0; setAttr ($lock_SR + ".maxX") 1; setAttr ($lock_SR + ".oldMinX") 0; setAttr ($lock_SR + ".oldMaxX") 10;     connectAttr ($ctrlPole + ".lock") ($lock_SR + ".valueX");    connectAttr ($lock_SR + ".outValueX") ($lockShoulder_BC + ".blender");    connectAttr ($lock_SR + ".outValueX") ($lockElbow_BC + ".blender");//stretchy 开关,连给 setRange 转为 0-1再连给 blendersetAttr ($stretchy_SR + ".minX") 0; setAttr ($stretchy_SR + ".maxX") 1; setAttr ($stretchy_SR + ".oldMinX") 0; setAttr ($stretchy_SR + ".oldMaxX") 10;     connectAttr ($ctrlName + ".stretchy") ($stretchy_SR + ".valueX");    connectAttr ($stretchy_SR + ".outValueX") ($stretchyShoulder_BC + ".blender");    connectAttr ($stretchy_SR + ".outValueX") ($stretchyElbow_BC + ".blender");//上臂 lock乘除同stretchy乘除连给 lock blenderColors 的 颜色1、2     connectAttr ($lockShoulder_MD + ".outputX") ($lockShoulder_BC + ".color1R");connectAttr ($stretchy_MD + ".outputX") ($lockShoulder_BC + ".color2R");//前臂 lock乘除同stretchy乘除连给 lock blenderColors 的 颜色1、2     connectAttr ($lockElbowl_MD + ".outputX") ($lockElbow_BC + ".color1R");connectAttr ($stretchy_MD + ".outputX") ($lockElbow_BC + ".color2R");//上臂  lock blenderColors 连给 stretchy 开关  blenderColorssetAttr ($stretchyShoulder_BC + ".color2R") 1;    connectAttr ($lockShoulder_BC + ".outputR") ($stretchyShoulder_BC + ".color1R");//前臂  lock blenderColors 连给 stretchy 开关  blenderColorssetAttr ($stretchyElbow_BC + ".color2R") 1;    connectAttr ($lockElbow_BC + ".outputR") ($stretchyElbow_BC + ".color1R");//上臂 最终连给 骨骼    connectAttr ($stretchyShoulder_BC + ".outputR") ($jntStart + ".sx");//前臂 最终连给 骨骼    connectAttr ($stretchyElbow_BC + ".outputR") ($jntMid + ".sx");    //--------世界全局缩放---------    if ($worldSpace != "" && `objExists $worldSpace`)    {        $global_MD = `shadingNode -au -n ($ctrlName+"_global_MD") multiplyDivide`;        setAttr ($global_MD + ".operation") 1;        setAttr ($global_MD + ".input1X") (getJointChainLength($jntStart, $jntEnd));        connectAttr ($worldSpace + $worldScaleAxis) ($global_MD + ".input2X");        connectAttr -f ($global_MD + ".outputX")  ($stretchy_CD+ ".secondTerm");        connectAttr -f ($global_MD + ".outputX")  ($stretchy_CD+ ".colorIfFalseR");        connectAttr -f ($global_MD + ".outputX")  ($stretchy_MD + ".input2X");    }    //请理、打组    if (`objExists "distanceDistance_grp"`)    {            parent $startLoc $midLoc $endLoc $arm_DS $shoulder_DS $elbow_DS distanceDistance_grp;    }else    {        group -n "distanceDistance_grp" $startLoc $midLoc $endLoc $arm_DS $shoulder_DS $elbow_DS ;xform -os -piv 0 0 0;    }setAttr "distanceDistance_grp.v" 0;select -r $ctrlName;    return 1;}proc int ikStretchyUI(){string $selected[] = `ls -sl`;ikStretchy($selected[0],$selected[1],$selected[2],$selected[3],$selected[4],"main_ctrl",".sx",".sx");return 1;}//--------------创建 feet IK grp 创建脚的IK组(3K5组,再多就是内外侧撇脚)。-----------proc int createFeetIkGroup(string $ikCtrl, string $ankleIK, string  $ballJoint, string $toeJoint, string  $heelJoint, string $prefix){//    if (size($ikJointLoc) != 6)//    {//        error "最少要也选中,1 IK控制器,2 脚踝IK,3 脚掌骨,4 脚尖骨,5 脚根定位体 ,6 前缀!";//    }//    string $ikCtrl = $ikJointLoc[0];//    string $ankleIK = $ikJointLoc[1];//    string $ballJoint = $ikJointLoc[2];//    string $toeJoint = $ikJointLoc[3];//    string $heelJoint = $ikJointLoc[4];//    string $prefix = $ikJointLoc[5];//string $prefix = "L";    string $ballIK[] ,$toeIK[],$group[], $loc[0], $temp[];    float $p[];    //判断所选内容是否正确    if (checkObjectType($ankleIK) == "ikHandle" && checkObjectType($ballJoint) == "joint" && checkObjectType($toeJoint) == "joint"  && checkObjectType($heelJoint) == "joint")    {        $temp = `listConnections ($ankleIK+".rotatePivot")`;        catch(`delete $temp[0]`);        $temp = `listConnections ($ankleIK+".endEffector")`;        $temp = `listConnections ($temp[0]+".tx")`;        $ballIK = `ikHandle -sj $temp[0] -ee $ballJoint -solver "ikSCsolver" -n ($ballJoint + "_ikHandle")`;        rename $ballIK[1] ($ballJoint + "_effector");        $toeIK = `ikHandle -sj $ballJoint -ee $toeJoint -solver "ikSCsolver" -n ($toeJoint + "_ikHandle")`;        rename $ballIK[1] ($toeJoint + "_effector");        //五个组的名字,先拼出来,方便后面用。        $group[0] = ($prefix + "_ankleIK_grp");        $group[1] = ($prefix + "_ballIK_grp");        $group[2] = ($prefix + "_toeIK_grp");        $group[3] = ($prefix + "_heel_grp");        $group[4] = ($prefix + "_feet_grp");        catch(`ungroup $group[0]`);        catch(`ungroup $group[1]`);        catch(`ungroup $group[2]`);        catch(`ungroup $group[3]`);        catch(`ungroup $group[4]`);catch(`ungroup ($prefix +  "_footInSide_grp")`);catch(`ungroup ($prefix +  "_footOutSide_grp")`);catch(`ungroup ($prefix +  "_footPiv_grp")`);        //Group1 ankleIK_grp : 脚裸IK打组,轴心放到 ball        $p = `xform -q -ws -t $ballJoint`;        group -n $group[0] $ankleIK;        xform -ws -piv $p[0] $p[1] $p[2];        //Group2 ballIK_grp:( ballIK + toeIK )打组,轴心放到 ball        group -n $group[1] $ballIK[0] $toeIK[0];        xform -ws -piv $p[0] $p[1] $p[2];        //Group3 toeIK_grp:(Group1 + Group2 )打组,轴心放到 toe        $p = `xform -q -ws -t $toeJoint`;        group -n $group[2] $group[0] $group[1];        xform -ws -piv $p[0] $p[1] $p[2];        //Group4 heel_grp:(Group3)打组,轴心放到 heel        $p = `xform -q -ws -t $heelJoint`;        group -n $group[3] $group[2];        xform -ws -piv $p[0] $p[1] $p[2];        //Group5 feet_grp:(Group4)打组,轴心放到 ankleIK        $p = `xform -q -ws -t $ankleIK`;        group -n $group[4] $group[3];        xform -ws -piv $p[0] $p[1] $p[2];//inSide_grpgroup -n ($prefix +  "_footInSide_grp") $group[2];//outSide_grpgroup -n ($prefix +  "_footOutSide_grp");//footPiv_grpgroup -n ($prefix +  "_footPiv_grp") $group[3];        //为组4创建轴心 loc        $p = `xform -q -ws -t $heelJoint`;        $loc = `spaceLocator -n ($prefix + "_footPivLoc")`;// -p $p[0] $p[1] $p[2]`;        group -n  ($prefix + "_footPivLoc_grp") $loc[0];        xform -ws -t $p[0] $p[1] $p[2] ($prefix + "_footPivLoc_grp");        parent ($prefix + "_footPivLoc_grp") $group[3];$temp = `listRelatives -shapes $loc[0]`;connectAttr -f ($temp[0] + ".worldPosition[0]") ($prefix + "_footPiv_grp.rotatePivot");setAttr ($prefix + "_footPiv_grp.displayHandle") 1;setAttr ($prefix + "_footPiv_grp.selectHandle") (getAttr ($ikCtrl +"_grp.tx")) (getAttr($ikCtrl +"_grp.ty")) $p[2] ;        //在控制器上添加属性        catch (`deleteAttr -attribute "toe" $ikCtrl`);        catch(`addAttr -ln "toe"  -at double  -min -10 -max 10 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".toe")`);        catch (`deleteAttr -attribute "roll" $ikCtrl`);        catch(`addAttr -ln "roll"  -at double  -min -10 -max 10 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".roll")`);        catch (`deleteAttr -attribute "side" $ikCtrl`);        catch(`addAttr -ln "side"  -at double  -min -10 -max 10 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".side")`);catch (`deleteAttr -attribute "toePivot" $ikCtrl`);        catch(`addAttr -ln "toePivot"  -at double  -min -10 -max 10 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".toePivot")`);        catch (`deleteAttr -attribute "ballPivot" $ikCtrl`);        catch(`addAttr -ln "ballPivot"  -at double  -min -10 -max 10 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".ballPivot")`);        catch (`deleteAttr -attribute "hellPivot" $ikCtrl`);        catch(`addAttr -ln "hellPivot"  -at double  -min -10 -max 10 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".hellPivot")`);catch(`deleteAttr -attribute "footPivVisibe" $ikCtrl`);catch(`addAttr -ln "footPivVisibe"  -at double  -min 0 -max 1 -dv 0 $ikCtrl`);        catch(`setAttr -e -keyable true ($ikCtrl + ".footPivVisibe")`);//设置 属性 连接 和 驱动关键帧connectAttr ($ikCtrl + ".footPivVisibe") ($prefix +  "_footPivLoc_grp.v");setDK(($ikCtrl + ".toe"),0,($group[1]+".rx"),0);setDK(($ikCtrl + ".toe"),10,($group[1]+".rx"),-100);setDK(($ikCtrl + ".toe"),-10,($group[1]+".rx"),80);//rollsetDK(($ikCtrl + ".roll"),0,($group[0] + "rx"),0);setDK(($ikCtrl + ".roll"),0,($group[3] + "rx"),0);setDK(($ikCtrl + ".roll"),-5,($group[2] + ".rx"),0);setDK(($ikCtrl + ".roll"),-5,($group[0] + "rx"),70);setDK(($ikCtrl + ".roll"),10,($group[3] + "rx"),-60);setDK(($ikCtrl + ".roll"),-10,($group[0] + "rx"),0);setDK(($ikCtrl + ".roll"),-10,($group[2] + ".rx"),80);//sidesetDK(($ikCtrl + ".side"),0,($prefix +  "_footInSide_grp.rz"),0);setDK(($ikCtrl + ".side"),0,($prefix +  "_footOutSide_grp.rz"),0);if ($prefix == "L"){setDK(($ikCtrl + ".side"),-10,($prefix +  "_footInSide_grp.rz"),50);setDK(($ikCtrl + ".side"),10,($prefix +  "_footOutSide_grp.rz"),-60);}else if($prefix == "R"){setDK(($ikCtrl + ".side"),-10,($prefix +  "_footInSide_grp.rz"),-60);setDK(($ikCtrl + ".side"),10,($prefix +  "_footOutSide_grp.rz"),50);}//toePivotsetDK(($ikCtrl + ".toePivot"),0,($group[2] + ".ry"),0);setDK(($ikCtrl + ".toePivot"),10,($group[2] + ".ry"),-90);setDK(($ikCtrl + ".toePivot"),-10,($group[2] + ".ry"),90);//ballPivotsetDK(($ikCtrl + ".ballPivot"),0,($group[0] + "ry"),0);setDK(($ikCtrl + ".ballPivot"),10,($group[0] + "ry"),-90);setDK(($ikCtrl + ".ballPivot"),-10,($group[0] + "ry"),90);//heelPivotsetDK(($ikCtrl + ".heelPivot"),0,($group[3] + "ry"),0);setDK(($ikCtrl + ".heelPivot"),10,($group[3] + "ry"),-90);setDK(($ikCtrl + ".heelPivot"),-10,($group[3] + "ry"),90);    }return 1;}proc int createFeetIkGroupUI(){string $selected[] = `ls -sl`;createFeetIkGroup($selected[0],$selected[1],$selected[2],$selected[3],$selected[4],"ssside");return 1;}//-----------------------手指是控制器加属性------------------------------------proc int fingersCtrlAttr(string $ctrl){    //在控制器上添加属性        catch (`deleteAttr -attribute "fist" $ctrl`);        catch(`addAttr -ln "fist"  -at double  -min -10 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".fist")`);catch (`deleteAttr -attribute "relax" $ctrl`);        catch(`addAttr -ln "relax"  -at double  -min 0 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".relax")`);catch (`deleteAttr -attribute "win" $ctrl`);        catch(`addAttr -ln "win"  -at double  -min 0 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".win")`);catch (`deleteAttr -attribute "catch" $ctrl`);        catch(`addAttr -ln "catch"  -at double  -min 0 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".catch")`);catch (`deleteAttr -attribute "bend" $ctrl`);        catch(`addAttr -ln "bend"  -at double  -min 0 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".bend")`);catch (`deleteAttr -attribute "curl" $ctrl`);        catch(`addAttr -ln "curl"  -at double  -min 0 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".curl")`);catch (`deleteAttr -attribute "hold" $ctrl`);        catch(`addAttr -ln "hold"  -at double  -min 0 -max 10 -dv 0 $ctrl`);        catch(`setAttr -e -keyable true ($ctrl + ".hold")`);return 1;}//----------------------------FKIK 三套骨骼 创建融合---------------------------------//目前只支持 FK、IK、SK 统一 三节骨骼,参数 FK IK SK FKIK融合属性proc int blendFKIK(string $fk[],string $ik[],string $sk[],string $skForeArmRoll,string $fkik_blend,string $preSuffix){//  parentConstraint -mo -weight 1;//pointConstraint -mo -weight 1 $ctrlName $handle[0];//orientConstraint -mo -weight 1;//scaleConstraint -mo -weight 1;//scaleConstraint -mo -skip y -skip z -weight 1;string $temp[], $reverseName,$setRange,$constrWeightAttrName[] ;float $kSize;$kSize = size($fk);if ($kSize != 3 || $kSize != size($ik) ||  $kSize != size($sk) ){error "FK IK SK 数量要一至,最少要有一组。";}//-----------------------约束并设置权重---------------------------------//肩部 parent,scale 约束。约束权重由,FKIK 的 blender属性控制$temp = `parentConstraint -mo -weight 1 $fk[0] $ik[0] $sk[0]`;$setRange = createConstraintBlend($fk[0],$ik[0],$temp[0],$fkik_blend,0);//第一次 createConstraintBlend 创建setRange$temp = `scaleConstraint -mo -weight 1 $fk[0] $ik[0] $sk[0]`;setConstraintBlend($setRange,$fk[0],$ik[0],$temp[0],0);//已有 setRange,直接用setConstraintBlend//createConstraintBlend($fk[0],$ik[0],$temp[0],$fkik_blend,0);//肘部 parent,scale 约束。约束权重由,FKIK 的 blender属性控制$temp = `parentConstraint -mo -weight 1 $fk[1] $ik[1] $sk[1]`;setConstraintBlend($setRange,$fk[1],$ik[1],$temp[0],0);$temp = `scaleConstraint -mo -weight 1 $fk[1] $ik[1] $sk[1]`;setConstraintBlend($setRange,$fk[1],$ik[1],$temp[0],0);//腕部 point, 约束。约束权重由,FKIK 的 blender属性控制$temp = `pointConstraint -mo -weight 1 $fk[2] $ik[2] $sk[2]`;setConstraintBlend($setRange,$fk[2],$ik[2],$temp[0],0);//前臂 point, 约束。约束权重由,FKIK 的 blender属性控制$temp = `pointConstraint -mo -weight 1 $fk[1] $fk[2]  $ik[1] $ik[2] $skForeArmRoll `;//获取约束上的权重属性$constrWeightAttrName = `listAttr -ud $temp[0]`;connectAttr -force ($setRange+".outValueX") ($temp[0]+"."+$constrWeightAttrName[0]);connectAttr -force ($setRange+".outValueX") ($temp[0]+"."+$constrWeightAttrName[1]);connectAttr -force ($setRange+".outValueY") ($temp[0]+"."+$constrWeightAttrName[2]);connectAttr -force ($setRange+".outValueY") ($temp[0]+"."+$constrWeightAttrName[3]);//-----------------------创建并设置节点---------------------------------//创建  blendColors 混合节点四个    $skForeArmRoll_r_BC = `shadingNode -au -n ($preSuffix +"_skForeArmRoll_r_BC") blendColors`;    $wrist_rYZ_BC = `shadingNode -au -n ($preSuffix +"_wrist_rYZ_BC") blendColors`;//创建 multiplyDivide 乘除节点    $foreArmRoll_MD = `shadingNode -au -n ($preSuffix +"_foreArmRoll_MD") multiplyDivide`;$wrist_MD = `shadingNode -au -n ($preSuffix +"_wrist_MD") multiplyDivide`;//设置并连接setAttr ($foreArmRoll_MD + ".input2X") .3;setAttr ($wrist_MD + ".input2X") .7;//FKIK控制器的 FKIKblender 控制融合,骨头的rx 连给融合connectAttr -force ($setRange+".outValueX") ($skForeArmRoll_r_BC + ".b");connectAttr -force ($fk[2]+".rx") ($skForeArmRoll_r_BC + ".c1r");connectAttr -force ($ik[2]+".rx") ($skForeArmRoll_r_BC + ".c2r");//从fk,ik骨头上取来的rx,融合后,连给 各自己的乘除节点connectAttr -force ($skForeArmRoll_r_BC+".outputR") ($foreArmRoll_MD + ".input1X");connectAttr -force ($skForeArmRoll_r_BC+".outputR") ($wrist_MD + ".input1X");//前臂和手腕的rx 分别连到 sk 骨头。connectAttr -force ($foreArmRoll_MD + ".outputX") ($skForeArmRoll + ".rx");connectAttr -force ($wrist_MD + ".outputX") ($sk[2] + ".rx");//肘的 s 连给 前臂connectAttr -force ($sk[1] + ".s") ($skForeArmRoll + ".s");//手腕的 FKIK 的r YZ 连给 融合,融合连给 sk 骨头 connectAttr -force ($setRange+".outValueX") ($wrist_rYZ_BC + ".b");connectAttr -force ($fk[2] + ".ry") ($wrist_rYZ_BC + ".c1g");connectAttr -force ($ik[2] + ".ry") ($wrist_rYZ_BC + ".c2g");connectAttr -force ($fk[2] + ".rz") ($wrist_rYZ_BC + ".c1b");connectAttr -force ($ik[2] + ".rz") ($wrist_rYZ_BC + ".c2b");connectAttr -force ($wrist_rYZ_BC + ".outputG") ($sk[2] + ".ry");connectAttr -force ($wrist_rYZ_BC + ".outputB") ($sk[2] + ".rz");return 1;}proc int blendFKIKUI(){string $sel[] = `ls -sl`;string $fk[] = {$sel[0],$sel[1],$sel[2]};string $ik[] = {$sel[3],$sel[4],$sel[5]};string $sk[] = {$sel[6],$sel[7],$sel[8]};string $skForeArmRoll = $sel[9];blendFKIK($fk,$ik,$sk,$skForeArmRoll,"L_arm_FKIK_ctrl.FKIK_blend","L_arm");if (`window -ex blendFKIK_win` == true)    {        deleteUI -window renameCtrls_win;    }     window -t "blendFKIK by Jerry" -wh 300 200 blendFKIK_win;        columnLayout -adj 1 -co "both" 5;        string $rcLayout = `rowColumnLayout -nc 2 -cw 1 195 -cw 2 80`;            string $ctrlName= `textField -h 40 -tx " " ctrlName`;            string $getCtrlName= `button -h 40 -l "getCtrlName" -c "string $selected[] = `ls -sl`;textField -e -tx $selected[0] ctrlName;" $getCtrlName`;        setParent ..;checkBoxGrp -ncb 1 -l "parent" -v1 1 parentCheckBoxGrp;        button -l "Move and Rename Ctrls" -h 100 -c "renameCtrls(`ls -sl`,\"ctrl\",`checkBoxGrp -q -v1 parentCheckBoxGrp`)";    showWindow blendFKIK_win;    window -e -wh 300 200 blendFKIK_win;     return 1;}//----------------------------任意三个对象 创建约束,并创建融合---------------------------------proc int createBlend4Constraint(string $tfg1, string $tfg2, string $tfg3, string $tfg4, string $tfg5){string $reverseName, $temp[];string $w0 = `textFieldButtonGrp -q -tx $tfg1`;string $w1 = `textFieldButtonGrp -q -tx $tfg2`;string $target = `textFieldButtonGrp -q -tx $tfg3`;string $blendAttr = `textFieldButtonGrp -q -tx $tfg4`;string $constraintType = `textFieldGrp -q -tx $tfg5`;string $obj_attr[];$numTokens = `tokenize $blendAttr "." $obj_attr`;if ($numTokens != 2){error "  obj.attr ";}if (!`attributeExists $obj_attr[1] $obj_attr[0]`){catch(`addAttr -ln $obj_attr[1]  -at double  -min 0 -max 1 -dv 0 $obj_attr[0]`);catch(`setAttr -e -keyable true $blendAttr`);}switch ($constraintType){case "p":$temp = `parentConstraint -mo -weight 1 $w0 $w1 $target`;break;case "t":$temp = `pointConstraint -mo -weight 1 $w0 $w1 $target`;break;case "r":$temp = `orientConstraint -mo -weight 1 $w0 $w1 $target`;break;case "s":$temp = `scaleConstraint -mo -weight 1 $w0 $w1 $target`;break;default:warning "ConstraintType : (p, t, r, s)";break;}createConstraintBlend($w0,$w1,$temp[0],$blendAttr,0);select -r $target;return 1;}proc int createBlend4ConstraintUI(){if (`window -ex createBlend_win` == true)    {        deleteUI -window createBlend_win;    }     window -t "Create Constraint Blend by Jerry" -wh 300 200 createBlend_win; columnLayout -adj true;$tfg1 = `textFieldButtonGrp -l "Object 1 (blender=0):" -bl "Load Sel"`;$tfg2 = `textFieldButtonGrp -l "Object 2 (blender=1):" -bl "Load Sel"`;text -l "";$tfg3 = `textFieldButtonGrp -l "Target Object:" -bl "Load Sel"`;$tfg5 = `textFieldGrp -l "ConstraintType (p, t, r, s): "`;text -l "";$tfg4 = `textFieldButtonGrp -l "Driver (Attribute):" -bl "Load Sel"`;button -l "Go" -h 35 -c ("createBlend4Constraint " + $tfg1 + " " + $tfg2 + " " + $tfg3 + " " + $tfg4 + " " + $tfg5 );textFieldButtonGrp -e -bc ("string $sel[];$sel=`ls -sl`;textFieldButtonGrp -e -tx $sel[0] "  + $tfg1) $tfg1;;textFieldButtonGrp -e -bc ("string $sel[0];$sel=`ls -sl`;textFieldButtonGrp -e -tx $sel[0] "  + $tfg2) $tfg2;textFieldButtonGrp -e -bc ("string $sel[0];$sel=`ls -sl`;textFieldButtonGrp -e -tx $sel[0] "  + $tfg3) $tfg3;textFieldButtonGrp -e -bc ("string $sel[0] = `ls -sl`;select -r $sel[0];global string $gChannelBoxName; string $attrList[] = `channelBox -q -sma $gChannelBoxName`; textFieldButtonGrp -e -tx ($sel[0] + \".\" +  $attrList[0]) "  + $tfg4) $tfg4;showWindow createBlend_win;    window -e -wh 450 220 createBlend_win;return 1;}//createBlend4ConstraintUI();//-----------------------------------为FK控制器 创建 Global-------------------------------------proc int createGlobal(string $ctrlName,string $main_ctrl){//判断 $main_ctrl  在不在select -r $main_ctrl;//判断 global 系统组在不在    if (!`objExists "global_grp"`)    {parent `group -em -n "global_grp"` $main_ctrl;    }//防万一,清一遍catch(delete($ctrlName+"_global_loc"));catch(delete($ctrlName+"_global_loc_offset"));catch(ungroup($ctrlName+"_global"));catch(ungroup($ctrlName+"_globalStatic"));//在控制器上添加属性catch (`deleteAttr -attribute "global" $ctrlName`);catch(`addAttr -ln "global"  -at double  -min 0 -max 10 -dv 0 $ctrlName`);catch(`setAttr -e -keyable true ($ctrlName + ".global")`);//如果控制器上有offset组,那么在这个组上操作string $temp[],$ctrlNameGrp;$temp = `listRelatives -p $ctrlName`;if ($temp[0] == ($ctrlName+"_grp")){$ctrlNameGrp = ($ctrlName+"_grp");}else{$ctrlNameGrp = $ctrlName;}//控制器上打上两层组group -em -n ($ctrlName+"_global") ;group -n ($ctrlName+"_globalStatic");$temp = `parentConstraint -weight 1 $ctrlName ($ctrlName+"_globalStatic")`;delete $temp[0];$temp = `listRelatives -p $ctrlName`;parent $ctrlName ($ctrlName+"_global");parent ($ctrlName+"_globalStatic") $temp[0];//创建 global 全局定位的空组group -em -n ($ctrlName+"_global_loc");parent `group -n ($ctrlName+"_global_loc_offset")` global_grp;$temp = `parentConstraint -weight 1 $ctrlName ($ctrlName+"_global_loc_offset")`;delete $temp[0];$temp = `orientConstraint -mo -weight 1 ($ctrlName+"_globalStatic") ($ctrlName+"_global_loc") ($ctrlName+"_global")`;createConstraintBlend(($ctrlName+"_globalStatic"),($ctrlName+"_global_loc"),$temp[0],($ctrlName+".global"),0);select -r $ctrlName;return 1;}proc int createGlobalUI(){string $selected[] = `ls -sl`;createGlobal($selected[0],"main_ctrl");return 1;}//-----------------------------------为IK控制器 创建 follow-------------------------------------proc int createFollow(string $ctrlName,string $followYou, string $main_ctrl, string $ctrlType) //$ctrlType = "follow"{//判断 $main_ctrl  在不在select -r $main_ctrl;//判断 $ctrlType 系统组在不在    if (!`objExists ($ctrlType+"_grp")`)    {parent `group -em -n ($ctrlType+"_grp")` $main_ctrl;    }//在控制器上添加属性if (!`attributeExists $ctrlType $ctrlName`){catch(`addAttr -ln $ctrlType  -at double  -min 0 -max 10 -dv 0 $ctrlName`);catch(`setAttr -e -keyable true ($ctrlName + "." + $ctrlType)`);}//防万一,清一遍if (`objExists ($ctrlName+"_"+ $ctrlType + "_loc")`)delete($ctrlName+"_"+ $ctrlType + "_loc");if (`objExists ($ctrlName+"_"+ $ctrlType + "_loc_offset")`)delete($ctrlName+"_"+ $ctrlType + "_loc_offset");if (`objExists ($ctrlName+"_"+ $ctrlType)`){//parent `group -em` ($ctrlName+"_"+ $ctrlType);delete(listConnections ($ctrlName+"_"+ $ctrlType+".rx"));delete(listConnections ($ctrlName+".follow"));select -r ($ctrlName+"_"+ $ctrlType);if (size(`listRelatives -c ($ctrlName+"_"+ $ctrlType)`) == 0){delete ($ctrlName+"_"+ $ctrlType);}else{ungroup ($ctrlName+"_"+ $ctrlType);}}//控制器上打组group -em -n ($ctrlName+"_" + $ctrlType) ;//group -n ($ctrlName+"_"+ $ctrlType + "Static");$temp = `parentConstraint -weight 1 $ctrlName ($ctrlName+"_" + $ctrlType)`;delete $temp[0];//判断是否在世界空间下$temp = `listRelatives -f -p $ctrlName`;parent $ctrlName ($ctrlName+"_" + $ctrlType);if (size($temp)==1){parent ($ctrlName+"_" + $ctrlType) $temp[0];}//创建 global 全局定位的空组group -em -n ($ctrlName+"_"+ $ctrlType + "_loc");parent `group -n ($ctrlName+"_"+ $ctrlType + "_loc_offset")` ($ctrlType+"_grp");$temp = `parentConstraint -weight 1 $ctrlName ($ctrlName+"_"+ $ctrlType + "_loc_offset")`;delete $temp[0];$temp = `parentConstraint -mo -weight 1 $followYou ($ctrlName+"_"+ $ctrlType + "_loc") ($ctrlName+"_"+ $ctrlType)`;createConstraintBlend(($ctrlName+"_"+ $ctrlType + "_loc"),$followYou,$temp[0],($ctrlName+"."+ $ctrlType),1);select -r $ctrlName;return 1;}proc int createFollowUI(){string $selected[] = `ls -sl`;createFollow($selected[0],$selected[1],"main_ctrl","follow");return 1;}//批量约束global proc int autoParentConstraint(){//约束string $sels[] = `ls -sl`;int $selSize,$halfSize; $selSize = size($sels);$halfSize = $selSize/2;if ( ($selSize % 2) != 0){error "成对选择,方可关联";} int $i,$selSize;for ($i = 0 ; $i < $halfSize; $i++ ){print ($i + " / " +  ($i+$halfSize-1) + " / " +  $halfSize + "n");// CBdeleteConnection ($sels[($i+$halfSize)] + ".r");//connectAttr -f ($sels[$i]+".r") ($sels[$i+$halfSize]+".r");parentConstraint -mo -weight 1 $sels[$i] $sels[$i+$halfSize];}return 1;}//============================ 主 UI ===================================//=================jerryRigAssistant=================global proc int jerryRigAssistant(){    if (`window -ex jerryRigAssistant_win` == true)    {        deleteUI -window jerryRigAssistant_win;    }     window -t "Jerry Rig Assistant"  jerryRigAssistant_win;        columnLayout -adj 1 -co "both" 5;         text -label "Rig Assistant" -align "center" -h 30 -fn "boldLabelFont";        button -l "Move and Rename Ctrls" -h 35 -c "renameCtrlsUI()";        button -l "Grp Selected Objects" -h 35 -c "grp_selectedObjs(`ls -sl`,\"_grp\")" -ann "选:所有要打组的对象。执行";//打组功能未完全。要加个UI。做后缀判断button -l "Create IK 4 Arm" -h 35 -c "createArmIkRPsolverUI()" -ann "选:IK_ctrl, Pole_ctrl, $jntStart, $jntEnd。执行";button -l "Create IK 4 Leg" -h 35 -c "createLegIkRPsolverUI()" -ann "选:IK_ctrl, Pole_ctrl, $jntStart, $jntEnd。执行"; button -l "Create IK Stretchy" -h 35 -c "ikStretchyUI()" -ann "选:IK_ctrl, Pole_ctrl, $jntStart, $jntMid, $jntEnd。执行";button -l "Create Blend Constraint" -h 35 -c "createBlend4ConstraintUI()";button -l "Create Global" -h 35 -c "createGlobalUI()" -ann "选:控制器。执行";button -l "Create Follow" -h 35 -c "createFollowUI()" -ann "选:跟随对象、跟随目标。执行";button -l "Blend FKIK" -h 35 -c "blendFKIKUI()" -ann "选:fk123,ik123,sk1243 创建FKIK约束。执行";//button -l "attrA switch attrB,C" -h 35 -c "attrA_switch_attrBattrC_UI()";//button -l "attrA ctrl attrB,C" -h 35 -c "attrA_ctrl_attrBattrC_UI()";button -l "批量做父子约束" -h 35 -c "autoParentConstraint()"  -ann "批量做父子约束";    showWindow jerryRigAssistant_win;    return 1;}jerryRigAssistant();


原创粉丝点击