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