mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
feat(globe): instanced movers on both engines
engine.movers.createSet({ id, kind: sprite|point|model, capacity, order,
depthTest, sprite|point|model, pickable }) → a MoverSet: set(index,
fields) stores an instance (position, screen rotation, orientation, rgba,
scale, atlas cell, show, pickId) in flat arrays, commit() uploads the
changed range once and requests one render, positionsView() reads the
positions, destroy() removes it; movers.list() for QA. The options, the
store and the registry are engine-neutral (src/globe/movers.js); the fake
engine keeps them for layer tests.
- Cesium: one primitive per set in an engine-owned PrimitiveCollection
added with the first set, in `order`: sprites a BillboardCollection
(one image per atlas cell, NearFarScalar, disableDepthTestDistance),
points a PointPrimitiveCollection, models a Model per instance.
- Navara: a public MeshDesc per set. Sprites and points are one
InstancedMesh of a quad, faced to the screen and sized in CSS pixels in
the vertex shader from uniforms (the pick pass draws the same
footprint), atlas uv, rotation, colour and scale per instance, drawn in
the transparent pass unlit; offsets from an origin that follows the
camera past max(1 km, 10 % of its height). Models: the glTF once, one
InstancedMesh per mesh, minimumPixelSize/maximumScale on the CPU per
drawn frame, colorBlend in the shader. Pickable sets register a
PickableInstancedMeshWrapper; pickIds.js maps batch ids back to
instances (used by Task 4).
- The contract suite draws three 24 px sprites on both engines: centred
within 2 px of worldToWindow, hidden by show:false, recoloured, gone on
destroy, and no frames added once the commit has drawn.
- qa-engine-bench --scenario=movers: 10 000 synthetic aircraft
(src/bench/syntheticFlights.js, moved from the Navara spike with its
test), every instance moved and committed every frame. p95 Navara
(look=minimal) / Cesium: global 5.2/7.0 ms, city 5.6/9.9, orbit 6.0/7.4
(0.74, 0.57, 0.81; gate 1.1). Cesium is measured without its 60 fps cap.
Main chunk 2,860,302 bytes (+9,706, +0.34 %: the Cesium movers).
This commit is contained in:
1 parent
4623c8b616
commit
0109097440
24 files changed
+2735
-3
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
BoxGeometry,
|
||||
Group,
|
||||
Matrix4,
|
||||
Mesh,
|
||||
MeshStandardMaterial,
|
||||
Vector3,
|
||||
} from 'three';
|
||||
import { createMoverStore, normalizeMoverSetOptions } from '../../movers.js';
|
||||
import { createModelMover } from './modelMover.js';
|
||||
|
||||
const options = normalizeMoverSetOptions({
|
||||
id: 'm',
|
||||
kind: 'model',
|
||||
capacity: 2,
|
||||
model: {
|
||||
url: '/models/box.glb',
|
||||
minimumPixelSize: 40,
|
||||
colorBlend: { mode: 'mix', amount: 0.3 },
|
||||
},
|
||||
});
|
||||
|
||||
function fakeGltf() {
|
||||
const scene = new Group();
|
||||
const box = new Mesh(new BoxGeometry(2, 2, 2), new MeshStandardMaterial());
|
||||
box.position.set(0, 1, 0);
|
||||
scene.add(box);
|
||||
return { scene };
|
||||
}
|
||||
|
||||
test('instances share the model meshes, placed from the origin', async () => {
|
||||
const store = createMoverStore(options);
|
||||
const mover = createModelMover(options, store, {
|
||||
load: async () => fakeGltf(),
|
||||
});
|
||||
store.set(0, { position: { x: 6_378_137, y: 0, z: 0 } });
|
||||
store.set(1, {
|
||||
position: { x: 6_378_147, y: 0, z: 0 },
|
||||
orientation: { x: 0, y: 0, z: Math.SQRT1_2, w: Math.SQRT1_2 },
|
||||
color: [1, 0, 0, 1],
|
||||
});
|
||||
store.setCount(2);
|
||||
mover.commit(store.dirty());
|
||||
await mover.group.ready;
|
||||
const [mesh] = mover.group.meshes;
|
||||
assert.equal(mesh.count, 2);
|
||||
assert.equal(mesh.position.x, 6_378_137);
|
||||
assert.equal(mover.uniforms.uGevBlend.value, 0.3);
|
||||
const matrix = new Matrix4();
|
||||
mesh.getMatrixAt(1, matrix);
|
||||
const translation = new Vector3().setFromMatrixPosition(matrix);
|
||||
// Offset 10 m east of the origin plus the box's local +1 y turned 90° about z.
|
||||
assert.ok(Math.abs(translation.x - 9) < 1e-9, translation.x);
|
||||
assert.ok(Math.abs(translation.y) < 1e-9);
|
||||
const color = mesh.geometry.getAttribute('gevColor');
|
||||
assert.deepEqual([...color.array.subarray(4, 8)], [1, 0, 0, 1]);
|
||||
});
|
||||
|
||||
test('a far model keeps its minimum pixel size', async () => {
|
||||
const store = createMoverStore(options);
|
||||
const mover = createModelMover(options, store, {
|
||||
load: async () => fakeGltf(),
|
||||
});
|
||||
store.set(0, { position: { x: 6_378_137, y: 0, z: 0 } });
|
||||
store.setCount(1);
|
||||
mover.commit(store.dirty());
|
||||
await mover.group.ready;
|
||||
mover.update({
|
||||
cameraPosition: { x: 6_378_137 + 100_000, y: 0, z: 0 },
|
||||
cameraHeight: 100_000,
|
||||
fovDeg: 60,
|
||||
viewportHeightPx: 800,
|
||||
});
|
||||
const matrix = new Matrix4();
|
||||
mover.group.meshes[0].getMatrixAt(0, matrix);
|
||||
const scale = new Vector3().setFromMatrixScale(matrix).x;
|
||||
// Box radius √3; 40 px at 100 km with a 60° fov over 800 px.
|
||||
const footprint = (2 * Math.tan(Math.PI / 6)) / 800;
|
||||
const expected = (40 * footprint * 100_000) / (2 * Math.sqrt(3));
|
||||
assert.ok(
|
||||
Math.abs(scale - expected) / expected < 1e-6,
|
||||
`${scale} vs ${expected}`,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user