@babylonjs/core 7.48.0 → 7.48.2

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 (38) hide show
  1. package/Buffers/bufferUtils.d.ts +6 -0
  2. package/Buffers/bufferUtils.js.map +1 -1
  3. package/Cameras/camera.d.ts +1 -1
  4. package/Cameras/camera.js +1 -1
  5. package/Cameras/camera.js.map +1 -1
  6. package/DeviceInput/webDeviceInputSystem.d.ts +2 -0
  7. package/DeviceInput/webDeviceInputSystem.js +29 -13
  8. package/DeviceInput/webDeviceInputSystem.js.map +1 -1
  9. package/Engines/Extensions/engine.rawTexture.js +4 -0
  10. package/Engines/Extensions/engine.rawTexture.js.map +1 -1
  11. package/Engines/abstractEngine.js +2 -2
  12. package/Engines/abstractEngine.js.map +1 -1
  13. package/Engines/nativeEngine.js +2 -2
  14. package/Engines/nativeEngine.js.map +1 -1
  15. package/Loading/sceneLoader.d.ts +61 -5
  16. package/Loading/sceneLoader.js +156 -63
  17. package/Loading/sceneLoader.js.map +1 -1
  18. package/Materials/Textures/Filtering/hdrFiltering.d.ts +1 -3
  19. package/Materials/Textures/Filtering/hdrFiltering.js +8 -18
  20. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  21. package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +1 -3
  22. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +11 -27
  23. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -1
  24. package/Materials/effect.d.ts +5 -0
  25. package/Materials/effect.js +9 -0
  26. package/Materials/effect.js.map +1 -1
  27. package/Meshes/Compression/dracoCompressionWorker.js +14 -1
  28. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
  29. package/Meshes/Compression/dracoEncoder.js +8 -11
  30. package/Meshes/Compression/dracoEncoder.js.map +1 -1
  31. package/Meshes/Compression/dracoEncoder.types.d.ts +2 -1
  32. package/Meshes/Compression/dracoEncoder.types.js.map +1 -1
  33. package/Misc/dumpTools.js +5 -0
  34. package/Misc/dumpTools.js.map +1 -1
  35. package/Misc/environmentTextureTools.d.ts +77 -13
  36. package/Misc/environmentTextureTools.js +205 -68
  37. package/Misc/environmentTextureTools.js.map +1 -1
  38. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { Observable } from "../Misc/observable";
2
- import type { Nullable } from "../types";
2
+ import type { DeepImmutable, Nullable } from "../types";
3
3
  import { Scene } from "../scene";
4
4
  import type { AbstractMesh } from "../Meshes/abstractMesh";
5
5
  import type { AnimationGroup } from "../Animations/animationGroup";
@@ -351,10 +351,39 @@ export interface ImportAnimationsOptions extends SceneLoaderOptions {
351
351
  * Adds a new plugin to the list of registered plugins
352
352
  * @param plugin defines the plugin to add
353
353
  */
354
+ export declare function RegisterSceneLoaderPlugin(plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory): void;
355
+ /**
356
+ * Adds a new plugin to the list of registered plugins
357
+ * @deprecated Please use `RegisterSceneLoaderPlugin` instead.
358
+ * @param plugin defines the plugin to add
359
+ */
354
360
  export declare function registerSceneLoaderPlugin(plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory): void;
361
+ /**
362
+ * Gets metadata for all currently registered scene loader plugins.
363
+ * @returns An array where each entry has metadata for a single scene loader plugin.
364
+ */
365
+ export declare function GetRegisteredSceneLoaderPluginMetadata(): DeepImmutable<Array<Pick<ISceneLoaderPluginMetadata, "name"> & {
366
+ /**
367
+ * The extensions supported by the plugin.
368
+ */
369
+ extensions: ({
370
+ /**
371
+ * The file extension.
372
+ */
373
+ extension: string;
374
+ } & ISceneLoaderPluginExtensions[string])[];
375
+ }>>;
355
376
  /**
356
377
  * Load a scene
357
- * @experimental
378
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
379
+ * @param engine is the instance of BABYLON.Engine to use to create the scene
380
+ * @param options an object that configures aspects of how the scene is loaded
381
+ * @returns The loaded scene
382
+ */
383
+ export declare function LoadSceneAsync(source: SceneSource, engine: AbstractEngine, options?: LoadOptions): Promise<Scene>;
384
+ /**
385
+ * Load a scene
386
+ * @deprecated Please use `LoadSceneAsync` instead.
358
387
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
359
388
  * @param engine is the instance of BABYLON.Engine to use to create the scene
360
389
  * @param options an object that configures aspects of how the scene is loaded
@@ -363,15 +392,32 @@ export declare function registerSceneLoaderPlugin(plugin: ISceneLoaderPlugin | I
363
392
  export declare function loadSceneAsync(source: SceneSource, engine: AbstractEngine, options?: LoadOptions): Promise<Scene>;
364
393
  /**
365
394
  * Append a scene
366
- * @experimental
367
395
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
368
396
  * @param scene is the instance of BABYLON.Scene to append to
369
397
  * @param options an object that configures aspects of how the scene is loaded
398
+ * @returns A promise that resolves when the scene is appended
399
+ */
400
+ export declare function AppendSceneAsync(source: SceneSource, scene: Scene, options?: AppendOptions): Promise<void>;
401
+ /**
402
+ * Append a scene
403
+ * @deprecated Please use `AppendSceneAsync` instead.
404
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
405
+ * @param scene is the instance of BABYLON.Scene to append to
406
+ * @param options an object that configures aspects of how the scene is loaded
407
+ * @returns A promise that resolves when the scene is appended
370
408
  */
371
409
  export declare function appendSceneAsync(source: SceneSource, scene: Scene, options?: AppendOptions): Promise<void>;
372
410
  /**
373
411
  * Load a scene into an asset container
374
- * @experimental
412
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
413
+ * @param scene is the instance of Scene to append to
414
+ * @param options an object that configures aspects of how the scene is loaded
415
+ * @returns The loaded asset container
416
+ */
417
+ export declare function LoadAssetContainerAsync(source: SceneSource, scene: Scene, options?: LoadAssetContainerOptions): Promise<AssetContainer>;
418
+ /**
419
+ * Load a scene into an asset container
420
+ * @deprecated Please use `LoadAssetContainerAsync` instead.
375
421
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
376
422
  * @param scene is the instance of Scene to append to
377
423
  * @param options an object that configures aspects of how the scene is loaded
@@ -380,15 +426,25 @@ export declare function appendSceneAsync(source: SceneSource, scene: Scene, opti
380
426
  export declare function loadAssetContainerAsync(source: SceneSource, scene: Scene, options?: LoadAssetContainerOptions): Promise<AssetContainer>;
381
427
  /**
382
428
  * Import animations from a file into a scene
383
- * @experimental
384
429
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
385
430
  * @param scene is the instance of BABYLON.Scene to append to
386
431
  * @param options an object that configures aspects of how the scene is loaded
432
+ * @returns A promise that resolves when the animations are imported
433
+ */
434
+ export declare function ImportAnimationsAsync(source: SceneSource, scene: Scene, options?: ImportAnimationsOptions): Promise<void>;
435
+ /**
436
+ * Import animations from a file into a scene
437
+ * @deprecated Please use `ImportAnimationsAsync` instead.
438
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
439
+ * @param scene is the instance of BABYLON.Scene to append to
440
+ * @param options an object that configures aspects of how the scene is loaded
441
+ * @returns A promise that resolves when the animations are imported
387
442
  */
388
443
  export declare function importAnimationsAsync(source: SceneSource, scene: Scene, options?: ImportAnimationsOptions): Promise<void>;
389
444
  /**
390
445
  * Class used to load scene from various file formats using registered plugins
391
446
  * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes
447
+ * @deprecated The module level functions (such as LoadAssetContainerAsync) are more efficient for bundler tree shaking and allow plugin options to be passed through. Future improvements to scene loading will primarily be in the module level functions. The SceneLoader class will remain available, but it will be beneficial to prefer the module level functions.
392
448
  */
393
449
  export declare class SceneLoader {
394
450
  /**
@@ -294,7 +294,7 @@ function _getFileInfo(rootUrl, sceneSource) {
294
294
  * Adds a new plugin to the list of registered plugins
295
295
  * @param plugin defines the plugin to add
296
296
  */
297
- export function registerSceneLoaderPlugin(plugin) {
297
+ export function RegisterSceneLoaderPlugin(plugin) {
298
298
  if (typeof plugin.extensions === "string") {
299
299
  const extension = plugin.extensions;
300
300
  registeredPlugins[extension.toLowerCase()] = {
@@ -313,6 +313,28 @@ export function registerSceneLoaderPlugin(plugin) {
313
313
  });
314
314
  }
315
315
  }
316
+ /**
317
+ * Adds a new plugin to the list of registered plugins
318
+ * @deprecated Please use `RegisterSceneLoaderPlugin` instead.
319
+ * @param plugin defines the plugin to add
320
+ */
321
+ export function registerSceneLoaderPlugin(plugin) {
322
+ RegisterSceneLoaderPlugin(plugin);
323
+ }
324
+ /**
325
+ * Gets metadata for all currently registered scene loader plugins.
326
+ * @returns An array where each entry has metadata for a single scene loader plugin.
327
+ */
328
+ export function GetRegisteredSceneLoaderPluginMetadata() {
329
+ return Array.from(Object.entries(registeredPlugins).reduce((pluginMap, [extension, extensionRegistration]) => {
330
+ let pluginMetadata = pluginMap.get(extensionRegistration.plugin.name);
331
+ if (!pluginMetadata) {
332
+ pluginMap.set(extensionRegistration.plugin.name, (pluginMetadata = []));
333
+ }
334
+ pluginMetadata.push({ extension, isBinary: extensionRegistration.isBinary, mimeType: extensionRegistration.mimeType });
335
+ return pluginMap;
336
+ }, new Map())).map(([name, extensions]) => ({ name, extensions }));
337
+ }
316
338
  async function importMeshAsync(meshNames, rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
317
339
  if (!scene) {
318
340
  Logger.Error("No scene available to import mesh to");
@@ -391,51 +413,69 @@ async function importMeshAsync(meshNames, rootUrl, sceneFilename = "", scene = E
391
413
  }
392
414
  function importMeshAsyncCore(meshNames, rootUrl, sceneFilename, scene, onProgress, pluginExtension, name, pluginOptions) {
393
415
  return new Promise((resolve, reject) => {
394
- importMeshAsync(meshNames, rootUrl, sceneFilename, scene, (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights, spriteManagers) => {
395
- resolve({
396
- meshes: meshes,
397
- particleSystems: particleSystems,
398
- skeletons: skeletons,
399
- animationGroups: animationGroups,
400
- transformNodes: transformNodes,
401
- geometries: geometries,
402
- lights: lights,
403
- spriteManagers: spriteManagers,
404
- });
405
- }, onProgress, (scene, message, exception) => {
406
- reject(exception || new Error(message));
407
- }, pluginExtension, name, pluginOptions);
416
+ try {
417
+ importMeshAsync(meshNames, rootUrl, sceneFilename, scene, (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights, spriteManagers) => {
418
+ resolve({
419
+ meshes: meshes,
420
+ particleSystems: particleSystems,
421
+ skeletons: skeletons,
422
+ animationGroups: animationGroups,
423
+ transformNodes: transformNodes,
424
+ geometries: geometries,
425
+ lights: lights,
426
+ spriteManagers: spriteManagers,
427
+ });
428
+ }, onProgress, (scene, message, exception) => {
429
+ reject(exception || new Error(message));
430
+ }, pluginExtension, name, pluginOptions).catch(reject);
431
+ }
432
+ catch (error) {
433
+ reject(error);
434
+ }
408
435
  });
409
436
  }
410
- function loadScene(rootUrl, sceneFilename = "", engine = EngineStore.LastCreatedEngine, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
437
+ // This is the core implementation of load scene
438
+ async function loadSceneImplAsync(rootUrl, sceneFilename = "", engine = EngineStore.LastCreatedEngine, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
411
439
  if (!engine) {
412
440
  Tools.Error("No engine available");
413
441
  return;
414
442
  }
415
- appendAsync(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension, name, pluginOptions);
443
+ await appendSceneImplAsync(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension, name, pluginOptions);
416
444
  }
417
445
  /**
418
446
  * Load a scene
419
- * @experimental
420
447
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
421
448
  * @param engine is the instance of BABYLON.Engine to use to create the scene
422
449
  * @param options an object that configures aspects of how the scene is loaded
423
450
  * @returns The loaded scene
424
451
  */
425
- export function loadSceneAsync(source, engine, options) {
452
+ export function LoadSceneAsync(source, engine, options) {
426
453
  const { rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = options ?? {};
427
- return loadSceneAsyncCore(rootUrl, source, engine, onProgress, pluginExtension, name, pluginOptions);
454
+ return loadSceneSharedAsync(rootUrl, source, engine, onProgress, pluginExtension, name, pluginOptions);
428
455
  }
429
- function loadSceneAsyncCore(rootUrl, sceneFilename, engine, onProgress, pluginExtension, name, pluginOptions) {
456
+ /**
457
+ * Load a scene
458
+ * @deprecated Please use `LoadSceneAsync` instead.
459
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
460
+ * @param engine is the instance of BABYLON.Engine to use to create the scene
461
+ * @param options an object that configures aspects of how the scene is loaded
462
+ * @returns The loaded scene
463
+ */
464
+ export function loadSceneAsync(source, engine, options) {
465
+ return LoadSceneAsync(source, engine, options);
466
+ }
467
+ // This function is shared between the new module level loadSceneAsync and the legacy SceneLoader.LoadAsync
468
+ function loadSceneSharedAsync(rootUrl, sceneFilename, engine, onProgress, pluginExtension, name, pluginOptions) {
430
469
  return new Promise((resolve, reject) => {
431
- loadScene(rootUrl, sceneFilename, engine, (scene) => {
470
+ loadSceneImplAsync(rootUrl, sceneFilename, engine, (scene) => {
432
471
  resolve(scene);
433
472
  }, onProgress, (scene, message, exception) => {
434
473
  reject(exception || new Error(message));
435
474
  }, pluginExtension, name, pluginOptions);
436
475
  });
437
476
  }
438
- async function appendAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
477
+ // This is the core implementation of append scene
478
+ async function appendSceneImplAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
439
479
  if (!scene) {
440
480
  Logger.Error("No scene available to append to");
441
481
  return null;
@@ -514,25 +554,43 @@ async function appendAsync(rootUrl, sceneFilename = "", scene = EngineStore.Last
514
554
  }
515
555
  /**
516
556
  * Append a scene
517
- * @experimental
518
557
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
519
558
  * @param scene is the instance of BABYLON.Scene to append to
520
559
  * @param options an object that configures aspects of how the scene is loaded
560
+ * @returns A promise that resolves when the scene is appended
521
561
  */
522
- export async function appendSceneAsync(source, scene, options) {
562
+ export async function AppendSceneAsync(source, scene, options) {
523
563
  const { rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = options ?? {};
524
- await appendSceneAsyncCore(rootUrl, source, scene, onProgress, pluginExtension, name, pluginOptions);
564
+ await appendSceneSharedAsync(rootUrl, source, scene, onProgress, pluginExtension, name, pluginOptions);
565
+ }
566
+ /**
567
+ * Append a scene
568
+ * @deprecated Please use `AppendSceneAsync` instead.
569
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
570
+ * @param scene is the instance of BABYLON.Scene to append to
571
+ * @param options an object that configures aspects of how the scene is loaded
572
+ * @returns A promise that resolves when the scene is appended
573
+ */
574
+ export function appendSceneAsync(source, scene, options) {
575
+ return AppendSceneAsync(source, scene, options);
525
576
  }
526
- function appendSceneAsyncCore(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name, pluginOptions) {
577
+ // This function is shared between the new module level appendSceneAsync and the legacy SceneLoader.AppendAsync
578
+ function appendSceneSharedAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name, pluginOptions) {
527
579
  return new Promise((resolve, reject) => {
528
- appendAsync(rootUrl, sceneFilename, scene, (scene) => {
529
- resolve(scene);
530
- }, onProgress, (scene, message, exception) => {
531
- reject(exception || new Error(message));
532
- }, pluginExtension, name, pluginOptions);
580
+ try {
581
+ appendSceneImplAsync(rootUrl, sceneFilename, scene, (scene) => {
582
+ resolve(scene);
583
+ }, onProgress, (scene, message, exception) => {
584
+ reject(exception || new Error(message));
585
+ }, pluginExtension, name, pluginOptions).catch(reject);
586
+ }
587
+ catch (error) {
588
+ reject(error);
589
+ }
533
590
  });
534
591
  }
535
- async function loadAssetContainerCoreAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
592
+ // This is the core implementation of load asset container
593
+ async function loadAssetContainerImplAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
536
594
  if (!scene) {
537
595
  Logger.Error("No scene available to load asset container to");
538
596
  return null;
@@ -609,26 +667,43 @@ async function loadAssetContainerCoreAsync(rootUrl, sceneFilename = "", scene =
609
667
  }
610
668
  /**
611
669
  * Load a scene into an asset container
612
- * @experimental
613
670
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
614
671
  * @param scene is the instance of Scene to append to
615
672
  * @param options an object that configures aspects of how the scene is loaded
616
673
  * @returns The loaded asset container
617
674
  */
618
- export function loadAssetContainerAsync(source, scene, options) {
675
+ export function LoadAssetContainerAsync(source, scene, options) {
619
676
  const { rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = options ?? {};
620
- return internalLoadAssetContainerAsync(rootUrl, source, scene, onProgress, pluginExtension, name, pluginOptions);
677
+ return loadAssetContainerSharedAsync(rootUrl, source, scene, onProgress, pluginExtension, name, pluginOptions);
621
678
  }
622
- function internalLoadAssetContainerAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name, pluginOptions) {
679
+ /**
680
+ * Load a scene into an asset container
681
+ * @deprecated Please use `LoadAssetContainerAsync` instead.
682
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
683
+ * @param scene is the instance of Scene to append to
684
+ * @param options an object that configures aspects of how the scene is loaded
685
+ * @returns The loaded asset container
686
+ */
687
+ export function loadAssetContainerAsync(source, scene, options) {
688
+ return LoadAssetContainerAsync(source, scene, options);
689
+ }
690
+ // This function is shared between the new module level loadAssetContainerAsync and the legacy SceneLoader.LoadAssetContainerAsync
691
+ function loadAssetContainerSharedAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name, pluginOptions) {
623
692
  return new Promise((resolve, reject) => {
624
- loadAssetContainerCoreAsync(rootUrl, sceneFilename, scene, (assets) => {
625
- resolve(assets);
626
- }, onProgress, (scene, message, exception) => {
627
- reject(exception || new Error(message));
628
- }, pluginExtension, name, pluginOptions);
693
+ try {
694
+ loadAssetContainerImplAsync(rootUrl, sceneFilename, scene, (assets) => {
695
+ resolve(assets);
696
+ }, onProgress, (scene, message, exception) => {
697
+ reject(exception || new Error(message));
698
+ }, pluginExtension, name, pluginOptions).catch(reject);
699
+ }
700
+ catch (error) {
701
+ reject(error);
702
+ }
629
703
  });
630
704
  }
631
- function importAnimations(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = 0 /* SceneLoaderAnimationGroupLoadingMode.Clean */, targetConverter = null, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
705
+ // This is the core implementation of import animations
706
+ async function importAnimationsImplAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = 0 /* SceneLoaderAnimationGroupLoadingMode.Clean */, targetConverter = null, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
632
707
  if (!scene) {
633
708
  Logger.Error("No scene available to load animations to");
634
709
  return;
@@ -684,31 +759,49 @@ function importAnimations(rootUrl, sceneFilename = "", scene = EngineStore.LastC
684
759
  onSuccess(scene);
685
760
  }
686
761
  };
687
- loadAssetContainerCoreAsync(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError, pluginExtension, name, pluginOptions);
762
+ await loadAssetContainerImplAsync(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError, pluginExtension, name, pluginOptions);
688
763
  }
689
764
  /**
690
765
  * Import animations from a file into a scene
691
- * @experimental
692
766
  * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
693
767
  * @param scene is the instance of BABYLON.Scene to append to
694
768
  * @param options an object that configures aspects of how the scene is loaded
769
+ * @returns A promise that resolves when the animations are imported
695
770
  */
696
- export async function importAnimationsAsync(source, scene, options) {
771
+ export async function ImportAnimationsAsync(source, scene, options) {
697
772
  const { rootUrl = "", overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name, pluginOptions } = options ?? {};
698
- await importAnimationsAsyncCore(rootUrl, source, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name, pluginOptions);
773
+ await importAnimationsSharedAsync(rootUrl, source, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name, pluginOptions);
699
774
  }
700
- function importAnimationsAsyncCore(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name, pluginOptions) {
775
+ /**
776
+ * Import animations from a file into a scene
777
+ * @deprecated Please use `ImportAnimationsAsync` instead.
778
+ * @param source a string that defines the name of the scene file, or starts with "data:" following by the stringified version of the scene, or a File object, or an ArrayBufferView
779
+ * @param scene is the instance of BABYLON.Scene to append to
780
+ * @param options an object that configures aspects of how the scene is loaded
781
+ * @returns A promise that resolves when the animations are imported
782
+ */
783
+ export function importAnimationsAsync(source, scene, options) {
784
+ return ImportAnimationsAsync(source, scene, options);
785
+ }
786
+ // This function is shared between the new module level importAnimationsAsync and the legacy SceneLoader.ImportAnimationsAsync
787
+ function importAnimationsSharedAsync(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name, pluginOptions) {
701
788
  return new Promise((resolve, reject) => {
702
- importAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, (scene) => {
703
- resolve(scene);
704
- }, onProgress, (scene, message, exception) => {
705
- reject(exception || new Error(message));
706
- }, pluginExtension, name, pluginOptions);
789
+ try {
790
+ importAnimationsImplAsync(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, (scene) => {
791
+ resolve(scene);
792
+ }, onProgress, (scene, message, exception) => {
793
+ reject(exception || new Error(message));
794
+ }, pluginExtension, name, pluginOptions).catch(reject);
795
+ }
796
+ catch (error) {
797
+ reject(error);
798
+ }
707
799
  });
708
800
  }
709
801
  /**
710
802
  * Class used to load scene from various file formats using registered plugins
711
803
  * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes
804
+ * @deprecated The module level functions (such as LoadAssetContainerAsync) are more efficient for bundler tree shaking and allow plugin options to be passed through. Future improvements to scene loading will primarily be in the module level functions. The SceneLoader class will remain available, but it will be beneficial to prefer the module level functions.
712
805
  */
713
806
  export class SceneLoader {
714
807
  /**
@@ -779,7 +872,7 @@ export class SceneLoader {
779
872
  * @param plugin defines the plugin to add
780
873
  */
781
874
  static RegisterPlugin(plugin) {
782
- registerSceneLoaderPlugin(plugin);
875
+ RegisterSceneLoaderPlugin(plugin);
783
876
  }
784
877
  /**
785
878
  * Import meshes into a scene
@@ -795,7 +888,7 @@ export class SceneLoader {
795
888
  * @deprecated Please use ImportMeshAsync instead
796
889
  */
797
890
  static ImportMesh(meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name) {
798
- importMeshAsync(meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name);
891
+ importMeshAsync(meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name).catch((error) => onError?.(EngineStore.LastCreatedScene, error?.message, error));
799
892
  }
800
893
  /**
801
894
  * Import meshes into a scene
@@ -824,7 +917,7 @@ export class SceneLoader {
824
917
  * @deprecated Please use LoadAsync instead
825
918
  */
826
919
  static Load(rootUrl, sceneFilename, engine, onSuccess, onProgress, onError, pluginExtension, name) {
827
- loadScene(rootUrl, sceneFilename, engine, onSuccess, onProgress, onError, pluginExtension, name);
920
+ loadSceneImplAsync(rootUrl, sceneFilename, engine, onSuccess, onProgress, onError, pluginExtension, name).catch((error) => onError?.(EngineStore.LastCreatedScene, error?.message, error));
828
921
  }
829
922
  /**
830
923
  * Load a scene
@@ -837,7 +930,7 @@ export class SceneLoader {
837
930
  * @returns The loaded scene
838
931
  */
839
932
  static LoadAsync(rootUrl, sceneFilename, engine, onProgress, pluginExtension, name) {
840
- return loadSceneAsyncCore(rootUrl, sceneFilename, engine, onProgress, pluginExtension, name);
933
+ return loadSceneSharedAsync(rootUrl, sceneFilename, engine, onProgress, pluginExtension, name);
841
934
  }
842
935
  /**
843
936
  * Append a scene
@@ -852,7 +945,7 @@ export class SceneLoader {
852
945
  * @deprecated Please use AppendAsync instead
853
946
  */
854
947
  static Append(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name) {
855
- appendAsync(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name);
948
+ appendSceneImplAsync(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name).catch((error) => onError?.((scene ?? EngineStore.LastCreatedScene), error?.message, error));
856
949
  }
857
950
  /**
858
951
  * Append a scene
@@ -865,7 +958,7 @@ export class SceneLoader {
865
958
  * @returns The given scene
866
959
  */
867
960
  static AppendAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name) {
868
- return appendSceneAsyncCore(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name);
961
+ return appendSceneSharedAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name);
869
962
  }
870
963
  /**
871
964
  * Load a scene into an asset container
@@ -880,7 +973,7 @@ export class SceneLoader {
880
973
  * @deprecated Please use LoadAssetContainerAsync instead
881
974
  */
882
975
  static LoadAssetContainer(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name) {
883
- loadAssetContainerCoreAsync(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name);
976
+ loadAssetContainerImplAsync(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name).catch((error) => onError?.((scene ?? EngineStore.LastCreatedScene), error?.message, error));
884
977
  }
885
978
  /**
886
979
  * Load a scene into an asset container
@@ -893,7 +986,7 @@ export class SceneLoader {
893
986
  * @returns The loaded asset container
894
987
  */
895
988
  static LoadAssetContainerAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name) {
896
- return internalLoadAssetContainerAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name);
989
+ return loadAssetContainerSharedAsync(rootUrl, sceneFilename, scene, onProgress, pluginExtension, name);
897
990
  }
898
991
  /**
899
992
  * Import animations from a file into a scene
@@ -911,7 +1004,7 @@ export class SceneLoader {
911
1004
  * @deprecated Please use ImportAnimationsAsync instead
912
1005
  */
913
1006
  static ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onSuccess, onProgress, onError, pluginExtension, name) {
914
- importAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onSuccess, onProgress, onError, pluginExtension, name);
1007
+ importAnimationsImplAsync(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onSuccess, onProgress, onError, pluginExtension, name).catch((error) => onError?.((scene ?? EngineStore.LastCreatedScene), error?.message, error));
915
1008
  }
916
1009
  /**
917
1010
  * Import animations from a file into a scene
@@ -933,7 +1026,7 @@ export class SceneLoader {
933
1026
  onSuccess, onProgress,
934
1027
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
935
1028
  onError, pluginExtension, name) {
936
- return importAnimationsAsyncCore(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name);
1029
+ return importAnimationsSharedAsync(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name);
937
1030
  }
938
1031
  }
939
1032
  /**