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',