AnimationAction.html 15 KB

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