Display panel: a Sky group for the atmosphere, day and night, sun, moon, stars and Milky Way

createViewSky sets globe.sky from the panel's switches and Milky Way
slider and keeps the choice for the next visit; what the user has not set
stays as the renderer draws it. Distance fog stays with the styles that
switch it.
This commit is contained in:
Sameh Khamis committed 2026-11-13 21:13:35 -08:00
1 parent 5cd28731fa
commit af3383a5a9
19 files changed
+331 -14

No files matched your search

+7
View File
@@ -3,6 +3,7 @@ import { StyleManager } from '../ui/composition.js';
import { applyStartView, START_VIEW } from '../camera.js';
import { initCockpitCloudEffects } from '../cockpitCloudEffects.js';
import { createViewWeather } from '../viewWeather.js';
import { createViewSky } from '../viewSky.js';
import { findGlobe } from '../render/rendererOf.js';
import { useDisplayStore } from '../ui/stores/display.js';
import { applicationPinia } from '../ui/vueRuntime.js';
@@ -70,6 +71,12 @@ export function createApplicationControls({
store: useDisplayStore(applicationPinia()),
});
defer(() => viewWeather.destroy());
// The atmosphere, sun lighting, sun, moon, stars and Milky Way the user
// chooses in the Display panel.
const viewSky = createViewSky(viewer, {
store: useDisplayStore(applicationPinia()),
});
defer(() => viewSky.destroy());
loaderStatus.textContent = styleManager.hasShareState
? t('Restoring shared view...')
+7 -1
View File
@@ -3956,5 +3956,11 @@
"Confirm: remove every added entry from Data Layers": "تأكيد: إزالة كل الإدخالات المُضافة من طبقات البيانات",
"Remove every added entry from Data Layers": "إزالة كل الإدخالات المُضافة من طبقات البيانات",
"Showing {shown} of {total}": "عرض {shown} من {total}",
"BROWSE DATA LIBRARY": "تصفّح مكتبة البيانات"
"BROWSE DATA LIBRARY": "تصفّح مكتبة البيانات",
"Atmosphere": "الغلاف الجوي",
"Day and night": "الليل والنهار",
"Sun": "الشمس",
"Moon": "القمر",
"Stars": "النجوم",
"Milky Way": "درب التبانة"
}
+7 -1
View File
@@ -3608,5 +3608,11 @@
"Confirm: remove every added entry from Data Layers": "Bestätigen: alle hinzugefügten Einträge aus Datenebenen entfernen",
"Remove every added entry from Data Layers": "Alle hinzugefügten Einträge aus Datenebenen entfernen",
"Showing {shown} of {total}": "{shown} von {total} angezeigt",
"BROWSE DATA LIBRARY": "DATENBIBLIOTHEK DURCHSUCHEN"
"BROWSE DATA LIBRARY": "DATENBIBLIOTHEK DURCHSUCHEN",
"Atmosphere": "Atmosphäre",
"Day and night": "Tag und Nacht",
"Sun": "Sonne",
"Moon": "Mond",
"Stars": "Sterne",
"Milky Way": "Milchstraße"
}
+7 -1
View File
@@ -3695,5 +3695,11 @@
"500–1,000 m": "500–1000 m",
"1,000–2,000 m": "1000–2000 m",
"2,000–3,000 m": "2000–3000 m",
"3,000 m and above": "3000 m o más"
"3,000 m and above": "3000 m o más",
"Atmosphere": "Atmósfera",
"Day and night": "Día y noche",
"Sun": "Sol",
"Moon": "Luna",
"Stars": "Estrellas",
"Milky Way": "Vía Láctea"
}
+7 -1
View File
@@ -3695,5 +3695,11 @@
"Confirm: remove every added entry from Data Layers": "Confirmer : retirer du panneau Couches toutes les entrées ajoutées",
"Remove every added entry from Data Layers": "Retirer du panneau Couches toutes les entrées ajoutées",
"Showing {shown} of {total}": "Affichées : {shown} sur {total}",
"BROWSE DATA LIBRARY": "PARCOURIR LA BIBLIOTHÈQUE DE DONNÉES"
"BROWSE DATA LIBRARY": "PARCOURIR LA BIBLIOTHÈQUE DE DONNÉES",
"Atmosphere": "Atmosphère",
"Day and night": "Jour et nuit",
"Sun": "Soleil",
"Moon": "Lune",
"Stars": "Étoiles",
"Milky Way": "Voie lactée"
}
+7 -1
View File
@@ -3695,5 +3695,11 @@
"Confirm: remove every added entry from Data Layers": "אישור: הסרת כל הפריטים שנוספו משכבות נתונים",
"Remove every added entry from Data Layers": "הסרת כל הפריטים שנוספו משכבות נתונים",
"Showing {shown} of {total}": "מוצגים {shown} מתוך {total}",
"BROWSE DATA LIBRARY": "עיון בספריית הנתונים"
"BROWSE DATA LIBRARY": "עיון בספריית הנתונים",
"Atmosphere": "אטמוספרה",
"Day and night": "יום ולילה",
"Sun": "שמש",
"Moon": "ירח",
"Stars": "כוכבים",
"Milky Way": "שביל החלב"
}
+7 -1
View File
@@ -3695,5 +3695,11 @@
"Confirm: remove every added entry from Data Layers": "Conferma: rimuovi da Livelli dati tutte le voci aggiunte",
"Remove every added entry from Data Layers": "Rimuovi da Livelli dati tutte le voci aggiunte",
"Showing {shown} of {total}": "Mostrati: {shown} su {total}",
"BROWSE DATA LIBRARY": "ESPLORA LIBRERIA DATI"
"BROWSE DATA LIBRARY": "ESPLORA LIBRERIA DATI",
"Atmosphere": "Atmosfera",
"Day and night": "Giorno e notte",
"Sun": "Sole",
"Moon": "Luna",
"Stars": "Stelle",
"Milky Way": "Via Lattea"
}
+7 -1
View File
@@ -3521,5 +3521,11 @@
"Confirm: remove every added entry from Data Layers": "確認:追加したすべての項目をデータレイヤーから削除",
"Remove every added entry from Data Layers": "追加したすべての項目をデータレイヤーから削除",
"Showing {shown} of {total}": "{total}件中{shown}件を表示",
"BROWSE DATA LIBRARY": "データライブラリを見る"
"BROWSE DATA LIBRARY": "データライブラリを見る",
"Atmosphere": "大気",
"Day and night": "昼と夜",
"Sun": "太陽",
"Moon": "月",
"Stars": "星",
"Milky Way": "天の川"
}
+7 -1
View File
@@ -3695,5 +3695,11 @@
"Confirm: remove every added entry from Data Layers": "Confirmar: remover de \"Camadas de dados\" todas as entradas adicionadas",
"Remove every added entry from Data Layers": "Remover de \"Camadas de dados\" todas as entradas adicionadas",
"Showing {shown} of {total}": "Mostrando {shown} de {total}",
"BROWSE DATA LIBRARY": "EXPLORAR BIBLIOTECA DE DADOS"
"BROWSE DATA LIBRARY": "EXPLORAR BIBLIOTECA DE DADOS",
"Atmosphere": "Atmosfera",
"Day and night": "Dia e noite",
"Sun": "Sol",
"Moon": "Lua",
"Stars": "Estrelas",
"Milky Way": "Via Láctea"
}
+7 -1
View File
@@ -3782,5 +3782,11 @@
"500–1,000 m": "500–1000 м",
"1,000–2,000 m": "1000–2000 м",
"2,000–3,000 m": "2000–3000 м",
"3,000 m and above": "3000 м и выше"
"3,000 m and above": "3000 м и выше",
"Atmosphere": "Атмосфера",
"Day and night": "День и ночь",
"Sun": "Солнце",
"Moon": "Луна",
"Stars": "Звёзды",
"Milky Way": "Млечный Путь"
}
+7 -1
View File
@@ -3608,5 +3608,11 @@
"Confirm: remove every added entry from Data Layers": "Bekräfta: ta bort alla tillagda poster från Datalager",
"Remove every added entry from Data Layers": "Ta bort alla tillagda poster från Datalager",
"Showing {shown} of {total}": "Visar {shown} av {total}",
"BROWSE DATA LIBRARY": "BLÄDDRA I DATABIBLIOTEKET"
"BROWSE DATA LIBRARY": "BLÄDDRA I DATABIBLIOTEKET",
"Atmosphere": "Atmosfär",
"Day and night": "Dag och natt",
"Sun": "Sol",
"Moon": "Måne",
"Stars": "Stjärnor",
"Milky Way": "Vintergatan"
}
+7 -1
View File
@@ -3782,5 +3782,11 @@
"Confirm: remove every added entry from Data Layers": "Підтвердити: видалити всі додані записи з «Шарів даних»",
"Remove every added entry from Data Layers": "Видалити всі додані записи з «Шарів даних»",
"Showing {shown} of {total}": "Показано {shown} з {total}",
"BROWSE DATA LIBRARY": "ВІДКРИТИ БІБЛІОТЕКУ ДАНИХ"
"BROWSE DATA LIBRARY": "ВІДКРИТИ БІБЛІОТЕКУ ДАНИХ",
"Atmosphere": "Атмосфера",
"Day and night": "День і ніч",
"Sun": "Сонце",
"Moon": "Місяць",
"Stars": "Зорі",
"Milky Way": "Чумацький Шлях"
}
+7 -1
View File
@@ -3521,5 +3521,11 @@
"Confirm: remove every added entry from Data Layers": "确认:从数据图层中移除所有已添加条目",
"Remove every added entry from Data Layers": "从数据图层中移除所有已添加条目",
"Showing {shown} of {total}": "显示 {shown} / {total}",
"BROWSE DATA LIBRARY": "浏览数据资源库"
"BROWSE DATA LIBRARY": "浏览数据资源库",
"Atmosphere": "大气",
"Day and night": "昼夜",
"Sun": "太阳",
"Moon": "月亮",
"Stars": "星星",
"Milky Way": "银河"
}
+7 -1
View File
@@ -3521,5 +3521,11 @@
"Confirm: remove every added entry from Data Layers": "確認:從數據圖層中移除所有已添加條目",
"Remove every added entry from Data Layers": "從數據圖層中移除所有已添加條目",
"Showing {shown} of {total}": "顯示 {shown} / {total}",
"BROWSE DATA LIBRARY": "瀏覽數據資源庫"
"BROWSE DATA LIBRARY": "瀏覽數據資源庫",
"Atmosphere": "大氣",
"Day and night": "晝夜",
"Sun": "太陽",
"Moon": "月亮",
"Stars": "星星",
"Milky Way": "銀河"
}
+13
View File
@@ -39,6 +39,17 @@ export const useDisplayStore = defineStore('gev-display', () => {
weather.value = next && markRaw(next);
}
/**
* The Sky group, `{switches, milkyWay}` (switches by name, the Milky Way
* in percent); null where the renderer has no sky to set.
*/
const sky = shallowRef(null);
/** @param {?object} next A fresh presentation of the Sky group. */
function publishSky(next) {
sky.value = next && markRaw(next);
}
/** The Draw controls; null until the draw tool first renders. */
const draw = shallowRef(null);
@@ -121,6 +132,8 @@ export const useDisplayStore = defineStore('gev-display', () => {
publishModels3d,
weather,
publishWeather,
sky,
publishSky,
draw,
publishDraw,
geoImport,
+21 -1
View File
@@ -17,7 +17,7 @@ import { StyleParameterRows } from '../../styleParameters.js';
// and each publishes them; until they do, the panel shows its initial markup.
// Draw and Import live in UTILITIES (LayerPanelsView).
const display = useDisplayStore();
const { view, models3d, parameters, cockpitPortal, weather } = storeToRefs(display);
const { view, models3d, parameters, cockpitPortal, weather, sky } = storeToRefs(display);
// A control's change goes to its owner (DisplayBindings).
const act = (name, ...args) => display.act(name, ...args);
const pct = (value) => `${value}%`;
@@ -41,6 +41,13 @@ const weatherRows = computed(() => [
{ key: 'rain', label: t('Rain') },
{ key: 'snow', label: t('Snow') },
]);
const skyRows = computed(() => [
{ key: 'atmosphere', label: t('Atmosphere'), icon: 'public' },
{ key: 'lighting', label: t('Day and night'), icon: 'adjust' },
{ key: 'sun', label: t('Sun'), icon: 'light_mode' },
{ key: 'moon', label: t('Moon'), icon: 'dark_mode' },
{ key: 'stars', label: t('Stars'), icon: 'flare' },
]);
const models3dOn = computed(() => models3d.value?.pressed ?? true);
const modelsMode = computed(() => models3d.value?.mode ?? 'proximity');
const modelsOptions = computed(() => [
@@ -181,6 +188,19 @@ const allocationOptions = computed(() => [
<span class="pp-label">{{ t('Celestial') }}</span>
</UiButton>
</div>
<!-- Sky: only where the renderer has a sky to set. -->
<div v-if="sky" class="pp-toggle-group" id="sky-group">
<label v-for="row in skyRows" :key="row.key" class="pp-toggle-btn pp-scope-toggle" :id="`sky-${row.key}-row`">
<span class="pp-icon material-symbols-outlined" aria-hidden="true">{{ row.icon }}</span>
<span class="pp-label">{{ row.label }}</span>
<input type="checkbox" :id="`sky-${row.key}-toggle`" @change="act('setSkySwitch', row.key, $event.target.checked)" :checked="sky.switches[row.key]" />
</label>
<div class="pp-slider-row visible" id="sky-milkyway-row">
<span class="pp-slider-mini-label">{{ t('Milky Way') }}</span>
<UiSlider class="pp-slider" id="sky-milkyway-slider" @update:model-value="act('setSkyMilkyWay', $event)" min="0" max="100" :model-value="sky.milkyWay" :aria-label="t('Milky Way')" />
<span class="pp-slider-value">{{ pct(sky.milkyWay) }}</span>
</div>
</div>
<!-- Weather: only where the renderer draws it. -->
<div v-if="weather" class="pp-toggle-group" id="weather-group">
<label class="pp-toggle-btn pp-scope-toggle" :title="t('Live weather: the conditions under the camera')">
+103
View File
@@ -0,0 +1,103 @@
/**
* The sky the user chooses in the Display panel's Sky group: the
* atmosphere, sun lighting (day and night by scene time), the sun and moon,
* the stars and the Milky Way's brightness, through the renderer's
* `globe.sky`. The choice is kept across visits; what the user has not set
* stays as the renderer draws it. Distance fog is left to the styles that
* switch it (infrared).
*/
import { findGlobe } from './render/rendererOf.js';
const STORAGE_KEY = 'godsEyeView.viewSky';
/** The switches the panel lists, in its order. */
export const SKY_SWITCHES = Object.freeze([
'atmosphere',
'lighting',
'sun',
'moon',
'stars',
]);
/** The saved choice: only the settings the user set, each checked. */
function readSaved(storage) {
try {
const saved = JSON.parse(storage?.getItem(STORAGE_KEY) ?? 'null');
if (!saved || typeof saved !== 'object') return {};
const choice = {};
for (const key of SKY_SWITCHES)
if (typeof saved[key] === 'boolean') choice[key] = saved[key];
const milkyWay = Number(saved.milkyWay);
if (Number.isFinite(milkyWay))
choice.milkyWay = Math.min(1, Math.max(0, milkyWay));
return choice;
} catch {
return {};
}
}
/**
* @param {object} viewer The scene host a renderer is bound to.
* @param {object} options
* @param {{publishSky: Function, connect: Function, detach: Function}} options.store
* The Display store: the panel's Sky group and its controls.
* @param {Storage} [options.storage]
* @returns {{destroy: () => void}}
*/
export function createViewSky(
viewer,
{ store, storage = globalThis.localStorage },
) {
const sky = findGlobe(viewer)?.sky ?? null;
if (!sky) {
store?.publishSky?.(null);
return { destroy() {} };
}
const choice = readSaved(storage);
if (Object.keys(choice).length) sky.set(choice);
function publish() {
const shown = sky.get();
store?.publishSky?.({
switches: Object.fromEntries(
SKY_SWITCHES.map((key) => [key, Boolean(shown[key])]),
),
milkyWay: Math.round((shown.milkyWay ?? 0) * 100),
});
}
function save() {
try {
storage?.setItem(STORAGE_KEY, JSON.stringify(choice));
} catch {
// Private mode: the choice lasts the visit.
}
}
function apply(change) {
Object.assign(choice, change);
sky.set(change);
save();
publish();
}
const token = store?.connect?.({
setSkySwitch(key, on) {
if (!SKY_SWITCHES.includes(key)) return;
apply({ [key]: Boolean(on) });
},
setSkyMilkyWay(pct) {
const value = Number(pct) / 100;
if (!Number.isFinite(value)) return;
apply({ milkyWay: Math.min(1, Math.max(0, value)) });
},
});
publish();
return {
destroy() {
if (token) store?.detach?.(token);
store?.publishSky?.(null);
},
};
}
+92
View File
@@ -0,0 +1,92 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { bindRenderer } from './render/rendererOf.js';
import { createStubRenderer } from './render/stub/index.js';
import { createViewSky } from './viewSky.js';
function setup(saved = new Map()) {
const renderer = createStubRenderer();
const host = {};
const unbind = bindRenderer(host, renderer);
const published = [];
const owners = [];
const store = {
publishSky: (view) => published.push(view),
connect: (actions) => (owners.push(actions), actions),
detach: (token) => owners.splice(owners.indexOf(token), 1),
};
const storage = {
getItem: (k) => saved.get(k) ?? null,
setItem: (k, v) => saved.set(k, v),
};
const act = (name, ...args) => owners.at(-1)?.[name](...args);
const sky = createViewSky(host, { store, storage });
return {
renderer,
published,
owners,
act,
saved,
sky,
done() {
sky.destroy();
unbind();
renderer.destroy();
},
};
}
test('the Sky group shows the renderer’s sky, untouched until the user sets it', () => {
const s = setup();
const before = s.renderer.globe.sky.get();
const shown = s.published.at(-1);
assert.equal(shown.switches.atmosphere, before.atmosphere);
assert.equal(shown.switches.lighting, before.lighting);
assert.equal(shown.milkyWay, Math.round(before.milkyWay * 100));
assert.equal(s.saved.size, 0, 'nothing saved before a change');
s.done();
});
test('a switch or the Milky Way slider sets the sky, shows it and is kept for the next visit', () => {
const s = setup();
s.act('setSkySwitch', 'lighting', true);
s.act('setSkySwitch', 'stars', false);
s.act('setSkyMilkyWay', 40);
const sky = s.renderer.globe.sky.get();
assert.equal(sky.lighting, true);
assert.equal(sky.stars, false);
assert.equal(sky.milkyWay, 0.4);
const shown = s.published.at(-1);
assert.equal(shown.switches.lighting, true);
assert.equal(shown.switches.stars, false);
assert.equal(shown.milkyWay, 40);
s.act('setSkySwitch', 'fog', false);
assert.equal(
s.renderer.globe.sky.get().fog,
sky.fog,
'fog is not a panel switch',
);
s.act('setSkyMilkyWay', 'x');
assert.equal(
s.renderer.globe.sky.get().milkyWay,
0.4,
'a bad value changes nothing',
);
const saved = s.saved;
s.done();
const next = setup(saved);
const again = next.renderer.globe.sky.get();
assert.equal(again.lighting, true);
assert.equal(again.stars, false);
assert.equal(again.milkyWay, 0.4);
next.done();
});
test('destroy hides the group and stops answering its controls', () => {
const s = setup();
s.done();
assert.equal(s.published.at(-1), null);
assert.equal(s.owners.length, 0);
});