mwg API
    Preparing search index...

    Function loadModelContainer3D

    • Loads a model once per resolved source and caches the in-flight/loaded AssetContainer, so a second call for the same source returns the same container instead of importing and parsing it again over the network. A container is not itself scene content - call container.instantiateModelsToScene() for each independent copy a game wants to place, which is Babylon's own way to get several unaliased instances of one loaded model without a second fetch; loadModel3D imports straight into the scene instead, for the common case of only ever wanting one copy.

      Only caches when source is a string (an asset path or already-resolved URI) - a File or in-memory byte view has no stable identity to key a cache on, so those always load fresh, the same way loadModel3D never tries to resolve them as a path either.

      Parameters

      • source: ModelSource3D
      • scene: Scene
      • Optionaloptions: LoadAssetContainerOptions

      Returns Promise<AssetContainer>

      import { loadModelContainer3D, isModelContainerLoaded, releaseModelContainer } from '@datamoc/mwg/3d/models';

      declare const scene: import('@babylonjs/core/scene.js').Scene;

      const container = await loadModelContainer3D('models/tree.glb', scene);
      const treeA = container.instantiateModelsToScene();
      const treeB = container.instantiateModelsToScene(); // a second, independent copy - no re-fetch

      console.log(isModelContainerLoaded('models/tree.glb')); // true
      releaseModelContainer('models/tree.glb'); // frees the container once every copy is placed