fix(navara): batch contours and order ground overlays

Batch consecutive disjoint installation outlines to avoid three stencil draws
per feature. Preserve overlapping volumes, material order and local precision.
Delete the public effect handle correctly during teardown.

Keep imagery below ground classifications and glyphs in every activation order,
including minimal mode without tone mapping. Exclude fully offscreen ground
volumes from the screen candidate grid.

Full unit/allocation, boundaries, formatting and keyless builds pass. Browser
checks cover contour coverage, bounded colour differences, a missing-contour
negative control, real pass order, sprite alpha and FIRMS glows. Whole-wave
performance acceptance remains separate from this implementation checkpoint.
This commit is contained in:
German Khokhlov committed 2026-10-29 20:27:24 +04:00
1 parent 9ba5a3aba9
commit 8328aab779
12 files changed
+320 -31

No files matched your search

+22 -20
View File
@@ -11,6 +11,7 @@ import {
createInstallationDrapedMesh,
createInstallationOutlineDrapedMesh,
} from './navaraGeometry.js';
import { batchInstallationOutlines } from './navaraOutlineBatch.js';
const registeredViews = new WeakSet();
const KEY = 'gevInstallationsDrape';
@@ -131,7 +132,9 @@ export function createInstallationsNavaraRenderer(
const contextObjects = new Map();
const namedRecords = new Map();
const selectionMeshes = new Set();
const outlinesById = new Map();
const outlineMeshes = new Set();
let outlineRecords = [],
outlineWidthM = null;
let drapeHandle = null;
let visible = false;
let fillRecord = null;
@@ -228,18 +231,17 @@ export function createInstallationsNavaraRenderer(
1,
(2 * cameraHeight * Math.tan(fov / 2) * 2) / canvasHeight,
);
const desired = new Map(
records
.filter((record) => !record.pointOnly && !record.namedArea)
.map((record) => [record.id, record]),
const desired = records.filter(
(record) => !record.pointOnly && !record.namedArea,
);
for (const [id, entry] of outlinesById) {
if (desired.get(id) === entry.record && entry.widthM === widthM) continue;
replaceOwnedMeshes(entry.meshes, []);
outlinesById.delete(id);
}
for (const [id, record] of desired) {
if (outlinesById.has(id)) continue;
if (
outlineWidthM === widthM &&
desired.length === outlineRecords.length &&
desired.every((record, index) => record === outlineRecords[index])
)
return;
const next = [];
for (const record of desired) {
const lines =
record.outlineLines || (record.footprint ? [record.footprint] : []);
const meshes = lines
@@ -254,17 +256,17 @@ export function createInstallationsNavaraRenderer(
}),
)
.filter(Boolean);
const owned = new Set(meshes);
for (const mesh of owned) owner.meshes.add(mesh);
outlinesById.set(id, { record, widthM, meshes: owned });
next.push(...meshes);
}
syncDrapeEffect();
replaceOwnedMeshes(outlineMeshes, batchInstallationOutlines(next));
outlineRecords = desired;
outlineWidthM = widthM;
}
function clearOutlines() {
for (const entry of outlinesById.values())
replaceOwnedMeshes(entry.meshes, []);
outlinesById.clear();
replaceOwnedMeshes(outlineMeshes, []);
outlineRecords = [];
outlineWidthM = null;
}
function registerContext(record) {
@@ -643,7 +645,7 @@ export function createInstallationsNavaraRenderer(
selection.destroy();
rendering.clearRendered();
namedMarkers.destroy();
drapeHandle?.destroy();
drapeHandle?.delete();
drapeHandle = null;
normalSet.destroy();
selectedSet.destroy();
@@ -42,6 +42,7 @@ test('selected installation fill is reused and removed with its scene resources'
};
},
removeEntityContextsForLayer() {},
clearSelectedEntityContextForLayer() {},
},
picking: { registerPickOwner() {}, unregisterPickOwner() {} },
};
@@ -64,13 +65,19 @@ test('selected installation fill is reused and removed with its scene resources'
render: { request() {} },
};
let effectConfig;
let deletedEffects = 0;
const view = {
canvas: { clientHeight: 800 },
camera: { raw: { fov: 60 } },
registerEffect() {},
addEffect(config) {
effectConfig = config;
return { update() {}, destroy() {} };
return {
update() {},
delete() {
deletedEffects++;
},
};
},
};
let meshCount = 0;
@@ -88,6 +95,8 @@ test('selected installation fill is reused and removed with its scene resources'
installationSourceLabel: () => 'OpenStreetMap',
},
namedMarkers: { sync() {}, enable() {}, hide() {}, destroy() {} },
viewport: { clearUnavailableRetry() {} },
ingestion: { setInstallationStatus() {} },
};
const renderer = createInstallationsNavaraRenderer(engine, {
state,
@@ -144,4 +153,7 @@ test('selected installation fill is reused and removed with its scene resources'
'clearing selection preserves the ordinary outline',
);
assert.equal(sets.length, 3);
renderer.lifecycle.methods.destroy();
assert.equal(deletedEffects, 1, 'destroy deletes the public effect handle');
assert.equal(effectConfig.gevInstallationsDrape.owner.meshes.size, 0);
});
@@ -0,0 +1,63 @@
import { Matrix4 } from 'three';
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
// Each DrapedMesh needs three stencil draws. Consecutive, equally coloured
// volumes with disjoint XY bounds can share those draws without changing
// translucent overlap order. Keep coordinates local to preserve precision.
// Consumes the input meshes; the returned meshes own the surviving resources.
export function batchInstallationOutlines(meshes) {
const groups = [];
for (const mesh of meshes) {
const group = groups.at(-1);
let geometry;
if (
group &&
mesh.material.color.equals(group.mesh.material.color) &&
mesh.material.opacity === group.mesh.material.opacity
) {
const relative = new Matrix4().multiplyMatrices(
group.inverse,
mesh.matrix,
);
if (Math.hypot(...relative.elements.slice(12, 15)) <= 100_000) {
geometry = mesh.geometry.clone().applyMatrix4(relative);
geometry.computeBoundingBox();
const b = geometry.boundingBox;
if (
group.bounds.every(
(a) =>
b.min.x > a.max.x ||
b.max.x < a.min.x ||
b.min.y > a.max.y ||
b.max.y < a.min.y,
)
) {
group.geometries.push(geometry);
group.bounds.push(b);
group.mesh.userData.installationIds.push(
mesh.userData.installationId,
);
mesh.geometry.dispose();
mesh.material.dispose();
continue;
}
geometry.dispose();
}
}
mesh.geometry.computeBoundingBox();
mesh.userData.installationIds = [mesh.userData.installationId];
groups.push({
mesh,
inverse: mesh.matrix.clone().invert(),
geometries: [mesh.geometry],
bounds: [mesh.geometry.boundingBox],
});
}
return groups.map(({ mesh, geometries }) => {
if (geometries.length > 1) {
mesh.geometry = mergeGeometries(geometries);
for (const geometry of geometries) geometry.dispose();
}
return mesh;
});
}
@@ -0,0 +1,97 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { BoxGeometry, Mesh, MeshBasicMaterial, Vector3 } from 'three';
import { batchInstallationOutlines } from './navaraOutlineBatch.js';
function volume(id, x, { color = '#ff8800', opacity = 0.85, y = 0 } = {}) {
const mesh = new Mesh(
new BoxGeometry(10, 10, 40000),
new MeshBasicMaterial({ color, opacity }),
);
mesh.matrix.makeTranslation(x, y, 0);
mesh.userData.installationId = id;
return mesh;
}
test('disjoint equal-colour outlines share a stencil volume without moving their vertices', () => {
const meshes = [
volume('a', 6_000_000),
volume('b', 6_000_100),
volume('c', 6_000_200),
];
const positions = meshes.flatMap((m) => {
const a = m.geometry.attributes.position;
return Array.from({ length: a.count }, (_, i) =>
new Vector3().fromBufferAttribute(a, i).applyMatrix4(m.matrix),
);
});
const geometryDisposals = [],
materialDisposals = [];
for (const m of meshes) {
m.geometry.addEventListener('dispose', () =>
geometryDisposals.push(m.userData.installationId),
);
m.material.addEventListener('dispose', () =>
materialDisposals.push(m.userData.installationId),
);
}
const result = batchInstallationOutlines(meshes);
assert.equal(result.length, 1);
assert.deepEqual(result[0].userData.installationIds, ['a', 'b', 'c']);
const a = result[0].geometry.attributes.position;
assert.equal(a.count, positions.length);
for (let i = 0; i < a.count; i++)
assert.ok(
new Vector3()
.fromBufferAttribute(a, i)
.applyMatrix4(result[0].matrix)
.distanceTo(positions[i]) < 1e-5,
);
assert.deepEqual(geometryDisposals.sort(), ['a', 'b', 'c']);
assert.deepEqual(materialDisposals.sort(), ['b', 'c']);
result[0].geometry.dispose();
result[0].material.dispose();
assert.deepEqual(materialDisposals.sort(), ['a', 'b', 'c']);
});
test('overlapping volumes, different materials and distant origins retain separate draws and order', () => {
for (const second of [
volume('b', 5),
volume('b', 100, { color: '#00ff00' }),
volume('b', 100, { opacity: 0.5 }),
volume('b', 100_001),
]) {
const first = volume('a', 0),
result = batchInstallationOutlines([first, second]);
assert.deepEqual(result, [first, second]);
for (const mesh of result) {
mesh.geometry.dispose();
mesh.material.dispose();
}
}
const meshes = [
volume('a', 0),
volume('b', 100, { color: '#00ff00' }),
volume('c', 200),
];
assert.deepEqual(batchInstallationOutlines(meshes), meshes);
for (const mesh of meshes) {
mesh.geometry.dispose();
mesh.material.dispose();
}
});
test('batch admission compares against every prior volume, including rotated bounds', () => {
const meshes = [volume('a', 0), volume('b', 100), volume('c', 0)];
meshes[2].matrix.makeRotationZ(Math.PI / 4);
const result = batchInstallationOutlines(meshes);
assert.equal(result.length, 2);
assert.deepEqual(
result.map((m) => m.userData.installationIds),
[['a', 'b'], ['c']],
);
for (const mesh of result) {
mesh.geometry.dispose();
mesh.material.dispose();
}
});