mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
feat(render): a renderer can draw weather: the weather capability adds globe.weather (clouds, fog, haze, rain and snow, 0 to 1, and the wind they drift on); the view shows the conditions observed under the camera, and the Display panel's Weather group sets them by hand
This commit is contained in:
1 parent
639e92b4f7
commit
0b1dc325bc
29 files changed
+869
-27
No files matched your search
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
- A renderer can draw weather: the `weather` capability adds `globe.weather`,
|
||||||
|
with clouds, fog, haze, rain and snow (each 0 to 1) and the wind they drift
|
||||||
|
on. Where the renderer lists it, the view shows the conditions observed
|
||||||
|
under the camera, asked again after five minutes or 25 km of movement, and
|
||||||
|
the Display panel's Weather group can turn live weather off and set
|
||||||
|
clouds, fog, rain and snow by hand. The Cesium renderer does not draw
|
||||||
|
weather, and shows no Weather group (samehkhamis).
|
||||||
- The globe opens at planet level, the whole Earth in view, on every
|
- The globe opens at planet level, the whole Earth in view, on every
|
||||||
renderer, instead of flying in to Austin. A shared link still flies from
|
renderer, instead of flying in to Austin. A shared link still flies from
|
||||||
there to its view. An application can start somewhere else, a city for
|
there to its view. An application can start somewhere else, a city for
|
||||||
|
|||||||
@@ -138,6 +138,17 @@ The Cesium port lists `modelAtmosphere`: Cesium scatters drawn models
|
|||||||
through the atmosphere in the same stage as its distance fog, so models take
|
through the atmosphere in the same stage as its distance fog, so models take
|
||||||
it while `globe.sky`'s `fog` is on.
|
it while `globe.sky`'s `fog` is on.
|
||||||
|
|
||||||
|
`weather` adds `globe.weather`: clouds, fog, haze, rain and snow drawn
|
||||||
|
around the view, each a strength from 0 to 1, with the wind they drift on.
|
||||||
|
`src/render/weather.js` keeps and clamps them alike for the renderer
|
||||||
|
(`mergeWeather`). The app's `src/viewWeather.js` sets the conditions observed
|
||||||
|
under the camera (the weather service, through
|
||||||
|
`deriveWeatherEffectProfile`), asking again after five minutes or 25 km,
|
||||||
|
and none from orbit; the Display panel's Weather group turns live off and
|
||||||
|
sets clouds, fog, rain and snow by hand, and shows only on a renderer that
|
||||||
|
lists `weather`. The Cesium port does not list it. The checks
|
||||||
|
`globe.weather` and `globe.weather.drawn` (a pixel check) pin it.
|
||||||
|
|
||||||
The Cesium port lists `followAutodetect`: an `autodetect` follow is
|
The Cesium port lists `followAutodetect`: an `autodetect` follow is
|
||||||
Cesium's own AUTODETECT tracking frame, east-north-up on a still or slow
|
Cesium's own AUTODETECT tracking frame, east-north-up on a still or slow
|
||||||
target and an orbit frame (x along the inertial motion, z up) on a fast
|
target and an orbit frame (x along the inertial motion, z up) on a fast
|
||||||
@@ -391,7 +402,7 @@ puts every member of `PORTS` in exactly one role. It changes no member.
|
|||||||
| `scene` | Draws the application's data as keyed, retained sets | `draw`, `drawSet` |
|
| `scene` | Draws the application's data as keyed, retained sets | `draw`, `drawSet` |
|
||||||
| `view` | Places and moves the camera, hands pointer input to the application | `camera`, `flight`, `input`, `lease` |
|
| `view` | Places and moves the camera, hands pointer input to the application | `camera`, `flight`, `input`, `lease` |
|
||||||
| `queries` | Picks, surface positions and heights, rays, projection, occlusion | `query` |
|
| `queries` | Picks, surface positions and heights, rays, projection, occlusion | `query` |
|
||||||
| `look` | Sky and atmosphere, surface shading, per-layer lighting, styles and screen effects | `effects`, `globe.sky`, `globe.setSurfaceShading`, `imageryLayer.lit` |
|
| `look` | Sky and atmosphere, surface shading, per-layer lighting, styles and screen effects | `effects`, `globe.sky`, `globe.weather`, `globe.setSurfaceShading`, `imageryLayer.lit` |
|
||||||
| `host` | Canvas and life cycle, the frame loop and scene time, quality, capture, settling | `renderer`, `frame`, `quality` |
|
| `host` | Canvas and life cycle, the frame loop and scene time, quality, capture, settling | `renderer`, `frame`, `quality` |
|
||||||
|
|
||||||
An entry is a port or a `port.member` prefix; the most specific one wins, so
|
An entry is a port or a `port.member` prefix; the most specific one wins, so
|
||||||
|
|||||||
Vendored
+17
-3
@@ -2,6 +2,10 @@ import { catalogControlServices } from './catalog.js';
|
|||||||
import { StyleManager } from '../ui/composition.js';
|
import { StyleManager } from '../ui/composition.js';
|
||||||
import { applyStartView, START_VIEW } from '../camera.js';
|
import { applyStartView, START_VIEW } from '../camera.js';
|
||||||
import { initCockpitCloudEffects } from '../cockpitCloudEffects.js';
|
import { initCockpitCloudEffects } from '../cockpitCloudEffects.js';
|
||||||
|
import { createViewWeather } from '../viewWeather.js';
|
||||||
|
import { findGlobe } from '../render/rendererOf.js';
|
||||||
|
import { useDisplayStore } from '../ui/stores/display.js';
|
||||||
|
import { applicationPinia } from '../ui/vueRuntime.js';
|
||||||
import { t } from '../i18n/index.js';
|
import { t } from '../i18n/index.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,10 +56,20 @@ export function createApplicationControls({
|
|||||||
// clouds use a separate, capped low-resolution GPU pass that never attaches
|
// clouds use a separate, capped low-resolution GPU pass that never attaches
|
||||||
// Cesium fog or post-process stages and is fully stopped in map mode.
|
// Cesium fog or post-process stages and is fully stopped in map mode.
|
||||||
const weatherEffects = null;
|
const weatherEffects = null;
|
||||||
const cockpitCloudEffects = initCockpitCloudEffects(viewer, {
|
// Where the renderer draws weather, it draws the cockpit's clouds too.
|
||||||
weatherService: operations.requests.weather,
|
const cockpitCloudEffects = findGlobe(viewer)?.weather
|
||||||
});
|
? null
|
||||||
|
: initCockpitCloudEffects(viewer, {
|
||||||
|
weatherService: operations.requests.weather,
|
||||||
|
});
|
||||||
defer(() => cockpitCloudEffects?.destroy());
|
defer(() => cockpitCloudEffects?.destroy());
|
||||||
|
// Clouds, fog, rain and snow on a renderer that draws them: the conditions
|
||||||
|
// under the camera, or what the user sets in the Display panel.
|
||||||
|
const viewWeather = createViewWeather(viewer, {
|
||||||
|
weatherService: operations.requests.weather,
|
||||||
|
store: useDisplayStore(applicationPinia()),
|
||||||
|
});
|
||||||
|
defer(() => viewWeather.destroy());
|
||||||
|
|
||||||
loaderStatus.textContent = styleManager.hasShareState
|
loaderStatus.textContent = styleManager.hasShareState
|
||||||
? t('Restoring shared view...')
|
? t('Restoring shared view...')
|
||||||
|
|||||||
@@ -3812,5 +3812,11 @@
|
|||||||
"{source} imagery could not be opened": "تعذّر فتح صور {source}",
|
"{source} imagery could not be opened": "تعذّر فتح صور {source}",
|
||||||
"{place} has no position to look for imagery at": "لا يوجد لـ{place} موضع للبحث عن الصور فيه",
|
"{place} has no position to look for imagery at": "لا يوجد لـ{place} موضع للبحث عن الصور فيه",
|
||||||
"No {source} imagery near {place}": "لا توجد صور {source} قرب {place}",
|
"No {source} imagery near {place}": "لا توجد صور {source} قرب {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (المرشحات المفعّلة: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (المرشحات المفعّلة: {filters})",
|
||||||
|
"Clouds": "السحب",
|
||||||
|
"Fog": "الضباب",
|
||||||
|
"Rain": "المطر",
|
||||||
|
"Snow": "الثلج",
|
||||||
|
"Live weather: the conditions under the camera": "الطقس المباشر: الأحوال تحت الكاميرا",
|
||||||
|
"No weather report here": "لا يوجد تقرير طقس هنا"
|
||||||
}
|
}
|
||||||
@@ -3488,5 +3488,11 @@
|
|||||||
"{source} imagery could not be opened": "Bilder von {source} konnten nicht geöffnet werden",
|
"{source} imagery could not be opened": "Bilder von {source} konnten nicht geöffnet werden",
|
||||||
"{place} has no position to look for imagery at": "{place} hat keine Position, an der nach Bildern gesucht werden kann",
|
"{place} has no position to look for imagery at": "{place} hat keine Position, an der nach Bildern gesucht werden kann",
|
||||||
"No {source} imagery near {place}": "Keine Bilder von {source} in der Nähe von {place}",
|
"No {source} imagery near {place}": "Keine Bilder von {source} in der Nähe von {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (aktive Filter: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (aktive Filter: {filters})",
|
||||||
|
"Clouds": "Wolken",
|
||||||
|
"Fog": "Nebel",
|
||||||
|
"Rain": "Regen",
|
||||||
|
"Snow": "Schnee",
|
||||||
|
"Live weather: the conditions under the camera": "Live-Wetter: die Bedingungen unter der Kamera",
|
||||||
|
"No weather report here": "Hier gibt es keinen Wetterbericht"
|
||||||
}
|
}
|
||||||
@@ -3569,5 +3569,11 @@
|
|||||||
"{source} imagery could not be opened": "No se pudieron abrir las imágenes de {source}",
|
"{source} imagery could not be opened": "No se pudieron abrir las imágenes de {source}",
|
||||||
"{place} has no position to look for imagery at": "{place} no tiene una posición donde buscar imágenes",
|
"{place} has no position to look for imagery at": "{place} no tiene una posición donde buscar imágenes",
|
||||||
"No {source} imagery near {place}": "No hay imágenes de {source} cerca de {place}",
|
"No {source} imagery near {place}": "No hay imágenes de {source} cerca de {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (filtros activos: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (filtros activos: {filters})",
|
||||||
|
"Clouds": "Nubes",
|
||||||
|
"Fog": "Niebla",
|
||||||
|
"Rain": "Lluvia",
|
||||||
|
"Snow": "Nieve",
|
||||||
|
"Live weather: the conditions under the camera": "Clima en directo: las condiciones bajo la cámara",
|
||||||
|
"No weather report here": "No hay parte meteorológico aquí"
|
||||||
}
|
}
|
||||||
@@ -3569,5 +3569,11 @@
|
|||||||
"{source} imagery could not be opened": "Impossible d'ouvrir les images de {source}",
|
"{source} imagery could not be opened": "Impossible d'ouvrir les images de {source}",
|
||||||
"{place} has no position to look for imagery at": "{place} n'a pas de position où chercher des images",
|
"{place} has no position to look for imagery at": "{place} n'a pas de position où chercher des images",
|
||||||
"No {source} imagery near {place}": "Aucune image {source} près de {place}",
|
"No {source} imagery near {place}": "Aucune image {source} près de {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (filtres actifs : {filters})"
|
"{reason} (filters on: {filters})": "{reason} (filtres actifs : {filters})",
|
||||||
|
"Clouds": "Nuages",
|
||||||
|
"Fog": "Brouillard",
|
||||||
|
"Rain": "Pluie",
|
||||||
|
"Snow": "Neige",
|
||||||
|
"Live weather: the conditions under the camera": "Météo en direct : les conditions sous la caméra",
|
||||||
|
"No weather report here": "Aucun bulletin météo ici"
|
||||||
}
|
}
|
||||||
@@ -3569,5 +3569,11 @@
|
|||||||
"{source} imagery could not be opened": "לא ניתן היה לפתוח את הצילומים של {source}",
|
"{source} imagery could not be opened": "לא ניתן היה לפתוח את הצילומים של {source}",
|
||||||
"{place} has no position to look for imagery at": "ל-{place} אין מיקום לחיפוש צילומים",
|
"{place} has no position to look for imagery at": "ל-{place} אין מיקום לחיפוש צילומים",
|
||||||
"No {source} imagery near {place}": "אין צילומים של {source} ליד {place}",
|
"No {source} imagery near {place}": "אין צילומים של {source} ליד {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (מסננים פעילים: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (מסננים פעילים: {filters})",
|
||||||
|
"Clouds": "עננים",
|
||||||
|
"Fog": "ערפל",
|
||||||
|
"Rain": "גשם",
|
||||||
|
"Snow": "שלג",
|
||||||
|
"Live weather: the conditions under the camera": "מזג אוויר חי: התנאים מתחת למצלמה",
|
||||||
|
"No weather report here": "אין כאן דיווח מזג אוויר"
|
||||||
}
|
}
|
||||||
@@ -3569,5 +3569,11 @@
|
|||||||
"{source} imagery could not be opened": "Impossibile aprire le immagini di {source}",
|
"{source} imagery could not be opened": "Impossibile aprire le immagini di {source}",
|
||||||
"{place} has no position to look for imagery at": "{place} non ha una posizione in cui cercare immagini",
|
"{place} has no position to look for imagery at": "{place} non ha una posizione in cui cercare immagini",
|
||||||
"No {source} imagery near {place}": "Nessuna immagine di {source} vicino a {place}",
|
"No {source} imagery near {place}": "Nessuna immagine di {source} vicino a {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (filtri attivi: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (filtri attivi: {filters})",
|
||||||
|
"Clouds": "Nuvole",
|
||||||
|
"Fog": "Nebbia",
|
||||||
|
"Rain": "Pioggia",
|
||||||
|
"Snow": "Neve",
|
||||||
|
"Live weather: the conditions under the camera": "Meteo in diretta: le condizioni sotto la telecamera",
|
||||||
|
"No weather report here": "Nessun bollettino meteo qui"
|
||||||
}
|
}
|
||||||
@@ -3407,5 +3407,11 @@
|
|||||||
"{source} imagery could not be opened": "{source}の画像を開けませんでした",
|
"{source} imagery could not be opened": "{source}の画像を開けませんでした",
|
||||||
"{place} has no position to look for imagery at": "{place}には画像を探す位置がありません",
|
"{place} has no position to look for imagery at": "{place}には画像を探す位置がありません",
|
||||||
"No {source} imagery near {place}": "{place}の近くに{source}の画像はありません",
|
"No {source} imagery near {place}": "{place}の近くに{source}の画像はありません",
|
||||||
"{reason} (filters on: {filters})": "{reason}(有効なフィルター: {filters})"
|
"{reason} (filters on: {filters})": "{reason}(有効なフィルター: {filters})",
|
||||||
|
"Clouds": "雲",
|
||||||
|
"Fog": "霧",
|
||||||
|
"Rain": "雨",
|
||||||
|
"Snow": "雪",
|
||||||
|
"Live weather: the conditions under the camera": "ライブ気象:カメラ直下の状況",
|
||||||
|
"No weather report here": "ここには気象情報がありません"
|
||||||
}
|
}
|
||||||
@@ -3569,5 +3569,11 @@
|
|||||||
"{source} imagery could not be opened": "Não foi possível abrir as imagens de {source}",
|
"{source} imagery could not be opened": "Não foi possível abrir as imagens de {source}",
|
||||||
"{place} has no position to look for imagery at": "{place} não tem uma posição para buscar imagens",
|
"{place} has no position to look for imagery at": "{place} não tem uma posição para buscar imagens",
|
||||||
"No {source} imagery near {place}": "Nenhuma imagem de {source} perto de {place}",
|
"No {source} imagery near {place}": "Nenhuma imagem de {source} perto de {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (filtros ativos: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (filtros ativos: {filters})",
|
||||||
|
"Clouds": "Nuvens",
|
||||||
|
"Fog": "Nevoeiro",
|
||||||
|
"Rain": "Chuva",
|
||||||
|
"Snow": "Neve",
|
||||||
|
"Live weather: the conditions under the camera": "Clima ao vivo: as condições sob a câmara",
|
||||||
|
"No weather report here": "Sem boletim meteorológico aqui"
|
||||||
}
|
}
|
||||||
@@ -3650,5 +3650,11 @@
|
|||||||
"{source} imagery could not be opened": "Не удалось открыть снимки {source}",
|
"{source} imagery could not be opened": "Не удалось открыть снимки {source}",
|
||||||
"{place} has no position to look for imagery at": "У места «{place}» нет координат для поиска снимков",
|
"{place} has no position to look for imagery at": "У места «{place}» нет координат для поиска снимков",
|
||||||
"No {source} imagery near {place}": "Нет снимков {source} рядом с {place}",
|
"No {source} imagery near {place}": "Нет снимков {source} рядом с {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (включены фильтры: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (включены фильтры: {filters})",
|
||||||
|
"Clouds": "Облака",
|
||||||
|
"Fog": "Туман",
|
||||||
|
"Rain": "Дождь",
|
||||||
|
"Snow": "Снег",
|
||||||
|
"Live weather: the conditions under the camera": "Погода сейчас: условия под камерой",
|
||||||
|
"No weather report here": "Здесь нет сводки погоды"
|
||||||
}
|
}
|
||||||
@@ -3488,5 +3488,11 @@
|
|||||||
"Play speed": "Uppspelningshastighet",
|
"Play speed": "Uppspelningshastighet",
|
||||||
"Scroll or pinch to zoom, drag to move along · double-click to see it all": "Scrolla eller nyp för att zooma, dra för att flytta · dubbelklicka för att se allt",
|
"Scroll or pinch to zoom, drag to move along · double-click to see it all": "Scrolla eller nyp för att zooma, dra för att flytta · dubbelklicka för att se allt",
|
||||||
"Live": "Live",
|
"Live": "Live",
|
||||||
"Back to live": "Tillbaka till live"
|
"Back to live": "Tillbaka till live",
|
||||||
|
"Clouds": "Moln",
|
||||||
|
"Fog": "Dimma",
|
||||||
|
"Rain": "Regn",
|
||||||
|
"Snow": "Snö",
|
||||||
|
"Live weather: the conditions under the camera": "Väder live: förhållandena under kameran",
|
||||||
|
"No weather report here": "Ingen väderrapport här"
|
||||||
}
|
}
|
||||||
@@ -3650,5 +3650,11 @@
|
|||||||
"{source} imagery could not be opened": "Не вдалося відкрити знімки {source}",
|
"{source} imagery could not be opened": "Не вдалося відкрити знімки {source}",
|
||||||
"{place} has no position to look for imagery at": "Для місця «{place}» немає координат для пошуку знімків",
|
"{place} has no position to look for imagery at": "Для місця «{place}» немає координат для пошуку знімків",
|
||||||
"No {source} imagery near {place}": "Немає знімків {source} поблизу {place}",
|
"No {source} imagery near {place}": "Немає знімків {source} поблизу {place}",
|
||||||
"{reason} (filters on: {filters})": "{reason} (увімкнено фільтри: {filters})"
|
"{reason} (filters on: {filters})": "{reason} (увімкнено фільтри: {filters})",
|
||||||
|
"Clouds": "Хмари",
|
||||||
|
"Fog": "Туман",
|
||||||
|
"Rain": "Дощ",
|
||||||
|
"Snow": "Сніг",
|
||||||
|
"Live weather: the conditions under the camera": "Погода зараз: умови під камерою",
|
||||||
|
"No weather report here": "Тут немає зведення погоди"
|
||||||
}
|
}
|
||||||
@@ -3407,5 +3407,11 @@
|
|||||||
"{source} imagery could not be opened": "无法打开 {source} 影像",
|
"{source} imagery could not be opened": "无法打开 {source} 影像",
|
||||||
"{place} has no position to look for imagery at": "{place} 没有可查找影像的位置",
|
"{place} has no position to look for imagery at": "{place} 没有可查找影像的位置",
|
||||||
"No {source} imagery near {place}": "{place} 附近没有 {source} 影像",
|
"No {source} imagery near {place}": "{place} 附近没有 {source} 影像",
|
||||||
"{reason} (filters on: {filters})": "{reason}(已开启筛选:{filters})"
|
"{reason} (filters on: {filters})": "{reason}(已开启筛选:{filters})",
|
||||||
|
"Clouds": "云",
|
||||||
|
"Fog": "雾",
|
||||||
|
"Rain": "雨",
|
||||||
|
"Snow": "雪",
|
||||||
|
"Live weather: the conditions under the camera": "实时天气:相机下方的状况",
|
||||||
|
"No weather report here": "此处没有天气报告"
|
||||||
}
|
}
|
||||||
@@ -3407,5 +3407,11 @@
|
|||||||
"{source} imagery could not be opened": "無法打開 {source} 影像",
|
"{source} imagery could not be opened": "無法打開 {source} 影像",
|
||||||
"{place} has no position to look for imagery at": "{place} 沒有可查找影像的位置",
|
"{place} has no position to look for imagery at": "{place} 沒有可查找影像的位置",
|
||||||
"No {source} imagery near {place}": "{place} 附近沒有 {source} 影像",
|
"No {source} imagery near {place}": "{place} 附近沒有 {source} 影像",
|
||||||
"{reason} (filters on: {filters})": "{reason}(已開啟篩選:{filters})"
|
"{reason} (filters on: {filters})": "{reason}(已開啟篩選:{filters})",
|
||||||
|
"Clouds": "雲",
|
||||||
|
"Fog": "霧",
|
||||||
|
"Rain": "雨",
|
||||||
|
"Snow": "雪",
|
||||||
|
"Live weather: the conditions under the camera": "即時天氣:相機下方的狀況",
|
||||||
|
"No weather report here": "此處沒有天氣報告"
|
||||||
}
|
}
|
||||||
@@ -4642,6 +4642,71 @@ export function portChecks() {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
check(
|
||||||
|
'globe.weather',
|
||||||
|
'weather starts clear, keeps what a set leaves out, and clamps',
|
||||||
|
(h, r) => {
|
||||||
|
const first = r.globe.weather.get();
|
||||||
|
for (const key of ['clouds', 'fog', 'haze', 'rain', 'snow'])
|
||||||
|
equal(first[key], 0, `${key} clear at first`);
|
||||||
|
equal(first.wind.speedMps, 0, 'no wind at first');
|
||||||
|
r.globe.weather.set({ clouds: 0.6, rain: 2 });
|
||||||
|
r.globe.weather.set({
|
||||||
|
fog: -1,
|
||||||
|
wind: { speedMps: 8, fromDeg: -45 },
|
||||||
|
});
|
||||||
|
const after = r.globe.weather.get();
|
||||||
|
near(after.clouds, 0.6, 1e-9, 'clouds kept');
|
||||||
|
equal(after.rain, 1, 'rain clamped to 1');
|
||||||
|
equal(after.fog, 0, 'fog clamped to 0');
|
||||||
|
equal(after.snow, 0, 'snow untouched');
|
||||||
|
near(after.wind.speedMps, 8, 1e-9, 'wind speed');
|
||||||
|
near(after.wind.fromDeg, 315, 1e-9, 'wind direction wrapped');
|
||||||
|
after.clouds = 0;
|
||||||
|
near(r.globe.weather.get().clouds, 0.6, 1e-9, 'get hands out a copy');
|
||||||
|
},
|
||||||
|
{ capability: 'weather' },
|
||||||
|
),
|
||||||
|
check(
|
||||||
|
'globe.weather.drawn',
|
||||||
|
'clouds and fog change the drawn frame; clearing them brings it back',
|
||||||
|
async (h, r) => {
|
||||||
|
if (h.pixels === false) return { skip: 'reads pixels' };
|
||||||
|
// Low and looking toward the horizon, where fog and a cloud layer
|
||||||
|
// both show.
|
||||||
|
r.camera.setView({
|
||||||
|
destination: { ...AUSTIN, height: 600 },
|
||||||
|
orientation: { heading: 0, pitch: -0.12, roll: 0 },
|
||||||
|
});
|
||||||
|
const frame = async () => {
|
||||||
|
await drawn(h, r, 4);
|
||||||
|
await settled(r);
|
||||||
|
r.frame.renderNow();
|
||||||
|
return r.readPixels({ scale: 0.1 }).data;
|
||||||
|
};
|
||||||
|
const apart = (a, b) => {
|
||||||
|
let sum = 0;
|
||||||
|
for (let i = 0; i < a.length; i += 4)
|
||||||
|
for (let c = 0; c < 3; c++) sum += Math.abs(a[i + c] - b[i + c]);
|
||||||
|
return sum / ((a.length / 4) * 3);
|
||||||
|
};
|
||||||
|
const clear = await frame();
|
||||||
|
r.globe.weather.set({ clouds: 1, fog: 1 });
|
||||||
|
const weathered = await frame();
|
||||||
|
ok(
|
||||||
|
apart(clear, weathered) > 6,
|
||||||
|
`weather changes the frame (${apart(clear, weathered).toFixed(1)})`,
|
||||||
|
);
|
||||||
|
r.globe.weather.set({ clouds: 0, fog: 0 });
|
||||||
|
const again = await frame();
|
||||||
|
ok(
|
||||||
|
apart(clear, again) < 3,
|
||||||
|
`cleared, the frame is back (${apart(clear, again).toFixed(1)})`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ capability: 'weather' },
|
||||||
|
),
|
||||||
|
|
||||||
// --- Effects, credits, quality ---------------------------------------
|
// --- Effects, credits, quality ---------------------------------------
|
||||||
check(
|
check(
|
||||||
'effects.styles',
|
'effects.styles',
|
||||||
|
|||||||
Vendored
+2
@@ -152,6 +152,8 @@ export type Capability =
|
|||||||
| 'terrain'
|
| 'terrain'
|
||||||
/** Atmosphere scattering applied to drawn models. */
|
/** Atmosphere scattering applied to drawn models. */
|
||||||
| 'modelAtmosphere'
|
| 'modelAtmosphere'
|
||||||
|
/** Clouds, fog, haze, rain and snow around the view (`globe.weather`). */
|
||||||
|
| 'weather'
|
||||||
/** Imagery draped onto 3D tiles as well as the globe. */
|
/** Imagery draped onto 3D tiles as well as the globe. */
|
||||||
| 'imageryOnTiles'
|
| 'imageryOnTiles'
|
||||||
/** A screen-split comparison between imagery layers. */
|
/** A screen-split comparison between imagery layers. */
|
||||||
|
|||||||
@@ -76,20 +76,26 @@ function nestedShape(type) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** `[member, optional]` for every member, nested shapes dotted. */
|
/**
|
||||||
function members(type, prefix = '') {
|
* `[member, optional]` for every member, nested shapes dotted; a member of
|
||||||
|
* an optional shape is as optional as the shape.
|
||||||
|
*/
|
||||||
|
function members(type, prefix = '', inOptional = false) {
|
||||||
const out = [];
|
const out = [];
|
||||||
for (const property of checker.getPropertiesOfType(type)) {
|
for (const property of checker.getPropertiesOfType(type)) {
|
||||||
const name = `${prefix}${property.name}`;
|
const name = `${prefix}${property.name}`;
|
||||||
const optional = Boolean(property.flags & ts.SymbolFlags.Optional);
|
const optional =
|
||||||
|
inOptional || Boolean(property.flags & ts.SymbolFlags.Optional);
|
||||||
out.push([name, optional]);
|
out.push([name, optional]);
|
||||||
const declaration = property.valueDeclaration ?? property.declarations?.[0];
|
const declaration = property.valueDeclaration ?? property.declarations?.[0];
|
||||||
const propertyType = checker.getTypeOfSymbolAtLocation(
|
const declared = checker.getTypeOfSymbolAtLocation(property, declaration);
|
||||||
property,
|
// An optional member's shape, without the `undefined` its `?` adds.
|
||||||
declaration,
|
const propertyType =
|
||||||
);
|
property.flags & ts.SymbolFlags.Optional
|
||||||
|
? checker.getNonNullableType(declared)
|
||||||
|
: declared;
|
||||||
const nested = nestedShape(propertyType);
|
const nested = nestedShape(propertyType);
|
||||||
if (nested) out.push(...members(nested, `${name}.`));
|
if (nested) out.push(...members(nested, `${name}.`, optional));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+42
@@ -215,6 +215,36 @@ export interface SkySettings {
|
|||||||
lighting: boolean;
|
lighting: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `weather`: the conditions drawn around the view. Each strength is 0..1,
|
||||||
|
* 0 drawing none of it; all are 0 at first. Clouds are a layer above the
|
||||||
|
* ground that the camera can fly into and above; fog and haze thin what is
|
||||||
|
* seen with distance, fog close in, haze far off; rain and snow fall around
|
||||||
|
* the eye below the clouds and are not drawn from above them. A renderer
|
||||||
|
* fades what makes no sense at the camera's height (rain from orbit) by
|
||||||
|
* itself. None of it is picked or answers height queries. The application sets the
|
||||||
|
* conditions observed at the view, which the user can override.
|
||||||
|
*/
|
||||||
|
export interface WeatherSettings {
|
||||||
|
/** Cloud cover. */
|
||||||
|
clouds: number;
|
||||||
|
/** Fog: 1 is about 500 m visibility or less. */
|
||||||
|
fog: number;
|
||||||
|
/** Haze. */
|
||||||
|
haze: number;
|
||||||
|
/** Rain. */
|
||||||
|
rain: number;
|
||||||
|
/** Snow. */
|
||||||
|
snow: number;
|
||||||
|
/** What the clouds and precipitation drift with. */
|
||||||
|
wind: {
|
||||||
|
/** Metres per second. */
|
||||||
|
speedMps: number;
|
||||||
|
/** Where the wind blows from, degrees clockwise from north. */
|
||||||
|
fromDeg: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View-lit shading of the drawn terrain's own relief (the ellipsoid's
|
* View-lit shading of the drawn terrain's own relief (the ellipsoid's
|
||||||
* curvature where terrain has no normals); darkens only, at most
|
* curvature where terrain has no normals); darkens only, at most
|
||||||
@@ -295,6 +325,18 @@ export interface GlobePort {
|
|||||||
get(): SkySettings;
|
get(): SkySettings;
|
||||||
set(settings: Partial<SkySettings>): void;
|
set(settings: Partial<SkySettings>): void;
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* `weather`. `set` keeps each strength it is not given or given as no
|
||||||
|
* number, clamps the others to 0..1, and asks for a frame. `wind` is taken
|
||||||
|
* whole: a speed below 0 or missing is 0, the direction is wrapped into
|
||||||
|
* [0, 360) and a missing one is 0. `get` answers a copy of what was set;
|
||||||
|
* at first every strength and the wind speed are 0 (`CLEAR_WEATHER` in
|
||||||
|
* `src/render/weather.js`, whose `mergeWeather` is these rules).
|
||||||
|
*/
|
||||||
|
readonly weather?: {
|
||||||
|
get(): WeatherSettings;
|
||||||
|
set(settings: Partial<WeatherSettings>): void;
|
||||||
|
};
|
||||||
/** Whether that part of the base has finished loading what is in view. */
|
/** Whether that part of the base has finished loading what is in view. */
|
||||||
isSettled(kind: SettleKind): boolean;
|
isSettled(kind: SettleKind): boolean;
|
||||||
on(event: 'progress', cb: (progress: LoadProgress) => void): Off;
|
on(event: 'progress', cb: (progress: LoadProgress) => void): Off;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const CAPABILITIES = Object.freeze([
|
|||||||
'finestHeights',
|
'finestHeights',
|
||||||
'terrain',
|
'terrain',
|
||||||
'modelAtmosphere',
|
'modelAtmosphere',
|
||||||
|
'weather',
|
||||||
'imageryOnTiles',
|
'imageryOnTiles',
|
||||||
'splitSwipe',
|
'splitSwipe',
|
||||||
'imageryFrames',
|
'imageryFrames',
|
||||||
@@ -147,6 +148,9 @@ export const PORTS = deepFreeze({
|
|||||||
['setSurfaceShading', 'surfaceShading'],
|
['setSurfaceShading', 'surfaceShading'],
|
||||||
['imagery.getSplit', 'splitSwipe'],
|
['imagery.getSplit', 'splitSwipe'],
|
||||||
['imagery.setSplit', 'splitSwipe'],
|
['imagery.setSplit', 'splitSwipe'],
|
||||||
|
['weather', 'weather'],
|
||||||
|
['weather.get', 'weather'],
|
||||||
|
['weather.set', 'weather'],
|
||||||
]),
|
]),
|
||||||
draw: Object.fromEntries([
|
draw: Object.fromEntries([
|
||||||
...required(
|
...required(
|
||||||
@@ -353,6 +357,7 @@ export const ROLES = deepFreeze([
|
|||||||
members: [
|
members: [
|
||||||
'effects',
|
'effects',
|
||||||
'globe.sky',
|
'globe.sky',
|
||||||
|
'globe.weather',
|
||||||
'globe.setSurfaceShading',
|
'globe.setSurfaceShading',
|
||||||
'imageryLayer.lit',
|
'imageryLayer.lit',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { alongLength } from '../../geo/polyline.js';
|
|||||||
import { clusterScreenPoints } from '../../geo/screenCluster.js';
|
import { clusterScreenPoints } from '../../geo/screenCluster.js';
|
||||||
import { createInputRouter } from '../input/router.js';
|
import { createInputRouter } from '../input/router.js';
|
||||||
import { cssColor } from '../color.js';
|
import { cssColor } from '../color.js';
|
||||||
|
import { CLEAR_WEATHER, mergeWeather } from '../weather.js';
|
||||||
import { CAPABILITIES, CONTRACT_VERSION } from '../contract/index.js';
|
import { CAPABILITIES, CONTRACT_VERSION } from '../contract/index.js';
|
||||||
import { createStubCamera } from './camera.js';
|
import { createStubCamera } from './camera.js';
|
||||||
import { motionPosition } from '../motion/iconMotion.js';
|
import { motionPosition } from '../motion/iconMotion.js';
|
||||||
@@ -1659,6 +1660,16 @@ export function createStubRenderer(options = {}) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
if (capabilities.has('weather')) {
|
||||||
|
let weather = CLEAR_WEATHER;
|
||||||
|
globe.weather = {
|
||||||
|
get: () => mergeWeather(weather),
|
||||||
|
set(patch) {
|
||||||
|
weather = mergeWeather(weather, patch);
|
||||||
|
requestRender('weather');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
if (capabilities.has('globeVisibility'))
|
if (capabilities.has('globeVisibility'))
|
||||||
globe.isGlobeVisible = () => globeVisible;
|
globe.isGlobeVisible = () => globeVisible;
|
||||||
if (capabilities.has('surfaceIdentity'))
|
if (capabilities.has('surfaceIdentity'))
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ test('the stub passes the conformance suite', async () => {
|
|||||||
.filter((r) => r.status === 'skip')
|
.filter((r) => r.status === 'skip')
|
||||||
.map((r) => r.id);
|
.map((r) => r.id);
|
||||||
// It draws only models into pixels, so the sweep's, a lit shape's, a line outline's and
|
// It draws only models into pixels, so the sweep's, a lit shape's, a line outline's and
|
||||||
// the blends' (over a drawn shape) and video tiles' pixels go unread; its camera takes no user gestures: the drag and wheel scripts are for a
|
// the blends' (over a drawn shape), video tiles' and the weather's pixels go unread; its camera takes no user gestures: the drag and wheel scripts are for a
|
||||||
// camera that does (a controller over it, say).
|
// camera that does (a controller over it, say).
|
||||||
assert.deepEqual(skipped, [
|
assert.deepEqual(skipped, [
|
||||||
'effects.screenModulation.pixels',
|
'effects.screenModulation.pixels',
|
||||||
@@ -29,6 +29,7 @@ test('the stub passes the conformance suite', async () => {
|
|||||||
'draw.sets.blend',
|
'draw.sets.blend',
|
||||||
'draw.models.blend',
|
'draw.models.blend',
|
||||||
'globe.imagery.video',
|
'globe.imagery.video',
|
||||||
|
'globe.weather.drawn',
|
||||||
...CAMERA_SCRIPTS.filter(usesInput).map((s) => `camera.trace.${s.name}`),
|
...CAMERA_SCRIPTS.filter(usesInput).map((s) => `camera.trace.${s.name}`),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* The weather a renderer draws (`globe.weather`, the `weather` capability):
|
||||||
|
* clear at first, and how a `set` merges into what was set. Shared by every
|
||||||
|
* renderer that lists `weather`, so they keep and clamp it alike.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @type {Readonly<import('./contract/globe').WeatherSettings>} */
|
||||||
|
export const CLEAR_WEATHER = Object.freeze({
|
||||||
|
clouds: 0,
|
||||||
|
fog: 0,
|
||||||
|
haze: 0,
|
||||||
|
rain: 0,
|
||||||
|
snow: 0,
|
||||||
|
wind: Object.freeze({ speedMps: 0, fromDeg: 0 }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const STRENGTHS = ['clouds', 'fog', 'haze', 'rain', 'snow'];
|
||||||
|
|
||||||
|
const unit = (value, fallback) =>
|
||||||
|
Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : fallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `current` with `patch` applied: each strength given is clamped to 0..1,
|
||||||
|
* one not given (or not a number) is kept; `wind` is taken whole, its speed
|
||||||
|
* at least 0 and its direction in [0, 360).
|
||||||
|
* @param {import('./contract/globe').WeatherSettings} current
|
||||||
|
* @param {Partial<import('./contract/globe').WeatherSettings>} [patch]
|
||||||
|
* @returns {import('./contract/globe').WeatherSettings}
|
||||||
|
*/
|
||||||
|
export function mergeWeather(current, patch = {}) {
|
||||||
|
const next = { ...current, wind: { ...current.wind } };
|
||||||
|
for (const key of STRENGTHS) next[key] = unit(patch[key], current[key]);
|
||||||
|
if (patch.wind) {
|
||||||
|
const speed = Number(patch.wind.speedMps);
|
||||||
|
const from = Number(patch.wind.fromDeg);
|
||||||
|
next.wind = {
|
||||||
|
speedMps: Number.isFinite(speed) ? Math.max(0, speed) : 0,
|
||||||
|
fromDeg: Number.isFinite(from) ? ((from % 360) + 360) % 360 : 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { test } from 'node:test';
|
||||||
|
|
||||||
|
import { CLEAR_WEATHER, mergeWeather } from './weather.js';
|
||||||
|
|
||||||
|
test('clear weather draws nothing', () => {
|
||||||
|
for (const key of ['clouds', 'fog', 'haze', 'rain', 'snow'])
|
||||||
|
assert.equal(CLEAR_WEATHER[key], 0, key);
|
||||||
|
assert.deepEqual(CLEAR_WEATHER.wind, { speedMps: 0, fromDeg: 0 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a set keeps what it is not given and clamps strengths', () => {
|
||||||
|
const a = mergeWeather(CLEAR_WEATHER, { clouds: 0.4, rain: 3 });
|
||||||
|
assert.equal(a.clouds, 0.4);
|
||||||
|
assert.equal(a.rain, 1);
|
||||||
|
const b = mergeWeather(a, { fog: -1, snow: Number.NaN });
|
||||||
|
assert.equal(b.fog, 0);
|
||||||
|
assert.equal(b.snow, 0);
|
||||||
|
assert.equal(b.clouds, 0.4, 'clouds kept');
|
||||||
|
assert.equal(b.rain, 1, 'rain kept');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('wind is taken whole, its speed at least 0, its direction wrapped', () => {
|
||||||
|
const a = mergeWeather(CLEAR_WEATHER, {
|
||||||
|
wind: { speedMps: 12, fromDeg: -90 },
|
||||||
|
});
|
||||||
|
assert.deepEqual(a.wind, { speedMps: 12, fromDeg: 270 });
|
||||||
|
const b = mergeWeather(a, { wind: { speedMps: -3, fromDeg: 725 } });
|
||||||
|
assert.deepEqual(b.wind, { speedMps: 0, fromDeg: 5 });
|
||||||
|
const c = mergeWeather(b, { clouds: 1 });
|
||||||
|
assert.deepEqual(c.wind, b.wind, 'wind kept');
|
||||||
|
assert.notEqual(c.wind, b.wind, 'a copy');
|
||||||
|
});
|
||||||
@@ -28,6 +28,17 @@ export const useDisplayStore = defineStore('gev-display', () => {
|
|||||||
models3d.value = markRaw(next);
|
models3d.value = markRaw(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Weather group, `{live, status, values}` (values in percent by
|
||||||
|
* condition); null where the renderer draws no weather.
|
||||||
|
*/
|
||||||
|
const weather = shallowRef(null);
|
||||||
|
|
||||||
|
/** @param {?object} next A fresh presentation of the Weather group. */
|
||||||
|
function publishWeather(next) {
|
||||||
|
weather.value = next && markRaw(next);
|
||||||
|
}
|
||||||
|
|
||||||
/** The Draw controls; null until the draw tool first renders. */
|
/** The Draw controls; null until the draw tool first renders. */
|
||||||
const draw = shallowRef(null);
|
const draw = shallowRef(null);
|
||||||
|
|
||||||
@@ -108,6 +119,8 @@ export const useDisplayStore = defineStore('gev-display', () => {
|
|||||||
publish,
|
publish,
|
||||||
models3d,
|
models3d,
|
||||||
publishModels3d,
|
publishModels3d,
|
||||||
|
weather,
|
||||||
|
publishWeather,
|
||||||
draw,
|
draw,
|
||||||
publishDraw,
|
publishDraw,
|
||||||
geoImport,
|
geoImport,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { StyleParameterRows } from '../../styleParameters.js';
|
|||||||
// and each publishes them; until they do, the panel shows its initial markup.
|
// and each publishes them; until they do, the panel shows its initial markup.
|
||||||
// Draw and Import live in UTILITIES (LayerPanelsView).
|
// Draw and Import live in UTILITIES (LayerPanelsView).
|
||||||
const display = useDisplayStore();
|
const display = useDisplayStore();
|
||||||
const { view, models3d, parameters, cockpitPortal } = storeToRefs(display);
|
const { view, models3d, parameters, cockpitPortal, weather } = storeToRefs(display);
|
||||||
// A control's change goes to its owner (DisplayBindings).
|
// A control's change goes to its owner (DisplayBindings).
|
||||||
const act = (name, ...args) => display.act(name, ...args);
|
const act = (name, ...args) => display.act(name, ...args);
|
||||||
const pct = (value) => `${value}%`;
|
const pct = (value) => `${value}%`;
|
||||||
@@ -35,6 +35,12 @@ const celestialTitle = computed(() =>
|
|||||||
? t('Celestial ring — available in Normal style')
|
? t('Celestial ring — available in Normal style')
|
||||||
: t('Celestial ring — reveal the full globe'),
|
: t('Celestial ring — reveal the full globe'),
|
||||||
);
|
);
|
||||||
|
const weatherRows = computed(() => [
|
||||||
|
{ key: 'clouds', label: t('Clouds') },
|
||||||
|
{ key: 'fog', label: t('Fog') },
|
||||||
|
{ key: 'rain', label: t('Rain') },
|
||||||
|
{ key: 'snow', label: t('Snow') },
|
||||||
|
]);
|
||||||
const models3dOn = computed(() => models3d.value?.pressed ?? true);
|
const models3dOn = computed(() => models3d.value?.pressed ?? true);
|
||||||
const modelsMode = computed(() => models3d.value?.mode ?? 'proximity');
|
const modelsMode = computed(() => models3d.value?.mode ?? 'proximity');
|
||||||
const modelsOptions = computed(() => [
|
const modelsOptions = computed(() => [
|
||||||
@@ -175,6 +181,22 @@ const allocationOptions = computed(() => [
|
|||||||
<span class="pp-label">{{ t('Celestial') }}</span>
|
<span class="pp-label">{{ t('Celestial') }}</span>
|
||||||
</UiButton>
|
</UiButton>
|
||||||
</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')">
|
||||||
|
<span class="pp-icon material-symbols-outlined" aria-hidden="true">partly_cloudy_day</span>
|
||||||
|
<span class="pp-label">{{ t('Weather') }} · {{ t('Live') }}</span>
|
||||||
|
<input type="checkbox" id="weather-live-toggle" @change="act('setWeatherLive', $event.target.checked)" :checked="weather.live" />
|
||||||
|
</label>
|
||||||
|
<div v-if="weather.live && weather.status === 'unavailable'" class="pp-slider-row visible" id="weather-status">
|
||||||
|
<span class="pp-slider-mini-label">{{ t('No weather report here') }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-for="row in weatherRows" :key="row.key" class="pp-slider-row visible" :id="`weather-${row.key}-row`">
|
||||||
|
<span class="pp-slider-mini-label">{{ row.label }}</span>
|
||||||
|
<UiSlider class="pp-slider" :id="`weather-${row.key}-slider`" @update:model-value="act('setWeatherValue', row.key, $event)" min="0" max="100" :model-value="weather.values[row.key] ?? 0" :aria-label="row.label" />
|
||||||
|
<span class="pp-slider-value">{{ pct(weather.values[row.key] ?? 0) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<button class="pp-toggle-btn" id="clean-view-toggle" @click="act('toggleCleanView')" :title="t('Hide UI chrome')">
|
<button class="pp-toggle-btn" id="clean-view-toggle" @click="act('toggleCleanView')" :title="t('Hide UI chrome')">
|
||||||
<span class="pp-icon">□</span>
|
<span class="pp-icon">□</span>
|
||||||
<span class="pp-label">{{ t('Clean UI') }}</span>
|
<span class="pp-label">{{ t('Clean UI') }}</span>
|
||||||
|
|||||||
@@ -0,0 +1,272 @@
|
|||||||
|
/**
|
||||||
|
* The weather drawn around the view, on a renderer that draws weather (the
|
||||||
|
* `weather` capability, `globe.weather`). Live, it is the conditions observed
|
||||||
|
* under the camera, asked of the weather service again after five minutes or
|
||||||
|
* 25 km of movement; the user can turn live off and set clouds, fog, rain and
|
||||||
|
* snow by hand. Without the capability it does nothing and the Display panel
|
||||||
|
* shows no weather controls.
|
||||||
|
*/
|
||||||
|
import { findCamera, findGlobe } from './render/rendererOf.js';
|
||||||
|
import { greatCircleMeters } from './geoDistance.js';
|
||||||
|
import { deriveWeatherEffectProfile } from './weatherEffectsMath.js';
|
||||||
|
import { CLEAR_WEATHER } from './render/weather.js';
|
||||||
|
|
||||||
|
const REFRESH_MS = 5 * 60_000;
|
||||||
|
const MOVE_REFRESH_M = 25_000;
|
||||||
|
/** Above this the camera is over a region, not a place: no new observation. */
|
||||||
|
const OBSERVE_BELOW_M = 200_000;
|
||||||
|
const STORAGE_KEY = 'godsEyeView.viewWeather';
|
||||||
|
/** The conditions the user sets by hand, in the order the panel lists them. */
|
||||||
|
export const MANUAL_KEYS = Object.freeze(['clouds', 'fog', 'rain', 'snow']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What a renderer draws for an observation: the profile the app derives from
|
||||||
|
* the report (`deriveWeatherEffectProfile`), clear when there is none.
|
||||||
|
* @param {object|null|undefined} observation The weather service's `weather`.
|
||||||
|
* @returns {import('./render/contract/globe').WeatherSettings}
|
||||||
|
*/
|
||||||
|
export function weatherFromObservation(observation) {
|
||||||
|
const profile = deriveWeatherEffectProfile(observation);
|
||||||
|
if (!profile.available) return CLEAR_WEATHER;
|
||||||
|
const kph = Number(observation.windKph);
|
||||||
|
return {
|
||||||
|
clouds: profile.cloud,
|
||||||
|
fog: profile.fog,
|
||||||
|
haze: profile.haze,
|
||||||
|
rain: profile.rain,
|
||||||
|
snow: profile.snow,
|
||||||
|
wind: {
|
||||||
|
speedMps: Number.isFinite(kph) ? Math.max(0, kph / 3.6) : 0,
|
||||||
|
fromDeg: profile.windDirectionDeg,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The saved choice: live, and the hand-set strengths (0..1). */
|
||||||
|
function readSaved(storage) {
|
||||||
|
try {
|
||||||
|
const saved = JSON.parse(storage?.getItem(STORAGE_KEY) ?? 'null');
|
||||||
|
if (!saved || typeof saved !== 'object') return null;
|
||||||
|
const manual = {};
|
||||||
|
for (const key of MANUAL_KEYS) {
|
||||||
|
const value = Number(saved.manual?.[key]);
|
||||||
|
manual[key] = Number.isFinite(value)
|
||||||
|
? Math.min(1, Math.max(0, value))
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
return { live: saved.live !== false, manual };
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {object} viewer The scene host a renderer is bound to.
|
||||||
|
* @param {object} options
|
||||||
|
* @param {{getConditions: Function}} options.weatherService
|
||||||
|
* @param {{publishWeather: Function, connect: Function, detach: Function}} options.store
|
||||||
|
* The Display store: the panel's Weather group and its controls.
|
||||||
|
* @param {Storage} [options.storage]
|
||||||
|
* @param {() => number} [options.now]
|
||||||
|
* @returns {{refresh: () => Promise<void>, destroy: () => void}}
|
||||||
|
*/
|
||||||
|
export function createViewWeather(
|
||||||
|
viewer,
|
||||||
|
{
|
||||||
|
weatherService,
|
||||||
|
store,
|
||||||
|
storage = globalThis.localStorage,
|
||||||
|
now = () => Date.now(),
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const port = findGlobe(viewer)?.weather ?? null;
|
||||||
|
if (!port) {
|
||||||
|
store?.publishWeather?.(null);
|
||||||
|
return { refresh: async () => {}, destroy() {} };
|
||||||
|
}
|
||||||
|
const saved = readSaved(storage);
|
||||||
|
let live = saved?.live ?? true;
|
||||||
|
const manual = saved?.manual ?? { clouds: 0, fog: 0, rain: 0, snow: 0 };
|
||||||
|
/** Haze by hand: what was shown when live went off, until fog is moved. */
|
||||||
|
let manualHaze = null;
|
||||||
|
/** The observation under `anchor`, or null: none for where the camera is. */
|
||||||
|
let observed = null;
|
||||||
|
/** `loading`, `live`, `unavailable` or `none` (no place under the camera). */
|
||||||
|
let status = 'loading';
|
||||||
|
let fetchedAt = -Infinity;
|
||||||
|
let anchor = null;
|
||||||
|
/** The fetch in flight: its abort and the point it asks about. */
|
||||||
|
let pending = null;
|
||||||
|
let timer = null;
|
||||||
|
let destroyed = false;
|
||||||
|
|
||||||
|
function settings() {
|
||||||
|
if (live) return observed ?? CLEAR_WEATHER;
|
||||||
|
return {
|
||||||
|
...manual,
|
||||||
|
haze: manualHaze ?? manual.fog * 0.78,
|
||||||
|
// The observed wind, or still air.
|
||||||
|
wind: (observed ?? CLEAR_WEATHER).wind,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function apply() {
|
||||||
|
port.set(settings());
|
||||||
|
publish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function publish() {
|
||||||
|
const shown = settings();
|
||||||
|
store?.publishWeather?.({
|
||||||
|
live,
|
||||||
|
status,
|
||||||
|
values: Object.fromEntries(
|
||||||
|
MANUAL_KEYS.map((key) => [key, Math.round(shown[key] * 100)]),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
try {
|
||||||
|
storage?.setItem(STORAGE_KEY, JSON.stringify({ live, manual }));
|
||||||
|
} catch {
|
||||||
|
// Private mode: the choice lasts the visit.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hand-set from what is shown now, so going off live changes nothing. */
|
||||||
|
function takeShown() {
|
||||||
|
const shown = settings();
|
||||||
|
for (const key of MANUAL_KEYS) manual[key] = shown[key];
|
||||||
|
manualHaze = shown.haze;
|
||||||
|
live = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cameraPoint() {
|
||||||
|
const pose = findCamera(viewer)?.pose();
|
||||||
|
if (!pose || !Number.isFinite(pose.lat) || !Number.isFinite(pose.lon))
|
||||||
|
return null;
|
||||||
|
return { lat: pose.lat, lon: pose.lon, height: pose.height };
|
||||||
|
}
|
||||||
|
|
||||||
|
const far = (a, b) => !a || !b || greatCircleMeters(a, b) >= MOVE_REFRESH_M;
|
||||||
|
|
||||||
|
/** Ask for the conditions under the camera when they are due. */
|
||||||
|
async function refresh() {
|
||||||
|
if (destroyed || !live || globalThis.document?.hidden) return;
|
||||||
|
const point = cameraPoint();
|
||||||
|
if (!point) return;
|
||||||
|
if (!(point.height < OBSERVE_BELOW_M)) {
|
||||||
|
// Over a region, not a place: no one place's weather over it all.
|
||||||
|
pending?.abort.abort();
|
||||||
|
pending = null;
|
||||||
|
if (observed || status !== 'none') {
|
||||||
|
observed = null;
|
||||||
|
anchor = null;
|
||||||
|
status = 'none';
|
||||||
|
apply();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (far(anchor, point) && observed) {
|
||||||
|
// Moved off the place observed: clear until the new report comes.
|
||||||
|
observed = null;
|
||||||
|
status = 'loading';
|
||||||
|
apply();
|
||||||
|
}
|
||||||
|
const due = !observed || now() - fetchedAt >= REFRESH_MS;
|
||||||
|
if (!due) return;
|
||||||
|
// A fetch for a place far from here is out of date: ask again here.
|
||||||
|
if (pending && !far(pending.point, point)) return;
|
||||||
|
pending?.abort.abort();
|
||||||
|
const request = { abort: new AbortController(), point };
|
||||||
|
pending = request;
|
||||||
|
try {
|
||||||
|
const payload = await weatherService.getConditions(point.lat, point.lon, {
|
||||||
|
signal: request.abort.signal,
|
||||||
|
});
|
||||||
|
if (destroyed || pending !== request) return;
|
||||||
|
observed = weatherFromObservation(payload?.weather);
|
||||||
|
status = payload?.weather ? 'live' : 'unavailable';
|
||||||
|
} catch (error) {
|
||||||
|
if (destroyed || pending !== request || error?.name === 'AbortError')
|
||||||
|
return;
|
||||||
|
// Missing weather fails clear instead of inventing conditions.
|
||||||
|
observed = CLEAR_WEATHER;
|
||||||
|
status = 'unavailable';
|
||||||
|
} finally {
|
||||||
|
if (pending === request) pending = null;
|
||||||
|
}
|
||||||
|
fetchedAt = now();
|
||||||
|
anchor = point;
|
||||||
|
schedule();
|
||||||
|
if (live) apply();
|
||||||
|
else publish();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The next refresh, five minutes after the last report. */
|
||||||
|
function schedule() {
|
||||||
|
if (timer !== null) clearTimeout(timer);
|
||||||
|
timer = null;
|
||||||
|
if (destroyed) return;
|
||||||
|
const wait = Number.isFinite(fetchedAt)
|
||||||
|
? Math.max(1000, fetchedAt + REFRESH_MS - now())
|
||||||
|
: REFRESH_MS;
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
timer = null;
|
||||||
|
void refresh().finally(() => {
|
||||||
|
if (timer === null) schedule();
|
||||||
|
});
|
||||||
|
}, wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onVisible = () => {
|
||||||
|
if (!globalThis.document?.hidden) void refresh();
|
||||||
|
};
|
||||||
|
globalThis.document?.addEventListener?.('visibilitychange', onVisible);
|
||||||
|
const offMove = findCamera(viewer)?.on('moveEnd', () => void refresh());
|
||||||
|
const token = store?.connect?.({
|
||||||
|
setWeatherLive(next) {
|
||||||
|
if (Boolean(next) === live) return;
|
||||||
|
if (next) {
|
||||||
|
live = true;
|
||||||
|
manualHaze = null;
|
||||||
|
} else {
|
||||||
|
takeShown();
|
||||||
|
}
|
||||||
|
save();
|
||||||
|
apply();
|
||||||
|
if (live) void refresh();
|
||||||
|
},
|
||||||
|
setWeatherValue(key, pct) {
|
||||||
|
if (!MANUAL_KEYS.includes(key)) return;
|
||||||
|
const value = Number(pct) / 100;
|
||||||
|
if (!Number.isFinite(value)) return;
|
||||||
|
// Moving a slider takes the weather off live, from what it shows.
|
||||||
|
if (live) takeShown();
|
||||||
|
manual[key] = Math.min(1, Math.max(0, value));
|
||||||
|
if (key === 'fog') manualHaze = null;
|
||||||
|
save();
|
||||||
|
apply();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
apply();
|
||||||
|
void refresh();
|
||||||
|
schedule();
|
||||||
|
|
||||||
|
return {
|
||||||
|
refresh,
|
||||||
|
destroy() {
|
||||||
|
destroyed = true;
|
||||||
|
pending?.abort.abort();
|
||||||
|
pending = null;
|
||||||
|
globalThis.document?.removeEventListener?.('visibilitychange', onVisible);
|
||||||
|
if (timer !== null) clearTimeout(timer);
|
||||||
|
timer = null;
|
||||||
|
offMove?.();
|
||||||
|
if (token) store?.detach?.(token);
|
||||||
|
store?.publishWeather?.(null);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
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 { CAPABILITIES } from './render/contract/index.js';
|
||||||
|
import { createViewWeather, weatherFromObservation } from './viewWeather.js';
|
||||||
|
|
||||||
|
const RAIN = {
|
||||||
|
weatherCode: 63,
|
||||||
|
cloudCoverPct: 90,
|
||||||
|
precipitationMm: 2,
|
||||||
|
windKph: 36,
|
||||||
|
windDirectionDeg: 200,
|
||||||
|
visibilityM: 9000,
|
||||||
|
};
|
||||||
|
|
||||||
|
function setup({ capabilities = CAPABILITIES, height = 1500, reply } = {}) {
|
||||||
|
const renderer = createStubRenderer({ capabilities });
|
||||||
|
const host = {};
|
||||||
|
const unbind = bindRenderer(host, renderer);
|
||||||
|
renderer.camera.setView({
|
||||||
|
destination: { lon: -97.74, lat: 30.27, height },
|
||||||
|
orientation: { heading: 0, pitch: -0.3, roll: 0 },
|
||||||
|
});
|
||||||
|
const asked = [];
|
||||||
|
const weatherService = {
|
||||||
|
async getConditions(lat, lon) {
|
||||||
|
asked.push([lat, lon]);
|
||||||
|
if (reply instanceof Error) throw reply;
|
||||||
|
return reply ?? { status: 'ready', weather: RAIN };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const published = [];
|
||||||
|
const owners = [];
|
||||||
|
const store = {
|
||||||
|
publishWeather: (view) => published.push(view),
|
||||||
|
connect: (actions) => (owners.push(actions), actions),
|
||||||
|
detach: (token) => owners.splice(owners.indexOf(token), 1),
|
||||||
|
};
|
||||||
|
const saved = new Map();
|
||||||
|
const storage = {
|
||||||
|
getItem: (k) => saved.get(k) ?? null,
|
||||||
|
setItem: (k, v) => saved.set(k, v),
|
||||||
|
};
|
||||||
|
const act = (name, ...args) => owners.at(-1)?.[name](...args);
|
||||||
|
return {
|
||||||
|
renderer,
|
||||||
|
host,
|
||||||
|
weatherService,
|
||||||
|
store,
|
||||||
|
storage,
|
||||||
|
asked,
|
||||||
|
published,
|
||||||
|
act,
|
||||||
|
saved,
|
||||||
|
done() {
|
||||||
|
unbind();
|
||||||
|
renderer.destroy();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const settle = () => new Promise((done) => setTimeout(done, 0));
|
||||||
|
|
||||||
|
test('an observation becomes what the renderer draws; none is clear', () => {
|
||||||
|
const rain = weatherFromObservation(RAIN);
|
||||||
|
assert.ok(rain.rain > 0.2, 'rain');
|
||||||
|
assert.ok(rain.clouds > 0.8, 'clouds');
|
||||||
|
assert.equal(rain.snow, 0);
|
||||||
|
assert.equal(rain.wind.speedMps, 10);
|
||||||
|
assert.equal(rain.wind.fromDeg, 200);
|
||||||
|
assert.equal(weatherFromObservation(null).clouds, 0);
|
||||||
|
assert.equal(weatherFromObservation({ weatherCode: null }).rain, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('without the weather capability it does nothing and shows nothing', async (t) => {
|
||||||
|
const s = setup({
|
||||||
|
capabilities: CAPABILITIES.filter((c) => c !== 'weather'),
|
||||||
|
});
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.deepEqual(s.published, [null]);
|
||||||
|
assert.deepEqual(s.asked, []);
|
||||||
|
weather.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('live, it draws the conditions under the camera', async (t) => {
|
||||||
|
const s = setup();
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.equal(s.asked.length, 1);
|
||||||
|
assert.ok(Math.abs(s.asked[0][0] - 30.27) < 1e-6, 'asked at the camera');
|
||||||
|
const drawn = s.renderer.globe.weather.get();
|
||||||
|
assert.ok(drawn.rain > 0.2 && drawn.clouds > 0.8, 'rain and clouds drawn');
|
||||||
|
const last = s.published.at(-1);
|
||||||
|
assert.equal(last.live, true);
|
||||||
|
assert.equal(last.status, 'live');
|
||||||
|
assert.equal(last.values.rain, Math.round(drawn.rain * 100));
|
||||||
|
// Not due again: no second ask on a small move.
|
||||||
|
await weather.refresh();
|
||||||
|
assert.equal(s.asked.length, 1);
|
||||||
|
weather.destroy();
|
||||||
|
assert.equal(s.published.at(-1), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a slider takes it off live from what it shows, and the choice is kept', async (t) => {
|
||||||
|
const s = setup();
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
const before = s.renderer.globe.weather.get();
|
||||||
|
s.act('setWeatherValue', 'snow', 40);
|
||||||
|
const after = s.renderer.globe.weather.get();
|
||||||
|
assert.equal(after.snow, 0.4);
|
||||||
|
assert.equal(after.clouds, before.clouds, 'clouds kept from live');
|
||||||
|
assert.equal(s.published.at(-1).live, false);
|
||||||
|
weather.destroy();
|
||||||
|
// A new page keeps the hand-set weather and asks for none.
|
||||||
|
const again = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.equal(s.renderer.globe.weather.get().snow, 0.4);
|
||||||
|
assert.equal(s.asked.length, 1);
|
||||||
|
s.act('setWeatherLive', true);
|
||||||
|
await settle();
|
||||||
|
assert.equal(s.published.at(-1).live, true);
|
||||||
|
again.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('no report fails clear and says so', async (t) => {
|
||||||
|
const s = setup({ reply: new Error('down') });
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.equal(s.renderer.globe.weather.get().clouds, 0);
|
||||||
|
assert.equal(s.published.at(-1).status, 'unavailable');
|
||||||
|
weather.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('from orbit it asks for no observation', async (t) => {
|
||||||
|
const s = setup({ height: 5_000_000 });
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.deepEqual(s.asked, []);
|
||||||
|
weather.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rising to orbit clears the place observed; coming down asks again', async (t) => {
|
||||||
|
const s = setup();
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.ok(s.renderer.globe.weather.get().clouds > 0.8);
|
||||||
|
s.renderer.camera.setView({
|
||||||
|
destination: { lon: -97.74, lat: 30.27, height: 8_000_000 },
|
||||||
|
});
|
||||||
|
await weather.refresh();
|
||||||
|
assert.equal(s.renderer.globe.weather.get().clouds, 0, 'clear from orbit');
|
||||||
|
assert.equal(s.published.at(-1).status, 'none');
|
||||||
|
s.renderer.camera.setView({
|
||||||
|
destination: { lon: 139.7, lat: 35.7, height: 1500 },
|
||||||
|
});
|
||||||
|
await weather.refresh();
|
||||||
|
assert.equal(s.asked.length, 2);
|
||||||
|
assert.ok(Math.abs(s.asked[1][0] - 35.7) < 1e-6, 'asked at Tokyo');
|
||||||
|
weather.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a move far from a fetch in flight asks again where the camera is', async (t) => {
|
||||||
|
const s = setup();
|
||||||
|
t.after(() => s.done());
|
||||||
|
const replies = [];
|
||||||
|
s.weatherService.getConditions = (lat, lon, { signal }) => {
|
||||||
|
s.asked.push([lat, lon]);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
replies.push(resolve);
|
||||||
|
signal.addEventListener('abort', () =>
|
||||||
|
reject(Object.assign(new Error('aborted'), { name: 'AbortError' })),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
assert.equal(s.asked.length, 1, 'Austin asked');
|
||||||
|
s.renderer.camera.setView({
|
||||||
|
destination: { lon: -104.99, lat: 39.74, height: 1500 },
|
||||||
|
});
|
||||||
|
const denver = weather.refresh();
|
||||||
|
assert.equal(s.asked.length, 2, 'Denver asked while Austin was pending');
|
||||||
|
replies[0]({ weather: RAIN });
|
||||||
|
replies[1]({ weather: { weatherCode: 71, cloudCoverPct: 100 } });
|
||||||
|
await denver;
|
||||||
|
await settle();
|
||||||
|
const drawn = s.renderer.globe.weather.get();
|
||||||
|
assert.ok(drawn.snow > 0, 'Denver’s snow drawn');
|
||||||
|
assert.equal(drawn.rain, 0, 'not Austin’s rain');
|
||||||
|
weather.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('turning live off keeps what was shown, haze included', async (t) => {
|
||||||
|
const s = setup();
|
||||||
|
t.after(() => s.done());
|
||||||
|
const weather = createViewWeather(s.host, s);
|
||||||
|
await settle();
|
||||||
|
const shown = s.renderer.globe.weather.get();
|
||||||
|
s.act('setWeatherLive', false);
|
||||||
|
assert.deepEqual(s.renderer.globe.weather.get(), shown);
|
||||||
|
s.act('setWeatherValue', 'rain', 10);
|
||||||
|
const after = s.renderer.globe.weather.get();
|
||||||
|
assert.equal(after.rain, 0.1);
|
||||||
|
assert.equal(after.haze, shown.haze, 'haze kept until fog moves');
|
||||||
|
s.act('setWeatherValue', 'fog', 50);
|
||||||
|
assert.equal(s.renderer.globe.weather.get().haze, 0.5 * 0.78);
|
||||||
|
weather.destroy();
|
||||||
|
});
|
||||||
Reference in new issue
Block a user