Module three::animation

source ·
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.

Structs

Controls the playback properties of an animation
A reusable set of keyframe tracks which represent an animation.
Scheduler for the playback of animation actions.
A track of animation keyframes.

Enums

Describes the target property of an animation.
Describes the interpolation behaviour between keyframes.
Describes the looping behaviour of an Action.
The keyframe values of a Track.

Type Definitions

A target of an animation.