Expand description
Animation system.
Introduction
The three
animation system is designed around three structures, namely
Action
, Clip
, and Mixer
.
Action
An Action
controls the playback properties of an animation.
Methods such as play
, pause
, and disable
are provided to control
an single animation at runtime.
Actions must be created and updated by a Mixer
.
Mixer
An animation Mixer
schedules the playback of actions.
The user is expected to create actions from a mixer with the Mixer::action
function and update actions with the Mixer::update
function.
Clip
An animation Clip
defines the keyframes and target of an animation.
Clips are usually imported from 3D formats such as glTF.
Walkthrough
Creating a mixer
First, we create a Mixer
to play our animation.
// Initialization omitted.
let mut mixer = three::animation::Mixer::new();
Loading some animation clips
Now, we load some clips from an animated glTF scene.
let gltf = window.factory.load_gltf("AnimatedScene.gltf");
window.scene.add(&gltf);
Creating animation actions
Now, we schedule the playback of the clips by creating actions.
The created actions are enabled by default in the ‘play’ state. This means that
when calling Mixer::update
the created actions will begin to be played back
immediately.
let actions: Vec<three::animation::Action> = gltf.clips
.into_iter()
.map(|clip| mixer.action(clip))
.collect();
Playing the animation back
Finally, we run the animation actions by updating their Mixer
in the main
game loop.
while window.update() {
mixer.update(window.input.delta_time());
window.render(&camera);
}
Putting it all together
See the gltf-animation
example for the full code.