New Animation System!!

Look at the title of this post.

Now look at it again.

Read it out loud!


There’s a new animation system in Crimild. And, most importantly, it actually works!

I’m really, really happy with what I managed to achieve over the course of the last weeks for the new animation system. Not only it provides a clean and simple to use interface, but it’s also powerful enough to achieve different blending and post-processing operations.

Just take a look at the new animation system in all its glory:

Low-Level API

The new animation system has been designed to work as a low level API for animations, not only for skeletal meshes, but for any quantity that you want to animate over time. The rationale behind this design is to be able to integrate the animation system with other systems like controllers, behavior trees or shader graphs (spoiler!).

The core classes related with the new animation system are:

Channel: Contains keyframe data and times for each key. For example, it may hold positions or rotations data over time. It is also responsible for evaluating such data at any given time and performing interpolations if needed.

Clip: Contains one or more clip for a given animation. For example, a clip that represents a walking animation for a skinned mesh should contain the position and rotation channels for each bone in the skeleton.

Animation: Computes an animation based on a clip and other params, like duration or frame rate. It also contains all accumulated values for a given point in time. Two or more animations can be chained to achieve different results like blending or masking.

Accumulator: Holds the result for a single accumulated value after computing an animation. For a given skeleton, for example, each accumulator will be associated with a bone.

Skeleton: Contains a set of bones and the animations associated with them. A skeleton may contain multiple animations, like walking, running and jumping.

An example

Let’s consider a simple animation, like rotating a triangle around the Y axis:


The pseudo-code for achieving such animation will look like this:

/* Scene Setup */
crimild::Quaternion4 keys[] = { /* Rotations over time */ };
crimild::Real32 times[] = { /* Time for each rotation */ };
Channel *rotations = new Quaternion4fChannel( "rotation", times, keys );
Clip *clip = new Clip();
clip->addChannel( rotations );
Animation *animation = new Animation( clip );
Geometry *triangle = ...

/* Update Loop */
Clock c = /* get current frame's clock */
animation->update( c )->getValue( "rotation", triangle->local().rotate() );

Notice the update step: First we update the animation by passing the clock for the current frame. Then, we get the computed value for the rotation channel and apply it to the transformation for the triangle.

Chaining Animations

As I mentioned before, the new animation system allows animations to be chained together if needed. This allows to compute new animations procedurally by combining existing ones.

For example, the following chain:

Animation *walk = ...
Animation *run = ...
crimild::Real32 speed = 0.5f;
Animation *result = walk->update( clock )->lerp( run, speed );

Will result in an animation that’s half way between walking and running. First, we need to update the base animation (walking) for a specific point in time. Then, we interpolate it with the second animation (running) using the value of speed. The function lerp automatically synchronizes the two animations together before computing the interpolation.

You can keep chaining animations, adding or interpolating them to achieve different effects as show below.


The demo shown at the beginning of this post was implemented by using additive blending to perform head tracking for the character. Additive blending is an animation technique that combines animations by computing a “difference clip”, the result of subtracting a known pose from an exiting animation data, and adding that to a third animation.

In other words, the walking animation above is combined with the one that results from subtracting the idle pose to the head turning animation, which is nothing more than just a bunch of rotations for the neck.

The head tracking animation itself is computed by interpolating from five other animations (look up, down, left right and center) using the mouse position as the interpolation factor.

But wait! There’s more:

This is a classical animation blending demo that computes transitions between different clips.

Each wolf has four animations pre-defined: idle, stalk, walk and run. Based on the value of a variable “speed” (itself controlled by user’s input), two or more of those animations are linearly interpolated, resulting in smoother transitions.

For reference purposes, the wolf on the right does not perform any interpolation at all. Notice how it just “jumps” from one state to the next, making the changes in animations to be quite visible.

This is only the beginning

What I achieved so far is just the barebones for a true animation system. There are still many enhancements that will be implemented over time, like inverse kinematics, locomotion controller, custom interpolators, integration with behavior trees…

The road ahead will be a lot of fun.