KeyframeTrack.html 10.0 KB

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