diff --git a/js/scene.js b/js/scene.js index 24a557e..1ecadf6 100644 --- a/js/scene.js +++ b/js/scene.js @@ -1,6 +1,6 @@ // Global ATON -import { getSceneStatus, setSceneStatus } from "./state.js"; +import { AppState, getSceneStatus, setSceneStatus } from "./state.js"; const material = { color: "#fff", @@ -43,6 +43,8 @@ Scene.changeLightDirection = function(vector) { */ Scene.toggleAmbientOcclusion = function(isEnabled) { ATON.FX.togglePass(ATON.FX.PASS_AO, isEnabled); + console.log('Ambient occlusion', isEnabled ? 'ON' : 'OFF'); + AppState.ambientOcclusion = isEnabled; } /** @@ -101,17 +103,20 @@ Scene.toggleSettingsPanel = function(id) { const ambientOcclSwitch = document.createElement('div'); ambientOcclSwitch.className = 'form-check form-switch ms-4 mt-2'; ambientOcclSwitch.innerHTML = ` - - + + `; const shadowsSwitch = document.createElement('div'); shadowsSwitch.className = 'form-check form-switch ms-4 mt-2'; shadowsSwitch.innerHTML = ` - - + + `; + shadowsSwitch.querySelector('input[type="checkbox"').checked = AppState.shadows; + ambientOcclSwitch.querySelector('input[type="checkbox"').checked = AppState.ambientOcclusion; + ATON.UI.elSidePanel.appendChild(ambientOcclSwitch); ATON.UI.elSidePanel.appendChild(shadowsSwitch); // TODO: move somewhere else... @@ -124,7 +129,9 @@ Scene.toggleSettingsPanel = function(id) { document.querySelector('#shadowsSwitch').addEventListener( 'change', event => { - ATON.toggleShadows(event.target.checked); + const checked = event.target.checked; + ATON.toggleShadows(checked); + AppState.shadows = checked; } ); }); @@ -155,6 +162,9 @@ Scene.toggleScene = function(id) { btn.addEventListener('click', () => { scene.classList.toggle('d-none'); + // Pause rendering the 3D scene to free resources (hopefully) + // when browsing the map + ATON.renderPause(); document.querySelector('#map').classList.toggle('d-none'); }); } @@ -171,6 +181,7 @@ Scene.openScene = function(marker) { } scene.classList.toggle('d-none'); + ATON.renderResume(); if (!getSceneStatus(marker.id)) { // Set scene as active diff --git a/js/state.js b/js/state.js index 983dc58..a67341f 100644 --- a/js/state.js +++ b/js/state.js @@ -5,6 +5,8 @@ export const AppState = { active : false } ], + ambientOcclusion : true, + shadows : true, } /**