Moving files into AssetContainer from scene after FilesInput.loadFiles

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?

cc @alexchuber

Yeah, all resources are actually managed at the scene level. It’s not obvious from the default constructor, but the AssetContainer is tied to the active scene at creation time.

Moving the contents of an AssetContainer into a different scene is really a question of moving assets from one scene to another. The only way I can think of doing this is via serialization: export the old scene as .gltf or .babylon, then re-import it back into the new scene. See this thread for more discussion:


Could you explain what the second scene is for? Maybe we can come up with something more elegant, depending on what your goal is :slight_smile: