animation-system.html 6.0 KB

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