You’re right. I’ve kept it as you said:
scene.dispose();
preloadEvents(data.next.container);
and it loads a different scene when I go to a another page
Although, I’m having a small issue. I implemented the functionality from this post to move the camera (Best method for moving camera to target object - Questions - Babylon.js). It does work wonders on the first page but once I load a different page it doesn’t animate anymore. Here are the functions I took from the example. I also had to add my own ones to adjust it to my needs
var animateCameraTargetToPosition = function(cam, speed, frameCount, newPos) {
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
var animCam1 = BABYLON.Animation.CreateAndStartAnimation('at1', cam, 'target', speed, frameCount, cam.target, newPos, 0, ease);
animCam1.disposeOnEnd = true;
}
var animateCameraToPosition = function(cam, speed, frameCount, newPos) {
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
var animCam2 = BABYLON.Animation.CreateAndStartAnimation('at2', cam, 'position', speed, frameCount, cam.position, newPos, 0, ease);
animCam2.disposeOnEnd = true;
}
var speed = 60;
var frameCount = 200;
var setCamDefault = function() {
animateCameraTargetToPosition(camera, speed, frameCount, new BABYLON.Vector3(0, -15, 0));
animateCameraToPosition(camera, speed, frameCount, new BABYLON.Vector3(-40, 15, -45));
};
var setCamZoomedIn = function() {
animateCameraTargetToPosition(camera, speed, frameCount, new BABYLON.Vector3(35, -30, 80));
animateCameraToPosition(camera, speed, frameCount, new BABYLON.Vector3(-10, 10, -25));
};
function funcZoomIn() {
setCamZoomedIn();
jsBody.addClass("zoomedin");
}
function funcZoomOut() {
setCamDefault();
jsBody.removeClass("zoomedin");
}
ScrollTrigger.create({
trigger: ".hero_section",
start: "top center",
end: "bottom center",
markers: false,
onEnter: () => { funcZoomOut(); },
onLeave: () => { funcZoomIn(); },
onEnterBack: () => { funcZoomOut(); }
});
I added values in the console to all the above functions and they all get triggered perfectly fine so I don’t know what on earth is going on