mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Move scene effects and imported geometry behind the globe contract
Move Cesium viewer, map, sky, projection, trail and sonar internals into its engine. Drive styles, bloom, sharpening and contact sonar through engine.render. Count camera-input suspensions across all three engines and migrate the feature callers. Preserve Cesium's effects and input behaviour; fix transit lens clicks on Cesium and make zero sharpening on Navara disable sharpening, as it does on Cesium. Parse imported files into plain records and draw them through movers, lines, ground and imagery on both engines. Follow Cesium's KML style precedence, preserve local KMZ images and frame the drawable records. Open overlays use imagery when the engine has no native map-overlay API. Run every imported-display case on fake and headless Cesium engines. The shared import path retains these known differences from Cesium's old DataSources: wall fills, extruded prisms and gx:LatLonQuad are undrawn; raised polygon fills drape while outlines retain altitude; GroundOverlay rotation, altitude and RGB tint are not applied; rhumb lines become great circles. Ground heights use the loaded surface synchronously instead of waiting for most-detailed sampling. Supported KMZ ground overlays now draw on Navara too. Document the limits rather than claiming full parity. Combine batches B and C because their disjoint path manifests cannot place the shared boundary and format files in a later commit while keeping B independently valid. This combined commit owns the shared docs, package boundaries, format scope, locale catalogs and coupling baseline. Remove five obsolete import strings from all eleven catalogs. Make the load-time source scan include new files and skip deleted paths so the same checks work before and after recording the moves. Coupling: Navara renderer lines fall from 1695 to 1294, Cesium import files from 25 to 9, viewer lines from 1177 to 1026, SDK loads from 4 to 3 and engine-name lines from 62 to 42. No count grows. The full unit suite and the boundary, format and coupling checks pass. Browser validation remains to be run. Browser checks to run GOOGLE_MAPS_API_KEY= CESIUM_ION_TOKEN= npm run dev -- --port 4291 node scripts/qa-contract-suite.mjs http://localhost:4291 node scripts/qa-navara-visual-styles.mjs http://localhost:4291 node scripts/qa-navara-bloom.mjs http://localhost:4291 node scripts/qa-navara-sonar.mjs http://localhost:4291 QA_BASE_URL=http://localhost:4291 node scripts/qa-visual-effects.mjs QA_BASE_URL=http://localhost:4291 node scripts/qa-zoom-out-guard.mjs node scripts/qa-sky-model-lighting.mjs --url http://localhost:4291 node scripts/qa-geo-import.mjs http://localhost:4291 node scripts/qa-geo-import-regressions.mjs http://localhost:4291 node scripts/qa-geo-import-large.mjs http://localhost:4291 node scripts/qa-navara-geo-import.mjs http://localhost:4291 Use the keyless server for every check. Photoreal-only cases remain unverified; do not enable paid tiles to run them.
This commit is contained in:
1 parent
c079b329d0
commit
97c4dc76ce
130 files changed
+4763
-3495
No files matched your search
+69
-140
@@ -1,4 +1,3 @@
|
||||
import { PostProcessStage } from 'cesium';
|
||||
import {
|
||||
bloomStrengthFromIntensity,
|
||||
clampBloomIntensity,
|
||||
@@ -6,17 +5,16 @@ import {
|
||||
} from '../bloom.js';
|
||||
import {
|
||||
STYLES,
|
||||
SHARPEN_SHADER,
|
||||
TRANSITION_DURATION_MS,
|
||||
sharpenAmount,
|
||||
} from './visualPresets.js';
|
||||
|
||||
/**
|
||||
* A style stage drawn by the globe engine (render.setStyle) instead of a
|
||||
* Cesium post stage: the same { uniforms, enabled } shape, so the owner of
|
||||
* the stages writes its uniforms as it writes a Cesium stage's; each write
|
||||
* reaches the engine. A value the engine refuses (NaN from an old link,
|
||||
* say) stays here and is reported, as a Cesium uniform would just draw it.
|
||||
* A style stage drawn by the globe engine (render.setStyle), in a Cesium
|
||||
* post stage's { uniforms, enabled } shape, so the owner of the stages
|
||||
* writes its uniforms as it wrote a stage's; each write reaches the engine.
|
||||
* A value the engine refuses (NaN from an old link, say) stays here and is
|
||||
* reported.
|
||||
*/
|
||||
function engineStyleStage(render, name, shader) {
|
||||
const values = { intensity: 0 };
|
||||
@@ -47,17 +45,21 @@ function engineStyleStage(render, name, shader) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Own the post-process stages and their animation, without DOM dependencies. */
|
||||
/**
|
||||
* Own the visual styles, bloom and sharpening and their animation, without
|
||||
* DOM dependencies, on the globe engine that draws them (render.setStyle,
|
||||
* render.setBloom, render.setSharpen: Cesium through its post stages,
|
||||
* Navara in its pipeline).
|
||||
*/
|
||||
export class VisualEffects {
|
||||
/**
|
||||
* @param {object} options - Viewer, render ownership callbacks and optional clocks.
|
||||
* Without a viewer, `engine` (the globe engine) draws the sharpening
|
||||
* through render.setSharpen, and the styles and bloom through
|
||||
* render.setStyle and render.setBloom when it has them. Construction is inert; initStyles and
|
||||
* @param {object} options - The globe engine, render ownership callbacks
|
||||
* and optional clocks. The styles and bloom reach the engine when it has
|
||||
* them (the visualStyles and bloom capabilities); without an engine the
|
||||
* controls change nothing. Construction is inert; initStyles and
|
||||
* initPostProcess retain startup ordering.
|
||||
*/
|
||||
constructor({
|
||||
viewer,
|
||||
engine = null,
|
||||
requestRender,
|
||||
holdRender,
|
||||
@@ -66,29 +68,20 @@ export class VisualEffects {
|
||||
cancelFrame = (id) => cancelAnimationFrame(id),
|
||||
now = () => performance.now(),
|
||||
wallNow = () => Date.now(),
|
||||
createStage = (options) => new PostProcessStage(options),
|
||||
}) {
|
||||
this.viewer = viewer;
|
||||
// Cesium sharpens with its own post stage below, and the engine's
|
||||
// render.sharpen() mirrors that stage (the Cesium engine keeps the state
|
||||
// only); an engine without a viewer (Navara) sharpens in its pipeline.
|
||||
this.engineRender =
|
||||
typeof engine?.render?.setSharpen === 'function' ? engine.render : null;
|
||||
// Without a viewer, an engine that draws the styles itself
|
||||
// (render.setStyle) gets them through stand-in stages (initStyles).
|
||||
// (The visualStyles and bloom capabilities of src/globe/contract.js
|
||||
// engineCapabilities, read by member: this package stays engine-free.)
|
||||
this.engine = engine;
|
||||
const render = engine?.render;
|
||||
this.engineRender =
|
||||
typeof render?.setSharpen === 'function' ? render : null;
|
||||
// The visualStyles and bloom capabilities of src/globe/contract.js
|
||||
// engineCapabilities, read by member: this package stays engine-free.
|
||||
this.engineStyles =
|
||||
!viewer &&
|
||||
Array.isArray(render?.visualStyles) &&
|
||||
typeof render.setStyle === 'function' &&
|
||||
typeof render.style === 'function'
|
||||
? render
|
||||
: null;
|
||||
// Likewise the bloom (render.setBloom) for Cesium's bloom stage.
|
||||
this.engineBloom =
|
||||
!viewer &&
|
||||
typeof render?.setBloom === 'function' &&
|
||||
typeof render.bloom === 'function'
|
||||
? render
|
||||
@@ -100,7 +93,6 @@ export class VisualEffects {
|
||||
this.cancelFrame = cancelFrame;
|
||||
this.now = now;
|
||||
this.wallNow = wallNow;
|
||||
this.createStage = createStage;
|
||||
this.stages = {};
|
||||
this.transitions = new Map();
|
||||
this.startTime = wallNow();
|
||||
@@ -108,106 +100,46 @@ export class VisualEffects {
|
||||
this.sharpenEnabled = false;
|
||||
this.bloomIntensity = BLOOM_INTENSITY_DEFAULT;
|
||||
this.sharpenIntensity = 0.49;
|
||||
this.bloomStage = null;
|
||||
this.sharpenStage = null;
|
||||
this.postProcessReady = false;
|
||||
// What the engine was last told about the sharpening: it starts off.
|
||||
this.sharpenShown = false;
|
||||
this.frameId = null;
|
||||
this.stopped = false;
|
||||
this.destroyed = false;
|
||||
this.stageEntries = [];
|
||||
this.previousBloom = null;
|
||||
}
|
||||
|
||||
// Post-process stages are Cesium's. Without a viewer (the Navara engine)
|
||||
// an engine that draws the styles gets stand-in stages (engineStyleStage),
|
||||
// which start every style at 0 on it; otherwise there are none and the
|
||||
// style controls change nothing (the engine sharpens, see engineRender).
|
||||
// The styles the engine draws get stand-in stages (engineStyleStage),
|
||||
// which start every style at 0 on it; an engine without them gets none
|
||||
// and the style controls change nothing.
|
||||
initStyles() {
|
||||
if (this.stopped || this.stageEntries.length) return;
|
||||
if (!this.viewer) {
|
||||
if (!this.engineStyles) return;
|
||||
const drawn = this.engineStyles.visualStyles;
|
||||
for (const [name, shader] of Object.entries(STYLES))
|
||||
if (drawn.includes(name))
|
||||
this.stages[name] = engineStyleStage(this.engineStyles, name, shader);
|
||||
this.stageEntries = Object.entries(this.stages);
|
||||
return;
|
||||
}
|
||||
for (const [name, shader] of Object.entries(STYLES)) {
|
||||
const uniforms = { intensity: 0.0 };
|
||||
if (shader.fragmentShader.includes('uniform float time'))
|
||||
uniforms.time = 0.0;
|
||||
for (const [name, meta] of Object.entries(shader.uniforms || {}))
|
||||
uniforms[name] = meta.default;
|
||||
const stage = this.createStage({
|
||||
name: `godsEyeView_${name}`,
|
||||
fragmentShader: shader.fragmentShader,
|
||||
uniforms,
|
||||
});
|
||||
stage.enabled = false;
|
||||
this.viewer.scene.postProcessStages.add(stage);
|
||||
this.stages[name] = stage;
|
||||
}
|
||||
if (this.stopped || this.stageEntries.length || !this.engineStyles) return;
|
||||
const drawn = this.engineStyles.visualStyles;
|
||||
for (const [name, shader] of Object.entries(STYLES))
|
||||
if (drawn.includes(name))
|
||||
this.stages[name] = engineStyleStage(this.engineStyles, name, shader);
|
||||
this.stageEntries = Object.entries(this.stages);
|
||||
}
|
||||
|
||||
initPostProcess(sharpenIntensity = this.sharpenIntensity) {
|
||||
if (this.stopped || this.sharpenStage) return;
|
||||
// An engine that blooms starts from this owner's bloom (off), whatever
|
||||
// a previous owner left on it.
|
||||
if (!this.viewer) {
|
||||
this.engineBloom?.setBloom({
|
||||
enabled: false,
|
||||
strength: bloomStrengthFromIntensity(this.bloomIntensity),
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.bloomStage = this.viewer.scene.postProcessStages.bloom;
|
||||
const names = [
|
||||
'glowOnly',
|
||||
'contrast',
|
||||
'brightness',
|
||||
'delta',
|
||||
'sigma',
|
||||
'stepSize',
|
||||
];
|
||||
this.previousBloom = {
|
||||
enabled: this.bloomStage.enabled,
|
||||
uniforms: Object.fromEntries(
|
||||
names.map((name) => [name, this.bloomStage.uniforms[name]]),
|
||||
),
|
||||
};
|
||||
this.bloomStage.enabled = false;
|
||||
Object.assign(this.bloomStage.uniforms, {
|
||||
glowOnly: false,
|
||||
contrast: 256.0,
|
||||
brightness: -0.35,
|
||||
delta: 0.25,
|
||||
sigma: 0.35,
|
||||
stepSize: 1.0,
|
||||
if (this.stopped || this.postProcessReady) return;
|
||||
this.postProcessReady = true;
|
||||
// The engine starts from this owner's bloom and sharpening (off),
|
||||
// whatever a previous owner left on it.
|
||||
this.engineBloom?.setBloom({
|
||||
enabled: false,
|
||||
strength: bloomStrengthFromIntensity(this.bloomIntensity),
|
||||
});
|
||||
this.sharpenStage = this.createStage({
|
||||
name: 'godsEyeView_sharpen',
|
||||
fragmentShader: SHARPEN_SHADER,
|
||||
uniforms: { amount: 1.3 },
|
||||
});
|
||||
this.sharpenStage.enabled = false;
|
||||
this.viewer.scene.postProcessStages.add(this.sharpenStage);
|
||||
this.sharpenShown = false;
|
||||
this.engineRender?.setSharpen({ enabled: false });
|
||||
this.applySharpenIntensity(sharpenIntensity);
|
||||
}
|
||||
|
||||
setStageIntensity(stage, value) {
|
||||
if (this.stopped || !stage) return;
|
||||
// The engine fades its stars with Anime (render.setStyle).
|
||||
stage.uniforms.intensity = value;
|
||||
stage.enabled = value > 0.001;
|
||||
// Anime's bands turn the faint Milky Way into blotches, and depth cannot
|
||||
// tell the sky from far geometry, so the glow fades with the style.
|
||||
// The engine fades its own stars with Anime (render.setStyle).
|
||||
if (
|
||||
stage === this.stages.anime &&
|
||||
this.viewer?.scene.skyBox?.milkyWayVisibility !== undefined
|
||||
)
|
||||
this.viewer.scene.skyBox.milkyWayVisibility = 1 - value;
|
||||
if (stage.enabled && stage.uniforms.time !== undefined)
|
||||
this.startAnimationLoop();
|
||||
this.requestRender('style-stage');
|
||||
@@ -218,12 +150,13 @@ export class VisualEffects {
|
||||
this.setStageIntensity(stage, stage.uniforms.intensity);
|
||||
}
|
||||
|
||||
// The engine eases the strength above its 0.06 dead zone (Cesium's bloom
|
||||
// stage); under it, nothing glows with the toggle on.
|
||||
syncBloomEnabled() {
|
||||
if (this.stopped) return;
|
||||
const enabled =
|
||||
this.bloomEnabled &&
|
||||
bloomStrengthFromIntensity(this.bloomIntensity) > 0.06;
|
||||
if (this.bloomStage) this.bloomStage.enabled = enabled;
|
||||
this.engineBloom?.setBloom({ enabled });
|
||||
}
|
||||
|
||||
@@ -231,21 +164,10 @@ export class VisualEffects {
|
||||
if (this.stopped) return;
|
||||
this.bloomIntensity = clampBloomIntensity(intensity);
|
||||
this.requestRender('bloom');
|
||||
if (this.engineBloom) {
|
||||
this.engineBloom.setBloom({
|
||||
strength: bloomStrengthFromIntensity(this.bloomIntensity),
|
||||
});
|
||||
this.syncBloomEnabled();
|
||||
}
|
||||
if (!this.bloomStage) return;
|
||||
const rawStrength = bloomStrengthFromIntensity(this.bloomIntensity);
|
||||
const strength = rawStrength <= 0.06 ? 0.0 : (rawStrength - 0.06) / 0.94;
|
||||
const eased = strength * strength * (3.0 - 2.0 * strength);
|
||||
this.bloomStage.uniforms.contrast = 255.0 - eased * 168.0;
|
||||
this.bloomStage.uniforms.brightness = -0.5 + eased * 0.36;
|
||||
this.bloomStage.uniforms.sigma = 0.28 + eased * 6.3;
|
||||
this.bloomStage.uniforms.delta = 0.2 + eased * 2.25;
|
||||
this.bloomStage.uniforms.stepSize = 1.0 + eased * 1.25;
|
||||
if (!this.engineBloom) return;
|
||||
this.engineBloom.setBloom({
|
||||
strength: bloomStrengthFromIntensity(this.bloomIntensity),
|
||||
});
|
||||
this.syncBloomEnabled();
|
||||
}
|
||||
|
||||
@@ -262,18 +184,18 @@ export class VisualEffects {
|
||||
* on the Arc, 2026-10-24), and `0.1 + value * 2` still sharpened at 0.
|
||||
*/
|
||||
syncSharpenEnabled() {
|
||||
if (this.stopped || !this.sharpenStage) return;
|
||||
this.sharpenStage.enabled =
|
||||
this.sharpenEnabled && this.sharpenIntensity > 0.001;
|
||||
if (this.stopped) return;
|
||||
const enabled = this.sharpenEnabled && this.sharpenIntensity > 0.001;
|
||||
if (enabled === this.sharpenShown) return;
|
||||
this.sharpenShown = enabled;
|
||||
this.engineRender?.setSharpen({ enabled });
|
||||
}
|
||||
|
||||
applySharpenIntensity(value) {
|
||||
if (this.stopped) return;
|
||||
this.sharpenIntensity = value;
|
||||
if (this.sharpenStage)
|
||||
this.sharpenStage.uniforms.amount = sharpenAmount(value);
|
||||
this.syncSharpenEnabled();
|
||||
this.engineRender?.setSharpen({ amount: sharpenAmount(value) });
|
||||
this.syncSharpenEnabled();
|
||||
this.requestRender('sharpen');
|
||||
}
|
||||
|
||||
@@ -281,7 +203,6 @@ export class VisualEffects {
|
||||
if (this.stopped) return;
|
||||
this.sharpenEnabled = !!enabled;
|
||||
this.syncSharpenEnabled();
|
||||
this.engineRender?.setSharpen({ enabled: this.sharpenEnabled });
|
||||
this.requestRender('sharpen');
|
||||
}
|
||||
|
||||
@@ -337,18 +258,26 @@ export class VisualEffects {
|
||||
this.transitions.clear();
|
||||
}
|
||||
|
||||
/** Remove owned stages and restore the borrowed bloom stage after callers release it. */
|
||||
/**
|
||||
* Turn every style, the bloom and the sharpening off on the engine after
|
||||
* callers release them, as removing Cesium's stages did: the engine keeps
|
||||
* the frame of a later owner, which starts them again (initStyles,
|
||||
* initPostProcess).
|
||||
*/
|
||||
destroy() {
|
||||
if (this.destroyed) return;
|
||||
this.stop();
|
||||
this.destroyed = true;
|
||||
if (!this.viewer) return;
|
||||
const stages = this.viewer.scene.postProcessStages;
|
||||
for (const [, stage] of this.stageEntries) stages.remove(stage);
|
||||
if (this.sharpenStage) stages.remove(this.sharpenStage);
|
||||
if (this.bloomStage && this.previousBloom) {
|
||||
Object.assign(this.bloomStage.uniforms, this.previousBloom.uniforms);
|
||||
this.bloomStage.enabled = this.previousBloom.enabled;
|
||||
}
|
||||
if (!this.engine || this.engine.isDestroyed?.()) return;
|
||||
for (const [name, stage] of this.stageEntries)
|
||||
if (stage.uniforms.intensity !== 0) {
|
||||
try {
|
||||
this.engineStyles.setStyle(name, { intensity: 0 });
|
||||
} catch {
|
||||
// The engine went with its scene.
|
||||
}
|
||||
}
|
||||
if (this.postProcessReady) this.engineBloom?.setBloom({ enabled: false });
|
||||
if (this.sharpenShown) this.engineRender?.setSharpen({ enabled: false });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user