From 983045196139021381a4b9b041eaadfdb70bf757 Mon Sep 17 00:00:00 2001 From: Abhinav <102739327+AbhinavHaridas@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:57:14 +0530 Subject: [PATCH] Update skybox.js --- Day 1/skybox.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Day 1/skybox.js b/Day 1/skybox.js index 778a70f..7e965c3 100644 --- a/Day 1/skybox.js +++ b/Day 1/skybox.js @@ -37,7 +37,14 @@ function init(){ let skyBox = new THREE.Mesh(skyBoxGeo, materialArray); //Mesh requires scene.add(skyBox); - window.addEventListener('resize', ()=>{window.location.reload()}); + // In the resize event handler, you are reloading the entire page when the window is resized. + // This approach may cause unnecessary resource reloads and reinitialization. Instead, consider updating the camera and + // renderer aspect ratio directly without reloading the whole page + window.addEventListener('resize', () => { + camera.aspect = window.innerWidth / window.innerHeight; + camera.updateProjectionMatrix(); + renderer.setSize(window.innerWidth, window.innerHeight); + }); } function animate() {