@babylonjs/loaders 8.23.1 → 8.24.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/glTF/2.0/glTFLoader.js +47 -37
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +79 -67
- package/glTF/glTFFileLoader.js +72 -68
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +3 -3
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -24,6 +24,10 @@ import { registeredGLTFExtensions, registerGLTFExtension, unregisterGLTFExtensio
|
|
24
24
|
import { GetMappingForKey } from "./Extensions/objectModelMapping.js";
|
25
25
|
import { deepMerge } from "@babylonjs/core/Misc/deepMerger.js";
|
26
26
|
import { GetTypedArrayConstructor } from "@babylonjs/core/Buffers/bufferUtils.js";
|
27
|
+
import { Lazy } from "@babylonjs/core/Misc/lazy.js";
|
28
|
+
// Caching these dynamic imports gives a surprising perf boost (compared to importing them directly each time).
|
29
|
+
const LazyAnimationGroupModulePromise = new Lazy(() => import("@babylonjs/core/Animations/animationGroup.js"));
|
30
|
+
const LazyLoaderAnimationModulePromise = new Lazy(() => import("./glTFLoaderAnimation.js"));
|
27
31
|
export { GLTFFileLoader };
|
28
32
|
/**
|
29
33
|
* Helper class for working with arrays when loading the glTF asset
|
@@ -1262,6 +1266,7 @@ export class GLTFLoader {
|
|
1262
1266
|
});
|
1263
1267
|
}
|
1264
1268
|
_loadAnimationsAsync() {
|
1269
|
+
this._parent._startPerformanceCounter("Load animations");
|
1265
1270
|
const animations = this._gltf.animations;
|
1266
1271
|
if (!animations) {
|
1267
1272
|
return Promise.resolve();
|
@@ -1276,7 +1281,9 @@ export class GLTFLoader {
|
|
1276
1281
|
}
|
1277
1282
|
}));
|
1278
1283
|
}
|
1279
|
-
return Promise.all(promises).then(() => {
|
1284
|
+
return Promise.all(promises).then(() => {
|
1285
|
+
this._parent._endPerformanceCounter("Load animations");
|
1286
|
+
});
|
1280
1287
|
}
|
1281
1288
|
/**
|
1282
1289
|
* Loads a glTF animation.
|
@@ -1285,12 +1292,13 @@ export class GLTFLoader {
|
|
1285
1292
|
* @returns A promise that resolves with the loaded Babylon animation group when the load is complete
|
1286
1293
|
*/
|
1287
1294
|
loadAnimationAsync(context, animation) {
|
1295
|
+
this._parent._startPerformanceCounter("Load animation");
|
1288
1296
|
const promise = this._extensionsLoadAnimationAsync(context, animation);
|
1289
1297
|
if (promise) {
|
1290
1298
|
return promise;
|
1291
1299
|
}
|
1292
1300
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
1293
|
-
return
|
1301
|
+
return LazyAnimationGroupModulePromise.value.then(({ AnimationGroup }) => {
|
1294
1302
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1295
1303
|
const babylonAnimationGroup = new AnimationGroup(animation.name || `animation${animation.index}`, this._babylonScene);
|
1296
1304
|
babylonAnimationGroup._parentContainer = this._assetContainer;
|
@@ -1306,6 +1314,7 @@ export class GLTFLoader {
|
|
1306
1314
|
babylonAnimationGroup.addTargetedAnimation(babylonAnimation, babylonTarget);
|
1307
1315
|
}));
|
1308
1316
|
}
|
1317
|
+
this._parent._endPerformanceCounter("Load animation");
|
1309
1318
|
return Promise.all(promises).then(() => {
|
1310
1319
|
babylonAnimationGroup.normalize(0);
|
1311
1320
|
return babylonAnimationGroup;
|
@@ -1322,58 +1331,59 @@ export class GLTFLoader {
|
|
1322
1331
|
* @param onLoad Called for each animation loaded
|
1323
1332
|
* @returns A void promise that resolves when the load is complete
|
1324
1333
|
*/
|
1325
|
-
|
1334
|
+
_loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
|
1326
1335
|
const promise = this._extensionsLoadAnimationChannelAsync(context, animationContext, animation, channel, onLoad);
|
1327
1336
|
if (promise) {
|
1328
|
-
return
|
1337
|
+
return promise;
|
1329
1338
|
}
|
1330
1339
|
if (channel.target.node == undefined) {
|
1331
|
-
return
|
1340
|
+
return Promise.resolve();
|
1332
1341
|
}
|
1333
1342
|
const targetNode = ArrayItem.Get(`${context}/target/node`, this._gltf.nodes, channel.target.node);
|
1334
1343
|
const channelTargetPath = channel.target.path;
|
1335
1344
|
const pathIsWeights = channelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */;
|
1336
1345
|
// Ignore animations that have no animation targets.
|
1337
1346
|
if ((pathIsWeights && !targetNode._numMorphTargets) || (!pathIsWeights && !targetNode._babylonTransformNode)) {
|
1338
|
-
return
|
1347
|
+
return Promise.resolve();
|
1339
1348
|
}
|
1340
1349
|
// Don't load node animations if disabled.
|
1341
1350
|
if (!this._parent.loadNodeAnimations && !pathIsWeights && !targetNode._isJoint) {
|
1342
|
-
return
|
1351
|
+
return Promise.resolve();
|
1343
1352
|
}
|
1344
1353
|
// async-load the animation sampler to provide the interpolation of the channelTargetPath
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1354
|
+
return LazyLoaderAnimationModulePromise.value.then(() => {
|
1355
|
+
let properties;
|
1356
|
+
switch (channelTargetPath) {
|
1357
|
+
case "translation" /* AnimationChannelTargetPath.TRANSLATION */: {
|
1358
|
+
properties = GetMappingForKey("/nodes/{}/translation")?.interpolation;
|
1359
|
+
break;
|
1360
|
+
}
|
1361
|
+
case "rotation" /* AnimationChannelTargetPath.ROTATION */: {
|
1362
|
+
properties = GetMappingForKey("/nodes/{}/rotation")?.interpolation;
|
1363
|
+
break;
|
1364
|
+
}
|
1365
|
+
case "scale" /* AnimationChannelTargetPath.SCALE */: {
|
1366
|
+
properties = GetMappingForKey("/nodes/{}/scale")?.interpolation;
|
1367
|
+
break;
|
1368
|
+
}
|
1369
|
+
case "weights" /* AnimationChannelTargetPath.WEIGHTS */: {
|
1370
|
+
properties = GetMappingForKey("/nodes/{}/weights")?.interpolation;
|
1371
|
+
break;
|
1372
|
+
}
|
1373
|
+
default: {
|
1374
|
+
throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);
|
1375
|
+
}
|
1363
1376
|
}
|
1364
|
-
|
1365
|
-
|
1377
|
+
// stay safe
|
1378
|
+
if (!properties) {
|
1379
|
+
throw new Error(`${context}/target/path: Could not find interpolation properties for target path (${channel.target.path})`);
|
1366
1380
|
}
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
object: targetNode,
|
1374
|
-
info: properties,
|
1375
|
-
};
|
1376
|
-
return await this._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
|
1381
|
+
const targetInfo = {
|
1382
|
+
object: targetNode,
|
1383
|
+
info: properties,
|
1384
|
+
};
|
1385
|
+
return this._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
|
1386
|
+
});
|
1377
1387
|
}
|
1378
1388
|
/**
|
1379
1389
|
* @hidden
|