animationGroup.d.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. import type { Animatable } from "./animatable";
  2. import { Animation } from "./animation";
  3. import type { IMakeAnimationAdditiveOptions } from "./animation";
  4. import type { Scene, IDisposable } from "../scene";
  5. import { Observable } from "../Misc/observable";
  6. import type { Nullable } from "../types";
  7. import type { AbstractScene } from "../abstractScene";
  8. import type { AnimationGroupMask } from "./animationGroupMask";
  9. /**
  10. * This class defines the direct association between an animation and a target
  11. */
  12. export declare class TargetedAnimation {
  13. /**
  14. * Animation to perform
  15. */
  16. animation: Animation;
  17. /**
  18. * Target to animate
  19. */
  20. target: any;
  21. /**
  22. * Returns the string "TargetedAnimation"
  23. * @returns "TargetedAnimation"
  24. */
  25. getClassName(): string;
  26. /**
  27. * Serialize the object
  28. * @returns the JSON object representing the current entity
  29. */
  30. serialize(): any;
  31. }
  32. /**
  33. * Options to be used when creating an additive group animation
  34. */
  35. export interface IMakeAnimationGroupAdditiveOptions extends IMakeAnimationAdditiveOptions {
  36. /**
  37. * Defines if the animation group should be cloned or not (default is false)
  38. */
  39. cloneOriginalAnimationGroup?: boolean;
  40. /**
  41. * The name of the cloned animation group if cloneOriginalAnimationGroup is true
  42. */
  43. clonedAnimationGroupName?: string;
  44. }
  45. /**
  46. * Use this class to create coordinated animations on multiple targets
  47. */
  48. export declare class AnimationGroup implements IDisposable {
  49. /** The name of the animation group */
  50. name: string;
  51. private _scene;
  52. private _targetedAnimations;
  53. private _animatables;
  54. private _from;
  55. private _to;
  56. private _isStarted;
  57. private _isPaused;
  58. private _speedRatio;
  59. private _loopAnimation;
  60. private _isAdditive;
  61. private _weight;
  62. private _playOrder;
  63. private _enableBlending;
  64. private _blendingSpeed;
  65. private _numActiveAnimatables;
  66. /** @internal */
  67. _parentContainer: Nullable<AbstractScene>;
  68. /**
  69. * Gets or sets the unique id of the node
  70. */
  71. uniqueId: number;
  72. /**
  73. * This observable will notify when one animation have ended
  74. */
  75. onAnimationEndObservable: Observable<TargetedAnimation>;
  76. /**
  77. * Observer raised when one animation loops
  78. */
  79. onAnimationLoopObservable: Observable<TargetedAnimation>;
  80. /**
  81. * Observer raised when all animations have looped
  82. */
  83. onAnimationGroupLoopObservable: Observable<AnimationGroup>;
  84. /**
  85. * This observable will notify when all animations have ended.
  86. */
  87. onAnimationGroupEndObservable: Observable<AnimationGroup>;
  88. /**
  89. * This observable will notify when all animations have paused.
  90. */
  91. onAnimationGroupPauseObservable: Observable<AnimationGroup>;
  92. /**
  93. * This observable will notify when all animations are playing.
  94. */
  95. onAnimationGroupPlayObservable: Observable<AnimationGroup>;
  96. /**
  97. * Gets or sets an object used to store user defined information for the node
  98. */
  99. metadata: any;
  100. private _mask;
  101. /**
  102. * Gets or sets the mask associated with this animation group. This mask is used to filter which objects should be animated.
  103. */
  104. get mask(): Nullable<AnimationGroupMask>;
  105. set mask(value: Nullable<AnimationGroupMask>);
  106. /**
  107. * Makes sure that the animations are either played or stopped according to the animation group mask.
  108. * Note however that the call won't have any effect if the animation group has not been started yet.
  109. * @param forceUpdate If true, forces to loop over the animatables even if no mask is defined (used internally, you shouldn't need to use it). Default: false.
  110. */
  111. syncWithMask(forceUpdate?: boolean): void;
  112. /**
  113. * Removes all animations for the targets not retained by the animation group mask.
  114. * Use this function if you know you won't need those animations anymore and if you want to free memory.
  115. */
  116. removeUnmaskedAnimations(): void;
  117. /**
  118. * Gets or sets the first frame
  119. */
  120. get from(): number;
  121. set from(value: number);
  122. /**
  123. * Gets or sets the last frame
  124. */
  125. get to(): number;
  126. set to(value: number);
  127. /**
  128. * Define if the animations are started
  129. */
  130. get isStarted(): boolean;
  131. /**
  132. * Gets a value indicating that the current group is playing
  133. */
  134. get isPlaying(): boolean;
  135. /**
  136. * Gets or sets the speed ratio to use for all animations
  137. */
  138. get speedRatio(): number;
  139. /**
  140. * Gets or sets the speed ratio to use for all animations
  141. */
  142. set speedRatio(value: number);
  143. /**
  144. * Gets or sets if all animations should loop or not
  145. */
  146. get loopAnimation(): boolean;
  147. set loopAnimation(value: boolean);
  148. /**
  149. * Gets or sets if all animations should be evaluated additively
  150. */
  151. get isAdditive(): boolean;
  152. set isAdditive(value: boolean);
  153. /**
  154. * Gets or sets the weight to apply to all animations of the group
  155. */
  156. get weight(): number;
  157. set weight(value: number);
  158. /**
  159. * Gets the targeted animations for this animation group
  160. */
  161. get targetedAnimations(): Array<TargetedAnimation>;
  162. /**
  163. * returning the list of animatables controlled by this animation group.
  164. */
  165. get animatables(): Array<Animatable>;
  166. /**
  167. * Gets the list of target animations
  168. */
  169. get children(): TargetedAnimation[];
  170. /**
  171. * Gets or sets the order of play of the animation group (default: 0)
  172. */
  173. get playOrder(): number;
  174. set playOrder(value: number);
  175. /**
  176. * Allows the animations of the animation group to blend with current running animations
  177. * Note that a null value means that each animation will use their own existing blending configuration (Animation.enableBlending)
  178. */
  179. get enableBlending(): Nullable<boolean>;
  180. set enableBlending(value: Nullable<boolean>);
  181. /**
  182. * Gets or sets the animation blending speed
  183. * Note that a null value means that each animation will use their own existing blending configuration (Animation.blendingSpeed)
  184. */
  185. get blendingSpeed(): Nullable<number>;
  186. set blendingSpeed(value: Nullable<number>);
  187. /**
  188. * Gets the length (in seconds) of the animation group
  189. * This function assumes that all animations are played at the same framePerSecond speed!
  190. * Note: you can only call this method after you've added at least one targeted animation!
  191. * @param from Starting frame range (default is AnimationGroup.from)
  192. * @param to Ending frame range (default is AnimationGroup.to)
  193. * @returns The length in seconds
  194. */
  195. getLength(from?: number, to?: number): number;
  196. /**
  197. * Merge the array of animation groups into a new animation group
  198. * @param animationGroups List of animation groups to merge
  199. * @param disposeSource If true, animation groups will be disposed after being merged (default: true)
  200. * @param normalize If true, animation groups will be normalized before being merged, so that all animations have the same "from" and "to" frame (default: false)
  201. * @param weight Weight for the new animation group. If not provided, it will inherit the weight from the first animation group of the array
  202. * @returns The new animation group or null if no animation groups were passed
  203. */
  204. static MergeAnimationGroups(animationGroups: Array<AnimationGroup>, disposeSource?: boolean, normalize?: boolean, weight?: number): Nullable<AnimationGroup>;
  205. /**
  206. * Instantiates a new Animation Group.
  207. * This helps managing several animations at once.
  208. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/groupAnimations
  209. * @param name Defines the name of the group
  210. * @param scene Defines the scene the group belongs to
  211. * @param weight Defines the weight to use for animations in the group (-1.0 by default, meaning "no weight")
  212. * @param playOrder Defines the order of play of the animation group (default is 0)
  213. */
  214. constructor(
  215. /** The name of the animation group */
  216. name: string, scene?: Nullable<Scene>, weight?: number, playOrder?: number);
  217. /**
  218. * Add an animation (with its target) in the group
  219. * @param animation defines the animation we want to add
  220. * @param target defines the target of the animation
  221. * @returns the TargetedAnimation object
  222. */
  223. addTargetedAnimation(animation: Animation, target: any): TargetedAnimation;
  224. /**
  225. * Remove an animation from the group
  226. * @param animation defines the animation we want to remove
  227. */
  228. removeTargetedAnimation(animation: Animation): void;
  229. /**
  230. * This function will normalize every animation in the group to make sure they all go from beginFrame to endFrame
  231. * It can add constant keys at begin or end
  232. * @param beginFrame defines the new begin frame for all animations or the smallest begin frame of all animations if null (defaults to null)
  233. * @param endFrame defines the new end frame for all animations or the largest end frame of all animations if null (defaults to null)
  234. * @returns the animation group
  235. */
  236. normalize(beginFrame?: Nullable<number>, endFrame?: Nullable<number>): AnimationGroup;
  237. private _animationLoopCount;
  238. private _animationLoopFlags;
  239. private _processLoop;
  240. /**
  241. * Start all animations on given targets
  242. * @param loop defines if animations must loop
  243. * @param speedRatio defines the ratio to apply to animation speed (1 by default)
  244. * @param from defines the from key (optional)
  245. * @param to defines the to key (optional)
  246. * @param isAdditive defines the additive state for the resulting animatables (optional)
  247. * @returns the current animation group
  248. */
  249. start(loop?: boolean, speedRatio?: number, from?: number, to?: number, isAdditive?: boolean): AnimationGroup;
  250. /**
  251. * Pause all animations
  252. * @returns the animation group
  253. */
  254. pause(): AnimationGroup;
  255. /**
  256. * Play all animations to initial state
  257. * This function will start() the animations if they were not started or will restart() them if they were paused
  258. * @param loop defines if animations must loop
  259. * @returns the animation group
  260. */
  261. play(loop?: boolean): AnimationGroup;
  262. /**
  263. * Reset all animations to initial state
  264. * @returns the animation group
  265. */
  266. reset(): AnimationGroup;
  267. /**
  268. * Restart animations from key 0
  269. * @returns the animation group
  270. */
  271. restart(): AnimationGroup;
  272. /**
  273. * Stop all animations
  274. * @returns the animation group
  275. */
  276. stop(): AnimationGroup;
  277. /**
  278. * Set animation weight for all animatables
  279. *
  280. * @since 6.12.4
  281. * You can pass the weight to the AnimationGroup constructor, or use the weight property to set it after the group has been created,
  282. * making it easier to define the overall animation weight than calling setWeightForAllAnimatables() after the animation group has been started
  283. * @param weight defines the weight to use
  284. * @returns the animationGroup
  285. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-weights
  286. */
  287. setWeightForAllAnimatables(weight: number): AnimationGroup;
  288. /**
  289. * Synchronize and normalize all animatables with a source animatable
  290. * @param root defines the root animatable to synchronize with (null to stop synchronizing)
  291. * @returns the animationGroup
  292. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-weights
  293. */
  294. syncAllAnimationsWith(root: Nullable<Animatable>): AnimationGroup;
  295. /**
  296. * Goes to a specific frame in this animation group. Note that the animation group must be in playing or paused status
  297. * @param frame the frame number to go to
  298. * @returns the animationGroup
  299. */
  300. goToFrame(frame: number): AnimationGroup;
  301. /**
  302. * Dispose all associated resources
  303. */
  304. dispose(): void;
  305. private _checkAnimationGroupEnded;
  306. /**
  307. * Clone the current animation group and returns a copy
  308. * @param newName defines the name of the new group
  309. * @param targetConverter defines an optional function used to convert current animation targets to new ones
  310. * @param cloneAnimations defines if the animations should be cloned or referenced
  311. * @returns the new animation group
  312. */
  313. clone(newName: string, targetConverter?: (oldTarget: any) => any, cloneAnimations?: boolean): AnimationGroup;
  314. /**
  315. * Serializes the animationGroup to an object
  316. * @returns Serialized object
  317. */
  318. serialize(): any;
  319. /**
  320. * Returns a new AnimationGroup object parsed from the source provided.
  321. * @param parsedAnimationGroup defines the source
  322. * @param scene defines the scene that will receive the animationGroup
  323. * @returns a new AnimationGroup
  324. */
  325. static Parse(parsedAnimationGroup: any, scene: Scene): AnimationGroup;
  326. /**
  327. * Convert the keyframes for all animations belonging to the group to be relative to a given reference frame.
  328. * @param sourceAnimationGroup defines the AnimationGroup containing animations to convert
  329. * @param referenceFrame defines the frame that keyframes in the range will be relative to (default: 0)
  330. * @param range defines the name of the AnimationRange belonging to the animations in the group to convert
  331. * @param cloneOriginal defines whether or not to clone the group and convert the clone or convert the original group (default is false)
  332. * @param clonedName defines the name of the resulting cloned AnimationGroup if cloneOriginal is true
  333. * @returns a new AnimationGroup if cloneOriginal is true or the original AnimationGroup if cloneOriginal is false
  334. */
  335. static MakeAnimationAdditive(sourceAnimationGroup: AnimationGroup, referenceFrame: number, range?: string, cloneOriginal?: boolean, clonedName?: string): AnimationGroup;
  336. /**
  337. * Convert the keyframes for all animations belonging to the group to be relative to a given reference frame.
  338. * @param sourceAnimationGroup defines the AnimationGroup containing animations to convert
  339. * @param options defines the options to use when converting keyframes
  340. * @returns a new AnimationGroup if options.cloneOriginalAnimationGroup is true or the original AnimationGroup if options.cloneOriginalAnimationGroup is false
  341. */
  342. static MakeAnimationAdditive(sourceAnimationGroup: AnimationGroup, options?: IMakeAnimationGroupAdditiveOptions): AnimationGroup;
  343. /**
  344. * Creates a new animation, keeping only the keys that are inside a given key range
  345. * @param sourceAnimationGroup defines the animation group on which to operate
  346. * @param fromKey defines the lower bound of the range
  347. * @param toKey defines the upper bound of the range
  348. * @param name defines the name of the new animation group. If not provided, use the same name as animationGroup
  349. * @param dontCloneAnimations defines whether or not the animations should be cloned before clipping the keys. Default is false, so animations will be cloned
  350. * @returns a new animation group stripped from all the keys outside the given range
  351. */
  352. static ClipKeys(sourceAnimationGroup: AnimationGroup, fromKey: number, toKey: number, name?: string, dontCloneAnimations?: boolean): AnimationGroup;
  353. /**
  354. * Updates an existing animation, keeping only the keys that are inside a given key range
  355. * @param animationGroup defines the animation group on which to operate
  356. * @param fromKey defines the lower bound of the range
  357. * @param toKey defines the upper bound of the range
  358. * @param dontCloneAnimations defines whether or not the animations should be cloned before clipping the keys. Default is false, so animations will be cloned
  359. * @returns the animationGroup stripped from all the keys outside the given range
  360. */
  361. static ClipKeysInPlace(animationGroup: AnimationGroup, fromKey: number, toKey: number, dontCloneAnimations?: boolean): AnimationGroup;
  362. /**
  363. * Creates a new animation, keeping only the frames that are inside a given frame range
  364. * @param sourceAnimationGroup defines the animation group on which to operate
  365. * @param fromFrame defines the lower bound of the range
  366. * @param toFrame defines the upper bound of the range
  367. * @param name defines the name of the new animation group. If not provided, use the same name as animationGroup
  368. * @param dontCloneAnimations defines whether or not the animations should be cloned before clipping the frames. Default is false, so animations will be cloned
  369. * @returns a new animation group stripped from all the frames outside the given range
  370. */
  371. static ClipFrames(sourceAnimationGroup: AnimationGroup, fromFrame: number, toFrame: number, name?: string, dontCloneAnimations?: boolean): AnimationGroup;
  372. /**
  373. * Updates an existing animation, keeping only the frames that are inside a given frame range
  374. * @param animationGroup defines the animation group on which to operate
  375. * @param fromFrame defines the lower bound of the range
  376. * @param toFrame defines the upper bound of the range
  377. * @param dontCloneAnimations defines whether or not the animations should be cloned before clipping the frames. Default is false, so animations will be cloned
  378. * @returns the animationGroup stripped from all the frames outside the given range
  379. */
  380. static ClipFramesInPlace(animationGroup: AnimationGroup, fromFrame: number, toFrame: number, dontCloneAnimations?: boolean): AnimationGroup;
  381. /**
  382. * Updates an existing animation, keeping only the keys that are inside a given key or frame range
  383. * @param animationGroup defines the animation group on which to operate
  384. * @param start defines the lower bound of the range
  385. * @param end defines the upper bound of the range
  386. * @param dontCloneAnimations defines whether or not the animations should be cloned before clipping the keys. Default is false, so animations will be cloned
  387. * @param useFrame defines if the range is defined by frame numbers or key indices (default is false which means use key indices)
  388. * @returns the animationGroup stripped from all the keys outside the given range
  389. */
  390. static ClipInPlace(animationGroup: AnimationGroup, start: number, end: number, dontCloneAnimations?: boolean, useFrame?: boolean): AnimationGroup;
  391. /**
  392. * Returns the string "AnimationGroup"
  393. * @returns "AnimationGroup"
  394. */
  395. getClassName(): string;
  396. /**
  397. * Creates a detailed string about the object
  398. * @param fullDetails defines if the output string will support multiple levels of logging within scene loading
  399. * @returns a string representing the object
  400. */
  401. toString(fullDetails?: boolean): string;
  402. }