diff --git a/js/scene.js b/js/scene.js index daea1ff..d354c41 100644 --- a/js/scene.js +++ b/js/scene.js @@ -42,6 +42,7 @@ function init () { AppState.camera = ATON.Nav._camera; AppState.renderer = ATON._renderer; AppState.shadows = config.scene.shadows; + AppState.lightDirection = ATON.getMainLightDirection(); ATON.Nav.setUserControl(true); } diff --git a/js/state.js b/js/state.js index 7300779..05980bc 100644 --- a/js/state.js +++ b/js/state.js @@ -20,7 +20,7 @@ let AppState = { // {id: String, active: Boolean} nodes: [], /** - * @property {NormalizedSceneNode[]} normalizedNodes + * @type {NormalizedSceneNode[]} normalizedNodes */ normalizedNodes: [], mainNodeId: null, @@ -28,6 +28,7 @@ let AppState = { sceneHasAudio: false, layersMenuBuilt: false, initialRotation: null, + lightDirection: [], camera: null, renderer: null, ambientOcclusion : true, diff --git a/js/utils/environment.js b/js/utils/environment.js index 4adfb20..f4f1a8a 100644 --- a/js/utils/environment.js +++ b/js/utils/environment.js @@ -1,5 +1,7 @@ // Global ATON and THREE +import AppState from "../state.js"; + /** * @module Environment */ @@ -28,16 +30,21 @@ export function toggleAmbientOcclusion(isEnabled) { * @param {Number} step - The slider's step */ export function createLightSlider(direction, label, range, step) { - const currentVal = ATON.getMainLightDirection()[direction]; + const currentVal = AppState.lightDirection[direction]; + + console.debug(currentVal); + const lightSlider = ATON.UI.createSlider({ range, label, - value: Number.parseFloat(currentVal).toPrecision(1), + value: Number.parseFloat(currentVal).toPrecision(2), oninput: val => { - const lightDir = ATON.getMainLightDirection(); + const lightDir = AppState.lightDirection; + // Keep existing direction values for the other axes lightDir[direction] = Number.parseFloat(val); changeLightDirection(lightDir); + AppState.lightDirection = lightDir; }, });