mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 18:52:18 +00:00
Draw CCTV and data packs through engine.meshes
Add indexed world triangles to the required globe contract on Cesium, Navara and the fake engine. Own geometry, textures, visibility, depth tests, pick identities and teardown inside each engine. Reused canvas images request another frame until their new pixels upload. Move obstruction rays and owned mesh, line and mover exclusions into the Cesium surface adapter. Draw CCTV monitor planes and viewshed volumes through shared mesh handles. Draw data-pack points, straight lines, raised polygons, image rectangles and media captions through movers, lines and meshes. Delete the feature renderers for each engine and retain decoded assets across scene rebinds. Register the modules, dependency, format scope and reduced coupling baseline. Cesium is the reference for geometry, colours, image placement, marker sizes, caption offsets, picking and resource ownership. Navara now uses straight pack lines and per-position polygon heights without edge densification. Navara meshes draw in the transparent pass after the effects, with the scene-depth test and the view's exposure undone, as the pack meshes did: in the scene pass the landscape look's exposure washed a red pack image to white. The scene-depth helper moves into the Navara engine, and the stems helper that only its test still used is deleted. The mesh picker takes the globe when Navara's depth read answers with the camera itself, which it does right after another click and which hid a polygon from a quick second click. The 256 px media caption is not pickable: its transparent square took clicks meant for nearby pack features, and no action targets it. Annotation drapes remain on their existing renderers because bounded building classification, animated fills and wire cages need a separate contract extension to preserve Cesium behaviour. Coupling falls from 344 to 210 Cesium layer-renderer lines, 1294 to 794 Navara layer-renderer lines, 9 to 7 external Cesium import files, 1026 to 1005 viewer lines, 9 to 6 extension reads and 42 to 39 engine-name lines. Other counts do not grow. The full unit suite, import directions, package boundaries, formatting and coupling checks pass. No user-visible strings change. In the browser, keyless: the contract suite passes on Navara and on Cesium apart from the camera-events check that also fails intermittently before this change; CCTV v2 (58 checks), the CCTV and director engine switches pass, with the pack image at the same pixel as before on both engines. The mesh contract fixture now sits at 3 km, above the terrain Navara draws there. The director interactions script starts at its view in the link so the app's arrival flight no longer lands after the shot, and waits for the click's asynchronous pick; its last step, the next-shot action, fails the same way before this change.
This commit is contained in:
1 parent
3907b7084e
commit
f4b83a3a31
57 files changed
+1891
-1588
No files matched your search
@@ -0,0 +1,161 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
BasicDepthPacking,
|
||||
DataTexture,
|
||||
MeshBasicMaterial,
|
||||
RGBADepthPacking,
|
||||
ShaderLib,
|
||||
} from 'three';
|
||||
import {
|
||||
SCENE_DEPTH_BIAS,
|
||||
createSceneDepthTest,
|
||||
withSceneDepthTest,
|
||||
} from './sceneDepth.js';
|
||||
import { createPackRenderer } from '../../scenes/dataPacks/display.js';
|
||||
import { createNavaraMeshes } from './meshes.js';
|
||||
|
||||
const count = (text, part) => text.split(part).length - 1;
|
||||
|
||||
test('the scene-depth test goes after the log depth and brings packing once', () => {
|
||||
for (const source of [
|
||||
ShaderLib.basic.fragmentShader,
|
||||
'#include <common>\n#include <packing>\nvoid main() {\n#include <logdepthbuf_fragment>\n}',
|
||||
]) {
|
||||
const patched = withSceneDepthTest(source);
|
||||
assert.equal(count(patched, '#include <packing>'), 1);
|
||||
assert.equal(count(patched, 'uniform sampler2D tGevSceneDepth;'), 1);
|
||||
const depth = patched.indexOf('#include <logdepthbuf_fragment>');
|
||||
const test = patched.indexOf('if (uGevSceneDepthOn > 0.5)');
|
||||
assert.ok(depth >= 0 && test > depth, 'tested after gl_FragDepth is set');
|
||||
assert.ok(
|
||||
patched.indexOf('uniform float uGevSceneDepthOn;') <
|
||||
patched.indexOf('void main() {'),
|
||||
);
|
||||
assert.match(patched, /gevDepth > gevScene \+ 5e-6\)\s*discard;/);
|
||||
}
|
||||
assert.ok(SCENE_DEPTH_BIAS > 0 && SCENE_DEPTH_BIAS < 1e-4);
|
||||
assert.throws(() => withSceneDepthTest('void main() {}'), /logdepthbuf/);
|
||||
});
|
||||
|
||||
test('the test binds the MRT pass packed depth before each draw, and only packed RGBA depth', () => {
|
||||
const depth = createSceneDepthTest();
|
||||
const material = depth.material(new MeshBasicMaterial());
|
||||
const shader = {
|
||||
uniforms: {},
|
||||
vertexShader: ShaderLib.basic.vertexShader,
|
||||
fragmentShader: ShaderLib.basic.fragmentShader,
|
||||
};
|
||||
material.onBeforeCompile(shader, null);
|
||||
assert.match(material.customProgramCacheKey(), /_gevSceneDepth$/);
|
||||
assert.equal(shader.uniforms.tGevSceneDepth, depth.uniforms.tGevSceneDepth);
|
||||
assert.match(shader.fragmentShader, /discard;/);
|
||||
|
||||
const drawn = [];
|
||||
const object = depth.object({
|
||||
userData: {},
|
||||
onBeforeRender: (renderer) => drawn.push(renderer),
|
||||
});
|
||||
const texture = new DataTexture();
|
||||
const mrt = { depthBuffer: texture, depthBufferPacking: RGBADepthPacking };
|
||||
const renderer = { getRenderTarget: () => ({ width: 640, height: 360 }) };
|
||||
// Before the descriptor attaches its context the test stays off.
|
||||
object.onBeforeRender(renderer);
|
||||
assert.equal(depth.uniforms.uGevSceneDepthOn.value, 0);
|
||||
depth.attach({ findEffect: (key) => (key === 'mrt' ? mrt : undefined) });
|
||||
object.onBeforeRender(renderer);
|
||||
assert.equal(depth.uniforms.tGevSceneDepth.value, texture);
|
||||
assert.equal(depth.uniforms.uGevSceneDepthOn.value, 1);
|
||||
assert.deepEqual(depth.uniforms.uGevTargetSize.value.toArray(), [640, 360]);
|
||||
assert.deepEqual(drawn, [renderer, renderer], 'the mesh hook still runs');
|
||||
// Another packing would be read wrong: the mesh draws as before.
|
||||
mrt.depthBufferPacking = BasicDepthPacking;
|
||||
object.onBeforeRender(renderer);
|
||||
assert.equal(depth.uniforms.uGevSceneDepthOn.value, 0);
|
||||
assert.equal(depth.uniforms.tGevSceneDepth.value, null);
|
||||
});
|
||||
|
||||
/** A Navara view that builds each descriptor as the SDK does. */
|
||||
function fakeView() {
|
||||
const kinds = new Map();
|
||||
const created = [];
|
||||
const mrt = {
|
||||
depthBuffer: new DataTexture(),
|
||||
depthBufferPacking: RGBADepthPacking,
|
||||
};
|
||||
const ctx = { findEffect: (key) => (key === 'mrt' ? mrt : undefined) };
|
||||
class MeshDesc {
|
||||
constructor(view, context, config) {
|
||||
this.ctx = context;
|
||||
this.config = config;
|
||||
}
|
||||
onDestroy() {}
|
||||
}
|
||||
const view = {
|
||||
forceUpdate() {},
|
||||
registerMesh: (kind, desc) => kinds.set(kind, desc),
|
||||
addMesh(config) {
|
||||
const kind = Object.keys(config)[0];
|
||||
const desc = new (kinds.get(kind))(view, ctx, config);
|
||||
const object = desc.createMesh();
|
||||
created.push({ kind, pass: desc.getPassKey(), object });
|
||||
return { delete: () => desc.onDestroy() };
|
||||
},
|
||||
};
|
||||
return { view, MeshDesc, created, mrt };
|
||||
}
|
||||
|
||||
/** Every renderable under an object compiles with the test and binds depth. */
|
||||
function assertTested(object, mrt) {
|
||||
const renderables = [];
|
||||
object.traverse?.((child) => {
|
||||
if (child.material) renderables.push(child);
|
||||
});
|
||||
if (!object.traverse && object.material) renderables.push(object);
|
||||
assert.ok(renderables.length > 0);
|
||||
for (const child of renderables) {
|
||||
const shader = {
|
||||
uniforms: { ...(child.material.uniforms ?? {}) },
|
||||
vertexShader: '',
|
||||
fragmentShader:
|
||||
child.material.fragmentShader ?? ShaderLib.basic.fragmentShader,
|
||||
};
|
||||
child.material.onBeforeCompile(shader, null);
|
||||
assert.match(shader.fragmentShader, /if \(uGevSceneDepthOn > 0\.5\)/);
|
||||
assert.ok(shader.uniforms.tGevSceneDepth);
|
||||
child.onBeforeRender(
|
||||
{
|
||||
getRenderTarget: () => ({ width: 8, height: 8 }),
|
||||
getViewport: (target) => target.set(0, 0, 8, 8),
|
||||
},
|
||||
null,
|
||||
null,
|
||||
child.geometry,
|
||||
child.material,
|
||||
);
|
||||
assert.equal(shader.uniforms.tGevSceneDepth.value, mrt.depthBuffer);
|
||||
assert.equal(shader.uniforms.uGevSceneDepthOn.value, 1);
|
||||
}
|
||||
}
|
||||
|
||||
test('pack meshes stay transparent and test the scene depth', () => {
|
||||
const packs = fakeView();
|
||||
const owned = [];
|
||||
const port = createNavaraMeshes(packs.view, {
|
||||
MeshDesc: packs.MeshDesc,
|
||||
camera: {},
|
||||
picker: { registerMeshPicker: () => () => {} },
|
||||
});
|
||||
const engine = { meshes: port.meshes, render: { request() {} } };
|
||||
createPackRenderer(engine).image(
|
||||
{ id: 'p', placement: { bounds: [0, 0, 0.01, 0.01], height: 300 } },
|
||||
{},
|
||||
{ own: (fn) => owned.push(fn) },
|
||||
);
|
||||
assert.equal(packs.created.length, 1);
|
||||
assert.equal(packs.created[0].pass, 'transparent');
|
||||
assertTested(packs.created[0].object, packs.mrt);
|
||||
assert.equal(packs.created[0].object.children[0].material.depthTest, true);
|
||||
for (const release of owned) release();
|
||||
port.destroy();
|
||||
});
|
||||
Reference in new issue
Block a user