@onerjs/serializers 8.23.6 → 8.23.8
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/glTF/2.0/glTFAnimation.js +224 -88
- package/package.json +2 -2
|
@@ -17,11 +17,11 @@ var _TangentType;
|
|
|
17
17
|
/**
|
|
18
18
|
* Specifies that input tangents are used.
|
|
19
19
|
*/
|
|
20
|
-
_TangentType[_TangentType["INTANGENT"] = 0] = "INTANGENT";
|
|
20
|
+
_TangentType[(_TangentType["INTANGENT"] = 0)] = "INTANGENT";
|
|
21
21
|
/**
|
|
22
22
|
* Specifies that output tangents are used.
|
|
23
23
|
*/
|
|
24
|
-
_TangentType[_TangentType["OUTTANGENT"] = 1] = "OUTTANGENT";
|
|
24
|
+
_TangentType[(_TangentType["OUTTANGENT"] = 1)] = "OUTTANGENT";
|
|
25
25
|
})(_TangentType || (_TangentType = {}));
|
|
26
26
|
/**
|
|
27
27
|
* @internal
|
|
@@ -56,17 +56,38 @@ export class _GLTFAnimation {
|
|
|
56
56
|
const interpolation = interpolationOrBake.interpolationType;
|
|
57
57
|
const shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
|
|
58
58
|
if (shouldBakeAnimation) {
|
|
59
|
-
_GLTFAnimation._CreateBakedAnimation(
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
_GLTFAnimation._CreateBakedAnimation(
|
|
60
|
+
babylonTransformNode,
|
|
61
|
+
animation,
|
|
62
|
+
animationChannelTargetPath,
|
|
63
|
+
minMaxKeyFrames.min,
|
|
64
|
+
minMaxKeyFrames.max,
|
|
65
|
+
animation.framePerSecond,
|
|
66
|
+
animationSampleRate,
|
|
67
|
+
inputs,
|
|
68
|
+
outputs,
|
|
69
|
+
minMaxKeyFrames,
|
|
70
|
+
useQuaternion
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
62
73
|
if (interpolation === "LINEAR" /* AnimationSamplerInterpolation.LINEAR */ || interpolation === "STEP" /* AnimationSamplerInterpolation.STEP */) {
|
|
63
74
|
_GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion);
|
|
64
|
-
}
|
|
65
|
-
else if (interpolation === "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */) {
|
|
75
|
+
} else if (interpolation === "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */) {
|
|
66
76
|
_GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
} else {
|
|
78
|
+
_GLTFAnimation._CreateBakedAnimation(
|
|
79
|
+
babylonTransformNode,
|
|
80
|
+
animation,
|
|
81
|
+
animationChannelTargetPath,
|
|
82
|
+
minMaxKeyFrames.min,
|
|
83
|
+
minMaxKeyFrames.max,
|
|
84
|
+
animation.framePerSecond,
|
|
85
|
+
animationSampleRate,
|
|
86
|
+
inputs,
|
|
87
|
+
outputs,
|
|
88
|
+
minMaxKeyFrames,
|
|
89
|
+
useQuaternion
|
|
90
|
+
);
|
|
70
91
|
}
|
|
71
92
|
}
|
|
72
93
|
if (inputs.length && outputs.length) {
|
|
@@ -84,7 +105,7 @@ export class _GLTFAnimation {
|
|
|
84
105
|
}
|
|
85
106
|
static _DeduceAnimationInfo(animation) {
|
|
86
107
|
let animationChannelTargetPath = null;
|
|
87
|
-
let dataAccessorType = "VEC3" /* AccessorType.VEC3
|
|
108
|
+
let dataAccessorType = "VEC3"; /* AccessorType.VEC3 */
|
|
88
109
|
let useQuaternion = false;
|
|
89
110
|
const property = animation.targetProperty.split(".");
|
|
90
111
|
switch (property[0]) {
|
|
@@ -118,8 +139,7 @@ export class _GLTFAnimation {
|
|
|
118
139
|
}
|
|
119
140
|
if (animationChannelTargetPath) {
|
|
120
141
|
return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
142
|
+
} else {
|
|
123
143
|
Tools.Error("animation channel target path and data accessor type could be deduced");
|
|
124
144
|
}
|
|
125
145
|
return null;
|
|
@@ -137,7 +157,19 @@ export class _GLTFAnimation {
|
|
|
137
157
|
* @param accessors
|
|
138
158
|
* @param animationSampleRate
|
|
139
159
|
*/
|
|
140
|
-
static _CreateNodeAnimationFromNodeAnimations(
|
|
160
|
+
static _CreateNodeAnimationFromNodeAnimations(
|
|
161
|
+
babylonNode,
|
|
162
|
+
runtimeGLTFAnimation,
|
|
163
|
+
idleGLTFAnimations,
|
|
164
|
+
nodeMap,
|
|
165
|
+
nodes,
|
|
166
|
+
bufferManager,
|
|
167
|
+
bufferViews,
|
|
168
|
+
accessors,
|
|
169
|
+
animationSampleRate,
|
|
170
|
+
useRightHanded,
|
|
171
|
+
shouldExportAnimation
|
|
172
|
+
) {
|
|
141
173
|
let glTFAnimation;
|
|
142
174
|
if (_GLTFAnimation._IsTransformable(babylonNode)) {
|
|
143
175
|
if (babylonNode.animations) {
|
|
@@ -152,7 +184,21 @@ export class _GLTFAnimation {
|
|
|
152
184
|
samplers: [],
|
|
153
185
|
channels: [],
|
|
154
186
|
};
|
|
155
|
-
_GLTFAnimation._AddAnimation(
|
|
187
|
+
_GLTFAnimation._AddAnimation(
|
|
188
|
+
`${animation.name}`,
|
|
189
|
+
animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation,
|
|
190
|
+
babylonNode,
|
|
191
|
+
animation,
|
|
192
|
+
animationInfo.dataAccessorType,
|
|
193
|
+
animationInfo.animationChannelTargetPath,
|
|
194
|
+
nodeMap,
|
|
195
|
+
bufferManager,
|
|
196
|
+
bufferViews,
|
|
197
|
+
accessors,
|
|
198
|
+
animationInfo.useQuaternion,
|
|
199
|
+
animationSampleRate,
|
|
200
|
+
useRightHanded
|
|
201
|
+
);
|
|
156
202
|
if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
|
|
157
203
|
idleGLTFAnimations.push(glTFAnimation);
|
|
158
204
|
}
|
|
@@ -174,7 +220,19 @@ export class _GLTFAnimation {
|
|
|
174
220
|
* @param accessors
|
|
175
221
|
* @param animationSampleRate
|
|
176
222
|
*/
|
|
177
|
-
static _CreateMorphTargetAnimationFromMorphTargetAnimations(
|
|
223
|
+
static _CreateMorphTargetAnimationFromMorphTargetAnimations(
|
|
224
|
+
babylonNode,
|
|
225
|
+
runtimeGLTFAnimation,
|
|
226
|
+
idleGLTFAnimations,
|
|
227
|
+
nodeMap,
|
|
228
|
+
nodes,
|
|
229
|
+
bufferManager,
|
|
230
|
+
bufferViews,
|
|
231
|
+
accessors,
|
|
232
|
+
animationSampleRate,
|
|
233
|
+
useRightHanded,
|
|
234
|
+
shouldExportAnimation
|
|
235
|
+
) {
|
|
178
236
|
let glTFAnimation;
|
|
179
237
|
if (babylonNode instanceof Mesh) {
|
|
180
238
|
const morphTargetManager = babylonNode.morphTargetManager;
|
|
@@ -185,7 +243,14 @@ export class _GLTFAnimation {
|
|
|
185
243
|
if (shouldExportAnimation && !shouldExportAnimation(animation)) {
|
|
186
244
|
continue;
|
|
187
245
|
}
|
|
188
|
-
const combinedAnimation = new Animation(
|
|
246
|
+
const combinedAnimation = new Animation(
|
|
247
|
+
`${animation.name}`,
|
|
248
|
+
"influence",
|
|
249
|
+
animation.framePerSecond,
|
|
250
|
+
animation.dataType,
|
|
251
|
+
animation.loopMode,
|
|
252
|
+
animation.enableBlending
|
|
253
|
+
);
|
|
189
254
|
const combinedAnimationKeys = [];
|
|
190
255
|
const animationKeys = animation.getKeys();
|
|
191
256
|
for (let j = 0; j < animationKeys.length; ++j) {
|
|
@@ -193,8 +258,7 @@ export class _GLTFAnimation {
|
|
|
193
258
|
for (let k = 0; k < morphTargetManager.numTargets; ++k) {
|
|
194
259
|
if (k == i) {
|
|
195
260
|
combinedAnimationKeys.push(animationKey);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
261
|
+
} else {
|
|
198
262
|
combinedAnimationKeys.push({ frame: animationKey.frame, value: 0 });
|
|
199
263
|
}
|
|
200
264
|
}
|
|
@@ -207,7 +271,22 @@ export class _GLTFAnimation {
|
|
|
207
271
|
samplers: [],
|
|
208
272
|
channels: [],
|
|
209
273
|
};
|
|
210
|
-
_GLTFAnimation._AddAnimation(
|
|
274
|
+
_GLTFAnimation._AddAnimation(
|
|
275
|
+
animation.name,
|
|
276
|
+
animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation,
|
|
277
|
+
babylonNode,
|
|
278
|
+
combinedAnimation,
|
|
279
|
+
animationInfo.dataAccessorType,
|
|
280
|
+
animationInfo.animationChannelTargetPath,
|
|
281
|
+
nodeMap,
|
|
282
|
+
bufferManager,
|
|
283
|
+
bufferViews,
|
|
284
|
+
accessors,
|
|
285
|
+
animationInfo.useQuaternion,
|
|
286
|
+
animationSampleRate,
|
|
287
|
+
useRightHanded,
|
|
288
|
+
morphTargetManager.numTargets
|
|
289
|
+
);
|
|
211
290
|
if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
|
|
212
291
|
idleGLTFAnimations.push(glTFAnimation);
|
|
213
292
|
}
|
|
@@ -229,7 +308,17 @@ export class _GLTFAnimation {
|
|
|
229
308
|
* @param accessors
|
|
230
309
|
* @param animationSampleRate
|
|
231
310
|
*/
|
|
232
|
-
static _CreateNodeAndMorphAnimationFromAnimationGroups(
|
|
311
|
+
static _CreateNodeAndMorphAnimationFromAnimationGroups(
|
|
312
|
+
babylonScene,
|
|
313
|
+
glTFAnimations,
|
|
314
|
+
nodeMap,
|
|
315
|
+
bufferManager,
|
|
316
|
+
bufferViews,
|
|
317
|
+
accessors,
|
|
318
|
+
animationSampleRate,
|
|
319
|
+
leftHandedNodes,
|
|
320
|
+
shouldExportAnimation
|
|
321
|
+
) {
|
|
233
322
|
let glTFAnimation;
|
|
234
323
|
if (babylonScene.animationGroups) {
|
|
235
324
|
const animationGroups = babylonScene.animationGroups;
|
|
@@ -242,7 +331,7 @@ export class _GLTFAnimation {
|
|
|
242
331
|
name: animationGroup.name,
|
|
243
332
|
channels: [],
|
|
244
333
|
samplers: [],
|
|
245
|
-
|
|
334
|
+
extras: animationGroup.metadata,
|
|
246
335
|
};
|
|
247
336
|
for (let i = 0; i < animationGroup.targetedAnimations.length; ++i) {
|
|
248
337
|
const targetAnimation = animationGroup.targetedAnimations[i];
|
|
@@ -257,11 +346,24 @@ export class _GLTFAnimation {
|
|
|
257
346
|
if (animationInfo) {
|
|
258
347
|
const babylonTransformNode = this._IsTransformable(target) ? target : this._IsTransformable(target[0]) ? target[0] : null;
|
|
259
348
|
if (babylonTransformNode) {
|
|
260
|
-
_GLTFAnimation._AddAnimation(
|
|
349
|
+
_GLTFAnimation._AddAnimation(
|
|
350
|
+
`${animation.name}`,
|
|
351
|
+
glTFAnimation,
|
|
352
|
+
babylonTransformNode,
|
|
353
|
+
animation,
|
|
354
|
+
animationInfo.dataAccessorType,
|
|
355
|
+
animationInfo.animationChannelTargetPath,
|
|
356
|
+
nodeMap,
|
|
357
|
+
bufferManager,
|
|
358
|
+
bufferViews,
|
|
359
|
+
accessors,
|
|
360
|
+
animationInfo.useQuaternion,
|
|
361
|
+
animationSampleRate,
|
|
362
|
+
convertToRightHanded
|
|
363
|
+
);
|
|
261
364
|
}
|
|
262
365
|
}
|
|
263
|
-
}
|
|
264
|
-
else if (target instanceof MorphTarget || (target.length === 1 && target[0] instanceof MorphTarget)) {
|
|
366
|
+
} else if (target instanceof MorphTarget || (target.length === 1 && target[0] instanceof MorphTarget)) {
|
|
265
367
|
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
|
|
266
368
|
if (animationInfo) {
|
|
267
369
|
const babylonMorphTarget = target instanceof MorphTarget ? target : target[0];
|
|
@@ -289,8 +391,7 @@ export class _GLTFAnimation {
|
|
|
289
391
|
}
|
|
290
392
|
}
|
|
291
393
|
}
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
394
|
+
} else {
|
|
294
395
|
// this is the place for the KHR_animation_pointer.
|
|
295
396
|
}
|
|
296
397
|
}
|
|
@@ -318,11 +419,17 @@ export class _GLTFAnimation {
|
|
|
318
419
|
const morphTargetAnimation = animationsByMorphTarget.get(morphTarget);
|
|
319
420
|
if (morphTargetAnimation) {
|
|
320
421
|
if (!combinedAnimationGroup) {
|
|
321
|
-
combinedAnimationGroup = new Animation(
|
|
422
|
+
combinedAnimationGroup = new Animation(
|
|
423
|
+
`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`,
|
|
424
|
+
"influence",
|
|
425
|
+
morphTargetAnimation.framePerSecond,
|
|
426
|
+
Animation.ANIMATIONTYPE_FLOAT,
|
|
427
|
+
morphTargetAnimation.loopMode,
|
|
428
|
+
morphTargetAnimation.enableBlending
|
|
429
|
+
);
|
|
322
430
|
}
|
|
323
431
|
animationKeys.push(morphTargetAnimation.getKeys()[i]);
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
432
|
+
} else {
|
|
326
433
|
animationKeys.push({
|
|
327
434
|
frame: animationGroup.from + (animationGroupFrameDiff / numAnimationKeys) * i,
|
|
328
435
|
value: morphTarget.influence,
|
|
@@ -336,7 +443,22 @@ export class _GLTFAnimation {
|
|
|
336
443
|
combinedAnimationGroup.setKeys(animationKeys);
|
|
337
444
|
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup);
|
|
338
445
|
if (animationInfo) {
|
|
339
|
-
_GLTFAnimation._AddAnimation(
|
|
446
|
+
_GLTFAnimation._AddAnimation(
|
|
447
|
+
`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`,
|
|
448
|
+
glTFAnimation,
|
|
449
|
+
mesh,
|
|
450
|
+
combinedAnimationGroup,
|
|
451
|
+
animationInfo.dataAccessorType,
|
|
452
|
+
animationInfo.animationChannelTargetPath,
|
|
453
|
+
nodeMap,
|
|
454
|
+
bufferManager,
|
|
455
|
+
bufferViews,
|
|
456
|
+
accessors,
|
|
457
|
+
animationInfo.useQuaternion,
|
|
458
|
+
animationSampleRate,
|
|
459
|
+
false,
|
|
460
|
+
morphTargetManager?.numTargets
|
|
461
|
+
);
|
|
340
462
|
}
|
|
341
463
|
});
|
|
342
464
|
if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
|
|
@@ -345,7 +467,22 @@ export class _GLTFAnimation {
|
|
|
345
467
|
}
|
|
346
468
|
}
|
|
347
469
|
}
|
|
348
|
-
static _AddAnimation(
|
|
470
|
+
static _AddAnimation(
|
|
471
|
+
name,
|
|
472
|
+
glTFAnimation,
|
|
473
|
+
babylonTransformNode,
|
|
474
|
+
animation,
|
|
475
|
+
dataAccessorType,
|
|
476
|
+
animationChannelTargetPath,
|
|
477
|
+
nodeMap,
|
|
478
|
+
bufferManager,
|
|
479
|
+
bufferViews,
|
|
480
|
+
accessors,
|
|
481
|
+
useQuaternion,
|
|
482
|
+
animationSampleRate,
|
|
483
|
+
convertToRightHanded,
|
|
484
|
+
morphAnimationChannels
|
|
485
|
+
) {
|
|
349
486
|
const animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, useQuaternion, animationSampleRate);
|
|
350
487
|
let bufferView;
|
|
351
488
|
let accessor;
|
|
@@ -376,10 +513,17 @@ export class _GLTFAnimation {
|
|
|
376
513
|
// Create buffer view and accessor for key frames.
|
|
377
514
|
const inputData = new Float32Array(animationData.inputs);
|
|
378
515
|
bufferView = bufferManager.createBufferView(inputData);
|
|
379
|
-
accessor = bufferManager.createAccessor(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
516
|
+
accessor = bufferManager.createAccessor(
|
|
517
|
+
bufferView,
|
|
518
|
+
"SCALAR" /* AccessorType.SCALAR */,
|
|
519
|
+
5126 /* AccessorComponentType.FLOAT */,
|
|
520
|
+
animationData.inputs.length,
|
|
521
|
+
undefined,
|
|
522
|
+
{
|
|
523
|
+
min: [animationData.inputsMin],
|
|
524
|
+
max: [animationData.inputsMax],
|
|
525
|
+
}
|
|
526
|
+
);
|
|
383
527
|
accessors.push(accessor);
|
|
384
528
|
keyframeAccessorIndex = accessors.length - 1;
|
|
385
529
|
// Perform conversions on keyed values while also building their buffer.
|
|
@@ -402,8 +546,7 @@ export class _GLTFAnimation {
|
|
|
402
546
|
case "rotation" /* AnimationChannelTargetPath.ROTATION */:
|
|
403
547
|
if (output.length === 4) {
|
|
404
548
|
Quaternion.FromArrayToRef(output, 0, rotationQuaternion);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
549
|
+
} else {
|
|
407
550
|
outputToWrite = new Array(4); // Will need 4, not 3, for a quaternion
|
|
408
551
|
Vector3.FromArrayToRef(output, 0, eulerVec3);
|
|
409
552
|
Quaternion.FromEulerVectorToRef(eulerVec3, rotationQuaternion);
|
|
@@ -479,22 +622,18 @@ export class _GLTFAnimation {
|
|
|
479
622
|
if (i === 0) {
|
|
480
623
|
// set the first frame to itself
|
|
481
624
|
endFrame = currKeyFrame.frame;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
625
|
+
} else {
|
|
484
626
|
continue;
|
|
485
627
|
}
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
628
|
+
} else {
|
|
488
629
|
endFrame = nextKeyFrame.frame;
|
|
489
630
|
}
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
631
|
+
} else {
|
|
492
632
|
// at the last key frame
|
|
493
633
|
prevKeyFrame = keyFrames[i - 1];
|
|
494
634
|
if ((currKeyFrame.value.equals && currKeyFrame.value.equals(prevKeyFrame.value)) || currKeyFrame.value === prevKeyFrame.value) {
|
|
495
635
|
continue;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
636
|
+
} else {
|
|
498
637
|
endFrame = maxFrame;
|
|
499
638
|
}
|
|
500
639
|
}
|
|
@@ -556,14 +695,12 @@ export class _GLTFAnimation {
|
|
|
556
695
|
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */) {
|
|
557
696
|
if (useQuaternion) {
|
|
558
697
|
quaternionCache = value;
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
698
|
+
} else {
|
|
561
699
|
cacheValue = value;
|
|
562
700
|
Quaternion.RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);
|
|
563
701
|
}
|
|
564
702
|
outputs.push(quaternionCache.asArray());
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
703
|
+
} else {
|
|
567
704
|
// scaling and position animation
|
|
568
705
|
cacheValue = value;
|
|
569
706
|
outputs.push(cacheValue.asArray());
|
|
@@ -596,9 +733,23 @@ export class _GLTFAnimation {
|
|
|
596
733
|
static _CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion) {
|
|
597
734
|
animation.getKeys().forEach(function (keyFrame) {
|
|
598
735
|
inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
|
|
599
|
-
_GLTFAnimation._AddSplineTangent(
|
|
736
|
+
_GLTFAnimation._AddSplineTangent(
|
|
737
|
+
_TangentType.INTANGENT,
|
|
738
|
+
outputs,
|
|
739
|
+
animationChannelTargetPath,
|
|
740
|
+
"CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */,
|
|
741
|
+
keyFrame,
|
|
742
|
+
useQuaternion
|
|
743
|
+
);
|
|
600
744
|
_GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, useQuaternion);
|
|
601
|
-
_GLTFAnimation._AddSplineTangent(
|
|
745
|
+
_GLTFAnimation._AddSplineTangent(
|
|
746
|
+
_TangentType.OUTTANGENT,
|
|
747
|
+
outputs,
|
|
748
|
+
animationChannelTargetPath,
|
|
749
|
+
"CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */,
|
|
750
|
+
keyFrame,
|
|
751
|
+
useQuaternion
|
|
752
|
+
);
|
|
602
753
|
});
|
|
603
754
|
}
|
|
604
755
|
static _GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, useQuaternion) {
|
|
@@ -607,17 +758,14 @@ export class _GLTFAnimation {
|
|
|
607
758
|
if (useQuaternion) {
|
|
608
759
|
const q = babylonTransformNode.rotationQuaternion;
|
|
609
760
|
basePositionRotationOrScale = (q ?? Quaternion.Identity()).asArray();
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
761
|
+
} else {
|
|
612
762
|
const r = babylonTransformNode.rotation;
|
|
613
763
|
basePositionRotationOrScale = (r ?? Vector3.Zero()).asArray();
|
|
614
764
|
}
|
|
615
|
-
}
|
|
616
|
-
else if (animationChannelTargetPath === "translation" /* AnimationChannelTargetPath.TRANSLATION */) {
|
|
765
|
+
} else if (animationChannelTargetPath === "translation" /* AnimationChannelTargetPath.TRANSLATION */) {
|
|
617
766
|
const p = babylonTransformNode.position;
|
|
618
767
|
basePositionRotationOrScale = (p ?? Vector3.Zero()).asArray();
|
|
619
|
-
}
|
|
620
|
-
else {
|
|
768
|
+
} else {
|
|
621
769
|
// scale
|
|
622
770
|
const s = babylonTransformNode.scaling;
|
|
623
771
|
basePositionRotationOrScale = (s ?? Vector3.One()).asArray();
|
|
@@ -644,12 +792,10 @@ export class _GLTFAnimation {
|
|
|
644
792
|
value = rotationQuaternion.asArray();
|
|
645
793
|
}
|
|
646
794
|
outputs.push(value); // scale vector.
|
|
647
|
-
}
|
|
648
|
-
else if (animationType === Animation.ANIMATIONTYPE_FLOAT) {
|
|
795
|
+
} else if (animationType === Animation.ANIMATIONTYPE_FLOAT) {
|
|
649
796
|
if (animationChannelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */) {
|
|
650
797
|
outputs.push([keyFrame.value]);
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
798
|
+
} else {
|
|
653
799
|
// handles single component x, y, z or w component animation by using a base property and animating over a component.
|
|
654
800
|
newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationChannelTargetPath, useQuaternion);
|
|
655
801
|
if (newPositionRotationOrScale) {
|
|
@@ -662,11 +808,9 @@ export class _GLTFAnimation {
|
|
|
662
808
|
outputs.push(newPositionRotationOrScale.asArray());
|
|
663
809
|
}
|
|
664
810
|
}
|
|
665
|
-
}
|
|
666
|
-
else if (animationType === Animation.ANIMATIONTYPE_QUATERNION) {
|
|
811
|
+
} else if (animationType === Animation.ANIMATIONTYPE_QUATERNION) {
|
|
667
812
|
outputs.push(keyFrame.value.normalize().asArray());
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
813
|
+
} else {
|
|
670
814
|
Tools.Error("glTFAnimation: Unsupported key frame values for animation!");
|
|
671
815
|
}
|
|
672
816
|
}
|
|
@@ -693,25 +837,23 @@ export class _GLTFAnimation {
|
|
|
693
837
|
shouldBakeAnimation = true;
|
|
694
838
|
break;
|
|
695
839
|
}
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
840
|
+
} else {
|
|
698
841
|
interpolationType = "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */;
|
|
699
842
|
}
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
843
|
+
} else {
|
|
702
844
|
if (interpolationType) {
|
|
703
|
-
if (
|
|
704
|
-
|
|
845
|
+
if (
|
|
846
|
+
interpolationType === "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */ ||
|
|
847
|
+
(key.interpolation && key.interpolation === 1 /* AnimationKeyInterpolation.STEP */ && interpolationType !== "STEP") /* AnimationSamplerInterpolation.STEP */
|
|
848
|
+
) {
|
|
705
849
|
interpolationType = "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
|
|
706
850
|
shouldBakeAnimation = true;
|
|
707
851
|
break;
|
|
708
852
|
}
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
853
|
+
} else {
|
|
711
854
|
if (key.interpolation && key.interpolation === 1 /* AnimationKeyInterpolation.STEP */) {
|
|
712
855
|
interpolationType = "STEP" /* AnimationSamplerInterpolation.STEP */;
|
|
713
|
-
}
|
|
714
|
-
else {
|
|
856
|
+
} else {
|
|
715
857
|
interpolationType = "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
|
|
716
858
|
}
|
|
717
859
|
}
|
|
@@ -740,29 +882,23 @@ export class _GLTFAnimation {
|
|
|
740
882
|
if (tangentValue) {
|
|
741
883
|
if (useQuaternion) {
|
|
742
884
|
tangent = tangentValue.asArray();
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
885
|
+
} else {
|
|
745
886
|
const array = tangentValue;
|
|
746
887
|
tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();
|
|
747
888
|
}
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
889
|
+
} else {
|
|
750
890
|
tangent = [0, 0, 0, 0];
|
|
751
891
|
}
|
|
752
|
-
}
|
|
753
|
-
else if (animationChannelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */) {
|
|
892
|
+
} else if (animationChannelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */) {
|
|
754
893
|
if (tangentValue) {
|
|
755
894
|
tangent = [tangentValue];
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
895
|
+
} else {
|
|
758
896
|
tangent = [0];
|
|
759
897
|
}
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
898
|
+
} else {
|
|
762
899
|
if (tangentValue) {
|
|
763
900
|
tangent = tangentValue.asArray();
|
|
764
|
-
}
|
|
765
|
-
else {
|
|
901
|
+
} else {
|
|
766
902
|
tangent = [0, 0, 0];
|
|
767
903
|
}
|
|
768
904
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onerjs/serializers",
|
|
3
|
-
"version": "8.23.
|
|
3
|
+
"version": "8.23.8",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@onerjs/core": "^8.23.
|
|
21
|
+
"@onerjs/core": "^8.23.8",
|
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
|
23
23
|
"@lts/serializers": "^1.0.0",
|
|
24
24
|
"babylonjs-gltf2interface": "^8.23.1"
|