Files
scaenae/js/utils/environment.js

48 lines
1.3 KiB
JavaScript

// Global ATON and THREE
/**
* @module Environment
*/
/**
*
* @param {THREE.Vector3} vector - An object with x,y,z coordinates
*/
export function changeLightDirection(vector) {
ATON.setMainLightDirection(vector);
}
/**
*
* @param {Boolean} isEnabled
*/
export function toggleAmbientOcclusion(isEnabled) {
ATON.FX.togglePass(ATON.FX.PASS_AO, isEnabled);
console.log('Ambient occlusion', isEnabled ? 'ON' : 'OFF');
}
/**
*
* @param {String} direction - The axis direction, one of 'x','y','z'
* @param {String} label - The slider label
* @param {Number[]} range - The slider's range
* @param {Number} step - The slider's step
*/
export function createLightSlider(direction, label, range, step) {
const currentVal = ATON.getMainLightDirection()[direction];
const lightSlider = ATON.UI.createSlider({
range,
label,
value: Number.parseFloat(currentVal).toPrecision(1),
oninput: val => {
const lightDir = ATON.getMainLightDirection();
// Keep existing direction values for the other axes
lightDir[direction] = Number.parseFloat(val);
changeLightDirection(lightDir);
},
});
lightSlider.classList.add('ms-4');
lightSlider.querySelector('input').step = step;
return lightSlider;
}