Hello everyone I am trying to understand how to restart a scene, for that I have the following code example.
var canvas: HTMLCanvasElement = document.getElementById("renderCanvas") as HTMLCanvasElement;;
var engine: BABYLON.Engine = new BABYLON.Engine(canvas, true);
function NewScene() {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
scene.debugLayer.show();
console.log("¡¡INIT!!");
// This creates and positions an arc rotate camera (non-mesh)
var camera = new BABYLON.ArcRotateCamera("Camera", BABYLON.Tools.ToRadians(90), BABYLON.Tools.ToRadians(90), 5, new BABYLON.Vector3(0, 0, 0), scene);
camera.attachControl(canvas, false);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
//Observable to know when it starts,
//does not work when calling function again
scene.onReadyObservable.add(function (){
console.log("init the scene ")
})
return scene;
};
//I create the new scene and save it in a variable
var iniciarEscena:BABYLON.Scene = NewScene();
//if i press click i make the variable
//call the function again
window.addEventListener("click", function () {
iniciarEscena = NewScene();// I call it again in the variable
console.log("reinicie la escnea")
});
//principal renderLoop
engine.runRenderLoop(function ()
{
iniciarEscena.render();
});
I mean, as you can see, what I do is press click and call the variable again.
and I have an observable to check when the scene starts
However it doesn’t work
How can I verify that the scene was restarted and started correctly?
I see strange things, I mean the scene restarts, but it does not show the messages by console when verifying that the scene was reloaded
IF I create a custom observable it doesn’t work either or it works 1 time only.