Compare commits
2 Commits
becb0865b9
...
380999ff4b
| Author | SHA1 | Date | |
|---|---|---|---|
| 380999ff4b | |||
| d0d24c0e6c |
@@ -1,7 +1,7 @@
|
|||||||
// Global ATON
|
// Global ATON
|
||||||
import { Controller } from "@hotwired/stimulus"
|
import { Controller } from "@hotwired/stimulus"
|
||||||
import AppState from "../state.js";
|
import AppState from "../state.js";
|
||||||
import { createLightSlider } from "../utils/environment.js";
|
import { createExposureSlider, createLightSlider } from "../utils/environment.js";
|
||||||
|
|
||||||
const html = String.raw;
|
const html = String.raw;
|
||||||
const panelHeader = html`
|
const panelHeader = html`
|
||||||
@@ -39,12 +39,15 @@ export default class extends Controller {
|
|||||||
#buildSettingsPanel(panel) {
|
#buildSettingsPanel(panel) {
|
||||||
const fragment = this.#cloneTemplate('tmpl-settings');
|
const fragment = this.#cloneTemplate('tmpl-settings');
|
||||||
let sliderContainer = fragment.querySelector('[data-sliders-container]');
|
let sliderContainer = fragment.querySelector('[data-sliders-container]');
|
||||||
|
let exposureContainer = fragment.querySelector('[data-slider-exposure-container]');
|
||||||
|
|
||||||
['x', 'y', 'z'].forEach((axis, i) => {
|
['x', 'y', 'z'].forEach((axis, i) => {
|
||||||
const label = ['Asse X', 'Asse Y', 'Asse Z'][i];
|
const label = ['Asse X', 'Asse Y', 'Asse Z'][i];
|
||||||
sliderContainer.appendChild(createLightSlider(axis, label, [-2, 2], 0.1));
|
sliderContainer.appendChild(createLightSlider(axis, label, [-2, 2], 0.1));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
exposureContainer.appendChild(createExposureSlider('Valore', [0, 5]));
|
||||||
|
|
||||||
panel.appendChild(fragment);
|
panel.appendChild(fragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ function init () {
|
|||||||
AppState.camera = ATON.Nav._camera;
|
AppState.camera = ATON.Nav._camera;
|
||||||
AppState.renderer = ATON._renderer;
|
AppState.renderer = ATON._renderer;
|
||||||
AppState.shadows = config.scene.shadows;
|
AppState.shadows = config.scene.shadows;
|
||||||
|
AppState.lightDirection = ATON.getMainLightDirection();
|
||||||
|
AppState.exposure = config.scene.initialExposure;
|
||||||
|
|
||||||
ATON.Nav.setUserControl(true);
|
ATON.Nav.setUserControl(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ let AppState = {
|
|||||||
// {id: String, active: Boolean}
|
// {id: String, active: Boolean}
|
||||||
nodes: [],
|
nodes: [],
|
||||||
/**
|
/**
|
||||||
* @property {NormalizedSceneNode[]} normalizedNodes
|
* @type {NormalizedSceneNode[]} normalizedNodes
|
||||||
*/
|
*/
|
||||||
normalizedNodes: [],
|
normalizedNodes: [],
|
||||||
mainNodeId: null,
|
mainNodeId: null,
|
||||||
@@ -28,6 +28,11 @@ let AppState = {
|
|||||||
sceneHasAudio: false,
|
sceneHasAudio: false,
|
||||||
layersMenuBuilt: false,
|
layersMenuBuilt: false,
|
||||||
initialRotation: null,
|
initialRotation: null,
|
||||||
|
lightDirection: [],
|
||||||
|
/**
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
exposure: null,
|
||||||
camera: null,
|
camera: null,
|
||||||
renderer: null,
|
renderer: null,
|
||||||
ambientOcclusion : true,
|
ambientOcclusion : true,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// Global ATON and THREE
|
// Global ATON and THREE
|
||||||
|
|
||||||
|
import AppState from "../state.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module Environment
|
* @module Environment
|
||||||
*/
|
*/
|
||||||
@@ -21,23 +23,28 @@ export function toggleAmbientOcclusion(isEnabled) {
|
|||||||
console.log('Ambient occlusion', isEnabled ? 'ON' : 'OFF');
|
console.log('Ambient occlusion', isEnabled ? 'ON' : 'OFF');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
* Slider to change light direction, based on ATON.UI
|
||||||
* @param {String} direction - The axis direction, one of 'x','y','z'
|
* @param {String} direction - The axis direction, one of 'x','y','z'
|
||||||
* @param {String} label - The slider label
|
* @param {String} label - The slider label
|
||||||
* @param {Number[]} range - The slider's range
|
* @param {Array<Number>} range - The slider's range
|
||||||
* @param {Number} step - The slider's step
|
* @param {Number} step - The slider's step
|
||||||
*/
|
*/
|
||||||
export function createLightSlider(direction, label, range, 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({
|
const lightSlider = ATON.UI.createSlider({
|
||||||
range,
|
range,
|
||||||
label,
|
label,
|
||||||
value: Number.parseFloat(currentVal).toPrecision(1),
|
value: Number.parseFloat(currentVal).toPrecision(2),
|
||||||
oninput: val => {
|
oninput: val => {
|
||||||
const lightDir = ATON.getMainLightDirection();
|
const lightDir = AppState.lightDirection;
|
||||||
|
|
||||||
// Keep existing direction values for the other axes
|
// Keep existing direction values for the other axes
|
||||||
lightDir[direction] = Number.parseFloat(val);
|
lightDir[direction] = Number.parseFloat(val);
|
||||||
changeLightDirection(lightDir);
|
changeLightDirection(lightDir);
|
||||||
|
AppState.lightDirection = lightDir;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,3 +53,29 @@ export function createLightSlider(direction, label, range, step) {
|
|||||||
|
|
||||||
return lightSlider;
|
return lightSlider;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Slider to change the env exposure level, based on ATON.UI
|
||||||
|
* @param {String} label - The slider label
|
||||||
|
* @param {Array<Number>} range - The slider's range
|
||||||
|
* @param {Number} step - The slider's step
|
||||||
|
*/
|
||||||
|
export function createExposureSlider(label, range, step = 0.2) {
|
||||||
|
const currentVal = AppState.exposure;
|
||||||
|
|
||||||
|
const exposureSlider = ATON.UI.createSlider({
|
||||||
|
range,
|
||||||
|
label,
|
||||||
|
value: Number.parseFloat(currentVal).toPrecision(2),
|
||||||
|
oninput: val => {
|
||||||
|
ATON.setExposure(val);
|
||||||
|
AppState.exposure = val;
|
||||||
|
|
||||||
|
console.debug(ATON.getExposure());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
exposureSlider.classList.add('ms-4');
|
||||||
|
exposureSlider.querySelector('input').step = step;
|
||||||
|
|
||||||
|
return exposureSlider;
|
||||||
|
}
|
||||||
@@ -99,9 +99,16 @@
|
|||||||
<template id="tmpl-settings">
|
<template id="tmpl-settings">
|
||||||
<div data-controller="settings">
|
<div data-controller="settings">
|
||||||
<h2 class="fs-5 ms-2 mb-3 mt-3">
|
<h2 class="fs-5 ms-2 mb-3 mt-3">
|
||||||
<i class="bi bi-lightbulb me-1"></i> Direzione luce
|
<i class="bi bi-lightbulb me-1"></i> Illuminazione
|
||||||
</h2>
|
</h2>
|
||||||
|
<h3 class="fs-6 ms-4 mb-3 mt-3">
|
||||||
|
Direzione (x, y, z)
|
||||||
|
</h3>
|
||||||
<div data-sliders-container></div>
|
<div data-sliders-container></div>
|
||||||
|
<h3 class="fs-6 ms-4 mb-3 mt-3">
|
||||||
|
Intensità
|
||||||
|
</h3>
|
||||||
|
<div data-slider-exposure-container></div>
|
||||||
<h2 class="fs-5 ms-2 mb-3 mt-3">
|
<h2 class="fs-5 ms-2 mb-3 mt-3">
|
||||||
<i class="bi bi-brightness-high me-1"></i> Ambiente
|
<i class="bi bi-brightness-high me-1"></i> Ambiente
|
||||||
</h2>
|
</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user