AnimationAction.html 17 KB

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