Keep shape radii, rim gradients, depth-fail looks, sweep cadence and step camera moves out of the renderer contract

Shapes take their radii in metres; the world annotation ring follows the
camera height itself (ringRadiusAt), resizing on preRender. The radial rim
preset and depthBias go: the launch pad zone draws a canvas image fill made
by the layer. Solid and dashed lines take one depthFail look (solid or
dash) in place of depthFailColor and depthFailDash. sonarCadenceHz goes from
the quality settings: nothing set it, and the sweep moves every 80 ms.

Camera move, look, rotateAround and zoom leave the camera port: the app's pans,
in-place turns, globe turns and zooms are setView views summed over the pose
(geo/eyeMoves), and the Cesium port places a view by direction and up
exactly rather than through heading, pitch and roll. The conformance driver
runs those script steps through setView; the lookAt script turns in place
where it turned about the frame-local axis, and its reference is recorded
again.
This commit is contained in:
Sameh Khamis committed 2026-11-10 04:08:41 -08:00
1 parent 7a376ebefc
commit c8346c9fda
44 files changed
+810 -799

No files matched your search

+5 -2
View File
@@ -217,8 +217,11 @@ export function initDrawTool({
length: 16,
},
// Dashed behind the surface too, as the band in front of it is.
depthFailColor: withAlpha(cssColor(PREVIEW.primary), 0.35),
depthFailDash: { length: 16 },
depthFail: {
kind: 'dash',
color: withAlpha(cssColor(PREVIEW.primary), 0.35),
length: 16,
},
},
]);
};
+3 -4
View File
@@ -503,11 +503,10 @@ test('the rubber band follows the pointer, closes an area and takes the chosen c
'the band takes the colour',
);
assert.deepEqual(
band().depthFailColor,
[139 / 255, 233 / 255, 1, 0.35],
'behind the surface it stays the primary colour, as before',
band().depthFail,
{ kind: 'dash', color: [139 / 255, 233 / 255, 1, 0.35], length: 16 },
'behind the surface it stays the primary colour, dashed, as before',
);
assert.deepEqual(band().depthFailDash, { length: 16 }, 'and dashed there');
assert.equal(band().style.kind, 'dash');
assert.equal(band().style.length, 16);
assert.equal(band().widthPx, 3);
+109 -16
View File
@@ -2,7 +2,12 @@ import { recordWorkSlice } from '../sources/phaseTiming.js';
import { ringCentroid } from '../sources/featureGeometry.js';
import { showOsmCredit, hideOsmCredit } from '../data/dataCredits.js';
import { fromDegrees } from '../geo/ellipsoid.js';
import { drawOf, frameOf } from '../render/rendererOf.js';
import {
drawOf,
findCamera,
findFrame,
frameOf,
} from '../render/rendererOf.js';
import { heightsOf } from '../queries/heights.js';
/**
@@ -22,7 +27,8 @@ import { heightsOf } from '../queries/heights.js';
* Fades follow the mark's alpha: the engine calls `sync` as it changes, and
* each mark's items take their new colours where they are. Pulsing fills
* are a declarative pulse the renderer runs; target rings follow the
* camera's height, which the renderer reads each frame.
* camera's height, read before each frame, and are sent again at the radius
* it gives when that changes.
*
* Each mark draws into sets of its own, so adding or removing one leaves
* the others' geometry alone.
@@ -57,9 +63,23 @@ const PULSE_MS = (2 * Math.PI) / 0.005;
const PULSE_LOW = 0.6;
/** Target rings: 3% of the camera's height, between 14 m and 170 m. */
const RING_RADIUS = Object.freeze({
byCameraHeight: Object.freeze({ factor: 0.03, min: 14, max: 170 }),
});
const RING_RADIUS = Object.freeze({ factor: 0.03, min: 14, max: 170 });
/** Relative change of the ring radius under which rings are not redrawn. */
const RING_RESIZE = 1e-3;
/**
* A target ring's radius, metres, for a camera `height` metres above the
* ellipsoid; 1000 m stands in for a height the camera cannot give.
* @param {number} height
*/
export function ringRadiusAt(height) {
const h = Number.isFinite(height) ? height : 1000;
return Math.max(
RING_RADIUS.min,
Math.min(RING_RADIUS.max, h * RING_RADIUS.factor),
);
}
/**
* Each renderer's sets have ids of their own, unique across copies of this
@@ -79,6 +99,56 @@ export function createWorldAnnotationRenderer(viewer) {
const groundQueue = [];
let offGroundFrame = null;
let destroyed = false;
// Marks with a target ring, and the radius they are drawn at.
const ringed = new Set();
let offRingFrame = null;
let ringRadius = ringRadiusAt(cameraHeight());
/** The camera's height above the ellipsoid, or NaN when it has none. */
function cameraHeight() {
try {
return findCamera(viewer)?.pose().height ?? Number.NaN;
} catch {
return Number.NaN;
}
}
/** The current ring radius, for the items that draw rings. */
const ringRadiusNow = () => ringRadius;
/**
* Before each frame: when the camera's height gives the rings another
* radius, every shown mark's ring is sent again at it. A hidden mark's
* ring catches up when it shows (`sync`).
*/
function followRings() {
const radius = ringRadiusAt(cameraHeight());
if (Math.abs(radius - ringRadius) <= RING_RESIZE * ringRadius) return;
ringRadius = radius;
for (const anno of ringed) if (!anno.hidden) resizeRing(anno);
}
/** Send a mark's ring again at the current radius, when it differs. */
function resizeRing(anno) {
const was = anno._drawn;
const set = anno._draw?.shapes;
if (!was?.ring || !set || was.ringRadius === ringRadius) return;
was.ringRadius = ringRadius;
set.upsert([was.ring(was.alpha)]);
}
/**
* Keep the ring frame listener while any mark has a ring. A host with no
* frame port draws its rings at the radius they were added with.
*/
function watchRings() {
if (ringed.size && !offRingFrame)
offRingFrame = findFrame(viewer)?.on('preRender', followRings) ?? null;
else if (!ringed.size && offRingFrame) {
offRingFrame();
offRingFrame = null;
}
}
const requestRender = () => frameOf(viewer).requestRender('annotations');
@@ -338,8 +408,18 @@ export function createWorldAnnotationRenderer(viewer) {
return sampleBuilding(anno, options);
}
const items = itemsOf(anno, options);
anno._drawn = { alpha: alphaOf(anno), items };
// Rings not yet followed take the camera's height now.
if (!offRingFrame) ringRadius = ringRadiusAt(cameraHeight());
const items = itemsOf(anno, options, ringRadiusNow);
anno._drawn = {
alpha: alphaOf(anno),
items,
ring: items.ring,
ringRadius,
};
if (items.ring) ringed.add(anno);
else ringed.delete(anno);
watchRings();
const current = () => options.isCurrent?.() ?? true;
const building = anno.footprintKind === 'building';
for (const kind of ['shapes', 'lines', 'points']) {
@@ -394,6 +474,8 @@ export function createWorldAnnotationRenderer(viewer) {
hideOsmCredit(viewer, anno);
osmAnnotations.delete(anno);
drawn.delete(anno);
ringed.delete(anno);
watchRings();
clearSets(anno);
if (anno) {
anno._draw = null;
@@ -415,8 +497,13 @@ export function createWorldAnnotationRenderer(viewer) {
if (sets[kind] && sets[kind].show !== show) sets[kind].show = show;
const was = anno._drawn;
const alpha = alphaOf(anno);
if (!was || was.alpha === alpha) continue;
if (!was || was.alpha === alpha) {
// Shown again: its ring catches up with the camera.
if (show) resizeRing(anno);
continue;
}
was.alpha = alpha;
was.ringRadius = ringRadius;
for (const kind of ['shapes', 'lines', 'points'])
if (sets[kind] && was.items[kind].length)
sets[kind].upsert(was.items[kind].map((item) => item(alpha)));
@@ -428,6 +515,8 @@ export function createWorldAnnotationRenderer(viewer) {
for (const task of [...pendingGround.values()]) task.finish('cancelled');
for (const anno of osmAnnotations) hideOsmCredit(viewer, anno);
osmAnnotations.clear();
ringed.clear();
watchRings();
for (const anno of drawn) {
clearSets(anno);
anno._draw = null;
@@ -455,14 +544,16 @@ const pulse = (alpha) => ({
/**
* What a mark draws, as item makers by kind, each taking the mark's alpha:
* built once per add, called again on each fade step.
* built once per add, called again on each fade step. `ring` is the target
* ring's maker among the shapes, drawn at `ringRadiusNow()`.
*/
function itemsOf(anno, options) {
function itemsOf(anno, options, ringRadiusNow) {
const base = PALETTE[anno.color] || PALETTE.primary;
const shapes = [];
const lines = [];
const points = [];
const meta = { annotation: anno.id };
let ring = null;
const draped = (id, positions, widthPx, style) => (alpha) => ({
id,
positions,
@@ -612,21 +703,23 @@ function itemsOf(anno, options) {
} else {
// pin / highlight / label — a camera-proportional target ring + a marker.
const pos = { lon: anno.anchor.lon, lat: anno.anchor.lat };
if (anno.type !== 'label')
shapes.push((alpha) => ({
if (anno.type !== 'label') {
ring = (alpha) => ({
id: 'ring',
geometry: {
kind: 'ellipse',
center: pos,
semiMajor: RING_RADIUS,
semiMinor: RING_RADIUS,
semiMajor: ringRadiusNow(),
semiMinor: ringRadiusNow(),
},
fill: colour(base, 0.38 * alpha),
animate: pulse(0.38 * alpha),
height: 'clampGround',
clampTo: CLAMP_TO,
meta,
}));
});
shapes.push(ring);
}
// Captions belong to the hybrid renderer's screen-space callouts.
points.push((alpha) => ({
id: 'marker',
@@ -640,7 +733,7 @@ function itemsOf(anno, options) {
meta,
}));
}
return { shapes, lines, points };
return { shapes, lines, points, ring };
}
/** `[lon, lat]` pairs as ECEF positions on the ellipsoid. */
@@ -8,29 +8,40 @@ import { bindRenderer } from '../render/rendererOf.js';
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
import { createWorldAnnotationRenderer } from './worldAnnotationRenderer.js';
/** A viewer with a fake draw port, frame and query bound. */
/**
* A viewer with a fake draw port, frame, camera and query bound. The camera
* stands at `camera.height`; `preRender()` runs the frame's preRender
* listeners, `emit()` its postRender ones.
*/
function viewer(t, { heights = () => null } = {}) {
const draw = fakeDrawPort();
const frames = new Set();
const before = new Set();
const v = { requests: 0 };
const frame = {
on(phase, cb) {
if (phase !== 'postRender') return () => {};
frames.add(cb);
return () => frames.delete(cb);
const listeners =
phase === 'postRender' ? frames : phase === 'preRender' ? before : null;
if (!listeners) return () => {};
listeners.add(cb);
return () => listeners.delete(cb);
},
requestRender() {
v.requests += 1;
},
};
const camera = { height: 2000, pose: () => ({ height: camera.height }) };
const query = { sampleHeightNow: (point) => heights(point) };
const unbind = bindRenderer(v, { draw, frame, query });
const unbind = bindRenderer(v, { draw, frame, query, camera });
t.after(unbind);
return {
v,
draw,
frames,
before,
camera,
emit: () => [...frames].forEach((cb) => cb()),
preRender: () => [...before].forEach((cb) => cb()),
};
}
@@ -213,9 +224,7 @@ test('every kind draws as it did: draped on terrain and tiles alike, rings by ca
);
const [ring] = items(pin, 'shapes');
assert.deepEqual(ring.geometry.semiMajor, {
byCameraHeight: { factor: 0.03, min: 14, max: 170 },
});
assert.equal(ring.geometry.semiMajor, 60, '3% of the camera height');
assert.equal(ring.geometry.semiMinor, ring.geometry.semiMajor);
const [marker] = items(pin, 'points');
assert.deepEqual(
@@ -232,6 +241,67 @@ test('every kind draws as it did: draped on terrain and tiles alike, rings by ca
renderer.destroy();
});
test('target rings follow the camera height, sent again only when the radius changes, and catch up once shown', (t) => {
const { v, draw, camera, preRender, before } = viewer(t);
const renderer = createWorldAnnotationRenderer(v);
const [, , pin] = marks();
const other = { ...pin, id: 'pin2', anchor: { lat: 0.03, lon: 0.03 } };
renderer.add(pin);
renderer.add(other);
const ringOf = (anno) =>
setsOf(draw, anno)
.find((r) => r.kind === 'shapes')
.items.get('ring');
// Writes to the rings' sets since they were drawn.
const shapeSets = [pin, other].map((anno) =>
setsOf(draw, anno).find((r) => r.kind === 'shapes'),
);
const upserts = {
get length() {
return shapeSets.reduce((n, record) => n + record.writes - 1, 0);
},
};
assert.equal(ringOf(pin).geometry.semiMajor, 60);
assert.equal(before.size, 1, 'one listener for every ring');
// The camera has not moved: nothing is sent.
preRender();
assert.equal(upserts.length, 0);
// It climbs: both rings are sent at the new radius, once.
camera.height = 4000;
preRender();
preRender();
assert.equal(upserts.length, 2);
assert.equal(ringOf(pin).geometry.semiMajor, 120);
assert.equal(ringOf(pin).geometry.semiMinor, 120);
assert.equal(ringOf(other).geometry.semiMajor, 120);
// A change under 0.1% sends nothing.
camera.height = 4002;
preRender();
assert.equal(upserts.length, 2);
// Held within 14 m and 170 m.
camera.height = 1e6;
preRender();
assert.equal(ringOf(pin).geometry.semiMajor, 170);
camera.height = 10;
preRender();
assert.equal(ringOf(pin).geometry.semiMajor, 14);
// A hidden mark waits, and catches up when shown.
other.hidden = true;
renderer.sync();
camera.height = 3000;
preRender();
assert.equal(ringOf(pin).geometry.semiMajor, 90);
assert.equal(ringOf(other).geometry.semiMajor, 14, 'hidden: not sent');
other.hidden = false;
renderer.sync();
assert.equal(ringOf(other).geometry.semiMajor, 90, 'shown: caught up');
// The last ring gone, the listener goes with it.
renderer.remove(pin);
renderer.remove(other);
assert.equal(before.size, 0);
renderer.destroy();
});
test('a building waits for its ground probes, then draws a pulsing column, a cage and a draped base', async (t) => {
const { v, draw, emit, frames } = viewer(t, { heights: () => 150 });
const renderer = createWorldAnnotationRenderer(v);