@spiffcommerce/preview 3.6.2-rc.8 → 4.0.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.
Files changed (45) hide show
  1. package/dist/index.esm.js +1576 -38
  2. package/dist/index.umd.js +1 -0
  3. package/package.json +4 -6
  4. package/dist/_tslib.esm.js +0 -33
  5. package/dist/animation.esm.js +0 -1364
  6. package/dist/assetCache.esm.js +0 -6
  7. package/dist/assetCache.esm2.js +0 -825
  8. package/dist/blurPostProcess.esm.js +0 -327
  9. package/dist/bumpVertex.esm.js +0 -497
  10. package/dist/compatibilityOptions.esm.js +0 -68
  11. package/dist/configuration.esm.js +0 -121
  12. package/dist/core.esm.js +0 -8135
  13. package/dist/dynamicTexture.esm.js +0 -105
  14. package/dist/dynamicTexture.esm2.js +0 -238
  15. package/dist/easing.esm.js +0 -130
  16. package/dist/effectFallbacks.esm.js +0 -378
  17. package/dist/engine.esm.js +0 -25504
  18. package/dist/glbLoaderExtensions.esm.js +0 -690
  19. package/dist/glowLayer.esm.js +0 -1621
  20. package/dist/glowLayerManager.esm.js +0 -50
  21. package/dist/guid.esm.js +0 -21
  22. package/dist/hdrFilteringFunctions.esm.js +0 -816
  23. package/dist/helperFunctions.esm.js +0 -5145
  24. package/dist/material.esm.js +0 -115
  25. package/dist/material.esm2.js +0 -5245
  26. package/dist/math.axis.esm.js +0 -35
  27. package/dist/math.color.esm.js +0 -1661
  28. package/dist/math.path.esm.js +0 -15
  29. package/dist/math.size.esm.js +0 -137
  30. package/dist/mesh.esm.js +0 -11170
  31. package/dist/modelContainer.esm.js +0 -1895
  32. package/dist/node.esm.js +0 -795
  33. package/dist/pbrBRDFFunctions.esm.js +0 -124
  34. package/dist/pbrMaterial.esm.js +8 -8739
  35. package/dist/productAnimations.esm.js +0 -182
  36. package/dist/productCamera.esm.js +0 -14
  37. package/dist/productCamera.esm2.js +0 -3870
  38. package/dist/renderConstants.esm.js +0 -116
  39. package/dist/renderingPipeline.esm.js +0 -18
  40. package/dist/renderingPipeline.esm2.js +1 -3594
  41. package/dist/sceneLoaderFlags.esm.js +0 -51
  42. package/dist/types.esm.js +0 -30
  43. package/dist/variants.esm.js +0 -16
  44. package/dist/variants.esm2.js +0 -3097
  45. package/dist/webRequest.esm.js +0 -7777
@@ -1,1364 +0,0 @@
1
- import { Q as Quaternion, V as Vector3, b as Vector2, T as TmpVectors, M as Matrix, S as SerializationHelper, W as WebRequest } from './webRequest.esm.js';
2
- import { a as Color3, C as Color4, S as Scalar, R as RegisterClass } from './math.color.esm.js';
3
- import { N as Node } from './node.esm.js';
4
- import { S as Size } from './math.size.esm.js';
5
-
6
- /**
7
- * Enum for the animation key frame interpolation type
8
- */
9
- var AnimationKeyInterpolation;
10
- (function (AnimationKeyInterpolation) {
11
- /**
12
- * Use tangents to interpolate between start and end values.
13
- */
14
- AnimationKeyInterpolation[AnimationKeyInterpolation["NONE"] = 0] = "NONE";
15
- /**
16
- * Do not interpolate between keys and use the start key value only. Tangents are ignored
17
- */
18
- AnimationKeyInterpolation[AnimationKeyInterpolation["STEP"] = 1] = "STEP";
19
- })(AnimationKeyInterpolation || (AnimationKeyInterpolation = {}));
20
-
21
- /**
22
- * Represents the range of an animation
23
- */
24
- class AnimationRange {
25
- /**
26
- * Initializes the range of an animation
27
- * @param name The name of the animation range
28
- * @param from The starting frame of the animation
29
- * @param to The ending frame of the animation
30
- */
31
- constructor(
32
- /**The name of the animation range**/
33
- name,
34
- /**The starting frame of the animation */
35
- from,
36
- /**The ending frame of the animation*/
37
- to) {
38
- this.name = name;
39
- this.from = from;
40
- this.to = to;
41
- }
42
- /**
43
- * Makes a copy of the animation range
44
- * @returns A copy of the animation range
45
- */
46
- clone() {
47
- return new AnimationRange(this.name, this.from, this.to);
48
- }
49
- }
50
-
51
- /**
52
- * Class used to store any kind of animation
53
- */
54
- class Animation {
55
- /**
56
- * @internal Internal use
57
- */
58
- static _PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction) {
59
- let dataType = undefined;
60
- if (!isNaN(parseFloat(from)) && isFinite(from)) {
61
- dataType = Animation.ANIMATIONTYPE_FLOAT;
62
- }
63
- else if (from instanceof Quaternion) {
64
- dataType = Animation.ANIMATIONTYPE_QUATERNION;
65
- }
66
- else if (from instanceof Vector3) {
67
- dataType = Animation.ANIMATIONTYPE_VECTOR3;
68
- }
69
- else if (from instanceof Vector2) {
70
- dataType = Animation.ANIMATIONTYPE_VECTOR2;
71
- }
72
- else if (from instanceof Color3) {
73
- dataType = Animation.ANIMATIONTYPE_COLOR3;
74
- }
75
- else if (from instanceof Color4) {
76
- dataType = Animation.ANIMATIONTYPE_COLOR4;
77
- }
78
- else if (from instanceof Size) {
79
- dataType = Animation.ANIMATIONTYPE_SIZE;
80
- }
81
- if (dataType == undefined) {
82
- return null;
83
- }
84
- const animation = new Animation(name, targetProperty, framePerSecond, dataType, loopMode);
85
- const keys = [
86
- { frame: 0, value: from },
87
- { frame: totalFrame, value: to },
88
- ];
89
- animation.setKeys(keys);
90
- if (easingFunction !== undefined) {
91
- animation.setEasingFunction(easingFunction);
92
- }
93
- return animation;
94
- }
95
- /**
96
- * Sets up an animation
97
- * @param property The property to animate
98
- * @param animationType The animation type to apply
99
- * @param framePerSecond The frames per second of the animation
100
- * @param easingFunction The easing function used in the animation
101
- * @returns The created animation
102
- */
103
- static CreateAnimation(property, animationType, framePerSecond, easingFunction) {
104
- const animation = new Animation(property + "Animation", property, framePerSecond, animationType, Animation.ANIMATIONLOOPMODE_CONSTANT);
105
- animation.setEasingFunction(easingFunction);
106
- return animation;
107
- }
108
- /**
109
- * Create and start an animation on a node
110
- * @param name defines the name of the global animation that will be run on all nodes
111
- * @param target defines the target where the animation will take place
112
- * @param targetProperty defines property to animate
113
- * @param framePerSecond defines the number of frame per second yo use
114
- * @param totalFrame defines the number of frames in total
115
- * @param from defines the initial value
116
- * @param to defines the final value
117
- * @param loopMode defines which loop mode you want to use (off by default)
118
- * @param easingFunction defines the easing function to use (linear by default)
119
- * @param onAnimationEnd defines the callback to call when animation end
120
- * @param scene defines the hosting scene
121
- * @returns the animatable created for this animation
122
- */
123
- static CreateAndStartAnimation(name, target, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd, scene) {
124
- const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);
125
- if (!animation) {
126
- return null;
127
- }
128
- if (target.getScene) {
129
- scene = target.getScene();
130
- }
131
- if (!scene) {
132
- return null;
133
- }
134
- return scene.beginDirectAnimation(target, [animation], 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);
135
- }
136
- /**
137
- * Create and start an animation on a node and its descendants
138
- * @param name defines the name of the global animation that will be run on all nodes
139
- * @param node defines the root node where the animation will take place
140
- * @param directDescendantsOnly if true only direct descendants will be used, if false direct and also indirect (children of children, an so on in a recursive manner) descendants will be used
141
- * @param targetProperty defines property to animate
142
- * @param framePerSecond defines the number of frame per second to use
143
- * @param totalFrame defines the number of frames in total
144
- * @param from defines the initial value
145
- * @param to defines the final value
146
- * @param loopMode defines which loop mode you want to use (off by default)
147
- * @param easingFunction defines the easing function to use (linear by default)
148
- * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)
149
- * @returns the list of animatables created for all nodes
150
- * @example https://www.babylonjs-playground.com/#MH0VLI
151
- */
152
- static CreateAndStartHierarchyAnimation(name, node, directDescendantsOnly, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd) {
153
- const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);
154
- if (!animation) {
155
- return null;
156
- }
157
- const scene = node.getScene();
158
- return scene.beginDirectHierarchyAnimation(node, directDescendantsOnly, [animation], 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);
159
- }
160
- /**
161
- * Creates a new animation, merges it with the existing animations and starts it
162
- * @param name Name of the animation
163
- * @param node Node which contains the scene that begins the animations
164
- * @param targetProperty Specifies which property to animate
165
- * @param framePerSecond The frames per second of the animation
166
- * @param totalFrame The total number of frames
167
- * @param from The frame at the beginning of the animation
168
- * @param to The frame at the end of the animation
169
- * @param loopMode Specifies the loop mode of the animation
170
- * @param easingFunction (Optional) The easing function of the animation, which allow custom mathematical formulas for animations
171
- * @param onAnimationEnd Callback to run once the animation is complete
172
- * @returns Nullable animation
173
- */
174
- static CreateMergeAndStartAnimation(name, node, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd) {
175
- const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);
176
- if (!animation) {
177
- return null;
178
- }
179
- node.animations.push(animation);
180
- return node.getScene().beginAnimation(node, 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);
181
- }
182
- /**
183
- * Convert the keyframes for all animations belonging to the group to be relative to a given reference frame.
184
- * @param sourceAnimation defines the Animation containing keyframes to convert
185
- * @param referenceFrame defines the frame that keyframes in the range will be relative to
186
- * @param range defines the name of the AnimationRange belonging to the Animation to convert
187
- * @param cloneOriginal defines whether or not to clone the animation and convert the clone or convert the original animation (default is false)
188
- * @param clonedName defines the name of the resulting cloned Animation if cloneOriginal is true
189
- * @returns a new Animation if cloneOriginal is true or the original Animation if cloneOriginal is false
190
- */
191
- static MakeAnimationAdditive(sourceAnimation, referenceFrame = 0, range, cloneOriginal = false, clonedName) {
192
- let animation = sourceAnimation;
193
- if (cloneOriginal) {
194
- animation = sourceAnimation.clone();
195
- animation.name = clonedName || animation.name;
196
- }
197
- if (!animation._keys.length) {
198
- return animation;
199
- }
200
- referenceFrame = referenceFrame >= 0 ? referenceFrame : 0;
201
- let startIndex = 0;
202
- const firstKey = animation._keys[0];
203
- let endIndex = animation._keys.length - 1;
204
- const lastKey = animation._keys[endIndex];
205
- const valueStore = {
206
- referenceValue: firstKey.value,
207
- referencePosition: TmpVectors.Vector3[0],
208
- referenceQuaternion: TmpVectors.Quaternion[0],
209
- referenceScaling: TmpVectors.Vector3[1],
210
- keyPosition: TmpVectors.Vector3[2],
211
- keyQuaternion: TmpVectors.Quaternion[1],
212
- keyScaling: TmpVectors.Vector3[3],
213
- };
214
- let referenceFound = false;
215
- let from = firstKey.frame;
216
- let to = lastKey.frame;
217
- if (range) {
218
- const rangeValue = animation.getRange(range);
219
- if (rangeValue) {
220
- from = rangeValue.from;
221
- to = rangeValue.to;
222
- }
223
- }
224
- let fromKeyFound = firstKey.frame === from;
225
- let toKeyFound = lastKey.frame === to;
226
- // There's only one key, so use it
227
- if (animation._keys.length === 1) {
228
- const value = animation._getKeyValue(animation._keys[0]);
229
- valueStore.referenceValue = value.clone ? value.clone() : value;
230
- referenceFound = true;
231
- }
232
- // Reference frame is before the first frame, so just use the first frame
233
- else if (referenceFrame <= firstKey.frame) {
234
- const value = animation._getKeyValue(firstKey.value);
235
- valueStore.referenceValue = value.clone ? value.clone() : value;
236
- referenceFound = true;
237
- }
238
- // Reference frame is after the last frame, so just use the last frame
239
- else if (referenceFrame >= lastKey.frame) {
240
- const value = animation._getKeyValue(lastKey.value);
241
- valueStore.referenceValue = value.clone ? value.clone() : value;
242
- referenceFound = true;
243
- }
244
- // Find key bookends, create them if they don't exist
245
- let index = 0;
246
- while (!referenceFound || !fromKeyFound || (!toKeyFound && index < animation._keys.length - 1)) {
247
- const currentKey = animation._keys[index];
248
- const nextKey = animation._keys[index + 1];
249
- // If reference frame wasn't found yet, check if we can interpolate to it
250
- if (!referenceFound && referenceFrame >= currentKey.frame && referenceFrame <= nextKey.frame) {
251
- let value;
252
- if (referenceFrame === currentKey.frame) {
253
- value = animation._getKeyValue(currentKey.value);
254
- }
255
- else if (referenceFrame === nextKey.frame) {
256
- value = animation._getKeyValue(nextKey.value);
257
- }
258
- else {
259
- const animationState = {
260
- key: index,
261
- repeatCount: 0,
262
- loopMode: this.ANIMATIONLOOPMODE_CONSTANT,
263
- };
264
- value = animation._interpolate(referenceFrame, animationState);
265
- }
266
- valueStore.referenceValue = value.clone ? value.clone() : value;
267
- referenceFound = true;
268
- }
269
- // If from key wasn't found yet, check if we can interpolate to it
270
- if (!fromKeyFound && from >= currentKey.frame && from <= nextKey.frame) {
271
- if (from === currentKey.frame) {
272
- startIndex = index;
273
- }
274
- else if (from === nextKey.frame) {
275
- startIndex = index + 1;
276
- }
277
- else {
278
- const animationState = {
279
- key: index,
280
- repeatCount: 0,
281
- loopMode: this.ANIMATIONLOOPMODE_CONSTANT,
282
- };
283
- const value = animation._interpolate(from, animationState);
284
- const key = {
285
- frame: from,
286
- value: value.clone ? value.clone() : value,
287
- };
288
- animation._keys.splice(index + 1, 0, key);
289
- startIndex = index + 1;
290
- }
291
- fromKeyFound = true;
292
- }
293
- // If to key wasn't found yet, check if we can interpolate to it
294
- if (!toKeyFound && to >= currentKey.frame && to <= nextKey.frame) {
295
- if (to === currentKey.frame) {
296
- endIndex = index;
297
- }
298
- else if (to === nextKey.frame) {
299
- endIndex = index + 1;
300
- }
301
- else {
302
- const animationState = {
303
- key: index,
304
- repeatCount: 0,
305
- loopMode: this.ANIMATIONLOOPMODE_CONSTANT,
306
- };
307
- const value = animation._interpolate(to, animationState);
308
- const key = {
309
- frame: to,
310
- value: value.clone ? value.clone() : value,
311
- };
312
- animation._keys.splice(index + 1, 0, key);
313
- endIndex = index + 1;
314
- }
315
- toKeyFound = true;
316
- }
317
- index++;
318
- }
319
- // Conjugate the quaternion
320
- if (animation.dataType === Animation.ANIMATIONTYPE_QUATERNION) {
321
- valueStore.referenceValue.normalize().conjugateInPlace();
322
- }
323
- // Decompose matrix and conjugate the quaternion
324
- else if (animation.dataType === Animation.ANIMATIONTYPE_MATRIX) {
325
- valueStore.referenceValue.decompose(valueStore.referenceScaling, valueStore.referenceQuaternion, valueStore.referencePosition);
326
- valueStore.referenceQuaternion.normalize().conjugateInPlace();
327
- }
328
- // Subtract the reference value from all of the key values
329
- for (index = startIndex; index <= endIndex; index++) {
330
- const key = animation._keys[index];
331
- // If this key was duplicated to create a frame 0 key, skip it because its value has already been updated
332
- if (index && animation.dataType !== Animation.ANIMATIONTYPE_FLOAT && key.value === firstKey.value) {
333
- continue;
334
- }
335
- switch (animation.dataType) {
336
- case Animation.ANIMATIONTYPE_MATRIX:
337
- key.value.decompose(valueStore.keyScaling, valueStore.keyQuaternion, valueStore.keyPosition);
338
- valueStore.keyPosition.subtractInPlace(valueStore.referencePosition);
339
- valueStore.keyScaling.divideInPlace(valueStore.referenceScaling);
340
- valueStore.referenceQuaternion.multiplyToRef(valueStore.keyQuaternion, valueStore.keyQuaternion);
341
- Matrix.ComposeToRef(valueStore.keyScaling, valueStore.keyQuaternion, valueStore.keyPosition, key.value);
342
- break;
343
- case Animation.ANIMATIONTYPE_QUATERNION:
344
- valueStore.referenceValue.multiplyToRef(key.value, key.value);
345
- break;
346
- case Animation.ANIMATIONTYPE_VECTOR2:
347
- case Animation.ANIMATIONTYPE_VECTOR3:
348
- case Animation.ANIMATIONTYPE_COLOR3:
349
- case Animation.ANIMATIONTYPE_COLOR4:
350
- key.value.subtractToRef(valueStore.referenceValue, key.value);
351
- break;
352
- case Animation.ANIMATIONTYPE_SIZE:
353
- key.value.width -= valueStore.referenceValue.width;
354
- key.value.height -= valueStore.referenceValue.height;
355
- break;
356
- default:
357
- key.value -= valueStore.referenceValue;
358
- }
359
- }
360
- return animation;
361
- }
362
- /**
363
- * Transition property of an host to the target Value
364
- * @param property The property to transition
365
- * @param targetValue The target Value of the property
366
- * @param host The object where the property to animate belongs
367
- * @param scene Scene used to run the animation
368
- * @param frameRate Framerate (in frame/s) to use
369
- * @param transition The transition type we want to use
370
- * @param duration The duration of the animation, in milliseconds
371
- * @param onAnimationEnd Callback trigger at the end of the animation
372
- * @returns Nullable animation
373
- */
374
- static TransitionTo(property, targetValue, host, scene, frameRate, transition, duration, onAnimationEnd = null) {
375
- if (duration <= 0) {
376
- host[property] = targetValue;
377
- if (onAnimationEnd) {
378
- onAnimationEnd();
379
- }
380
- return null;
381
- }
382
- const endFrame = frameRate * (duration / 1000);
383
- transition.setKeys([
384
- {
385
- frame: 0,
386
- value: host[property].clone ? host[property].clone() : host[property],
387
- },
388
- {
389
- frame: endFrame,
390
- value: targetValue,
391
- },
392
- ]);
393
- if (!host.animations) {
394
- host.animations = [];
395
- }
396
- host.animations.push(transition);
397
- const animation = scene.beginAnimation(host, 0, endFrame, false);
398
- animation.onAnimationEnd = onAnimationEnd;
399
- return animation;
400
- }
401
- /**
402
- * Return the array of runtime animations currently using this animation
403
- */
404
- get runtimeAnimations() {
405
- return this._runtimeAnimations;
406
- }
407
- /**
408
- * Specifies if any of the runtime animations are currently running
409
- */
410
- get hasRunningRuntimeAnimations() {
411
- for (const runtimeAnimation of this._runtimeAnimations) {
412
- if (!runtimeAnimation.isStopped()) {
413
- return true;
414
- }
415
- }
416
- return false;
417
- }
418
- /**
419
- * Initializes the animation
420
- * @param name Name of the animation
421
- * @param targetProperty Property to animate
422
- * @param framePerSecond The frames per second of the animation
423
- * @param dataType The data type of the animation
424
- * @param loopMode The loop mode of the animation
425
- * @param enableBlending Specifies if blending should be enabled
426
- */
427
- constructor(
428
- /**Name of the animation */
429
- name,
430
- /**Property to animate */
431
- targetProperty,
432
- /**The frames per second of the animation */
433
- framePerSecond,
434
- /**The data type of the animation */
435
- dataType,
436
- /**The loop mode of the animation */
437
- loopMode,
438
- /**Specifies if blending should be enabled */
439
- enableBlending) {
440
- this.name = name;
441
- this.targetProperty = targetProperty;
442
- this.framePerSecond = framePerSecond;
443
- this.dataType = dataType;
444
- this.loopMode = loopMode;
445
- this.enableBlending = enableBlending;
446
- /**
447
- * Stores the easing function of the animation
448
- */
449
- this._easingFunction = null;
450
- /**
451
- * @internal Internal use only
452
- */
453
- this._runtimeAnimations = new Array();
454
- /**
455
- * The set of event that will be linked to this animation
456
- */
457
- this._events = new Array();
458
- /**
459
- * Stores the blending speed of the animation
460
- */
461
- this.blendingSpeed = 0.01;
462
- /**
463
- * Stores the animation ranges for the animation
464
- */
465
- this._ranges = {};
466
- this.targetPropertyPath = targetProperty.split(".");
467
- this.dataType = dataType;
468
- this.loopMode = loopMode === undefined ? Animation.ANIMATIONLOOPMODE_CYCLE : loopMode;
469
- this.uniqueId = Animation._UniqueIdGenerator++;
470
- }
471
- // Methods
472
- /**
473
- * Converts the animation to a string
474
- * @param fullDetails support for multiple levels of logging within scene loading
475
- * @returns String form of the animation
476
- */
477
- toString(fullDetails) {
478
- let ret = "Name: " + this.name + ", property: " + this.targetProperty;
479
- ret += ", datatype: " + ["Float", "Vector3", "Quaternion", "Matrix", "Color3", "Vector2"][this.dataType];
480
- ret += ", nKeys: " + (this._keys ? this._keys.length : "none");
481
- ret += ", nRanges: " + (this._ranges ? Object.keys(this._ranges).length : "none");
482
- if (fullDetails) {
483
- ret += ", Ranges: {";
484
- let first = true;
485
- for (const name in this._ranges) {
486
- if (first) {
487
- ret += ", ";
488
- first = false;
489
- }
490
- ret += name;
491
- }
492
- ret += "}";
493
- }
494
- return ret;
495
- }
496
- /**
497
- * Add an event to this animation
498
- * @param event Event to add
499
- */
500
- addEvent(event) {
501
- this._events.push(event);
502
- this._events.sort((a, b) => a.frame - b.frame);
503
- }
504
- /**
505
- * Remove all events found at the given frame
506
- * @param frame The frame to remove events from
507
- */
508
- removeEvents(frame) {
509
- for (let index = 0; index < this._events.length; index++) {
510
- if (this._events[index].frame === frame) {
511
- this._events.splice(index, 1);
512
- index--;
513
- }
514
- }
515
- }
516
- /**
517
- * Retrieves all the events from the animation
518
- * @returns Events from the animation
519
- */
520
- getEvents() {
521
- return this._events;
522
- }
523
- /**
524
- * Creates an animation range
525
- * @param name Name of the animation range
526
- * @param from Starting frame of the animation range
527
- * @param to Ending frame of the animation
528
- */
529
- createRange(name, from, to) {
530
- // check name not already in use; could happen for bones after serialized
531
- if (!this._ranges[name]) {
532
- this._ranges[name] = new AnimationRange(name, from, to);
533
- }
534
- }
535
- /**
536
- * Deletes an animation range by name
537
- * @param name Name of the animation range to delete
538
- * @param deleteFrames Specifies if the key frames for the range should also be deleted (true) or not (false)
539
- */
540
- deleteRange(name, deleteFrames = true) {
541
- const range = this._ranges[name];
542
- if (!range) {
543
- return;
544
- }
545
- if (deleteFrames) {
546
- const from = range.from;
547
- const to = range.to;
548
- // this loop MUST go high to low for multiple splices to work
549
- for (let key = this._keys.length - 1; key >= 0; key--) {
550
- if (this._keys[key].frame >= from && this._keys[key].frame <= to) {
551
- this._keys.splice(key, 1);
552
- }
553
- }
554
- }
555
- this._ranges[name] = null; // said much faster than 'delete this._range[name]'
556
- }
557
- /**
558
- * Gets the animation range by name, or null if not defined
559
- * @param name Name of the animation range
560
- * @returns Nullable animation range
561
- */
562
- getRange(name) {
563
- return this._ranges[name];
564
- }
565
- /**
566
- * Gets the key frames from the animation
567
- * @returns The key frames of the animation
568
- */
569
- getKeys() {
570
- return this._keys;
571
- }
572
- /**
573
- * Gets the highest frame rate of the animation
574
- * @returns Highest frame rate of the animation
575
- */
576
- getHighestFrame() {
577
- let ret = 0;
578
- for (let key = 0, nKeys = this._keys.length; key < nKeys; key++) {
579
- if (ret < this._keys[key].frame) {
580
- ret = this._keys[key].frame;
581
- }
582
- }
583
- return ret;
584
- }
585
- /**
586
- * Gets the easing function of the animation
587
- * @returns Easing function of the animation
588
- */
589
- getEasingFunction() {
590
- return this._easingFunction;
591
- }
592
- /**
593
- * Sets the easing function of the animation
594
- * @param easingFunction A custom mathematical formula for animation
595
- */
596
- setEasingFunction(easingFunction) {
597
- this._easingFunction = easingFunction;
598
- }
599
- /**
600
- * Interpolates a scalar linearly
601
- * @param startValue Start value of the animation curve
602
- * @param endValue End value of the animation curve
603
- * @param gradient Scalar amount to interpolate
604
- * @returns Interpolated scalar value
605
- */
606
- floatInterpolateFunction(startValue, endValue, gradient) {
607
- return Scalar.Lerp(startValue, endValue, gradient);
608
- }
609
- /**
610
- * Interpolates a scalar cubically
611
- * @param startValue Start value of the animation curve
612
- * @param outTangent End tangent of the animation
613
- * @param endValue End value of the animation curve
614
- * @param inTangent Start tangent of the animation curve
615
- * @param gradient Scalar amount to interpolate
616
- * @returns Interpolated scalar value
617
- */
618
- floatInterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {
619
- return Scalar.Hermite(startValue, outTangent, endValue, inTangent, gradient);
620
- }
621
- /**
622
- * Interpolates a quaternion using a spherical linear interpolation
623
- * @param startValue Start value of the animation curve
624
- * @param endValue End value of the animation curve
625
- * @param gradient Scalar amount to interpolate
626
- * @returns Interpolated quaternion value
627
- */
628
- quaternionInterpolateFunction(startValue, endValue, gradient) {
629
- return Quaternion.Slerp(startValue, endValue, gradient);
630
- }
631
- /**
632
- * Interpolates a quaternion cubically
633
- * @param startValue Start value of the animation curve
634
- * @param outTangent End tangent of the animation curve
635
- * @param endValue End value of the animation curve
636
- * @param inTangent Start tangent of the animation curve
637
- * @param gradient Scalar amount to interpolate
638
- * @returns Interpolated quaternion value
639
- */
640
- quaternionInterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {
641
- return Quaternion.Hermite(startValue, outTangent, endValue, inTangent, gradient).normalize();
642
- }
643
- /**
644
- * Interpolates a Vector3 linearly
645
- * @param startValue Start value of the animation curve
646
- * @param endValue End value of the animation curve
647
- * @param gradient Scalar amount to interpolate (value between 0 and 1)
648
- * @returns Interpolated scalar value
649
- */
650
- vector3InterpolateFunction(startValue, endValue, gradient) {
651
- return Vector3.Lerp(startValue, endValue, gradient);
652
- }
653
- /**
654
- * Interpolates a Vector3 cubically
655
- * @param startValue Start value of the animation curve
656
- * @param outTangent End tangent of the animation
657
- * @param endValue End value of the animation curve
658
- * @param inTangent Start tangent of the animation curve
659
- * @param gradient Scalar amount to interpolate (value between 0 and 1)
660
- * @returns InterpolatedVector3 value
661
- */
662
- vector3InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {
663
- return Vector3.Hermite(startValue, outTangent, endValue, inTangent, gradient);
664
- }
665
- /**
666
- * Interpolates a Vector2 linearly
667
- * @param startValue Start value of the animation curve
668
- * @param endValue End value of the animation curve
669
- * @param gradient Scalar amount to interpolate (value between 0 and 1)
670
- * @returns Interpolated Vector2 value
671
- */
672
- vector2InterpolateFunction(startValue, endValue, gradient) {
673
- return Vector2.Lerp(startValue, endValue, gradient);
674
- }
675
- /**
676
- * Interpolates a Vector2 cubically
677
- * @param startValue Start value of the animation curve
678
- * @param outTangent End tangent of the animation
679
- * @param endValue End value of the animation curve
680
- * @param inTangent Start tangent of the animation curve
681
- * @param gradient Scalar amount to interpolate (value between 0 and 1)
682
- * @returns Interpolated Vector2 value
683
- */
684
- vector2InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {
685
- return Vector2.Hermite(startValue, outTangent, endValue, inTangent, gradient);
686
- }
687
- /**
688
- * Interpolates a size linearly
689
- * @param startValue Start value of the animation curve
690
- * @param endValue End value of the animation curve
691
- * @param gradient Scalar amount to interpolate
692
- * @returns Interpolated Size value
693
- */
694
- sizeInterpolateFunction(startValue, endValue, gradient) {
695
- return Size.Lerp(startValue, endValue, gradient);
696
- }
697
- /**
698
- * Interpolates a Color3 linearly
699
- * @param startValue Start value of the animation curve
700
- * @param endValue End value of the animation curve
701
- * @param gradient Scalar amount to interpolate
702
- * @returns Interpolated Color3 value
703
- */
704
- color3InterpolateFunction(startValue, endValue, gradient) {
705
- return Color3.Lerp(startValue, endValue, gradient);
706
- }
707
- /**
708
- * Interpolates a Color3 cubically
709
- * @param startValue Start value of the animation curve
710
- * @param outTangent End tangent of the animation
711
- * @param endValue End value of the animation curve
712
- * @param inTangent Start tangent of the animation curve
713
- * @param gradient Scalar amount to interpolate
714
- * @returns interpolated value
715
- */
716
- color3InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {
717
- return Color3.Hermite(startValue, outTangent, endValue, inTangent, gradient);
718
- }
719
- /**
720
- * Interpolates a Color4 linearly
721
- * @param startValue Start value of the animation curve
722
- * @param endValue End value of the animation curve
723
- * @param gradient Scalar amount to interpolate
724
- * @returns Interpolated Color3 value
725
- */
726
- color4InterpolateFunction(startValue, endValue, gradient) {
727
- return Color4.Lerp(startValue, endValue, gradient);
728
- }
729
- /**
730
- * Interpolates a Color4 cubically
731
- * @param startValue Start value of the animation curve
732
- * @param outTangent End tangent of the animation
733
- * @param endValue End value of the animation curve
734
- * @param inTangent Start tangent of the animation curve
735
- * @param gradient Scalar amount to interpolate
736
- * @returns interpolated value
737
- */
738
- color4InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {
739
- return Color4.Hermite(startValue, outTangent, endValue, inTangent, gradient);
740
- }
741
- /**
742
- * @internal Internal use only
743
- */
744
- _getKeyValue(value) {
745
- if (typeof value === "function") {
746
- return value();
747
- }
748
- return value;
749
- }
750
- /**
751
- * Evaluate the animation value at a given frame
752
- * @param currentFrame defines the frame where we want to evaluate the animation
753
- * @returns the animation value
754
- */
755
- evaluate(currentFrame) {
756
- return this._interpolate(currentFrame, {
757
- key: 0,
758
- repeatCount: 0,
759
- loopMode: Animation.ANIMATIONLOOPMODE_CONSTANT,
760
- });
761
- }
762
- /**
763
- * @internal Internal use only
764
- */
765
- _interpolate(currentFrame, state) {
766
- if (state.loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && state.repeatCount > 0) {
767
- return state.highLimitValue.clone ? state.highLimitValue.clone() : state.highLimitValue;
768
- }
769
- const keys = this._keys;
770
- const keysLength = keys.length;
771
- let key = state.key;
772
- while (key >= 0 && currentFrame < keys[key].frame) {
773
- --key;
774
- }
775
- while (key + 1 <= keysLength - 1 && currentFrame >= keys[key + 1].frame) {
776
- ++key;
777
- }
778
- state.key = key;
779
- if (key < 0) {
780
- return this._getKeyValue(keys[0].value);
781
- }
782
- else if (key + 1 > keysLength - 1) {
783
- return this._getKeyValue(keys[keysLength - 1].value);
784
- }
785
- const startKey = keys[key];
786
- const endKey = keys[key + 1];
787
- const startValue = this._getKeyValue(startKey.value);
788
- const endValue = this._getKeyValue(endKey.value);
789
- if (startKey.interpolation === AnimationKeyInterpolation.STEP) {
790
- if (endKey.frame > currentFrame) {
791
- return startValue;
792
- }
793
- else {
794
- return endValue;
795
- }
796
- }
797
- const useTangent = startKey.outTangent !== undefined && endKey.inTangent !== undefined;
798
- const frameDelta = endKey.frame - startKey.frame;
799
- // gradient : percent of currentFrame between the frame inf and the frame sup
800
- let gradient = (currentFrame - startKey.frame) / frameDelta;
801
- // check for easingFunction and correction of gradient
802
- const easingFunction = this.getEasingFunction();
803
- if (easingFunction !== null) {
804
- gradient = easingFunction.ease(gradient);
805
- }
806
- switch (this.dataType) {
807
- // Float
808
- case Animation.ANIMATIONTYPE_FLOAT: {
809
- const floatValue = useTangent
810
- ? this.floatInterpolateFunctionWithTangents(startValue, startKey.outTangent * frameDelta, endValue, endKey.inTangent * frameDelta, gradient)
811
- : this.floatInterpolateFunction(startValue, endValue, gradient);
812
- switch (state.loopMode) {
813
- case Animation.ANIMATIONLOOPMODE_CYCLE:
814
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
815
- case Animation.ANIMATIONLOOPMODE_YOYO:
816
- return floatValue;
817
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
818
- return state.offsetValue * state.repeatCount + floatValue;
819
- }
820
- break;
821
- }
822
- // Quaternion
823
- case Animation.ANIMATIONTYPE_QUATERNION: {
824
- const quatValue = useTangent
825
- ? this.quaternionInterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)
826
- : this.quaternionInterpolateFunction(startValue, endValue, gradient);
827
- switch (state.loopMode) {
828
- case Animation.ANIMATIONLOOPMODE_CYCLE:
829
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
830
- case Animation.ANIMATIONLOOPMODE_YOYO:
831
- return quatValue;
832
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
833
- return quatValue.addInPlace(state.offsetValue.scale(state.repeatCount));
834
- }
835
- return quatValue;
836
- }
837
- // Vector3
838
- case Animation.ANIMATIONTYPE_VECTOR3: {
839
- const vec3Value = useTangent
840
- ? this.vector3InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)
841
- : this.vector3InterpolateFunction(startValue, endValue, gradient);
842
- switch (state.loopMode) {
843
- case Animation.ANIMATIONLOOPMODE_CYCLE:
844
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
845
- case Animation.ANIMATIONLOOPMODE_YOYO:
846
- return vec3Value;
847
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
848
- return vec3Value.add(state.offsetValue.scale(state.repeatCount));
849
- }
850
- break;
851
- }
852
- // Vector2
853
- case Animation.ANIMATIONTYPE_VECTOR2: {
854
- const vec2Value = useTangent
855
- ? this.vector2InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)
856
- : this.vector2InterpolateFunction(startValue, endValue, gradient);
857
- switch (state.loopMode) {
858
- case Animation.ANIMATIONLOOPMODE_CYCLE:
859
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
860
- case Animation.ANIMATIONLOOPMODE_YOYO:
861
- return vec2Value;
862
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
863
- return vec2Value.add(state.offsetValue.scale(state.repeatCount));
864
- }
865
- break;
866
- }
867
- // Size
868
- case Animation.ANIMATIONTYPE_SIZE: {
869
- switch (state.loopMode) {
870
- case Animation.ANIMATIONLOOPMODE_CYCLE:
871
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
872
- case Animation.ANIMATIONLOOPMODE_YOYO:
873
- return this.sizeInterpolateFunction(startValue, endValue, gradient);
874
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
875
- return this.sizeInterpolateFunction(startValue, endValue, gradient).add(state.offsetValue.scale(state.repeatCount));
876
- }
877
- break;
878
- }
879
- // Color3
880
- case Animation.ANIMATIONTYPE_COLOR3: {
881
- const color3Value = useTangent
882
- ? this.color3InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)
883
- : this.color3InterpolateFunction(startValue, endValue, gradient);
884
- switch (state.loopMode) {
885
- case Animation.ANIMATIONLOOPMODE_CYCLE:
886
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
887
- case Animation.ANIMATIONLOOPMODE_YOYO:
888
- return color3Value;
889
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
890
- return color3Value.add(state.offsetValue.scale(state.repeatCount));
891
- }
892
- break;
893
- }
894
- // Color4
895
- case Animation.ANIMATIONTYPE_COLOR4: {
896
- const color4Value = useTangent
897
- ? this.color4InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)
898
- : this.color4InterpolateFunction(startValue, endValue, gradient);
899
- switch (state.loopMode) {
900
- case Animation.ANIMATIONLOOPMODE_CYCLE:
901
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
902
- case Animation.ANIMATIONLOOPMODE_YOYO:
903
- return color4Value;
904
- case Animation.ANIMATIONLOOPMODE_RELATIVE:
905
- return color4Value.add(state.offsetValue.scale(state.repeatCount));
906
- }
907
- break;
908
- }
909
- // Matrix
910
- case Animation.ANIMATIONTYPE_MATRIX: {
911
- switch (state.loopMode) {
912
- case Animation.ANIMATIONLOOPMODE_CYCLE:
913
- case Animation.ANIMATIONLOOPMODE_CONSTANT:
914
- case Animation.ANIMATIONLOOPMODE_YOYO: {
915
- if (Animation.AllowMatricesInterpolation) {
916
- return this.matrixInterpolateFunction(startValue, endValue, gradient, state.workValue);
917
- }
918
- return startValue;
919
- }
920
- case Animation.ANIMATIONLOOPMODE_RELATIVE: {
921
- return startValue;
922
- }
923
- }
924
- break;
925
- }
926
- }
927
- return 0;
928
- }
929
- /**
930
- * Defines the function to use to interpolate matrices
931
- * @param startValue defines the start matrix
932
- * @param endValue defines the end matrix
933
- * @param gradient defines the gradient between both matrices
934
- * @param result defines an optional target matrix where to store the interpolation
935
- * @returns the interpolated matrix
936
- */
937
- matrixInterpolateFunction(startValue, endValue, gradient, result) {
938
- if (Animation.AllowMatrixDecomposeForInterpolation) {
939
- if (result) {
940
- Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);
941
- return result;
942
- }
943
- return Matrix.DecomposeLerp(startValue, endValue, gradient);
944
- }
945
- if (result) {
946
- Matrix.LerpToRef(startValue, endValue, gradient, result);
947
- return result;
948
- }
949
- return Matrix.Lerp(startValue, endValue, gradient);
950
- }
951
- /**
952
- * Makes a copy of the animation
953
- * @returns Cloned animation
954
- */
955
- clone() {
956
- const clone = new Animation(this.name, this.targetPropertyPath.join("."), this.framePerSecond, this.dataType, this.loopMode);
957
- clone.enableBlending = this.enableBlending;
958
- clone.blendingSpeed = this.blendingSpeed;
959
- if (this._keys) {
960
- clone.setKeys(this._keys);
961
- }
962
- if (this._ranges) {
963
- clone._ranges = {};
964
- for (const name in this._ranges) {
965
- const range = this._ranges[name];
966
- if (!range) {
967
- continue;
968
- }
969
- clone._ranges[name] = range.clone();
970
- }
971
- }
972
- return clone;
973
- }
974
- /**
975
- * Sets the key frames of the animation
976
- * @param values The animation key frames to set
977
- */
978
- setKeys(values) {
979
- this._keys = values.slice(0);
980
- }
981
- /**
982
- * Serializes the animation to an object
983
- * @returns Serialized object
984
- */
985
- serialize() {
986
- const serializationObject = {};
987
- serializationObject.name = this.name;
988
- serializationObject.property = this.targetProperty;
989
- serializationObject.framePerSecond = this.framePerSecond;
990
- serializationObject.dataType = this.dataType;
991
- serializationObject.loopBehavior = this.loopMode;
992
- serializationObject.enableBlending = this.enableBlending;
993
- serializationObject.blendingSpeed = this.blendingSpeed;
994
- const dataType = this.dataType;
995
- serializationObject.keys = [];
996
- const keys = this.getKeys();
997
- for (let index = 0; index < keys.length; index++) {
998
- const animationKey = keys[index];
999
- const key = {};
1000
- key.frame = animationKey.frame;
1001
- switch (dataType) {
1002
- case Animation.ANIMATIONTYPE_FLOAT:
1003
- key.values = [animationKey.value];
1004
- if (animationKey.inTangent !== undefined) {
1005
- key.values.push(animationKey.inTangent);
1006
- }
1007
- if (animationKey.outTangent !== undefined) {
1008
- if (animationKey.inTangent === undefined) {
1009
- key.values.push(undefined);
1010
- }
1011
- key.values.push(animationKey.outTangent);
1012
- }
1013
- if (animationKey.interpolation !== undefined) {
1014
- if (animationKey.inTangent === undefined) {
1015
- key.values.push(undefined);
1016
- }
1017
- if (animationKey.outTangent === undefined) {
1018
- key.values.push(undefined);
1019
- }
1020
- key.values.push(animationKey.interpolation);
1021
- }
1022
- break;
1023
- case Animation.ANIMATIONTYPE_QUATERNION:
1024
- case Animation.ANIMATIONTYPE_MATRIX:
1025
- case Animation.ANIMATIONTYPE_VECTOR3:
1026
- case Animation.ANIMATIONTYPE_COLOR3:
1027
- case Animation.ANIMATIONTYPE_COLOR4:
1028
- key.values = animationKey.value.asArray();
1029
- if (animationKey.inTangent != undefined) {
1030
- key.values.push(animationKey.inTangent.asArray());
1031
- }
1032
- if (animationKey.outTangent != undefined) {
1033
- if (animationKey.inTangent === undefined) {
1034
- key.values.push(undefined);
1035
- }
1036
- key.values.push(animationKey.outTangent.asArray());
1037
- }
1038
- if (animationKey.interpolation !== undefined) {
1039
- if (animationKey.inTangent === undefined) {
1040
- key.values.push(undefined);
1041
- }
1042
- if (animationKey.outTangent === undefined) {
1043
- key.values.push(undefined);
1044
- }
1045
- key.values.push(animationKey.interpolation);
1046
- }
1047
- break;
1048
- }
1049
- serializationObject.keys.push(key);
1050
- }
1051
- serializationObject.ranges = [];
1052
- for (const name in this._ranges) {
1053
- const source = this._ranges[name];
1054
- if (!source) {
1055
- continue;
1056
- }
1057
- const range = {};
1058
- range.name = name;
1059
- range.from = source.from;
1060
- range.to = source.to;
1061
- serializationObject.ranges.push(range);
1062
- }
1063
- return serializationObject;
1064
- }
1065
- /**
1066
- * @internal
1067
- */
1068
- static _UniversalLerp(left, right, amount) {
1069
- const constructor = left.constructor;
1070
- if (constructor.Lerp) {
1071
- // Lerp supported
1072
- return constructor.Lerp(left, right, amount);
1073
- }
1074
- else if (constructor.Slerp) {
1075
- // Slerp supported
1076
- return constructor.Slerp(left, right, amount);
1077
- }
1078
- else if (left.toFixed) {
1079
- // Number
1080
- return left * (1.0 - amount) + amount * right;
1081
- }
1082
- else {
1083
- // Blending not supported
1084
- return right;
1085
- }
1086
- }
1087
- /**
1088
- * Parses an animation object and creates an animation
1089
- * @param parsedAnimation Parsed animation object
1090
- * @returns Animation object
1091
- */
1092
- static Parse(parsedAnimation) {
1093
- const animation = new Animation(parsedAnimation.name, parsedAnimation.property, parsedAnimation.framePerSecond, parsedAnimation.dataType, parsedAnimation.loopBehavior);
1094
- const dataType = parsedAnimation.dataType;
1095
- const keys = [];
1096
- let data;
1097
- let index;
1098
- if (parsedAnimation.enableBlending) {
1099
- animation.enableBlending = parsedAnimation.enableBlending;
1100
- }
1101
- if (parsedAnimation.blendingSpeed) {
1102
- animation.blendingSpeed = parsedAnimation.blendingSpeed;
1103
- }
1104
- for (index = 0; index < parsedAnimation.keys.length; index++) {
1105
- const key = parsedAnimation.keys[index];
1106
- let inTangent = undefined;
1107
- let outTangent = undefined;
1108
- let interpolation = undefined;
1109
- switch (dataType) {
1110
- case Animation.ANIMATIONTYPE_FLOAT:
1111
- data = key.values[0];
1112
- if (key.values.length >= 2) {
1113
- inTangent = key.values[1];
1114
- }
1115
- if (key.values.length >= 3) {
1116
- outTangent = key.values[2];
1117
- }
1118
- if (key.values.length >= 4) {
1119
- interpolation = key.values[3];
1120
- }
1121
- break;
1122
- case Animation.ANIMATIONTYPE_QUATERNION:
1123
- data = Quaternion.FromArray(key.values);
1124
- if (key.values.length >= 8) {
1125
- const _inTangent = Quaternion.FromArray(key.values.slice(4, 8));
1126
- if (!_inTangent.equals(Quaternion.Zero())) {
1127
- inTangent = _inTangent;
1128
- }
1129
- }
1130
- if (key.values.length >= 12) {
1131
- const _outTangent = Quaternion.FromArray(key.values.slice(8, 12));
1132
- if (!_outTangent.equals(Quaternion.Zero())) {
1133
- outTangent = _outTangent;
1134
- }
1135
- }
1136
- if (key.values.length >= 13) {
1137
- interpolation = key.values[12];
1138
- }
1139
- break;
1140
- case Animation.ANIMATIONTYPE_MATRIX:
1141
- data = Matrix.FromArray(key.values);
1142
- if (key.values.length >= 17) {
1143
- interpolation = key.values[16];
1144
- }
1145
- break;
1146
- case Animation.ANIMATIONTYPE_COLOR3:
1147
- data = Color3.FromArray(key.values);
1148
- if (key.values[3]) {
1149
- inTangent = Color3.FromArray(key.values[3]);
1150
- }
1151
- if (key.values[4]) {
1152
- outTangent = Color3.FromArray(key.values[4]);
1153
- }
1154
- if (key.values[5]) {
1155
- interpolation = key.values[5];
1156
- }
1157
- break;
1158
- case Animation.ANIMATIONTYPE_COLOR4:
1159
- data = Color4.FromArray(key.values);
1160
- if (key.values[4]) {
1161
- inTangent = Color4.FromArray(key.values[4]);
1162
- }
1163
- if (key.values[5]) {
1164
- outTangent = Color4.FromArray(key.values[5]);
1165
- }
1166
- if (key.values[6]) {
1167
- interpolation = Color4.FromArray(key.values[6]);
1168
- }
1169
- break;
1170
- case Animation.ANIMATIONTYPE_VECTOR3:
1171
- default:
1172
- data = Vector3.FromArray(key.values);
1173
- if (key.values[3]) {
1174
- inTangent = Vector3.FromArray(key.values[3]);
1175
- }
1176
- if (key.values[4]) {
1177
- outTangent = Vector3.FromArray(key.values[4]);
1178
- }
1179
- if (key.values[5]) {
1180
- interpolation = key.values[5];
1181
- }
1182
- break;
1183
- }
1184
- const keyData = {};
1185
- keyData.frame = key.frame;
1186
- keyData.value = data;
1187
- if (inTangent != undefined) {
1188
- keyData.inTangent = inTangent;
1189
- }
1190
- if (outTangent != undefined) {
1191
- keyData.outTangent = outTangent;
1192
- }
1193
- if (interpolation != undefined) {
1194
- keyData.interpolation = interpolation;
1195
- }
1196
- keys.push(keyData);
1197
- }
1198
- animation.setKeys(keys);
1199
- if (parsedAnimation.ranges) {
1200
- for (index = 0; index < parsedAnimation.ranges.length; index++) {
1201
- data = parsedAnimation.ranges[index];
1202
- animation.createRange(data.name, data.from, data.to);
1203
- }
1204
- }
1205
- return animation;
1206
- }
1207
- /**
1208
- * Appends the serialized animations from the source animations
1209
- * @param source Source containing the animations
1210
- * @param destination Target to store the animations
1211
- */
1212
- static AppendSerializedAnimations(source, destination) {
1213
- SerializationHelper.AppendSerializedAnimations(source, destination);
1214
- }
1215
- /**
1216
- * Creates a new animation or an array of animations from a snippet saved in a remote file
1217
- * @param name defines the name of the animation to create (can be null or empty to use the one from the json data)
1218
- * @param url defines the url to load from
1219
- * @returns a promise that will resolve to the new animation or an array of animations
1220
- */
1221
- static ParseFromFileAsync(name, url) {
1222
- return new Promise((resolve, reject) => {
1223
- const request = new WebRequest();
1224
- request.addEventListener("readystatechange", () => {
1225
- if (request.readyState == 4) {
1226
- if (request.status == 200) {
1227
- let serializationObject = JSON.parse(request.responseText);
1228
- if (serializationObject.animations) {
1229
- serializationObject = serializationObject.animations;
1230
- }
1231
- if (serializationObject.length) {
1232
- const output = new Array();
1233
- for (const serializedAnimation of serializationObject) {
1234
- output.push(this.Parse(serializedAnimation));
1235
- }
1236
- resolve(output);
1237
- }
1238
- else {
1239
- const output = this.Parse(serializationObject);
1240
- if (name) {
1241
- output.name = name;
1242
- }
1243
- resolve(output);
1244
- }
1245
- }
1246
- else {
1247
- reject("Unable to load the animation");
1248
- }
1249
- }
1250
- });
1251
- request.open("GET", url);
1252
- request.send();
1253
- });
1254
- }
1255
- /**
1256
- * Creates an animation or an array of animations from a snippet saved by the Inspector
1257
- * @param snippetId defines the snippet to load
1258
- * @returns a promise that will resolve to the new animation or a new array of animations
1259
- */
1260
- static ParseFromSnippetAsync(snippetId) {
1261
- return new Promise((resolve, reject) => {
1262
- const request = new WebRequest();
1263
- request.addEventListener("readystatechange", () => {
1264
- if (request.readyState == 4) {
1265
- if (request.status == 200) {
1266
- const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);
1267
- if (snippet.animations) {
1268
- const serializationObject = JSON.parse(snippet.animations);
1269
- const outputs = new Array();
1270
- for (const serializedAnimation of serializationObject.animations) {
1271
- const output = this.Parse(serializedAnimation);
1272
- output.snippetId = snippetId;
1273
- outputs.push(output);
1274
- }
1275
- resolve(outputs);
1276
- }
1277
- else {
1278
- const serializationObject = JSON.parse(snippet.animation);
1279
- const output = this.Parse(serializationObject);
1280
- output.snippetId = snippetId;
1281
- resolve(output);
1282
- }
1283
- }
1284
- else {
1285
- reject("Unable to load the snippet " + snippetId);
1286
- }
1287
- }
1288
- });
1289
- request.open("GET", this.SnippetUrl + "/" + snippetId.replace(/#/g, "/"));
1290
- request.send();
1291
- });
1292
- }
1293
- }
1294
- Animation._UniqueIdGenerator = 0;
1295
- /**
1296
- * Use matrix interpolation instead of using direct key value when animating matrices
1297
- */
1298
- Animation.AllowMatricesInterpolation = false;
1299
- /**
1300
- * When matrix interpolation is enabled, this boolean forces the system to use Matrix.DecomposeLerp instead of Matrix.Lerp. Interpolation is more precise but slower
1301
- */
1302
- Animation.AllowMatrixDecomposeForInterpolation = true;
1303
- /** Define the Url to load snippets */
1304
- Animation.SnippetUrl = `https://snippet.babylonjs.com`;
1305
- // Statics
1306
- /**
1307
- * Float animation type
1308
- */
1309
- Animation.ANIMATIONTYPE_FLOAT = 0;
1310
- /**
1311
- * Vector3 animation type
1312
- */
1313
- Animation.ANIMATIONTYPE_VECTOR3 = 1;
1314
- /**
1315
- * Quaternion animation type
1316
- */
1317
- Animation.ANIMATIONTYPE_QUATERNION = 2;
1318
- /**
1319
- * Matrix animation type
1320
- */
1321
- Animation.ANIMATIONTYPE_MATRIX = 3;
1322
- /**
1323
- * Color3 animation type
1324
- */
1325
- Animation.ANIMATIONTYPE_COLOR3 = 4;
1326
- /**
1327
- * Color3 animation type
1328
- */
1329
- Animation.ANIMATIONTYPE_COLOR4 = 7;
1330
- /**
1331
- * Vector2 animation type
1332
- */
1333
- Animation.ANIMATIONTYPE_VECTOR2 = 5;
1334
- /**
1335
- * Size animation type
1336
- */
1337
- Animation.ANIMATIONTYPE_SIZE = 6;
1338
- /**
1339
- * Relative Loop Mode
1340
- */
1341
- Animation.ANIMATIONLOOPMODE_RELATIVE = 0;
1342
- /**
1343
- * Cycle Loop Mode
1344
- */
1345
- Animation.ANIMATIONLOOPMODE_CYCLE = 1;
1346
- /**
1347
- * Constant Loop Mode
1348
- */
1349
- Animation.ANIMATIONLOOPMODE_CONSTANT = 2;
1350
- /**
1351
- * Yoyo Loop Mode
1352
- */
1353
- Animation.ANIMATIONLOOPMODE_YOYO = 4;
1354
- /**
1355
- * Creates an animation or an array of animations from a snippet saved by the Inspector
1356
- * @deprecated Please use ParseFromSnippetAsync instead
1357
- * @param snippetId defines the snippet to load
1358
- * @returns a promise that will resolve to the new animation or a new array of animations
1359
- */
1360
- Animation.CreateFromSnippetAsync = Animation.ParseFromSnippetAsync;
1361
- RegisterClass("BABYLON.Animation", Animation);
1362
- Node._AnimationRangeFactory = (name, from, to) => new AnimationRange(name, from, to);
1363
-
1364
- export { Animation as A, AnimationRange as a, AnimationKeyInterpolation as b };