# How to reverse Animation Curve?

#1

Hi, I’m trying to flip the x and the y values of an animation curve in maya. That is, I want to run information through a curve backwards (using the curve.output channel as the input). The information only needs to be queried, so it could be done with a calculation. I’ve tried my hand at this for quite some time now with no success. If anyone has any ideas, please let me know!
Right now I’m trying to make a duplicate curve and rebuild that backwards. The only problem with that is reversing the tangent angles: something that appears to be beyond me. The tangent angles returned from the keyTangent command seem to be degrees at first glance, however they do not change in a linear fashion. So I don’t understand how to get them into a predictable unit I understand and convert them back again.

#2

Well, I managed to figure something out myself. If anyone needs to reverse an animation curve in the future, here’s the code I came up with. I’m fairly sure it only works with weighted curves though.

``````global proc inverseCurve(string \$curve){
//this is closer to reversing a curve, but that is already a named command.
int \$numKeys = `keyframe -q -kc \$curve`;
float \$tempFloat[];
float \$yVal[];
float \$xVal[];
float \$ox[];
float \$oy[];
float \$ix[];
float \$iy[];
for(\$x = 0; \$x < \$numKeys; \$x++){
\$tempFloat = `keyframe -in \$x -a -q -vc \$curve `;	   \$yVal[\$x] = \$tempFloat[0];
\$tempFloat = `keyframe -in \$x -a -q -fc \$curve `;	   \$xVal[\$x] = \$tempFloat[0];
\$tempFloat = `keyTangent -in \$x -q -ox \$curve `;		\$ox[\$x] = \$tempFloat[0];
\$tempFloat = `keyTangent -in \$x -q -oy \$curve `;		\$oy[\$x] = \$tempFloat[0];
\$tempFloat = `keyTangent -in \$x -q -ix \$curve `;		\$ix[\$x] = \$tempFloat[0];
\$tempFloat = `keyTangent -in \$x -q -iy \$curve `;		\$iy[\$x] = \$tempFloat[0];
}
for(\$x = 0; \$x < \$numKeys; \$x++){
keyframe -in \$x -a -o over -fc \$yVal[\$x] -vc \$xVal[\$x] \$curve;
keyTangent -in \$x -ox \$oy[\$x] -oy \$ox[\$x] -ix \$iy[\$x] -iy \$ix[\$x] \$curve;
}
}

``````

I would still like to know why the tangent angles in maya don’t move in a linear fashion, if anyone knows. You never know when you’ll need to know stuff like that in the future!

#3

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.