@babylonjs/serializers 5.20.0 → 5.22.1
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/OBJ/objSerializer.js +35 -39
- package/OBJ/objSerializer.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +44 -52
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +49 -56
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +31 -38
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +18 -25
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +25 -32
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +24 -32
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +29 -37
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +29 -37
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +15 -22
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +31 -39
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +33 -42
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/glTFAnimation.js +171 -187
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFData.js +9 -11
- package/glTF/2.0/glTFData.js.map +1 -1
- package/glTF/2.0/glTFExporter.js +498 -544
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.js +385 -423
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFSerializer.js +20 -25
- package/glTF/2.0/glTFSerializer.js.map +1 -1
- package/glTF/2.0/glTFUtilities.js +45 -49
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/glTF/2.0/shaders/textureTransform.fragment.js +7 -3
- package/glTF/2.0/shaders/textureTransform.fragment.js.map +1 -1
- package/legacy/legacy-glTF2Serializer.js +16 -16
- package/legacy/legacy-glTF2Serializer.js.map +1 -1
- package/legacy/legacy-objSerializer.js +2 -2
- package/legacy/legacy-objSerializer.js.map +1 -1
- package/legacy/legacy-stlSerializer.js +2 -2
- package/legacy/legacy-stlSerializer.js.map +1 -1
- package/package.json +5 -8
- package/stl/stlSerializer.js +29 -38
- package/stl/stlSerializer.js.map +1 -1
@@ -28,17 +28,15 @@ var _TangentType;
|
|
28
28
|
* @hidden
|
29
29
|
* Utility class for generating glTF animation data from BabylonJS.
|
30
30
|
*/
|
31
|
-
|
32
|
-
function _GLTFAnimation() {
|
33
|
-
}
|
31
|
+
export class _GLTFAnimation {
|
34
32
|
/**
|
35
33
|
* Determine if a node is transformable - ie has properties it should be part of animation of transformation.
|
36
34
|
* @param babylonNode the node to test
|
37
35
|
* @returns true if can be animated, false otherwise. False if the parameter is null or undefined.
|
38
36
|
*/
|
39
|
-
|
37
|
+
static _IsTransformable(babylonNode) {
|
40
38
|
return babylonNode && (babylonNode instanceof TransformNode || babylonNode instanceof Camera || babylonNode instanceof Light);
|
41
|
-
}
|
39
|
+
}
|
42
40
|
/**
|
43
41
|
* @ignore
|
44
42
|
*
|
@@ -50,16 +48,16 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
50
48
|
* @param useQuaternion - Specifies if quaternions are used.
|
51
49
|
* @returns nullable IAnimationData
|
52
50
|
*/
|
53
|
-
|
51
|
+
static _CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
|
54
52
|
if (this._IsTransformable(babylonTransformNode)) {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
const inputs = [];
|
54
|
+
const outputs = [];
|
55
|
+
const keyFrames = animation.getKeys();
|
56
|
+
const minMaxKeyFrames = _GLTFAnimation._CalculateMinMaxKeyFrames(keyFrames);
|
57
|
+
const interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
|
58
|
+
const frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
|
59
|
+
const interpolation = interpolationOrBake.interpolationType;
|
60
|
+
const shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
|
63
61
|
if (shouldBakeAnimation) {
|
64
62
|
_GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
|
65
63
|
}
|
@@ -75,7 +73,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
75
73
|
}
|
76
74
|
}
|
77
75
|
if (inputs.length && outputs.length) {
|
78
|
-
|
76
|
+
const result = {
|
79
77
|
inputs: inputs,
|
80
78
|
outputs: outputs,
|
81
79
|
samplerInterpolation: interpolation,
|
@@ -86,12 +84,12 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
86
84
|
}
|
87
85
|
}
|
88
86
|
return null;
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
}
|
88
|
+
static _DeduceAnimationInfo(animation) {
|
89
|
+
let animationChannelTargetPath = null;
|
90
|
+
let dataAccessorType = "VEC3" /* VEC3 */;
|
91
|
+
let useQuaternion = false;
|
92
|
+
const property = animation.targetProperty.split(".");
|
95
93
|
switch (property[0]) {
|
96
94
|
case "scaling": {
|
97
95
|
animationChannelTargetPath = "scale" /* SCALE */;
|
@@ -118,7 +116,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
118
116
|
break;
|
119
117
|
}
|
120
118
|
default: {
|
121
|
-
Tools.Error(
|
119
|
+
Tools.Error(`Unsupported animatable property ${property[0]}`);
|
122
120
|
}
|
123
121
|
}
|
124
122
|
if (animationChannelTargetPath) {
|
@@ -128,7 +126,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
128
126
|
Tools.Error("animation channel target path and data accessor type could be deduced");
|
129
127
|
}
|
130
128
|
return null;
|
131
|
-
}
|
129
|
+
}
|
132
130
|
/**
|
133
131
|
* @ignore
|
134
132
|
* Create node animations from the transform node animations
|
@@ -143,20 +141,19 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
143
141
|
* @param convertToRightHandedSystem
|
144
142
|
* @param animationSampleRate
|
145
143
|
*/
|
146
|
-
|
147
|
-
|
144
|
+
static _CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
|
145
|
+
let glTFAnimation;
|
148
146
|
if (_GLTFAnimation._IsTransformable(babylonNode)) {
|
149
147
|
if (babylonNode.animations) {
|
150
|
-
for (
|
151
|
-
|
152
|
-
var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
|
148
|
+
for (const animation of babylonNode.animations) {
|
149
|
+
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
|
153
150
|
if (animationInfo) {
|
154
151
|
glTFAnimation = {
|
155
152
|
name: animation.name,
|
156
153
|
samplers: [],
|
157
154
|
channels: [],
|
158
155
|
};
|
159
|
-
_GLTFAnimation._AddAnimation(
|
156
|
+
_GLTFAnimation._AddAnimation(`${animation.name}`, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
|
160
157
|
if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
|
161
158
|
idleGLTFAnimations.push(glTFAnimation);
|
162
159
|
}
|
@@ -164,7 +161,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
164
161
|
}
|
165
162
|
}
|
166
163
|
}
|
167
|
-
}
|
164
|
+
}
|
168
165
|
/**
|
169
166
|
* @ignore
|
170
167
|
* Create individual morph animations from the mesh's morph target animation tracks
|
@@ -179,21 +176,20 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
179
176
|
* @param convertToRightHandedSystem
|
180
177
|
* @param animationSampleRate
|
181
178
|
*/
|
182
|
-
|
183
|
-
|
179
|
+
static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
|
180
|
+
let glTFAnimation;
|
184
181
|
if (babylonNode instanceof Mesh) {
|
185
|
-
|
182
|
+
const morphTargetManager = babylonNode.morphTargetManager;
|
186
183
|
if (morphTargetManager) {
|
187
|
-
for (
|
188
|
-
|
189
|
-
for (
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
for (var k = 0; k < morphTargetManager.numTargets; ++k) {
|
184
|
+
for (let i = 0; i < morphTargetManager.numTargets; ++i) {
|
185
|
+
const morphTarget = morphTargetManager.getTarget(i);
|
186
|
+
for (const animation of morphTarget.animations) {
|
187
|
+
const combinedAnimation = new Animation(`${animation.name}`, "influence", animation.framePerSecond, animation.dataType, animation.loopMode, animation.enableBlending);
|
188
|
+
const combinedAnimationKeys = [];
|
189
|
+
const animationKeys = animation.getKeys();
|
190
|
+
for (let j = 0; j < animationKeys.length; ++j) {
|
191
|
+
const animationKey = animationKeys[j];
|
192
|
+
for (let k = 0; k < morphTargetManager.numTargets; ++k) {
|
197
193
|
if (k == i) {
|
198
194
|
combinedAnimationKeys.push(animationKey);
|
199
195
|
}
|
@@ -203,7 +199,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
203
199
|
}
|
204
200
|
}
|
205
201
|
combinedAnimation.setKeys(combinedAnimationKeys);
|
206
|
-
|
202
|
+
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimation);
|
207
203
|
if (animationInfo) {
|
208
204
|
glTFAnimation = {
|
209
205
|
name: combinedAnimation.name,
|
@@ -219,7 +215,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
219
215
|
}
|
220
216
|
}
|
221
217
|
}
|
222
|
-
}
|
218
|
+
}
|
223
219
|
/**
|
224
220
|
* @ignore
|
225
221
|
* Create node and morph animations from the animation groups
|
@@ -233,57 +229,56 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
233
229
|
* @param convertToRightHandedSystemMap
|
234
230
|
* @param animationSampleRate
|
235
231
|
*/
|
236
|
-
|
237
|
-
|
238
|
-
var glTFAnimation;
|
232
|
+
static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene, glTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystemMap, animationSampleRate) {
|
233
|
+
let glTFAnimation;
|
239
234
|
if (babylonScene.animationGroups) {
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
235
|
+
const animationGroups = babylonScene.animationGroups;
|
236
|
+
for (const animationGroup of animationGroups) {
|
237
|
+
const morphAnimations = new Map();
|
238
|
+
const sampleAnimations = new Map();
|
239
|
+
const morphAnimationMeshes = new Set();
|
240
|
+
const animationGroupFrameDiff = animationGroup.to - animationGroup.from;
|
246
241
|
glTFAnimation = {
|
247
242
|
name: animationGroup.name,
|
248
243
|
channels: [],
|
249
244
|
samplers: [],
|
250
245
|
};
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
if (
|
256
|
-
|
246
|
+
for (let i = 0; i < animationGroup.targetedAnimations.length; ++i) {
|
247
|
+
const targetAnimation = animationGroup.targetedAnimations[i];
|
248
|
+
const target = targetAnimation.target;
|
249
|
+
const animation = targetAnimation.animation;
|
250
|
+
if (this._IsTransformable(target) || (target.length === 1 && this._IsTransformable(target[0]))) {
|
251
|
+
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
|
257
252
|
if (animationInfo) {
|
258
|
-
|
253
|
+
const babylonTransformNode = this._IsTransformable(target) ? target : this._IsTransformable(target[0]) ? target[0] : null;
|
259
254
|
if (babylonTransformNode) {
|
260
|
-
|
261
|
-
_GLTFAnimation._AddAnimation(
|
255
|
+
const convertToRightHandedSystem = convertToRightHandedSystemMap[babylonTransformNode.uniqueId];
|
256
|
+
_GLTFAnimation._AddAnimation(`${animation.name}`, glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
|
262
257
|
}
|
263
258
|
}
|
264
259
|
}
|
265
260
|
else if (target instanceof MorphTarget || (target.length === 1 && target[0] instanceof MorphTarget)) {
|
266
|
-
|
261
|
+
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
|
267
262
|
if (animationInfo) {
|
268
|
-
|
269
|
-
if (
|
270
|
-
|
271
|
-
for (
|
272
|
-
if (morphTargetManager.getTarget(j) ===
|
263
|
+
const babylonMorphTarget = target instanceof MorphTarget ? target : target[0];
|
264
|
+
if (babylonMorphTarget) {
|
265
|
+
const babylonMorphTargetManager = babylonScene.morphTargetManagers.find((morphTargetManager) => {
|
266
|
+
for (let j = 0; j < morphTargetManager.numTargets; ++j) {
|
267
|
+
if (morphTargetManager.getTarget(j) === babylonMorphTarget) {
|
273
268
|
return true;
|
274
269
|
}
|
275
270
|
}
|
276
271
|
return false;
|
277
272
|
});
|
278
|
-
if (
|
279
|
-
|
280
|
-
return mesh.morphTargetManager ===
|
273
|
+
if (babylonMorphTargetManager) {
|
274
|
+
const babylonMesh = babylonScene.meshes.find((mesh) => {
|
275
|
+
return mesh.morphTargetManager === babylonMorphTargetManager;
|
281
276
|
});
|
282
277
|
if (babylonMesh) {
|
283
278
|
if (!morphAnimations.has(babylonMesh)) {
|
284
279
|
morphAnimations.set(babylonMesh, new Map());
|
285
280
|
}
|
286
|
-
|
281
|
+
morphAnimations.get(babylonMesh)?.set(babylonMorphTarget, animation);
|
287
282
|
morphAnimationMeshes.add(babylonMesh);
|
288
283
|
sampleAnimations.set(babylonMesh, animation);
|
289
284
|
}
|
@@ -294,17 +289,14 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
294
289
|
else {
|
295
290
|
// this is the place for the KHR_animation_pointer.
|
296
291
|
}
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
var sampleAnimation = sampleAnimations.get(mesh);
|
306
|
-
var sampleAnimationKeys = sampleAnimation.getKeys();
|
307
|
-
var numAnimationKeys = sampleAnimationKeys.length;
|
292
|
+
}
|
293
|
+
morphAnimationMeshes.forEach((mesh) => {
|
294
|
+
const morphTargetManager = mesh.morphTargetManager;
|
295
|
+
let combinedAnimationGroup = null;
|
296
|
+
const animationKeys = [];
|
297
|
+
const sampleAnimation = sampleAnimations.get(mesh);
|
298
|
+
const sampleAnimationKeys = sampleAnimation.getKeys();
|
299
|
+
const numAnimationKeys = sampleAnimationKeys.length;
|
308
300
|
/*
|
309
301
|
Due to how glTF expects morph target animation data to be formatted, we need to rearrange the individual morph target animation tracks,
|
310
302
|
such that we have a single animation, where a given keyframe input value has successive output values for each morph target belonging to the manager.
|
@@ -314,15 +306,15 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
314
306
|
We reuse the Babylon Animation data structure for ease of handling export of cubic spline animation keys, and to reuse the
|
315
307
|
existing _GLTFAnimation.AddAnimation codepath with minimal modification, however the constructed Babylon Animation is NOT intended for use in-engine.
|
316
308
|
*/
|
317
|
-
for (
|
318
|
-
for (
|
319
|
-
|
320
|
-
|
309
|
+
for (let i = 0; i < numAnimationKeys; ++i) {
|
310
|
+
for (let j = 0; j < morphTargetManager.numTargets; ++j) {
|
311
|
+
const morphTarget = morphTargetManager.getTarget(j);
|
312
|
+
const animationsByMorphTarget = morphAnimations.get(mesh);
|
321
313
|
if (animationsByMorphTarget) {
|
322
|
-
|
314
|
+
const morphTargetAnimation = animationsByMorphTarget.get(morphTarget);
|
323
315
|
if (morphTargetAnimation) {
|
324
316
|
if (!combinedAnimationGroup) {
|
325
|
-
combinedAnimationGroup = new Animation(
|
317
|
+
combinedAnimationGroup = new Animation(`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`, "influence", morphTargetAnimation.framePerSecond, Animation.ANIMATIONTYPE_FLOAT, morphTargetAnimation.loopMode, morphTargetAnimation.enableBlending);
|
326
318
|
}
|
327
319
|
animationKeys.push(morphTargetAnimation.getKeys()[i]);
|
328
320
|
}
|
@@ -338,31 +330,26 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
338
330
|
}
|
339
331
|
}
|
340
332
|
combinedAnimationGroup.setKeys(animationKeys);
|
341
|
-
|
333
|
+
const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup);
|
342
334
|
if (animationInfo) {
|
343
|
-
_GLTFAnimation._AddAnimation(
|
335
|
+
_GLTFAnimation._AddAnimation(`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`, glTFAnimation, mesh, combinedAnimationGroup, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, false, animationInfo.useQuaternion, animationSampleRate, morphTargetManager?.numTargets);
|
344
336
|
}
|
345
337
|
});
|
346
338
|
if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
|
347
339
|
glTFAnimations.push(glTFAnimation);
|
348
340
|
}
|
349
|
-
};
|
350
|
-
var this_1 = this;
|
351
|
-
for (var _i = 0, animationGroups_1 = animationGroups; _i < animationGroups_1.length; _i++) {
|
352
|
-
var animationGroup = animationGroups_1[_i];
|
353
|
-
_loop_1(animationGroup);
|
354
341
|
}
|
355
342
|
}
|
356
|
-
}
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
343
|
+
}
|
344
|
+
static _AddAnimation(name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate, morphAnimationChannels) {
|
345
|
+
const animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate);
|
346
|
+
let bufferView;
|
347
|
+
let accessor;
|
348
|
+
let keyframeAccessorIndex;
|
349
|
+
let dataAccessorIndex;
|
350
|
+
let outputLength;
|
351
|
+
let animationSampler;
|
352
|
+
let animationChannel;
|
366
353
|
if (animationData) {
|
367
354
|
/*
|
368
355
|
* Now that we have the glTF converted morph target animation data,
|
@@ -370,9 +357,9 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
370
357
|
* and morphAnimationChannels * n output frames
|
371
358
|
*/
|
372
359
|
if (morphAnimationChannels) {
|
373
|
-
|
374
|
-
|
375
|
-
|
360
|
+
let index = 0;
|
361
|
+
let currentInput = 0;
|
362
|
+
const newInputs = [];
|
376
363
|
while (animationData.inputs.length > 0) {
|
377
364
|
currentInput = animationData.inputs.shift();
|
378
365
|
if (index % morphAnimationChannels == 0) {
|
@@ -382,29 +369,29 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
382
369
|
}
|
383
370
|
animationData.inputs = newInputs;
|
384
371
|
}
|
385
|
-
|
372
|
+
const nodeIndex = nodeMap[babylonTransformNode.uniqueId];
|
386
373
|
// Creates buffer view and accessor for key frames.
|
387
|
-
|
388
|
-
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined,
|
374
|
+
let byteLength = animationData.inputs.length * 4;
|
375
|
+
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} keyframe data view`);
|
389
376
|
bufferViews.push(bufferView);
|
390
377
|
animationData.inputs.forEach(function (input) {
|
391
378
|
binaryWriter.setFloat32(input);
|
392
379
|
});
|
393
|
-
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1,
|
380
|
+
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} keyframes`, "SCALAR" /* SCALAR */, 5126 /* FLOAT */, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
|
394
381
|
accessors.push(accessor);
|
395
382
|
keyframeAccessorIndex = accessors.length - 1;
|
396
383
|
// create bufferview and accessor for keyed values.
|
397
384
|
outputLength = animationData.outputs.length;
|
398
385
|
byteLength = _GLTFUtilities._GetDataAccessorElementCount(dataAccessorType) * 4 * animationData.outputs.length;
|
399
386
|
// check for in and out tangents
|
400
|
-
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined,
|
387
|
+
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} data view`);
|
401
388
|
bufferViews.push(bufferView);
|
402
389
|
animationData.outputs.forEach(function (output) {
|
403
390
|
output.forEach(function (entry) {
|
404
391
|
binaryWriter.setFloat32(entry);
|
405
392
|
});
|
406
393
|
});
|
407
|
-
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1,
|
394
|
+
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} data`, dataAccessorType, 5126 /* FLOAT */, outputLength, null, null, null);
|
408
395
|
accessors.push(accessor);
|
409
396
|
dataAccessorIndex = accessors.length - 1;
|
410
397
|
// create sampler
|
@@ -424,7 +411,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
424
411
|
};
|
425
412
|
glTFAnimation.channels.push(animationChannel);
|
426
413
|
}
|
427
|
-
}
|
414
|
+
}
|
428
415
|
/**
|
429
416
|
* Create a baked animation
|
430
417
|
* @param babylonTransformNode BabylonJS mesh
|
@@ -442,22 +429,22 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
442
429
|
* @param convertToRightHandedSystem converts the values to right-handed
|
443
430
|
* @param useQuaternion specifies if quaternions should be used
|
444
431
|
*/
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
432
|
+
static _CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion) {
|
433
|
+
let value;
|
434
|
+
const quaternionCache = Quaternion.Identity();
|
435
|
+
let previousTime = null;
|
436
|
+
let time;
|
437
|
+
let maxUsedFrame = null;
|
438
|
+
let currKeyFrame = null;
|
439
|
+
let nextKeyFrame = null;
|
440
|
+
let prevKeyFrame = null;
|
441
|
+
let endFrame = null;
|
455
442
|
minMaxFrames.min = Tools.FloatRound(minFrame / fps);
|
456
|
-
|
457
|
-
for (
|
443
|
+
const keyFrames = animation.getKeys();
|
444
|
+
for (let i = 0, length = keyFrames.length; i < length; ++i) {
|
458
445
|
endFrame = null;
|
459
446
|
currKeyFrame = keyFrames[i];
|
460
|
-
if (i + 1 <
|
447
|
+
if (i + 1 < length) {
|
461
448
|
nextKeyFrame = keyFrames[i + 1];
|
462
449
|
if ((currKeyFrame.value.equals && currKeyFrame.value.equals(nextKeyFrame.value)) || currKeyFrame.value === nextKeyFrame.value) {
|
463
450
|
if (i === 0) {
|
@@ -483,14 +470,14 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
483
470
|
}
|
484
471
|
}
|
485
472
|
if (endFrame) {
|
486
|
-
for (
|
473
|
+
for (let f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {
|
487
474
|
time = Tools.FloatRound(f / fps);
|
488
475
|
if (time === previousTime) {
|
489
476
|
continue;
|
490
477
|
}
|
491
478
|
previousTime = time;
|
492
479
|
maxUsedFrame = time;
|
493
|
-
|
480
|
+
const state = {
|
494
481
|
key: 0,
|
495
482
|
repeatCount: 0,
|
496
483
|
loopMode: animation.loopMode,
|
@@ -503,12 +490,12 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
503
490
|
if (maxUsedFrame) {
|
504
491
|
minMaxFrames.max = maxUsedFrame;
|
505
492
|
}
|
506
|
-
}
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
493
|
+
}
|
494
|
+
static _ConvertFactorToVector3OrQuaternion(factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
|
495
|
+
let property;
|
496
|
+
let componentName;
|
497
|
+
let value = null;
|
498
|
+
const basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
|
512
499
|
if (animationType === Animation.ANIMATIONTYPE_FLOAT) {
|
513
500
|
// handles single component x, y, z or w component animation by using a base property and animating over a component.
|
514
501
|
property = animation.targetProperty.split(".");
|
@@ -532,15 +519,15 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
532
519
|
break;
|
533
520
|
}
|
534
521
|
default: {
|
535
|
-
Tools.Error(
|
522
|
+
Tools.Error(`glTFAnimation: Unsupported component type "${componentName}" for scale animation!`);
|
536
523
|
}
|
537
524
|
}
|
538
525
|
}
|
539
526
|
return value;
|
540
|
-
}
|
541
|
-
|
542
|
-
|
543
|
-
|
527
|
+
}
|
528
|
+
static _SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
|
529
|
+
const animationType = animation.dataType;
|
530
|
+
let cacheValue;
|
544
531
|
inputs.push(time);
|
545
532
|
if (value) {
|
546
533
|
if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
|
@@ -579,7 +566,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
579
566
|
outputs.push(cacheValue.asArray());
|
580
567
|
}
|
581
568
|
}
|
582
|
-
}
|
569
|
+
}
|
583
570
|
/**
|
584
571
|
* Creates linear animation from the animation key frames
|
585
572
|
* @param babylonTransformNode BabylonJS mesh
|
@@ -591,13 +578,12 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
591
578
|
* @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
|
592
579
|
* @param useQuaternion Specifies if quaternions are used in the animation
|
593
580
|
*/
|
594
|
-
|
595
|
-
for (
|
596
|
-
var keyFrame = _a[_i];
|
581
|
+
static _CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
|
582
|
+
for (const keyFrame of animation.getKeys()) {
|
597
583
|
inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
|
598
584
|
_GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
|
599
585
|
}
|
600
|
-
}
|
586
|
+
}
|
601
587
|
/**
|
602
588
|
* Creates cubic spline animation from the animation key frames
|
603
589
|
* @param babylonTransformNode BabylonJS mesh
|
@@ -609,20 +595,20 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
609
595
|
* @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
|
610
596
|
* @param useQuaternion Specifies if quaternions are used in the animation
|
611
597
|
*/
|
612
|
-
|
598
|
+
static _CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
|
613
599
|
animation.getKeys().forEach(function (keyFrame) {
|
614
600
|
inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
|
615
601
|
_GLTFAnimation._AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
|
616
602
|
_GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
|
617
603
|
_GLTFAnimation._AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
|
618
604
|
});
|
619
|
-
}
|
620
|
-
|
621
|
-
|
605
|
+
}
|
606
|
+
static _GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
|
607
|
+
let basePositionRotationOrScale;
|
622
608
|
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
623
609
|
if (useQuaternion) {
|
624
|
-
|
625
|
-
basePositionRotationOrScale = (q
|
610
|
+
const q = babylonTransformNode.rotationQuaternion;
|
611
|
+
basePositionRotationOrScale = (q ?? Quaternion.Identity()).asArray();
|
626
612
|
if (convertToRightHandedSystem) {
|
627
613
|
_GLTFUtilities._GetRightHandedQuaternionArrayFromRef(basePositionRotationOrScale);
|
628
614
|
if (!babylonTransformNode.parent) {
|
@@ -631,25 +617,25 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
631
617
|
}
|
632
618
|
}
|
633
619
|
else {
|
634
|
-
|
635
|
-
basePositionRotationOrScale = (r
|
620
|
+
const r = babylonTransformNode.rotation;
|
621
|
+
basePositionRotationOrScale = (r ?? Vector3.Zero()).asArray();
|
636
622
|
_GLTFUtilities._GetRightHandedNormalArray3FromRef(basePositionRotationOrScale);
|
637
623
|
}
|
638
624
|
}
|
639
625
|
else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
|
640
|
-
|
641
|
-
basePositionRotationOrScale = (p
|
626
|
+
const p = babylonTransformNode.position;
|
627
|
+
basePositionRotationOrScale = (p ?? Vector3.Zero()).asArray();
|
642
628
|
if (convertToRightHandedSystem) {
|
643
629
|
_GLTFUtilities._GetRightHandedPositionArray3FromRef(basePositionRotationOrScale);
|
644
630
|
}
|
645
631
|
}
|
646
632
|
else {
|
647
633
|
// scale
|
648
|
-
|
649
|
-
basePositionRotationOrScale = (s
|
634
|
+
const s = babylonTransformNode.scaling;
|
635
|
+
basePositionRotationOrScale = (s ?? Vector3.One()).asArray();
|
650
636
|
}
|
651
637
|
return basePositionRotationOrScale;
|
652
|
-
}
|
638
|
+
}
|
653
639
|
/**
|
654
640
|
* Adds a key frame value
|
655
641
|
* @param keyFrame
|
@@ -660,15 +646,15 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
660
646
|
* @param convertToRightHandedSystem
|
661
647
|
* @param useQuaternion
|
662
648
|
*/
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
649
|
+
static _AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion) {
|
650
|
+
let value;
|
651
|
+
let newPositionRotationOrScale;
|
652
|
+
const animationType = animation.dataType;
|
667
653
|
if (animationType === Animation.ANIMATIONTYPE_VECTOR3) {
|
668
654
|
value = keyFrame.value.asArray();
|
669
655
|
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
670
|
-
|
671
|
-
|
656
|
+
const array = Vector3.FromArray(value);
|
657
|
+
let rotationQuaternion = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z);
|
672
658
|
if (convertToRightHandedSystem) {
|
673
659
|
_GLTFUtilities._GetRightHandedQuaternionFromRef(rotationQuaternion);
|
674
660
|
if (!babylonTransformNode.parent) {
|
@@ -697,7 +683,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
697
683
|
newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
|
698
684
|
if (newPositionRotationOrScale) {
|
699
685
|
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
700
|
-
|
686
|
+
let posRotScale = useQuaternion
|
701
687
|
? newPositionRotationOrScale
|
702
688
|
: Quaternion.RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();
|
703
689
|
if (convertToRightHandedSystem) {
|
@@ -734,21 +720,21 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
734
720
|
else {
|
735
721
|
Tools.Error("glTFAnimation: Unsupported key frame values for animation!");
|
736
722
|
}
|
737
|
-
}
|
723
|
+
}
|
738
724
|
/**
|
739
725
|
* Determine the interpolation based on the key frames
|
740
726
|
* @param keyFrames
|
741
727
|
* @param animationChannelTargetPath
|
742
728
|
* @param useQuaternion
|
743
729
|
*/
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
730
|
+
static _DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion) {
|
731
|
+
let interpolationType;
|
732
|
+
let shouldBakeAnimation = false;
|
733
|
+
let key;
|
748
734
|
if (animationChannelTargetPath === "rotation" /* ROTATION */ && !useQuaternion) {
|
749
735
|
return { interpolationType: "LINEAR" /* LINEAR */, shouldBakeAnimation: true };
|
750
736
|
}
|
751
|
-
for (
|
737
|
+
for (let i = 0, length = keyFrames.length; i < length; ++i) {
|
752
738
|
key = keyFrames[i];
|
753
739
|
if (key.inTangent || key.outTangent) {
|
754
740
|
if (interpolationType) {
|
@@ -785,7 +771,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
785
771
|
interpolationType = "LINEAR" /* LINEAR */;
|
786
772
|
}
|
787
773
|
return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
|
788
|
-
}
|
774
|
+
}
|
789
775
|
/**
|
790
776
|
* Adds an input tangent or output tangent to the output data
|
791
777
|
* If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
|
@@ -799,9 +785,9 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
799
785
|
* @param useQuaternion Specifies if quaternions are used
|
800
786
|
* @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
|
801
787
|
*/
|
802
|
-
|
803
|
-
|
804
|
-
|
788
|
+
static _AddSplineTangent(babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem) {
|
789
|
+
let tangent;
|
790
|
+
const tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
|
805
791
|
if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
|
806
792
|
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
807
793
|
if (tangentValue) {
|
@@ -809,7 +795,7 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
809
795
|
tangent = tangentValue.asArray();
|
810
796
|
}
|
811
797
|
else {
|
812
|
-
|
798
|
+
const array = tangentValue;
|
813
799
|
tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();
|
814
800
|
}
|
815
801
|
if (convertToRightHandedSystem) {
|
@@ -850,22 +836,20 @@ var _GLTFAnimation = /** @class */ (function () {
|
|
850
836
|
}
|
851
837
|
outputs.push(tangent);
|
852
838
|
}
|
853
|
-
}
|
839
|
+
}
|
854
840
|
/**
|
855
841
|
* Get the minimum and maximum key frames' frame values
|
856
842
|
* @param keyFrames animation key frames
|
857
843
|
* @returns the minimum and maximum key frame value
|
858
844
|
*/
|
859
|
-
|
860
|
-
|
861
|
-
|
845
|
+
static _CalculateMinMaxKeyFrames(keyFrames) {
|
846
|
+
let min = Infinity;
|
847
|
+
let max = -Infinity;
|
862
848
|
keyFrames.forEach(function (keyFrame) {
|
863
849
|
min = Math.min(min, keyFrame.frame);
|
864
850
|
max = Math.max(max, keyFrame.frame);
|
865
851
|
});
|
866
852
|
return { min: min, max: max };
|
867
|
-
}
|
868
|
-
|
869
|
-
}());
|
870
|
-
export { _GLTFAnimation };
|
853
|
+
}
|
854
|
+
}
|
871
855
|
//# sourceMappingURL=glTFAnimation.js.map
|