How to combine multiple scenes into one?

I am using this function
const scene = await BABYLON.SceneLoader.LoadAsync(“”, url);
in this the url hits multiple times and from that it extract the models from server and create a scene each time .I want when all the models are extracted I want to combine all the scenes to make a full complete model.

You should probably use the AssetContainer to load your assets:

https://doc.babylonjs.com/features/featuresDeepDive/importers/assetContainers

You will then be able to move everything in an existing scene.

1 Like

thanks for the response ,Actually with the screenloader I am able to create the scene but the problem is arising at the time of merging multiple scenes.

It is better to use the word “assets” here instead of “scene”.
Do as here and you will have no problems anymore :slight_smile: - Babylon.js Playground

2 Likes

ok will try…thanks…

I think we will need a repro in the Playground to be able to help. If you need to host your asset files so that they are available to the Playground, you can refer to:

https://doc.babylonjs.com/toolsAndResources/thePlayground/externalPGAssets

sorry for extending this question thread but i want to ask that is there any way like I have an array of scenes and i want to combine all the scene to make one single scene ??

It’s not possible. Instead of having your assets in a scene, you should load them in an asset container. This way, you can copy/move these assets from the container to a scene.

how can i store a the scenes in asset ?

async function combineScenes(scenesArray) {
const combinedScene = new BABYLON.Scene(engine);

// Iterate through each scene
scenesArray.forEach((scene) => {
    const container = new BABYLON.AssetContainer(scene);
    container.addAllToScene();
});
console.log("combinedScene", combinedScene);

}

I am using it like this is this correct ?

It would be more something like:

const container = new BABYLON.AssetContainer();
scenesArray.forEach((scene) => {
    container.scene = scene;
    container.removeAllFromScene();
});
container.scene = combinedScene;
container.addAllToScene();

You can try it, but I don’t know if changing the scene the container points to is expected to work…

cc @Deltakosh who may know better.

Do you use KTX textures?

no I am using png files

I think we need some test PG to start with :slight_smile: