mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +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,111 @@
|
||||
// Pack polygons and image rectangles as indexed world triangles.
|
||||
import earcut from 'earcut';
|
||||
import * as geo from '../../geo/index.js';
|
||||
|
||||
// Cesium's default granularity: no edge or cell spans more than one degree.
|
||||
const GRANULARITY_DEGREES = 1;
|
||||
|
||||
function shape(positions, indices, st = null) {
|
||||
const center = geo.cartesian3.create();
|
||||
for (const p of positions) geo.cartesian3.add(center, p, center);
|
||||
geo.cartesian3.divideByScalar(center, positions.length || 1, center);
|
||||
const values = new Float64Array(positions.length * 3);
|
||||
positions.forEach((p, i) => values.set([p.x, p.y, p.z], i * 3));
|
||||
return {
|
||||
attributes: {
|
||||
position: { values },
|
||||
...(st ? { st: { values: st } } : {}),
|
||||
},
|
||||
indices: new Uint32Array(indices),
|
||||
boundingSphere: { center },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A filled polygon: `rings` are GeoJSON-style [lon, lat, height?] rings, the
|
||||
* first the outline and the rest holes, each vertex at its own height (as
|
||||
* Cesium's perPositionHeight). Triangulated in the plane tangent to the
|
||||
* Earth at the outline's centre; null when nothing is left to fill.
|
||||
*/
|
||||
export function polygonShape(rings) {
|
||||
const loops = rings
|
||||
.map((ring) => {
|
||||
const open =
|
||||
ring.length > 1 &&
|
||||
ring[0][0] === ring.at(-1)[0] &&
|
||||
ring[0][1] === ring.at(-1)[1]
|
||||
? ring.slice(0, -1)
|
||||
: ring;
|
||||
return open;
|
||||
})
|
||||
.filter((ring) => ring.length >= 3);
|
||||
if (!loops.length) return null;
|
||||
const [outline, ...holes] = loops;
|
||||
const points = loops.flat();
|
||||
const world = points.map(([lon, lat, h]) =>
|
||||
geo.cartesian3.fromDegrees(lon, lat, h),
|
||||
);
|
||||
const middle = geo.cartesian3.create();
|
||||
for (const p of world.slice(0, outline.length))
|
||||
geo.cartesian3.add(middle, p, middle);
|
||||
geo.cartesian3.divideByScalar(middle, outline.length, middle);
|
||||
const frame = geo.transforms.eastNorthUpToFixedFrame(middle);
|
||||
const east = geo.cartesian3.create(frame[0], frame[1], frame[2]);
|
||||
const north = geo.cartesian3.create(frame[4], frame[5], frame[6]);
|
||||
const offset = geo.cartesian3.create();
|
||||
const plane = world.map((p) => {
|
||||
geo.cartesian3.subtract(p, middle, offset);
|
||||
return [
|
||||
geo.cartesian3.dot(offset, east),
|
||||
geo.cartesian3.dot(offset, north),
|
||||
];
|
||||
});
|
||||
let start = outline.length;
|
||||
const holeIndices = holes.map((hole) => {
|
||||
const index = start;
|
||||
start += hole.length;
|
||||
return index;
|
||||
});
|
||||
const triangles = earcut(plane.flat(), holeIndices);
|
||||
if (!triangles.length) return null;
|
||||
return shape(world, triangles);
|
||||
}
|
||||
|
||||
/**
|
||||
* An image's rectangle, [west, south, east, north] in degrees at `height`:
|
||||
* a grid of cells no larger than the granularity, texture coordinates from
|
||||
* (0, 0) at the south-west corner to (1, 1) at the north-east one.
|
||||
*/
|
||||
export function rectangleShape([west, south, east, north], height = 0) {
|
||||
const span = east >= west ? east - west : east + 360 - west;
|
||||
const columns = Math.max(1, Math.ceil(span / GRANULARITY_DEGREES));
|
||||
const rows = Math.max(
|
||||
1,
|
||||
Math.ceil(Math.abs(north - south) / GRANULARITY_DEGREES),
|
||||
);
|
||||
const positions = [];
|
||||
const st = new Float32Array((rows + 1) * (columns + 1) * 2);
|
||||
for (let row = 0; row <= rows; row++)
|
||||
for (let column = 0; column <= columns; column++) {
|
||||
const s = column / columns,
|
||||
t = row / rows;
|
||||
st.set([s, t], positions.length * 2);
|
||||
positions.push(
|
||||
geo.cartesian3.fromDegrees(
|
||||
west + span * s,
|
||||
south + (north - south) * t,
|
||||
height,
|
||||
),
|
||||
);
|
||||
}
|
||||
const indices = [];
|
||||
for (let row = 0; row < rows; row++)
|
||||
for (let column = 0; column < columns; column++) {
|
||||
const a = row * (columns + 1) + column,
|
||||
b = a + 1,
|
||||
c = a + columns + 1,
|
||||
d = c + 1;
|
||||
indices.push(a, b, d, a, d, c);
|
||||
}
|
||||
return shape(positions, indices, st);
|
||||
}
|
||||
Reference in new issue
Block a user