randkey 랜덤 키 MEL




이건 랜덤키값 발생을 위한건데
Highend3D에 있던걸 조금 수정을 한것.



다운로드





// randKey.mel v1.1 by Mikael Hakansson.
//
// This script brings up a window, which lets you randomize
// selected keyframes from the graph editor.
//
// It has two modes of randomization. The first mode is the 'offset mode'.
// The selected keyframes will be offset from their current position
// (in time and/or value) within the entered value.
//
// The second mode is the 'box mode'. It will randomize your selected
// keyframes to any time and position within a specified "box".
// For example in the time range 10 to 23, and value range -3 to 8.
// Much like PA's randomize, except that you enter the range values
// numerically, instead of drawing a box in the graph editor.
//
// In both modes there's the possibility to randomize only in time
// or value.
//
// To run the script, just put the script in ~/maya/scripts/
// and type 'randKey' from the command line.

// 수정되었으면 하는 내용:
// 그래프에디터에서 키프레임 포인트들을 잡고 실행하면
// 키들의 time, value 값을 원하는 수치만큼 random하게
// 재 배열하는 것인데,  한가지 흠은 오브젝트 구분없이 x,y,z 값들이
// 무작위로 재배열한다는 겁니다.
// 결과로, 오브젝트 하나의 키값들이 무척 지저분하게 나열되어
// 그뒤의 작업이 좀 불편해 지지요.
// 오브젝트하나당 한가지의 키가 가지런하게
// 배열되는 식으로 바뀌었음 합니다.



global proc randKey()
{
window -t "Randomize Keyframes";
string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`;
string $tab1 = `columnLayout`;
text "Offset Mode (relative)";

floatFieldGrp -v1 0 -en 1 -nf 1 -l "Time" timeOffset;
floatFieldGrp -v1 0 -en 1 -nf 1 -l "Value" valueOffset;

rowLayout -numberOfColumns 3
-columnWidth3 70 70 70
-columnAttach 1 "both"  0
-columnAttach 2 "both"  0
-columnAttach 3 "both"  0;

button -w 50 -l "Rand Time"
-c "randKeyOffset(`floatFieldGrp -q -v1 timeOffset`,0,1)";
button -w 50 -l "Rand Val"
-c "randKeyOffset(0,`floatFieldGrp -q -v1 valueOffset`,2)";
button -w 50 -l "Rand Both"
-c "randKeyOffset(`floatFieldGrp -q -v1 timeOffset`,`floatFieldGrp -q -v1 valueOffset`,0)";
setParent ..;
setParent ..;

string $tab2 = `columnLayout`;

text "Box Mode (absolute)";
floatFieldGrp -v1 0 -v2 0 -en 1 -en1 1 -nf 2 -l "Min/Max Time" timeBox;
floatFieldGrp -v1 0 -v2 0 -en 1 -en1 1 -nf 2 -l "Min/Max Value" valueBox;
 
rowLayout -numberOfColumns 3
-columnWidth3 70 70 70
-columnAttach 1 "both"  0
-columnAttach 2 "both"  0
-columnAttach 3 "both"  0;

button -l "Rand Time"
-c "randKeyBox(`floatFieldGrp -q -v1 timeBox`,0,`floatFieldGrp -q -v2 timeBox`,0,1)";
button -l "Rand Val"
-c "randKeyBox(0,`floatFieldGrp -q -v1 valueBox`,0,`floatFieldGrp -q -v2 valueBox`,2)";
button -l "Rand Both"
-c "randKeyBox(`floatFieldGrp -q -v1 timeBox`,`floatFieldGrp -q -v1 valueBox`,`floatFieldGrp -q -v2 timeBox`,`floatFieldGrp -q -v2 valueBox`,0)";

setParent ..;

                tabLayout -edit
                        -tabLabel $tab1 "Offset" -tabLabel $tab2 "Box"
                        $tabs;
showWindow;
}


global proc randKeyOffset(float $randValT, float $randValV, int $mode)
{
string $channel[] = `keyframe -q -n`;
int $numChannels = size($channel);
float $newPosT;
float $newPosV;
int $keyIndex[];

if ($mode == 0)
for ($count=0; $count<$numChannels; $count++)
{
$keyIndex = `keyframe -sl -q -iv $channel[$count]`;
for ($keyCount=0; $keyCount<(size($keyIndex)); $keyCount++)
{
$newPosT = rand(-$randValT, $randValT);
$newPosV = rand(-$randValV, $randValV);
keyframe -e -in $keyIndex[$keyCount] -option over -r -tc $newPosT $channel[$count];
keyframe -e -in $keyIndex[$keyCount] -r -vc $newPosV $channel[$count];
}
}
if ($mode == 1)
for ($count=0; $count<$numChannels; $count++)
{
$keyIndex = `keyframe -sl -q -iv $channel[$count]`;
for ($keyCount=0; $keyCount<(size($keyIndex)); $keyCount++)
{
$newPosT = rand(-$randValT, $randValT);
keyframe -e -in $keyIndex[$keyCount] -option over -r -tc $newPosT $channel[$count];
}
}

if ($mode == 2)
for ($count=0; $count<$numChannels; $count++)
{
$keyIndex = `keyframe -sl -q -iv $channel[$count]`;
for ($keyCount=0; $keyCount<(size($keyIndex)); $keyCount++)
{
$newPosV = rand(-$randValV, $randValV);
keyframe -e -in $keyIndex[$keyCount] -r -vc $newPosV $channel[$count];
}
}
}


global proc randKeyBox(float $minTime, float $minValue, float $maxTime, float $maxValue, int $mode)
{
string $channel[] = `keyframe -q -n`;
int $numChannels = size($channel);
float $newPosT;
float $newPosV;
int $keyIndex[];

if ($mode == 0)
for ($count=0; $count<$numChannels; $count++)
{
$keyIndex = `keyframe -sl -q -iv $channel[$count]`;
for ($keyCount=0; $keyCount<(size($keyIndex)); $keyCount++)
{
$newPosT = rand($minTime, $maxTime);
$newPosV = rand($minValue, $maxValue);
keyframe -e -in $keyIndex[$keyCount] -option over -a -tc $newPosT $channel[$count];
keyframe -e -in $keyIndex[$keyCount] -a -vc $newPosV $channel[$count];
}
}

if ($mode == 1)
for ($count=0; $count<$numChannels; $count++)
{
$keyIndex = `keyframe -sl -q -iv $channel[$count]`;
for ($keyCount=0; $keyCount<(size($keyIndex)); $keyCount++)
{
$newPosT = rand($minTime, $maxTime);
keyframe -e -in $keyIndex[$keyCount] -option over -a -tc $newPosT $channel[$count];
}
}

if ($mode == 2)
for ($count=0; $count<$numChannels; $count++)
{
$keyIndex = `keyframe -sl -q -iv $channel[$count]`;
for ($keyCount=0; $keyCount<(size($keyIndex)); $keyCount++)
{
$newPosV = rand($minValue, $maxValue);
keyframe -e -in $keyIndex[$keyCount] -a -vc $newPosV $channel[$count];
}
}
}


randKey();