Merge origin/main into byrdit/cctv-visible-only-fetch

# Conflicts:
#	src/layers/cctv/frames.test.mjs
This commit is contained in:
German Khokhlov committed 2026-11-20 17:33:48 +04:00
commit 20647f6549
391 files changed
+32429 -1796

No files matched your search

+57
View File
@@ -7103,6 +7103,63 @@ test('models moved every frame keep their shader and pick ids: only a new look o
}
});
test('a model poses its named nodes once ready, writes only what changed, and gives a dropped one its own pose back', async () => {
const { loads, restore } = fakeModelLoads();
try {
const part = createCesiumDraw({
scene: fakeScene(),
report: (error) => assert.fail(error),
});
const set = part.port.models({ id: 'station' });
const turn = (x) => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
const item = (nodes) => ({
id: 'iss',
pos: { lon: 0, lat: 0, height: 400e3 },
url: 'iss.glb',
orientation: { heading: 0, pitch: 0, roll: 0 },
nodes,
});
set.upsert([item({ joint: turn(1), other: turn(2), missing: turn(3) })]);
loads[0].resolve();
await settle();
const model = loads[0].model;
const writes = [];
const nodes = {};
for (const name of ['joint', 'other'])
nodes[name] = {
originalMatrix: Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(9, 9, 9),
),
set matrix(m) {
writes.push(name);
// As Cesium's runtime node does: a copy, not the matrix handed in.
this.current = Cesium.Matrix4.clone(m);
},
};
model.getNode = (name) => {
assert.equal(model.ready, true, 'nodes are asked for once ready');
return nodes[name];
};
loads[0].ready();
assert.deepEqual(writes.sort(), ['joint', 'other'], 'posed when ready');
assert.equal(nodes.joint.current[12], 1);
assert.equal(nodes.other.current[12], 2);
writes.length = 0;
set.upsert([item({ joint: turn(1), other: turn(5), missing: turn(3) })]);
assert.deepEqual(writes, ['other'], 'only the node that moved');
assert.equal(nodes.other.current[12], 5);
writes.length = 0;
set.upsert([item({ other: turn(5) })]);
assert.deepEqual(writes, ['joint'], 'the dropped node, back to its pose');
assert.equal(nodes.joint.current[12], 9);
set.dispose();
} finally {
restore();
}
});
test('a model set that recedes fades its models toward the limb with their focus; focus alone dims', async () => {
const { recedeFactors, recedeFrame, recedeParams, recededAlpha } =
await import('../recession.js');
+58 -1
View File
@@ -5,7 +5,7 @@
* item's `url` re-poses and restyles its model in place (position,
* orientation, scale, `axisScale` and pixel bounds, `shading`, `tint`,
* `colorBlend`, `maskColor`, `clip`, `environmentMap`, `displayRange`,
* `show`); only a new `url` loads again, and the old model keeps drawing
* `nodes`, `show`); only a new `url` loads again, and the old model keeps drawing
* until the new one is ready, so a swap never blinks. `ready` fires once per
* load, when the model has loaded and is posed. An item with its `gltf`
* bytes is built from them; its url is then not fetched.
@@ -78,6 +78,62 @@ export const MODEL_RETRY_MS = 5000;
*/
export const RECEDE_WRITE_EPSILON = 0.005;
/**
* Each model's posed nodes (`ModelItem.nodes`): name → the 16 numbers last
* written, so an update that keeps a node's matrix writes nothing.
*/
const posedNodes = new WeakMap();
/** A posed name the model has no node for: looked up once, then skipped. */
const NO_NODE = Symbol('no such node');
const scratchNodeMatrix = new Cesium.Matrix4();
/**
* Write the item's node transforms to `model` once it is ready: changed
* ones only, and a node whose name left the map back to its authored pose.
* Names the model lacks are skipped.
*/
function poseNodes(item, model) {
if (model.ready !== true) return;
const wanted = item.nodes;
let posed = posedNodes.get(model);
if (!wanted && !posed) return;
if (!posed) posedNodes.set(model, (posed = new Map()));
for (const [name, last] of posed) {
if (wanted && Object.hasOwn(wanted, name)) continue;
posed.delete(name);
if (last === NO_NODE) continue;
const node = model.getNode(name);
if (node) node.matrix = Cesium.Matrix4.clone(node.originalMatrix);
}
if (!wanted) return;
for (const name of Object.keys(wanted)) {
const matrix = wanted[name];
if (!matrix || matrix.length < 16) continue;
const last = posed.get(name);
if (last === NO_NODE) continue;
if (last && sameMatrix(last, matrix)) continue;
const node = model.getNode(name);
if (!node) {
posed.set(name, NO_NODE);
continue;
}
// The last matrix written, kept in one array per node, copied in place.
let kept = last;
if (!(kept instanceof Float64Array)) {
kept = new Float64Array(16);
posed.set(name, kept);
}
for (let i = 0; i < 16; i++) kept[i] = matrix[i];
// The node copies the matrix it is given.
node.matrix = Cesium.Matrix4.fromArray(matrix, 0, scratchNodeMatrix);
}
}
function sameMatrix(a, b) {
for (let i = 0; i < 16; i++) if (a[i] !== b[i]) return false;
return true;
}
/** Cesium's own blend amount, for a `mix` that names none. */
const DEFAULT_MIX = 0.5;
@@ -1057,6 +1113,7 @@ export function createModelSets({
const hidden = range && !(range[1] > range[0]);
if (entry.styled?.range !== rangeKey) entry.styled = { range: rangeKey };
entry.dynamic = needsFrame(item, record.spec);
poseNodes(item, model);
apply(entry, model, entry.frame ?? STILL, hidden);
}
+3
View File
@@ -82,6 +82,7 @@ export const CESIUM_CHECKS = new Set([
'draw.models',
'draw.shapes.lit',
'draw.models.loadFailed',
'draw.models.nodes',
'draw.models.tint',
'draw.models.blend',
'draw.models.paint',
@@ -197,6 +198,7 @@ function nextFrame() {
export function createCesiumHarness({
name = 'cesium',
model,
modelNode,
missingModel,
cameraController,
} = {}) {
@@ -269,6 +271,7 @@ export function createCesiumHarness({
? {
assets: {
model,
...(modelNode ? { modelNode } : {}),
missingModel,
// The model's bytes, for the check that a model drawn from them
// never fetches its url.
+16 -9
View File
@@ -92,6 +92,7 @@ out vec2 v_uv;
out vec4 v_color;
out vec4 v_pickColor;
out float v_proxy;
out float v_overDepth; // 1 for a row drawn over depth, on the near plane
// The row's anchor in clip space before screen offsets, for effects that wrap
// main() (sonar) and must not change geometry or picks.
@@ -125,6 +126,7 @@ void main() {
v_uv = vec2(0.0);
v_color = vec4(0.0);
v_proxy = 0.0;
v_overDepth = 0.0;
gl_Position = vec4(0.0, 0.0, 2.0, 1.0); // outside the clip volume: not drawn
float flags = style1.z;
@@ -260,14 +262,9 @@ void main() {
distanceSq < style3.w * style3.w;
if (overDepth && zclip >= -1.0 && zclip <= 1.0) {
gl_Position.z = -gl_Position.w;
#ifdef LOG_DEPTH
// Just past the near plane, not on it: czm_writeLogDepth discards a
// fragment at or below 0.9999999, and 1.0 interpolated across the quad
// can arrive a rounding step or two under that, dropping the icon for a
// frame as it moves (flicker). 1e-4 m past the near plane is still in
// front of everything the scene draws.
v_depthFromNearPlusOne = 1.0001;
#endif
// With a log depth buffer the fragment shader writes the near plane's
// depth itself.
v_overDepth = 1.0;
}
v_uv = mix(rect.xy, rect.zw, vec2(corner.x * 0.5 + 0.5, 0.5 - corner.y * 0.5));
@@ -282,6 +279,7 @@ in vec2 v_uv;
in vec4 v_color;
in vec4 v_pickColor;
in float v_proxy;
in float v_overDepth;
void main() {
vec4 color = czm_gammaCorrect(texture(u_atlas, v_uv));
@@ -296,7 +294,16 @@ void main() {
#endif
out_FragColor = color;
#ifdef LOG_DEPTH
czm_writeLogDepth(v_depthFromNearPlusOne);
// Over depth: exactly the near plane's depth, written here and not through
// czm_writeLogDepth. That function discards a fragment whose interpolated
// depth arrives a rounding step under the near plane (the icon drops for a
// frame as it moves), and any depth past the near plane is a surface to
// Cesium's depth pick: the camera controller then sizes a zoom step from an
// icon under the canvas centre, a near plane's distance away, and the wheel
// stops zooming. The pick reads a depth of 0 as nothing drawn, and keeps
// the depth of the ground under the icon.
if (v_overDepth > 0.5) gl_FragDepth = 0.0;
else czm_writeLogDepth(v_depthFromNearPlusOne);
#endif
}
`;
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import fs from 'node:fs';
import * as Cesium from 'cesium';
import { createIconSet } from '../../data/iconSet.js';
import { IconSetPrimitive } from './iconSetPrimitive.js';
@@ -58,3 +59,29 @@ test('by default the set draws an opaque pass and a translucent one, and draws n
assert.equal(translucent.renderState.depthMask, false);
assert.equal(primitive.drawsBlend('translucent'), false);
});
test('an over-depth row writes a depth of exactly 0, which a depth pick ignores', () => {
// Shaders do not compile under node: this reads the fragment shader's
// source. A depth past the near plane (as 1.0001 through
// czm_writeLogDepth was) is a surface to Cesium's depth pick, a near
// plane's distance from the camera, and the wheel stops zooming with an
// icon under the canvas centre (scripts/qa-zoom-under-icon.mjs).
const source = fs.readFileSync(
new URL('./iconSetPrimitive.js', import.meta.url),
'utf8',
);
const [vertex, fragment] = source
.slice(source.indexOf('const VERTEX_SHADER'))
.split('const FRAGMENT_SHADER')
.map((shader) => shader.replace(/\/\/.*$/gm, '')); // comments out
assert.match(
fragment,
/if \(v_overDepth > 0\.5\) gl_FragDepth = 0\.0;\s+else czm_writeLogDepth\(v_depthFromNearPlusOne\);/,
);
// The vertex shader flags the row and leaves its log depth alone.
assert.match(
vertex,
/gl_Position\.z = -gl_Position\.w;[^}]*v_overDepth = 1\.0;/,
);
assert.doesNotMatch(vertex, /v_depthFromNearPlusOne\s*=/);
});
+2
View File
@@ -77,6 +77,8 @@ export function cesiumCapabilities(scene, only) {
// Cesium scatters drawn models through the atmosphere wherever the
// scene draws fog (its models' atmosphere stage).
'modelAtmosphere',
// A model item's nodes, written to the model's runtime nodes.
'modelNodes',
'quads',
'meshes',
// Raster shells; other field kinds are refused.
+1
View File
@@ -39,6 +39,7 @@ test('capabilities follow what the scene supports', () => {
'models',
'modelParts',
'modelAtmosphere',
'modelNodes',
'quads',
'meshes',
'fields',
+71 -2
View File
@@ -3769,6 +3769,71 @@ export function portChecks() {
},
{ capability: 'models' },
),
check(
'draw.models.nodes',
"a model item's nodes pose its named glTF nodes, live, and a node that leaves the map goes back to its authored pose",
async (h, r) => {
if (!h.assets?.model || !h.assets?.modelNode)
return { skip: 'no model with a named node in this harness' };
const NODE = h.assets.modelNode;
await overAustin(h, r);
const set = r.draw.models({ id: 'conf:models.nodes' });
const ready = [];
set.on('ready', (id) => ready.push(id));
const pos = h.toEcef({ ...AUSTIN, height: 0 });
// Far off along the node's own x axis: off the screen's centre.
const away = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5000, 0, 0, 1];
const model = (nodes) => ({
id: 'm',
pos,
url: h.assets.model,
orientation: { heading: 0, pitch: 0, roll: 0 },
minPixelSize: 160,
environmentMap: false,
shading: 'unlit',
tint: '#ff0000',
colorBlend: { mode: 'replace' },
...(nodes ? { nodes } : {}),
});
try {
set.set([model(null)]);
for (let i = 0; i < 600 && !ready.length; i++) await drawn(h, r, 1);
deepEqual(ready, ['m'], 'ready');
const s = r.query.project(pos);
// How many pixels of a patch at the model's centre are red.
const red = async () => {
await drawn(h, r, 3);
await settled(r);
r.frame.renderNow();
const image = r.readPixels({
crop: {
x: Math.round(s.x) - 4,
y: Math.round(s.y) - 4,
width: 9,
height: 9,
},
});
let n = 0;
for (let i = 0; i < image.data.length; i += 4) {
const [r0, g, b] = image.data.subarray(i, i + 3);
if (r0 > 180 && g < 70 && b < 70) n++;
}
return n;
};
ok((await red()) >= 40, 'authored pose: at the centre');
set.upsert([model({ [NODE]: away })]);
ok((await red()) < 10, 'the node moved away, live');
set.upsert([model({ [NODE]: away, NO_SUCH_NODE: away })]);
ok((await red()) < 10, 'a name the model lacks changes nothing');
set.upsert([model(null)]);
ok((await red()) >= 40, 'the node left the map: authored pose');
deepEqual(ready, ['m'], 'without loading again');
} finally {
set.dispose();
}
},
{ capability: 'modelNodes', bareSky: true },
),
check(
'draw.models.loadFailed',
'a model set says when a model fails to load, and loads it when added again',
@@ -5356,10 +5421,14 @@ export function portChecks() {
const chunks = [];
recorder.ondataavailable = (e) => chunks.push(e.data);
let colour = '#ff0000';
const paint = setInterval(() => {
const fill = () => {
g.fillStyle = colour;
g.fillRect(0, 0, 32, 32);
}, 20);
};
// Red from the first recorded frame: a blank canvas until the first
// tick read dark early in the segment on a loaded runner.
fill();
const paint = setInterval(fill, 20);
const wait = (ms) => new Promise((done) => setTimeout(done, ms));
recorder.start();
await wait(1000);
+2
View File
@@ -68,6 +68,8 @@ export interface ConformanceHarness {
): void | Promise<void>;
assets?: {
model?: string;
/** The name of a node `model` has, for the `nodes` check. */
modelNode?: string;
missingModel?: string;
modelBytes?: () => Promise<Uint8Array>;
};
+2
View File
@@ -157,6 +157,8 @@ export type Capability =
| 'terrain'
/** Atmosphere scattering applied to drawn models. */
| 'modelAtmosphere'
/** A model item's `nodes` pose the model's named glTF nodes. */
| 'modelNodes'
/** Clouds, fog, haze, rain and snow around the view (`globe.weather`). */
| 'weather'
/** Imagery draped onto 3D tiles as well as the globe. */
+11
View File
@@ -444,6 +444,15 @@ export interface ModelItem extends Placed {
* would not hide what lies below it). Can change live.
*/
clip?: 'belowOrigin';
/**
* Transforms of the model's named glTF nodes (an articulated model's
* joints): each a column-major 4×4 matrix in the node's parent frame that
* replaces the node's own transform. A node whose name leaves the map goes
* back to its authored pose; names the model lacks are ignored. Applied
* once the model is ready, on a renderer with the `modelNodes`
* capability; elsewhere the model draws as authored. Can change live.
*/
nodes?: Readonly<Record<string, ArrayLike<number>>>;
/**
* Emphasis for a focused model, 0..1, 1 = none: the tint's alpha is
* multiplied by it (in a set that recedes, as `RecedeSpec` says). Can
@@ -584,6 +593,8 @@ export type FieldSpec =
*/
detail?: { image: ImageRef; rectangle: GeoRect } | null;
alpha?: number;
/** What the raster shows, as imagery's `shows`. */
shows?: string;
};
export interface FieldHandle extends Handle {
+5
View File
@@ -122,6 +122,11 @@ export interface ImagerySpec {
) => Promise<unknown> | undefined;
/** Draw order among imagery layers; higher draws on top. */
zOrder?: number;
/**
* What the imagery shows, such as `'clouds'` or `'radar'`. Drawing never
* depends on it; a renderer may use it to tell such a layer apart.
*/
shows?: string;
}
export interface TimedUrl {
+1
View File
@@ -19,6 +19,7 @@ export const CAPABILITIES = Object.freeze([
'finestHeights',
'terrain',
'modelAtmosphere',
'modelNodes',
'weather',
'imageryOnTiles',
'splitSwipe',
+2
View File
@@ -45,6 +45,8 @@ export function createStubHarness(name = 'stub') {
// its failing scheme.
assets: {
model: 'stub:model.glb',
// A stub model is one node, named after its file.
modelNode: 'model',
missingModel: `${STUB_FAILING_MODEL_SCHEME}model.glb`,
// Any bytes: the stub parses none.
modelBytes: async () => new Uint8Array([0x67, 0x6c, 0x54, 0x46]),
+42
View File
@@ -10,6 +10,7 @@
* loop on a virtual clock, one frame at a time, in the contract's order.
*/
import { horizonFrom } from '../../geo/horizon.js';
import { headingPitchRollFrame } from '../../geo/quaternion.js';
import { alongLength } from '../../geo/polyline.js';
import { clusterScreenPoints } from '../../geo/screenCluster.js';
import { createInputRouter } from '../input/router.js';
@@ -810,6 +811,7 @@ export function createStubRenderer(options = {}) {
function itemPosition(set, item, aheadMs = 0) {
if (!item.pos) return null;
const base = toEcef(item.pos);
if (set.kind === 'models') return posedModelPosition(item, base);
const p =
set.kind === 'icons' && item.motion && capabilities.has('motionSegments')
? motionPosition(item.motion, base, motionTime(set) + aheadMs)
@@ -823,6 +825,46 @@ export function createStubRenderer(options = {}) {
: p;
}
/**
* Where the stub draws a model. A stub model is one node, named after its
* file (`/models/c172.glb` is `c172`, `stub:model.glb` is `model`): with
* `modelNodes`, an item's
* `nodes` entry for that name moves it by the matrix's translation, on the
* model's axes and at its scale; any other name is one the model lacks.
*/
function posedModelPosition(item, base) {
if (!capabilities.has('modelNodes') || !item.nodes) return base;
const file = String(item.url ?? '')
.split(/[?#]/)[0]
.split(/[/:]/)
.pop();
const name = file.replace(/\.[^.]*$/, '');
const m = name ? item.nodes[name] : null;
if (!m || m.length < 16) return base;
const k = item.scale ?? 1;
const frame = headingPitchRollFrame(base, {
heading: item.orientation?.heading ?? 0,
pitch: item.orientation?.pitch ?? 0,
roll: item.orientation?.roll ?? 0,
});
const along = (axis, t) => ({
x: axis.x * t * k,
y: axis.y * t * k,
z: axis.z * t * k,
});
let p = base;
for (const [axis, t] of [
[frame.x, m[12]],
[frame.y, m[13]],
[frame.z, m[14]],
])
if (t) {
const d = along(axis, t);
p = { x: p.x + d.x, y: p.y + d.y, z: p.z + d.z };
}
return p;
}
/**
* The shown models as the stub draws them: a square as wide as a pick
* takes (at most `maxPixelSize`, at least `minPixelSize`), far