@babylonjs/loaders 5.24.0 → 5.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/STL/stlFileLoader.d.ts +4 -4
- package/STL/stlFileLoader.js +4 -4
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.d.ts +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +1 -1
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +3 -3
- package/glTF/1.0/glTFLoader.js +3 -3
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +45 -45
- package/glTF/1.0/glTFLoaderInterfaces.js +8 -8
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +1 -1
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.js +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +5 -8
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +4 -7
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +3 -7
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +3 -7
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +3 -6
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +3 -6
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +3 -7
- package/glTF/2.0/Extensions/EXT_texture_webp.js +3 -7
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +5 -15
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +5 -15
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +14 -35
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.d.ts +133 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js +169 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +56 -208
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +3 -7
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +4 -8
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +6 -9
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_specular.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +4 -11
- package/glTF/2.0/Extensions/KHR_materials_variants.js +4 -11
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_materials_volume.js +3 -7
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +2 -3
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +2 -3
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +3 -7
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +3 -7
- package/glTF/2.0/Extensions/KHR_texture_transform.js +3 -7
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +2 -3
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +2 -3
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +6 -14
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +6 -14
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +8 -26
- package/glTF/2.0/Extensions/MSFT_lod.js +8 -26
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +55 -52
- package/glTF/2.0/glTFLoader.js +217 -91
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderAnimation.d.ts +29 -0
- package/glTF/2.0/glTFLoaderAnimation.js +66 -0
- package/glTF/2.0/glTFLoaderAnimation.js.map +1 -0
- package/glTF/2.0/glTFLoaderExtension.d.ts +20 -7
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +58 -31
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +20 -53
- package/glTF/glTFFileLoader.js +17 -50
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +3 -3
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.d.ts +0 -15
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js +0 -454
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js.map +0 -1
- package/glTF/2.0/glTFUtilities.d.ts +0 -7
- package/glTF/2.0/glTFUtilities.js +0 -23
- package/glTF/2.0/glTFUtilities.js.map +0 -1
package/glTF/2.0/glTFLoader.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
|
4
4
|
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
5
5
|
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
|
6
6
|
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera.js";
|
|
7
|
+
import { AnimationKeyInterpolation } from "@babylonjs/core/Animations/animationKey.js";
|
|
7
8
|
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
|
|
8
9
|
import { Bone } from "@babylonjs/core/Bones/bone.js";
|
|
9
10
|
import { Skeleton } from "@babylonjs/core/Bones/skeleton.js";
|
|
@@ -20,6 +21,27 @@ import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLo
|
|
|
20
21
|
import { DecodeBase64UrlToBinary, IsBase64DataUrl, LoadFileError } from "@babylonjs/core/Misc/fileTools.js";
|
|
21
22
|
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
22
23
|
import { BoundingInfo } from "@babylonjs/core/Culling/boundingInfo.js";
|
|
24
|
+
import { nodeAnimationData } from "./glTFLoaderAnimation.js";
|
|
25
|
+
// https://stackoverflow.com/a/48218209
|
|
26
|
+
function mergeDeep(...objects) {
|
|
27
|
+
const isObject = (obj) => obj && typeof obj === "object";
|
|
28
|
+
return objects.reduce((prev, obj) => {
|
|
29
|
+
Object.keys(obj).forEach((key) => {
|
|
30
|
+
const pVal = prev[key];
|
|
31
|
+
const oVal = obj[key];
|
|
32
|
+
if (Array.isArray(pVal) && Array.isArray(oVal)) {
|
|
33
|
+
prev[key] = pVal.concat(...oVal);
|
|
34
|
+
}
|
|
35
|
+
else if (isObject(pVal) && isObject(oVal)) {
|
|
36
|
+
prev[key] = mergeDeep(pVal, oVal);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
prev[key] = oVal;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return prev;
|
|
43
|
+
}, {});
|
|
44
|
+
}
|
|
23
45
|
/**
|
|
24
46
|
* Helper class for working with arrays when loading the glTF asset
|
|
25
47
|
*/
|
|
@@ -49,42 +71,21 @@ export class ArrayItem {
|
|
|
49
71
|
}
|
|
50
72
|
}
|
|
51
73
|
}
|
|
52
|
-
// https://stackoverflow.com/a/48218209
|
|
53
|
-
function mergeDeep(...objects) {
|
|
54
|
-
const isObject = (obj) => obj && typeof obj === "object";
|
|
55
|
-
return objects.reduce((prev, obj) => {
|
|
56
|
-
Object.keys(obj).forEach((key) => {
|
|
57
|
-
const pVal = prev[key];
|
|
58
|
-
const oVal = obj[key];
|
|
59
|
-
if (Array.isArray(pVal) && Array.isArray(oVal)) {
|
|
60
|
-
prev[key] = pVal.concat(...oVal);
|
|
61
|
-
}
|
|
62
|
-
else if (isObject(pVal) && isObject(oVal)) {
|
|
63
|
-
prev[key] = mergeDeep(pVal, oVal);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
prev[key] = oVal;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return prev;
|
|
70
|
-
}, {});
|
|
71
|
-
}
|
|
72
74
|
/**
|
|
73
75
|
* The glTF 2.0 loader
|
|
74
76
|
*/
|
|
75
77
|
export class GLTFLoader {
|
|
76
78
|
/**
|
|
77
|
-
* @
|
|
78
|
-
* @hidden
|
|
79
|
+
* @internal
|
|
79
80
|
*/
|
|
80
81
|
constructor(parent) {
|
|
81
|
-
/** @
|
|
82
|
+
/** @internal */
|
|
82
83
|
this._completePromises = new Array();
|
|
83
|
-
/** @
|
|
84
|
+
/** @internal */
|
|
84
85
|
this._assetContainer = null;
|
|
85
86
|
/** Storage */
|
|
86
87
|
this._babylonLights = [];
|
|
87
|
-
/** @
|
|
88
|
+
/** @internal */
|
|
88
89
|
this._disableInstancedMesh = 0;
|
|
89
90
|
this._extensions = new Array();
|
|
90
91
|
this._disposed = false;
|
|
@@ -158,7 +159,7 @@ export class GLTFLoader {
|
|
|
158
159
|
get rootBabylonMesh() {
|
|
159
160
|
return this._rootBabylonMesh;
|
|
160
161
|
}
|
|
161
|
-
/** @
|
|
162
|
+
/** @internal */
|
|
162
163
|
dispose() {
|
|
163
164
|
if (this._disposed) {
|
|
164
165
|
return;
|
|
@@ -176,14 +177,7 @@ export class GLTFLoader {
|
|
|
176
177
|
this._parent.dispose();
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
|
-
* @
|
|
180
|
-
* @param scene
|
|
181
|
-
* @param container
|
|
182
|
-
* @param data
|
|
183
|
-
* @param rootUrl
|
|
184
|
-
* @param onProgress
|
|
185
|
-
* @param fileName
|
|
186
|
-
* @hidden
|
|
180
|
+
* @internal
|
|
187
181
|
*/
|
|
188
182
|
importMeshAsync(meshesNames, scene, container, data, rootUrl, onProgress, fileName = "") {
|
|
189
183
|
return Promise.resolve().then(() => {
|
|
@@ -223,12 +217,7 @@ export class GLTFLoader {
|
|
|
223
217
|
});
|
|
224
218
|
}
|
|
225
219
|
/**
|
|
226
|
-
* @
|
|
227
|
-
* @param data
|
|
228
|
-
* @param rootUrl
|
|
229
|
-
* @param onProgress
|
|
230
|
-
* @param fileName
|
|
231
|
-
* @hidden
|
|
220
|
+
* @internal
|
|
232
221
|
*/
|
|
233
222
|
loadAsync(scene, data, rootUrl, onProgress, fileName = "") {
|
|
234
223
|
return Promise.resolve().then(() => {
|
|
@@ -691,7 +680,7 @@ export class GLTFLoader {
|
|
|
691
680
|
});
|
|
692
681
|
}
|
|
693
682
|
/**
|
|
694
|
-
* @
|
|
683
|
+
* @internal Define this method to modify the default behavior when loading data for mesh primitives.
|
|
695
684
|
* @param context The context when loading the asset
|
|
696
685
|
* @param name The mesh name when loading the asset
|
|
697
686
|
* @param node The glTF node when loading the asset
|
|
@@ -1127,6 +1116,7 @@ export class GLTFLoader {
|
|
|
1127
1116
|
babylonCamera._parentContainer = this._assetContainer;
|
|
1128
1117
|
this._babylonScene._blockEntityCollection = false;
|
|
1129
1118
|
babylonCamera.ignoreParentScaling = true;
|
|
1119
|
+
camera._babylonCamera = babylonCamera;
|
|
1130
1120
|
babylonCamera.rotation = new Vector3(0, Math.PI, 0);
|
|
1131
1121
|
switch (camera.type) {
|
|
1132
1122
|
case "perspective" /* PERSPECTIVE */: {
|
|
@@ -1159,8 +1149,6 @@ export class GLTFLoader {
|
|
|
1159
1149
|
GLTFLoader.AddPointerMetadata(babylonCamera, context);
|
|
1160
1150
|
this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
|
|
1161
1151
|
assign(babylonCamera);
|
|
1162
|
-
// register the camera to be used later.
|
|
1163
|
-
camera._babylonCamera = babylonCamera;
|
|
1164
1152
|
this.logClose();
|
|
1165
1153
|
return Promise.all(promises).then(() => {
|
|
1166
1154
|
return babylonCamera;
|
|
@@ -1190,32 +1178,190 @@ export class GLTFLoader {
|
|
|
1190
1178
|
* @returns A promise that resolves with the loaded Babylon animation group when the load is complete
|
|
1191
1179
|
*/
|
|
1192
1180
|
loadAnimationAsync(context, animation) {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
continue;
|
|
1197
|
-
}
|
|
1198
|
-
// decorate the channel with a KHR_animation_pointer extension.
|
|
1199
|
-
channel.target.extensions = channel.target.extensions || {};
|
|
1200
|
-
channel.target.extensions.KHR_animation_pointer = {
|
|
1201
|
-
pointer: `/nodes/${channel.target.node}/${channel.target.path}`,
|
|
1202
|
-
};
|
|
1203
|
-
channel.target.path = "pointer" /* POINTER */;
|
|
1204
|
-
delete channel.target.node;
|
|
1205
|
-
// ensure to declare extension used.
|
|
1206
|
-
this._gltf.extensionsUsed = this._gltf.extensionsUsed || [];
|
|
1207
|
-
if (this._gltf.extensionsUsed.indexOf(GLTFLoader._KHRAnimationPointerName) === -1) {
|
|
1208
|
-
this._gltf.extensionsUsed.push(GLTFLoader._KHRAnimationPointerName);
|
|
1209
|
-
}
|
|
1181
|
+
const promise = this._extensionsLoadAnimationAsync(context, animation);
|
|
1182
|
+
if (promise) {
|
|
1183
|
+
return promise;
|
|
1210
1184
|
}
|
|
1211
|
-
// create the animation group to be passed to extension.
|
|
1212
1185
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
|
1213
1186
|
const babylonAnimationGroup = new AnimationGroup(animation.name || `animation${animation.index}`, this._babylonScene);
|
|
1214
1187
|
babylonAnimationGroup._parentContainer = this._assetContainer;
|
|
1215
1188
|
this._babylonScene._blockEntityCollection = false;
|
|
1216
1189
|
animation._babylonAnimationGroup = babylonAnimationGroup;
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1190
|
+
const promises = new Array();
|
|
1191
|
+
ArrayItem.Assign(animation.channels);
|
|
1192
|
+
ArrayItem.Assign(animation.samplers);
|
|
1193
|
+
for (const channel of animation.channels) {
|
|
1194
|
+
promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel, (babylonTarget, babylonAnimation) => {
|
|
1195
|
+
babylonTarget.animations = babylonTarget.animations || [];
|
|
1196
|
+
babylonTarget.animations.push(babylonAnimation);
|
|
1197
|
+
babylonAnimationGroup.addTargetedAnimation(babylonAnimation, babylonTarget);
|
|
1198
|
+
}));
|
|
1199
|
+
}
|
|
1200
|
+
return Promise.all(promises).then(() => {
|
|
1201
|
+
babylonAnimationGroup.normalize(0);
|
|
1202
|
+
return babylonAnimationGroup;
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* @hidden
|
|
1207
|
+
* Loads a glTF animation channel.
|
|
1208
|
+
* @param context The context when loading the asset
|
|
1209
|
+
* @param animationContext The context of the animation when loading the asset
|
|
1210
|
+
* @param animation The glTF animation property
|
|
1211
|
+
* @param channel The glTF animation channel property
|
|
1212
|
+
* @param onLoad Called for each animation loaded
|
|
1213
|
+
* @returns A void promise that resolves when the load is complete
|
|
1214
|
+
*/
|
|
1215
|
+
_loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
|
|
1216
|
+
const promise = this._extensionsLoadAnimationChannelAsync(context, animationContext, animation, channel, onLoad);
|
|
1217
|
+
if (promise) {
|
|
1218
|
+
return promise;
|
|
1219
|
+
}
|
|
1220
|
+
if (channel.target.node == undefined) {
|
|
1221
|
+
return Promise.resolve();
|
|
1222
|
+
}
|
|
1223
|
+
const targetNode = ArrayItem.Get(`${context}/target/node`, this._gltf.nodes, channel.target.node);
|
|
1224
|
+
// Ignore animations that have no animation targets.
|
|
1225
|
+
if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
|
|
1226
|
+
(channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
|
|
1227
|
+
return Promise.resolve();
|
|
1228
|
+
}
|
|
1229
|
+
let properties;
|
|
1230
|
+
switch (channel.target.path) {
|
|
1231
|
+
case "translation" /* TRANSLATION */: {
|
|
1232
|
+
properties = nodeAnimationData.translation;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
case "rotation" /* ROTATION */: {
|
|
1236
|
+
properties = nodeAnimationData.rotation;
|
|
1237
|
+
break;
|
|
1238
|
+
}
|
|
1239
|
+
case "scale" /* SCALE */: {
|
|
1240
|
+
properties = nodeAnimationData.scale;
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
case "weights" /* WEIGHTS */: {
|
|
1244
|
+
properties = nodeAnimationData.weights;
|
|
1245
|
+
break;
|
|
1246
|
+
}
|
|
1247
|
+
default: {
|
|
1248
|
+
throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
const targetInfo = {
|
|
1252
|
+
target: targetNode,
|
|
1253
|
+
properties: properties,
|
|
1254
|
+
};
|
|
1255
|
+
return this._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* @hidden
|
|
1259
|
+
* Loads a glTF animation channel.
|
|
1260
|
+
* @param context The context when loading the asset
|
|
1261
|
+
* @param animationContext The context of the animation when loading the asset
|
|
1262
|
+
* @param animation The glTF animation property
|
|
1263
|
+
* @param channel The glTF animation channel property
|
|
1264
|
+
* @param targetInfo The glTF target and properties
|
|
1265
|
+
* @param onLoad Called for each animation loaded
|
|
1266
|
+
* @returns A void promise that resolves when the load is complete
|
|
1267
|
+
*/
|
|
1268
|
+
_loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad) {
|
|
1269
|
+
const fps = this.parent.targetFps;
|
|
1270
|
+
const invfps = 1 / fps;
|
|
1271
|
+
const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);
|
|
1272
|
+
return this._loadAnimationSamplerAsync(`${animationContext}/samplers/${channel.sampler}`, sampler).then((data) => {
|
|
1273
|
+
let numAnimations = 0;
|
|
1274
|
+
// Extract the corresponding values from the read value.
|
|
1275
|
+
// GLTF values may be dispatched to several Babylon properties.
|
|
1276
|
+
// For example, baseColorFactor [`r`, `g`, `b`, `a`] is dispatched to
|
|
1277
|
+
// - albedoColor as Color3(`r`, `g`, `b`)
|
|
1278
|
+
// - alpha as `a`
|
|
1279
|
+
for (const property of targetInfo.properties) {
|
|
1280
|
+
const stride = property.getStride(targetInfo.target);
|
|
1281
|
+
const input = data.input;
|
|
1282
|
+
const output = data.output;
|
|
1283
|
+
const keys = new Array(input.length);
|
|
1284
|
+
let outputOffset = 0;
|
|
1285
|
+
switch (data.interpolation) {
|
|
1286
|
+
case "STEP" /* STEP */: {
|
|
1287
|
+
for (let index = 0; index < input.length; index++) {
|
|
1288
|
+
const value = property.getValue(targetInfo.target, output, outputOffset, 1);
|
|
1289
|
+
outputOffset += stride;
|
|
1290
|
+
keys[index] = {
|
|
1291
|
+
frame: input[index] * fps,
|
|
1292
|
+
value: value,
|
|
1293
|
+
interpolation: AnimationKeyInterpolation.STEP,
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
|
1299
|
+
for (let index = 0; index < input.length; index++) {
|
|
1300
|
+
const inTangent = property.getValue(targetInfo.target, output, outputOffset, invfps);
|
|
1301
|
+
outputOffset += stride;
|
|
1302
|
+
const value = property.getValue(targetInfo.target, output, outputOffset, 1);
|
|
1303
|
+
outputOffset += stride;
|
|
1304
|
+
const outTangent = property.getValue(targetInfo.target, output, outputOffset, invfps);
|
|
1305
|
+
outputOffset += stride;
|
|
1306
|
+
keys[index] = {
|
|
1307
|
+
frame: input[index] * fps,
|
|
1308
|
+
inTangent: inTangent,
|
|
1309
|
+
value: value,
|
|
1310
|
+
outTangent: outTangent,
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
case "LINEAR" /* LINEAR */: {
|
|
1316
|
+
for (let index = 0; index < input.length; index++) {
|
|
1317
|
+
const value = property.getValue(targetInfo.target, output, outputOffset, 1);
|
|
1318
|
+
outputOffset += stride;
|
|
1319
|
+
keys[index] = {
|
|
1320
|
+
frame: input[index] * fps,
|
|
1321
|
+
value: value,
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (outputOffset > 0) {
|
|
1328
|
+
const name = `${animation.name || `animation${animation.index}`}_channel${channel.index}_${numAnimations}`;
|
|
1329
|
+
property.buildAnimations(targetInfo.target, name, fps, keys, (babylonAnimatable, babylonAnimation) => {
|
|
1330
|
+
++numAnimations;
|
|
1331
|
+
onLoad(babylonAnimatable, babylonAnimation);
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
_loadAnimationSamplerAsync(context, sampler) {
|
|
1338
|
+
if (sampler._data) {
|
|
1339
|
+
return sampler._data;
|
|
1340
|
+
}
|
|
1341
|
+
const interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
|
|
1342
|
+
switch (interpolation) {
|
|
1343
|
+
case "STEP" /* STEP */:
|
|
1344
|
+
case "LINEAR" /* LINEAR */:
|
|
1345
|
+
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
default: {
|
|
1349
|
+
throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
const inputAccessor = ArrayItem.Get(`${context}/input`, this._gltf.accessors, sampler.input);
|
|
1353
|
+
const outputAccessor = ArrayItem.Get(`${context}/output`, this._gltf.accessors, sampler.output);
|
|
1354
|
+
sampler._data = Promise.all([
|
|
1355
|
+
this._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),
|
|
1356
|
+
this._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),
|
|
1357
|
+
]).then(([inputData, outputData]) => {
|
|
1358
|
+
return {
|
|
1359
|
+
input: inputData,
|
|
1360
|
+
interpolation: interpolation,
|
|
1361
|
+
output: outputData,
|
|
1362
|
+
};
|
|
1363
|
+
});
|
|
1364
|
+
return sampler._data;
|
|
1219
1365
|
}
|
|
1220
1366
|
/**
|
|
1221
1367
|
* Loads a glTF buffer.
|
|
@@ -1330,9 +1476,7 @@ export class GLTFLoader {
|
|
|
1330
1476
|
return accessor._data;
|
|
1331
1477
|
}
|
|
1332
1478
|
/**
|
|
1333
|
-
* @
|
|
1334
|
-
* @param accessor
|
|
1335
|
-
* @hidden
|
|
1479
|
+
* @internal
|
|
1336
1480
|
*/
|
|
1337
1481
|
_loadFloatAccessorAsync(context, accessor) {
|
|
1338
1482
|
return this._loadAccessorAsync(context, accessor, Float32Array);
|
|
@@ -1435,12 +1579,7 @@ export class GLTFLoader {
|
|
|
1435
1579
|
return Promise.all(promises).then(() => { });
|
|
1436
1580
|
}
|
|
1437
1581
|
/**
|
|
1438
|
-
* @
|
|
1439
|
-
* @param material
|
|
1440
|
-
* @param babylonMesh
|
|
1441
|
-
* @param babylonDrawMode
|
|
1442
|
-
* @param assign
|
|
1443
|
-
* @hidden
|
|
1582
|
+
* @internal
|
|
1444
1583
|
*/
|
|
1445
1584
|
_loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign = () => { }) {
|
|
1446
1585
|
const extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
|
|
@@ -1642,10 +1781,7 @@ export class GLTFLoader {
|
|
|
1642
1781
|
return promise;
|
|
1643
1782
|
}
|
|
1644
1783
|
/**
|
|
1645
|
-
* @
|
|
1646
|
-
* @param texture
|
|
1647
|
-
* @param assign
|
|
1648
|
-
* @hidden
|
|
1784
|
+
* @internal
|
|
1649
1785
|
*/
|
|
1650
1786
|
_loadTextureAsync(context, texture, assign = () => { }) {
|
|
1651
1787
|
const extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
|
|
@@ -1660,13 +1796,7 @@ export class GLTFLoader {
|
|
|
1660
1796
|
return promise;
|
|
1661
1797
|
}
|
|
1662
1798
|
/**
|
|
1663
|
-
* @
|
|
1664
|
-
* @param sampler
|
|
1665
|
-
* @param image
|
|
1666
|
-
* @param assign
|
|
1667
|
-
* @param textureLoaderOptions
|
|
1668
|
-
* @param useSRGBBuffer
|
|
1669
|
-
* @hidden
|
|
1799
|
+
* @internal
|
|
1670
1800
|
*/
|
|
1671
1801
|
_createTextureAsync(context, sampler, image, assign = () => { }, textureLoaderOptions, useSRGBBuffer) {
|
|
1672
1802
|
const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
|
|
@@ -1775,7 +1905,6 @@ export class GLTFLoader {
|
|
|
1775
1905
|
/**
|
|
1776
1906
|
* Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
|
|
1777
1907
|
* @param babylonObject the Babylon object with metadata
|
|
1778
|
-
* @param babylonObject.metadata
|
|
1779
1908
|
* @param pointer the JSON pointer
|
|
1780
1909
|
*/
|
|
1781
1910
|
static AddPointerMetadata(babylonObject, pointer) {
|
|
@@ -1898,9 +2027,7 @@ export class GLTFLoader {
|
|
|
1898
2027
|
return Tools.IsBase64(uri) || uri.indexOf("..") === -1;
|
|
1899
2028
|
}
|
|
1900
2029
|
/**
|
|
1901
|
-
* @
|
|
1902
|
-
* @param mode
|
|
1903
|
-
* @hidden
|
|
2030
|
+
* @internal
|
|
1904
2031
|
*/
|
|
1905
2032
|
static _GetDrawMode(context, mode) {
|
|
1906
2033
|
if (mode == undefined) {
|
|
@@ -2034,6 +2161,9 @@ export class GLTFLoader {
|
|
|
2034
2161
|
_extensionsLoadAnimationAsync(context, animation) {
|
|
2035
2162
|
return this._applyExtensions(animation, "loadAnimation", (extension) => extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation));
|
|
2036
2163
|
}
|
|
2164
|
+
_extensionsLoadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
|
|
2165
|
+
return this._applyExtensions(animation, "loadAnimationChannel", (extension) => extension._loadAnimationChannelAsync && extension._loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad));
|
|
2166
|
+
}
|
|
2037
2167
|
_extensionsLoadSkinAsync(context, node, skin) {
|
|
2038
2168
|
return this._applyExtensions(skin, "loadSkin", (extension) => extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin));
|
|
2039
2169
|
}
|
|
@@ -2127,10 +2257,6 @@ export class GLTFLoader {
|
|
|
2127
2257
|
this._parent._endPerformanceCounter(counterName);
|
|
2128
2258
|
}
|
|
2129
2259
|
}
|
|
2130
|
-
/** @hidden */
|
|
2131
|
-
// note : KHR_animation_pointer is used to load animation in ALL case, turning everything
|
|
2132
|
-
// into pointer. This is the reason why this value is located here.
|
|
2133
|
-
GLTFLoader._KHRAnimationPointerName = "KHR_animation_pointer";
|
|
2134
2260
|
GLTFLoader._RegisteredExtensions = {};
|
|
2135
2261
|
/**
|
|
2136
2262
|
* The default glTF sampler.
|