mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +00:00
Draw Bhote Koshi and awareness pulses through engine.ground
Render the Bhote Koshi event and locator through one ground and point display. Keep Cesium's reveal paths, dashed halo, glowing core, polygon classification, pick identities and independent point outline opacity. Add static pixel dash masks, synchronous ground reveals after terrain bounds load, and per-point outline colour so the shared display preserves those behaviours. Add a ground pulse field with checked state on all three engines. Keep Cesium's raised material disc, band equations, front widths, wake and rest timing and reduced-motion behaviour. Navara now follows Cesium's raised pulse surface and story styling, with ground effects composed after tone mapping. Move the wind mesh shader into the Navara engine without changing its transparent pass. Layer renderer lines fall from 210 to 14 for Cesium and from 794 to 314 for Navara. Viewer lines fall from 953 to 948, extension reads from 6 to 4, and engine-name lines from 37 to 36. No coupling count grows. Checked in the browser, keyless: the contract suite, with its new pulse pixel checks, passes on Navara and on Cesium apart from the camera-events check that also fails intermittently before; the Nepal locator and Contacts engine switches pass. The Nepal event and wind engine switches fail the same way before this change. Side by side at the locator's overview, Cesium draws the same pixels as before and Navara's river corridor now glows as Cesium's does, where it was faint.
This commit is contained in:
1 parent
dacfd33f10
commit
f385986383
50 files changed
+1438
-520
No files matched your search
+58
-11
@@ -18,6 +18,7 @@
|
||||
// under it); identify() names a picked item.
|
||||
|
||||
import * as Cesium from 'cesium';
|
||||
import { createCesiumPulseField } from './groundPulse.js';
|
||||
import {
|
||||
areaRings,
|
||||
createGroundRegistry,
|
||||
@@ -119,14 +120,21 @@ export function corridorUniforms(item) {
|
||||
}
|
||||
|
||||
const corridorMaterial = (item) =>
|
||||
new Cesium.Material({
|
||||
fabric: {
|
||||
type: CORRIDOR_MATERIAL,
|
||||
uniforms: corridorUniforms(item),
|
||||
source: CORRIDOR_SOURCE,
|
||||
},
|
||||
translucent: true,
|
||||
});
|
||||
item.animation.pattern
|
||||
? Cesium.Material.fromType('PolylineDash', {
|
||||
color: colorOf(item.fill),
|
||||
gapColor: Cesium.Color.TRANSPARENT,
|
||||
dashLength: item.animation.pattern.lengthPx,
|
||||
dashPattern: item.animation.pattern.pattern,
|
||||
})
|
||||
: new Cesium.Material({
|
||||
fabric: {
|
||||
type: CORRIDOR_MATERIAL,
|
||||
uniforms: corridorUniforms(item),
|
||||
source: CORRIDOR_SOURCE,
|
||||
},
|
||||
translucent: true,
|
||||
});
|
||||
|
||||
// Items of one look and colour share a primitive.
|
||||
const lookKey = (item) =>
|
||||
@@ -270,6 +278,10 @@ export function createCesiumGround(
|
||||
) {
|
||||
const make = { ...DEFAULT_FACTORIES, ...factories };
|
||||
const { scene } = viewer;
|
||||
let heightsReady =
|
||||
make.lines !== DEFAULT_FACTORIES.lines &&
|
||||
make.fills !== DEFAULT_FACTORIES.fills;
|
||||
let heightsPromise = null;
|
||||
let root = null;
|
||||
const ordered = [];
|
||||
const building = new Set();
|
||||
@@ -322,7 +334,7 @@ export function createCesiumGround(
|
||||
}
|
||||
return root;
|
||||
};
|
||||
const registry = createGroundRegistry((options) => {
|
||||
const build = (options) => {
|
||||
const slot = new Cesium.PrimitiveCollection({ destroyPrimitives: true });
|
||||
const at = ordered.filter((entry) => entry.order <= options.order).length;
|
||||
ordered.splice(at, 0, { order: options.order, slot });
|
||||
@@ -331,14 +343,37 @@ export function createCesiumGround(
|
||||
let looks = [];
|
||||
const classificationType = classificationOf(options.drape);
|
||||
const allowPicking = options.pickable;
|
||||
let pending = null;
|
||||
let waiting = false;
|
||||
let destroyed = false;
|
||||
const forget = () => {
|
||||
for (const primitive of drawn) building.delete(primitive);
|
||||
for (const material of looks) materials.delete(material);
|
||||
drawn = [];
|
||||
looks = [];
|
||||
};
|
||||
return {
|
||||
const part = {
|
||||
commit(items) {
|
||||
pending = items;
|
||||
if (options.dynamic && !heightsReady) {
|
||||
if (!waiting) {
|
||||
waiting = true;
|
||||
heightsPromise ??=
|
||||
Cesium.GroundPrimitive.initializeTerrainHeights();
|
||||
heightsPromise.then(
|
||||
() => {
|
||||
heightsReady = true;
|
||||
waiting = false;
|
||||
if (!destroyed) part.commit(pending);
|
||||
},
|
||||
() => {
|
||||
heightsPromise = null;
|
||||
waiting = false;
|
||||
},
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
forget();
|
||||
slot.removeAll();
|
||||
const { fills, lines, animated } = groundInstances(options, items);
|
||||
@@ -352,6 +387,7 @@ export function createCesiumGround(
|
||||
}),
|
||||
classificationType,
|
||||
allowPicking,
|
||||
asynchronous: !options.dynamic,
|
||||
}),
|
||||
);
|
||||
if (lines.length)
|
||||
@@ -361,6 +397,7 @@ export function createCesiumGround(
|
||||
appearance: new Cesium.PolylineColorAppearance(),
|
||||
classificationType,
|
||||
allowPicking,
|
||||
asynchronous: !options.dynamic,
|
||||
}),
|
||||
);
|
||||
for (const { item, instances } of animated) {
|
||||
@@ -374,6 +411,7 @@ export function createCesiumGround(
|
||||
appearance: new Cesium.PolylineMaterialAppearance({ material }),
|
||||
classificationType,
|
||||
allowPicking,
|
||||
asynchronous: !options.dynamic,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -391,8 +429,13 @@ export function createCesiumGround(
|
||||
animate();
|
||||
requestRender('ground');
|
||||
},
|
||||
ready: () => drawn.every((primitive) => primitive.ready === true),
|
||||
ready: () =>
|
||||
(!options.dynamic || heightsReady) &&
|
||||
!waiting &&
|
||||
drawn.every((primitive) => primitive.ready === true),
|
||||
destroy() {
|
||||
destroyed = true;
|
||||
pending = null;
|
||||
forget();
|
||||
animate();
|
||||
ordered.splice(
|
||||
@@ -403,6 +446,10 @@ export function createCesiumGround(
|
||||
requestRender('ground');
|
||||
},
|
||||
};
|
||||
return part;
|
||||
};
|
||||
const registry = createGroundRegistry(build, {
|
||||
pulseField: (options) => createCesiumPulseField(viewer, options),
|
||||
});
|
||||
return {
|
||||
ground: registry.ground,
|
||||
|
||||
@@ -19,6 +19,76 @@ for (const name of [
|
||||
const items = (kind, list) =>
|
||||
list.map((item, index) => normalizeGroundItem(kind, item, index));
|
||||
|
||||
test('dynamic reveals wait for height bounds, draw the latest path and cancel on release', async (t) => {
|
||||
const viewer = createFakeViewer();
|
||||
viewer.scene.groundPrimitives = new Cesium.PrimitiveCollection();
|
||||
let resolve;
|
||||
let loads = 0;
|
||||
t.mock.method(Cesium.GroundPrimitive, 'initializeTerrainHeights', () => {
|
||||
loads++;
|
||||
return new Promise((done) => {
|
||||
resolve = done;
|
||||
});
|
||||
});
|
||||
const part = createCesiumGround(viewer, {
|
||||
factories: {
|
||||
lines: (options) => ({
|
||||
...options,
|
||||
ready: false,
|
||||
destroy() {},
|
||||
isDestroyed: () => false,
|
||||
}),
|
||||
},
|
||||
});
|
||||
t.after(() => part.destroy());
|
||||
const reveal = part.ground.createSet({
|
||||
id: 'reveal',
|
||||
kind: 'corridor',
|
||||
dynamic: true,
|
||||
});
|
||||
const cancelled = part.ground.createSet({
|
||||
id: 'cancelled',
|
||||
kind: 'corridor',
|
||||
dynamic: true,
|
||||
});
|
||||
const path = (lon) => [
|
||||
{
|
||||
positions: [
|
||||
[0, 0],
|
||||
[lon, 1],
|
||||
],
|
||||
color: [0, 1, 1, 1],
|
||||
widthPx: 3,
|
||||
},
|
||||
];
|
||||
reveal.replace(path(1));
|
||||
reveal.commit();
|
||||
cancelled.replace(path(1));
|
||||
cancelled.commit();
|
||||
assert.equal(loads, 1, 'sets share the pending height bounds');
|
||||
assert.equal(reveal.ready(), false);
|
||||
reveal.replace(path(2));
|
||||
reveal.commit();
|
||||
cancelled.destroy();
|
||||
resolve();
|
||||
await Promise.resolve();
|
||||
const root = viewer.scene.groundPrimitives.get(0);
|
||||
assert.equal(
|
||||
root.length,
|
||||
1,
|
||||
'released set does not return when bounds arrive',
|
||||
);
|
||||
const primitive = root.get(0).get(0);
|
||||
assert.equal(primitive.asynchronous, false);
|
||||
const end = primitive.geometryInstances[0].geometry._positions.at(-1);
|
||||
assert.ok(
|
||||
Math.abs(
|
||||
Cesium.Math.toDegrees(Cesium.Cartographic.fromCartesian(end).longitude) -
|
||||
2,
|
||||
) < 1e-9,
|
||||
);
|
||||
});
|
||||
|
||||
test('fills batch into GroundPrimitive instances, outlines into ground polylines', () => {
|
||||
const options = { id: 'zones', kind: 'polygon' };
|
||||
const { fills, lines } = groundInstances(
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
// A ground pulse field: one unpickable ellipse with uniform-only pulse updates.
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
/** The pulse disc's Cesium material type, one cached template per page. */
|
||||
const MATERIAL_TYPE = 'GevGroundPulseField';
|
||||
|
||||
// Ellipse texture coordinates put the centre at (0.5, 0.5) and the rim at
|
||||
// distance 0.5, so `r` is the fraction of the range. Each pulse is a line
|
||||
// `lineWidth` CSS pixels wide whose outer `haloWidth` is a dark halo, half
|
||||
// on each side, as Cesium's polyline outline material draws it, with a band
|
||||
// behind it that is strongest at the line and fades to nothing `depth`
|
||||
// inward. Widths come from the screen-space gradient of `r`, as Cesium's
|
||||
// contour material measures its lines; without derivatives the lines are
|
||||
// left out and only the band shows.
|
||||
const SOURCE = `
|
||||
uniform vec4 color;
|
||||
uniform vec4 lineColor;
|
||||
uniform vec4 haloColor;
|
||||
uniform vec4 radii;
|
||||
uniform vec4 alphas;
|
||||
uniform float depth;
|
||||
uniform float lineWidth;
|
||||
uniform float haloWidth;
|
||||
vec4 over(vec4 top, vec4 under) {
|
||||
float a = top.a + under.a * (1.0 - top.a);
|
||||
if (a <= 0.0) return vec4(0.0);
|
||||
return vec4((top.rgb * top.a + under.rgb * under.a * (1.0 - top.a)) / a, a);
|
||||
}
|
||||
czm_material czm_getMaterial(czm_materialInput materialInput) {
|
||||
czm_material material = czm_getDefaultMaterial(materialInput);
|
||||
float r = length(materialInput.st - vec2(0.5)) * 2.0;
|
||||
float band = 0.0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float inside = radii[i] - r;
|
||||
if (inside >= 0.0 && inside <= depth) {
|
||||
float t = 1.0 - inside / depth;
|
||||
band += alphas[i] * t * t;
|
||||
}
|
||||
}
|
||||
vec4 result = vec4(color.rgb, clamp(band * color.a, 0.0, 1.0));
|
||||
#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))
|
||||
// Change in r per CSS pixel: the gradient's length per device pixel,
|
||||
// times the device pixels in one CSS pixel.
|
||||
float cssPx = max(length(vec2(dFdx(r), dFdy(r))), 1e-7) * czm_pixelRatio;
|
||||
float outerHalf = lineWidth * 0.5;
|
||||
float coreHalf = max(lineWidth - haloWidth, 0.0) * 0.5;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float d = abs(radii[i] - r) / cssPx;
|
||||
float cover = clamp(outerHalf + 0.5 - d, 0.0, 1.0);
|
||||
if (cover <= 0.0) continue;
|
||||
float core = clamp(coreHalf + 0.5 - d, 0.0, 1.0);
|
||||
vec4 pulse = mix(haloColor, lineColor, core);
|
||||
result = over(vec4(pulse.rgb, pulse.a * cover * alphas[i]), result);
|
||||
}
|
||||
#endif
|
||||
material.diffuse = result.rgb;
|
||||
material.alpha = result.a;
|
||||
return material;
|
||||
}
|
||||
`;
|
||||
|
||||
const toColor = ([red, green, blue, alpha]) =>
|
||||
new Cesium.Color(red, green, blue, alpha);
|
||||
|
||||
/**
|
||||
* The rotation about the Earth's centre that carries `from` onto `to`, as a
|
||||
* model matrix, so a disc built around `from` sits around `to`.
|
||||
* @param {Cesium.Cartesian3} from Where the disc was built.
|
||||
* @param {Cesium.Cartesian3} to Where it should be.
|
||||
* @param {Cesium.Matrix4} [result]
|
||||
* @returns {Cesium.Matrix4}
|
||||
*/
|
||||
export function discFollowMatrix(from, to, result = new Cesium.Matrix4()) {
|
||||
const a = Cesium.Cartesian3.normalize(from, new Cesium.Cartesian3());
|
||||
const b = Cesium.Cartesian3.normalize(to, new Cesium.Cartesian3());
|
||||
const axis = Cesium.Cartesian3.cross(a, b, new Cesium.Cartesian3());
|
||||
const sin = Cesium.Cartesian3.magnitude(axis);
|
||||
if (sin < 1e-12) return Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY, result);
|
||||
const angle = Math.atan2(sin, Cesium.Cartesian3.dot(a, b));
|
||||
const rotation = Cesium.Matrix3.fromQuaternion(
|
||||
Cesium.Quaternion.fromAxisAngle(
|
||||
Cesium.Cartesian3.divideByScalar(axis, sin, axis),
|
||||
angle,
|
||||
),
|
||||
);
|
||||
return Cesium.Matrix4.fromRotationTranslation(
|
||||
rotation,
|
||||
Cesium.Cartesian3.ZERO,
|
||||
result,
|
||||
);
|
||||
}
|
||||
|
||||
function createDisc(center, radiusM, heightM, material) {
|
||||
return new Cesium.Primitive({
|
||||
geometryInstances: new Cesium.GeometryInstance({
|
||||
geometry: new Cesium.EllipseGeometry({
|
||||
center,
|
||||
semiMajorAxis: radiusM,
|
||||
semiMinorAxis: radiusM,
|
||||
height: heightM,
|
||||
granularity: Cesium.Math.toRadians(0.25),
|
||||
vertexFormat:
|
||||
Cesium.MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat,
|
||||
}),
|
||||
}),
|
||||
appearance: new Cesium.MaterialAppearance({
|
||||
material,
|
||||
flat: true,
|
||||
translucent: true,
|
||||
faceForward: true,
|
||||
}),
|
||||
asynchronous: false,
|
||||
allowPicking: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The pulse disc on a Cesium viewer, or null when its scene has no
|
||||
* primitive collection: `draw({ radii, alphas, level })`, `move(center)`,
|
||||
* `destroy()`. Colours are rgba arrays in 0..1.
|
||||
*/
|
||||
export function createCesiumPulseField(
|
||||
viewer,
|
||||
{
|
||||
center,
|
||||
radiusM,
|
||||
heightM,
|
||||
color,
|
||||
lineColor,
|
||||
haloColor,
|
||||
depth,
|
||||
lineWidth,
|
||||
haloWidth,
|
||||
},
|
||||
) {
|
||||
const primitives = viewer?.scene?.primitives;
|
||||
if (!primitives?.add) return null;
|
||||
const uniforms = {
|
||||
color: toColor(color),
|
||||
lineColor: toColor(lineColor),
|
||||
haloColor: toColor(haloColor),
|
||||
radii: new Cesium.Cartesian4(),
|
||||
alphas: new Cesium.Cartesian4(),
|
||||
depth,
|
||||
lineWidth,
|
||||
haloWidth,
|
||||
};
|
||||
// A named type: Cesium caches every material type for the page's
|
||||
// lifetime, so an unnamed fabric (a fresh GUID each time) would leave one
|
||||
// entry per new visual. Built from the cached template, the uniforms come
|
||||
// back as plain copies; restore this disc's own.
|
||||
const material = new Cesium.Material({
|
||||
fabric: { type: MATERIAL_TYPE, uniforms, source: SOURCE },
|
||||
translucent: true,
|
||||
});
|
||||
Object.assign(material.uniforms, uniforms);
|
||||
const built = Cesium.Cartesian3.clone(center);
|
||||
let disc = primitives.add(createDisc(built, radiusM, heightM, material));
|
||||
let destroyed = false;
|
||||
return {
|
||||
draw({ radii, alphas, level }) {
|
||||
if (destroyed) return;
|
||||
disc.show = level > 0;
|
||||
Cesium.Cartesian4.fromArray(radii, 0, material.uniforms.radii);
|
||||
Cesium.Cartesian4.fromArray(alphas, 0, material.uniforms.alphas);
|
||||
},
|
||||
/**
|
||||
* Centres the disc on `next`: within 20 km of where it was
|
||||
* built by its model matrix (the ellipsoid curves a little differently
|
||||
* from that sphere, tens of metres in height at 20 km), further away by
|
||||
* a rebuild, which costs a few milliseconds.
|
||||
*/
|
||||
move(next) {
|
||||
if (destroyed) return;
|
||||
if (Cesium.Cartesian3.distance(built, next) < 20000) {
|
||||
disc.modelMatrix = discFollowMatrix(built, next, disc.modelMatrix);
|
||||
return;
|
||||
}
|
||||
const previous = disc;
|
||||
Cesium.Cartesian3.clone(next, built);
|
||||
disc = primitives.add(createDisc(built, radiusM, heightM, material));
|
||||
disc.show = previous.show;
|
||||
// Primitive.destroy leaves the material alone, so the new disc keeps
|
||||
// sharing it.
|
||||
primitives.remove(previous);
|
||||
},
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
primitives.remove(disc);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -205,6 +205,10 @@ function pointPart(options, store, { factories, requestRender, owners }) {
|
||||
}
|
||||
item.position = readPosition(store, index);
|
||||
item.pixelSize = point.sizePx * store.scales[index];
|
||||
item.outlineColor = Cesium.Color.unpack(
|
||||
store.outlineColors,
|
||||
index * 4,
|
||||
);
|
||||
item.color = readColor(store, index);
|
||||
item.show = store.shows[index] === 1;
|
||||
item.id = store.pickIds[index];
|
||||
|
||||
@@ -227,6 +227,24 @@ test('points take the size, scale, outline, translucency and depth test of the s
|
||||
assert.equal(point.disableDepthTestDistance, 5000);
|
||||
assert.equal(point.id, 25544);
|
||||
assert.ok(Cesium.Color.equals(point.color, new Cesium.Color(0, 1, 0, 1)));
|
||||
set.set(0, { outlineColor: [0.5, 0, 1, 0.25] });
|
||||
set.commit();
|
||||
assert.deepEqual(
|
||||
Cesium.Color.pack(point.outlineColor, []),
|
||||
[0.5, 0, 1, 0.25],
|
||||
);
|
||||
assert.ok(Cesium.Color.equals(point.color, new Cesium.Color(0, 1, 0, 1)));
|
||||
assert.equal(point.outlineWidth, 1);
|
||||
assert.throws(
|
||||
() => set.set(0, { scale: 9, outlineColor: [1, 0, 0, 2] }),
|
||||
TypeError,
|
||||
);
|
||||
set.commit();
|
||||
assert.equal(
|
||||
point.pixelSize,
|
||||
6,
|
||||
'an invalid outline update leaves the point unchanged',
|
||||
);
|
||||
// 'normal' keeps Cesium's depth test.
|
||||
const normal = movers.createSet({
|
||||
id: 'normal',
|
||||
|
||||
Reference in new issue
Block a user