ThreeJS Animation Systems

You may animate many aspects of your models with the three.js animation system, including the bones of a skinned and rigged model, morph targets, multiple material properties (colours, opacity, booleans), visibility, and transforms. Fade in, fade out, crossfaded, and warped animation qualities are all possible. The weight and time scales of separate simultaneous animations on the same item as well as on other objects can be modified individually. It is possible to synchronise many animations on the same and separate objects.

The three.js animation system was fully redesigned in 2015 to achieve all of this in a single homogeneous framework, and it now has an architecture comparable to Unity/Unreal Engine 4. This page provides a quick overview of the system's primary components and how they interact.

Animation Clips

If you successfully imported an animated 3D object (whether it has bones, morph targets, or both) — for example, by exporting it from Blender with the glTF Blender exporter and loading it into a three.js scene with GLTFLoader — one of the response fields should be an array named "animations," which contains the AnimationClips for this model (see a list of possible loaders below).

The data for a certain object action is normally stored in each AnimationClip. For example, if the mesh represents a character, there may be one AnimationClip for walking, another for jumping, a third for sidestepping, and so on.

Keyframe Tracks

Each animated property's data is saved in a single KeyframeTrack within such an AnimationClip. If a character object contains a skeleton, one keyframe track may store data for position changes of the lower arm bone over time, another track could store data for rotation changes of the same bone, a third track could store data for track position, rotation, or scale of another bone, and so on. It should go without saying that an AnimationClip can be made up of multiple such tracks.

If the model has morph targets, each track contains information about how the influence of each morph target varies during the clip's performance.

Animation Mixer

The saved data simply serves as a foundation for the animations; the AnimationMixer is in charge of the actual playing. You might envisage this as more than just an animation player; it may also be a simulation of hardware, such as a real mixer console, that can manage multiple animations at once, blending and merging them.

Animation Actions

Because the AnimationMixer is controlled by the AnimationActions, it only contains a few (generic) properties and methods. By configuring an AnimationAction, you can specify when a specific AnimationClip should be played, paused, or stopped on one of the mixers, as well as whether and how often the clip should be repeated, whether it should be performed with a fade or time scaling, and other options like crossfading and synchronising.

Animation Object Groups

If you want a group of objects to receive a shared animation state, you can use an AnimationObjectGroup.

Example

let mesh;


// Create an AnimationMixer, and get the list of AnimationClip instances
const mixer = new THREE.AnimationMixer( mesh );
const clips = mesh.animations;


// Update the mixer on each frame
function update () {
	mixer.update( deltaSeconds );
}


// Play a specific animation
const clip = THREE.AnimationClip.findByName( clips, 'dance' );
const action = mixer.clipAction( clip );
action.play();


// Play all animations
clips.forEach( function ( clip ) {
	mixer.clipAction( clip ).play();
} );

Related Topics

ThreeJS AnimationClip

An AnimationClip is a group of keyframe tracks that may be reused to depict an animation. The "Animation System" page in the "Next Steps" part of the handbook provides an overview...

2 minutes read.

ThreeJS InterleavedBuffer

The term "interleaved" refers to the packing of multiple attributes, possibly of different types (e.g., position, normal, uv, colour) into a single array buffer. Constructor InterleavedBuffer( array : TypedArray, stride : Integer...

3 minutes read.

ThreeJS Curve

An abstract base class for creating a Curve object with interpolation methods. CurvePath is an array of Curves. Constructor Curve() This constructor creates a new Curve. Properties .arcLengthDivisions : Integer This value determines the amount of...

13 minutes read.

ThreeJS Layers

A Layers object assigns an Object3D to one or more of the 32 layers numbered 0 to 31 - the layers are internally stored as a bit mask, and all...

1 minute read.

ThreeJS Installation

You can use npm and modern build tools to install three.js, or you can get started quickly with static hosting or a CDN. Installing from npm is the best option...

4 minutes read.

ThreeJS Cameras

ArrayCamera ArrayCamera can be used to render a scene using a preset group of cameras quickly. This is an important feature of VR scene rendering performance. An array of sub cameras is...

6 minutes read.

ThreeJS Loader 1

AnimationLoader Class for loading AnimationClips in JSON format. This uses the FileLoader internally for loading files. Code Example // instantiate a loader const loader = new THREE.AnimationLoader(); // load a resource loader.load( // resource URL 'animations/animation.js', // onLoad callback function...

8 minutes read.

ThreeJS Interpolant

CubicInterpolant Code Example const interpolant = new THREE.CubicInterpolant(new Float32Array( 2 ),new Float32Array( 2 ),1,new Float32Array( 1 ));interpolant.evaluate( 0.5 ); Constructor CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) parameterPositions -- array of positions sampleValues -- array of samples sampleSize...

2 minutes read.

ThreeJS Animation Systems

You may animate many aspects of your models with the three.js animation system, including the bones of a skinned and rigged model, morph targets, multiple material properties (colours, opacity, booleans),...

3 minutes read.

ThreeJS Testing with npm

This article explains how to install three.js in a node.js environment so that automated tests may be run. Tests can be done manually or with the help of automated CI...

4 minutes read.

ThreeJS Uniform

Uniforms are global GLSL variables. They are passed to shader programs. Code Example When declaring a uniform of a ShaderMaterial, it is declared by value or by object. uniforms: { time: { value: 1.0...

2 minutes read.

ThreeJS Materials 3

RawShaderMaterial This class works just like ShaderMaterial, except that definitions of built-in uniforms and attributes are not automatically prepended to the GLSL shader code. Code Example const material = new THREE.RawShaderMaterial( {    ...

9 minutes read.

ThreeJS Renderers

WebGLMultipleRenderTargets A special render target that enables a fragment shader to write to several textures. This approach is useful for advanced rendering techniques like post-processing or deferred rendering. Heads up: WebGLMultipleRenderTargets...

15 minutes read.

ThreeJS Managers

DefaultLoadingManager When no custom manager is specified, most loaders use a global instance of the LoadingManager. This will suffice for most purposes, but there may be times when you want separate loading...

4 minutes read.

ThreeJS Matrix Transformations

Three.js encodes 3D transformations using matrices for translations (position), rotations, and scaling. Every Object3D instance has a matrix that records the location, rotation, and scale of the object. This page...

2 minutes read.

ThreeJS AnimationObjectGroup and Utils

AnimationObjectGroup A group of objects that receives a shared animation state. Usage Add items you'd normally send as 'root' to AnimationMixer's function Object() { [native code] } or clipAction method, and instead pass...

2 minutes read.

ThreeJS Property Binding and Mixer

PropertyBinding Internally, this holds a reference to real property in the scene graph. Constructor PropertyBinding( rootNode : Object3D, path, parsedPath ) -- rootNode: -- path -- parsedPath (optional) Properties The properties are as follows: .path : Number.parsedPath...

2 minutes read.

ThreeJS Geometries-1

BoxGeometry BoxGeometry is a geometry class for a rectangular cuboid with a given 'width', 'height', and 'depth'. On creation, the cuboid is centered on the origin, with each edge parallel to...

7 minutes read.

ThreeJS Audio

It is used to create a non-positional (global ) audio object. Code Example: // create an AudioListener and add it to the camera const listener = new THREE.AudioListener(); camera.add( listener ); // create a global...

6 minutes read.

ThreeJS Material - Mesh

MeshBasicMaterial A material for drawing geometries in a simple shaded (flat or wireframe) way. This material is not affected by lights. Constructor MeshBasicMaterial( parameters : Object ) parameters - (optional) an object with one or...

24 minutes read.