KeyframeTrack.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. <p class="desc">
  12. A KeyframeTrack is a timed sequence of [link:https://en.wikipedia.org/wiki/Key_frame keyframes],
  13. which are composed of lists of times and related values, and which are used to animate a
  14. specific property of an object.
  15. </p>
  16. <p>
  17. For an overview of the different elements of the three.js animation system see the
  18. "Animation System" article in the "Next Steps" section of the manual.
  19. </p>
  20. <p>
  21. In contrast to the animation hierarchy of the
  22. [link:https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3 JSON model format] a
  23. *KeyframeTrack* doesn't store its single keyframes as objects in a "keys" array (holding the
  24. times and the values for each frame together in one place).
  25. </p>
  26. <p>
  27. Instead of this there are always two arrays in a *KeyframeTrack*: the [page:.times times] array
  28. stores the time values for all keyframes of this track in sequential order, and the
  29. [page:.values values] array contains the corresponding changing values of the animated property.
  30. </p>
  31. <p>
  32. A single value, belonging to a certain point of time, can not only be a simple number, but (for
  33. example) a vector (if a position is animated) or a quaternion (if a rotation is animated). For
  34. this reason the values array (which is a flat array, too) might be three or four times as long as the
  35. times array.
  36. </p>
  37. <p>
  38. Corresponding to the different possible types of animated values there are several subclasses of
  39. *KeyframeTrack*, inheriting the most properties and methods:
  40. </p>
  41. <ul>
  42. <li>[page:BooleanKeyframeTrack]</li>
  43. <li>[page:ColorKeyframeTrack]</li>
  44. <li>[page:NumberKeyframeTrack]</li>
  45. <li>[page:QuaternionKeyframeTrack]</li>
  46. <li>[page:StringKeyframeTrack]</li>
  47. <li>[page:VectorKeyframeTrack]</li>
  48. </ul>
  49. <p>
  50. Some examples of how to manually create [page:AnimationClip AnimationClips] with different sorts
  51. of KeyframeTracks can be found in the [link:https://threejs.org/examples/jsm/animation/AnimationClipCreator.js AnimationClipCreator]
  52. file.
  53. </p>
  54. <p>
  55. Since explicit values are only specified for the discrete points of time stored in the times array,
  56. all values in between have to be interpolated.
  57. </p>
  58. <p>
  59. The track's name is important for the connection of this track with a specific property of the
  60. animated node (done by [page:PropertyBinding]).
  61. </p>
  62. <h2>Constructor</h2>
  63. <h3>[name]( [param:String name], [param:Array times], [param:Array values], [param:Constant interpolation] )</h3>
  64. <p>
  65. [page:String name] - the identifier for the *KeyframeTrack*.<br />
  66. [page:Array times] - an array of keyframe times, converted internally to a
  67. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array Float32Array].<br />
  68. [page:Array values] - an array with the values related to the times array, converted internally to a
  69. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array Float32Array].<br />
  70. [page:Constant interpolation] - the type of interpolation to use. See
  71. [page:Animation Animation Constants] for possible values. Default is [page:Animation InterpolateLinear].
  72. </p>
  73. <h2>Properties</h2>
  74. <h3>[property:String name]</h3>
  75. <p>
  76. The track's name can refer to morph targets or [page:SkinnedMesh bones] or possibly other values within an animated object. See
  77. [page:PropertyBinding.parseTrackName] for the forms of strings that can be parsed for property
  78. binding:
  79. </p>
  80. <p>
  81. The name can specify the node either using its name or its uuid (although it needs to be in the
  82. subtree of the scene graph node passed into the mixer). Or, if the track name starts with a dot,
  83. the track applies to the root node that was passed into the mixer.
  84. </p>
  85. <p>
  86. Usually after the node a property will be specified directly. But you can also specify a
  87. subproperty, such as .rotation[x], if you just want to drive the X component of the rotation
  88. via a float track.
  89. </p>
  90. <p>
  91. You can also specify bones or multimaterials by using an object name, for example:
  92. .bones[R_hand].scale; the red channel of the diffuse color of the fourth material in a
  93. materials array - as a further example - can be accessed with .materials[3].diffuse[r].
  94. </p>
  95. <p>
  96. PropertyBinding will also resolve morph target names, for example: .morphTargetInfluences[run].
  97. </p>
  98. <p>
  99. Note: The track's name does not necessarily have to be unique. Multiple tracks can drive the same
  100. property. The result should be based on a weighted blend between the multiple tracks according to
  101. the weights of their respective actions.
  102. </p>
  103. <h3>[property:Float32Array times]</h3>
  104. <p>
  105. A [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array Float32Array],
  106. converted from the times array which is passed in the constructor.
  107. </p>
  108. <h3>[property:Float32Array values]</h3>
  109. <p>
  110. A [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array Float32Array],
  111. converted from the values array which is passed in the constructor.
  112. </p>
  113. <h3>[property:Constant DefaultInterpolation]</h3>
  114. <p>
  115. The default interpolation type: [page:Animation InterpolateLinear].
  116. </p>
  117. <h3>[property:Constant TimeBufferType ]</h3>
  118. <p>
  119. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array Float32Array],
  120. the type of the buffer internally used for the times.
  121. </p>
  122. <h3>[property:Constant ValueBufferType ]</h3>
  123. <p>
  124. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array Float32Array],
  125. the type of the buffer internally used for the values.
  126. </p>
  127. <h2>Methods</h2>
  128. <h3>[method:KeyframeTrack clone]()</h3>
  129. <p>
  130. Returns a copy of this track.
  131. </p>
  132. <h3>[method:null createInterpolant]()</h3>
  133. <p>
  134. Creates a [page:LinearInterpolant LinearInterpolant], [page:CubicInterpolant CubicInterpolant]
  135. or [page:DiscreteInterpolant DiscreteInterpolant], depending on the value of the interpolation
  136. parameter passed in the constructor.
  137. </p>
  138. <h3>[method:null getInterpolation]()</h3>
  139. <p>
  140. Returns the interpolation type.
  141. </p>
  142. <h3>[method:Number getValueSize]()</h3>
  143. <p>
  144. Returns the size of each value (that is the length of the [page:.values values] array divided
  145. by the length of the [page:.times times] array).
  146. </p>
  147. <h3>[method:DiscreteInterpolant InterpolantFactoryMethodDiscrete]( [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array result] )</h3>
  148. <p>
  149. Creates a new [page:DiscreteInterpolant DiscreteInterpolant] from the
  150. [page:KeyframeTrack.times times] and [page:KeyframeTrack.times values]. A Float32Array can be
  151. passed which will receive the results. Otherwise a new array with the appropriate size will be
  152. created automatically.
  153. </p>
  154. <h3>[method:null InterpolantFactoryMethodLinear]( [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array result] )</h3>
  155. <p>
  156. Creates a new [page:LinearInterpolant LinearInterpolant] from the
  157. [page:KeyframeTrack.times times] and [page:KeyframeTrack.times values]. A Float32Array can be
  158. passed which will receive the results. Otherwise a new array with the appropriate size will be
  159. created automatically.
  160. </p>
  161. <h3>[method:null InterpolantFactoryMethodSmooth]( [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array result] )</h3>
  162. <p>
  163. Create a new [page:CubicInterpolant CubicInterpolant] from the
  164. [page:KeyframeTrack.times times] and [page:KeyframeTrack.times values]. A Float32Array can be
  165. passed which will receive the results. Otherwise a new array with the appropriate size will be
  166. created automatically.
  167. </p>
  168. <h3>[method:this optimize]()</h3>
  169. <p>
  170. Removes equivalent sequential keys, which are common in morph target sequences.
  171. </p>
  172. <h3>[method:this scale]()</h3>
  173. <p>
  174. Scales all keyframe times by a factor.<br /><br />
  175. Note: This is useful, for example, for conversions to a certain rate of frames per seconds (as it
  176. is done internally by
  177. [page:AnimationClip.CreateFromMorphTargetSequence animationClip.CreateFromMorphTargetSequence]).
  178. </p>
  179. <h3>[method:this setInterpolation]( [param:Constant interpolationType] )</h3>
  180. <p>
  181. Sets the interpolation type. See [page:Animation Animation Constants] for choices.
  182. </p>
  183. <h3>[method:this shift]( [param:Number timeOffsetInSeconds] )</h3>
  184. <p>
  185. Moves all keyframes either forward or backward in time.
  186. </p>
  187. <h3>[method:this trim]( [param:Number startTimeInSeconds], [param:Number endTimeInSeconds] )</h3>
  188. <p>
  189. Removes keyframes before *startTime* and after *endTime*,
  190. without changing any values within the range [*startTime*, *endTime*].
  191. </p>
  192. <h3>[method:Boolean validate]()</h3>
  193. <p>
  194. Performs minimal validation on the tracks. Returns true if valid.
  195. </p>
  196. <p>
  197. This method logs errors to the console, if a track is empty, if the [page:.valueSize value size] is not valid, if an item
  198. in the [page:.times times] or [page:.values values] array is not a valid number or if the items in the *times* array are out of order.
  199. </p>
  200. <h2>Static Methods</h2>
  201. <h3>[method:JSON toJSON]( [param:KeyframeTrack track] )</h3>
  202. <p>
  203. Converts the track to JSON.
  204. </p>
  205. <h2>Source</h2>
  206. <p>
  207. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  208. </p>
  209. </body>
  210. </html>