mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw FIRMS fire glows through the draw port and take the FIRMS renderer off the Cesium list
The fire glows are one draw-port icon set with horizon cull, drawn on the renderer's moving-icon path with a hold motion, as the layer's own icon primitive drew them. Only glows that are new or changed are written, after the set accepts them; fires a refresh drops are removed. Clicks read the renderer's hit and match the layer's own set id. The sprite order registers the set by its id.
This commit is contained in:
1 parent
3fa1ad0283
commit
b2502d6f37
11 files changed
+275
-118
No files matched your search
@@ -1093,6 +1093,9 @@ and scene services. Disable and teardown cancel pending refreshes; malformed
|
||||
snapshots preserve the last good display. Refresh restoration keeps selection
|
||||
identity without announcing a new user selection. Source/label, LOD thresholds,
|
||||
card limits, fire identities, altitude placement and analyst records are retained.
|
||||
The layer draws its fire glows through the renderer's draw port and no longer
|
||||
reaches Cesium; a caller handing it a Cesium viewer, with no
|
||||
renderer bound, loads the `./render/cesium/unbound` export once first.
|
||||
|
||||
Earthquake rendering is exposed through `./layers/earthquakes`. The layer owns
|
||||
its renderer draw set and request lifecycle and no longer reaches Cesium; the
|
||||
|
||||
@@ -15,6 +15,7 @@ import { createIconSet, ICON_CULL_LIFT } from './iconSet.js';
|
||||
import { writeHoldSegment } from './iconSegment.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import { bindFakeCesiumScene } from '../testSupport/fakeCesiumScene.mjs';
|
||||
import { createCesiumDraw } from '../render/cesium/draw.js';
|
||||
|
||||
const AUSTIN = { lon: -97.7, lat: 30.2 };
|
||||
/** Antipode of Austin — as far behind the limb as a point on Earth can be. */
|
||||
@@ -379,9 +380,14 @@ function createHarness(rawFires) {
|
||||
},
|
||||
frameState: { mode: Cesium.SceneMode.SCENE3D, mapProjection: new Cesium.GeographicProjection() },
|
||||
mapProjection: new Cesium.GeographicProjection(),
|
||||
requestRender: () => {},
|
||||
isDestroyed: () => false,
|
||||
},
|
||||
};
|
||||
bindFakeCesiumScene(viewer);
|
||||
// The Cesium draw port over the stub scene: the glows are a real GPU icon
|
||||
// set, whose rows say what the GPU would draw.
|
||||
const draw = createCesiumDraw({ scene: viewer.scene, report: () => {} });
|
||||
bindFakeCesiumScene(viewer, { draw: draw.port });
|
||||
fakeInput(viewer);
|
||||
|
||||
const layer = createFirmsHeatmapLayer({
|
||||
@@ -411,7 +417,7 @@ function createHarness(rawFires) {
|
||||
const occluder = new Cesium.EllipsoidalOccluder(Cesium.Ellipsoid.WGS84, viewer.camera.positionWC);
|
||||
const out = new Map();
|
||||
for (let row = 0; row < set.count; row += 1)
|
||||
out.set(set.idAt(row), set.show && gpuShows(set, row, occluder));
|
||||
out.set(set.idAt(row), primitives[0].show !== false && set.show && gpuShows(set, row, occluder));
|
||||
return out;
|
||||
},
|
||||
moveCameraTo(lon, lat, height = REPRO_HEIGHT_M) {
|
||||
@@ -482,7 +488,8 @@ test('layer: a refresh keeps rows and restyles one whose index now holds another
|
||||
const set = harness.icons();
|
||||
const austin = set.row('firms-0');
|
||||
const handle = set.handleAt(austin);
|
||||
const before = set.width(austin);
|
||||
const drawnPx = (row) => set.width(row) * set.scale(row);
|
||||
const before = drawnPx(austin);
|
||||
const beforeImage = set.imageFar(austin);
|
||||
|
||||
fires[0] = rawFire(AUSTIN.lat + 0.5, AUSTIN.lon, 1);
|
||||
@@ -490,7 +497,7 @@ test('layer: a refresh keeps rows and restyles one whose index now holds another
|
||||
|
||||
const row = set.row('firms-0');
|
||||
assert.equal(set.handleAt(row), handle, 'the row (and its pick id) survives the rebuild');
|
||||
assert.ok(set.width(row) < before, `restyled for the weaker fire: ${set.width(row)} < ${before}`);
|
||||
assert.ok(drawnPx(row) < before, `restyled for the weaker fire: ${drawnPx(row)} < ${before}`);
|
||||
assert.notEqual(set.imageFar(row), beforeImage, 'a red glow becomes a yellow one');
|
||||
const carto = Cesium.Cartographic.fromCartesian(set.position(row, 0, new Cesium.Cartesian3()));
|
||||
assert.ok(Math.abs(Cesium.Math.toDegrees(carto.latitude) - (AUSTIN.lat + 0.5)) < 1e-6, 'moved to the new fire');
|
||||
@@ -519,7 +526,7 @@ test('layer: re-enabling after the camera moved shows the icons, culled from the
|
||||
// loaded, so enable() does not reload): the GPU culls from the current
|
||||
// camera on the first frame.
|
||||
const show = harness.showById();
|
||||
assert.equal(harness.icons().show, true, 'the icon set is visible again');
|
||||
assert.notEqual(harness.primitives[0].show, false, 'the icon set is visible again');
|
||||
assert.equal(show.get('firms-1'), true, 'the Tokyo fire is revealed at enable time');
|
||||
assert.equal(show.get('firms-0'), false, 'the Austin fire is NOT left shining through the planet');
|
||||
} finally {
|
||||
@@ -547,7 +554,8 @@ test('layer: a refresh drops rows whose fires left, and an empty one drops them
|
||||
Array.from({ length: set.count }, (_, row) => set.idAt(row)),
|
||||
['firms-0'],
|
||||
);
|
||||
assert.equal(set.metaAt(set.row('firms-0')).fire.lat, AUSTIN.lat, 'the kept row holds its own fire');
|
||||
const kept = Cesium.Cartographic.fromCartesian(set.position(set.row('firms-0'), 0, new Cesium.Cartesian3()));
|
||||
assert.ok(Math.abs(Cesium.Math.toDegrees(kept.latitude) - AUSTIN.lat) < 1e-6, 'the kept row holds its own fire');
|
||||
|
||||
fires.length = 0;
|
||||
await harness.layer.update();
|
||||
|
||||
@@ -17,6 +17,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import { bindFakeCesiumScene } from '../testSupport/fakeCesiumScene.mjs';
|
||||
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
|
||||
|
||||
const LAYER_SOURCE = readLayerSource(
|
||||
path.join(path.dirname(fileURLToPath(import.meta.url)), 'firmsHeatmap.js'),
|
||||
@@ -37,6 +38,9 @@ function makeFire(overrides = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
/** A pick of the layer's glow `id`, as the renderer reports one of its icons. */
|
||||
const glowPick = (id) => ({ glow: id });
|
||||
|
||||
/**
|
||||
* Stand the layer up far enough to drive one click. `cardHit` is what the
|
||||
* overlay host reports under the click position — the real host only publishes
|
||||
@@ -73,16 +77,30 @@ function harness({
|
||||
},
|
||||
});
|
||||
|
||||
const draw = fakeDrawPort();
|
||||
// A glow pick names the layer's own icon set, as the renderer's pick does.
|
||||
const pick = () =>
|
||||
picked?.glow
|
||||
? {
|
||||
primitive: {},
|
||||
id: {
|
||||
set: [...draw.sets.values()].find(
|
||||
(record) => record.kind === 'icons' && !record.disposed,
|
||||
)?.spec.id,
|
||||
id: picked.glow,
|
||||
},
|
||||
}
|
||||
: picked;
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => picked,
|
||||
pick,
|
||||
canvas: { clientWidth: 1280, clientHeight: 800 },
|
||||
camera: cameraPosition ? { positionWC: cameraPosition } : undefined,
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
},
|
||||
dataSources: { add() {}, remove() {} },
|
||||
};
|
||||
bindFakeCesiumScene(viewer);
|
||||
bindFakeCesiumScene(viewer, { draw });
|
||||
const input = fakeInput(viewer);
|
||||
// The LOD rebuild (and with it the context-registration sweep) is inert
|
||||
// without a data source, so tests that drive a real refresh need one.
|
||||
@@ -205,7 +223,7 @@ test('far-side detections cannot consume the bounded ambient-card cohort', () =>
|
||||
|
||||
test('clicking a fire sprite selects it and requests the camera transfer', () => {
|
||||
const fire = makeFire();
|
||||
const h = harness({ fires: [fire], picked: { id: 'firms-7' } });
|
||||
const h = harness({ fires: [fire], picked: glowPick('firms-7') });
|
||||
try {
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 1);
|
||||
@@ -217,6 +235,19 @@ test('clicking a fire sprite selects it and requests the camera transfer', () =>
|
||||
}
|
||||
});
|
||||
|
||||
test('an item named like a fire in another draw set is not a fire', () => {
|
||||
const h = harness({
|
||||
fires: [makeFire()],
|
||||
picked: { primitive: {}, id: { set: 'other-layer:1:icons', id: 'firms-7' } },
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 0);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('clicking a fire CARD behaves exactly like clicking its sprite', () => {
|
||||
const fire = makeFire();
|
||||
// The click lands on the card, but the scene pick returns the 3D-Tiles
|
||||
@@ -239,7 +270,7 @@ test('clicking a fire CARD behaves exactly like clicking its sprite', () => {
|
||||
// The voice model reads these labels as data (track_entity, get_entity_context,
|
||||
// pointer_context); the voice card translates them where it shows them.
|
||||
test('fire labels stay English data in a translated interface', () => {
|
||||
const h = harness({ fires: [makeFire()], picked: { id: 'firms-7' } });
|
||||
const h = harness({ fires: [makeFire()], picked: glowPick('firms-7') });
|
||||
try {
|
||||
setLocale('ru');
|
||||
h.click();
|
||||
|
||||
@@ -115,7 +115,7 @@ test('flights, AIS, and FIRMS enable paths are wired through the shared sprite r
|
||||
assert.match(firmsLayer.enable.toString(), /restoreSpriteOrderOnEnable\('firms', viewer\)/);
|
||||
assert.match(
|
||||
createFirmsRendering.toString(),
|
||||
/registerSpriteCollection\('firms', layerState\._iconPrimitive\);\s*restoreSpriteOrder\(layerState\._viewer\);/,
|
||||
/spriteEntry = registerSpriteSet\('firms', set\.id\);\s*restoreSpriteOrder\(layerState\._viewer\);/,
|
||||
'lazy FIRMS registration must restore order immediately',
|
||||
);
|
||||
});
|
||||
@@ -181,6 +181,7 @@ export function createQueries({
|
||||
layerState._firesByFrp = [...fires];
|
||||
layerState._pickIndexById.clear();
|
||||
layerState._labelLodDistance = 1e7;
|
||||
components.rendering.ensureDetectionCollections();
|
||||
layerState._labelCandidates = fires.map((fire) => {
|
||||
layerState._pickIndexById.set(`firms-${fire.index}`, fire);
|
||||
return { fire, position: components.model.firePosition(fire) };
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import * as Cesium from 'cesium';
|
||||
// Still Cesium for its icons, so this layer loads the unbound camera
|
||||
// factory, which loads the draw, frame and query factories its other parts
|
||||
// reach the renderer through.
|
||||
import '../../render/cesium/camera.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { findFrame, findQuery } from '../../render/rendererOf.js';
|
||||
import { drawOf, findFrame, findQuery } from '../../render/rendererOf.js';
|
||||
import { FIRMS_OVERLAY_SOURCE_ID } from '../../data/firmsLabels.js';
|
||||
import { LOD_LEVELS, CONTEXT_TOP_N, GLOW_SPRITE_PX } from './policy.js';
|
||||
import { createIconSet, ICON_CULL_LIFT } from '../../data/iconSet.js';
|
||||
import { writeHoldSegment } from '../../data/iconSegment.js';
|
||||
import { IconSetPrimitive } from '../../render/cesium/iconSetPrimitive.js';
|
||||
import { iconAtlas } from '../../data/iconAtlas.js';
|
||||
|
||||
/** Icon sets made so far, by every fire layer: set ids unique to each. */
|
||||
let iconSets = 0;
|
||||
|
||||
export function createRendering({
|
||||
layerState,
|
||||
@@ -20,7 +14,8 @@ export function createRendering({
|
||||
feed,
|
||||
}) {
|
||||
const { warmFireAnchorFloors } = services.anchors;
|
||||
const { registerSpriteCollection, restoreSpriteOrder } = services.sprites;
|
||||
const { registerSpriteSet, unregisterSpriteCollection, restoreSpriteOrder } =
|
||||
services.sprites;
|
||||
const { overlayHost } = config;
|
||||
|
||||
/**
|
||||
@@ -71,9 +66,23 @@ export function createRendering({
|
||||
if (layerState._cells?.size()) layerState._cells.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Each drawn glow's detection and anchor, by its item id: what it was last
|
||||
* written with, so a rebuild writes only the glows that changed.
|
||||
* @type {Map<string, {fire: object, position: object}>}
|
||||
*/
|
||||
const drawnGlows = new Map();
|
||||
|
||||
/** Take every glow down (no write when there are none). */
|
||||
function clearIcons() {
|
||||
if (!drawnGlows.size) return;
|
||||
drawnGlows.clear();
|
||||
layerState._icons?.clear();
|
||||
}
|
||||
|
||||
function clearRendered() {
|
||||
clearCells();
|
||||
layerState._icons?.clear();
|
||||
clearIcons();
|
||||
layerState._pickIndexById.clear();
|
||||
layerState._cellCount = 0;
|
||||
layerState._labelCandidates = [];
|
||||
@@ -152,7 +161,7 @@ export function createRendering({
|
||||
|
||||
function renderCells(cells, lod, bounds) {
|
||||
ensureDetectionCollections();
|
||||
layerState._icons?.clear();
|
||||
clearIcons();
|
||||
layerState._pickIndexById.clear();
|
||||
layerState._cellCount = cells.length;
|
||||
const maxScore = Math.max(1, ...cells.map(components.model.heatScore));
|
||||
@@ -246,15 +255,17 @@ export function createRendering({
|
||||
layerState._labelCandidates = [];
|
||||
layerState._labelLodDistance = lod.labelDistance;
|
||||
|
||||
// Fires keep their rows across rebuilds: a pan that keeps a fire in view
|
||||
// rewrites nothing for it, and only rows that left the view go.
|
||||
// Fires keep their glows across rebuilds: a pan that keeps a fire in
|
||||
// view rewrites nothing for it, and only glows that left the view go.
|
||||
const keep = new Set();
|
||||
const writes = [];
|
||||
for (const fire of candidates) {
|
||||
const position = components.model.firePosition(fire);
|
||||
const pickId = `firms-${fire.index}`;
|
||||
layerState._pickIndexById.set(pickId, fire);
|
||||
keep.add(pickId);
|
||||
placeFireIcon(set, pickId, fire, position);
|
||||
const glow = fireGlow(pickId, fire, position);
|
||||
if (glow) writes.push({ glow, fire, position });
|
||||
// FRP-sorted walk: candidate order doubles as label priority.
|
||||
layerState._labelCandidates.push({
|
||||
position,
|
||||
@@ -263,9 +274,15 @@ export function createRendering({
|
||||
cell: null,
|
||||
});
|
||||
}
|
||||
for (let row = set.count - 1; row >= 0; row -= 1) {
|
||||
const pickId = set.idAt(row);
|
||||
if (!keep.has(pickId)) set.remove(pickId);
|
||||
const gone = [];
|
||||
for (const pickId of drawnGlows.keys())
|
||||
if (!keep.has(pickId)) gone.push(pickId);
|
||||
for (const pickId of gone) drawnGlows.delete(pickId);
|
||||
if (gone.length) set.remove(gone);
|
||||
if (writes.length) {
|
||||
set.upsert(writes.map((write) => write.glow));
|
||||
for (const { glow, fire, position } of writes)
|
||||
drawnGlows.set(glow.id, { fire, position });
|
||||
}
|
||||
|
||||
components.cards.rebuildAmbientLabels();
|
||||
@@ -289,82 +306,69 @@ export function createRendering({
|
||||
}
|
||||
|
||||
/**
|
||||
* A fire's glow row: drawn depth-test-free at its anchor (a detection is
|
||||
* never swallowed by terrain it sits on), with the far side of the globe
|
||||
* culled on the GPU each frame. The Cesium globe is hidden here (Google 3D
|
||||
* Tiles render the planet), so nothing writes far-side depth, and the cull
|
||||
* is what keeps fires from shining through the planet. The anchor moves
|
||||
* once, when its floor warms.
|
||||
* A fire's glow icon, when it is new or changed since it was last drawn
|
||||
* (else null): drawn depth-test-free at its anchor (a detection is never
|
||||
* swallowed by terrain it sits on), with the far side of the globe culled
|
||||
* by the set's horizon cull each frame. The Cesium globe is hidden here
|
||||
* (Google 3D Tiles render the planet), so nothing writes far-side depth,
|
||||
* and the cull is what keeps fires from shining through the planet. The
|
||||
* anchor moves once, when its floor warms. A refresh reuses indices, so a
|
||||
* kept id can hold a different detection, restyled then.
|
||||
*
|
||||
* The glow is rasterised once per colour at GLOW_SPRITE_PX and drawn at
|
||||
* the fire's own size by its scale. Its hold motion draws it on the
|
||||
* renderer's moving-icon path, which culls the horizon on the GPU.
|
||||
*/
|
||||
function placeFireIcon(set, pickId, fire, position) {
|
||||
let row = set.row(pickId);
|
||||
if (row < 0) {
|
||||
row = set.add(pickId, {
|
||||
layer: 'firms',
|
||||
id: pickId,
|
||||
fire: null,
|
||||
position: null,
|
||||
});
|
||||
set.setFlag(row, ICON_CULL_LIFT, true);
|
||||
set.setShown(row, true);
|
||||
}
|
||||
const meta = set.metaAt(row);
|
||||
// A refresh reuses indices, so a kept row can hold a different detection.
|
||||
if (meta.fire !== fire) {
|
||||
meta.fire = fire;
|
||||
const slot = iconAtlas.slot(
|
||||
components.model.glowSprite(components.model.detectionColorStop(fire)),
|
||||
GLOW_SPRITE_PX,
|
||||
);
|
||||
const corePx = components.model.sizeBucket(
|
||||
components.model.frpPixelSize(fire.frp),
|
||||
);
|
||||
set.setImage(row, slot, slot);
|
||||
set.setSize(row, corePx * 2, corePx * 2);
|
||||
}
|
||||
if (meta.position === position) return;
|
||||
meta.position = position;
|
||||
writeHoldSegment(set.segments, row, position, 0);
|
||||
set.segmentWritten(row);
|
||||
function fireGlow(pickId, fire, position) {
|
||||
const drawn = drawnGlows.get(pickId);
|
||||
if (drawn && drawn.fire === fire && drawn.position === position)
|
||||
return null;
|
||||
const corePx = components.model.sizeBucket(
|
||||
components.model.frpPixelSize(fire.frp),
|
||||
);
|
||||
return {
|
||||
id: pickId,
|
||||
pos: { x: position.x, y: position.y, z: position.z },
|
||||
image: components.model.glowSprite(
|
||||
components.model.detectionColorStop(fire),
|
||||
),
|
||||
size: [GLOW_SPRITE_PX, GLOW_SPRITE_PX],
|
||||
scale: (corePx * 2) / GLOW_SPRITE_PX,
|
||||
disableDepthTest: Infinity,
|
||||
motion: { kind: 'hold' },
|
||||
meta: { layer: 'firms', id: pickId },
|
||||
};
|
||||
}
|
||||
|
||||
/** The scene the icon primitive was added to. */
|
||||
let iconScene = null;
|
||||
/** The sprite order's entry for the glow set. */
|
||||
let spriteEntry = null;
|
||||
|
||||
function ensureDetectionCollections() {
|
||||
if (!layerState._viewer || layerState._icons) return;
|
||||
const epoch = Cesium.JulianDate.now();
|
||||
layerState._icons = createIconSet({ epoch });
|
||||
layerState._iconPrimitive = new IconSetPrimitive({
|
||||
set: layerState._icons,
|
||||
renderTime: () => epoch,
|
||||
requestRender: () => layerState._viewer?.scene?.requestRender?.(),
|
||||
const set = drawOf(layerState._viewer).icons({
|
||||
id: `firms:${++iconSets}:icons`,
|
||||
horizonCull: true,
|
||||
show: layerState._enabled,
|
||||
});
|
||||
layerState._icons.show = layerState._enabled;
|
||||
iconScene = layerState._viewer.scene;
|
||||
iconScene.primitives.add(layerState._iconPrimitive);
|
||||
registerSpriteCollection('firms', layerState._iconPrimitive);
|
||||
// Columns of no rows put the set's host in the scene now, where the
|
||||
// sprite order finds it, rather than with its first fire.
|
||||
set.setColumns?.({ ids: [] });
|
||||
layerState._icons = set;
|
||||
spriteEntry = registerSpriteSet('firms', set.id);
|
||||
restoreSpriteOrder(layerState._viewer);
|
||||
overlayHost.setVisible(FIRMS_OVERLAY_SOURCE_ID, layerState._enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the icons out of the scene they were added to, whichever viewer the
|
||||
* caller tears down, and free them: a destroyed primitive left in a live
|
||||
* scene throws on its next frame.
|
||||
* Let the glow set go, whichever viewer the caller tears down: its
|
||||
* renderer takes it out of the scene it draws in.
|
||||
*/
|
||||
function removeDetectionCollections() {
|
||||
const primitive = layerState._iconPrimitive;
|
||||
try {
|
||||
if (primitive && iconScene && !iconScene.isDestroyed?.())
|
||||
iconScene.primitives.remove(primitive);
|
||||
} catch {
|
||||
/* already torn down */
|
||||
}
|
||||
if (primitive && !primitive.isDestroyed()) primitive.destroy();
|
||||
iconScene = null;
|
||||
layerState._iconPrimitive = null;
|
||||
if (spriteEntry) unregisterSpriteCollection('firms', spriteEntry);
|
||||
spriteEntry = null;
|
||||
layerState._icons?.dispose();
|
||||
layerState._icons = null;
|
||||
drawnGlows.clear();
|
||||
overlayHost.clearSource(FIRMS_OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(FIRMS_OVERLAY_SOURCE_ID, false);
|
||||
}
|
||||
@@ -372,8 +376,8 @@ export function createRendering({
|
||||
/**
|
||||
* The renderer's query and frame ports the cards and the LOD watcher use:
|
||||
* the bound renderer's, or for a viewer with no
|
||||
* renderer bound, those the Cesium adapter builds over it (`findQuery`,
|
||||
* `findFrame`; the camera factory loaded above loads theirs).
|
||||
* renderer bound, those the Cesium adapter builds over it once the
|
||||
* caller has loaded `./render/cesium/unbound` (`findQuery`, `findFrame`).
|
||||
* @returns {{query: object|null, frame: object|null}}
|
||||
*/
|
||||
function scenePorts() {
|
||||
|
||||
@@ -35,7 +35,7 @@ export function createSelection({
|
||||
const input = inputFor(layerState._viewer);
|
||||
layerState._clickSubscription = input.onClick((event) => {
|
||||
const picked = event.pick;
|
||||
const fire = pickedFire(picked);
|
||||
const fire = pickedFire(event.drawHit);
|
||||
if (fire) {
|
||||
selectAndFocusFire(fire);
|
||||
return;
|
||||
@@ -80,29 +80,17 @@ export function createSelection({
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a scene pick to one of this layer's fire records, or null.
|
||||
* Icon-set picks carry our row id on picked.id and on picked.primitive.id;
|
||||
* either is accepted.
|
||||
* @param {*} picked - Result of scene.pick().
|
||||
* Resolve a pick to one of this layer's fire records, or null: a hit (a
|
||||
* draw-port `Hit`, `event.drawHit`) on a glow of the layer's own icon set
|
||||
* whose id is a fire it draws now.
|
||||
* @param {?{set: string, id: string}} hit - The renderer's hit.
|
||||
* @returns {?Object} Fire record.
|
||||
*/
|
||||
|
||||
function pickedFire(picked) {
|
||||
if (!picked) return null;
|
||||
const primitiveId = picked.primitive?.id;
|
||||
if (
|
||||
typeof primitiveId === 'string' &&
|
||||
layerState._pickIndexById.has(primitiveId)
|
||||
) {
|
||||
return layerState._pickIndexById.get(primitiveId);
|
||||
}
|
||||
if (
|
||||
typeof picked.id === 'string' &&
|
||||
layerState._pickIndexById.has(picked.id)
|
||||
) {
|
||||
return layerState._pickIndexById.get(picked.id);
|
||||
}
|
||||
return null;
|
||||
function pickedFire(hit) {
|
||||
if (!hit || !layerState._icons || hit.set !== layerState._icons.id)
|
||||
return null;
|
||||
return layerState._pickIndexById.get(hit.id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,10 @@ export function createFirmsState({ services, config }) {
|
||||
|
||||
layerState._cells = null;
|
||||
|
||||
/** Detection glow rows and the primitive that draws them. */
|
||||
/** The detection glows' icon draw set (made with the first render). */
|
||||
|
||||
layerState._icons = null;
|
||||
|
||||
layerState._iconPrimitive = null;
|
||||
|
||||
layerState._enabled = false;
|
||||
|
||||
layerState._destroyed = false;
|
||||
|
||||
@@ -2887,6 +2887,128 @@ test('the vessels layer draws its ships as one GPU icon set that holds them on c
|
||||
}
|
||||
});
|
||||
|
||||
test('the FIRMS layer draws its fire glows as one GPU icon set on a viewer of its own', async (t) => {
|
||||
const { createRendering } = await import('../../layers/firms/rendering.js');
|
||||
const { createModel } = await import('../../layers/firms/model.js');
|
||||
const { createFirmsState } = await import('../../layers/firms/state.js');
|
||||
const { IconSetPrimitive } = await import('./iconSetPrimitive.js');
|
||||
const { ICON_CULL_LIFT } = await import('../../data/iconSet.js');
|
||||
const { GLOW_SPRITE_PX, LOD_LEVELS } =
|
||||
await import('../../layers/firms/policy.js');
|
||||
// Each glow colour is rasterised on a canvas once.
|
||||
const hadDocument = Object.hasOwn(globalThis, 'document');
|
||||
const priorDocument = globalThis.document;
|
||||
globalThis.document = {
|
||||
createElement: () => {
|
||||
let stops = [];
|
||||
return {
|
||||
width: 0,
|
||||
height: 0,
|
||||
getContext: () => ({
|
||||
createRadialGradient: () => ({
|
||||
addColorStop: (_, color) => stops.push(color),
|
||||
}),
|
||||
fillRect() {},
|
||||
}),
|
||||
toDataURL: () => `data:image/png;base64,AAAA#${stops.join('|')}`,
|
||||
};
|
||||
},
|
||||
};
|
||||
t.after(() => {
|
||||
if (hadDocument) globalThis.document = priorDocument;
|
||||
else delete globalThis.document;
|
||||
});
|
||||
const scene = fakeScene();
|
||||
const viewer = { scene, isDestroyed: () => false };
|
||||
const sprites = [];
|
||||
const noop = () => {};
|
||||
const services = {
|
||||
anchors: {
|
||||
fireAnchorHeight: () => 40,
|
||||
warmFireAnchorFloors: async () => false,
|
||||
},
|
||||
sprites: {
|
||||
registerSpriteSet: (layerId, setId) => {
|
||||
sprites.push([layerId, setId]);
|
||||
return { drawSetId: setId };
|
||||
},
|
||||
unregisterSpriteCollection: noop,
|
||||
restoreSpriteOrder: noop,
|
||||
},
|
||||
};
|
||||
const config = {
|
||||
overlayHost: { setVisible: noop, clearSource: noop },
|
||||
};
|
||||
const layerState = createFirmsState({ services, config });
|
||||
layerState._viewer = viewer;
|
||||
layerState._enabled = true;
|
||||
const components = {
|
||||
cards: { rebuildAmbientLabels: noop },
|
||||
selection: { refreshContextRegistrations: noop },
|
||||
};
|
||||
const context = { layerState, services, config, components, feed: null };
|
||||
components.model = createModel(context);
|
||||
const rendering = createRendering(context);
|
||||
const fire = (index, lon, frp) => ({
|
||||
index,
|
||||
lat: 30.2,
|
||||
lon,
|
||||
frp,
|
||||
confidence: 0.9,
|
||||
brightness: 340,
|
||||
acqMs: 1,
|
||||
});
|
||||
layerState._firesByFrp = [fire(0, -97.7, 900), fire(1, -97.6, 4)];
|
||||
const local = LOD_LEVELS.find((lod) => lod.id === 'local');
|
||||
rendering.renderDetections(local, null);
|
||||
|
||||
const [host] = scene.added;
|
||||
assert.ok(host instanceof IconSetPrimitive, 'one GPU icon set');
|
||||
assert.deepEqual(sprites, [['firms', host.drawSetId]]);
|
||||
const set = host.set;
|
||||
assert.equal(set.count, 2);
|
||||
const strong = set.row('firms-0');
|
||||
const weak = set.row('firms-1');
|
||||
assert.equal(set.flags(strong) & ICON_CULL_LIFT, ICON_CULL_LIFT);
|
||||
assert.ok(set.depthTestDistance(strong) >= 1e30, 'over depth everywhere');
|
||||
// One raster per colour at the sprite's size, drawn at the fire's size.
|
||||
assert.equal(set.width(strong), GLOW_SPRITE_PX);
|
||||
const drawnPx = (row) => set.width(row) * set.scale(row);
|
||||
assert.ok(Math.abs(drawnPx(strong) - 56) < 1e-4, `${drawnPx(strong)} px`);
|
||||
assert.ok(Math.abs(drawnPx(weak) - 24) < 1e-4, `${drawnPx(weak)} px`);
|
||||
assert.notEqual(set.imageFar(strong), set.imageFar(weak), 'red, not yellow');
|
||||
const tau = set.seconds(Cesium.JulianDate.now());
|
||||
const at = Cesium.Cartographic.fromCartesian(set.position(strong, tau));
|
||||
assert.ok(Math.abs(Cesium.Math.toDegrees(at.longitude) + 97.7) < 1e-6);
|
||||
assert.ok(Math.abs(at.height - 40) < 1e-3, 'at its anchor');
|
||||
assert.deepEqual(drawHitOf(host._pickObject('firms-0', null, { show: true })), {
|
||||
set: host.drawSetId,
|
||||
id: 'firms-0',
|
||||
meta: { layer: 'firms', id: 'firms-0' },
|
||||
surface: false,
|
||||
});
|
||||
|
||||
// A rebuild that keeps one fire writes nothing for it and drops the other.
|
||||
const written = [];
|
||||
const upsert = layerState._icons.upsert.bind(layerState._icons);
|
||||
layerState._icons.upsert = (items) => {
|
||||
written.push(...items.map((item) => item.id));
|
||||
return upsert(items);
|
||||
};
|
||||
layerState._firesByFrp = [layerState._firesByFrp[0]];
|
||||
rendering.renderDetections(local, null);
|
||||
assert.equal(set.count, 1);
|
||||
assert.equal(set.idAt(0), 'firms-0');
|
||||
assert.deepEqual(written, [], 'the kept fire is not written again');
|
||||
assert.equal(scene.added[0], host, 'the same host');
|
||||
|
||||
// Hidden with the layer, and gone with it.
|
||||
layerState._icons.show = false;
|
||||
assert.equal(host.show, false);
|
||||
rendering.removeDetectionCollections();
|
||||
assert.equal(scene.added.length, 0);
|
||||
});
|
||||
|
||||
test('vessels on a host with no sprite-set registry still draw, and say so once', async (t) => {
|
||||
const warnings = [];
|
||||
t.mock.method(console, 'warn', (...args) => warnings.push(args.join(' ')));
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
"src/data/geoImportPins.js",
|
||||
"src/input/dispatcher.js",
|
||||
"src/input/sensorPick.js",
|
||||
"src/layers/firms/rendering.js",
|
||||
"src/layers/ghostMaps/index.js",
|
||||
"src/layers/installations/rendering.js",
|
||||
"src/layers/launches/launchPad.js",
|
||||
|
||||
@@ -89,6 +89,9 @@ const DRAW_FROM_CALLER = new Set([
|
||||
// Its icons, wireframes, volumes, plane and gizmo draw through `drawOf`;
|
||||
// it picks, projects and reads the eye and the globe through the ports.
|
||||
'./layers/cctv',
|
||||
// Its heat cells and fire glows draw through `drawOf`; its cards and LOD
|
||||
// watcher read the eye, projection and frames through the ports.
|
||||
'./layers/firms',
|
||||
// Its data packs draw through `drawOf`; its flights ask `cameraOf`, which
|
||||
// throws until then too.
|
||||
'./scenes',
|
||||
|
||||
Reference in new issue
Block a user