2
0

Animation-system.html 5.4 KB

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