KeyframeTrack.html 9.7 KB

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