Oto działający kod:
if(`window -exists "addFKControl"`)
deleteUI "addFKControl";
if(`windowPref -exists "addFKControl"`)
windowPref -r "addFKControl";
window -rtf true -title "Add FK Controller" addFKControl;
columnLayout -rowSpacing 5 addFKControlColumn1;
intSliderGrp -label "Number of sides" -field true -minValue 3 -maxValue 32 -value 4 FKnumber;
intSliderGrp -label "Height divisions" -field true -minValue 1 -maxValue 32 -value 1 FKheight;
floatSliderGrp -label "Radius" -field true -minValue .0001 -maxValue 2 -value 1 FKradius;
text -label "Controller Orientation";
separator -ann "Controller Orientation" -w 250;
radioCollection addFKRadioGrp1;
rowLayout -numberOfColumns 3 addFKControlRow1;
radioButton -label "+X" posX;
radioButton -label "+Y" posY;
radioButton -label "+Z" posZ;
setParent ..;
rowLayout -numberOfColumns 3 addFKControlRow2;
radioButton -label "-X" negX;
radioButton -label "-Y" negY;
radioButton -label "-Z" negZ;
setParent ..;
separator -w 250;
button -c "addFKControlPrep" -label "Create";
setParent ..;
showWindow addFKControl;
radioCollection -e -sl posX addFKRadioGrp1;
// Preparation phase
global proc addFKControlPrep(){
$sel = `ls -sl`;
string $a;
float $length;
// See if we have anything selected
if (size($sel) == 0){
error "Select a target";
}
// Recurence trough selection
for($a in $sel){
$child = `listRelatives -c $a`;
if (size($child) > 0 && nodeType($child[0]) == "joint"){ // If the target is a joint calculate the length
float $componentX = `getAttr ($child[0] + ".tx")`;
float $componentY = `getAttr ($child[0] + ".ty")`;
float $componentZ = `getAttr ($child[0] + ".tz")`;
$length = `mag (>)`;
} else { // If not - set length to 1
$length = 1;
}
int $nGon = `intSliderGrp -q -value "FKnumber"`; // Read values
int $height = `intSliderGrp -q -value "FKheight"`;
float $rad = `floatSliderGrp -q -value "FKradius"`;
string $orient = `radioCollection -q -sl addFKRadioGrp1`;
addFKControl( $nGon, $height, $length, $rad, $a, $orient); // Make the main function
}
}
global proc string addFKControl ( int $nGon, int $height, float $len , float $radius, string $targetName, string $orient) {
string $name = $targetName + "_FK_control";
float $vertCoords[] = {};
string $command = "curve -d 1 ";
float $step = 360/$nGon;
float $angle = 0 - ($step/2);
string $endcommand = " ";
for ($a = 0; $a $angle +=$step;
float $resultX = (`cos (deg_to_rad($angle))`) * $radius;
float $resultY = (`sin (deg_to_rad($angle))`) * $radius;
$vertCoords[($a*2)] = $resultX;
$vertCoords[($a*2) + 1] = $resultY;
}
$vertCoords[$nGon*2] = $vertCoords[0];
$vertCoords[($nGon*2)+1] = $vertCoords[1];
for ($n = 0; $n float $div = 1.0;
float $flHeight = ($height/$len) * 1.0;
int $count = 0;
for ($a = 0; $a float $div = `floor($n/$nGon)`;
$command += "-p " + $vertCoords[($a*2)] + " " + ($n/$flHeight) + " " + $vertCoords[($a*2) + 1] + " ";
$command += "-p " + $vertCoords[(($a+1)*2)] + " " + ($n/$flHeight) + " " + $vertCoords[(($a+1)*2) + 1] + " ";
$command += "-p " + $vertCoords[(($a+1)*2)] + " " + (($n+1)/$flHeight) + " " + $vertCoords[(($a+1)*2) + 1] + " ";
$command += "-p " + $vertCoords[($a*2)] + " " + (($n+1)/$flHeight) + " " + $vertCoords[($a*2) + 1] + " ";
$command += "-p " + $vertCoords[($a*2)] + " " + ($n/$flHeight) + " " + $vertCoords[($a*2) + 1] + " ";
$count = $a;
}
$command += "-p " + $vertCoords[($count*2)] + " " + (($n + 1)/$flHeight) + " " + $vertCoords[($count*2) + 1] + " ";
}
$command += $endcommand;
$command += " -n ";
$command += $name;
$curveNode = `eval ($command)`;
$curveNodeShape = `listRelatives -c $curveNode`;
rename $curveNodeShape ($curveNode + "Shape");
if ($orient == "posX"){
setAttr ($curveNode + ".rotateZ") -90;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $curveNode;
}
if ($orient == "negX"){
setAttr ($curveNode + ".rotateZ") 90;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $curveNode;
}
if ($orient == "negY"){
setAttr ($curveNode + ".rotateZ") 180;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $curveNode;
}
if ($orient == "posZ"){
setAttr ($curveNode + ".rotateX") 90;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $curveNode;
}
if ($orient == "negZ"){
setAttr ($curveNode + ".rotateZ") -90;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $curveNode;
}
$controlOrient = `group -em -n ($targetName + "_FK_control_orient")`;
setAttr ($controlOrient + ".scalePivotX") ($radius / 10);
setAttr ($controlOrient + ".scalePivotY") ($radius / 10);
setAttr ($controlOrient + ".scalePivotZ") ($radius / 10);
parent $curveNode $controlOrient;
copyMatrixAddFK ($targetName, $controlOrient, 1);
// Set proper rotation order.
setAttr ($curveNode + ".rotateOrder") (`getAttr ($targetName + ".rotateOrder")`);
return $curveNode;
}
global proc copyMatrixAddFK( string $sourceObj, string $targetObj, int $worldSpace){
string $command;
float $sourceMatrix[];
if($worldSpace == 1){
$sourceMatrix = `xform -q -ws -m $sourceObj`;
$command = "xform -ws -m ";
} else {
$sourceMatrix = `xform -q -os -m $sourceObj`;
$command = "xform -os -m ";
}
string $matrix;
string $a;
for($a in $sourceMatrix){
$matrix += $a;
$matrix += " ";
}
$command += $matrix;
$command += $targetObj;
eval($command);
};
Wszystko pięknie bangla. Istny miodek. Big Thx Kroopson za skrypt.