@babylonjs/serializers 5.0.0-beta.8 → 5.0.0-beta.8-snapshot

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 (79) hide show
  1. package/package.json +20 -105
  2. package/OBJ/index.d.ts +0 -1
  3. package/OBJ/index.js +0 -2
  4. package/OBJ/index.js.map +0 -1
  5. package/OBJ/objSerializer.d.ts +0 -21
  6. package/OBJ/objSerializer.js +0 -160
  7. package/OBJ/objSerializer.js.map +0 -1
  8. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +0 -38
  9. package/glTF/2.0/Extensions/KHR_lights_punctual.js +0 -174
  10. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +0 -1
  11. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +0 -24
  12. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +0 -91
  13. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +0 -1
  14. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -24
  15. package/glTF/2.0/Extensions/KHR_materials_sheen.js +0 -74
  16. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +0 -1
  17. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +0 -21
  18. package/glTF/2.0/Extensions/KHR_materials_unlit.js +0 -52
  19. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +0 -1
  20. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +0 -34
  21. package/glTF/2.0/Extensions/KHR_texture_transform.js +0 -137
  22. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +0 -1
  23. package/glTF/2.0/Extensions/index.d.ts +0 -5
  24. package/glTF/2.0/Extensions/index.js +0 -6
  25. package/glTF/2.0/Extensions/index.js.map +0 -1
  26. package/glTF/2.0/glTFAnimation.d.ts +0 -200
  27. package/glTF/2.0/glTFAnimation.js +0 -840
  28. package/glTF/2.0/glTFAnimation.js.map +0 -1
  29. package/glTF/2.0/glTFData.d.ts +0 -19
  30. package/glTF/2.0/glTFData.js +0 -53
  31. package/glTF/2.0/glTFData.js.map +0 -1
  32. package/glTF/2.0/glTFExporter.d.ts +0 -445
  33. package/glTF/2.0/glTFExporter.js +0 -1943
  34. package/glTF/2.0/glTFExporter.js.map +0 -1
  35. package/glTF/2.0/glTFExporterExtension.d.ts +0 -74
  36. package/glTF/2.0/glTFExporterExtension.js +0 -3
  37. package/glTF/2.0/glTFExporterExtension.js.map +0 -1
  38. package/glTF/2.0/glTFMaterialExporter.d.ts +0 -230
  39. package/glTF/2.0/glTFMaterialExporter.js +0 -1143
  40. package/glTF/2.0/glTFMaterialExporter.js.map +0 -1
  41. package/glTF/2.0/glTFSerializer.d.ts +0 -60
  42. package/glTF/2.0/glTFSerializer.js +0 -63
  43. package/glTF/2.0/glTFSerializer.js.map +0 -1
  44. package/glTF/2.0/glTFUtilities.d.ts +0 -96
  45. package/glTF/2.0/glTFUtilities.js +0 -196
  46. package/glTF/2.0/glTFUtilities.js.map +0 -1
  47. package/glTF/2.0/index.d.ts +0 -8
  48. package/glTF/2.0/index.js +0 -9
  49. package/glTF/2.0/index.js.map +0 -1
  50. package/glTF/2.0/shaders/textureTransform.fragment.d.ts +0 -5
  51. package/glTF/2.0/shaders/textureTransform.fragment.js +0 -7
  52. package/glTF/2.0/shaders/textureTransform.fragment.js.map +0 -1
  53. package/glTF/glTFFileExporter.d.ts +0 -20
  54. package/glTF/glTFFileExporter.js +0 -3
  55. package/glTF/glTFFileExporter.js.map +0 -1
  56. package/glTF/index.d.ts +0 -2
  57. package/glTF/index.js +0 -3
  58. package/glTF/index.js.map +0 -1
  59. package/index.d.ts +0 -3
  60. package/index.js.map +0 -1
  61. package/legacy/legacy-glTF2Serializer.d.ts +0 -2
  62. package/legacy/legacy-glTF2Serializer.js +0 -44
  63. package/legacy/legacy-glTF2Serializer.js.map +0 -1
  64. package/legacy/legacy-objSerializer.d.ts +0 -1
  65. package/legacy/legacy-objSerializer.js +0 -13
  66. package/legacy/legacy-objSerializer.js.map +0 -1
  67. package/legacy/legacy-stlSerializer.d.ts +0 -1
  68. package/legacy/legacy-stlSerializer.js +0 -13
  69. package/legacy/legacy-stlSerializer.js.map +0 -1
  70. package/legacy/legacy.d.ts +0 -4
  71. package/legacy/legacy.js +0 -5
  72. package/legacy/legacy.js.map +0 -1
  73. package/readme.md +0 -29
  74. package/stl/index.d.ts +0 -1
  75. package/stl/index.js +0 -2
  76. package/stl/index.js.map +0 -1
  77. package/stl/stlSerializer.d.ts +0 -17
  78. package/stl/stlSerializer.js +0 -108
  79. package/stl/stlSerializer.js.map +0 -1
@@ -1,840 +0,0 @@
1
- import { Vector3, Quaternion } from "@babylonjs/core/Maths/math.vector.js";
2
- import { Tools } from "@babylonjs/core/Misc/tools.js";
3
- import { Animation } from "@babylonjs/core/Animations/animation.js";
4
- import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
5
- import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
6
- import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
7
- import { _GLTFUtilities } from "./glTFUtilities.js";
8
- import { AnimationKeyInterpolation } from '@babylonjs/core/Animations/animationKey.js';
9
- /**
10
- * @hidden
11
- * Enum for handling in tangent and out tangent.
12
- */
13
- var _TangentType;
14
- (function (_TangentType) {
15
- /**
16
- * Specifies that input tangents are used.
17
- */
18
- _TangentType[_TangentType["INTANGENT"] = 0] = "INTANGENT";
19
- /**
20
- * Specifies that output tangents are used.
21
- */
22
- _TangentType[_TangentType["OUTTANGENT"] = 1] = "OUTTANGENT";
23
- })(_TangentType || (_TangentType = {}));
24
- /**
25
- * @hidden
26
- * Utility class for generating glTF animation data from BabylonJS.
27
- */
28
- var _GLTFAnimation = /** @class */ (function () {
29
- function _GLTFAnimation() {
30
- }
31
- /**
32
- * @ignore
33
- *
34
- * Creates glTF channel animation from BabylonJS animation.
35
- * @param babylonTransformNode - BabylonJS mesh.
36
- * @param animation - animation.
37
- * @param animationChannelTargetPath - The target animation channel.
38
- * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
39
- * @param useQuaternion - Specifies if quaternions are used.
40
- * @returns nullable IAnimationData
41
- */
42
- _GLTFAnimation._CreateNodeAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
43
- var inputs = [];
44
- var outputs = [];
45
- var keyFrames = animation.getKeys();
46
- var minMaxKeyFrames = _GLTFAnimation.calculateMinMaxKeyFrames(keyFrames);
47
- var interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
48
- var frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
49
- var interpolation = interpolationOrBake.interpolationType;
50
- var shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
51
- if (shouldBakeAnimation) {
52
- _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
53
- }
54
- else {
55
- if (interpolation === "LINEAR" /* LINEAR */ || interpolation === "STEP" /* STEP */) {
56
- _GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
57
- }
58
- else if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
59
- _GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
60
- }
61
- else {
62
- _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
63
- }
64
- }
65
- if (inputs.length && outputs.length) {
66
- var result = {
67
- inputs: inputs,
68
- outputs: outputs,
69
- samplerInterpolation: interpolation,
70
- inputsMin: shouldBakeAnimation ? minMaxKeyFrames.min : Tools.FloatRound(minMaxKeyFrames.min / animation.framePerSecond),
71
- inputsMax: shouldBakeAnimation ? minMaxKeyFrames.max : Tools.FloatRound(minMaxKeyFrames.max / animation.framePerSecond)
72
- };
73
- return result;
74
- }
75
- return null;
76
- };
77
- _GLTFAnimation._DeduceAnimationInfo = function (animation) {
78
- var animationChannelTargetPath = null;
79
- var dataAccessorType = "VEC3" /* VEC3 */;
80
- var useQuaternion = false;
81
- var property = animation.targetProperty.split('.');
82
- switch (property[0]) {
83
- case 'scaling': {
84
- animationChannelTargetPath = "scale" /* SCALE */;
85
- break;
86
- }
87
- case 'position': {
88
- animationChannelTargetPath = "translation" /* TRANSLATION */;
89
- break;
90
- }
91
- case 'rotation': {
92
- dataAccessorType = "VEC4" /* VEC4 */;
93
- animationChannelTargetPath = "rotation" /* ROTATION */;
94
- break;
95
- }
96
- case 'rotationQuaternion': {
97
- dataAccessorType = "VEC4" /* VEC4 */;
98
- useQuaternion = true;
99
- animationChannelTargetPath = "rotation" /* ROTATION */;
100
- break;
101
- }
102
- case 'influence': {
103
- dataAccessorType = "SCALAR" /* SCALAR */;
104
- animationChannelTargetPath = "weights" /* WEIGHTS */;
105
- break;
106
- }
107
- default: {
108
- Tools.Error("Unsupported animatable property ".concat(property[0]));
109
- }
110
- }
111
- if (animationChannelTargetPath) {
112
- return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
113
- }
114
- else {
115
- Tools.Error('animation channel target path and data accessor type could be deduced');
116
- }
117
- return null;
118
- };
119
- /**
120
- * @ignore
121
- * Create node animations from the transform node animations
122
- * @param babylonNode
123
- * @param runtimeGLTFAnimation
124
- * @param idleGLTFAnimations
125
- * @param nodeMap
126
- * @param nodes
127
- * @param binaryWriter
128
- * @param bufferViews
129
- * @param accessors
130
- * @param convertToRightHandedSystem
131
- * @param animationSampleRate
132
- */
133
- _GLTFAnimation._CreateNodeAnimationFromNodeAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
134
- var glTFAnimation;
135
- if (babylonNode instanceof TransformNode) {
136
- if (babylonNode.animations) {
137
- for (var _i = 0, _a = babylonNode.animations; _i < _a.length; _i++) {
138
- var animation = _a[_i];
139
- var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
140
- if (animationInfo) {
141
- glTFAnimation = {
142
- name: animation.name,
143
- samplers: [],
144
- channels: []
145
- };
146
- _GLTFAnimation.AddAnimation("".concat(animation.name), animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
147
- if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
148
- idleGLTFAnimations.push(glTFAnimation);
149
- }
150
- }
151
- }
152
- }
153
- }
154
- };
155
- /**
156
- * @ignore
157
- * Create individual morph animations from the mesh's morph target animation tracks
158
- * @param babylonNode
159
- * @param runtimeGLTFAnimation
160
- * @param idleGLTFAnimations
161
- * @param nodeMap
162
- * @param nodes
163
- * @param binaryWriter
164
- * @param bufferViews
165
- * @param accessors
166
- * @param convertToRightHandedSystem
167
- * @param animationSampleRate
168
- */
169
- _GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
170
- var glTFAnimation;
171
- if (babylonNode instanceof Mesh) {
172
- var morphTargetManager = babylonNode.morphTargetManager;
173
- if (morphTargetManager) {
174
- for (var i = 0; i < morphTargetManager.numTargets; ++i) {
175
- var morphTarget = morphTargetManager.getTarget(i);
176
- for (var _i = 0, _a = morphTarget.animations; _i < _a.length; _i++) {
177
- var animation = _a[_i];
178
- var combinedAnimation = new Animation("".concat(animation.name), "influence", animation.framePerSecond, animation.dataType, animation.loopMode, animation.enableBlending);
179
- var combinedAnimationKeys = [];
180
- var animationKeys = animation.getKeys();
181
- for (var j = 0; j < animationKeys.length; ++j) {
182
- var animationKey = animationKeys[j];
183
- for (var k = 0; k < morphTargetManager.numTargets; ++k) {
184
- if (k == i) {
185
- combinedAnimationKeys.push(animationKey);
186
- }
187
- else {
188
- combinedAnimationKeys.push({ frame: animationKey.frame, value: 0 });
189
- }
190
- }
191
- }
192
- combinedAnimation.setKeys(combinedAnimationKeys);
193
- var animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimation);
194
- if (animationInfo) {
195
- glTFAnimation = {
196
- name: combinedAnimation.name,
197
- samplers: [],
198
- channels: []
199
- };
200
- _GLTFAnimation.AddAnimation(animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, combinedAnimation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate, morphTargetManager.numTargets);
201
- if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
202
- idleGLTFAnimations.push(glTFAnimation);
203
- }
204
- }
205
- }
206
- }
207
- }
208
- }
209
- };
210
- /**
211
- * @ignore
212
- * Create node and morph animations from the animation groups
213
- * @param babylonScene
214
- * @param glTFAnimations
215
- * @param nodeMap
216
- * @param nodes
217
- * @param binaryWriter
218
- * @param bufferViews
219
- * @param accessors
220
- * @param convertToRightHandedSystemMap
221
- * @param animationSampleRate
222
- */
223
- _GLTFAnimation._CreateNodeAndMorphAnimationFromAnimationGroups = function (babylonScene, glTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystemMap, animationSampleRate) {
224
- var _a;
225
- var glTFAnimation;
226
- if (babylonScene.animationGroups) {
227
- var animationGroups = babylonScene.animationGroups;
228
- var _loop_1 = function (animationGroup) {
229
- var morphAnimations = new Map();
230
- var sampleAnimations = new Map();
231
- var morphAnimationMeshes = new Set();
232
- var animationGroupFrameDiff = animationGroup.to - animationGroup.from;
233
- glTFAnimation = {
234
- name: animationGroup.name,
235
- channels: [],
236
- samplers: []
237
- };
238
- var _loop_2 = function (i) {
239
- var targetAnimation = animationGroup.targetedAnimations[i];
240
- var target = targetAnimation.target;
241
- var animation = targetAnimation.animation;
242
- if (target instanceof TransformNode || target.length === 1 && target[0] instanceof TransformNode) {
243
- var animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
244
- if (animationInfo) {
245
- var babylonTransformNode = target instanceof TransformNode ? target : target[0];
246
- var convertToRightHandedSystem = convertToRightHandedSystemMap[babylonTransformNode.uniqueId];
247
- _GLTFAnimation.AddAnimation("".concat(animation.name), glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
248
- }
249
- }
250
- else if (target instanceof MorphTarget || target.length === 1 && target[0] instanceof MorphTarget) {
251
- var animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
252
- if (animationInfo) {
253
- var babylonMorphTarget_1 = target instanceof MorphTarget ? target : target[0];
254
- if (babylonMorphTarget_1) {
255
- var babylonMorphTargetManager_1 = babylonScene.morphTargetManagers.find(function (morphTargetManager) {
256
- for (var j = 0; j < morphTargetManager.numTargets; ++j) {
257
- if (morphTargetManager.getTarget(j) === babylonMorphTarget_1) {
258
- return true;
259
- }
260
- }
261
- return false;
262
- });
263
- if (babylonMorphTargetManager_1) {
264
- var babylonMesh = babylonScene.meshes.find(function (mesh) {
265
- return mesh.morphTargetManager === babylonMorphTargetManager_1;
266
- });
267
- if (babylonMesh) {
268
- if (!morphAnimations.has(babylonMesh)) {
269
- morphAnimations.set(babylonMesh, new Map());
270
- }
271
- (_a = morphAnimations.get(babylonMesh)) === null || _a === void 0 ? void 0 : _a.set(babylonMorphTarget_1, animation);
272
- morphAnimationMeshes.add(babylonMesh);
273
- sampleAnimations.set(babylonMesh, animation);
274
- }
275
- }
276
- }
277
- }
278
- }
279
- };
280
- for (var i = 0; i < animationGroup.targetedAnimations.length; ++i) {
281
- _loop_2(i);
282
- }
283
- morphAnimationMeshes.forEach(function (mesh) {
284
- var morphTargetManager = mesh.morphTargetManager;
285
- var combinedAnimationGroup = null;
286
- var animationKeys = [];
287
- var sampleAnimation = sampleAnimations.get(mesh);
288
- var sampleAnimationKeys = sampleAnimation.getKeys();
289
- var numAnimationKeys = sampleAnimationKeys.length;
290
- /*
291
- Due to how glTF expects morph target animation data to be formatted, we need to rearrange the individual morph target animation tracks,
292
- 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.
293
- See: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
294
-
295
- We do this via constructing a new Animation track, and interleaving the frames of each morph target animation track in the current Animation Group
296
- We reuse the Babylon Animation data structure for ease of handling export of cubic spline animation keys, and to reuse the
297
- existing _GLTFAnimation.AddAnimation codepath with minimal modification, however the constructed Babylon Animation is NOT intended for use in-engine.
298
- */
299
- for (var i = 0; i < numAnimationKeys; ++i) {
300
- for (var j = 0; j < morphTargetManager.numTargets; ++j) {
301
- var morphTarget = morphTargetManager.getTarget(j);
302
- var animationsByMorphTarget = morphAnimations.get(mesh);
303
- if (animationsByMorphTarget) {
304
- var morphTargetAnimation = animationsByMorphTarget.get(morphTarget);
305
- if (morphTargetAnimation) {
306
- if (!combinedAnimationGroup) {
307
- combinedAnimationGroup = new Animation("".concat(animationGroup.name, "_").concat(mesh.name, "_MorphWeightAnimation"), "influence", morphTargetAnimation.framePerSecond, Animation.ANIMATIONTYPE_FLOAT, morphTargetAnimation.loopMode, morphTargetAnimation.enableBlending);
308
- }
309
- animationKeys.push(morphTargetAnimation.getKeys()[i]);
310
- }
311
- else {
312
- animationKeys.push({
313
- frame: animationGroup.from + (animationGroupFrameDiff / numAnimationKeys) * i,
314
- value: morphTarget.influence,
315
- inTangent: sampleAnimationKeys[0].inTangent ? 0 : undefined,
316
- outTangent: sampleAnimationKeys[0].outTangent ? 0 : undefined
317
- });
318
- }
319
- }
320
- }
321
- }
322
- combinedAnimationGroup.setKeys(animationKeys);
323
- var animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup);
324
- if (animationInfo) {
325
- _GLTFAnimation.AddAnimation("".concat(animationGroup.name, "_").concat(mesh.name, "_MorphWeightAnimation"), glTFAnimation, mesh, combinedAnimationGroup, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, false, animationInfo.useQuaternion, animationSampleRate, morphTargetManager === null || morphTargetManager === void 0 ? void 0 : morphTargetManager.numTargets);
326
- }
327
- });
328
- if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
329
- glTFAnimations.push(glTFAnimation);
330
- }
331
- };
332
- for (var _i = 0, animationGroups_1 = animationGroups; _i < animationGroups_1.length; _i++) {
333
- var animationGroup = animationGroups_1[_i];
334
- _loop_1(animationGroup);
335
- }
336
- }
337
- };
338
- _GLTFAnimation.AddAnimation = function (name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate, morphAnimationChannels) {
339
- var animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate);
340
- var bufferView;
341
- var accessor;
342
- var keyframeAccessorIndex;
343
- var dataAccessorIndex;
344
- var outputLength;
345
- var animationSampler;
346
- var animationChannel;
347
- if (animationData) {
348
- /*
349
- * Now that we have the glTF converted morph target animation data,
350
- * we can remove redundant input data so that we have n input frames,
351
- * and morphAnimationChannels * n output frames
352
- */
353
- if (morphAnimationChannels) {
354
- var index = 0;
355
- var currentInput = 0;
356
- var newInputs = [];
357
- while (animationData.inputs.length > 0) {
358
- currentInput = animationData.inputs.shift();
359
- if (index % morphAnimationChannels == 0) {
360
- newInputs.push(currentInput);
361
- }
362
- index++;
363
- }
364
- animationData.inputs = newInputs;
365
- }
366
- var nodeIndex = nodeMap[babylonTransformNode.uniqueId];
367
- // Creates buffer view and accessor for key frames.
368
- var byteLength = animationData.inputs.length * 4;
369
- bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "".concat(name, " keyframe data view"));
370
- bufferViews.push(bufferView);
371
- animationData.inputs.forEach(function (input) {
372
- binaryWriter.setFloat32(input);
373
- });
374
- accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, "".concat(name, " keyframes"), "SCALAR" /* SCALAR */, 5126 /* FLOAT */, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
375
- accessors.push(accessor);
376
- keyframeAccessorIndex = accessors.length - 1;
377
- // create bufferview and accessor for keyed values.
378
- outputLength = animationData.outputs.length;
379
- byteLength = _GLTFUtilities._GetDataAccessorElementCount(dataAccessorType) * 4 * animationData.outputs.length;
380
- // check for in and out tangents
381
- bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "".concat(name, " data view"));
382
- bufferViews.push(bufferView);
383
- animationData.outputs.forEach(function (output) {
384
- output.forEach(function (entry) {
385
- binaryWriter.setFloat32(entry);
386
- });
387
- });
388
- accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, "".concat(name, " data"), dataAccessorType, 5126 /* FLOAT */, outputLength, null, null, null);
389
- accessors.push(accessor);
390
- dataAccessorIndex = accessors.length - 1;
391
- // create sampler
392
- animationSampler = {
393
- interpolation: animationData.samplerInterpolation,
394
- input: keyframeAccessorIndex,
395
- output: dataAccessorIndex
396
- };
397
- glTFAnimation.samplers.push(animationSampler);
398
- // create channel
399
- animationChannel = {
400
- sampler: glTFAnimation.samplers.length - 1,
401
- target: {
402
- node: nodeIndex,
403
- path: animationChannelTargetPath
404
- }
405
- };
406
- glTFAnimation.channels.push(animationChannel);
407
- }
408
- };
409
- /**
410
- * Create a baked animation
411
- * @param babylonTransformNode BabylonJS mesh
412
- * @param animation BabylonJS animation corresponding to the BabylonJS mesh
413
- * @param animationChannelTargetPath animation target channel
414
- * @param minFrame minimum animation frame
415
- * @param maxFrame maximum animation frame
416
- * @param fps frames per second of the animation
417
- * @param inputs input key frames of the animation
418
- * @param outputs output key frame data of the animation
419
- * @param convertToRightHandedSystem converts the values to right-handed
420
- * @param useQuaternion specifies if quaternions should be used
421
- */
422
- _GLTFAnimation._CreateBakedAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion) {
423
- var value;
424
- var quaternionCache = Quaternion.Identity();
425
- var previousTime = null;
426
- var time;
427
- var maxUsedFrame = null;
428
- var currKeyFrame = null;
429
- var nextKeyFrame = null;
430
- var prevKeyFrame = null;
431
- var endFrame = null;
432
- minMaxFrames.min = Tools.FloatRound(minFrame / fps);
433
- var keyFrames = animation.getKeys();
434
- for (var i = 0, length_1 = keyFrames.length; i < length_1; ++i) {
435
- endFrame = null;
436
- currKeyFrame = keyFrames[i];
437
- if (i + 1 < length_1) {
438
- nextKeyFrame = keyFrames[i + 1];
439
- if (currKeyFrame.value.equals && currKeyFrame.value.equals(nextKeyFrame.value) || currKeyFrame.value === nextKeyFrame.value) {
440
- if (i === 0) { // set the first frame to itself
441
- endFrame = currKeyFrame.frame;
442
- }
443
- else {
444
- continue;
445
- }
446
- }
447
- else {
448
- endFrame = nextKeyFrame.frame;
449
- }
450
- }
451
- else {
452
- // at the last key frame
453
- prevKeyFrame = keyFrames[i - 1];
454
- if (currKeyFrame.value.equals && currKeyFrame.value.equals(prevKeyFrame.value) || currKeyFrame.value === prevKeyFrame.value) {
455
- continue;
456
- }
457
- else {
458
- endFrame = maxFrame;
459
- }
460
- }
461
- if (endFrame) {
462
- for (var f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {
463
- time = Tools.FloatRound(f / fps);
464
- if (time === previousTime) {
465
- continue;
466
- }
467
- previousTime = time;
468
- maxUsedFrame = time;
469
- var state = {
470
- key: 0,
471
- repeatCount: 0,
472
- loopMode: animation.loopMode
473
- };
474
- value = animation._interpolate(f, state);
475
- _GLTFAnimation._SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion);
476
- }
477
- }
478
- }
479
- if (maxUsedFrame) {
480
- minMaxFrames.max = maxUsedFrame;
481
- }
482
- };
483
- _GLTFAnimation._ConvertFactorToVector3OrQuaternion = function (factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
484
- var property;
485
- var componentName;
486
- var value = null;
487
- var basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
488
- if (animationType === Animation.ANIMATIONTYPE_FLOAT) { // handles single component x, y, z or w component animation by using a base property and animating over a component.
489
- property = animation.targetProperty.split('.');
490
- componentName = property ? property[1] : ''; // x, y, or z component
491
- value = useQuaternion ? Quaternion.FromArray(basePositionRotationOrScale).normalize() : Vector3.FromArray(basePositionRotationOrScale);
492
- switch (componentName) {
493
- case 'x': {
494
- value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
495
- break;
496
- }
497
- case 'y': {
498
- value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
499
- break;
500
- }
501
- case 'z': {
502
- value[componentName] = (convertToRightHandedSystem && !useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
503
- break;
504
- }
505
- case 'w': {
506
- value.w = factor;
507
- break;
508
- }
509
- default: {
510
- Tools.Error("glTFAnimation: Unsupported component type \"".concat(componentName, "\" for scale animation!"));
511
- }
512
- }
513
- }
514
- return value;
515
- };
516
- _GLTFAnimation._SetInterpolatedValue = function (babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
517
- var animationType = animation.dataType;
518
- var cacheValue;
519
- inputs.push(time);
520
- if (typeof value === "number" && babylonTransformNode instanceof TransformNode) {
521
- value = this._ConvertFactorToVector3OrQuaternion(value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
522
- }
523
- if (value) {
524
- if (animationChannelTargetPath === "rotation" /* ROTATION */) {
525
- if (useQuaternion) {
526
- quaternionCache = value;
527
- }
528
- else {
529
- cacheValue = value;
530
- Quaternion.RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);
531
- }
532
- if (convertToRightHandedSystem) {
533
- _GLTFUtilities._GetRightHandedQuaternionFromRef(quaternionCache);
534
- if (!babylonTransformNode.parent) {
535
- quaternionCache = Quaternion.FromArray([0, 1, 0, 0]).multiply(quaternionCache);
536
- }
537
- }
538
- outputs.push(quaternionCache.asArray());
539
- }
540
- else if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
541
- outputs.push([value]);
542
- }
543
- else { // scaling and position animation
544
- cacheValue = value;
545
- if (convertToRightHandedSystem && (animationChannelTargetPath !== "scale" /* SCALE */)) {
546
- _GLTFUtilities._GetRightHandedPositionVector3FromRef(cacheValue);
547
- if (!babylonTransformNode.parent) {
548
- cacheValue.x *= -1;
549
- cacheValue.z *= -1;
550
- }
551
- }
552
- outputs.push(cacheValue.asArray());
553
- }
554
- }
555
- };
556
- /**
557
- * Creates linear animation from the animation key frames
558
- * @param babylonTransformNode BabylonJS mesh
559
- * @param animation BabylonJS animation
560
- * @param animationChannelTargetPath The target animation channel
561
- * @param frameDelta The difference between the last and first frame of the animation
562
- * @param inputs Array to store the key frame times
563
- * @param outputs Array to store the key frame data
564
- * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
565
- * @param useQuaternion Specifies if quaternions are used in the animation
566
- */
567
- _GLTFAnimation._CreateLinearOrStepAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
568
- for (var _i = 0, _a = animation.getKeys(); _i < _a.length; _i++) {
569
- var keyFrame = _a[_i];
570
- inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
571
- _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
572
- }
573
- };
574
- /**
575
- * Creates cubic spline animation from the animation key frames
576
- * @param babylonTransformNode BabylonJS mesh
577
- * @param animation BabylonJS animation
578
- * @param animationChannelTargetPath The target animation channel
579
- * @param frameDelta The difference between the last and first frame of the animation
580
- * @param inputs Array to store the key frame times
581
- * @param outputs Array to store the key frame data
582
- * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
583
- * @param useQuaternion Specifies if quaternions are used in the animation
584
- */
585
- _GLTFAnimation._CreateCubicSplineAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
586
- animation.getKeys().forEach(function (keyFrame) {
587
- inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
588
- _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
589
- _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
590
- _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
591
- });
592
- };
593
- _GLTFAnimation._GetBasePositionRotationOrScale = function (babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
594
- var basePositionRotationOrScale;
595
- if (animationChannelTargetPath === "rotation" /* ROTATION */) {
596
- if (useQuaternion) {
597
- if (babylonTransformNode.rotationQuaternion) {
598
- basePositionRotationOrScale = babylonTransformNode.rotationQuaternion.asArray();
599
- if (convertToRightHandedSystem) {
600
- _GLTFUtilities._GetRightHandedQuaternionArrayFromRef(basePositionRotationOrScale);
601
- if (!babylonTransformNode.parent) {
602
- basePositionRotationOrScale = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(basePositionRotationOrScale)).asArray();
603
- }
604
- }
605
- }
606
- else {
607
- basePositionRotationOrScale = Quaternion.Identity().asArray();
608
- }
609
- }
610
- else {
611
- basePositionRotationOrScale = babylonTransformNode.rotation.asArray();
612
- _GLTFUtilities._GetRightHandedNormalArray3FromRef(basePositionRotationOrScale);
613
- }
614
- }
615
- else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
616
- basePositionRotationOrScale = babylonTransformNode.position.asArray();
617
- if (convertToRightHandedSystem) {
618
- _GLTFUtilities._GetRightHandedPositionArray3FromRef(basePositionRotationOrScale);
619
- }
620
- }
621
- else { // scale
622
- basePositionRotationOrScale = babylonTransformNode.scaling.asArray();
623
- }
624
- return basePositionRotationOrScale;
625
- };
626
- /**
627
- * Adds a key frame value
628
- * @param keyFrame
629
- * @param animation
630
- * @param outputs
631
- * @param animationChannelTargetPath
632
- * @param basePositionRotationOrScale
633
- * @param convertToRightHandedSystem
634
- * @param useQuaternion
635
- */
636
- _GLTFAnimation._AddKeyframeValue = function (keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion) {
637
- var value;
638
- var newPositionRotationOrScale;
639
- var animationType = animation.dataType;
640
- if (animationType === Animation.ANIMATIONTYPE_VECTOR3) {
641
- value = keyFrame.value.asArray();
642
- if (animationChannelTargetPath === "rotation" /* ROTATION */) {
643
- var array = Vector3.FromArray(value);
644
- var rotationQuaternion = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z);
645
- if (convertToRightHandedSystem) {
646
- _GLTFUtilities._GetRightHandedQuaternionFromRef(rotationQuaternion);
647
- if (!babylonTransformNode.parent) {
648
- rotationQuaternion = Quaternion.FromArray([0, 1, 0, 0]).multiply(rotationQuaternion);
649
- }
650
- }
651
- value = rotationQuaternion.asArray();
652
- }
653
- else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
654
- if (convertToRightHandedSystem) {
655
- _GLTFUtilities._GetRightHandedNormalArray3FromRef(value);
656
- if (!babylonTransformNode.parent) {
657
- value[0] *= -1;
658
- value[2] *= -1;
659
- }
660
- }
661
- }
662
- outputs.push(value); // scale vector.
663
- }
664
- else if (animationType === Animation.ANIMATIONTYPE_FLOAT) {
665
- if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
666
- outputs.push([keyFrame.value]);
667
- }
668
- else { // handles single component x, y, z or w component animation by using a base property and animating over a component.
669
- newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
670
- if (newPositionRotationOrScale) {
671
- if (animationChannelTargetPath === "rotation" /* ROTATION */) {
672
- var posRotScale = useQuaternion ? newPositionRotationOrScale : Quaternion.RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();
673
- if (convertToRightHandedSystem) {
674
- _GLTFUtilities._GetRightHandedQuaternionFromRef(posRotScale);
675
- if (!babylonTransformNode.parent) {
676
- posRotScale = Quaternion.FromArray([0, 1, 0, 0]).multiply(posRotScale);
677
- }
678
- }
679
- outputs.push(posRotScale.asArray());
680
- }
681
- else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
682
- if (convertToRightHandedSystem) {
683
- _GLTFUtilities._GetRightHandedNormalVector3FromRef(newPositionRotationOrScale);
684
- if (!babylonTransformNode.parent) {
685
- newPositionRotationOrScale.x *= -1;
686
- newPositionRotationOrScale.z *= -1;
687
- }
688
- }
689
- }
690
- outputs.push(newPositionRotationOrScale.asArray());
691
- }
692
- }
693
- }
694
- else if (animationType === Animation.ANIMATIONTYPE_QUATERNION) {
695
- value = keyFrame.value.normalize().asArray();
696
- if (convertToRightHandedSystem) {
697
- _GLTFUtilities._GetRightHandedQuaternionArrayFromRef(value);
698
- if (!babylonTransformNode.parent) {
699
- value = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(value)).asArray();
700
- }
701
- }
702
- outputs.push(value);
703
- }
704
- else {
705
- Tools.Error('glTFAnimation: Unsupported key frame values for animation!');
706
- }
707
- };
708
- /**
709
- * Determine the interpolation based on the key frames
710
- * @param keyFrames
711
- * @param animationChannelTargetPath
712
- * @param useQuaternion
713
- */
714
- _GLTFAnimation._DeduceInterpolation = function (keyFrames, animationChannelTargetPath, useQuaternion) {
715
- var interpolationType;
716
- var shouldBakeAnimation = false;
717
- var key;
718
- if (animationChannelTargetPath === "rotation" /* ROTATION */ && !useQuaternion) {
719
- return { interpolationType: "LINEAR" /* LINEAR */, shouldBakeAnimation: true };
720
- }
721
- for (var i = 0, length_2 = keyFrames.length; i < length_2; ++i) {
722
- key = keyFrames[i];
723
- if (key.inTangent || key.outTangent) {
724
- if (interpolationType) {
725
- if (interpolationType !== "CUBICSPLINE" /* CUBICSPLINE */) {
726
- interpolationType = "LINEAR" /* LINEAR */;
727
- shouldBakeAnimation = true;
728
- break;
729
- }
730
- }
731
- else {
732
- interpolationType = "CUBICSPLINE" /* CUBICSPLINE */;
733
- }
734
- }
735
- else {
736
- if (interpolationType) {
737
- if (interpolationType === "CUBICSPLINE" /* CUBICSPLINE */ ||
738
- (key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP) && interpolationType !== "STEP" /* STEP */)) {
739
- interpolationType = "LINEAR" /* LINEAR */;
740
- shouldBakeAnimation = true;
741
- break;
742
- }
743
- }
744
- else {
745
- if (key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP)) {
746
- interpolationType = "STEP" /* STEP */;
747
- }
748
- else {
749
- interpolationType = "LINEAR" /* LINEAR */;
750
- }
751
- }
752
- }
753
- }
754
- if (!interpolationType) {
755
- interpolationType = "LINEAR" /* LINEAR */;
756
- }
757
- return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
758
- };
759
- /**
760
- * Adds an input tangent or output tangent to the output data
761
- * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
762
- * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
763
- * @param outputs The animation data by keyframe
764
- * @param animationChannelTargetPath The target animation channel
765
- * @param interpolation The interpolation type
766
- * @param keyFrame The key frame with the animation data
767
- * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
768
- * @param useQuaternion Specifies if quaternions are used
769
- * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
770
- */
771
- _GLTFAnimation.AddSplineTangent = function (babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem) {
772
- var tangent;
773
- var tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
774
- if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
775
- if (animationChannelTargetPath === "rotation" /* ROTATION */) {
776
- if (tangentValue) {
777
- if (useQuaternion) {
778
- tangent = tangentValue.asArray();
779
- }
780
- else {
781
- var array = tangentValue;
782
- tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();
783
- }
784
- if (convertToRightHandedSystem) {
785
- _GLTFUtilities._GetRightHandedQuaternionArrayFromRef(tangent);
786
- if (!babylonTransformNode.parent) {
787
- tangent = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(tangent)).asArray();
788
- }
789
- }
790
- }
791
- else {
792
- tangent = [0, 0, 0, 0];
793
- }
794
- }
795
- else if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
796
- if (tangentValue) {
797
- tangent = [tangentValue];
798
- }
799
- else {
800
- tangent = [0];
801
- }
802
- }
803
- else {
804
- if (tangentValue) {
805
- tangent = tangentValue.asArray();
806
- if (convertToRightHandedSystem) {
807
- if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
808
- _GLTFUtilities._GetRightHandedPositionArray3FromRef(tangent);
809
- if (!babylonTransformNode.parent) {
810
- tangent[0] *= -1; // x
811
- tangent[2] *= -1; // z
812
- }
813
- }
814
- }
815
- }
816
- else {
817
- tangent = [0, 0, 0];
818
- }
819
- }
820
- outputs.push(tangent);
821
- }
822
- };
823
- /**
824
- * Get the minimum and maximum key frames' frame values
825
- * @param keyFrames animation key frames
826
- * @returns the minimum and maximum key frame value
827
- */
828
- _GLTFAnimation.calculateMinMaxKeyFrames = function (keyFrames) {
829
- var min = Infinity;
830
- var max = -Infinity;
831
- keyFrames.forEach(function (keyFrame) {
832
- min = Math.min(min, keyFrame.frame);
833
- max = Math.max(max, keyFrame.frame);
834
- });
835
- return { min: min, max: max };
836
- };
837
- return _GLTFAnimation;
838
- }());
839
- export { _GLTFAnimation };
840
- //# sourceMappingURL=glTFAnimation.js.map