Monday, July 13, 2009

scr

global string $aTan_version = "";
global proc dq_smooth_tan()
{
global string $aTan_version ;

if (`window -q -ex autoTangentWin`)
{
showWindow autoTangentWin ;
return ;
}
float $soft = 0.0 ;
int $bFlatten = 1 ;
if(`optionVar -ex "aTan_softness"`)
$soft = `optionVar -q "aTan_softness"` * 100.0 ;
if(`optionVar -ex "aTan_flatten"`)
$bFlatten = `optionVar -q "aTan_flatten"` ;
window -w 200 -h 125 -s 0 -t ("Smooth Tangent "+$aTan_version) -in "autoTangent" autoTangentWin;
columnLayout -adj true;
separator -style "in" -w 200 -h 5 ;
checkBox -vis 0 -l "Flatten Start/End Keys" -v $bFlatten cbFlatten ;
floatSliderGrp -label "Smooth Value:" -field true -min 0.0 -max 10 -v $soft -adj 3 -cw3 80 40 90 -cc ("aTan_start();") fsgSoft;
button -l ("Apply Selected Keys") -al "center" -w 180 -c ("aTan_start();") btnTan;
separator -style "in" -w 200 -h 5 ;
window -e -wh 210 80 autoTangentWin;
showWindow;
}
global proc aTan_start()
{
float $soft = `floatSliderGrp -q -v fsgSoft` / 100.0 ;
int $bFlatten = `checkBox -q -v cbFlatten` ;
optionVar -fv "aTan_softness" $soft ;
optionVar -iv "aTan_flatten" $bFlatten ;
aTan_smoothKeys($soft, $bFlatten) ;
}
global proc aTan_smoothKeys(float $softness, int $bFlatten)
{
string $curves[] = `keyframe -q -name -sl` ;
string $crv ;
waitCursor -state on ;
for ($crv in $curves)
{
int $idxs[] = `keyframe -q -indexValue -sl $crv` ;
int $idx ;
for ($idx in $idxs)
{
int $total = `keyframe -q -keyframeCount $crv` ;
float $valCs[] = `keyframe -index $idx -q -valueChange $crv` ;
float $timeCs[] = `keyframe -index $idx -q -timeChange $crv` ;

float $valPs[] = $valCs ;
float $valNs[] = $valCs ;
float $timePs[] = $timeCs ;
float $timeNs[] = $timeCs ;
if ($idx > 0)
{
$valPs = `keyframe -index ($idx-1) -q -valueChange $crv` ;
$timePs = `keyframe -index ($idx-1) -q -timeChange $crv` ;
}
if ($idx < $total-1)
{
$valNs = `keyframe -index ($idx+1) -q -valueChange $crv` ;
$timeNs = `keyframe -index ($idx+1) -q -timeChange $crv` ;
}
float $valC = $valCs[0] ;
float $valP = $valPs[0] ;
float $valN = $valNs[0] ;
float $timeC = $timeCs[0] ;
float $timeP = $timePs[0] ;
float $timeN = $timeNs[0] ;
if ($idx == 0 && !$bFlatten)
{
$timeP = $timeC - ($timeN - $timeC) ;
$valP = $valC - ($valN - $valC) ;
}
else if ($idx == ($total-1) && !$bFlatten)
{
$timeN = $timeC + ($timeC - $timeP) ;
$valN = $valC + ($valC - $valP) ;
}
float $valIn = $valC - $valP ;
float $valOut = $valN - $valC ;
float $timeIn = $timeC - $timeP ;
float $timeOut = $timeN - $timeC ;
float $slopeIn = 0 ;
float $slopeOut = 0 ;
if ($timeIn != 0)
$slopeIn = $valIn / $timeIn ;
if ($timeOut != 0)
$slopeOut = $valOut / $timeOut ;
float $powIn = 0.5, $powOut = 0.5;

if ($slopeIn + $slopeOut != 0)
$powIn = 1.0 - ( abs($slopeIn) / ( abs($slopeIn) + abs($slopeOut) ) ) ;
$powOut = 1.0 - $powIn ;
$powIn = ((1.0 - $softness) * $powIn ) + ($softness * 0.5) ;
$powOut = ((1.0 - $softness) * $powOut ) + ($softness * 0.5) ;
float $newSlope = ( $powIn * $slopeIn ) + ( $powOut * $slopeOut ) ;
float $ang = atan( $newSlope ) * 180.0 / 3.14159 ;
keyTangent -itt spline -ott spline -time $timeC $crv ;
keyTangent -ia $ang -oa $ang -time $timeC $crv ;
int $wts[] = `keyTangent -q -wt $crv` ;
if ($wts[0] == 1)
{
float $inWt = abs($timeIn) / 3.0 ;
float $outWt = abs($timeOut) / 3.0 ;
keyTangent -iw $inWt -ow $outWt -time $timeC $crv ;
}
}

}
waitCursor -state off ;
}
dq_smooth_tan;

No comments:

Post a Comment