From b754418706ef5cc27a94b474b6e7ca3ad46bf236 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 14 Nov 2026 00:56:07 -0800 Subject: [PATCH] fix(cockpit): a ship's bridge reads its water from the drawn surface, globe included The waterline probes read Cesium's scene sample, which takes the globe's terrain as well as 3D tiles. On the ports they asked for tiles alone, which hides the globe, so on a globe map a lake or river above sea level went unread and the eye fell back to the sea. They now ask for the drawn surface, as before. --- src/ui/cockpitBridge.test.mjs | 14 ++++++++++++-- src/ui/cockpitCamera.js | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ui/cockpitBridge.test.mjs b/src/ui/cockpitBridge.test.mjs index 7e6b562f5..86606c68e 100644 --- a/src/ui/cockpitBridge.test.mjs +++ b/src/ui/cockpitBridge.test.mjs @@ -101,6 +101,9 @@ function vesselLayer(record) { * heights come from `scene.sampleHeight` (loaded tiles, at once) and * `scene.sampleHeightMostDetailed` (the full-detail read), per probe. */ +/** The surfaces the bridge's height reads asked for, in order. */ +const surfacesAsked = []; + function sceneQuery(viewer, ports) { const scene = () => viewer.scene; const cartographic = ({ lon, lat }) => @@ -109,11 +112,13 @@ function sceneQuery(viewer, ports) { ...ports.query, project: (position) => scene().cartesianToCanvasCoordinates?.(position, {}) ?? null, - sampleHeightNow(point) { + sampleHeightNow(point, options = {}) { + surfacesAsked.push(options.against ?? 'surface'); const height = scene().sampleHeight?.(cartographic(point)); return Number.isFinite(height) ? height : null; }, - sampleHeight(points, { mostDetailed = false } = {}) { + sampleHeight(points, { mostDetailed = false, against = 'surface' } = {}) { + surfacesAsked.push(against); if ( !mostDetailed || typeof scene().sampleHeightMostDetailed !== 'function' @@ -971,6 +976,7 @@ test('a bridge on a river above sea level rides the water, not the geoid', async clock.set(START_MS); const record = { ...RECORD, lastPositionEpoch: START_MS / 1000 }; const river = fixture(t, { record }); + surfacesAsked.length = 0; const probed = []; // The ship's own model reads 40 m; the ring finds the river at 27 m and // a quay at 33 m. @@ -994,6 +1000,10 @@ test('a bridge on a river above sea level rides the water, not the geoid', async 0.5, ); assert.equal(probed[0], 9, 'the ship and eight probes around it'); + // The drawn surface, the globe's terrain included, as the scene's own + // sample read it. + assert.ok(surfacesAsked.length > 0); + assert.deepEqual([...new Set(surfacesAsked)], ['surface']); const reads = probed.length; frames(river.cockpit, clock, river.shots, 20); await settle(); diff --git a/src/ui/cockpitCamera.js b/src/ui/cockpitCamera.js index 0514546d3..9fb7c6426 100644 --- a/src/ui/cockpitCamera.js +++ b/src/ui/cockpitCamera.js @@ -197,7 +197,9 @@ function vesselSurfaceM(info, nowMs, at = info) { function readWaterline(read, query, probes, seaM) { read.inFlight = true; // An async read: a failure arrives as a rejection, never a throw here. - query.batch(probes, { against: 'tiles' }).then( + // The drawn surface, globe included, as the scene's own sample read it: + // a lake on a globe map stands on its terrain. + query.batch(probes).then( (samples) => { if (this.vesselWaterline !== read) return; read.inFlight = false; @@ -222,9 +224,7 @@ function readWaterline(read, query, probes, seaM) { */ function loadedWaterlineM(query, probes, seaM) { try { - const heights = probes.map((probe) => - query.now(probe, { against: 'tiles' }), - ); + const heights = probes.map((probe) => query.now(probe)); if (!heights.some(Number.isFinite)) return null; return vesselWaterlineM(seaM, heights); } catch {