Keep shape radii, rim gradients, depth-fail looks, sweep cadence and step camera moves out of the renderer contract

Shapes take their radii in metres; the world annotation ring follows the
camera height itself (ringRadiusAt), resizing on preRender. The radial rim
preset and depthBias go: the launch pad zone draws a canvas image fill made
by the layer. Solid and dashed lines take one depthFail look (solid or
dash) in place of depthFailColor and depthFailDash. sonarCadenceHz goes from
the quality settings: nothing set it, and the sweep moves every 80 ms.

Camera move, look, rotateAround and zoom leave the camera port: the app's pans,
in-place turns, globe turns and zooms are setView views summed over the pose
(geo/eyeMoves), and the Cesium port places a view by direction and up
exactly rather than through heading, pitch and roll. The conformance driver
runs those script steps through setView; the lookAt script turns in place
where it turned about the frame-local axis, and its reference is recorded
again.
This commit is contained in:
Sameh Khamis committed 2026-11-10 04:08:41 -08:00
1 parent 7a376ebefc
commit c8346c9fda
44 files changed
+810 -799

No files matched your search

+48 -41
View File
@@ -38,25 +38,6 @@ export const EASINGS = Object.freeze({
sineInOut: Cesium.EasingFunction.SINUSOIDAL_IN_OUT,
});
/**
* The contract's moves and looks as Cesium camera method names, called by
* name: a caller's camera may come from another copy of Cesium.
*/
const MOVES = Object.freeze({
forward: 'moveForward',
back: 'moveBackward',
left: 'moveLeft',
right: 'moveRight',
up: 'moveUp',
down: 'moveDown',
});
const LOOKS = Object.freeze({
left: 'lookLeft',
right: 'lookRight',
up: 'lookUp',
down: 'lookDown',
});
/** A contract destination as Cesium's: a Cartesian3, or a Rectangle. */
export function toDestination(d) {
if ('rect' in d) {
@@ -219,16 +200,60 @@ export function createCesiumCamera({
if (frustum.fov !== fov) frustum.fov = fov;
}
/**
* Put the eye at world point `destination` looking along `direction` with
* `up` up (made square to it), in the camera's frame: a `lookAt` frame
* stays, as Cesium's setView keeps it.
*/
function placeEye(destination, { direction, up }) {
const at = toCartesian(destination);
const dir = Cesium.Cartesian3.normalize(
toCartesian(direction),
new Cesium.Cartesian3(),
);
const right = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.cross(dir, toCartesian(up), new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
);
const square = Cesium.Cartesian3.cross(right, dir, new Cesium.Cartesian3());
const transform = camera.transform;
if (
transform &&
!Cesium.Matrix4.equals(transform, Cesium.Matrix4.IDENTITY)
) {
const inverse = Cesium.Matrix4.inverseTransformation(
transform,
new Cesium.Matrix4(),
);
Cesium.Matrix4.multiplyByPoint(inverse, at, camera.position);
Cesium.Matrix4.multiplyByPointAsVector(inverse, dir, camera.direction);
Cesium.Matrix4.multiplyByPointAsVector(inverse, square, camera.up);
Cesium.Matrix4.multiplyByPointAsVector(inverse, right, camera.right);
return;
}
Cesium.Cartesian3.clone(at, camera.position);
Cesium.Cartesian3.clone(dir, camera.direction);
Cesium.Cartesian3.clone(square, camera.up);
Cesium.Cartesian3.clone(right, camera.right);
}
const cameraPort = {
on: (event, cb, options) => cameraEvents.on(event, cb, options),
onCommand: (cb) => commandHooks.on(cb),
setView(spec) {
command('setView');
const d = spec.destination;
camera.setView({
...(d ? { destination: toDestination(d) } : {}),
orientation: toOrientation(spec.orientation),
});
const o = spec.orientation;
// A view by direction and up at a point is placed as given: Cesium's
// own setView would round it through heading, pitch and roll, which
// drifts looking straight down, where steps add up (the app's pans,
// turns and globe turns are setViews).
if (d && !('rect' in d) && o && 'direction' in o) placeEye(d, o);
else
camera.setView({
...(d ? { destination: toDestination(d) } : {}),
orientation: toOrientation(o),
});
scene.requestRender();
},
flyTo(destination, options = {}) {
@@ -314,24 +339,6 @@ export function createCesiumCamera({
camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
scene.requestRender();
},
move(direction, metres) {
camera[MOVES[direction]](metres);
scene.requestRender();
},
look(direction, radians) {
camera[LOOKS[direction]](radians);
scene.requestRender();
},
rotateAround(axis, radians) {
camera.rotate(toCartesian(axis), radians);
scene.requestRender();
},
zoom(metres) {
// Cesium's zoom, not a move: outside 3D it changes the view's width.
if (metres < 0) camera.zoomOut(-metres);
else camera.zoomIn(metres);
scene.requestRender();
},
setFov({ vertical }) {
// Cesium would take a bad angle and draw a garbage projection.
if (!(vertical > 0 && vertical < Math.PI))
+50 -227
View File
@@ -189,40 +189,11 @@ czm_material czm_getMaterial(czm_materialInput materialInput) {
return m;
}`;
/** The `radialRim` fill's material type. */
const RADIAL_RIM_MATERIAL = 'DrawRadialRimFill';
/**
* Across the ellipse (`st` from its centre, 1 at its edge) the fill's
* colour, easing into the rim's over `rimWidth` (a fraction of the
* radius) just inside a soft edge; the rim glows a little.
* How finely a clamped ellipse with an image fill is cut, radians, so an
* image's round edge (a zone's rim) runs round.
*/
const RADIAL_RIM_SOURCE = `
czm_material czm_getMaterial(czm_materialInput materialInput) {
czm_material material = czm_getDefaultMaterial(materialInput);
vec2 centered = (materialInput.st - vec2(0.5)) * 2.0;
float radius = length(centered);
float inside = 1.0 - smoothstep(0.985, 1.0, radius);
float rim = smoothstep(0.985 - rimWidth, 0.985, radius) * inside;
material.diffuse = mix(color.rgb, rimColor.rgb, rim);
material.emission = rimColor.rgb * rim * 0.35;
material.alpha = inside * mix(color.a, rimColor.a, rim);
return material;
}`;
/** How finely a rim-filled ellipse is cut, radians. */
const RIM_GRANULARITY = Cesium.Math.toRadians(0.08);
/**
* A ground fill pulled toward the eye (`depthBias`): depth-tested, not
* writing depth, offset toward the camera, alpha blended.
*/
const DEPTH_BIASED_STATE = Object.freeze({
depthTest: { enabled: true },
depthMask: false,
polygonOffset: { enabled: true, factor: -1, units: -4 },
blending: Cesium.BlendingState.ALPHA_BLEND,
});
const IMAGE_ELLIPSE_GRANULARITY = Cesium.Math.toRadians(0.08);
/**
* An image fill's material. The image carries its own alpha, so it draws in
@@ -241,33 +212,6 @@ function imageMaterial(image, repeat = [1, 1]) {
return material;
}
/** A `radialRim` fill's material. */
function radialRimMaterial(fill) {
const uniforms = {
color: toColor(fill.color),
rimColor: toColor(fill.rimColor),
rimWidth: fill.rimWidth,
};
// Built from its type, then given its values, as the line materials are.
const material = new Cesium.Material({
fabric: { type: RADIAL_RIM_MATERIAL, uniforms, source: RADIAL_RIM_SOURCE },
});
Object.assign(material.uniforms, uniforms);
return material;
}
/**
* An ellipse radius at a camera `height`: a fixed one as it is, one by
* camera height scaled by its factor and held within its bounds.
* @param {number|{byCameraHeight: {factor: number, min: number, max: number}}} radius
* @param {number} height
*/
export function radiusAt(radius, height) {
if (typeof radius === 'number') return radius;
const { factor, min, max } = radius.byCameraHeight;
return Math.max(min, Math.min(max, height * factor));
}
/**
* A shape's `animate`, checked: the Cesium renderer pulses alpha, forever.
* Null for a shape that does not pulse.
@@ -305,12 +249,6 @@ export function pulseAlpha(pulse, now) {
return pulse.from + (pulse.to - pulse.from) * (0.5 + 0.5 * Math.sin(turn));
}
/** Whether a shape is an ellipse with a radius by camera height. */
const byCameraHeight = (item) =>
item.geometry?.kind === 'ellipse' &&
(typeof item.geometry.semiMajor !== 'number' ||
typeof item.geometry.semiMinor !== 'number');
/** The line styles the port drapes. */
const DRAPED_STYLES = new Set(['solid', 'glow', 'dash', 'flow', 'arrow']);
@@ -1932,8 +1870,8 @@ export function createCesiumDraw({
positions.some((p) => !Cesium.Cartesian3.equals(p, positions[0]));
/**
* A line not draped that has a `depthFailColor`: a primitive of its own,
* drawn in that colour where the surface hides it. Built at once, so one
* A line not draped that has a `depthFail` style: a primitive of its own,
* drawn in that style where the surface hides it. Built at once, so one
* built anew where it moves draws in the frame it replaces the old one.
* Null when its positions make no line.
*/
@@ -1961,18 +1899,7 @@ export function createCesiumDraw({
}),
appearance: new Cesium.PolylineMaterialAppearance({ material }),
depthFailAppearance: new Cesium.PolylineMaterialAppearance({
material: lineMaterial(
record,
item.depthFailDash
? {
kind: 'dash',
color: item.depthFailColor,
length: item.depthFailDash.length,
pattern16: item.depthFailDash.pattern16,
}
: { kind: 'solid', color: item.depthFailColor },
reveal,
),
material: lineMaterial(record, item.depthFail, reveal),
}),
show: item.show !== false,
asynchronous: false,
@@ -2080,7 +2007,7 @@ export function createCesiumDraw({
const line = {
...rest,
mode: '3d',
depthFailColor: item.style.color,
depthFail: { kind: 'solid', color: item.style.color },
overlaid: true,
};
if (segmentShow?.length) {
@@ -2113,10 +2040,9 @@ export function createCesiumDraw({
return true;
}
/** An overlay line's look but its colours (its depth-fail colour is its
/** An overlay line's look but its colours (its depth-fail style is its
* colour too). */
const overlayShape = (item) =>
lineLook({ ...item, depthFailColor: null }, true);
const overlayShape = (item) => lineLook({ ...item, depthFail: null }, true);
/** Stop tracking a line no longer drawn over the surface for a draped
* one. */
@@ -2191,11 +2117,20 @@ export function createCesiumDraw({
);
else if (
item.frame === 'inertial' &&
(item.mode === 'draped' || item.depthFailColor)
(item.mode === 'draped' || item.depthFail)
)
throw new Error(
'the Cesium renderer draws inertial lines undraped, without depth-fail colours',
);
else if (
item.mode !== 'draped' &&
item.depthFail &&
item.depthFail.kind !== 'solid' &&
item.depthFail.kind !== 'dash'
)
throw new Error(
'the Cesium renderer draws solid and dashed lines behind the surface only',
);
else if (
segmented(item) &&
(item.mode !== 'draped' ||
@@ -2274,7 +2209,7 @@ export function createCesiumDraw({
draped.get(clampTo).push(drapedInstance(item, part, true));
continue;
}
if (item.depthFailColor) {
if (item.depthFail) {
deep ??= new Cesium.PrimitiveCollection();
const id = pickId(record, item);
const primitive = depthFailLine(record, item, id);
@@ -2418,10 +2353,14 @@ export function createCesiumDraw({
item.widthPx,
item.clampTo,
colourless ? { ...item.style, color: undefined } : item.style,
item.depthFailColor,
// A dash is drawn only with a depth-fail colour, the same in any key order.
item.depthFailColor && item.depthFailDash
? [item.depthFailDash.length, item.depthFailDash.pattern16]
// The same depth-fail style in any key order.
item.depthFail
? [
item.depthFail.kind,
item.depthFail.color,
item.depthFail.length,
item.depthFail.pattern16,
]
: null,
// Segment colours and shows change in place.
item.segmentColors != null,
@@ -2439,7 +2378,7 @@ export function createCesiumDraw({
Object.is(a.widthPx, b.widthPx) &&
a.clampTo === b.clampTo &&
a.style === b.style &&
a.depthFailColor === b.depthFailColor &&
a.depthFail === b.depthFail &&
(a.segmentColors != null) === (b.segmentColors != null) &&
(a.segmentShow != null) === (b.segmentShow != null) &&
revealed(a) === revealed(b) &&
@@ -2756,7 +2695,7 @@ export function createCesiumDraw({
const settles = (item) =>
item.mode !== 'draped' &&
item.frame !== 'inertial' &&
!item.depthFailColor &&
!item.depthFail &&
item.style.kind === 'solid' &&
!revealed(item) &&
// The collection draws no line under half a pixel wide; a batch
@@ -3219,10 +3158,6 @@ export function createCesiumDraw({
};
}
case 'ellipse': {
if (byCameraHeight(item))
throw new Error(
'the Cesium renderer takes radii by camera height on clamped ellipses only',
);
const ellipse = {
center: toCartesian(g.center),
semiMajorAxis: g.semiMajor,
@@ -3276,91 +3211,12 @@ export function createCesiumDraw({
}
}
/**
* The camera's height for radii by camera height: above the ellipsoid,
* as Cesium places it (1000 m while it has none).
*/
const cameraHeight = () => {
const height = scene.camera?.positionCartographic?.height;
return Number.isFinite(height) ? height : 1000;
};
/** A clamped ellipse's radii by camera height at this frame's height, or null. */
function radiiOf(item) {
if (!byCameraHeight(item)) return null;
const height = cameraHeight();
return [
radiusAt(item.geometry.semiMajor, height),
radiusAt(item.geometry.semiMinor, height),
];
}
/**
* Before a frame draws: clamped ellipses with radii by camera height
* whose radii have changed with the camera are drawn at the new ones. A
* colour fill is drawn alone where it is, built in this frame
* (`moveShape`), as Cesium's entities rebuild a ground ellipse whose
* radius follows a callback, while no more than `MOVING_SHAPES` of the
* set would be drawn alone; past that, and for any other fill once its
* radii have changed by more than `REBUILD_RADII`, its set rebuilds (one
* rebuild at a time). Hidden ones wait until they show.
*/
function followCameraHeight() {
for (const record of sets.values()) {
const parts = record.shapeParts;
if (record.kind !== 'shapes' || !parts || record.spec.show === false)
continue;
try {
followIn(record, parts);
} catch (error) {
// The set draws as it did; the next frame tries again.
report(error);
}
}
}
/** Relative change of radii past which a fill drawn in a batch rebuilds. */
const REBUILD_RADII = 0.02;
function followIn(record, parts) {
const changed = (radii, part, by) =>
Math.abs(radii[0] - part.radii[0]) > by * part.radii[0] ||
Math.abs(radii[1] - part.radii[1]) > by * part.radii[1];
let alone = 0;
for (const part of parts.values()) if (part.solo) alone += 1;
// Those the host still retiring draws alone count too, until it goes.
if (record.retiring)
for (const part of record.retiringShapeParts?.values() ?? [])
if (part.solo && part.ground && !part.ground.isDestroyed()) alone += 1;
let rebuild = false;
for (const [id, part] of parts) {
if (!part.radii || !part.ground) continue;
const item = record.items.get(id);
if (!item || item.show === false || !byCameraHeight(item)) continue;
const radii = radiiOf(item);
if (!changed(radii, part, 1e-3)) continue;
if (part.ground.isDestroyed() || part.batch?.isDestroyed()) continue;
const movable =
colourFill(item) &&
groundSyncs() &&
typeof record.host?.add === 'function' &&
(part.solo || alone < MOVING_SHAPES);
if (movable) {
if (!part.solo) alone += 1;
moveShape(record, part, item);
} else if (changed(radii, part, REBUILD_RADII)) rebuild = true;
}
if (rebuild && !record.pending) {
record.rebuild();
requestRender();
}
}
/**
* A clamped shape's fill geometry, on the ellipsoid for draping; an
* ellipse with a rim fill is cut finely, so its rim runs round.
* ellipse with an image fill is cut finely, so a round image's edge runs
* round.
*/
function groundGeometry(item, rimFill = null) {
function groundGeometry(item, imageFill = false) {
const g = item.geometry;
switch (g.kind) {
case 'polygon': {
@@ -3373,21 +3229,19 @@ export function createCesiumDraw({
});
}
case 'ellipse': {
// Radii by camera height are the ones it has at this frame's height.
const height = cameraHeight();
const major = radiusAt(g.semiMajor, height);
const minor = radiusAt(g.semiMinor, height);
// Radii that follow the camera apart may cross: the longer is then
// drawn as Cesium's semi-major axis, a quarter turn on.
const major = g.semiMajor;
const minor = g.semiMinor;
// A semi-minor axis longer than the semi-major one is drawn as
// Cesium's semi-major axis, a quarter turn on.
const crossed = minor > major;
return new Cesium.EllipseGeometry({
center: toCartesian(g.center),
semiMajorAxis: crossed ? minor : major,
semiMinorAxis: crossed ? major : minor,
rotation: (g.rotation ?? 0) + (crossed ? Math.PI / 2 : 0),
...(rimFill
...(imageFill
? {
granularity: RIM_GRANULARITY,
granularity: IMAGE_ELLIPSE_GRANULARITY,
vertexFormat:
Cesium.MaterialAppearance.MaterialSupport.TEXTURED
.vertexFormat,
@@ -3436,11 +3290,7 @@ export function createCesiumDraw({
typeof item.fill === 'object' && !Array.isArray(item.fill)
? item.fill
: null;
const rimFill =
objectFill?.preset === 'radialRim' && item.geometry.kind === 'ellipse'
? objectFill
: null;
const imageFill = rimFill ? null : objectFill;
const imageFill = objectFill;
if (imageFill && !imageFill.image)
throw new Error('the Cesium renderer fills shapes with colours only');
if (item.extrudeHeight !== undefined)
@@ -3457,7 +3307,7 @@ export function createCesiumDraw({
// load when they show.
let geometry;
try {
geometry = groundGeometry(item, rimFill);
geometry = groundGeometry(item, Boolean(imageFill));
} catch (error) {
if (item.show === false) continue;
throw error;
@@ -3466,8 +3316,6 @@ export function createCesiumDraw({
look: lookOf(item),
id: pickId(record, item),
ground: null,
// Radii by camera height as drawn (`followCameraHeight`).
radii: radiiOf(item),
pulse: pulseOf(item),
show: item.show !== false,
};
@@ -3477,29 +3325,17 @@ export function createCesiumDraw({
);
const instance = new Cesium.GeometryInstance({
geometry,
attributes:
imageFill || rimFill
? { show }
: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
toColor(item.fill),
),
show,
},
attributes: imageFill
? { show }
: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
toColor(item.fill),
),
show,
},
id: part.id,
});
const clampTo = item.clampTo ?? record.spec.clampTo ?? 'both';
if (rimFill) {
// A rim fill is a ground primitive of its own, with its material.
batches.push({
clampTo,
instances: [instance],
parts: [part],
rimFill,
depthBias: item.depthBias,
});
continue;
}
if (imageFill) {
// An image fill is a ground primitive of its own, with its material.
// (Cesium turns its texture wrongly across the antimeridian: its
@@ -3540,9 +3376,7 @@ export function createCesiumDraw({
const grounds = batches.map((batch) => {
const material = batch.imageFill
? imageMaterial(batch.image, batch.imageFill.repeat)
: batch.rimFill
? radialRimMaterial(batch.rimFill)
: null;
: null;
const ground = new Ground({
geometryInstances: batch.instances,
classificationType: classificationOf(batch.clampTo),
@@ -3555,15 +3389,6 @@ export function createCesiumDraw({
Cesium.MaterialAppearance.MaterialSupport.TEXTURED,
translucent: true,
flat: true,
...(batch.rimFill
? {
closed: false,
faceForward: true,
...(batch.depthBias
? { renderState: DEPTH_BIASED_STATE }
: {}),
}
: {}),
}),
}
: {}),
@@ -3943,7 +3768,6 @@ export function createCesiumDraw({
part.solo = true;
part.pendingShow = undefined;
part.look = lookOf(item);
part.radii = radiiOf(item);
part.pulse = pulseOf(item);
part.show = item.show !== false;
part.pendingColour = undefined;
@@ -4344,7 +4168,6 @@ export function createCesiumDraw({
building: () => [...sets.values()].some((record) => record.pending),
/** Each frame, before it draws: the horizon cull. */
beforeRender() {
followCameraHeight();
pulsing = runPulses();
cullHorizon();
runFlows();
+73 -168
View File
@@ -508,7 +508,7 @@ test('hidden clamped fills wait for nothing, and the hidden ones it cannot build
set.set([
fill('a', 0, false, { outline: '#000' }),
fill('b', 1, false, { extrudeHeight: 10 }),
fill('c', 2, false, { fill: { preset: 'radialRim' } }),
fill('c', 2, false, { fill: { gradient: 'radial' } }),
]),
);
assert.equal(groundsIn(scene.added.at(-1)).length, 0);
@@ -596,57 +596,22 @@ test('clamped shapes refuse what they cannot draw', () => {
fill: '#fff',
height: 'clampGround',
};
// A rim fill is drawn on ellipses alone.
// A fill that is neither a colour nor an image.
assert.throws(
() =>
set.set([
{
...disc,
geometry: {
kind: 'rectangle',
rect: { west: 0, south: 0, east: 1, north: 1 },
},
fill: {
preset: 'radialRim',
color: '#fff',
rimColor: '#fff',
rimWidth: 0.1,
},
},
]),
() => set.set([{ ...disc, fill: { gradient: 'radial' } }]),
/colours only/,
);
set.dispose();
// Radii by camera height are for clamped ellipses alone.
const unclamped = draw.shapes({ id: 'refuse-unclamped' });
assert.throws(
() =>
unclamped.set([
{
...disc,
height: 'absolute',
geometry: {
...disc.geometry,
semiMajor: { byCameraHeight: { factor: 1, min: 1, max: 2 } },
},
},
]),
/radii by camera height on clamped ellipses only/,
);
unclamped.dispose();
});
test('a clamped ellipse with radii by camera height draws at the camera height and follows it', () =>
test('a clamped colour ring whose radius alone changes is drawn alone where it now is', () =>
withTerrainHeights(() => {
const scene = fakeScene();
let height = 2000;
Object.defineProperty(scene.camera, 'positionCartographic', {
get: () => ({ height }),
});
const { draw, frame } = drawOver(scene);
const set = draw.shapes({ id: 'rings' });
const radius = { byCameraHeight: { factor: 0.03, min: 14, max: 170 } };
const ring = (show = true) => ({
// The app follows the camera's height and sends the radius it wants, as
// annotation target rings do.
const ring = (radius, show = true) => ({
id: 'ring',
geometry: {
kind: 'ellipse',
@@ -658,115 +623,65 @@ test('a clamped ellipse with radii by camera height draws at the camera height a
height: 'clampGround',
show,
});
set.set([ring()]);
set.set([ring(60)]);
const host = scene.added[0];
const radiusIn = (ground) =>
ground.geometryInstances[0].geometry._semiMajorAxis;
const last = () => host.get(host.length - 1);
assert.equal(radiusIn(last()), 60, '3% of 2000 m');
// The camera has not moved: nothing is built.
assert.equal(radiusIn(last()), 60);
const built = last();
frame();
assert.equal(last(), built);
// It climbs: the ring is drawn wider in the frame that draws it, alone.
height = 4000;
frame();
assert.equal(last(), built, 'nothing built while nothing changes');
// Wider: drawn alone, built in this frame, under its own pick id.
set.upsert([ring(120)]);
const wider = last();
assert.notEqual(wider, built);
assert.equal(wider.asynchronous, false);
assert.equal(radiusIn(wider), 120);
assert.equal(wider.geometryInstances[0].id.id, 'ring', 'its own pick id');
// Held within its bounds.
height = 1e6;
frame();
assert.equal(radiusIn(last()), 170);
height = 10;
frame();
set.upsert([ring(14)]);
assert.equal(radiusIn(last()), 14);
// Hidden, it waits; shown, it catches up.
set.upsert([ring(false)]);
const lastShown = last();
height = 3000;
frame();
assert.equal(last(), lastShown, 'hidden: not rebuilt');
set.upsert([ring(true)]);
frame();
assert.equal(radiusIn(last()), 90);
assert.equal(scene.added[0], host, 'never a rebuild of the set');
set.dispose();
assert.equal(scene.added.length, 0);
}));
test('radii by camera height that cross draw the longer as the major axis; past the cap of shapes drawn alone, the set rebuilds', () =>
test('a semi-minor axis longer than the semi-major is drawn as the major axis, a quarter turn on', () =>
withTerrainHeights(() => {
const scene = fakeScene();
let height = 1000;
Object.defineProperty(scene.camera, 'positionCartographic', {
get: () => ({ height }),
});
const { draw, frame } = drawOver(scene);
const { draw } = drawOver(scene);
const set = draw.shapes({ id: 'crossing' });
const ring = (id, lon) => ({
id,
geometry: {
kind: 'ellipse',
center: { lon, lat: 0 },
semiMajor: { byCameraHeight: { factor: 0.03, min: 14, max: 170 } },
semiMinor: { byCameraHeight: { factor: 0.05, min: 20, max: 100 } },
rotation: 0.25,
set.set([
{
id: 'r',
geometry: {
kind: 'ellipse',
center: { lon: 0, lat: 0 },
semiMajor: 30,
semiMinor: 50,
rotation: 0.25,
},
fill: [0.5, 0.9, 1, 0.38],
height: 'clampGround',
},
fill: [0.5, 0.9, 1, 0.38],
height: 'clampGround',
});
const rings = Array.from({ length: MOVING_SHAPES + 4 }, (_, i) =>
ring(`r${i}`, i * 0.1),
);
assert.doesNotThrow(() => set.set(rings));
const first = scene.added[0];
const ground = (host) => {
for (let i = 0; i < host.length; i++)
if (host.get(i) instanceof Cesium.GroundPrimitive) return host.get(i);
return null;
};
const geometry = ground(first).geometryInstances[0].geometry;
assert.equal(geometry._semiMajorAxis, 50, 'the longer, 5% of 1000 m');
]);
const host = scene.added[0];
let ground = null;
for (let i = 0; i < host.length; i++)
if (host.get(i) instanceof Cesium.GroundPrimitive) ground = host.get(i);
const geometry = ground.geometryInstances[0].geometry;
assert.equal(geometry._semiMajorAxis, 50);
assert.equal(geometry._semiMinorAxis, 30);
assert.ok(Math.abs(geometry._rotation - (0.25 + Math.PI / 2)) < 1e-12);
// Its batches built.
for (let i = 0; i < first.length; i++)
if (first.get(i) instanceof Cesium.GroundPrimitive) {
Object.defineProperty(first.get(i), 'ready', { value: true });
first.get(i).getGeometryInstanceAttributes = () => ({
show: new Uint8Array([1]),
});
}
frame();
// The camera climbs: no more than the cap are drawn alone; the set
// rebuilds for the rest, and nothing throws in the frame.
height = 1500;
assert.doesNotThrow(() => frame());
let solo = 0;
for (let i = 0; i < first.length; i++) {
const p = first.get(i);
if (p instanceof Cesium.GroundPrimitive && p.asynchronous === false)
solo += 1;
}
assert.equal(solo, MOVING_SHAPES);
assert.notEqual(scene.added.at(-1), first, 'rebuilt for the rest');
set.dispose();
}));
test('rings drawn alone by a host still retiring count toward the cap when the camera moves again', () =>
test('rings that would be drawn alone past the cap rebuild their set, counting those a retiring host draws alone', () =>
withTerrainHeights(() => {
const scene = fakeScene();
let height = 1000;
Object.defineProperty(scene.camera, 'positionCartographic', {
get: () => ({ height }),
});
const { draw, frame } = drawOver(scene);
const set = draw.shapes({ id: 'climbing' });
const radius = { byCameraHeight: { factor: 0.03, min: 14, max: 170 } };
const rings = Array.from({ length: MOVING_SHAPES + 4 }, (_, i) => ({
const ring = (i, radius) => ({
id: `r${i}`,
geometry: {
kind: 'ellipse',
@@ -776,7 +691,9 @@ test('rings drawn alone by a host still retiring count toward the cap when the c
},
fill: [0.5, 0.9, 1, 0.38],
height: 'clampGround',
}));
});
const all = (radius, from = 0, to = MOVING_SHAPES + 4) =>
Array.from({ length: to - from }, (_, k) => ring(from + k, radius));
const ready = (host) => {
for (let i = 0; i < host.length; i++)
if (host.get(i) instanceof Cesium.GroundPrimitive) {
@@ -795,21 +712,22 @@ test('rings drawn alone by a host still retiring count toward the cap when the c
}
return n;
};
set.set(rings);
set.set(all(30));
const first = scene.added[0];
ready(first);
frame();
// A climb: the cap drawn alone, and a rebuild for the rest.
height = 1500;
frame();
// The cap moves alone.
set.upsert(all(45, 0, MOVING_SHAPES));
assert.equal(solo(first), MOVING_SHAPES);
assert.equal(scene.added.at(-1), first);
// One more would pass it: the set rebuilds, the old host retiring.
set.upsert(all(45, MOVING_SHAPES));
const second = scene.added.at(-1);
assert.notEqual(second, first, 'rebuilding, the old host retiring');
ready(second);
// Climbing on while the old host retires: its rings drawn alone still
// count, so none more are drawn alone.
height = 2500;
frame();
// While the old host retires, its rings drawn alone still count, so
// none more are drawn alone.
set.upsert([ring(0, 75)]);
assert.equal(solo(second), 0, 'nothing more drawn alone');
set.dispose();
}));
@@ -4224,12 +4142,7 @@ test('an unclamped shape filled with an image draws a textured primitive and fre
kind: 'rectangle',
rect: { west: 0, south: 0, east: 1, north: 1 },
},
fill: {
preset: 'radialRim',
color: '#fff',
rimColor: '#000',
rimWidth: 1,
},
fill: { gradient: 'radial' },
},
]),
/colours only/,
@@ -4564,7 +4477,7 @@ test('a line with a depth-fail colour draws it behind the surface, and moves in
widthPx: 2.5,
mode: 'geodesic',
style: { kind: 'solid', color: [1, 0, 1, 0.9] },
depthFailColor: [1, 0, 1, 0.45],
depthFail: { kind: 'solid', color: [1, 0, 1, 0.45] },
meta: height,
...extra,
});
@@ -4579,7 +4492,7 @@ test('a line with a depth-fail colour draws it behind the surface, and moves in
widthPx: 1,
mode: '3d',
style: { kind: 'solid', color: '#fff' },
depthFailColor: null,
depthFail: null,
},
]);
const host = scene.added[0];
@@ -4629,13 +4542,15 @@ test('a line with a depth-fail colour draws it behind the surface, and moves in
assert.equal(deep.length, 1);
assert.equal(deep.get(0).show, false, 'hidden as asked');
// A new colour is a new look: rebuilt.
set.upsert([head(400, { depthFailColor: [1, 1, 1, 1] })]);
set.upsert([
head(400, { depthFail: { kind: 'solid', color: [1, 1, 1, 1] } }),
]);
assert.notEqual(scene.added[0], host);
set.dispose();
assert.equal(scene.added.length, 0);
}));
test('a depth-fail dash dashes the parts behind the surface, in the depth-fail colour', () =>
test('a dashed depth-fail style dashes the parts behind the surface, in its colour', () =>
withImageClasses(() => {
const { scene, draw } = drawOver();
const set = draw.lines({ id: 'band' });
@@ -4648,8 +4563,7 @@ test('a depth-fail dash dashes the parts behind the surface, in the depth-fail c
widthPx: 3,
mode: 'geodesic',
style: { kind: 'dash', color: [1, 1, 0, 0.9], length: 16 },
depthFailColor: [0, 1, 1, 0.35],
depthFailDash: { length: 16 },
depthFail: { kind: 'dash', color: [0, 1, 1, 0.35], length: 16 },
...extra,
});
set.set([band()]);
@@ -4666,21 +4580,27 @@ test('a depth-fail dash dashes the parts behind the surface, in the depth-fail c
assert.equal(hidden.uniforms.dashLength, 16);
assert.equal(hidden.uniforms.dashPattern, 255, 'the default pattern');
// A move keeps the dash; its fields in another order are the same look.
set.upsert([band({ depthFailDash: { length: 16 } })]);
set.upsert([
band({ depthFail: { length: 16, color: [0, 1, 1, 0.35], kind: 'dash' } }),
]);
assert.equal(scene.added[0], host, 'not rebuilt');
assert.equal(
host.get(1).get(0).depthFailAppearance.material.type,
'PolylineDash',
);
set.upsert([band({ depthFailDash: { pattern16: 0xf0f0, length: 8 } })]);
const patternedBand = (fields) =>
band({ depthFail: { kind: 'dash', color: [0, 1, 1, 0.35], ...fields } });
set.upsert([patternedBand({ pattern16: 0xf0f0, length: 8 })]);
const patterned = scene.added[0].get(1).get(0).depthFailAppearance.material;
assert.equal(patterned.uniforms.dashPattern, 0xf0f0);
assert.equal(patterned.uniforms.dashLength, 8);
const again = scene.added[0];
set.upsert([band({ depthFailDash: { length: 8, pattern16: 0xf0f0 } })]);
set.upsert([patternedBand({ length: 8, pattern16: 0xf0f0 })]);
assert.equal(scene.added[0], again, 'the same dash in another order');
// Without it the hidden parts are solid; the change is a new look.
set.upsert([band({ depthFailDash: undefined })]);
// Solid behind the surface: a new look.
set.upsert([
band({ depthFail: { kind: 'solid', color: [0, 1, 1, 0.35] } }),
]);
assert.notEqual(scene.added[0], host, 'rebuilt');
const solid = scene.added[0].get(1).get(0).depthFailAppearance.material;
assert.equal(solid.type, 'Color');
@@ -5456,7 +5376,7 @@ test('where the scene cannot drape, an overlay line is culled by its whole arc,
],
widthPx: 2,
mode: '3d',
depthFailColor: [1, 0, 0, 1],
depthFail: { kind: 'solid', color: [1, 0, 0, 1] },
style: { kind: 'solid', color: [1, 0, 0, 1] },
},
]);
@@ -5615,7 +5535,7 @@ test('revealFraction reveals flow and depth-fail lines too, their clocks still r
widthPx: 2,
mode: '3d',
style: { kind: 'solid', color: '#f0f' },
depthFailColor: [1, 0, 1, 0.45],
depthFail: { kind: 'solid', color: [1, 0, 1, 0.45] },
revealFraction: 0.5,
},
]);
@@ -6889,7 +6809,7 @@ test('a pattern line draws its image along it, repeated, and an inertial line tu
assert.equal(scene.added.length, 0);
}));
test('a clamped ellipse filled with a radial rim drapes its material, finely cut, pulled toward the eye', () =>
test('a clamped ellipse with an image fill drapes its material, finely cut so a round image runs round', () =>
withImageClasses(() => {
const { scene, draw } = drawOver();
const set = draw.shapes({ id: 'pad-zone' });
@@ -6901,14 +6821,8 @@ test('a clamped ellipse filled with a radial rim drapes its material, finely cut
semiMajor: 500,
semiMinor: 500,
},
fill: {
preset: 'radialRim',
color: [0.13, 0.9, 0.9, 0.105],
rimColor: [0.13, 0.9, 0.9, 0.72],
rimWidth: 0.033,
},
fill: { image: 'zone.png' },
height: 'clampGround',
depthBias: 1,
};
set.set([zone]);
const host = scene.added[0];
@@ -6918,17 +6832,8 @@ test('a clamped ellipse filled with a radial rim drapes its material, finely cut
assert.ok(ground);
const { appearance } = ground;
assert.ok(appearance instanceof Cesium.MaterialAppearance);
assert.equal(appearance.material.type, 'DrawRadialRimFill');
const { color, rimColor, rimWidth } = appearance.material.uniforms;
assert.ok(
color.equalsEpsilon(new Cesium.Color(0.13, 0.9, 0.9, 0.105), 1e-9),
);
assert.ok(
rimColor.equalsEpsilon(new Cesium.Color(0.13, 0.9, 0.9, 0.72), 1e-9),
);
assert.equal(rimWidth, 0.033);
assert.equal(appearance.renderState.polygonOffset.enabled, true);
assert.equal(appearance.renderState.depthMask, false);
assert.equal(appearance.material.type, 'Image');
assert.equal(appearance.material.uniforms.image, 'zone.png');
assert.equal(ground.classificationType, Cesium.ClassificationType.BOTH);
const [instance] = ground.geometryInstances;
assert.ok(instance.geometry instanceof Cesium.EllipseGeometry);
+2 -2
View File
@@ -44,7 +44,7 @@ export const CESIUM_CHECKS = new Set([
'draw.field.windStreamlines',
'draw.icons.distance',
'draw.icons.update',
'draw.lines.depthFailDash',
'draw.lines.depthFail',
'draw.lines.settled',
'draw.lines.styles',
'draw.lines.drape',
@@ -65,7 +65,7 @@ export const CESIUM_CHECKS = new Set([
'draw.displayRange',
'draw.sets',
'draw.shapes.drapedRotation',
'draw.shapes.radiusByCameraHeight',
'draw.shapes.resize',
'effects.crossfade',
'effects.defineStyle',
'effects.screenModulation',
+20
View File
@@ -6,6 +6,12 @@
* reference recorder's own.
*/
import { wheelLines } from '../input/wheel.js';
import {
eyeMoved,
eyeRotatedAbout,
eyeTurned,
eyeZoomed,
} from '../../geo/eyeMoves.js';
const NO_MODIFIERS = Object.freeze({
shift: false,
@@ -187,6 +193,18 @@ function resolveArgs(driver, name, args) {
return args;
}
/**
* Script steps that are the app's own sums over the pose, not port verbs: the
* contract driver turns them into `setView`, where the reference recorder
* runs Cesium's matching camera functions.
*/
const EYE_STEPS = {
move: eyeMoved,
look: eyeTurned,
rotateAround: eyeRotatedAbout,
zoom: eyeZoomed,
};
/**
* A driver over a renderer, through the contract only.
* @param {import('../contract/renderer').Renderer} renderer
@@ -200,6 +218,8 @@ export function contractDriver(renderer, hooks) {
const camera = renderer.camera;
return {
command(name, args) {
if (Object.hasOwn(EYE_STEPS, name))
return camera.setView(EYE_STEPS[name](camera.pose(), ...args));
return camera[name](...args);
},
frame: hooks.frame,
+1 -1
View File
@@ -253,7 +253,7 @@ export const CAMERA_SCRIPTS = Object.freeze([
},
{ do: 'move', args: ['forward', 500] },
{ record: 'pose' },
{ do: 'rotateAround', args: [{ x: 0, y: 0, z: 1 }, 0.4] },
{ do: 'look', args: ['left', 0.4] },
{ record: 'pose' },
{ do: 'zoom', args: [-1000] },
{ record: 'pose' },
+2 -1
View File
@@ -10,6 +10,7 @@ import {
} from '../cameraScripts.js';
import { contractDriver, runCameraScript } from '../cameraRunner.js';
import { deepEqual, equal, near, nearAngle, nearVec, ok } from '../expect.js';
import { eyeMoved } from '../../../geo/eyeMoves.js';
const lonLatToEcef = (h) => h.toEcef;
@@ -389,7 +390,7 @@ export function cameraChecks() {
r.camera.on('moveEnd', () => events.push(['end', h.now(r)]));
await h.frame(r);
const movingAt = h.now(r);
r.camera.move('forward', 1000);
r.camera.setView(eyeMoved(r.camera.pose(), 'forward', 1000));
await h.frame(r);
equal(events[0]?.[0], 'start', 'moveStart after the move');
const movedAt = h.now(r);
+27 -32
View File
@@ -1714,7 +1714,7 @@ export function portChecks() {
},
),
check(
'draw.lines.depthFailDash',
'draw.lines.depthFail',
'a line dashed behind the surface draws, moves in place and changes back to solid',
async (h, r) => {
await overAustin(h, r);
@@ -1727,8 +1727,7 @@ export function portChecks() {
widthPx: 3,
mode: 'geodesic',
style: { kind: 'dash', color: [1, 1, 0, 0.9], length: 16 },
depthFailColor: [0, 1, 1, 0.35],
depthFailDash: { length: 16 },
depthFail: { kind: 'dash', color: [0, 1, 1, 0.35], length: 16 },
...extra,
});
lines.set([band(-200)]);
@@ -1737,7 +1736,9 @@ export function portChecks() {
lines.upsert([band(-100)]);
await drawn(h, r);
equal(lines.size(), 1, 'moved in place, not added');
lines.upsert([band(-100, { depthFailDash: undefined })]);
lines.upsert([
band(-100, { depthFail: { kind: 'solid', color: [0, 1, 1, 0.35] } }),
]);
await drawn(h, r);
equal(lines.size(), 1, 'solid behind the surface again');
lines.dispose();
@@ -1877,24 +1878,21 @@ export function portChecks() {
},
),
check(
'draw.shapes.radiusByCameraHeight',
'a clamped ellipse with radii by camera height draws at the radius the camera height gives, held within its bounds, and follows the camera',
'draw.shapes.resize',
'a clamped ellipse whose radius alone is upserted draws at the new radius, growing and shrinking',
async (h, r) => {
const shapes = r.draw.shapes({ id: 'conf:rings' });
const radius = { byCameraHeight: { factor: 0.1, min: 50, max: 600 } };
shapes.set([
{
id: 'ring',
geometry: {
kind: 'ellipse',
center: { lon: AUSTIN.lon, lat: AUSTIN.lat },
semiMajor: radius,
semiMinor: radius,
},
fill: [0.5, 0.9, 1, 0.6],
height: 'clampGround',
const ring = (radius) => ({
id: 'ring',
geometry: {
kind: 'ellipse',
center: { lon: AUSTIN.lon, lat: AUSTIN.lat },
semiMajor: radius,
semiMinor: radius,
},
]);
fill: [0.5, 0.9, 1, 0.6],
height: 'clampGround',
});
// Metres east of the centre, at its latitude.
const east = (m) =>
h.toEcef({
@@ -1919,22 +1917,19 @@ export function portChecks() {
}
return false;
};
// 2000 m up: 200 m across its centre.
await overAustin(h, r, 2000);
ok(await until(() => covers(150)), 'at 2000 m it reaches 150 m');
ok(!covers(260), 'and not 260 m');
// 4000 m up: 400 m.
await overAustin(h, r, 4000);
shapes.set([ring(200)]);
ok(
await until(() => covers(150) && !covers(260)),
'at 200 m it reaches 150 m, not 260 m',
);
shapes.upsert([ring(400)]);
ok(
await until(() => covers(300) && !covers(460)),
'at 4000 m it reaches 300 m, not 460 m',
);
// 20 km up: held at 600 m.
await overAustin(h, r, 20000);
ok(
await until(() => covers(550) && !covers(700)),
'held at its largest',
'at 400 m it reaches 300 m, not 460 m',
);
shapes.upsert([ring(200)]);
ok(await until(() => covers(150) && !covers(260)), 'back at 200 m');
shapes.dispose();
await drawn(h, r);
ok(!covers(0), 'gone with its set');
@@ -1961,7 +1956,7 @@ export function portChecks() {
widthPx: 3,
mode: '3d',
style: { kind: 'solid', color: '#ff00ff' },
depthFailColor: [1, 0, 1, 0.45],
depthFail: { kind: 'solid', color: [1, 0, 1, 0.45] },
});
lines.set([
{
+48 -48
View File
@@ -1117,29 +1117,29 @@
"kind": "pose",
"value": {
"position": {
"x": -744971.9139187913,
"y": -5464375.678277303,
"z": 3195735.7092693974
"x": -744481.3426810508,
"y": -5464789.733339174,
"z": 3195145.9335938734
},
"direction": {
"x": 0.8577979868850266,
"y": 0.50373228948861,
"z": 0.10215867179324013
"x": 0.3312543721140628,
"y": 0.7819390858650948,
"z": 0.5280547385941896
},
"up": {
"x": 0.33601932677210566,
"y": -0.6999992672201266,
"z": 0.6301523926217426
"x": 0.22881921132251012,
"y": -0.6095195427272047,
"z": 0.7590307606173572
},
"right": {
"x": 0.38893910285752537,
"y": -0.5062161657018166,
"z": -0.7697217470297525
"x": 0.915375501903488,
"y": -0.13060318920332545,
"z": -0.38082869834724636
},
"heading": 1.099821436536688,
"pitch": -0.5003437292588502,
"roll": 6.283185070682873,
"height": 1198.9411841126202,
"heading": 0.25083973344668564,
"pitch": -0.45766939657173955,
"roll": 0.20978125179289364,
"height": 1198.941902759726,
"frameIsIdentity": false
}
},
@@ -1148,29 +1148,29 @@
"kind": "pose",
"value": {
"position": {
"x": -745829.7119056764,
"y": -5464879.410566793,
"z": 3195633.5505976044
"x": -744812.5970531654,
"y": -5465571.672425042,
"z": 3194617.878855279
},
"direction": {
"x": 0.8577979868850265,
"y": 0.5037322894886102,
"z": 0.10215867179324012
"x": 0.33125437211406306,
"y": 0.7819390858650948,
"z": 0.5280547385941895
},
"up": {
"x": 0.33601932677210533,
"y": -0.6999992672201268,
"z": 0.6301523926217425
"x": 0.22881921132251018,
"y": -0.6095195427272047,
"z": 0.7590307606173573
},
"right": {
"x": 0.3889391028575255,
"y": -0.5062161657018166,
"z": -0.7697217470297526
"x": 0.9153755019034878,
"y": -0.1306031892033257,
"z": -0.38082869834724653
},
"heading": 1.0997500524431754,
"pitch": -0.5004811848386681,
"roll": 6.283184976084162,
"height": 1678.7289113419563,
"heading": 0.2508194571959139,
"pitch": -0.45781035725623687,
"roll": 0.20978111856887782,
"height": 1640.8642564622487,
"frameIsIdentity": false
}
},
@@ -1179,29 +1179,29 @@
"kind": "pose",
"value": {
"position": {
"x": -745829.7119056764,
"y": -5464879.410566793,
"z": 3195633.5505976044
"x": -744812.5970531654,
"y": -5465571.672425042,
"z": 3194617.878855279
},
"direction": {
"x": 0.8577979868850266,
"y": 0.5037322894886103,
"z": 0.1021586717932402
"x": 0.3312543721140633,
"y": 0.7819390858650948,
"z": 0.5280547385941896
},
"up": {
"x": 0.33601932677210533,
"y": -0.6999992672201268,
"z": 0.6301523926217425
"x": 0.22881921132251018,
"y": -0.6095195427272047,
"z": 0.7590307606173573
},
"right": {
"x": 0.3889391028575255,
"y": -0.5062161657018165,
"z": -0.7697217470297525
"x": 0.9153755019034878,
"y": -0.13060318920332578,
"z": -0.3808286983472466
},
"heading": 1.0997500524431754,
"pitch": -0.5004811848386681,
"roll": 6.283184976084162,
"height": 1678.7289113419563,
"heading": 0.2508194571959148,
"pitch": -0.4578103572562373,
"roll": 0.20978111856887693,
"height": 1640.8642564622487,
"frameIsIdentity": true
}
}
+7 -7
View File
@@ -208,6 +208,13 @@ export type CameraEvent =
export interface CameraPort {
pose(): CameraPose;
/**
* Place the eye. A position with a `{direction, up}` orientation is placed
* exactly as given (`up` made square to `direction`), never rounded
* through heading, pitch and roll: the application's step moves (pans, turns, the
* globe turned under the eye, zooms; `geo/eyeMoves`) are such views,
* sent many times over.
*/
setView(view: ViewSpec): void;
setFov(fov: { vertical: number }): void;
/**
@@ -236,13 +243,6 @@ export interface CameraPort {
lookAt(target: Ecef, offset: HeadingPitchRange): void;
/** Leave `lookAt` for the world frame. */
release(): void;
move(
direction: 'forward' | 'back' | 'left' | 'right' | 'up' | 'down',
metres: number,
): void;
look(direction: 'left' | 'right' | 'up' | 'down', radians: number): void;
rotateAround(axis: Vec3, radians: number): void;
zoom(metres: number): void;
/**
* Follow `target`, or stop following with null; `followChanged` fires
* whenever `followed` changes, and only then.
+1 -1
View File
@@ -183,7 +183,7 @@ test('members added to version 0 later are optional, each behind its capability'
Object.fromEntries(
members(checker.getTypeAtLocation(declared(shape).name)),
)[field];
assert.equal(optional('LineItem', 'depthFailDash'), true);
assert.equal(optional('LineItem', 'depthFail'), true);
// And on one kind of a union: the rectangle's rotation.
const rectangle = checker
.getTypeAtLocation(declared('ShapeGeometry').name)
+18 -27
View File
@@ -212,15 +212,11 @@ export interface LineItem {
mode: '3d' | 'geodesic' | 'draped';
clampTo?: ClampTarget;
style: LineStyle;
/** Colour where the line is behind the surface; `null` hides those parts. */
depthFailColor?: Color | null;
/**
* Dash the parts behind the surface, in `depthFailColor`, as a `dash`
* style's `length` and `pattern16` dash a line. Omitted, they are solid; a
* renderer that predates it draws them solid too. Ignored without a
* `depthFailColor`, and on draped lines, which are never behind it.
* How the parts behind the surface draw, solid or dashed; omitted or
* `null` hides them. Ignored on draped lines, which are never behind it.
*/
depthFailDash?: { length: number; pattern16?: number };
depthFail?: Extract<LineStyle, { kind: 'solid' | 'dash' }> | null;
/** Per-segment colours; changing them does not rebuild the line. */
segmentColors?: Color[];
segmentShow?: boolean[];
@@ -233,25 +229,23 @@ export interface LineItem {
pickable?: boolean;
}
/** A shape's fill. */
export type Fill =
| Color
| { image: ImageRef; repeat?: [number, number] }
| { preset: 'radialRim'; color: Color; rimColor: Color; rimWidth: number };
/**
* A shape's fill: a colour, or an image stretched over the shape's extent
* (`repeat` times across and up). A canvas image sent again with a new
* `key` is new content.
*/
export type Fill = Color | { image: ImageRef; repeat?: [number, number] };
/** Declarative animation the renderer runs (no per-frame callbacks). */
/**
* Declarative animation the renderer runs (no per-frame callbacks): the
* fill's and outline's alpha swings between `from` and `to` and back every
* `periodMs`, forever.
*/
export interface Pulse {
property: 'radius' | 'alpha';
property: 'alpha';
from: number;
to: number;
periodMs: number;
/** Repeat count; omitted repeats forever. */
repeat?: number;
}
/** A radius that follows the camera's height above the ground. */
export interface RadiusByCameraHeight {
byCameraHeight: { factor: number; min: number; max: number };
}
export type ShapeGeometry =
@@ -259,12 +253,11 @@ export type ShapeGeometry =
| {
kind: 'ellipse';
center: Position;
semiMajor: number | RadiusByCameraHeight;
semiMinor: number | RadiusByCameraHeight;
/** Metres. */
semiMajor: number;
semiMinor: number;
/** Radians counter-clockwise from north to the semi-major axis. */
rotation?: number;
/** Only part of the ellipse, radians from north. */
arc?: { start: number; end: number };
}
/**
* `height`: metres above the ellipsoid, for a rectangle not clamped.
@@ -292,8 +285,6 @@ export interface ShapeItem {
extrudeHeight?: number;
height?: 'absolute' | 'clampGround';
clampTo?: ClampTarget;
/** Pull toward the eye, metres, to win depth against coplanar surfaces. */
depthBias?: number;
/**
* Shaded by the renderer's fixed light (true) or flat colour (false).
* Omitted: lit for extruded shapes, flat otherwise. A renderer
+2 -2
View File
@@ -46,8 +46,8 @@ export interface StyleDefinition extends StyleDescriptor {
* full inside the band, each by where its anchor is on screen; the map,
* lines and shapes draw as they are, and picks are unchanged. A radius of 0
* dims every marker to `floor` (the theme on, the sweep off). Setting a
* sector, or clearing it, asks for one frame; the app sets it again at
* `sonarCadenceHz`.
* sector, or clearing it, asks for one frame; the application moves it about every
* 80 ms while it sweeps.
* `diagnostics().passes` lists `'screenModulation'` while it draws, so a
* sector set but not listed is unsupported.
*/
-5
View File
@@ -74,7 +74,6 @@ export const QUALITY_KEYS = Object.freeze([
'particles',
'models',
'postFx',
'sonarCadenceHz',
'targetFps',
]);
@@ -174,10 +173,6 @@ export const PORTS = deepFreeze({
'flying',
'lookAt',
'release',
'move',
'look',
'rotateAround',
'zoom',
'follow',
'followed',
'followFramed',
-2
View File
@@ -26,8 +26,6 @@ export interface QualitySettings {
models: { maxInstances: number; maxDistance: number };
/** Detail of the post-processing passes; bloom and sharpen are switched in `effects`. */
postFx: 'low' | 'high';
/** Updates per second of a screen modulation sweep. */
sonarCadenceHz: number;
targetFps: number;
}
-46
View File
@@ -607,48 +607,6 @@ export function createStubCamera({
finishFlight('cancelled');
}
function move(dir, metres) {
const axis = {
forward: direction,
back: negate(direction),
right,
left: negate(right),
up,
down: negate(up),
}[dir];
position = add(position, scale(axis, metres));
requestRender('camera');
}
function look(dir, radians) {
const [axis, sign] = {
left: [up, -1],
right: [up, 1],
up: [right, -1],
down: [right, 1],
}[dir];
const a = clone(axis);
const angle = -(sign * radians);
direction = rotate(direction, a, angle);
up = rotate(up, a, angle);
right = rotate(right, a, angle);
requestRender('camera');
}
function rotateAround(axis, radians) {
const a = normalize(axis);
position = rotate(position, a, -radians);
direction = rotate(direction, a, -radians);
up = rotate(up, a, -radians);
right = cross(direction, up);
up = cross(right, direction);
requestRender('camera');
}
function zoom(metres) {
move('forward', metres);
}
// --- Follow ----------------------------------------------------------------
/** Where the target is drawn, for a drawn item; otherwise its own answer. */
@@ -797,10 +755,6 @@ export function createStubCamera({
},
lookAt,
release,
move,
look,
rotateAround,
zoom,
follow,
get followed() {
return followed;
+3 -19
View File
@@ -707,23 +707,11 @@ export function createStubRenderer(options = {}) {
);
}
/** The eye's height above the ellipsoid, for radii by camera height. */
const eyeHeight = () => toCartographicRadians(eye().position)?.height ?? 0;
/**
* Whether `lon`, `lat` (degrees) is in an ellipse geometry, its radii by
* camera height at the eye's height, measured in the plane tangent at its
* centre.
* Whether `lon`, `lat` (degrees) is in an ellipse geometry, measured in
* the plane tangent at its centre.
*/
function inEllipse(g, lon, lat) {
const height = eyeHeight();
const radius = (r) =>
typeof r === 'number'
? r
: Math.max(
r.byCameraHeight.min,
Math.min(r.byCameraHeight.max, height * r.byCameraHeight.factor),
);
const centre = toCartographicRadians(toEcef(g.center));
const metresPerRadian = 6378137;
const east =
@@ -735,11 +723,7 @@ export function createStubRenderer(options = {}) {
const turn = g.rotation ?? 0;
const along = north * Math.cos(turn) - east * Math.sin(turn);
const across = north * Math.sin(turn) + east * Math.cos(turn);
return (
(along / radius(g.semiMajor)) ** 2 +
(across / radius(g.semiMinor)) ** 2 <=
1
);
return (along / g.semiMajor) ** 2 + (across / g.semiMinor) ** 2 <= 1;
}
/**