AnimationAction.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. AnimationActions schedule the performance of the animations which are stored in
  13. [page:AnimationClip AnimationClips].<br /><br />
  14. Note: Most of AnimationAction's methods can be chained.<br /><br />
  15. For an overview of the different elements of the three.js animation system see the
  16. "Animation System" article in the "Next Steps" section of the manual.
  17. </p>
  18. <h2>Constructor</h2>
  19. <h3>[name]( [param:AnimationMixer mixer], [param:AnimationClip clip], [param:Object3D localRoot] )</h3>
  20. <p>
  21. [page:AnimationMixer mixer] - the *AnimationMixer* that is controlled by this action.<br />
  22. [page:AnimationClip clip] - the *AnimationClip* that holds the animation data for this action.<br />
  23. [page:Object3D localRoot] - the root object on which this action is performed.<br /><br />
  24. Note: Instead of calling this constructor directly you should instantiate an AnimationAction with
  25. [page:AnimationMixer.clipAction] since this method provides caching for better performance.
  26. </p>
  27. <h2>Properties</h2>
  28. <h3>[property:Boolean clampWhenFinished]</h3>
  29. <p>
  30. If *clampWhenFinished* is set to true the animation will automatically be [page:.paused paused]
  31. on its last frame.<br /><br />
  32. If *clampWhenFinished* is set to false, [page:.enabled enabled] will automatically be switched
  33. to false when the last loop of the action has finished, so that this action has no further
  34. impact.<br /><br />
  35. Default is false.<br /><br />
  36. Note: *clampWhenFinished* has no impact if the action is interrupted (it has only an effect if
  37. its last loop has really finished).
  38. </p>
  39. <h3>[property:Boolean enabled]</h3>
  40. <p>
  41. Setting *enabled* to *false* disables this action, so that it has no impact. Default is *true*.<br /><br />
  42. When the action is re-enabled, the animation continues from its current [page:.time time]
  43. (setting *enabled* to *false* doesn't reset the action).<br /><br />
  44. Note: Setting *enabled* to *true* doesn’t automatically restart the animation. Setting *enabled*
  45. to *true* will only restart the animation immediately if the following condition is fulfilled:
  46. [page:.paused paused] is *false*, this action has not been deactivated in the meantime (by
  47. executing a [page:.stop stop] or [page:.reset reset] command), and neither [page:.weight weight]
  48. nor [page:.timeScale timeScale] is 0.
  49. </p>
  50. <h3>[property:Number loop]</h3>
  51. <p>
  52. The looping mode (can be changed with [page:.setLoop setLoop]). Default is
  53. [page:Animation THREE.LoopRepeat] (with an infinite number of [page:.repetitions repetitions])<br /><br />
  54. Must be one of these constants:<br /><br />
  55. [page:Animation THREE.LoopOnce] - playing the clip once,<br />
  56. [page:Animation THREE.LoopRepeat] - playing the clip with the choosen number of *repetitions*,
  57. each time jumping from the end of the clip directly to its beginning,<br />
  58. [page:Animation THREE.LoopPingPong] - playing the clip with the choosen number of *repetitions*,
  59. alternately playing forward and backward.
  60. </p>
  61. <h3>[property:Boolean paused]</h3>
  62. <p>
  63. Setting *paused* to *true* pauses the execution of the action by setting the effective time scale
  64. to 0. Default is *false*.<br /><br />
  65. </p>
  66. <h3>[property:Number repetitions]</h3>
  67. <p>
  68. The number of repetitions of the performed [page:AnimationClip] over the course of this action.
  69. Can be set via [page:.setLoop setLoop]. Default is *Infinity*.<br /><br />
  70. Setting this number has no effect, if the [page:.loop loop mode] is set to
  71. [page:Animation THREE.LoopOnce].
  72. </p>
  73. <h3>[property:Number time]</h3>
  74. <p>
  75. The local time of this action (in seconds, starting with 0).<br /><br />
  76. The value gets clamped or wrapped to 0...clip.duration (according to the loop state). It can be
  77. scaled relativly to the global mixer time by changing [page:.timeScale timeScale] (using
  78. [page:.setEffectiveTimeScale setEffectiveTimeScale] or [page:.setDuration setDuration]).<br />
  79. </p>
  80. <h3>[property:Number timeScale]</h3>
  81. <p>
  82. Scaling factor for the [page:.time time]. A value of 0 causes the animation to pause. Negative
  83. values cause the animation to play backwards. Default is 1.<br /><br />
  84. Properties/methods concerning *timeScale* (respectively *time*) are:
  85. [page:.getEffectiveTimeScale getEffectiveTimeScale],
  86. [page:.halt halt],
  87. [page:.paused paused],
  88. [page:.setDuration setDuration],
  89. [page:.setEffectiveTimeScale setEffectiveTimeScale],
  90. [page:.stopWarping stopWarping],
  91. [page:.syncWith syncWith],
  92. [page:.warp warp].
  93. </p>
  94. <h3>[property:Number weight]</h3>
  95. <p>
  96. The degree of influence of this action (in the interval [0, 1]). Values between 0 (no impact)
  97. and 1 (full impact) can be used to blend between several actions. Default is 1. <br /><br />
  98. Properties/methods concerning *weight* are:
  99. [page:.crossFadeFrom crossFadeFrom],
  100. [page:.crossFadeTo crossFadeTo],
  101. [page:.enabled enabled],
  102. [page:.fadeIn fadeIn],
  103. [page:.fadeOut fadeOut],
  104. [page:.getEffectiveWeight getEffectiveWeight],
  105. [page:.setEffectiveWeight setEffectiveWeight],
  106. [page:.stopFading stopFading].
  107. </p>
  108. <h3>[property:Boolean zeroSlopeAtEnd]</h3>
  109. <p>
  110. Enables smooth interpolation without separate clips for start, loop and end. Default is *true*.
  111. </p>
  112. <h3>[property:Boolean zeroSlopeAtStart]</h3>
  113. <p>
  114. Enables smooth interpolation without separate clips for start, loop and end. Default is *true*.
  115. </p>
  116. <h2>Methods</h2>
  117. <h3>[method:AnimationAction crossFadeFrom]( [param:AnimationAction fadeOutAction], [param:Number durationInSeconds], [param:Boolean warpBoolean] )</h3>
  118. <p>
  119. Causes this action to [page:.fadeIn fade in], fading out another action simultaneously, within
  120. the passed time interval. This method can be chained.<br /><br />
  121. If warpBoolean is true, additional [page:.warp warping] (gradually changes of the time scales)
  122. will be applied.<br /><br />
  123. Note: Like with *fadeIn*/*fadeOut*, the fading starts/ends with a weight of 1.
  124. </p>
  125. <h3>[method:AnimationAction crossFadeTo]( [param:AnimationAction fadeInAction], [param:Number durationInSeconds], [param:Boolean warpBoolean] )</h3>
  126. <p>
  127. Causes this action to [page:.fadeOut fade out], fading in another action simultaneously, within
  128. the passed time interval. This method can be chained.<br /><br />
  129. If warpBoolean is true, additional [page:.warp warping] (gradually changes of the time scales)
  130. will be applied.<br /><br />
  131. Note: Like with *fadeIn*/*fadeOut*, the fading starts/ends with a weight of 1.
  132. </p>
  133. <h3>[method:AnimationAction fadeIn]( [param:Number durationInSeconds] )</h3>
  134. <p>
  135. Increases the [page:.weight weight] of this action gradually from 0 to 1, within the passed time
  136. interval. This method can be chained.
  137. </p>
  138. <h3>[method:AnimationAction fadeOut]( [param:Number durationInSeconds] )</h3>
  139. <p>
  140. Decreases the [page:.weight weight] of this action gradually from 1 to 0, within the passed time
  141. interval. This method can be chained.
  142. </p>
  143. <h3>[method:Number getEffectiveTimeScale]()</h3>
  144. <p>
  145. Returns the effective time scale (considering the current states of warping and
  146. [page:.paused paused]).
  147. </p>
  148. <h3>[method:number getEffectiveWeight]()</h3>
  149. <p>
  150. Returns the effective weight (considering the current states of fading and
  151. [page:.enabled enabled]).
  152. </p>
  153. <h3>[method:AnimationClip getClip]()</h3>
  154. <p>
  155. Returns the clip which holds the animation data for this action.
  156. </p>
  157. <h3>[method:AnimationMixer getMixer]()</h3>
  158. <p>
  159. Returns the mixer which is responsible for playing this action.
  160. </p>
  161. <h3>[method:Object3D getRoot]()</h3>
  162. <p>
  163. Returns the root object on which this action is performed.
  164. </p>
  165. <h3>[method:AnimationAction halt]( [param:Number durationInSeconds] )</h3>
  166. <p>
  167. Decelerates this animation's speed to 0 by decreasing [page:.timeScale timeScale] gradually
  168. (starting from its current value), within the passed time interval. This method can be chained.
  169. </p>
  170. <h3>[method:Boolean isRunning]()</h3>
  171. <p>
  172. Returns true if the action’s [page:.time time] is currently running.<br /><br />
  173. In addition to being activated in the mixer (see [page:.isScheduled isScheduled]) the following conditions must be fulfilled:
  174. [page:.paused paused] is equal to false, [page:.enabled enabled] is equal to true,
  175. [page:.timeScale timeScale] is different from 0, and there is no scheduling for a delayed start
  176. ([page:.startAt startAt]).<br /><br />
  177. Note: *isRunning* being true doesn’t necessarily mean that the animation can actually be seen.
  178. This is only the case, if [page:.weight weight] is additionally set to a non-zero value.
  179. </p>
  180. <h3>[method:Boolean isScheduled]()</h3>
  181. <p>
  182. Returns true, if this action is activated in the mixer.<br /><br />
  183. Note: This doesn’t necessarily mean that the animation is actually running (compare the additional
  184. conditions for [page:.isRunning isRunning]).
  185. </p>
  186. <h3>[method:AnimationAction play]()</h3>
  187. <p>
  188. Tells the mixer to activate the action. This method can be chained.<br /><br />
  189. Note: Activating this action doesn’t necessarily mean that the animation starts immediately:
  190. If the action had already finished before (by reaching the end of its last loop), or if a time
  191. for a delayed start has been set (via [page:.startAt startAt]), a [page:.reset reset] must be
  192. executed first. Some other settings ([page:.paused paused]=true, [page:.enabled enabled]=false,
  193. [page:.weight weight]=0, [page:.timeScale timeScale]=0) can prevent the animation from playing,
  194. too.
  195. </p>
  196. <h3>[method:AnimationAction reset]()</h3>
  197. <p>
  198. Resets the action. This method can be chained.<br /><br />
  199. This method sets [page:.paused paused] to false, [page:.enabled enabled] to true,
  200. [page:.time time] to 0, interrupts any scheduled fading and warping, and removes the internal
  201. loop count and scheduling for delayed starting.<br /><br />
  202. Note: .*reset* is always called by [page:.stop stop], but .*reset* doesn’t call .*stop* itself.
  203. This means: If you want both, resetting and stopping, don’t call .*reset*; call .*stop* instead.
  204. </p>
  205. <h3>[method:AnimationAction setDuration]( [param:Number durationInSeconds] )</h3>
  206. <p>
  207. Sets the duration for a single loop of this action (by adjusting [page:.timeScale timeScale]
  208. and stopping any scheduled warping). This method can be chained.
  209. </p>
  210. <h3>[method:AnimationAction setEffectiveTimeScale]( [param:Number timeScale] )</h3>
  211. <p>
  212. Sets the [page:.timeScale timeScale] and stops any scheduled warping. This method can be chained.<br /><br />
  213. If [page:.paused paused] is false, the effective time scale (an internal property) will also be set
  214. to this value; otherwise the effective time scale (directly affecting the animation at
  215. this moment) will be set to 0.<br /><br />
  216. Note: .*paused* will not be switched to *true* automatically, if .*timeScale* is set to 0 by
  217. this method.
  218. </p>
  219. <h3>[method:AnimationAction setEffectiveWeight]( [param:Number weight] )</h3>
  220. <p>
  221. Sets the [page:.weight weight] and stops any scheduled fading. This method can be chained.<br /><br />
  222. If [page:.enabled enabled] is true, the effective weight (an internal property) will also be set
  223. to this value; otherwise the effective weight (directly affecting the animation at this moment)
  224. will be set to 0.<br /><br />
  225. Note: .*enabled* will not be switched to *false* automatically, if .*weight* is set to 0 by
  226. this method.
  227. </p>
  228. <h3>[method:AnimationAction setLoop]( [param:Number loopMode], [param:Number repetitions] )</h3>
  229. <p>
  230. Sets the [page:.loop loop mode] and the number of [page:.repetitions repetitions]. This method
  231. can be chained.
  232. </p>
  233. <h3>[method:AnimationAction startAt]( [param:Number startTimeInSeconds] )</h3>
  234. <p>
  235. Defines the time for a delayed start (usually passed as [page:AnimationMixer.time] +
  236. deltaTimeInSeconds). This method can be chained.<br /><br />
  237. Note: The animation will only start at the given time, if .*startAt* is chained with
  238. [page:.play play], or if the action has already been activated in the mixer (by a previous
  239. call of .*play*, without stopping or resetting it in the meantime).
  240. </p>
  241. <h3>[method:AnimationAction stop]()</h3>
  242. <p>
  243. Tells the mixer to deactivate this action. This method can be chained.<br /><br />
  244. The action will be immediately stopped and completely [page:.reset reset].<br /><br />
  245. Note: You can stop all active actions on the same mixer in one go via
  246. [page:AnimationMixer.stopAllAction mixer.stopAllAction].
  247. </p>
  248. <h3>[method:AnimationAction stopFading]()</h3>
  249. <p>
  250. Stops any scheduled [page:.fadeIn fading] which is applied to this action. This method can be
  251. chained.
  252. </p>
  253. <h3>[method:AnimationAction stopWarping]()</h3>
  254. <p>
  255. Stops any scheduled [page:.warp warping] which is applied to this action. This method can be
  256. chained.
  257. </p>
  258. <h3>[method:AnimationAction syncWith]( [param:AnimationAction otherAction] )</h3>
  259. <p>
  260. Synchronizes this action with the passed other action. This method can be chained.<br /><br />
  261. Synchronizing is done by setting this action’s [page:.time time] and [page:.timeScale timeScale] values
  262. to the corresponding values of the other action (stopping any scheduled warping).<br /><br />
  263. Note: Future changes of the other action's *time* and *timeScale* will not be detected.
  264. </p>
  265. <h3>[method:AnimationAction warp]( [param:Number startTimeScale], [param:Number endTimeScale], [param:Number durationInSeconds] )</h3>
  266. <p>
  267. Changes the playback speed, within the passed time interval, by modifying
  268. [page:.timeScale timeScale] gradually from *startTimeScale* to *endTimeScale*. This method can
  269. be chained.
  270. </p>
  271. <h2>Events</h2>
  272. <p class="desc">
  273. There are two events indicating when a single loop of the action respectively the entire action has finished. You can react to them with:
  274. </p>
  275. <code>
  276. mixer.addEventListener( 'loop', function( e ) { …} ); // properties of e: type, action and loopDelta
  277. mixer.addEventListener( 'finished', function( e ) { …} ); // properties of e: type, action and direction
  278. </code>
  279. <h2>Source</h2>
  280. <p>
  281. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  282. </p>
  283. </body>
  284. </html>