Title: KIPA Game Engine Seminars
1KIPA Game Engine Seminars
Day 11
- Jonathan Blow
- Seoul, Korea
- December 7, 2002
2Character Animation
- The goal let artists make animation, and get it
into the game - Usually animation is made in a separate tool
- Maya / MAX
- Made out of hierarchical transforms
- Probably we need to write an exporter plugin and
some game-engine import code - Unless we use a licensed character animation
system (like Granny)
3Goals for in-enginereproduced animation
- As much like the art packages version of the
animation as possible - But small (low memory) and fast
4How animations are authored
- The artist sets up a bunch of keyframes for
transform data - Usually separated into translation, rotation,
scale - The art tool interpolates between these keyframes
at runtime - Maybe we should export the keyframes and
interpolate them in the engine
5Why you dont want toexport the keyframes (1)
- They can be in weird formats that require
confusing code to interpolate - 3DS max TCB curves
- They can be in formats that are slow to
interpolate - Euler angles
- They are not necessarily well-compressed
- Keyframes get fragmented over time
- What happens when you import an animation from
another package
6Why you dont want toexport the keyframes (2)
- Artists use IK tools to help create animations
- You would have to reconstruct all this IK
functionality exactly for the animation to look
right - Footstep controller
- Guy grabbing something from a table
7A better solutionSample the transforms
- Dont worry about the original keyframe data,
just evaluate the transforms at some sampling
interval - Save those transforms out, interpolate them at
runtime - Sample at perhaps 30Hz
8Interpolating transforms?
- We dont want to interpolate a 4x3 matrix
- It will denormalize, introduce shear
- Break it into intuitive pieces (translation,
rotation, scale) - By matrix decomposition
- But which decomposition you choose matters!
- Shear easily confused with rotation
- Use the polar decomposition
9Interpolating transforms? (2)
- If samples are close together, our interpolation
will not diverge much from the art tools - Euler vs slerp for small angles
- But those samples take a lot of memory!
- Example of how much
10Want to compress those samples
- Hopefully at export time (small file size)
- How to compress?
- Fourier / Wavelet compression
- Curve fitting
- Performance ramifications of each method
11Compression
- Probably, curve fitting is the best choice
- Each curve stored as an array of unevenly spaced
knots - At runtime we just evaluate a simple polynomial
to reconstruct values - For linear values like translation and scale
- What about rotation?
12Rotation interpolation
- For interpolation between two rotations, slerp is
the right answer - This may be too slow
- Review of slerp code
- Can we do something else
13Different kinds of rotation interpolation
- slerp
- exponential map
- lerp
- lerp approximates slerp for small angles
- sin(x) x as x - 0
- Its not that bad for large angles either
14Re-derivation of slerpin 2D
- Did this once before, but will do it again
quickly, as an introduction to the lerp
derivation
15What happens when welerp two quaternions?
- Assuming they dont differ by more than 90
degrees - double cover!
- We can analytically quantify the distoritions in
angle and length
16Using lerp as asubstitution for slerp
- Probably we have to renormalize
- Maybe we have to compensate for the angle
- Discussion of fast unit vector normalization
- Newton-raphson approximation to 1/sqrt(x) in the
neighborhood near 1 - Walk-through of code
17How to compensate forthe angle
- Discussion of approximating the inverse of the
angular distortion
18Maybe we dont have to compensate for the angle
- When curve-fitting, we measure our error with
respect to the lerped/normalized reconstruction
of a spline (not the ideal slerp solution) - This causes us to insert more knots in the curve
when we might need better angle accuracy - So maybe there is a trade-off here, memory for
runtime speed
19Fitting algorithm
- (discussion on whiteboard, including quirks)
20Data structures
- An animation structure contains
- Number of nodes, names of the nodes
- Keyframe data for compressed curves
- Information about how to blend in/out of
animation, when to start/stop - Explanation of some different ways you might want
to arrange things
21Data structures
- A mesh contains
- Number of nodes, names of the nodes
- Vertex data
- Vertex weight information
22Binding data structures
- A lot of systems work by building a table that
cross-references between node names in the
animations, and node names in the mesh - Animations might not be stored in the same order
node-wise - Some might have nodes that the others dont
- This is called the bind step
23I dont like the bind step
- It means that you cant have animation playback
without a mesh attached - I want animations to be meaningful without meshes
yet, i.e. I want to be able to play them back and
mix them - Though there are bone length assumptions built
into the animations - Lately I rewrote my animation system to not use a
bind step
24What I do
- An animation player class handles animation
playing - One channel per animation on the same figure
(so, 2 channels for upper/lower body) - The player has a string hash table that keeps
track of values, and maps each channels nodes to
a central node array - To animate an object, we map that objects node
names through the hash table (every frame,
potentially)
25Structuring node orderby dependency
- So you can compose a bunch of relative transforms
into object-space transforms in one pass - Only constraint is that any nodes parent has to
have an index less than its own - If you mix two arrays like this, it is easy to
maintain this constraint - So the players central animation array will be
correctly ordered
26Mixing Animations
- Sometimes you want to play back two different
animations on various nodes of the body - Description of how this reduces data size and
artist time - This will produce inappropriate results for some
actions - Because the meanings of various rotations depend
on whats higher up in the hierarchy - Example Guy swinging a sword
27Mixing Animations
- Interpolate transforms relative to a common root
between the two animations - Put these into the relative transform slots
during animation playback - Or else interpolate in object space, but that
might be inconvenient
28Brief discussion quaternion splines
- Very hard to precompute, not cheap to evaluate
either - Though Casey says you can do a de Casteljau-like
formulation, using slerp instead of lerp - I am not sure if this is the right answer but
it seems to work in many cases - So if lerp is not good enough, think about using
this layered slerp technique
29Mixing IK withplaying animations
- Evaluate the animations first
- Solve IK given those object-space coordinates
- Mix the IK back in as though it were an animation
channel
30Putting sound effectsin animation data
- Only robust way to generate sound cues at
appropriate times! - Put tag names in the animation these tags are
later converted to sound effect names - based on material contacted, etc
- (example of footsteps)
31Putting other auxiliary datain animations
- Example of attack strength in swordfighting
game - Advantage Easy for animator to change this
without programmers, easy to keep in sync with
animation - Disadvantage Maybe animator should not be in
charge of this might be better to have a
separate specification system
32Instead of IKfor aiming things
- Blending between pre-generated animations
- (Example of aiming a gun)
- Can do an iterated search through the animation
space until you find something close enough
33Reasons you still mightwant IK
- Example of two-handed weapon
- Shows why requiring a tree hierarchy is bad
34Facial Animation
- Probably should use morph targets, not a bone
system - Each facial expression is probably a short
animation (not a frozen mask)
35Code Inspection
36Questions?