global proc getDPQWin()


【资料图】

{

string $window=`window -title "关键帧相对偏移工具"

-iconName "KeyframeOffsetTool"

-dockStation

-nestedDockingEnabled true

-dockCorner "topLeft" "left"`;

columnLayout -adjustableColumn false;

text "1.关闭自动k帧";

button -label "关闭自动k帧" -command("autoKey 0");

text "2.选择需要偏移的控制器:";

button -label "选择控制器" -command("selectCtrls");

textField -ed 0 -w 400 -backgroundColor 0.2 0.2 0.2 ctrlsName;

text "3.记录控制器变换";

button -label "记录控制器变换属性" -command("recordTransforms");

text "4.将控制器移动到相对位置";

text "5.开始转换:";

checkBox -label "相对旋转(不推荐)" -v 0 rotateBox;

checkBox -label "相对位移" -v 1 translateBox;

button -label "开始转换"  -command("modKeys");

text "6.打开自动k帧";

button -label "打开自动k帧" -command("autoKey 1");

setParent ..;

showWindow $window;

}

global string $ctrls[];

string $tempStr[];

$ctrl=$tempStr;

global float $transDatas[];

global float $tempFloat[];

$transDatas=$tempFloat;

global string $saveCtrls[];

$saveCtrls=$tempStr;

global string $channels[];

$channels=$tempStr;

global string $cName[];

$cName=$tempStr;

$cName[0]="translateX";

$cName[1]="translateY";

$cName[2]="translateZ";

$cName[3]="rotateX";

$cName[4]="rotateY";

$cName[5]="rotateZ";

global proc autoKey(int $openOrClose)

{

autoKeyframe -state $openOrClose;

}

global proc selectCtrls()

{

global string $ctrls[];

$ctrls=`ls -sl -type transform`;

int $i=0;

string $temp;

for($i=0;$i

{

$temp+=$ctrls[$i]+";";

}

textField -edit -text $temp ctrlsName;

}

global proc recordTransforms()

{

global string $ctrls[];

global float $transDatas[];

global string $saveCtrls[];

int $i=0;

$saveCtrls=$ctrls;

int $channelIndex=0;

$transDatas=`GetAllChannelAndSaveName`;

}

global proc float[] GetAllChannelAndSaveName()

{

global string $ctrls[];

global string $channels[];

global string $cName[];

float $returnValue[];

int $index=0;

for($i=0;$i

{

int $j=0;

for($j=0;$j<6;$j++)

{

float $saveValue=0;

string $cmd="";

if(objExists($ctrls[$i])==0)

{

$saveValue=0;

}

string $tempValue="";

$tempValue=$cName[$j];

$cmd="getAttr "+$ctrls[$i]+"."+$tempValue;

$saveValue=eval($cmd);

$returnValue[$index]=$saveValue;

$channels[$index]=$ctrls[$i]+"_"+$tempValue;

$index++;

}

}

return $returnValue;

}

global proc modKeys()

{

int $shouldRotate=`checkBox -q -v rotateBox`;

int $shouldTranslate=`checkBox -q -v translateBox`;

if($shouldRotate==0&&$shouldTranslate==0)

{

warning("位移和旋转都没有勾选,未执行任何操作!");

return;

}

global string $ctrls[];

global string $channels[];

global string $cName[];

global float $transDatas[];

int $keyCount;

$keyCount=`keyframe -an keys -q -keyframeCount`;

int $i=0;

float $currentTrans[]=`GetAllChannelAndSaveName`;

for($i=0;$i

{

for($j=0;$j<6;$j++)

{

if($shouldRotate==0)

{

if($j>=3)

{

continue;

}

}

if($shouldTranslate==0)

{

if($j<3)

{

continue;

}

}

select -clear;

string $cmd="selectKey -time \":\" -attribute "+$cName[$j]+" "+$ctrls[$i];

int $curveExist=eval($cmd);

float $value=$currentTrans[$i*6+$j]-$transDatas[$i*6+$j]; 

$cmd="keyframe -animation keys -relative -valueChange "+$value;

print($cmd);

if($curveExist) 

{

eval($cmd);

}

}

}

}

getDPQWin;

推荐内容