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.
This commit is contained in:
Sameh Khamis committed 2026-11-14 00:56:07 -08:00
1 parent 5d48503c51
commit b754418706
2 files changed
+16 -6

No files matched your search

+12 -2
View File
@@ -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();
+4 -4
View File
@@ -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 {