/* ----- skinAssist 1.0 ----- ----- By Ced ----- skinAssist is an helper to assisste your skinning. You can assign rapidely weight, you have just to select joint... operations on weight : import/export, reskin, etc.... */ //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc skinAssist() { //UI global string $skin2sel_nameOfJoints[]; int $optionEnable = 1; if ((`window -ex skinAss`) == true) deleteUI skinAss; window -t "skAssistant" -h 240 -width 140 -resizeToFitChildren true skinAss ; // string $form = `formLayout`; string $tabs = `tabLayout -innerMarginWidth 2 -innerMarginHeight 2 -w 50`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachForm $tabs "bottom" 0 -attachForm $tabs "right" 0 $form; string $child1 = `columnLayout -adjustableColumn true`; if ($skin2sel_nameOfJoints[0] == "") $optionEnable = 0; text "skinAssisst1.0 by Cedric"; separator -h 15; checkBoxGrp -numberOfCheckBoxes 1 -cw2 80 50 -label "Auto weight" -value1 false useWeigt; floatFieldGrp -numberOfFields 1 -cw2 80 50 -label "1st weight" -precision 2 -value1 1 weightField; rowLayout -numberOfColumns 5 -cw 1 28 -cw 2 28 -cw 3 28 -cw 4 28 -cw 5 28; button -h 15 -w 28 -l "0" -c "floatFieldGrp -e -value1 0 weightField;"; button -h 15 -w 26 -l ".25" -c "floatFieldGrp -e -value1 .25 weightField;"; button -h 15 -w 26 -l ".5" -c "floatFieldGrp -e -value1 .5 weightField;"; button -h 15 -w 26 -l ".75" -c "floatFieldGrp -e -value1 .75 weightField;"; button -h 15 -w 28 -l "1" -c "floatFieldGrp -e -value1 1 weightField;"; setParent ..; separator -style "none" -h 10; button -l "select joints" -c "skin2sel_store"; button -h 30 -en $optionEnable -bgc 0.3 1 0.3 -l "Assign" -c "skin2sel_create"; separator -h 10 ; text -align "center" -l "------JOINTS LIST:-------"; textScrollList -h 155 -allowMultiSelection false -doubleClickCommand "select -r `textScrollList -q -si jointList`;" jointList; setParent ..; string $child2 = `columnLayout -adjustableColumn true`; text -align "center" -l "Vertices in Clipboard"; textScrollList -h 55 -allowMultiSelection false -doubleClickCommand "select -r `textScrollList -q -si VertexList`;" VertexList; button -l "copy Weight on Clipboard" -c "copyWeightOnClipboard;"; separator -h 20; button -l "paste weight" -c "copyWeight;"; separator -h 20; floatFieldGrp -numberOfFields 1 -cw2 80 30 -ann "factor of average for the 1st vertex" -label "factor" -value1 1 factorField; button -l "average weight" -c "averageWeight"; separator -h 20; button -l "delete nonSkin history" -c "deleteNoSkin"; button -l "Reskin" -c "ReSkin"; button -l "Transfert skin" -c "TransferSkin"; setParent ..; string $child3 = `columnLayout -adjustableColumn true`; button -l "WS skin export" -c "aeSkinWeightExportWorldSpace"; button -l "WS skin import" -c "aeSkinWeightImportWorldSpaceUI"; separator -h 20; button -l "by index skin export" -c "exportSkinWeights"; button -l "by index skin import" -c "importSkinWeights"; separator -h 20; button -l "cluster export" -c "exportClusterWeights"; button -l "cluster import" -c "importClusterWeights"; separator -h 20; button -l "comet Save Weight" -c "cometSaveWeights;"; setParent; tabLayout -edit -tabLabel $child1 "Assign" -tabLabel $child2 "Edit" -tabLabel $child3 "impot/Export" $tabs; showWindow skinAss; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc copyWeightOnClipboard() { string $sels[] = `filterExpand -sm 31 -ex 1`; global int $newClipboard; textScrollList -e -ra VertexList; textScrollList -e -append $sels[0] VertexList; textScrollList -e -append $sels[1] VertexList; textScrollList -e -append $sels[2] VertexList; textScrollList -e -append $sels[3] VertexList; textScrollList -e -sii 1 VertexList; $newClipboard = 1; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc skin2sel_store() { //global string $skin2sel_nameOfJoints[]; string $sels[] = `ls -sl -typ "joint"`; //if (`size ($sels)` > 1) error "please select only ONE object"; int $i=0; textScrollList -e -ra jointList; for ( $sel in $sels ) { textScrollList -e -append $sels[$i] jointList; $i++; } textScrollList -e -sii 1 jointList; //$skin2sel_nameOfJoints = $sels; //print $skin2sel_nameOfJoints; //skinAssist; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc skin2sel_create() { int $useWeight = `checkBoxGrp -q -value1 useWeigt`; float $weight = `floatFieldGrp -q -value1 weightField`; int $i; string $msg = ""; // string $skin2sel_nameOfJoints[] = `textScrollList -q -ai jointList`; string $joints[] = $skin2sel_nameOfJoints; // int $indexOfItem[] = `textScrollList -q -sii jointList`; //get selected transforms, verts, or NURBS cv's. Anything not covered, you'll want to add it here string $toWeight[] = `ls -sl -exactType "transform" -exactType "float3" -exactType "double3"`; float $jointCount = size($joints); string $cur, $curJoint; //iterate through selected verts or objects for($cur in $toWeight) { //we need to get the shape node so we can get the skin cluster string $tok[]; tokenize $cur "." $tok; string $nameSkinCluster = `findRelatedSkinCluster $tok[0]`; if($nameSkinCluster == "") error -showLineNumber true ($cur + " is not connected to a skin cluster"); //zero out all the weights skinPercent -nrm 0 -prw 100 $nameSkinCluster $cur; //iterate through joints if ($useWeight == 1) { $msg = ("//weight set at "+(1 / $jointCount)+" for: - "); for($curJoint in $joints) { skinPercent -nrm 0 -tv $curJoint (1 / $jointCount) $nameSkinCluster $cur; $msg+=($curJoint+" - "); } $msg+="\n"; } else { $i=1; //if ($jointCount==1) error "//please select a least TWO joints"; for($curJoint in $joints) { if ($i==$indexOfItem[0]) { skinPercent -nrm 0 -tv $curJoint($weight) $nameSkinCluster $cur; $msg = ("//weight set at "+($weight)+" for: "+$curJoint); } else { skinPercent -nrm 0 -tv $curJoint((1-$weight)/($jointCount-1)) $nameSkinCluster $cur; $msg+= (" / at "+((1-$weight)/($jointCount-1))+" for: "+$curJoint); } $i++; } $msg+="\n"; } print $msg; //this command should be unnessisary, but in case there's some error //in setting the weights this will make sure they're all still adding up to 1 skinPercent -nrm 1 $nameSkinCluster $cur; } } //------------------------------------------------------------------------------- //------------------------------------------------------------------------------- global proc takeWeight() { string $whatIs[] = `textScrollList -q -ai VertexList`; int $i = 0; global int $newClipboard; global float $skinAssClipboard1[]; global float $skinAssClipboard2[]; global float $skinAssClipboard3[]; global float $skinAssClipboard4[]; clear $skinAssClipboard1; clear $skinAssClipboard2; clear $skinAssClipboard3; clear $skinAssClipboard4; string $tok[]; tokenize $whatIs[0] "." $tok; string $nameSkinCluster = `findRelatedSkinCluster $tok[0]`; for ($singleWhatIs in $whatIs ) { if ($i==0) $skinAssClipboard1 = `skinPercent -v -q $nameSkinCluster $singleWhatIs`; if ($i==1) $skinAssClipboard2 = `skinPercent -v -q $nameSkinCluster $singleWhatIs`; if ($i==2) $skinAssClipboard3 = `skinPercent -v -q $nameSkinCluster $singleWhatIs`; if ($i==3) $skinAssClipboard4 = `skinPercent -v -q $nameSkinCluster $singleWhatIs`; $i++; } print "// take weight....\n"; $newClipboard = 0; /* print "put in clipboard : \n"; print $whatIs; print "values : \n"; print $skinAssClipboard1; print "----------------------\n"; print $skinAssClipboard2; print "----------------------\n"; print $skinAssClipboard3; print "----------------------\n"; print $skinAssClipboard4; print "----------------------\n"; */ } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc copyWeight() { string $swSelection[] = `ls -sl`; global float $skinAssClipboard1[]; global float $skinAssClipboard2[]; global float $skinAssClipboard3[]; global float $skinAssClipboard4[]; global int $newClipboard; if ( $newClipboard == 1 ) takeWeight; string $tok[]; tokenize $swSelection[0] "." $tok; string $nameSkinCluster = `findRelatedSkinCluster $tok[0]`; string $getNames[] = `skinPercent -q -t $nameSkinCluster $swSelection[0]`; int $indexOfItem[] = `textScrollList -q -sii VertexList`; int $i = 0; for ($singleSwSelection in $swSelection) { skinPercent -normalize off $nameSkinCluster $singleSwSelection; $i = 0; for ($getName in $getNames) { if ($indexOfItem[0] == 1) skinPercent -tv $getName $skinAssClipboard1[$i] $nameSkinCluster $singleSwSelection; if ($indexOfItem[0] == 2) skinPercent -tv $getName $skinAssClipboard2[$i] $nameSkinCluster $singleSwSelection; if ($indexOfItem[0] == 3) skinPercent -tv $getName $skinAssClipboard3[$i] $nameSkinCluster $singleSwSelection; if ($indexOfItem[0] == 4) skinPercent -tv $getName $skinAssClipboard4[$i] $nameSkinCluster $singleSwSelection; $i++; } print ("// Copy weight on " + $singleSwSelection + "\n"); skinPercent -normalize on $nameSkinCluster $singleSwSelection; } } //--------------------------------------------------------------------- //--------------------------------------------------------------------- global proc averageWeight() { string $swSelection[] = `ls -sl`; float $factorAv = `floatFieldGrp -q -value1 factorField`; global float $skinAssClipboard1[]; global float $skinAssClipboard2[]; global float $skinAssClipboard3[]; global float $skinAssClipboard4[]; float $result[]; float $somme[]; float $factorAv1=1; float $factorAv2=1; float $factorAv3=1; float $factorAv4=1; string $whatIs[] = `textScrollList -q -ai VertexList`; int $sizeWhatIs = `size ($whatIs)`; int $indexOfItem[] = `textScrollList -q -sii VertexList`; takeWeight; string $tok[]; tokenize $swSelection[0] "." $tok; string $nameSkinCluster = `findRelatedSkinCluster $tok[0]`; string $getNames[] = `skinPercent -q -t $nameSkinCluster $swSelection[0]`; //calcul des poids if ($indexOfItem[0] == 1) $factorAv1 = $factorAv; if ($indexOfItem[0] == 2) $factorAv2 = $factorAv; if ($indexOfItem[0] == 3) $factorAv3 = $factorAv; if ($indexOfItem[0] == 4) $factorAv4 = $factorAv; $i = 0; for ( $single_skinAssClipboard1 in $skinAssClipboard1 ) { $somme[$i] = ($skinAssClipboard1[$i]*$factorAv1) + ($skinAssClipboard2[$i]*$factorAv2) + ($skinAssClipboard3[$i]*$factorAv3) + ($skinAssClipboard4[$i]*$factorAv4); $result[$i] = $somme[$i] / ($sizeWhatIs + ($factorAv-1)); $i++; } // int $i = 0; for ($singleSwSelection in $swSelection) { skinPercent -normalize off $nameSkinCluster $singleSwSelection; $i = 0; for ($getName in $getNames) { skinPercent -tv $getName $result[$i] $nameSkinCluster $singleSwSelection; $i++; } print ("// average weight on " + $singleSwSelection + "\n"); skinPercent -normalize on $nameSkinCluster $singleSwSelection; } } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- // thanks to Horvatth Szabolcs global proc sz_ReturnComponentSelectionInOrderBis () { global string $compSelection2[]; string $selectionAll[] = `filterExpand -ex 1 -sm 31`; float $sizeSelection = `size $selectionAll`; //print $sizeSelection; string $selection[]; string $realSelection[]; string $buffer[]; string $lastCommand = `undoInfo -q -un`; int $counter = 0; //print ("last command " + $lastCommand + " counter " + $counter + "\n"); //while ((`match "select" $lastCommand` != "") || (`match "select" $lastCommand` == "select -cl ")) for ($i = 0; $i < $sizeSelection; $i++) { $lastCommand = `undoInfo -q -un`; //print ("last command " + $lastCommand + " counter " + $counter + "\n"); if (`match "select" $lastCommand` != "") { tokenize $lastCommand " " $buffer; $selection [$counter] = $buffer[2]; $counter++; undo; } } select $selectionAll; print " selection \n"; print $selection; print "----\n"; for ($i = ((`size $selection`)-1); $i >= 0; $i--) $realSelection [$i] = $selection[(`size $selection` - $i)-1]; //print $realSelection; float $sizeRealSelection = `size $realSelection`; if ($sizeRealSelection == 0) { print "tout vide\n"; } else { clear $compSelection2; $compSelection2 = $realSelection; } print $compSelection2; //return $realSelection; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc deleteNoSkin() { string $sel[] = `ls -sl`; string $dup[] = `duplicate`; select -r $sel[0]; select -add $dup[0]; TransferSkin; select -r $sel[0]; delete; rename $dup[0] $sel[0]; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- //thanks to mathieu thinzus... global proc TransferSkin () { string $sel[]; string $selShape1[]; string $selShape2[]; string $skinCluster[]; string $joints[]; string $selJoints[]; string $skinClusterSource[]; string $skinClusterDestination[]; int $sizeJoints; $sel = `ls -sl`; print ($sel[0]+": is the Source\n"); print ($sel[0]+": is the Destination \n"); if (`size $sel`==2 ) { $selShape1 = `listRelatives -s $sel[0]`; $selShape2 = `listRelatives -s $sel[1]`; // $skinClusterSource = `listConnections -d 0 -s 1 -t skinCluster $selShape1[0]`; $skinClusterSource[0] = `DetectSc $sel[0]`; if (`size $skinClusterSource`==0) { warning "select first the skinned object and then the destination one !"; } else { $joints = `listConnections -t joint $skinClusterSource[0]`; $sizeJoints = `size $joints`; print ( $sel[0]+" is skined to "+($sizeJoints/2)+" joints\n"); for ($i=0;$i<($sizeJoints/2);$i++) { $selJoints[$i] = $joints[$i]; } select -r $selJoints; skinCluster -tsb $selJoints $sel[1]; $skinClusterDestination = `listConnections -d 0 -s 1 -t skinCluster $selShape2[0]`; copySkinWeights -ss $skinClusterSource[0] -ds $skinClusterDestination[0] -noMirror; select -cl; select -r $sel[1]; print ( "skin transfered from :"+$sel[0]+" to:"+$sel[1]+"\n"); } } if (`size $sel`== 1 ) { warning "select a source then a destination oject !"; } if (`size $sel`== 0 ) { warning "nothing selected !"; } } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc ReSkin() { string $sel[]; string $selShape[]; string $skinCluster; string $bindPose[]; string $joints[]; string $selJoints[]; string $history[]; int $sizeJoints; $sel = `ls -sl`; print "----------------------------\n"; if (`size $sel`<1 ) { warning "nothing selected !"; } if (`size $sel`>1 ) { warning "plz select only ONE object"; } else { $selShape = `listRelatives -s $sel`; $skinCluster = `DetectScX`; $joints = `listConnections -t joint $skinCluster`; $sizeJoints = `size $joints`; for ($i=0;$i<($sizeJoints/2);$i++) { $selJoints[$i] = $joints[$i]; } $bindPose = `listConnections -d 1 -s 0 -t dagPose $joints[0]`; if (`size $bindPose[0]`>0) { delete $bindPose[0]; print ($bindPose[0]+" deleted !\n"); } else { print "no bindPose to delete!\n"; } skinCluster -e -ubk $selShape[0]; select -r $selJoints ; skinCluster -tsb $selJoints $sel[0]; print ($sel[0]+": has been reSkinned\n"); select -r $sel; } } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc string DetectScX() { string $sel[]= `ls -sl`; string $history[] = `listHistory $sel`; string $skinCluster[]=`ls -et skinCluster $history`; return $skinCluster[0]; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- global proc string DetectSc(string $name) { string $selSize = `size $name`; if ($name != "") { string $history[] = `listHistory $name`; string $skinCluster[]=`ls -et skinCluster $history`; return $skinCluster[0]; } else { string $sel[]= `ls -sl`; string $history[] = `listHistory $sel`; string $skinCluster[]=`ls -et skinCluster $history`; return $skinCluster[0]; } } //ze end...