mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
Merge origin/main into byrdit/cctv-visible-only-fetch
# Conflicts: # src/layers/cctv/frames.test.mjs
This commit is contained in:
commit
20647f6549
391 files changed
+32429
-1796
No files matched your search
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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*=/);
|
||||
});
|
||||
@@ -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.
|
||||
|
||||
@@ -39,6 +39,7 @@ test('capabilities follow what the scene supports', () => {
|
||||
'models',
|
||||
'modelParts',
|
||||
'modelAtmosphere',
|
||||
'modelNodes',
|
||||
'quads',
|
||||
'meshes',
|
||||
'fields',
|
||||
|
||||
Reference in new issue
Block a user