feat(globe): Navara's cinematic look by default

navaraScenePlan gains a pure `cinematic` plan, now the default of the app's
Navara mode (`?look=photoreal|minimal` picks the others): photoreal plus
volumetric clouds (low quality, layers from 1,500 m, no ground shadows),
ACES tone mapping, brighter stars and no sun shadow maps. From space, at
rest, the aerial perspective lights the globe from the atmosphere for a
real night side and terminator; it switches off below 1,000 km so the
Google tiles keep their baked light.

look.js builds the plan and keeps it current on frames Navara draws
anyway: the atmosphere's sun date follows the wall clock (the HUD's SUN
elevation), and the clouds hide above 4 km or over high ground in view,
parking their last image so the aerial perspective shows no ghosts.
This commit is contained in:
German Khokhlov committed 2026-10-16 02:29:46 +04:00
1 parent 177446c0be
commit ac081a008d
8 files changed
+589 -34

No files matched your search

+76 -10
View File
@@ -3,13 +3,16 @@
// dynamic import() so Navara stays out of the Cesium-mode bundle.
import ThreeView from '@navaramap/three';
import * as geo from '../../geo/index.js';
import { DefaultPlugin } from '@navaramap/three-default-plugin';
import { createNavaraEngine } from './createNavaraEngine.js';
import { navaraHooks } from './internals.js';
import { buildNavaraLook } from './look.js';
import {
NAVARA_CONTEXT_ATTRIBUTES,
navaraScenePlan,
navaraViewOptions,
resolveNavaraLook,
} from './viewOptions.js';
// Navara 0.2.1 has no preserveDrawingBuffer option but takes a canvas whose
@@ -29,36 +32,98 @@ function preservedCanvas(container) {
return canvas;
}
/** The camera height, or NaN while the camera has no position yet. */
function cameraHeight(camera) {
try {
return camera.height();
} catch {
return Number.NaN;
}
}
// The height of the ground in view, for the look's cloud rule: the depth of
// the last drawn frame halfway down the lower half (the near ground, not the
// horizon: over a canyon the rim, not the far floor). A depth read stalls for
// 1.5 to 4 ms, so it runs only when the camera comes to rest (and once more
// when the tiles in view have loaded).
function groundInView(engine) {
const { width, height } = engine.host.size();
const point = engine.picker.pickPosition({
x: width / 2,
y: height * 0.75,
});
const place =
point && geo.cartographic.fromCartesian(point, geo.ellipsoid.WGS84);
return place ? place.height : Number.NaN;
}
/**
* @param {{
* container: HTMLElement,
* effects?: 'minimal' | 'photoreal',
* effects?: 'minimal' | 'photoreal' | 'cinematic',
* search?: string,
* pixelRatio?: number,
* }} options `pixelRatio` only for measurements; the product uses the device's.
* }} options `effects` names the look (cinematic by default); `search`, the
* page's query string, picks it from `?look=` instead (the app's way).
* `pixelRatio` only for measurements; the product uses the device's.
* @returns {Promise<{ view: object, engine: import('../contract.js').GlobeEngine, destroy: () => void }>}
*/
export async function createNavaraGlobe({ container, effects, pixelRatio }) {
export async function createNavaraGlobe({
container,
effects,
search,
pixelRatio,
}) {
if (!container) throw new TypeError('createNavaraGlobe needs a container');
const plan = navaraScenePlan(effects);
const canvas = preservedCanvas(container);
let view;
let engine;
let removeLook = null;
try {
view = new ThreeView(navaraViewOptions({ container, canvas, pixelRatio }));
const plugin = new DefaultPlugin();
view.addPlugin(plugin);
await view.init();
if (plan.pluginDefault) plugin.addDefaultPhotorealScene();
else {
for (const name of plan.meshes) view.addMesh({ [name]: {} });
for (const name of plan.lights) view.addLight({ [name]: {} });
for (const name of plan.effects) view.addEffect({ [name]: {} });
}
const plan = navaraScenePlan(effects ?? resolveNavaraLook(search), {
mobile: Boolean(view.isMobileOptimized?.()),
});
const look = buildNavaraLook(view, plugin, plan);
engine = createNavaraEngine(view, {
hooks: navaraHooks(view),
container,
});
const camera = engine.camera;
let ground = Number.NaN;
// Whether `ground` was read from a frame with all its tiles: a read
// while they stream in is taken again once they have loaded.
let groundSettled = false;
const readGround = () => {
groundSettled = engine.surface.tilesLoaded();
ground = groundInView(engine);
};
let moving = false;
const removers = [
camera.moveStart.addEventListener(() => {
moving = true;
}),
camera.moveEnd.addEventListener(() => {
moving = false;
readGround();
engine.render.request('navara-look');
}),
// After the engine's camera sync: before the first frame the camera
// has no position yet (camera.height() throws).
engine.frames.preRender.addEventListener(() => {
if (!moving && !groundSettled && engine.surface.tilesLoaded())
readGround();
if (look.frame(cameraHeight(camera), moving, ground))
engine.render.request('navara-look');
}),
];
removeLook = () => removers.forEach((remove) => remove());
} catch (error) {
removeLook?.();
engine?.destroy();
view?.dispose();
canvas.remove();
throw error;
@@ -70,6 +135,7 @@ export async function createNavaraGlobe({ container, effects, pixelRatio }) {
destroy() {
if (destroyed) return;
destroyed = true;
removeLook();
engine.destroy();
view.dispose();
canvas.remove();