Animation
Introduction
The engine support all major animations: keyframe, morphing, morph target and skinning (skeletal animation).
We will see in this article the possibilities offered by the engine (such as animation blending and much more) and how to control animation playback.
AnimationContext
The animation state of a model is controlled with its
AnimationContext. AnimationContext specifies which animation(s) to play and control the playback time (timeline).
AnimationContext: Animation
Animation can be assigned to an AnimationContext in 3 ways, from the most basic to the most advanced:
*
AnimationContext.setAnimation: playback a single animation, usually read from model file and stored in Model (see
Model.getAnimation(int) and
Model.getAnimation(String)).
*
AnimationContext.setTracks: playback of animations tracks. An
AnimationTrack has its own timeline, playback speed and weight (track blending weight or visibility).
*
AnimationContext.setGraph:
AnimGraph is the most advanced way to specify a complex animation, such as animation blending, selection, state ...
Note: The first two ways are helpers, the engine uses internally exclusively the AnimGraph graph representation.Let see in pictures the two last to give a better idea on what we're talking about. If you're still a bit confused after that, see the animation track and graph
videos which introduce both of them in more details.
The first picture show a representation of animation tracks: one animation track by line, horizontal axis represents the time and vertical axis the weight (0 off, 1 on, in between for blending/fading). The yellow bar show current time on the track timeline, in this exemple the animation played is a blend between "Walk" and "Run" animations.
In the second picture a graph representation: each box is a node, line represent a connection between an output and input of two boxes. The box on the leftmost is the animation played on the model (graph output), the path in red represents the current active nodes. In this exemple, the active path plays 'Run' animation un-modified.
AnimationContext: Playback control
AnimationContext.getTimeline() defines the duration/looping and the current time of the animation playback. The time can be set in the timeline object, and is updated with usual model update.
In addition, the animation graph offers a flexible way to control animation state. The graph can be seen as a state machine. Each nodes have their own states, set of parameters and they depends on the whole graph state.
AnimGraph
TO BE WRITTEN, please refer to the javadoc in the meantime.
Animation
Skinning / Skeletal animation
The engine support skinning animation from the most common model formats.
A model with skinning animation have a
Skeleton which is bone representation of a model.
The skeleton is shown below in overlay of the model, the text displays the joint name while the white lines represents the bone of the mode:
Skeleton defines the
default pose (rest pose or t-pose) of the bone hierarchy and
animation information of the bone hierarchy for model motion. Skeleton animation can be read from the original model format, a separate source such a motion capture (bvh) or exported animation (jaf), by sharing from a different model, ... The next paragraphes introduce the api to manipulation skeleton motion.
Skinning: animation sharing
Tutorial 11 shows how to share a skeleton motion from a model to another.
Skeleton motion can be shared when the skeleton is compatible between the source motion and destination model. This means the skeleton must have the same bone/joint hierarchy, joint names and axis system.
When those conditions are not met, a motion retarget (see below) must be performed to match the original skeleton to the destination skeleton.
In the tutorial, all the conditions are fullfilled except the joint having different name. This condition can easily be bypassed by exporting all models with same joint naming. In the tutorial we used a different way, we are renaming the skeleton joints to a standardized naming for all model used.
Skinning: animation retarget
Tutorial 13 uses a skeletal animation from motion capture and retarget them to a model. The motion retarget step is necessary due to the fact the the skeleton of the motion and model are very different.
Motion retarget is an (heavy) algorithm which aim is to match any skeletal animation to any model. The retarget process takes as input the motion, the target skeleton and the map between motion joint to skeleton joint names.
Morph Target
The engine support morph target animation which can be read from dae and fbx model formats. Morph target are commonly used for facial expression.
Morph target are exposed in
MorphTargets object (referenced by
VertexData). MorphTargets exposes among other the number of targets and names, usefull for creating morph animation as we'll see below.
MorphMotion defines the morph targets active of the animation. The hashmap
MorphMotion contains the list weight/visibility keyframes associated to each morph target active (the key String is the name of the morph target.
The
Morph Target animation video introduce how to create and edit a
MorphMotion animation.
The MorphMotion is referenced by the usual Animation object with
Animation.morphMotions, which contains the list of MorphMotion names to play with the Animation.
When using AnimGraph, MorphMotion information are only used when connected to the
morph graph input.
Md3 animation
In md3 models, the animation is made of keyframe and morphing. The model has also multiples model childs (tree). The model has therefore multiple animation playing for each piece of the global model.
Md3 model has usually a torso and leg parts. To set the animation, you can use the traditional way (browse model hierarchy and set animation to the context) or use the utility:
Export/Import animation
TBW