How To Load New GLTF File After Deleting Previous File Content

Hi everyone, I am currently using the gltf importer code like below.

I want to bind it into a button. When a button is clicked, the scene content should be removed and it should show a different file. I tried it via scene.dispose() and recalling createScene with changing the file, but could not succeed in. It still loads the previous file. Is there any proper way to do it. When a button is clicked, I want to show only the next file without any object from the previous gltf.

static CreateScene(engine, canvas) {

                // This creates a basic Babylon Scene object (non-mesh)

                var scene = new BABYLON.Scene(engine);

                // This creates and positions a free camera (non-mesh)

                var camera = new BABYLON.FreeCamera(

                    "camera1",

                    new BABYLON.Vector3(3, 5, -10),

                    scene

                );

                // This targets the camera to scene origin

                camera.setTarget(BABYLON.Vector3.Zero());

                // This attaches the camera to the canvas

                camera.attachControl(canvas, true);

                // This creates a light, aiming 0,1,0 - to the sky (non-mesh)

                var light = new BABYLON.HemisphericLight(

                    "light1",

                    new BABYLON.Vector3(0, 1, 0),

                    scene

                );

                // Default intensity is 1. Let's dim the light a small amount

                light.intensity = 0.7;

               

                BABYLON.SceneLoader.Append(

                    "created_files/",

                    gltfFileList[listCounter],

                    scene,

                    function(nodeMesh) {

                       

                    }

                );
return scene;
}

Hi!
You can call mesh.dispose() to remove a mesh.

3 Likes

Thanks

1 Like