mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
engine.ground draws sets of polygons (with holes), discs, cells and
corridors draped on the surface, with fill and outline colours, order and
picks, written in bulk and committed. Every engine implements it:
- Cesium batches each set into one GroundPrimitive for fills and one
GroundPolylinePrimitive for outlines and pixel corridors, classified
against terrain and 3D tiles; sets that are not pickable stay out of the
pick pass.
- Navara draws them in one screen pass after tone mapping that finds each
pixel's ground from the scene depth and tests the items in its screen
cell; long rings are split into edge bins. Measured at Dubai against
SDK vector layers, the pass matched Cesium's frame time up to 10,000
polygons with a few megabytes instead of 70 to 146, drew exact colours
and outlines, and hid reliably across an engine switch, where vector
layers hidden with update({ show: false }) never hid. Dense corridors
remain its limit (10,000 cost 135 ms a frame).
- The fake engine keeps the same registry and CPU picks.
The contract suite checks it on both engines (Cesium 66/66, Navara 69/69).
Earthquakes and fire perimeters have unwired ground prototypes whose
drawing matches today's Cesium one (0.998 on Cesium, 0.976 on Navara).
docs/GLOBE-PRIMITIVES.md describes the primitives and when to use each.
160 lines
4.5 KiB
JavaScript
160 lines
4.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as Cesium from 'cesium';
|
|
import { normalizeGroundItem } from '../ground.js';
|
|
import { createCesiumGround, groundInstances } from './ground.js';
|
|
import { createFakeViewer } from './testing/fakeViewer.mjs';
|
|
|
|
const items = (kind, list) =>
|
|
list.map((item, index) => normalizeGroundItem(kind, item, index));
|
|
|
|
test('fills batch into GroundPrimitive instances, outlines into ground polylines', () => {
|
|
const options = { id: 'zones', kind: 'polygon' };
|
|
const { fills, lines } = groundInstances(
|
|
options,
|
|
items('polygon', [
|
|
{
|
|
rings: [
|
|
[
|
|
[0, 0],
|
|
[1, 0],
|
|
[1, 1],
|
|
],
|
|
[
|
|
[0.6, 0.2],
|
|
[0.8, 0.2],
|
|
[0.8, 0.4],
|
|
],
|
|
],
|
|
fill: [1, 0, 0, 0.5],
|
|
outline: { color: [1, 1, 1, 1], widthPx: 2 },
|
|
},
|
|
{
|
|
rings: [
|
|
[
|
|
[2, 0],
|
|
[3, 0],
|
|
[3, 1],
|
|
],
|
|
],
|
|
outline: { color: [0, 0, 1, 1], widthPx: 3 },
|
|
},
|
|
]),
|
|
);
|
|
assert.equal(fills.length, 1, 'an item without a fill adds none');
|
|
assert.ok(fills[0].geometry instanceof Cesium.PolygonGeometry);
|
|
assert.deepEqual(fills[0].id, { gevGroundSet: 'zones', instance: 0 });
|
|
assert.equal(lines.length, 3, 'one outline per ring');
|
|
assert.ok(lines[0].geometry instanceof Cesium.GroundPolylineGeometry);
|
|
assert.equal(lines[0].geometry.loop, true);
|
|
assert.equal(lines[0].geometry.width, 2);
|
|
assert.deepEqual(lines[2].id, { gevGroundSet: 'zones', instance: 1 });
|
|
const corridors = groundInstances(
|
|
{ id: 'roads', kind: 'corridor' },
|
|
items('corridor', [
|
|
{
|
|
positions: [
|
|
[0, 0],
|
|
[1, 0],
|
|
],
|
|
color: [1, 1, 1, 1],
|
|
widthPx: 4,
|
|
},
|
|
{
|
|
positions: [
|
|
[0, 1],
|
|
[1, 1],
|
|
],
|
|
color: [1, 1, 1, 1],
|
|
widthM: 30,
|
|
},
|
|
]),
|
|
);
|
|
assert.ok(corridors.fills[0].geometry instanceof Cesium.CorridorGeometry);
|
|
assert.equal(corridors.lines[0].geometry.width, 4);
|
|
const shapes = groundInstances(
|
|
{ id: 'shapes', kind: 'disc' },
|
|
items('disc', [{ center: [0, 0], radiusM: 500, fill: [1, 1, 1, 1] }]),
|
|
);
|
|
assert.ok(shapes.fills[0].geometry instanceof Cesium.EllipseGeometry);
|
|
});
|
|
|
|
test('sets join scene.groundPrimitives in order and rebuild on commit', () => {
|
|
const viewer = createFakeViewer();
|
|
const added = [];
|
|
viewer.scene.groundPrimitives = {
|
|
add: (value) => added.push(value),
|
|
remove: (value) => added.splice(added.indexOf(value), 1),
|
|
};
|
|
const made = [];
|
|
const fake = (type) => (options) => {
|
|
const primitive = {
|
|
type,
|
|
options,
|
|
ready: false,
|
|
destroy() {},
|
|
isDestroyed: () => false,
|
|
};
|
|
made.push(primitive);
|
|
return primitive;
|
|
};
|
|
const renders = [];
|
|
const part = createCesiumGround(viewer, {
|
|
requestRender: (reason) => renders.push(reason),
|
|
factories: { fills: fake('fills'), lines: fake('lines') },
|
|
});
|
|
const high = part.ground.createSet({ id: 'high', kind: 'cell', order: 2 });
|
|
const low = part.ground.createSet({
|
|
id: 'low',
|
|
kind: 'cell',
|
|
pickable: true,
|
|
drape: 'tiles',
|
|
});
|
|
assert.equal(added.length, 1, 'one engine collection');
|
|
const root = added[0];
|
|
low.replace([
|
|
{
|
|
west: 0,
|
|
south: 0,
|
|
east: 1,
|
|
north: 1,
|
|
fill: [1, 0, 0, 1],
|
|
outline: { color: [1, 1, 1, 1], widthPx: 2 },
|
|
pickId: 'cell-1',
|
|
},
|
|
]);
|
|
low.commit();
|
|
assert.equal(root.length, 2);
|
|
assert.equal(root.get(0).get(0), made[0], 'the lower order first');
|
|
assert.deepEqual(
|
|
made.map(({ type }) => type),
|
|
['fills', 'lines'],
|
|
);
|
|
const [fills] = made;
|
|
assert.equal(
|
|
fills.options.classificationType,
|
|
Cesium.ClassificationType.CESIUM_3D_TILE,
|
|
);
|
|
assert.equal(fills.options.allowPicking, true);
|
|
assert.equal(low.ready(), false, 'built in workers');
|
|
fills.ready = true;
|
|
made[1].ready = true;
|
|
assert.equal(low.ready(), true);
|
|
assert.deepEqual(
|
|
part.identify({ id: { gevGroundSet: 'low', instance: 0 } }),
|
|
{ owner: 'low', instance: 0, id: 'cell-1', pickable: true },
|
|
);
|
|
high.replace([
|
|
{ west: 0, south: 0, east: 1, north: 1, fill: [1, 1, 1, 1], pickId: 'x' },
|
|
]);
|
|
high.commit();
|
|
assert.equal(made.at(-1).options.allowPicking, false);
|
|
assert.equal(
|
|
part.identify({ id: { gevGroundSet: 'high', instance: 0 } }).pickable,
|
|
false,
|
|
);
|
|
assert.equal(part.identify({ id: 'entity' }), null);
|
|
part.destroy();
|
|
assert.equal(added.length, 0);
|
|
});
|