A continuation from Load GLTF into AssetContainer from FilePicker window/File API object - Questions - Babylon.js
Using the FilesInput to collect all the required files for the GLTF to load worked correctly, and I was able to get everything to load. I’m now questioning my understanding of AssetContainers, as I keep ending up with an empty container.
I didn’t realize that the scene used to load files with the FilesInput is the reference for the assets in the container. My initial plan was to create a temporary scene to use with the FilesInput, move everything into a container, and then dispose of the scene.
async function containerCallback(file, loadedScene)
{
let newAssetContainer = new BABYLON.AssetContainer();
loadedScene.rootNodes.forEach(node =>
{
newAssetContainer.addAllAssetsToContainer(node);
});
await CacheAssetContainer({ filename: name }, newAssetContainer);
tempscene.dispose();
}
Currently, if I dispose of the scene, the container is empty. If I try to load into my main scene, I have no way (that I know of) to know which nodes were just added by the FilesInput.
What’s the actual correct way to load nodes and materials into an AssetContainer, and move them to a different scene?