PDA

View Full Version : Reverse an animation curve


ronviers
06-18-2009, 10:00 PM
I would like to be able to select an animation curve, duplicate it, reverse it, then append it to the end of itself.
So a curve that looks like this:
http://lh5.ggpht.com/_FMU0SwkA6vA/SjqxC-1PHiI/AAAAAAAACKs/gTkrd1Kkrrs/s400/before.jpg
Will look like this:
http://lh3.ggpht.com/_FMU0SwkA6vA/SjqxC9vhrbI/AAAAAAAACKw/C99UVw_ud8U/s400/after.jpg

It seems to me something like this should work:

copyKey -time "0:24" -at tz nurbsSphere1;
scaleKey -ts -1;
pasteKey -timeOffset 24;

But I cannot get scaleKey to work on the contents of the copy buffer, or even read the copy buffer into an array.

djtomservo
06-19-2009, 04:56 AM
hmm...off the top of my head i might try something like this:

float $key_times[]= `keyframe -q -tc`;
float $key_vals[]= `keyframe -q -vc`;
int $mid_point= 24;
int $max_index= size($key_times);
for($i=$max_index-2;$i>=0;$i--)
{
float $new_time= $mid_point+($mid_point-$key_times[$i]);
setKeyframe -t $new_time -v ($key_vals[$i]);
}


you could either have the user pass in the value for $mid_point or you could derive it from the values in $key_times. It's a little brute force and i'm sure there are much mor elegant ways, this is just quick and dirty.

ewerybody
06-19-2009, 08:18 AM
do you need a script to do exactly this? or just tools to perform the steps accordingly?
In my case Id do it this way:


select the keys
copy them
paste them after the anim
reverse the pasted keys
move them to match the startpoint
takes about 2 seconds. one could put the currentTime directly on the last key and then paste so you can omit the move part.

If you're interested: I have 2 context sensitive hotkeys for reversing operations on Ctrl+R and Ctrl+Shift+R:

reverse_hotkey: reverses keys times in graph-, faces in 3d- and flips uvs vertically in UV-editor:
if (`getPanel -wf` == "graphEditor1")
{
float $selKeys[] = sort(`keyframe -q -sl -at`);
float $keyCenter;
if (size($selKeys))
$keyCenter = (($selKeys[size($selKeys) - 1] - $selKeys[0])/2) + $selKeys[0];
else
$keyCenter = (((`findKeyframe -w last`)-(`findKeyframe -w first`))/2)+(`findKeyframe -w first`);

scaleKey -timeScale -1 -timePivot $keyCenter;
}
else if (`getPanel -wf` == "polyTexturePlacementPanel1")
polyForceUV -flipVertical -local;
else
performPolyNormal 0 -1 0;


reverseValue_hotkey: reverses keys values in graph-, faces in 3d- and flips uvs horizontally in UV-editor
if (`getPanel -wf` == "graphEditor1")
scaleKey -valueScale -1 -timePivot 0;
else if (`getPanel -wf` == "polyTexturePlacementPanel1")
polyForceUV -flipHorizontal -local;
else
performPolyNormal 0 -1 0;

ronviers
06-19-2009, 01:17 PM
Thanks to both of you for getting me headed in the right direction.

CGTalk Moderation
06-19-2009, 01:17 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.