GameDev.netSmooth interpolation of irregularly spaced keyframes

Smooth interpolation of irregularly spaced keyframes
## IntroductionAnimating models by manipulating an attached skeleton is a common technique for producing lifelike animations in games. It has both a firm basis in biological reality, and a low memory requirement (compared to, for example, storing vertex and normal vectors for each frame). Also, high frame rates are now expected of animations, and skeletal animation data can easily be interpolated between "key" frames before transformations are applied to the model. It is assumed that the reader is familiar with this process. A glossary of terms has been included for reference at the bottom of the article. ## Standard interpolation formulaeThe whole animation is represented by a series of values
Finding the tangent gradients for the Catmull-Rom spline is quite straightforward:
In the case so far being examined, t, and t is an integer. But what if keyframes could be placed at any value of t? This would certainly be beneficial for animators, as not all time intervals in an animation contain the same amount of "detail." In the few (very humble) animations I've made, I have found a constant trade-off between the amount of detail you would like one region of your animation to have, and the sheer number of keyframes piling up in your animation. Why not just put in keyframes where you need them, and have them smoothly interpolated while you're at it?
Another problem that this will assist with is when one part of an animation is running just a little too fast or too slow. To tweak this normally, you have to adjust all the frames around the area, but with this system, you can just slide a keyframe or two a tiny bit to correct the error. This is an ability limited to high-end and non-realtime modelling software, as far as I know. Certainly, I've found no reference to coding it on the web. ## Irregular keyframe timingAll that now remains is to adapt the interpolation to work with irregular keyframe intervals. We need a new array to store the time offset into the animation of each keyframe, denoted
At the interpolation stage, we first need to find out what keyframes we're between at the moment. This is done easily enough with something like: while (t >= kt[iKeyFrame+1]) iKeyFrame++; Then we come across a slight snag - we need the value of
The value
Of course, we've now scaled time, so while You now have your interpolated value of ## Glossary*k(t)*- The value of a keyframe at time
*t*(one number, so several may be used to represent a complete orientation). *k(u)*- The interpolated value between two values
*k(t)*and*k(t+1)*(assuming a spacing of 1).*u*always takes a value in the range 0 to 1. *k'(t)*- The "gradient" of a keyframe - this is not set by the user, as is the case with splines in many graphics programs, but is calculated as an average of the gradients of lines to the keyframes on either side.
*kt(i)*- The time value
*t*for keyframe number*i*. It must always be the case that*kt(i) < kt(i+1)*. *δx*- The time interval between two particular keyframes. In most keyframing systems,
*δx*is 1, or some constant value. In this system,*δx*can take any value, and can vary throughout the animation.
© 1999-2011 Gamedev.net. All rights reserved. |