mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge origin/main into the renderer-contract branch: the procedural fleet models drawn through the renderer's model sets
Aircraft, military, local ADS-B, vessel, transit and rail models come from the fleet model set, loaded up front and drawn life size through the draw port's models sets; no layer touches the viewer or Cesium outside src/render/cesium/. The models capability gains glTF bytes (gltf), a per-axis stretch (axisScale), a colour for tinted parts (maskColor) and a cut below the origin (clip: 'belowOrigin'), with conformance checks. Main's rail layer and Data Library are ported to the ports; the CCTV footprint probe keeps the globe-terrain clamp through the query port.
This commit is contained in:
commit
e3865f462f
533 files changed
+55738
-2518
No files matched your search
@@ -3,11 +3,12 @@
|
||||
* @description The Cesium draw port's `models` sets: one `Cesium.Model` per
|
||||
* item in the set's collection, changed where it is. An update that keeps an
|
||||
* item's `url` re-poses and restyles its model in place (position,
|
||||
* orientation, scale and pixel bounds, `shading`, `tint`, `colorBlend`,
|
||||
* `environmentMap`, `displayRange`, `show`); only a new `url` loads again,
|
||||
* and the old model keeps drawing until the new one is ready, so a swap
|
||||
* never blinks. `ready` fires once per load, when the model has loaded and
|
||||
* is posed.
|
||||
* orientation, scale, `axisScale` and pixel bounds, `shading`, `tint`,
|
||||
* `colorBlend`, `maskColor`, `clip`, `environmentMap`, `displayRange`,
|
||||
* `show`); only a new `url` loads again, and the old model keeps drawing
|
||||
* until the new one is ready, so a swap never blinks. `ready` fires once per
|
||||
* load, when the model has loaded and is posed. An item with its `gltf`
|
||||
* bytes is built from them; its url is then not fetched.
|
||||
*
|
||||
* What Cesium has no option for runs each frame before the scene draws:
|
||||
* `maxPixelSize` (the scale capped so the bounding sphere spans at most that
|
||||
@@ -44,6 +45,64 @@ const DEFAULT_MIX = 0.5;
|
||||
let unlitShader = null;
|
||||
let thermalShader = null;
|
||||
|
||||
/** Mask shaders by shading and colour: one per pair, shared by its models. */
|
||||
const maskShaders = new Map();
|
||||
|
||||
/**
|
||||
* The custom shader that paints `mask` where a model's `_TINT` vertex
|
||||
* attribute marks it: drawn colour = colour × mix(1, mask, _TINT), unlit
|
||||
* under `unlit` shading.
|
||||
*/
|
||||
function maskShaderOf(shading, mask) {
|
||||
const key = `${shading === 'unlit' ? 'unlit' : 'pbr'}|${mask.toCssHexString()}`;
|
||||
let shader = maskShaders.get(key);
|
||||
if (!shader) {
|
||||
shader = new Cesium.CustomShader({
|
||||
mode: Cesium.CustomShaderMode.MODIFY_MATERIAL,
|
||||
...(shading === 'unlit'
|
||||
? { lightingModel: Cesium.LightingModel.UNLIT }
|
||||
: {}),
|
||||
uniforms: {
|
||||
u_maskColor: {
|
||||
type: Cesium.UniformType.VEC3,
|
||||
value: new Cesium.Cartesian3(mask.red, mask.green, mask.blue),
|
||||
},
|
||||
},
|
||||
fragmentShaderText: `
|
||||
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
|
||||
vec3 mask = czm_srgbToLinear(u_maskColor);
|
||||
material.diffuse *= mix(vec3(1.0), mask, fsInput.attributes.tint);
|
||||
}`,
|
||||
});
|
||||
maskShaders.set(key, shader);
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
/**
|
||||
* The custom shader an entry's item draws with: its mask colour's (but under
|
||||
* `thermal`), else its `shading`'s.
|
||||
*/
|
||||
function entryShader(entry) {
|
||||
const shading = entry.item.shading;
|
||||
if (entry.mask && shading !== 'thermal')
|
||||
return maskShaderOf(shading, entry.mask);
|
||||
return shaderOf(shading);
|
||||
}
|
||||
|
||||
/**
|
||||
* A clipping plane through the model's origin, keeping what is above it:
|
||||
* the planes sit in the model matrix's frame, whose origin is the item's
|
||||
* position and whose Z axis is the local vertical. One per model: a
|
||||
* collection belongs to the model it clips.
|
||||
*/
|
||||
function belowOriginClip() {
|
||||
return new Cesium.ClippingPlaneCollection({
|
||||
planes: [new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_Z, 0)],
|
||||
edgeWidth: 0,
|
||||
});
|
||||
}
|
||||
|
||||
/** The custom shader a `shading` draws with; undefined for `pbr`. */
|
||||
function shaderOf(shading) {
|
||||
if (shading === 'unlit')
|
||||
@@ -88,6 +147,7 @@ export function cappedScale(scale, radiusM, metresPerPixel, maxPixelSize) {
|
||||
}
|
||||
|
||||
const scratchHpr = new Cesium.HeadingPitchRoll();
|
||||
const scratchAxes = new Cesium.Cartesian3();
|
||||
const scratchMatrix = new Cesium.Matrix4();
|
||||
const scratchSphere = new Cesium.BoundingSphere();
|
||||
const scratchColor = new Cesium.Color();
|
||||
@@ -215,13 +275,20 @@ export function createModelSets({
|
||||
requestRender();
|
||||
};
|
||||
entry.settleLoad = settleLoad;
|
||||
// Bytes loaded already are drawn from: the url is then only the base
|
||||
// path (Cesium's glTF cache keys by it, so each model keeps its own).
|
||||
const source = item.gltf
|
||||
? { gltf: item.gltf, basePath: item.url }
|
||||
: { url: item.url };
|
||||
Cesium.Model.fromGltfAsync({
|
||||
url: item.url,
|
||||
...source,
|
||||
modelMatrix: matrixOf(entry, new Cesium.Matrix4()),
|
||||
scale: item.scale ?? 1,
|
||||
minimumPixelSize: item.minPixelSize ?? 0,
|
||||
maximumScale: item.maxScale,
|
||||
customShader: shaderOf(item.shading),
|
||||
customShader: entryShader(entry),
|
||||
clippingPlanes:
|
||||
item.clip === 'belowOrigin' ? belowOriginClip() : undefined,
|
||||
environmentMapOptions: { enabled: item.environmentMap !== false },
|
||||
// Shown once ready and placed: the pass below shows it.
|
||||
show: false,
|
||||
@@ -279,13 +346,24 @@ export function createModelSets({
|
||||
scratchHpr.heading = o.heading ?? 0;
|
||||
scratchHpr.pitch = o.pitch ?? 0;
|
||||
scratchHpr.roll = o.roll ?? 0;
|
||||
return Cesium.Transforms.headingPitchRollToFixedFrame(
|
||||
Cesium.Transforms.headingPitchRollToFixedFrame(
|
||||
entry.at,
|
||||
scratchHpr,
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
undefined,
|
||||
result,
|
||||
);
|
||||
const axes = entry.item.axisScale;
|
||||
if (axes && (axes[0] !== 1 || axes[1] !== 1 || axes[2] !== 1)) {
|
||||
// Cesium's glTF axis correction (Y up to Z up, then Z forward to X
|
||||
// forward) puts the model's own Z on local X, its X on local Y and
|
||||
// its Y on local Z.
|
||||
scratchAxes.x = axes[2];
|
||||
scratchAxes.y = axes[0];
|
||||
scratchAxes.z = axes[1];
|
||||
Cesium.Matrix4.multiplyByScale(result, scratchAxes, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,8 +380,11 @@ export function createModelSets({
|
||||
if (model.minimumPixelSize !== minimum) model.minimumPixelSize = minimum;
|
||||
if (model.maximumScale !== item.maxScale)
|
||||
model.maximumScale = item.maxScale;
|
||||
const shader = shaderOf(item.shading);
|
||||
const shader = entryShader(entry);
|
||||
if (model.customShader !== shader) model.customShader = shader;
|
||||
const clip = item.clip === 'belowOrigin';
|
||||
if (Boolean(model.clippingPlanes) !== clip)
|
||||
model.clippingPlanes = clip ? belowOriginClip() : undefined;
|
||||
const environment = item.environmentMap !== false;
|
||||
const manager = model.environmentMapManager;
|
||||
if (manager && manager.enabled !== environment)
|
||||
@@ -373,6 +454,8 @@ export function createModelSets({
|
||||
at: new Cesium.Cartesian3(),
|
||||
tint: null,
|
||||
tintKey: undefined,
|
||||
mask: null,
|
||||
maskKey: undefined,
|
||||
radius: 0,
|
||||
next: null,
|
||||
token: null,
|
||||
@@ -397,6 +480,11 @@ export function createModelSets({
|
||||
entry.tintKey = tint;
|
||||
entry.tint = tint === null ? null : toColor(item.tint);
|
||||
}
|
||||
const mask = tintKey(item.maskColor);
|
||||
if (entry.maskKey !== mask) {
|
||||
entry.maskKey = mask;
|
||||
entry.mask = mask === null ? null : toColor(item.maskColor);
|
||||
}
|
||||
if (entry.url !== item.url && item.url === entry.modelUrl) {
|
||||
// Back to the url it draws: the load in between is not wanted.
|
||||
cancel(record, entry);
|
||||
|
||||
@@ -233,6 +233,17 @@ export function createCesiumHarness({
|
||||
toEcef,
|
||||
tolerance: DEFAULT_TOLERANCE,
|
||||
flightPaths: 'trace',
|
||||
...(model ? { assets: { model, missingModel } } : {}),
|
||||
...(model
|
||||
? {
|
||||
assets: {
|
||||
model,
|
||||
missingModel,
|
||||
// The model's bytes, for the check that a model drawn from them
|
||||
// never fetches its url.
|
||||
modelBytes: async () =>
|
||||
new Uint8Array(await (await fetch(model)).arrayBuffer()),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
@@ -3525,6 +3525,81 @@ export function portChecks() {
|
||||
},
|
||||
{ capability: 'models' },
|
||||
),
|
||||
check(
|
||||
'draw.models.bytes',
|
||||
'a model given its bytes is drawn from them, its url never fetched',
|
||||
async (h, r) => {
|
||||
if (!h.assets?.modelBytes || !h.assets?.missingModel)
|
||||
return { skip: 'no model bytes in this harness' };
|
||||
const gltf = await h.assets.modelBytes();
|
||||
const set = r.draw.models({ id: 'conf:models.bytes' });
|
||||
const ready = [];
|
||||
const failed = [];
|
||||
set.on('ready', (id) => ready.push(id));
|
||||
set.on('loadFailed', (id) => failed.push(id));
|
||||
set.set([
|
||||
{
|
||||
id: 'm',
|
||||
pos: { ...AUSTIN, height: 0 },
|
||||
// A url that does not load: only the bytes can draw it.
|
||||
url: h.assets.missingModel,
|
||||
gltf,
|
||||
orientation: { heading: 0, pitch: 0, roll: 0 },
|
||||
},
|
||||
]);
|
||||
for (let i = 0; i < 600 && !ready.length && !failed.length; i++)
|
||||
await drawn(h, r, 1);
|
||||
deepEqual(ready, ['m'], 'ready from its bytes');
|
||||
deepEqual(failed, [], 'its url not fetched');
|
||||
set.dispose();
|
||||
},
|
||||
{ capability: 'models' },
|
||||
),
|
||||
check(
|
||||
'draw.models.fleet',
|
||||
'a model’s axis scale and clip change live, without loading again',
|
||||
async (h, r) => {
|
||||
if (!h.assets?.model) return { skip: 'no model asset in this harness' };
|
||||
await overAustin(h, r);
|
||||
const set = r.draw.models({ id: 'conf:models.fleet' });
|
||||
const ready = [];
|
||||
const failed = [];
|
||||
set.on('ready', (id) => ready.push(id));
|
||||
set.on('loadFailed', (id) => failed.push(id));
|
||||
const pos = h.toEcef({ ...AUSTIN, height: 0 });
|
||||
const model = (extra) => ({
|
||||
id: 'm',
|
||||
pos,
|
||||
url: h.assets.model,
|
||||
orientation: { heading: 0, pitch: 0, roll: 0 },
|
||||
minPixelSize: 96,
|
||||
meta: { n: 1 },
|
||||
...extra,
|
||||
});
|
||||
const picked = () => {
|
||||
const s = r.query.project(pos);
|
||||
return (
|
||||
s !== null &&
|
||||
r.query.drillPick(s.x, s.y).some((hit) => hit.set === set.id)
|
||||
);
|
||||
};
|
||||
set.set([model({ axisScale: [1, 1, 1] })]);
|
||||
for (let i = 0; i < 600 && !ready.length; i++) await drawn(h, r, 1);
|
||||
deepEqual(ready, ['m'], 'ready');
|
||||
set.upsert([model({ axisScale: [1, 1.5, 2], clip: 'belowOrigin' })]);
|
||||
await drawn(h, r, 3);
|
||||
await settled(r);
|
||||
ok(picked(), 'stretched and clipped, still drawn where it is');
|
||||
set.upsert([model({ axisScale: [2, 1, 1], clip: undefined })]);
|
||||
await drawn(h, r, 3);
|
||||
await settled(r);
|
||||
ok(picked(), 'restretched and unclipped');
|
||||
deepEqual(ready, ['m'], 'restyled without loading again');
|
||||
deepEqual(failed, [], 'nothing failed');
|
||||
set.dispose();
|
||||
},
|
||||
{ capability: 'models' },
|
||||
),
|
||||
|
||||
// --- Query -------------------------------------------------------------
|
||||
check(
|
||||
|
||||
@@ -55,7 +55,7 @@ import { portChecks } from './checks/ports.js';
|
||||
* @property {boolean} [cameraInput] The renderer's camera moves on pointer input sent through `pointer` (its own gestures, or a camera controller's): the camera scripts with `input` steps run.
|
||||
* @property {(r: object, fn: (point: {lon: number, lat: number}, against?: string) => number|null) => void} [scriptHeights]
|
||||
* @property {(r: object) => number} [wallTime] Epoch ms the renderer's `live` motion clock reads.
|
||||
* @property {{model?: string}} [assets]
|
||||
* @property {{model?: string, missingModel?: string, modelBytes?: () => Promise<Uint8Array>}} [assets] `modelBytes`: the bytes of a model, for the check that a model given its bytes never fetches its url.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ function contractOnly(renderer) {
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
const ctx = { toEcef, assets: { model: '/models/c172.glb' } };
|
||||
const ctx = { toEcef, assets: { model: '/models/fleet/aircraft/c172.glb' } };
|
||||
|
||||
test('every reference scene builds and disposes on the stub through the contract alone', async () => {
|
||||
const ids = new Set();
|
||||
|
||||
Vendored
+29
@@ -357,6 +357,35 @@ export interface ModelItem extends Placed {
|
||||
tint?: Color;
|
||||
colorBlend?: { mode: 'highlight' | 'replace' | 'mix'; amount?: number };
|
||||
environmentMap?: boolean;
|
||||
/**
|
||||
* The model's glTF (GLB) bytes, loaded already: the renderer draws it from
|
||||
* these and never fetches `url`, which stays its identity (an update that
|
||||
* keeps the `url` keeps the model, whatever bytes it carries), so models
|
||||
* loaded up front are never fetched mid-session. A renderer reads models
|
||||
* compressed with `EXT_meshopt_compression` and `KHR_mesh_quantization`.
|
||||
*/
|
||||
gltf?: Uint8Array;
|
||||
/**
|
||||
* Per-axis multipliers on top of `scale`, along the model's own glTF axes
|
||||
* (`x`, `y`, `z` as authored, before the Y-up turn): a model stretched
|
||||
* wider or taller than its length scale. `minPixelSize` and
|
||||
* `maxPixelSize` measure `scale` alone. Can change live.
|
||||
*/
|
||||
axisScale?: [x: number, y: number, z: number];
|
||||
/**
|
||||
* For a model whose meshes carry a `_TINT` vertex attribute (0..1): a
|
||||
* colour painted where it marks the model, drawn colour = colour ×
|
||||
* mix(1, maskColor, _TINT), `maskColor` read as sRGB (its alpha unused).
|
||||
* Applied under `pbr` and `unlit` shading, not under `thermal`. Never sent
|
||||
* for a model without the attribute. Can change live.
|
||||
*/
|
||||
maskColor?: Color;
|
||||
/**
|
||||
* `belowOrigin`: only the part of the model above the horizontal plane
|
||||
* through `pos` is drawn (a hull above its waterline, where the globe
|
||||
* would not hide what lies below it). Can change live.
|
||||
*/
|
||||
clip?: 'belowOrigin';
|
||||
}
|
||||
|
||||
/** A plane showing an image, a video or a canvas. */
|
||||
|
||||
@@ -30,6 +30,8 @@ export function createStubHarness(name = 'stub') {
|
||||
assets: {
|
||||
model: 'stub:model.glb',
|
||||
missingModel: `${STUB_FAILING_MODEL_SCHEME}model.glb`,
|
||||
// Any bytes: the stub parses none.
|
||||
modelBytes: async () => new Uint8Array([0x67, 0x6c, 0x54, 0x46]),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -407,7 +407,7 @@ export function createStubRenderer(options = {}) {
|
||||
log('draw', kind, [spec]);
|
||||
// A model is ready once per load: when it is new or its url changes,
|
||||
// not when it is moved or restyled. One under the failing scheme fails
|
||||
// its load instead.
|
||||
// its load instead, unless it came with its bytes (`gltf`).
|
||||
// Each load is told once: a listener that starts another load of the
|
||||
// same item (or removes it) supersedes the one queued here.
|
||||
const loadTokens = new Map();
|
||||
@@ -427,8 +427,10 @@ export function createStubRenderer(options = {}) {
|
||||
for (const [id, token] of loading) {
|
||||
if (loadTokens.get(id) !== token || !record.items.has(id)) continue;
|
||||
loadTokens.delete(id);
|
||||
const url = String(record.items.get(id).url ?? '');
|
||||
if (url.startsWith(STUB_FAILING_MODEL_SCHEME))
|
||||
const item = record.items.get(id);
|
||||
const url = String(item.url ?? '');
|
||||
// A model given its bytes is drawn from them: its url is not fetched.
|
||||
if (!item.gltf && url.startsWith(STUB_FAILING_MODEL_SCHEME))
|
||||
deliver(record.loadFailedListeners, id, `${url} does not load`);
|
||||
else deliver(record.readyListeners, id);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user