Draw transit vehicles through the renderer ports, off the Cesium list

Transit drew its vehicles into two Cesium billboard collections and culled,
turned and floored them through the Cesium scene. It now draws them as two
draw-port icon sets, still and moving, registered with the sprite order by
set id in the same places. Each marker is a plain record; a frame writes the
changed ones in one upsert per set, and markers taken out in one task go in
one removal. Clicks read the draw-port hit.

Visibility uses the query port's horizon test and the frustum planes of the
camera port's pose. Icons stay turned in screen space by an exact projection
through the query port, the same answer the Cesium helper gave. The flat
globe is told from terrain by asking the height service once per surface
change; floors are read again when the answer flips. The mesh floor sampler
sees through the layer's sets by id. The camera pose and surface version are
read once per task.

The Cesium draw port now moves and turns an icon without restyling it. The
GL upload probe moves to src/render/cesium/uploadProbe.js, which the QA
scripts hand to the frame probe; the QA scripts read the billboards drawn for
each set.
This commit is contained in:
Sameh Khamis committed 2026-11-08 21:44:22 -08:00
1 parent 00ae80908c
commit 347427f83d
24 files changed
+1618 -452

No files matched your search

+115
View File
@@ -6,6 +6,7 @@
* render noise. See `iconOrientation.js` for why the course is projected
* onto the camera basis. No engine.
*/
import { WGS84 } from '../geo/ellipsoid.js';
import { eastNorthUp, frameVector } from '../geo/frames.js';
import { dot, toRadians, vec } from '../geo/vector.js';
@@ -79,3 +80,117 @@ export function stabilizeScreenRotation(
);
return Math.abs(delta) < Math.max(0, deadbandRad) ? previous : next;
}
/**
* Metres ahead `perspectiveCourseRotation` probes: short, so the projection
* is local to the contact (a two kilometre probe on a bus seen from six
* hundred metres would sample a part of the view the bus is nowhere near).
*/
export const PERSPECTIVE_PROBE_M = 30;
/**
* Probe separations (CSS px) across which the exact and camera-basis
* answers are blended: at or below the floor the camera-basis answer alone,
* at or above the ceiling the exact one.
*/
export const PERSPECTIVE_BLEND_MIN_PX = 0.5;
export const PERSPECTIVE_BLEND_MAX_PX = 3;
/**
* The icon rotation (as `courseScreenRotation`'s) that points a SURFACE
* contact along `courseDeg`, projected exactly, perspective division
* included: the contact and a point `PERSPECTIVE_PROBE_M` ahead of it are
* projected through `project` (a query port's `project`) and the angle
* between them read on screen. The camera-basis answer is orthographic,
* exact at the view's centre and wrong by twenty-odd degrees for a
* street-level contact away from it in an oblique view. Where either point
* cannot be projected it falls back to the camera-basis answer; below a few
* pixels of separation, where projection noise rules the exact one, the
* two are blended the short way round, so the rotation is continuous.
* @param {(p: {x: number, y: number, z: number}) => ({x: number, y: number}|null)} project
* @param {{right?: object, up?: object}|null} basis The camera's axes.
* @param {{x: number, y: number, z: number}|null} position ECEF.
* @param {number} courseDeg Degrees clockwise from north.
* @param {number|null} [previous] Kept when the rotation is unknown.
* @returns {number|null}
*/
export function perspectiveCourseRotation(
project,
basis,
position,
courseDeg,
previous = null,
) {
if (!project || !position || !Number.isFinite(courseDeg)) return previous;
if (!courseProbeInto(position, courseDeg, probeScratch)) {
// At a pole, through the frame `eastNorthUp` defines there.
const courseRad = toRadians(courseDeg);
const forward = frameVector(
eastNorthUp(position),
vec(
Math.sin(courseRad) * PERSPECTIVE_PROBE_M,
Math.cos(courseRad) * PERSPECTIVE_PROBE_M,
0,
),
);
probeScratch.x = position.x + forward.x;
probeScratch.y = position.y + forward.y;
probeScratch.z = position.z + forward.z;
}
const at = project(position);
const atX = at?.x;
const atY = at?.y;
const ahead = at ? project(probeScratch) : null;
if (!at || !ahead)
return courseScreenRotation(basis, position, courseDeg, previous);
const dx = ahead.x - atX;
const dy = ahead.y - atY;
const separation = Math.hypot(dx, dy);
// Window y grows downward; rotation 0 points the icon screen-up.
const exact = Math.atan2(-dx, -dy);
if (separation >= PERSPECTIVE_BLEND_MAX_PX) return exact;
const camera = courseScreenRotation(basis, position, courseDeg, previous);
if (!Number.isFinite(camera)) return exact;
if (separation <= PERSPECTIVE_BLEND_MIN_PX) return camera;
const weight =
(separation - PERSPECTIVE_BLEND_MIN_PX) /
(PERSPECTIVE_BLEND_MAX_PX - PERSPECTIVE_BLEND_MIN_PX);
const delta = Math.atan2(Math.sin(exact - camera), Math.cos(exact - camera));
return camera + delta * weight;
}
// The probe point, reused: the rotation pass visits every visible contact.
const probeScratch = { x: 0, y: 0, z: 0 };
/**
* The point `PERSPECTIVE_PROBE_M` ahead of `position` along `courseDeg` on
* its east-north plane (as `eastNorthUp` and `frameVector` give it), into
* `out`, allocating nothing. False at a pole, where `eastNorthUp` picks
* its own east.
*/
function courseProbeInto(position, courseDeg, out) {
const { x, y, z } = position;
// `eastNorthUp`'s own test for a pole.
if (Math.abs(x) <= 1e-14 && Math.abs(y) <= 1e-14) return false;
const eastLength = Math.hypot(x, y);
const o = WGS84.oneOverRadiiSquared;
let ux = x * o.x,
uy = y * o.y,
uz = z * o.z;
const upLength = Math.sqrt(ux * ux + uy * uy + uz * uz);
ux /= upLength;
uy /= upLength;
uz /= upLength;
const ex = -y / eastLength,
ey = x / eastLength;
// North is up × east (east has no z).
const nx = -uz * ey,
ny = uz * ex,
nz = ux * ey - uy * ex;
const courseRad = toRadians(courseDeg);
const e = Math.sin(courseRad) * PERSPECTIVE_PROBE_M;
const n = Math.cos(courseRad) * PERSPECTIVE_PROBE_M;
out.x = x + ex * e + nx * n;
out.y = y + ey * e + ny * n;
out.z = z + nz * n;
return true;
}