Animation-system.html 5.2 KB

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