feat: 3d mode - sun presets

This commit is contained in:
Azgaar 2025-10-31 03:12:56 +01:00
parent 585f3c34b1
commit 07d0729cfc
3 changed files with 106 additions and 0 deletions

View file

@ -1054,6 +1054,7 @@ function toggle3dOptions() {
byId("options3dMeshWireframeMode").addEventListener("change", toggleWireframe3d);
byId("options3dSunColor").addEventListener("input", changeSunColor);
byId("options3dSubdivide").addEventListener("change", toggle3dSubdivision);
byId("options3dTimeOfDay").addEventListener("change", changeTimeOfDay);
function updateValues() {
const globe = byId("canvas3d").dataset.type === "viewGlobe";
@ -1075,6 +1076,41 @@ function toggle3dOptions() {
options3dGlobeResolution.value = ThreeD.options.resolution;
options3dSunColor.value = ThreeD.options.sunColor;
options3dSubdivide.value = ThreeD.options.subdivide;
updateTimeOfDayPreset();
}
function updateTimeOfDayPreset() {
const presetSelect = byId("options3dTimeOfDay");
if (!presetSelect) return;
const currentSunX = ThreeD.options.sun.x;
const currentSunY = ThreeD.options.sun.y;
const currentSunZ = ThreeD.options.sun.z;
const currentSunColor = ThreeD.options.sunColor;
const currentLightness = ThreeD.options.lightness;
let matchingPreset = "custom";
for (const [name, preset] of Object.entries(ThreeD.timeOfDayPresets)) {
if (
preset.sun.x === currentSunX &&
preset.sun.y === currentSunY &&
preset.sun.z === currentSunZ &&
preset.sunColor === currentSunColor &&
Math.abs(preset.lightness - currentLightness) < 0.05
) {
matchingPreset = name;
break;
}
}
presetSelect.value = matchingPreset;
}
function changeTimeOfDay() {
const presetName = this.value;
if (presetName === "custom") return;
ThreeD.setTimeOfDay(presetName);
updateValues();
}
function changeHeightScale() {
@ -1090,16 +1126,31 @@ function toggle3dOptions() {
function changeLightness() {
options3dLightnessRange.value = options3dLightnessNumber.value = this.value;
ThreeD.setLightness(this.value / 100);
// Mark as custom when user manually changes lightness
const presetSelect = byId("options3dTimeOfDay");
if (presetSelect && presetSelect.value !== "custom") {
presetSelect.value = "custom";
}
}
function changeSunColor() {
ThreeD.setSunColor(options3dSunColor.value);
// Mark as custom when user manually changes sun color
const presetSelect = byId("options3dTimeOfDay");
if (presetSelect && presetSelect.value !== "custom") {
presetSelect.value = "custom";
}
}
function changeSunPosition() {
const x = +options3dSunX.value;
const y = +options3dSunY.value;
ThreeD.setSun(x, y);
// Mark as custom when user manually changes sun position
const presetSelect = byId("options3dTimeOfDay");
if (presetSelect && presetSelect.value !== "custom") {
presetSelect.value = "custom";
}
}
function changeRotation() {