|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <base href="../../../" /> |
| 6 | + <script src="page.js"></script> |
| 7 | + <link type="text/css" rel="stylesheet" href="page.css" /> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <h1>[name]</h1> |
| 11 | + |
| 12 | + <h2>Overview</h2> |
| 13 | + |
| 14 | + <p class="desc"> |
| 15 | + Within the three.js animation system you can animate various properties of your models: |
| 16 | + the bones of a [page:SkinnedMesh skinned and rigged model], |
| 17 | + [page:Geometry.morphTargets morph targets], different material properties (colors, |
| 18 | + opacity, booleans), visibility and transforms. The animated properties can be faded in, |
| 19 | + faded out, crossfaded and warped. The weight and time scales of different simultaneous |
| 20 | + animations on the same object as well as on different objects can be changed |
| 21 | + independently. Various animations on the same and on different objects can be |
| 22 | + synchronized.<br /><br /> |
| 23 | + |
| 24 | + To achieve all this in one homogeneous system, the three.js animation system |
| 25 | + [link:https://github.com/mrdoob/three.js/issues/6881 has completely changed in 2015] |
| 26 | + (beware of outdated information!), and it has now an architecture similar to |
| 27 | + Unity/Unreal Engine 4. This page gives a short overview of the main components of the |
| 28 | + system and how they work together. |
| 29 | + |
| 30 | + </p> |
| 31 | + |
| 32 | + <h3>Animation Clips</h3> |
| 33 | + |
| 34 | + <p class="desc"> |
| 35 | + |
| 36 | + If you have successfully imported an animated 3D object (it doesn't matter if it has |
| 37 | + bones or morph targets or both) — for example exporting it from Blender with the |
| 38 | + [link:https://github.com/KhronosGroup/glTF-Blender-IO glTF Blender exporter] and |
| 39 | + loading it into a three.js scene using [page:GLTFLoader] — one of the response fields |
| 40 | + should be an array named "animations", containing the [page:AnimationClip AnimationClips] |
| 41 | + for this model (see a list of possible loaders below).<br /><br /> |
| 42 | + |
| 43 | + Each *AnimationClip* usually holds the data for a certain activity of the object. If the |
| 44 | + mesh is a character, for example, there may be one AnimationClip for a walkcycle, a second |
| 45 | + for a jump, a third for sidestepping and so on. |
| 46 | + |
| 47 | + </p> |
| 48 | + |
| 49 | + <h3>Keyframe Tracks</h3> |
| 50 | + |
| 51 | + <p class="desc"> |
| 52 | + |
| 53 | + Inside of such an *AnimationClip* the data for each animated property are stored in a |
| 54 | + separate [page:KeyframeTrack]. Assuming a character object has a [page:Skeleton skeleton], |
| 55 | + one keyframe track could store the data for the position changes of the lower arm bone |
| 56 | + over time, a different track the data for the rotation changes of the same bone, a third |
| 57 | + the track position, rotation or scaling of another bone, and so on. It should be clear, |
| 58 | + that an AnimationClip can be composed of lots of such tracks.<br /><br /> |
| 59 | + |
| 60 | + Assuming the model has [page:Geometry.morphTargets morph targets] (for example one morph |
| 61 | + target showing a friendly face and another showing an angry face), each track holds the |
| 62 | + information as to how the [page:Mesh.morphTargetInfluences influence] of a certain morph |
| 63 | + target changes during the performance of the clip. |
| 64 | + |
| 65 | + </p> |
| 66 | + |
| 67 | + <h3>Animation Mixer</h3> |
| 68 | + |
| 69 | + <p class="desc"> |
| 70 | + |
| 71 | + The stored data forms only the basis for the animations - actual playback is controlled by |
| 72 | + the [page:AnimationMixer]. You can imagine this not only as a player for animations, but |
| 73 | + as a simulation of a hardware like a real mixer console, which can control several animations |
| 74 | + simultaneously, blending and merging them. |
| 75 | + |
| 76 | + </p> |
| 77 | + |
| 78 | + <h3>Animation Actions</h3> |
| 79 | + |
| 80 | + <p class="desc"> |
| 81 | + |
| 82 | + The *AnimationMixer* itself has only very few (general) properties and methods, because it |
| 83 | + can be controlled by the [page:AnimationAction AnimationActions]. By configuring an |
| 84 | + *AnimationAction* you can determine when a certain *AnimationClip* shall be played, paused |
| 85 | + or stopped on one of the mixers, if and how often the clip has to be repeated, whether it |
| 86 | + shall be performed with a fade or a time scaling, and some additional things, such crossfading |
| 87 | + or synchronizing. |
| 88 | + |
| 89 | + </p> |
| 90 | + |
| 91 | + <h3>Animation Object Groups</h3> |
| 92 | + |
| 93 | + <p class="desc"> |
| 94 | + |
| 95 | + If you want a group of objects to receive a shared animation state, you can use an |
| 96 | + [page:AnimationObjectGroup]. |
| 97 | + |
| 98 | + </p> |
| 99 | + |
| 100 | + <h3>Supported Formats and Loaders</h3> |
| 101 | + |
| 102 | + <p class="desc"> |
| 103 | + Note that not all model formats include animation (OBJ notably does not), and that only some |
| 104 | + three.js loaders support [page:AnimationClip AnimationClip] sequences. Several that <i>do</i> |
| 105 | + support this animation type: |
| 106 | + </p> |
| 107 | + |
| 108 | + <ul> |
| 109 | + <li>[page:ObjectLoader THREE.ObjectLoader]</li> |
| 110 | + <li>THREE.BVHLoader</li> |
| 111 | + <li>THREE.ColladaLoader</li> |
| 112 | + <li>THREE.FBXLoader</li> |
| 113 | + <li>[page:GLTFLoader THREE.GLTFLoader]</li> |
| 114 | + <li>THREE.MMDLoader</li> |
| 115 | + </ul> |
| 116 | + |
| 117 | + <p class="desc"> |
| 118 | + Note that 3ds max and Maya currently can't export multiple animations (meaning animations which are not |
| 119 | + on the same timeline) directly to a single file. |
| 120 | + </p> |
| 121 | + |
| 122 | + <h2>Example</h2> |
| 123 | + |
| 124 | + <code> |
| 125 | + let mesh; |
| 126 | + |
| 127 | + // Create an AnimationMixer, and get the list of AnimationClip instances |
| 128 | + const mixer = new THREE.AnimationMixer( mesh ); |
| 129 | + const clips = mesh.animations; |
| 130 | + |
| 131 | + // Update the mixer on each frame |
| 132 | + function update () { |
| 133 | + mixer.update( deltaSeconds ); |
| 134 | + } |
| 135 | + |
| 136 | + // Play a specific animation |
| 137 | + const clip = THREE.AnimationClip.findByName( clips, 'dance' ); |
| 138 | + const action = mixer.clipAction( clip ); |
| 139 | + action.play(); |
| 140 | + |
| 141 | + // Play all animations |
| 142 | + clips.forEach( function ( clip ) { |
| 143 | + mixer.clipAction( clip ).play(); |
| 144 | + } ); |
| 145 | + </code> |
| 146 | + |
| 147 | + </body> |
| 148 | +</html> |
0 commit comments