An AssetContainer can be used to manage a list of assets (like nodes, cameras, lights, meshes, etc..). This assets are still linked to a scene but are not taken in account. Consider asset containers like pool of entities.
It can be created manually
var container = new BABYLON.AssetContainer(scene);
Or by loading from a file. See loading from files
The container can then be used to add or remove contents of the container from the scene.
// Add all objects in the asset container to the scene
container.addAllToScene()
// Remove all objects in the container from the scene
container.removeAllFromScene()
Demo -
When creating assets manually the moveAllFromScene method can be used to move all assets currently in a scene into an AssetContainer and remove them from the scene for later use.
var keepAssets = new BABYLON.KeepAssets();
keepAssets.cameras.push(camera);
container.moveAllFromScene(keepAssets);
Demo -
Asset containers can also be used as "templates" to duplicate models without reloading them.
To do so, you only need to call:
let entries = container.instantiateModelsToScene();
The return entries object will contain:
Demo -
You can also set two parameters to the call to instantiateModelsToScene
:
var entries = container.instantiateModelsToScene(name => "p" + name, true);