Fix the follow-up review findings in import, layers, startup and engines

- KML/KMZ import: a per-file canvas budget and cache for ground overlays,
  limits on rings and vertices of raised polygons, overlays across 360° and
  near the poles, degenerate holes, polar and single-latitude fills,
  absolute overlays at their altitude, overlay order by drawOrder as on
  Cesium, and pins on tiles keep their measured height.
- Points on the surface: OSM Places and Street Level cones share the
  surface sampler and sit on the terrain before they are measured, within
  a sampling budget per pass; Cockpit's contact-dot bank keeps the dot
  atlas, and a failed fleet model loads again after a pause.
- Startup: the loading screen lifts after the share-link view is restored,
  the retry screen names the failed engine and takes focus, and the
  fallback toast stays for 6 s.
- Engines: an engine switch lands a running camera flight at its
  destination (camera.completeFlight on both engines), the sighting card
  leaves focus on the engine picker after a switch, and a Cesium model
  error stays with the instance that failed.
- The MCP panel builds again: its wind-mesh alias resolves to the stub.
- QA: the wildlife switch waits for the camera to rest, GBFS --w2 says it
  needs the dev server, and test fixtures are shared instead of copied.
This commit is contained in:
German Khokhlov committed 2026-11-10 01:57:11 +04:00
1 parent 0ef29781e5
commit 60fb8fee07
82 files changed
+2363 -1574

No files matched your search

-141
View File
@@ -1,141 +0,0 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as geo from '../../geo/index.js';
import { isEngineEvent } from '../contract.js';
import { orientationVectors } from '../cameraMath.js';
import { createCameraModel } from './cameraModel.js';
const { cartesian2, cartesian3, math, matrix4 } = geo;
const near = (actual, expected, tolerance, label) =>
assert.ok(
Math.abs(actual - expected) <= tolerance,
`${label}: ${actual} is not within ${tolerance} of ${expected}`,
);
// A stand-in for Navara's camera: setCamera lands on the next update with
// Navara's ±89.99° pitch clamp; flights resolve when the test says so.
function createFakePort() {
const port = {
applied: [],
flights: [],
stops: 0,
frames: 0,
drawn: null,
width: 1280,
height: 800,
apply(pose) {
port.applied.push(pose);
},
read: () => port.drawn,
fly(pose, options) {
let settle;
const promise = new Promise((resolve) => (settle = resolve));
port.flights.push({ pose, options, settle });
return promise;
},
stop() {
port.stops++;
},
size: () => ({ width: port.width, height: port.height }),
requestFrame() {
port.frames++;
},
/** Navara's update: draw a newly applied pose (pitch clamped). */
drawnCount: 0,
update() {
if (port.applied.length === port.drawnCount) return;
port.drawnCount = port.applied.length;
const pose = port.applied.at(-1);
const pitch = Math.max(-89.99, Math.min(89.99, pose.pitch));
const position = cartesian3.fromDegrees(pose.lng, pose.lat, pose.height);
port.drawn = {
position,
...orientationVectors(
cartesian3.fromDegrees(pose.lng, pose.lat, 0),
math.toRadians(pose.heading),
math.toRadians(pitch),
math.toRadians(pose.roll),
),
};
},
};
return port;
}
function createClock() {
const clock = {
time: 0,
timers: [],
now: () => clock.time,
setTimeout(fn, ms) {
const timer = { fn, at: clock.time + ms };
clock.timers.push(timer);
return timer;
},
clearTimeout(timer) {
clock.timers = clock.timers.filter((entry) => entry !== timer);
},
advance(ms) {
clock.time += ms;
for (const timer of [...clock.timers])
if (timer.at <= clock.time) {
clock.clearTimeout(timer);
timer.fn();
}
},
};
return clock;
}
function setup() {
const port = createFakePort();
const clock = createClock();
const model = createCameraModel({ port, clock });
// One Navara frame: update, preRender sync, postRender events.
const frame = (ms = 16) => {
clock.advance(ms);
port.update();
model.sync();
model.afterFrame();
};
return { port, clock, model, camera: model.camera, frame };
}
// Cesium's Camera._updateCameraChanged: direction angle / (fovy / 2), and
// heading or roll change / π, each against percentageChanged (0.5).
test('turning in place raises changed as Cesium does', () => {
const { camera, frame } = setup();
const destination = cartesian3.fromDegrees(10, 45, 5000);
camera.setView({
destination,
orientation: { heading: 0, pitch: -math.PI_OVER_TWO, roll: 0 },
});
frame();
frame();
let changed = 0;
camera.changed.addEventListener(() => changed++);
// Tilt from straight down to 45° on the spot: 45° > half the fovy.
camera.setView({
destination,
orientation: { heading: 0, pitch: -(Math.PI / 4), roll: 0 },
});
frame();
assert.equal(changed, 1, 'a 45° tilt in place');
// Heading +170° looking straight down (north-up reset): direction unchanged.
camera.setView({
destination,
orientation: { heading: 0, pitch: -math.PI_OVER_TWO, roll: 0 },
});
frame();
const before = changed;
camera.setView({
destination,
orientation: {
heading: math.toRadians(170),
pitch: -math.PI_OVER_TWO,
roll: 0,
},
});
frame();
assert.equal(changed, before + 1, 'a 170° heading turn in the nadir');
});
+33 -16
View File
@@ -206,27 +206,34 @@ export function createCameraModel({
options.complete?.();
return;
}
const current = { options, resume: port.suspendCameraInputs?.() };
flight = current;
// Navara moves the camera from here on; read it back every frame.
pushed = null;
const pose = navaraPose(target.position, target.direction, target.up);
const flyOptions = {};
if (options.duration !== undefined)
flyOptions.duration = options.duration * 1000;
if (options.easing !== undefined)
flyOptions.easing = NAVARA_EASINGS[options.easing];
port
.fly(navaraPose(target.position, target.direction, target.up), flyOptions)
.then(
(arrived) => {
if (flight !== current || destroyed) return;
if (!arrived) return endFlight(current, 'cancel');
endFlight(current, 'complete');
land(options, target);
options.complete?.();
},
() => endFlight(current, 'cancel'),
);
const current = { options, target, resume: port.suspendCameraInputs?.() };
flight = current;
let pending;
try {
pending = port.fly(pose, flyOptions);
} catch (error) {
// As in Cesium, a flight that cannot start reports only the exception.
endFlight(current, 'fail');
throw error;
}
// Navara moves the camera from here on; read it back every frame.
pushed = null;
pending.then(
(arrived) => {
if (flight !== current || destroyed) return;
if (!arrived) return endFlight(current, 'cancel');
endFlight(current, 'complete');
land(options, target);
options.complete?.();
},
() => endFlight(current, 'cancel'),
);
}
/** Reads Navara's drawn camera; called once per frame before preRender. */
@@ -384,6 +391,16 @@ export function createCameraModel({
announce();
cancelCurrentFlight();
},
completeFlight() {
const current = flight;
if (!current) return;
endFlight(current, 'complete');
// Cesium lands it through setView, a command.
announce();
port.stop();
land(current.options, current.target);
current.options.complete?.();
},
zoomIn(amount = DEFAULT_ZOOM_AMOUNT) {
place({
...state,
+137
View File
@@ -273,6 +273,67 @@ test('easings map onto Navara presets and an omitted one stays Navara’s own',
assert.equal(port.flights.at(-1).options.duration, undefined);
});
test('an invalid flight pose does not suspend camera inputs', () => {
const { camera, port } = setup();
let suspensions = 0;
port.suspendCameraInputs = () => {
suspensions++;
return () => {};
};
assert.throws(
() =>
camera.flyTo({
destination: cartesian3.create(),
orientation: {
direction: cartesian3.create(0, 0, -1),
up: cartesian3.create(0, 1, 0),
},
duration: 2,
}),
TypeError,
);
assert.equal(suspensions, 0);
assert.equal(camera.flightActive(), false);
assert.equal(port.flights.length, 0);
});
test('a synchronous flight failure releases the camera inputs', async (context) => {
for (const method of ['flyTo', 'flyToSphere'])
await context.test(method, () => {
const { camera, port, model } = setup();
const outcome = [];
let suspensions = 0;
port.suspendCameraInputs = () => {
suspensions++;
return () => suspensions--;
};
const error = new Error('Flight could not start');
port.fly = () => {
throw error;
};
const destination = cartesian3.fromDegrees(10, 45, 5000);
const options = {
duration: 2,
complete: () => outcome.push('complete'),
cancel: () => outcome.push('cancel'),
};
assert.throws(
() =>
method === 'flyTo'
? camera.flyTo({ destination, ...options })
: camera.flyToSphere({ center: destination, radius: 100 }, options),
(thrown) => thrown === error,
);
assert.equal(camera.flightActive(), false);
assert.equal(suspensions, 0);
assert.deepEqual(outcome, [], 'the exception alone reports it');
camera.cancelFlight();
model.destroy();
assert.equal(suspensions, 0, 'the failed flight resumes only once');
assert.deepEqual(outcome, []);
});
});
test('cancelFlight stops Navara in place and calls cancel, never complete', async () => {
const { camera, port } = setup();
const outcome = [];
@@ -290,6 +351,43 @@ test('cancelFlight stops Navara in place and calls cancel, never complete', asyn
assert.deepEqual(outcome, ['cancel']);
});
test('completeFlight lands at the destination and calls complete, as Cesium', async () => {
const { camera, port } = setup();
const outcome = [];
let suspensions = 0;
port.suspendCameraInputs = () => {
suspensions++;
return () => suspensions--;
};
const destination = cartesian3.fromDegrees(86.925, 27.988, 40000);
camera.completeFlight();
assert.equal(port.stops, 0, 'without a flight it does nothing');
camera.flyTo({
destination,
orientation: { heading: 0.5, pitch: -0.8, roll: 0 },
duration: 8,
endTransform: matrix4.IDENTITY,
complete: () => outcome.push('complete'),
cancel: () => outcome.push('cancel'),
});
// Navara is midway when the flight is completed.
const midway = cartesian3.fromDegrees(50, 15, 8e6);
port.drawn = { position: midway, ...orientationVectors(midway, 0, -1, 0) };
camera.completeFlight();
assert.deepEqual(outcome, ['complete']);
assert.equal(camera.flightActive(), false);
assert.equal(suspensions, 0, 'the camera inputs are back');
assert.equal(port.stops, 1);
const pose = camera.pose();
near(cartesian3.distance(pose.position, destination), 0, 1e-6, 'position');
near(pose.heading, 0.5, 1e-9, 'heading');
near(pose.pitch, -0.8, 1e-9, 'pitch');
near(port.applied.at(-1).height, 40000, 1e-6, 'pushed to Navara');
port.flights[0].settle(false);
await flush();
assert.deepEqual(outcome, ['complete']);
});
test('a newer flight cancels the previous one', async () => {
const { camera, port } = setup();
const outcome = [];
@@ -548,3 +646,42 @@ test('setView cancels a model flight before its promise settles', async () => {
'setView stays',
);
});
// Cesium's Camera._updateCameraChanged: direction angle / (fovy / 2), and
// heading or roll change / π, each against percentageChanged (0.5).
test('turning in place raises changed as Cesium does', () => {
const { camera, frame } = setup();
const destination = cartesian3.fromDegrees(10, 45, 5000);
camera.setView({
destination,
orientation: { heading: 0, pitch: -math.PI_OVER_TWO, roll: 0 },
});
frame();
frame();
let changed = 0;
camera.changed.addEventListener(() => changed++);
// Tilt from straight down to 45° on the spot: 45° > half the fovy.
camera.setView({
destination,
orientation: { heading: 0, pitch: -(Math.PI / 4), roll: 0 },
});
frame();
assert.equal(changed, 1, 'a 45° tilt in place');
// Heading +170° looking straight down (north-up reset): direction unchanged.
camera.setView({
destination,
orientation: { heading: 0, pitch: -math.PI_OVER_TWO, roll: 0 },
});
frame();
const before = changed;
camera.setView({
destination,
orientation: {
heading: math.toRadians(170),
pitch: -math.PI_OVER_TWO,
roll: 0,
},
});
frame();
assert.equal(changed, before + 1, 'a 170° heading turn in the nadir');
});
@@ -739,3 +739,33 @@ test('ground picks use the visible surface and fall back to the globe', async ()
assert.equal(engine.picker.pick(at)?.id, 'roof');
engine.destroy();
});
// Cesium's CameraFlightPath turns the camera inputs off for the flight, so a
// gesture never cancels it; layers/infrastructure suspends the inputs for the
// same reason ("Camera input would cancel the flight").
test('a wheel during a flight with the camera inputs suspended does not cancel it', async () => {
const { engine, view } = setup();
const outcome = [];
const restore = engine.input.suspendCameraInputs();
engine.camera.flyTo({
destination: cartesian3.fromDegrees(100, 0, 5e6),
duration: 1.5,
complete: () => outcome.push('complete'),
cancel: () => outcome.push('cancel'),
});
view.canvas.dispatchEvent(new Event('wheel'));
view.canvas.dispatchEvent(new Event('pointerdown'));
assert.deepEqual(outcome, [], 'the flight goes on');
assert.equal(engine.camera.flightActive(), true);
restore();
assert.equal(
engine.input.cameraInputsEnabled(),
false,
'the flight keeps its own suspension',
);
view.flights[0].resolve(true);
await Promise.resolve();
assert.deepEqual(outcome, ['complete']);
assert.equal(engine.input.cameraInputsEnabled(), true);
engine.destroy();
});
-186
View File
@@ -1,186 +0,0 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as geo from '../../geo/index.js';
import { assertGlobeEngine, engineCapabilities } from '../contract.js';
import { cesiumFovy, orientationVectors } from '../cameraMath.js';
import { createNavaraEngine } from './createNavaraEngine.js';
const { cartesian2, cartesian3, math } = geo;
// The parts of a Navara ThreeView the engine uses.
function fakeView() {
const handlers = new Map();
const canvas = new EventTarget();
Object.assign(canvas, {
clientWidth: 1280,
clientHeight: 800,
getBoundingClientRect: () => ({ left: 10, top: 20 }),
parentElement: { id: 'container' },
});
const position = cartesian3.fromDegrees(0, 0, 1e7);
const { direction, up } = orientationVectors(
position,
0,
-math.PI_OVER_TWO,
0,
);
// three's camera.matrixWorld: columns right, up, back (−direction), position.
const right = cartesian3.cross(direction, up, cartesian3.create());
const elements = [
right.x,
right.y,
right.z,
0,
up.x,
up.y,
up.z,
0,
-direction.x,
-direction.y,
-direction.z,
0,
position.x,
position.y,
position.z,
1,
];
const view = {
canvas,
animation: false,
calls: [],
flights: [],
on(name, fn) {
if (!handlers.has(name)) handlers.set(name, new Set());
handlers.get(name).add(fn);
},
off(name, fn) {
handlers.get(name)?.delete(fn);
},
emit(name, ...args) {
for (const fn of [...(handlers.get(name) ?? [])]) fn(...args);
},
listenerCount: () =>
[...handlers.values()].reduce((count, set) => count + set.size, 0),
camera: {
raw: { matrixWorld: { elements }, updateMatrixWorld() {} },
fovs: [],
set fov(value) {
view.camera.fovs.push(value);
},
set options(value) {
view.calls.push(['options', value]);
},
},
setCamera(pose) {
view.calls.push(['setCamera', pose]);
},
flyTo(pose, options) {
return new Promise((resolve) =>
view.flights.push({ pose, options, resolve }),
);
},
forceUpdate() {
view.calls.push(['forceUpdate']);
},
pickDepthPosition(x, y) {
view.calls.push(['pickDepthPosition', x, y]);
return x > 100 ? { x: 1, y: 2, z: 3, isVector3: true } : null;
},
sampleTerrainHeight: () => undefined,
addSource: (desc) => ({ id: 's', desc, delete: () => true }),
addLayer: (desc) => ({ id: 'l', desc, delete() {} }),
attribution: { add() {}, remove() {} },
};
return view;
}
const hooks = {
tileRoots: () => [],
isIdle: () => true,
retainTileGeometry() {},
};
// Primitive ports for tests of engine orchestration.
const STUB_MOVERS = Object.freeze({
createSet() {
throw new Error("Navara movers need the view's three runtime (movers/)");
},
list: () => [],
});
const STUB_LINES = Object.freeze({
createSegments() {
throw new Error("Navara lines need the view's three runtime (lines/)");
},
createLine() {
throw new Error("Navara lines need the view's three runtime (lines/)");
},
list: () => [],
});
const STUB_MESHES = Object.freeze({
createMesh() {
throw new Error('Navara meshes need the view runtime');
},
list: () => [],
});
const STUB_GROUND = Object.freeze({
createPulseField() {
throw new Error('Navara ground needs the view runtime');
},
createSet() {
throw new Error("Navara ground needs the view's three runtime (ground/)");
},
list: () => [],
});
const STUB_IMAGERY = Object.freeze({
createLayer() {
throw new Error("Navara imagery needs the view's three runtime (imagery/)");
},
list: () => [],
setSplitPosition() {},
splitPosition: () => 0.5,
surface: () => 'globe',
});
const ports = {
movers: { movers: STUB_MOVERS, destroy() {} },
lines: { lines: STUB_LINES, destroy() {} },
ground: { ground: STUB_GROUND, destroy() {} },
imagery: () => ({ imagery: STUB_IMAGERY, destroy() {} }),
meshes: () => ({ meshes: STUB_MESHES, destroy() {} }),
};
const setup = () => {
const view = fakeView();
const engine = createNavaraEngine(view, { ...ports, hooks });
return { view, engine };
};
// Cesium's CameraFlightPath turns the camera inputs off for the flight, so a
// gesture never cancels it; layers/infrastructure suspends the inputs for the
// same reason ("Camera input would cancel the flight").
test('a wheel during a flight with the camera inputs suspended does not cancel it', async () => {
const { engine, view } = setup();
const outcome = [];
const restore = engine.input.suspendCameraInputs();
engine.camera.flyTo({
destination: cartesian3.fromDegrees(100, 0, 5e6),
duration: 1.5,
complete: () => outcome.push('complete'),
cancel: () => outcome.push('cancel'),
});
view.canvas.dispatchEvent(new Event('wheel'));
view.canvas.dispatchEvent(new Event('pointerdown'));
assert.deepEqual(outcome, [], 'the flight goes on');
assert.equal(engine.camera.flightActive(), true);
restore();
assert.equal(
engine.input.cameraInputsEnabled(),
false,
'the flight keeps its own suspension',
);
view.flights[0].resolve(true);
await Promise.resolve();
assert.deepEqual(outcome, ['complete']);
assert.equal(engine.input.cameraInputsEnabled(), true);
engine.destroy();
});
+58
View File
@@ -313,3 +313,61 @@ test('custom windows keep down synchronous, moves coalesced and clicks on one GP
);
destroy();
});
test('a pinch whose still finger lifts first is not a click', async () => {
const { canvas, input, destroy } = setup();
let clicks = 0;
input.on('click', () => clicks++);
const touch = (type, id, x, y) =>
pointer(type, x, y, {
pointerId: id,
pointerType: 'touch',
isPrimary: id === 1,
});
canvas.dispatchEvent(touch('pointerdown', 1, 100, 300));
canvas.dispatchEvent(touch('pointerdown', 2, 300, 300));
// Only the first finger moves (a one-sided pinch).
for (let i = 1; i <= 5; i++)
canvas.dispatchEvent(touch('pointermove', 1, 100 - 20 * i, 300));
canvas.dispatchEvent(touch('pointerup', 2, 300, 300));
canvas.dispatchEvent(touch('pointerup', 1, 0, 300));
await new Promise((resolve) => setTimeout(resolve, 50));
assert.equal(clicks, 0);
canvas.dispatchEvent(touch('pointerdown', 1, 100, 300));
canvas.dispatchEvent(touch('pointercancel', 1, 100, 300));
canvas.dispatchEvent(touch('pointerup', 1, 100, 300));
await Promise.resolve();
assert.equal(clicks, 0, 'a cancelled pointer cannot click');
canvas.dispatchEvent(touch('pointerdown', 1, 100, 300));
canvas.dispatchEvent(touch('pointerup', 1, 100, 300));
await Promise.resolve();
assert.equal(clicks, 1, 'the next single tap still clicks');
destroy();
});
test('a mouse released off the canvas does not hold back the next tap', async () => {
const { canvas, input, destroy } = setup();
let clicks = 0;
input.on('click', () => clicks++);
// The mouse goes down on the globe and up outside it.
canvas.dispatchEvent(
pointer('pointerdown', 100, 300, { pointerId: 1, isPrimary: true }),
);
canvas.dispatchEvent(
pointer('pointerdown', 100, 300, {
pointerId: 7,
pointerType: 'touch',
isPrimary: true,
}),
);
canvas.dispatchEvent(
pointer('pointerup', 100, 300, {
pointerId: 7,
pointerType: 'touch',
isPrimary: true,
}),
);
await Promise.resolve();
assert.equal(clicks, 1);
destroy();
});
-104
View File
@@ -1,104 +0,0 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { createNavaraInput } from './input.js';
function fakeCanvas() {
const canvas = new EventTarget();
canvas.getBoundingClientRect = () => ({ left: 100, top: 50 });
canvas.listenerCount = 0;
const add = canvas.addEventListener.bind(canvas);
const remove = canvas.removeEventListener.bind(canvas);
canvas.addEventListener = (...args) => {
canvas.listenerCount++;
add(...args);
};
canvas.removeEventListener = (...args) => {
canvas.listenerCount--;
remove(...args);
};
return canvas;
}
const pointer = (type, x, y, extra = {}) =>
Object.assign(new Event(type), {
clientX: x,
clientY: y,
button: 0,
shiftKey: false,
ctrlKey: false,
altKey: false,
...extra,
});
function setup() {
const canvas = fakeCanvas();
const cameraOptions = [];
const view = {
canvas,
camera: {
set options(value) {
cameraOptions.push(value);
},
},
};
const { input, destroy } = createNavaraInput(view);
return { canvas, input, destroy, cameraOptions };
}
test('a pinch whose still finger lifts first is not a click', async () => {
const { canvas, input, destroy } = setup();
let clicks = 0;
input.on('click', () => clicks++);
const touch = (type, id, x, y) =>
pointer(type, x, y, {
pointerId: id,
pointerType: 'touch',
isPrimary: id === 1,
});
canvas.dispatchEvent(touch('pointerdown', 1, 100, 300));
canvas.dispatchEvent(touch('pointerdown', 2, 300, 300));
// Only the first finger moves (a one-sided pinch).
for (let i = 1; i <= 5; i++)
canvas.dispatchEvent(touch('pointermove', 1, 100 - 20 * i, 300));
canvas.dispatchEvent(touch('pointerup', 2, 300, 300));
canvas.dispatchEvent(touch('pointerup', 1, 0, 300));
await new Promise((resolve) => setTimeout(resolve, 50));
assert.equal(clicks, 0);
canvas.dispatchEvent(touch('pointerdown', 1, 100, 300));
canvas.dispatchEvent(touch('pointercancel', 1, 100, 300));
canvas.dispatchEvent(touch('pointerup', 1, 100, 300));
await Promise.resolve();
assert.equal(clicks, 0, 'a cancelled pointer cannot click');
canvas.dispatchEvent(touch('pointerdown', 1, 100, 300));
canvas.dispatchEvent(touch('pointerup', 1, 100, 300));
await Promise.resolve();
assert.equal(clicks, 1, 'the next single tap still clicks');
destroy();
});
test('a mouse released off the canvas does not hold back the next tap', async () => {
const { canvas, input, destroy } = setup();
let clicks = 0;
input.on('click', () => clicks++);
// The mouse goes down on the globe and up outside it.
canvas.dispatchEvent(
pointer('pointerdown', 100, 300, { pointerId: 1, isPrimary: true }),
);
canvas.dispatchEvent(
pointer('pointerdown', 100, 300, {
pointerId: 7,
pointerType: 'touch',
isPrimary: true,
}),
);
canvas.dispatchEvent(
pointer('pointerup', 100, 300, {
pointerId: 7,
pointerType: 'touch',
isPrimary: true,
}),
);
await Promise.resolve();
assert.equal(clicks, 1);
destroy();
});
+38
View File
@@ -238,3 +238,41 @@ test('ordinary overlays keep the direct pass without a display copy or target',
assert.equal(h.renderer.autoClear, true);
h.pass.dispose();
});
test('static sprite glyphs are drawn again when the Cyber sonar moves', () => {
const h = harness(),
input = { width: 1280, height: 800, texture: {} },
output = {},
mesh = new InstancedMesh(
new PlaneGeometry(1, 1),
new MeshBasicMaterial({ map: new Texture() }),
1,
);
Object.assign(h.overlay.uniforms, {
uGevSonar: { value: [0, 1, 0.84, 1] },
uGevSonarSector: { value: 24 },
uGevSonarEnabled: { value: 1 },
});
mesh.userData.gevStaticSprite = true;
mesh.count = 1;
h.scene.add(mesh);
h.setActive(true);
h.pass.render(h.renderer, input, output);
const drawn = () => h.draws.filter((draw) => draw.object === h.scene).length;
assert.equal(drawn(), 1);
// The sweep turns (sonar.js writes the shared uniform each frame).
h.overlay.uniforms.uGevSonar.value[0] = 90;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 2, 'a new sonar angle draws the glyphs again');
h.overlay.uniforms.uGevSonarSector.value = 60;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 3, 'a new sector draws the glyphs again');
// The Cyber treatment is turned off.
h.overlay.uniforms.uGevSonarEnabled.value = 0;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 4, 'sonar off draws the glyphs again');
// Off, the angle still moves every frame; the glyphs stay cached.
h.overlay.uniforms.uGevSonar.value[0] = 180;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 4, 'the angle of an unused sonar draws nothing');
});
-110
View File
@@ -1,110 +0,0 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
Scene,
PerspectiveCamera,
HalfFloatType,
NoColorSpace,
SRGBColorSpace,
InstancedMesh,
MeshBasicMaterial,
PlaneGeometry,
Texture,
} from 'three';
import { GevOverlayPass } from './overlayPass.js';
function harness() {
let active = false,
target = null,
clearColor = 0x123456,
clearAlpha = 1;
const overlay = {
displayBlend: true,
hasDrawables: () => active,
uniforms: {
uGevResolution: { value: [0, 0] },
uGevDisplayBlend: { value: 0 },
uGevSonar: { value: [0, 1, 0.84, 1] },
uGevSonarSector: { value: 24 },
uGevSonarEnabled: { value: 1 },
},
};
const scene = new Scene(),
pass = new GevOverlayPass(scene, new PerspectiveCamera(), overlay),
draws = [];
const renderer = {
domElement: new EventTarget(),
autoClear: true,
outputColorSpace: SRGBColorSpace,
getPixelRatio: () => 1,
getClearColor(color) {
return color.set(clearColor);
},
getClearAlpha() {
return clearAlpha;
},
setClearColor(color, alpha) {
clearColor = color.isColor ? color.getHex() : color;
clearAlpha = alpha;
},
clear() {},
get clearAlpha() {
return clearAlpha;
},
setRenderTarget(value) {
target = value;
},
render(object) {
draws.push({
object,
target,
displayBlend: overlay.uniforms.uGevDisplayBlend.value,
});
},
};
return {
overlay,
scene,
pass,
draws,
renderer,
setActive(value) {
active = value;
},
get target() {
return target;
},
};
}
test('static sprite glyphs are drawn again when the Cyber sonar moves', () => {
const h = harness(),
input = { width: 1280, height: 800, texture: {} },
output = {},
mesh = new InstancedMesh(
new PlaneGeometry(1, 1),
new MeshBasicMaterial({ map: new Texture() }),
1,
);
mesh.userData.gevStaticSprite = true;
mesh.count = 1;
h.scene.add(mesh);
h.setActive(true);
h.pass.render(h.renderer, input, output);
const drawn = () => h.draws.filter((draw) => draw.object === h.scene).length;
assert.equal(drawn(), 1);
// The sweep turns (sonar.js writes the shared uniform each frame).
h.overlay.uniforms.uGevSonar.value[0] = 90;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 2, 'a new sonar angle draws the glyphs again');
h.overlay.uniforms.uGevSonarSector.value = 60;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 3, 'a new sector draws the glyphs again');
// The Cyber treatment is turned off.
h.overlay.uniforms.uGevSonarEnabled.value = 0;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 4, 'sonar off draws the glyphs again');
// Off, the angle still moves every frame; the glyphs stay cached.
h.overlay.uniforms.uGevSonar.value[0] = 180;
h.pass.render(h.renderer, input, output);
assert.equal(drawn(), 4, 'the angle of an unused sonar draws nothing');
});