AnimationAction.html 14 KB

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