@babylonjs/core 7.27.1 → 7.27.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/Animations/animatable.core.d.ts +198 -0
  2. package/Animations/animatable.core.js +893 -0
  3. package/Animations/animatable.core.js.map +1 -0
  4. package/Animations/animatable.d.ts +4 -213
  5. package/Animations/animatable.js +5 -886
  6. package/Animations/animatable.js.map +1 -1
  7. package/Animations/animationGroup.d.ts +1 -1
  8. package/Animations/animationGroup.js.map +1 -1
  9. package/Animations/runtimeAnimation.d.ts +1 -0
  10. package/Animations/runtimeAnimation.js +25 -1
  11. package/Animations/runtimeAnimation.js.map +1 -1
  12. package/Audio/audioSceneComponent.d.ts +0 -4
  13. package/Audio/audioSceneComponent.js.map +1 -1
  14. package/Behaviors/Cameras/bouncingBehavior.js.map +1 -1
  15. package/Behaviors/Cameras/framingBehavior.js.map +1 -1
  16. package/Bones/skeleton.d.ts +1 -1
  17. package/Bones/skeleton.js.map +1 -1
  18. package/Culling/ray.core.d.ts +328 -0
  19. package/Culling/ray.core.js +934 -0
  20. package/Culling/ray.core.js.map +1 -0
  21. package/Culling/ray.d.ts +1 -220
  22. package/Culling/ray.js +12 -791
  23. package/Culling/ray.js.map +1 -1
  24. package/Engines/abstractEngine.js +2 -2
  25. package/Engines/abstractEngine.js.map +1 -1
  26. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.d.ts +1 -1
  27. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js.map +1 -1
  28. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.d.ts +1 -1
  29. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js.map +1 -1
  30. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.d.ts +1 -1
  31. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.js.map +1 -1
  32. package/Inputs/scene.inputManager.js +1 -1
  33. package/Inputs/scene.inputManager.js.map +1 -1
  34. package/Layers/effectLayerSceneComponent.d.ts +0 -6
  35. package/Layers/effectLayerSceneComponent.js +0 -1
  36. package/Layers/effectLayerSceneComponent.js.map +1 -1
  37. package/Layers/layerSceneComponent.d.ts +0 -9
  38. package/Layers/layerSceneComponent.js +0 -1
  39. package/Layers/layerSceneComponent.js.map +1 -1
  40. package/LensFlares/lensFlareSystemSceneComponent.d.ts +0 -5
  41. package/LensFlares/lensFlareSystemSceneComponent.js +0 -1
  42. package/LensFlares/lensFlareSystemSceneComponent.js.map +1 -1
  43. package/Lights/light.js.map +1 -1
  44. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.d.ts +0 -10
  45. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.js +0 -1
  46. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.js.map +1 -1
  47. package/Materials/effectRenderer.d.ts +1 -0
  48. package/Materials/effectRenderer.js +2 -0
  49. package/Materials/effectRenderer.js.map +1 -1
  50. package/Meshes/mesh.d.ts +7 -0
  51. package/Meshes/mesh.js +15 -0
  52. package/Meshes/mesh.js.map +1 -1
  53. package/Misc/assetsManager.d.ts +1 -1
  54. package/Misc/assetsManager.js.map +1 -1
  55. package/Misc/tools.js +1 -13
  56. package/Misc/tools.js.map +1 -1
  57. package/Sprites/spriteSceneComponent.d.ts +1 -1
  58. package/Sprites/spriteSceneComponent.js +4 -4
  59. package/Sprites/spriteSceneComponent.js.map +1 -1
  60. package/assetContainer.d.ts +1 -1
  61. package/assetContainer.js.map +1 -1
  62. package/node.d.ts +1 -1
  63. package/node.js.map +1 -1
  64. package/package.json +1 -1
  65. package/scene.d.ts +45 -4
  66. package/scene.js +81 -54
  67. package/scene.js.map +1 -1
@@ -1,888 +1,7 @@
1
- import { Animation } from "./animation.js";
2
- import { RuntimeAnimation } from "./runtimeAnimation.js";
3
- import { Observable } from "../Misc/observable.js";
4
- import { Scene } from "../scene.js";
5
- import { Matrix, Quaternion, Vector3, TmpVectors } from "../Maths/math.vector.js";
6
- import { PrecisionDate } from "../Misc/precisionDate.js";
7
1
  import { Bone } from "../Bones/bone.js";
8
- /**
9
- * Class used to store an actual running animation
10
- */
11
- export class Animatable {
12
- /**
13
- * Gets the root Animatable used to synchronize and normalize animations
14
- */
15
- get syncRoot() {
16
- return this._syncRoot;
17
- }
18
- /**
19
- * Gets the current frame of the first RuntimeAnimation
20
- * Used to synchronize Animatables
21
- */
22
- get masterFrame() {
23
- if (this._runtimeAnimations.length === 0) {
24
- return 0;
25
- }
26
- return this._runtimeAnimations[0].currentFrame;
27
- }
28
- /**
29
- * Gets or sets the animatable weight (-1.0 by default meaning not weighted)
30
- */
31
- get weight() {
32
- return this._weight;
33
- }
34
- set weight(value) {
35
- if (value === -1) {
36
- // -1 is ok and means no weight
37
- this._weight = -1;
38
- return;
39
- }
40
- // Else weight must be in [0, 1] range
41
- this._weight = Math.min(Math.max(value, 0), 1.0);
42
- }
43
- /**
44
- * Gets or sets the speed ratio to apply to the animatable (1.0 by default)
45
- */
46
- get speedRatio() {
47
- return this._speedRatio;
48
- }
49
- set speedRatio(value) {
50
- for (let index = 0; index < this._runtimeAnimations.length; index++) {
51
- const animation = this._runtimeAnimations[index];
52
- animation._prepareForSpeedRatioChange(value);
53
- }
54
- this._speedRatio = value;
55
- // Resync _manualJumpDelay in case goToFrame was called before speedRatio was set.
56
- if (this._goToFrame !== null) {
57
- this.goToFrame(this._goToFrame);
58
- }
59
- }
60
- /**
61
- * Gets the elapsed time since the animatable started in milliseconds
62
- */
63
- get elapsedTime() {
64
- return this._localDelayOffset === null ? 0 : this._scene._animationTime - this._localDelayOffset;
65
- }
66
- /**
67
- * Creates a new Animatable
68
- * @param scene defines the hosting scene
69
- * @param target defines the target object
70
- * @param fromFrame defines the starting frame number (default is 0)
71
- * @param toFrame defines the ending frame number (default is 100)
72
- * @param loopAnimation defines if the animation must loop (default is false)
73
- * @param speedRatio defines the factor to apply to animation speed (default is 1)
74
- * @param onAnimationEnd defines a callback to call when animation ends if it is not looping
75
- * @param animations defines a group of animation to add to the new Animatable
76
- * @param onAnimationLoop defines a callback to call when animation loops
77
- * @param isAdditive defines whether the animation should be evaluated additively
78
- * @param playOrder defines the order in which this animatable should be processed in the list of active animatables (default: 0)
79
- */
80
- constructor(scene,
81
- /** defines the target object */
82
- target,
83
- /** [0] defines the starting frame number (default is 0) */
84
- fromFrame = 0,
85
- /** [100] defines the ending frame number (default is 100) */
86
- toFrame = 100,
87
- /** [false] defines if the animation must loop (default is false) */
88
- loopAnimation = false, speedRatio = 1.0,
89
- /** defines a callback to call when animation ends if it is not looping */
90
- onAnimationEnd, animations,
91
- /** defines a callback to call when animation loops */
92
- onAnimationLoop,
93
- /** [false] defines whether the animation should be evaluated additively */
94
- isAdditive = false,
95
- /** [0] defines the order in which this animatable should be processed in the list of active animatables (default: 0) */
96
- playOrder = 0) {
97
- this.target = target;
98
- this.fromFrame = fromFrame;
99
- this.toFrame = toFrame;
100
- this.loopAnimation = loopAnimation;
101
- this.onAnimationEnd = onAnimationEnd;
102
- this.onAnimationLoop = onAnimationLoop;
103
- this.isAdditive = isAdditive;
104
- this.playOrder = playOrder;
105
- this._localDelayOffset = null;
106
- this._pausedDelay = null;
107
- this._manualJumpDelay = null;
108
- /** @hidden */
109
- this._runtimeAnimations = new Array();
110
- this._paused = false;
111
- this._speedRatio = 1;
112
- this._weight = -1.0;
113
- this._syncRoot = null;
114
- this._frameToSyncFromJump = null;
115
- this._goToFrame = null;
116
- /**
117
- * Gets or sets a boolean indicating if the animatable must be disposed and removed at the end of the animation.
118
- * This will only apply for non looping animation (default is true)
119
- */
120
- this.disposeOnEnd = true;
121
- /**
122
- * Gets a boolean indicating if the animation has started
123
- */
124
- this.animationStarted = false;
125
- /**
126
- * Observer raised when the animation ends
127
- */
128
- this.onAnimationEndObservable = new Observable();
129
- /**
130
- * Observer raised when the animation loops
131
- */
132
- this.onAnimationLoopObservable = new Observable();
133
- this._scene = scene;
134
- if (animations) {
135
- this.appendAnimations(target, animations);
136
- }
137
- this._speedRatio = speedRatio;
138
- scene._activeAnimatables.push(this);
139
- }
140
- // Methods
141
- /**
142
- * Synchronize and normalize current Animatable with a source Animatable
143
- * This is useful when using animation weights and when animations are not of the same length
144
- * @param root defines the root Animatable to synchronize with (null to stop synchronizing)
145
- * @returns the current Animatable
146
- */
147
- syncWith(root) {
148
- this._syncRoot = root;
149
- if (root) {
150
- // Make sure this animatable will animate after the root
151
- const index = this._scene._activeAnimatables.indexOf(this);
152
- if (index > -1) {
153
- this._scene._activeAnimatables.splice(index, 1);
154
- this._scene._activeAnimatables.push(this);
155
- }
156
- }
157
- return this;
158
- }
159
- /**
160
- * Gets the list of runtime animations
161
- * @returns an array of RuntimeAnimation
162
- */
163
- getAnimations() {
164
- return this._runtimeAnimations;
165
- }
166
- /**
167
- * Adds more animations to the current animatable
168
- * @param target defines the target of the animations
169
- * @param animations defines the new animations to add
170
- */
171
- appendAnimations(target, animations) {
172
- for (let index = 0; index < animations.length; index++) {
173
- const animation = animations[index];
174
- const newRuntimeAnimation = new RuntimeAnimation(target, animation, this._scene, this);
175
- newRuntimeAnimation._onLoop = () => {
176
- this.onAnimationLoopObservable.notifyObservers(this);
177
- if (this.onAnimationLoop) {
178
- this.onAnimationLoop();
179
- }
180
- };
181
- this._runtimeAnimations.push(newRuntimeAnimation);
182
- }
183
- }
184
- /**
185
- * Gets the source animation for a specific property
186
- * @param property defines the property to look for
187
- * @returns null or the source animation for the given property
188
- */
189
- getAnimationByTargetProperty(property) {
190
- const runtimeAnimations = this._runtimeAnimations;
191
- for (let index = 0; index < runtimeAnimations.length; index++) {
192
- if (runtimeAnimations[index].animation.targetProperty === property) {
193
- return runtimeAnimations[index].animation;
194
- }
195
- }
196
- return null;
197
- }
198
- /**
199
- * Gets the runtime animation for a specific property
200
- * @param property defines the property to look for
201
- * @returns null or the runtime animation for the given property
202
- */
203
- getRuntimeAnimationByTargetProperty(property) {
204
- const runtimeAnimations = this._runtimeAnimations;
205
- for (let index = 0; index < runtimeAnimations.length; index++) {
206
- if (runtimeAnimations[index].animation.targetProperty === property) {
207
- return runtimeAnimations[index];
208
- }
209
- }
210
- return null;
211
- }
212
- /**
213
- * Resets the animatable to its original state
214
- */
215
- reset() {
216
- const runtimeAnimations = this._runtimeAnimations;
217
- for (let index = 0; index < runtimeAnimations.length; index++) {
218
- runtimeAnimations[index].reset(true);
219
- }
220
- this._localDelayOffset = null;
221
- this._pausedDelay = null;
222
- }
223
- /**
224
- * Allows the animatable to blend with current running animations
225
- * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending
226
- * @param blendingSpeed defines the blending speed to use
227
- */
228
- enableBlending(blendingSpeed) {
229
- const runtimeAnimations = this._runtimeAnimations;
230
- for (let index = 0; index < runtimeAnimations.length; index++) {
231
- runtimeAnimations[index].animation.enableBlending = true;
232
- runtimeAnimations[index].animation.blendingSpeed = blendingSpeed;
233
- }
234
- }
235
- /**
236
- * Disable animation blending
237
- * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending
238
- */
239
- disableBlending() {
240
- const runtimeAnimations = this._runtimeAnimations;
241
- for (let index = 0; index < runtimeAnimations.length; index++) {
242
- runtimeAnimations[index].animation.enableBlending = false;
243
- }
244
- }
245
- /**
246
- * Jump directly to a given frame
247
- * @param frame defines the frame to jump to
248
- */
249
- goToFrame(frame) {
250
- const runtimeAnimations = this._runtimeAnimations;
251
- if (runtimeAnimations[0]) {
252
- const fps = runtimeAnimations[0].animation.framePerSecond;
253
- this._frameToSyncFromJump = this._frameToSyncFromJump ?? runtimeAnimations[0].currentFrame;
254
- const delay = this.speedRatio === 0 ? 0 : (((frame - this._frameToSyncFromJump) / fps) * 1000) / this.speedRatio;
255
- this._manualJumpDelay = -delay;
256
- }
257
- for (let index = 0; index < runtimeAnimations.length; index++) {
258
- runtimeAnimations[index].goToFrame(frame, this._weight);
259
- }
260
- this._goToFrame = frame;
261
- }
262
- /**
263
- * Returns true if the animations for this animatable are paused
264
- */
265
- get paused() {
266
- return this._paused;
267
- }
268
- /**
269
- * Pause the animation
270
- */
271
- pause() {
272
- if (this._paused) {
273
- return;
274
- }
275
- this._paused = true;
276
- }
277
- /**
278
- * Restart the animation
279
- */
280
- restart() {
281
- this._paused = false;
282
- }
283
- _raiseOnAnimationEnd() {
284
- if (this.onAnimationEnd) {
285
- this.onAnimationEnd();
286
- }
287
- this.onAnimationEndObservable.notifyObservers(this);
288
- }
289
- /**
290
- * Stop and delete the current animation
291
- * @param animationName defines a string used to only stop some of the runtime animations instead of all
292
- * @param targetMask a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)
293
- * @param useGlobalSplice if true, the animatables will be removed by the caller of this function (false by default)
294
- * @param skipOnAnimationEnd defines if the system should not raise onAnimationEnd. Default is false
295
- */
296
- stop(animationName, targetMask, useGlobalSplice = false, skipOnAnimationEnd = false) {
297
- if (animationName || targetMask) {
298
- const idx = this._scene._activeAnimatables.indexOf(this);
299
- if (idx > -1) {
300
- const runtimeAnimations = this._runtimeAnimations;
301
- for (let index = runtimeAnimations.length - 1; index >= 0; index--) {
302
- const runtimeAnimation = runtimeAnimations[index];
303
- if (animationName && runtimeAnimation.animation.name != animationName) {
304
- continue;
305
- }
306
- if (targetMask && !targetMask(runtimeAnimation.target)) {
307
- continue;
308
- }
309
- runtimeAnimation.dispose();
310
- runtimeAnimations.splice(index, 1);
311
- }
312
- if (runtimeAnimations.length == 0) {
313
- if (!useGlobalSplice) {
314
- this._scene._activeAnimatables.splice(idx, 1);
315
- }
316
- if (!skipOnAnimationEnd) {
317
- this._raiseOnAnimationEnd();
318
- }
319
- }
320
- }
321
- }
322
- else {
323
- const index = this._scene._activeAnimatables.indexOf(this);
324
- if (index > -1) {
325
- if (!useGlobalSplice) {
326
- this._scene._activeAnimatables.splice(index, 1);
327
- }
328
- const runtimeAnimations = this._runtimeAnimations;
329
- for (let index = 0; index < runtimeAnimations.length; index++) {
330
- runtimeAnimations[index].dispose();
331
- }
332
- this._runtimeAnimations.length = 0;
333
- if (!skipOnAnimationEnd) {
334
- this._raiseOnAnimationEnd();
335
- }
336
- }
337
- }
338
- }
339
- /**
340
- * Wait asynchronously for the animation to end
341
- * @returns a promise which will be fulfilled when the animation ends
342
- */
343
- waitAsync() {
344
- return new Promise((resolve) => {
345
- this.onAnimationEndObservable.add(() => {
346
- resolve(this);
347
- }, undefined, undefined, this, true);
348
- });
349
- }
350
- /**
351
- * @internal
352
- */
353
- _animate(delay) {
354
- if (this._paused) {
355
- this.animationStarted = false;
356
- if (this._pausedDelay === null) {
357
- this._pausedDelay = delay;
358
- }
359
- return true;
360
- }
361
- if (this._localDelayOffset === null) {
362
- this._localDelayOffset = delay;
363
- this._pausedDelay = null;
364
- }
365
- else if (this._pausedDelay !== null) {
366
- this._localDelayOffset += delay - this._pausedDelay;
367
- this._pausedDelay = null;
368
- }
369
- if (this._manualJumpDelay !== null) {
370
- this._localDelayOffset += this._manualJumpDelay;
371
- this._manualJumpDelay = null;
372
- this._frameToSyncFromJump = null;
373
- }
374
- this._goToFrame = null;
375
- if (this._weight === 0) {
376
- // We consider that an animatable with a weight === 0 is "actively" paused
377
- return true;
378
- }
379
- // Animating
380
- let running = false;
381
- const runtimeAnimations = this._runtimeAnimations;
382
- let index;
383
- for (index = 0; index < runtimeAnimations.length; index++) {
384
- const animation = runtimeAnimations[index];
385
- const isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this._speedRatio, this._weight);
386
- running = running || isRunning;
387
- }
388
- this.animationStarted = running;
389
- if (!running) {
390
- if (this.disposeOnEnd) {
391
- // Remove from active animatables
392
- index = this._scene._activeAnimatables.indexOf(this);
393
- this._scene._activeAnimatables.splice(index, 1);
394
- // Dispose all runtime animations
395
- for (index = 0; index < runtimeAnimations.length; index++) {
396
- runtimeAnimations[index].dispose();
397
- }
398
- }
399
- this._raiseOnAnimationEnd();
400
- if (this.disposeOnEnd) {
401
- this.onAnimationEnd = null;
402
- this.onAnimationLoop = null;
403
- this.onAnimationLoopObservable.clear();
404
- this.onAnimationEndObservable.clear();
405
- }
406
- }
407
- return running;
408
- }
409
- }
410
- Scene.prototype._animate = function (customDeltaTime) {
411
- if (!this.animationsEnabled) {
412
- return;
413
- }
414
- // Getting time
415
- const now = PrecisionDate.Now;
416
- if (!this._animationTimeLast) {
417
- if (this._pendingData.length > 0) {
418
- return;
419
- }
420
- this._animationTimeLast = now;
421
- }
422
- this.deltaTime = customDeltaTime !== undefined ? customDeltaTime : this.useConstantAnimationDeltaTime ? 16.0 : (now - this._animationTimeLast) * this.animationTimeScale;
423
- this._animationTimeLast = now;
424
- const animatables = this._activeAnimatables;
425
- if (animatables.length === 0) {
426
- return;
427
- }
428
- this._animationTime += this.deltaTime;
429
- const animationTime = this._animationTime;
430
- for (let index = 0; index < animatables.length; index++) {
431
- const animatable = animatables[index];
432
- if (!animatable._animate(animationTime) && animatable.disposeOnEnd) {
433
- index--; // Array was updated
434
- }
435
- }
436
- // Late animation bindings
437
- this._processLateAnimationBindings();
438
- };
439
- Scene.prototype.sortActiveAnimatables = function () {
440
- this._activeAnimatables.sort((a, b) => {
441
- return a.playOrder - b.playOrder;
442
- });
443
- };
444
- Scene.prototype.beginWeightedAnimation = function (target, from, to, weight = 1.0, loop, speedRatio = 1.0, onAnimationEnd, animatable, targetMask, onAnimationLoop, isAdditive = false) {
445
- const returnedAnimatable = this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, false, targetMask, onAnimationLoop, isAdditive);
446
- returnedAnimatable.weight = weight;
447
- return returnedAnimatable;
448
- };
449
- Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio = 1.0, onAnimationEnd, animatable, stopCurrent = true, targetMask, onAnimationLoop, isAdditive = false) {
450
- // get speed speedRatio, to and from, based on the sign and value(s)
451
- if (speedRatio < 0) {
452
- const tmp = from;
453
- from = to;
454
- to = tmp;
455
- speedRatio = -speedRatio;
456
- }
457
- // if from > to switch speed ratio
458
- if (from > to) {
459
- speedRatio = -speedRatio;
460
- }
461
- if (stopCurrent) {
462
- this.stopAnimation(target, undefined, targetMask);
463
- }
464
- if (!animatable) {
465
- animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, undefined, onAnimationLoop, isAdditive);
466
- }
467
- const shouldRunTargetAnimations = targetMask ? targetMask(target) : true;
468
- // Local animations
469
- if (target.animations && shouldRunTargetAnimations) {
470
- animatable.appendAnimations(target, target.animations);
471
- }
472
- // Children animations
473
- if (target.getAnimatables) {
474
- const animatables = target.getAnimatables();
475
- for (let index = 0; index < animatables.length; index++) {
476
- this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, onAnimationLoop);
477
- }
478
- }
479
- animatable.reset();
480
- return animatable;
481
- };
482
- Scene.prototype.beginHierarchyAnimation = function (target, directDescendantsOnly, from, to, loop, speedRatio = 1.0, onAnimationEnd, animatable, stopCurrent = true, targetMask, onAnimationLoop, isAdditive = false) {
483
- const children = target.getDescendants(directDescendantsOnly);
484
- const result = [];
485
- result.push(this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, undefined, isAdditive));
486
- for (const child of children) {
487
- result.push(this.beginAnimation(child, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, undefined, isAdditive));
488
- }
489
- return result;
490
- };
491
- Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio = 1.0, onAnimationEnd, onAnimationLoop, isAdditive = false) {
492
- // get speed speedRatio, to and from, based on the sign and value(s)
493
- if (speedRatio < 0) {
494
- const tmp = from;
495
- from = to;
496
- to = tmp;
497
- speedRatio = -speedRatio;
498
- }
499
- // if from > to switch speed ratio
500
- if (from > to) {
501
- speedRatio = -speedRatio;
502
- }
503
- const animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations, onAnimationLoop, isAdditive);
504
- return animatable;
505
- };
506
- Scene.prototype.beginDirectHierarchyAnimation = function (target, directDescendantsOnly, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive = false) {
507
- const children = target.getDescendants(directDescendantsOnly);
508
- const result = [];
509
- result.push(this.beginDirectAnimation(target, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive));
510
- for (const child of children) {
511
- result.push(this.beginDirectAnimation(child, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive));
512
- }
513
- return result;
514
- };
515
- Scene.prototype.getAnimatableByTarget = function (target) {
516
- for (let index = 0; index < this._activeAnimatables.length; index++) {
517
- if (this._activeAnimatables[index].target === target) {
518
- return this._activeAnimatables[index];
519
- }
520
- }
521
- return null;
522
- };
523
- Scene.prototype.getAllAnimatablesByTarget = function (target) {
524
- const result = [];
525
- for (let index = 0; index < this._activeAnimatables.length; index++) {
526
- if (this._activeAnimatables[index].target === target) {
527
- result.push(this._activeAnimatables[index]);
528
- }
529
- }
530
- return result;
531
- };
532
- /**
533
- * Will stop the animation of the given target
534
- * @param target - the target
535
- * @param animationName - the name of the animation to stop (all animations will be stopped if both this and targetMask are empty)
536
- * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)
537
- */
538
- Scene.prototype.stopAnimation = function (target, animationName, targetMask) {
539
- const animatables = this.getAllAnimatablesByTarget(target);
540
- for (const animatable of animatables) {
541
- animatable.stop(animationName, targetMask);
542
- }
543
- };
544
- /**
545
- * Stops and removes all animations that have been applied to the scene
546
- */
547
- Scene.prototype.stopAllAnimations = function () {
548
- if (this._activeAnimatables) {
549
- for (let i = 0; i < this._activeAnimatables.length; i++) {
550
- this._activeAnimatables[i].stop(undefined, undefined, true);
551
- }
552
- this._activeAnimatables.length = 0;
553
- }
554
- for (const group of this.animationGroups) {
555
- group.stop();
556
- }
557
- };
558
- Scene.prototype._registerTargetForLateAnimationBinding = function (runtimeAnimation, originalValue) {
559
- const target = runtimeAnimation.target;
560
- this._registeredForLateAnimationBindings.pushNoDuplicate(target);
561
- if (!target._lateAnimationHolders) {
562
- target._lateAnimationHolders = {};
563
- }
564
- if (!target._lateAnimationHolders[runtimeAnimation.targetPath]) {
565
- target._lateAnimationHolders[runtimeAnimation.targetPath] = {
566
- totalWeight: 0,
567
- totalAdditiveWeight: 0,
568
- animations: [],
569
- additiveAnimations: [],
570
- originalValue: originalValue,
571
- };
572
- }
573
- if (runtimeAnimation.isAdditive) {
574
- target._lateAnimationHolders[runtimeAnimation.targetPath].additiveAnimations.push(runtimeAnimation);
575
- target._lateAnimationHolders[runtimeAnimation.targetPath].totalAdditiveWeight += runtimeAnimation.weight;
576
- }
577
- else {
578
- target._lateAnimationHolders[runtimeAnimation.targetPath].animations.push(runtimeAnimation);
579
- target._lateAnimationHolders[runtimeAnimation.targetPath].totalWeight += runtimeAnimation.weight;
580
- }
581
- };
582
- Scene.prototype._processLateAnimationBindingsForMatrices = function (holder) {
583
- if (holder.totalWeight === 0 && holder.totalAdditiveWeight === 0) {
584
- return holder.originalValue;
585
- }
586
- let normalizer = 1.0;
587
- const finalPosition = TmpVectors.Vector3[0];
588
- const finalScaling = TmpVectors.Vector3[1];
589
- const finalQuaternion = TmpVectors.Quaternion[0];
590
- let startIndex = 0;
591
- const originalAnimation = holder.animations[0];
592
- const originalValue = holder.originalValue;
593
- let scale = 1;
594
- let skipOverride = false;
595
- if (holder.totalWeight < 1.0) {
596
- // We need to mix the original value in
597
- scale = 1.0 - holder.totalWeight;
598
- originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
599
- }
600
- else {
601
- startIndex = 1;
602
- // We need to normalize the weights
603
- normalizer = holder.totalWeight;
604
- scale = originalAnimation.weight / normalizer;
605
- if (scale == 1) {
606
- if (holder.totalAdditiveWeight) {
607
- skipOverride = true;
608
- }
609
- else {
610
- return originalAnimation.currentValue;
611
- }
612
- }
613
- originalAnimation.currentValue.decompose(finalScaling, finalQuaternion, finalPosition);
614
- }
615
- // Add up the override animations
616
- if (!skipOverride) {
617
- finalScaling.scaleInPlace(scale);
618
- finalPosition.scaleInPlace(scale);
619
- finalQuaternion.scaleInPlace(scale);
620
- for (let animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {
621
- const runtimeAnimation = holder.animations[animIndex];
622
- if (runtimeAnimation.weight === 0) {
623
- continue;
624
- }
625
- scale = runtimeAnimation.weight / normalizer;
626
- const currentPosition = TmpVectors.Vector3[2];
627
- const currentScaling = TmpVectors.Vector3[3];
628
- const currentQuaternion = TmpVectors.Quaternion[1];
629
- runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);
630
- currentScaling.scaleAndAddToRef(scale, finalScaling);
631
- currentQuaternion.scaleAndAddToRef(Quaternion.Dot(finalQuaternion, currentQuaternion) > 0 ? scale : -scale, finalQuaternion);
632
- currentPosition.scaleAndAddToRef(scale, finalPosition);
633
- }
634
- finalQuaternion.normalize();
635
- }
636
- // Add up the additive animations
637
- for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {
638
- const runtimeAnimation = holder.additiveAnimations[animIndex];
639
- if (runtimeAnimation.weight === 0) {
640
- continue;
641
- }
642
- const currentPosition = TmpVectors.Vector3[2];
643
- const currentScaling = TmpVectors.Vector3[3];
644
- const currentQuaternion = TmpVectors.Quaternion[1];
645
- runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);
646
- currentScaling.multiplyToRef(finalScaling, currentScaling);
647
- Vector3.LerpToRef(finalScaling, currentScaling, runtimeAnimation.weight, finalScaling);
648
- finalQuaternion.multiplyToRef(currentQuaternion, currentQuaternion);
649
- Quaternion.SlerpToRef(finalQuaternion, currentQuaternion, runtimeAnimation.weight, finalQuaternion);
650
- currentPosition.scaleAndAddToRef(runtimeAnimation.weight, finalPosition);
651
- }
652
- const workValue = originalAnimation ? originalAnimation._animationState.workValue : TmpVectors.Matrix[0].clone();
653
- Matrix.ComposeToRef(finalScaling, finalQuaternion, finalPosition, workValue);
654
- return workValue;
655
- };
656
- Scene.prototype._processLateAnimationBindingsForQuaternions = function (holder, refQuaternion) {
657
- if (holder.totalWeight === 0 && holder.totalAdditiveWeight === 0) {
658
- return refQuaternion;
659
- }
660
- const originalAnimation = holder.animations[0];
661
- const originalValue = holder.originalValue;
662
- let cumulativeQuaternion = refQuaternion;
663
- if (holder.totalWeight === 0 && holder.totalAdditiveWeight > 0) {
664
- cumulativeQuaternion.copyFrom(originalValue);
665
- }
666
- else if (holder.animations.length === 1) {
667
- Quaternion.SlerpToRef(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight), cumulativeQuaternion);
668
- if (holder.totalAdditiveWeight === 0) {
669
- return cumulativeQuaternion;
670
- }
671
- }
672
- else if (holder.animations.length > 1) {
673
- // Add up the override animations
674
- let normalizer = 1.0;
675
- let quaternions;
676
- let weights;
677
- if (holder.totalWeight < 1.0) {
678
- const scale = 1.0 - holder.totalWeight;
679
- quaternions = [];
680
- weights = [];
681
- quaternions.push(originalValue);
682
- weights.push(scale);
683
- }
684
- else {
685
- if (holder.animations.length === 2) {
686
- // Slerp as soon as we can
687
- Quaternion.SlerpToRef(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight, refQuaternion);
688
- if (holder.totalAdditiveWeight === 0) {
689
- return refQuaternion;
690
- }
691
- }
692
- quaternions = [];
693
- weights = [];
694
- normalizer = holder.totalWeight;
695
- }
696
- for (let animIndex = 0; animIndex < holder.animations.length; animIndex++) {
697
- const runtimeAnimation = holder.animations[animIndex];
698
- quaternions.push(runtimeAnimation.currentValue);
699
- weights.push(runtimeAnimation.weight / normalizer);
700
- }
701
- // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
702
- let cumulativeAmount = 0;
703
- for (let index = 0; index < quaternions.length;) {
704
- if (!index) {
705
- Quaternion.SlerpToRef(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]), refQuaternion);
706
- cumulativeQuaternion = refQuaternion;
707
- cumulativeAmount = weights[index] + weights[index + 1];
708
- index += 2;
709
- continue;
710
- }
711
- cumulativeAmount += weights[index];
712
- Quaternion.SlerpToRef(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount, cumulativeQuaternion);
713
- index++;
714
- }
715
- }
716
- // Add up the additive animations
717
- for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {
718
- const runtimeAnimation = holder.additiveAnimations[animIndex];
719
- if (runtimeAnimation.weight === 0) {
720
- continue;
721
- }
722
- cumulativeQuaternion.multiplyToRef(runtimeAnimation.currentValue, TmpVectors.Quaternion[0]);
723
- Quaternion.SlerpToRef(cumulativeQuaternion, TmpVectors.Quaternion[0], runtimeAnimation.weight, cumulativeQuaternion);
724
- }
725
- return cumulativeQuaternion;
726
- };
727
- Scene.prototype._processLateAnimationBindings = function () {
728
- if (!this._registeredForLateAnimationBindings.length) {
729
- return;
730
- }
731
- for (let index = 0; index < this._registeredForLateAnimationBindings.length; index++) {
732
- const target = this._registeredForLateAnimationBindings.data[index];
733
- for (const path in target._lateAnimationHolders) {
734
- const holder = target._lateAnimationHolders[path];
735
- const originalAnimation = holder.animations[0];
736
- const originalValue = holder.originalValue;
737
- if (originalValue === undefined || originalValue === null) {
738
- continue;
739
- }
740
- const matrixDecomposeMode = Animation.AllowMatrixDecomposeForInterpolation && originalValue.m; // ie. data is matrix
741
- let finalValue = target[path];
742
- if (matrixDecomposeMode) {
743
- finalValue = this._processLateAnimationBindingsForMatrices(holder);
744
- }
745
- else {
746
- const quaternionMode = originalValue.w !== undefined;
747
- if (quaternionMode) {
748
- finalValue = this._processLateAnimationBindingsForQuaternions(holder, finalValue || Quaternion.Identity());
749
- }
750
- else {
751
- let startIndex = 0;
752
- let normalizer = 1.0;
753
- const originalAnimationIsLoopRelativeFromCurrent = originalAnimation && originalAnimation._animationState.loopMode === Animation.ANIMATIONLOOPMODE_RELATIVE_FROM_CURRENT;
754
- if (holder.totalWeight < 1.0) {
755
- // We need to mix the original value in
756
- if (originalAnimationIsLoopRelativeFromCurrent) {
757
- finalValue = originalValue.clone ? originalValue.clone() : originalValue;
758
- }
759
- else if (originalAnimation && originalValue.scale) {
760
- finalValue = originalValue.scale(1.0 - holder.totalWeight);
761
- }
762
- else if (originalAnimation) {
763
- finalValue = originalValue * (1.0 - holder.totalWeight);
764
- }
765
- else if (originalValue.clone) {
766
- finalValue = originalValue.clone();
767
- }
768
- else {
769
- finalValue = originalValue;
770
- }
771
- }
772
- else if (originalAnimation) {
773
- // We need to normalize the weights
774
- normalizer = holder.totalWeight;
775
- const scale = originalAnimation.weight / normalizer;
776
- if (scale !== 1) {
777
- if (originalAnimation.currentValue.scale) {
778
- finalValue = originalAnimation.currentValue.scale(scale);
779
- }
780
- else {
781
- finalValue = originalAnimation.currentValue * scale;
782
- }
783
- }
784
- else {
785
- finalValue = originalAnimation.currentValue;
786
- }
787
- if (originalAnimationIsLoopRelativeFromCurrent) {
788
- if (finalValue.addToRef) {
789
- finalValue.addToRef(originalValue, finalValue);
790
- }
791
- else {
792
- finalValue += originalValue;
793
- }
794
- }
795
- startIndex = 1;
796
- }
797
- // Add up the override animations
798
- for (let animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {
799
- const runtimeAnimation = holder.animations[animIndex];
800
- const scale = runtimeAnimation.weight / normalizer;
801
- if (!scale) {
802
- continue;
803
- }
804
- else if (runtimeAnimation.currentValue.scaleAndAddToRef) {
805
- runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);
806
- }
807
- else {
808
- finalValue += runtimeAnimation.currentValue * scale;
809
- }
810
- }
811
- // Add up the additive animations
812
- for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {
813
- const runtimeAnimation = holder.additiveAnimations[animIndex];
814
- const scale = runtimeAnimation.weight;
815
- if (!scale) {
816
- continue;
817
- }
818
- else if (runtimeAnimation.currentValue.scaleAndAddToRef) {
819
- runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);
820
- }
821
- else {
822
- finalValue += runtimeAnimation.currentValue * scale;
823
- }
824
- }
825
- }
826
- }
827
- target[path] = finalValue;
828
- }
829
- target._lateAnimationHolders = {};
830
- }
831
- this._registeredForLateAnimationBindings.reset();
832
- };
833
- Bone.prototype.copyAnimationRange = function (source, rangeName, frameOffset, rescaleAsRequired = false, skelDimensionsRatio = null) {
834
- // all animation may be coming from a library skeleton, so may need to create animation
835
- if (this.animations.length === 0) {
836
- this.animations.push(new Animation(this.name, "_matrix", source.animations[0].framePerSecond, Animation.ANIMATIONTYPE_MATRIX, 0));
837
- this.animations[0].setKeys([]);
838
- }
839
- // get animation info / verify there is such a range from the source bone
840
- const sourceRange = source.animations[0].getRange(rangeName);
841
- if (!sourceRange) {
842
- return false;
843
- }
844
- const from = sourceRange.from;
845
- const to = sourceRange.to;
846
- const sourceKeys = source.animations[0].getKeys();
847
- // rescaling prep
848
- const sourceBoneLength = source.length;
849
- const sourceParent = source.getParent();
850
- const parent = this.getParent();
851
- const parentScalingReqd = rescaleAsRequired && sourceParent && sourceBoneLength && this.length && sourceBoneLength !== this.length;
852
- const parentRatio = parentScalingReqd && parent && sourceParent ? parent.length / sourceParent.length : 1;
853
- const dimensionsScalingReqd = rescaleAsRequired && !parent && skelDimensionsRatio && (skelDimensionsRatio.x !== 1 || skelDimensionsRatio.y !== 1 || skelDimensionsRatio.z !== 1);
854
- const destKeys = this.animations[0].getKeys();
855
- // loop vars declaration
856
- let orig;
857
- let origTranslation;
858
- let mat;
859
- for (let key = 0, nKeys = sourceKeys.length; key < nKeys; key++) {
860
- orig = sourceKeys[key];
861
- if (orig.frame >= from && orig.frame <= to) {
862
- if (rescaleAsRequired) {
863
- mat = orig.value.clone();
864
- // scale based on parent ratio, when bone has parent
865
- if (parentScalingReqd) {
866
- origTranslation = mat.getTranslation();
867
- mat.setTranslation(origTranslation.scaleInPlace(parentRatio));
868
- // scale based on skeleton dimension ratio when root bone, and value is passed
869
- }
870
- else if (dimensionsScalingReqd && skelDimensionsRatio) {
871
- origTranslation = mat.getTranslation();
872
- mat.setTranslation(origTranslation.multiplyInPlace(skelDimensionsRatio));
873
- // use original when root bone, and no data for skelDimensionsRatio
874
- }
875
- else {
876
- mat = orig.value;
877
- }
878
- }
879
- else {
880
- mat = orig.value;
881
- }
882
- destKeys.push({ frame: orig.frame + frameOffset, value: mat });
883
- }
884
- }
885
- this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
886
- return true;
887
- };
2
+ import { AddAnimationExtensions } from "./animatable.core.js";
3
+ import { Scene } from "../scene.js";
4
+ export * from "./animatable.core.js";
5
+ // Connect everything!
6
+ AddAnimationExtensions(Scene, Bone);
888
7
  //# sourceMappingURL=animatable.js.map