Draw rocket launches through the renderer ports, off Cesium

The launches layer's sites, markers, reticles, mission lines, live orbit
rings and pad zone are now renderer draw sets. Picks go through the query
port, double-click follow through the camera port (shared with other layers
in src/data/stockFollow.js), and per-frame work through the frame port.
rendering.js, orbitRendering.js and launchPad.js leave the Cesium list.

The Cesium draw port gains what these need: pattern line styles, lines in
the inertial frame turned each frame by the set's motion clock, radial-rim
fills on clamped ellipses with a depth bias, and parking for hidden lines
that cannot settle into a static batch, so a hidden line no longer costs a
draw each frame. A roster writes each set once, and a followed live payload
shares one position sample with its marker each frame.
This commit is contained in:
Sameh Khamis committed 2026-11-08 11:26:21 -08:00
1 parent fa762f808e
commit 4a9b1389ba
22 files changed
+1476 -717

No files matched your search

+222 -20
View File
@@ -32,6 +32,7 @@
* `findDraw` for one (`rendererOf.js`).
*/
import * as Cesium from 'cesium';
import { temeToPseudoFixed } from '../../geo/celestial.js';
import { alongLength } from '../../geo/polyline.js';
import { provideUnboundDraw } from '../rendererOf.js';
import { listenerList, toCartesian, uncaught } from './common.js';
@@ -185,6 +186,56 @@ 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.
*/
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,
});
/** 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;
}
/** The line styles the port drapes. */
const DRAPED_STYLES = new Set(['solid', 'glow', 'dash', 'flow']);
@@ -1385,9 +1436,12 @@ export function createCesiumDraw({
// values in the fabric would be merged into copies of the type's.
const template = ({ type, source, uniforms }) =>
source ? { type, source, uniforms } : { type };
// A pattern's image carries its own alpha: drawn in the translucent
// pass, whatever its colour.
const translucent = style.kind === 'pattern' ? { translucent: true } : {};
const material =
reveal === undefined
? new Cesium.Material({ fabric: template(fabric) })
? new Cesium.Material({ fabric: template(fabric), ...translucent })
: new Cesium.Material({
fabric: {
type: `${REVEAL_MATERIAL}_${style.kind}`,
@@ -1395,6 +1449,7 @@ export function createCesiumDraw({
uniforms: { reveal },
source: REVEAL_SOURCE,
},
...translucent,
});
const drawn = reveal === undefined ? material : material.materials.revealed;
Object.assign(drawn.uniforms, fabric.uniforms);
@@ -1467,6 +1522,15 @@ export function createCesiumDraw({
type: 'PolylineArrow',
uniforms: { color: toColor(style.color) },
};
case 'pattern':
// The image along the line `repeat` times, across its width once.
return {
type: 'Image',
uniforms: {
image: toImage(style.image),
repeat: new Cesium.Cartesian2(style.repeat, 1),
},
};
default:
throw new Error(`the Cesium renderer has no ${style.kind} lines`);
}
@@ -1628,6 +1692,28 @@ export function createCesiumDraw({
});
}
/**
* Turn a line set's inertial lines to the sky at its motion clock's time
* now: the frame rotated by sidereal time from the Earth-fixed one.
*/
function turnInertial(record) {
const lines = record.inertialLines;
if (!lines || lines.isDestroyed()) return;
const clock = record.spec.motionClock;
const ms =
clock?.kind === 'scene'
? Cesium.JulianDate.toDate(
scene.frameState?.time ?? Cesium.JulianDate.now(),
).getTime()
: Date.now() - (clock?.delayMs ?? 0);
const { x, y, z } = temeToPseudoFixed(ms);
lines.modelMatrix = Cesium.Matrix4.fromRotationTranslation(
new Cesium.Matrix3(x.x, y.x, z.x, x.y, y.y, z.y, x.z, y.z, z.z),
Cesium.Cartesian3.ZERO,
lines.modelMatrix,
);
}
function buildLines(record) {
// Refused before anything changes, so the set keeps drawing as it was.
for (const item of record.items.values())
@@ -1635,6 +1721,13 @@ export function createCesiumDraw({
throw new Error(
'the Cesium renderer drapes solid, glow, dash and flow lines only',
);
else if (
item.frame === 'inertial' &&
(item.mode === 'draped' || item.depthFailColor)
)
throw new Error(
'the Cesium renderer draws inertial lines undraped, without depth-fail colours',
);
else if (
segmented(item) &&
(item.mode !== 'draped' ||
@@ -1645,6 +1738,8 @@ export function createCesiumDraw({
'the Cesium renderer colours and shows segments of draped solid lines only',
);
const polylines = new Cesium.PolylineCollection();
// Lines in the inertial frame, turned with the sky each frame.
let inertial = null;
const draped = new Map();
// Draped glow lines that look alike: one ground primitive and one
// material for them all, so they recolour together in place.
@@ -1712,8 +1807,37 @@ export function createCesiumDraw({
continue;
}
const id = pickId(record, item);
const { polyline, reveal } = addPolyline(record, polylines, item, id);
if (item.frame === 'inertial') {
inertial ??= new Cesium.PolylineCollection();
const { polyline, reveal, parked } = addPolyline(
record,
inertial,
item,
id,
true,
);
// Never settled into a static batch, which would not turn.
parts.set(item.id, {
look: lineLook(item),
shape: null,
positions: null,
id,
polyline,
reveal,
parked,
home: inertial,
batched: null,
});
continue;
}
const settled = settles(item);
const { polyline, reveal, parked } = addPolyline(
record,
polylines,
item,
id,
!settled,
);
parts.set(item.id, {
look: lineLook(item),
// How it draws but for its colour, and where it runs, to tell a
@@ -1723,6 +1847,9 @@ export function createCesiumDraw({
id,
polyline,
reveal,
// Hidden, out of the collection until it shows (`addPolyline`).
parked,
home: polylines,
// Drawn in the set's static batch instead (`settleLines`).
batched: null,
});
@@ -1731,12 +1858,15 @@ export function createCesiumDraw({
// Lines in the collection that can settle into a static batch draw
// beside it once they do.
const settling = [...record.items.values()].some(settles);
if (deep || settling) {
if (deep || settling || inertial) {
own = new Cesium.PrimitiveCollection();
own.add(polylines);
if (deep) own.add(deep);
if (inertial) own.add(inertial);
}
record.deepLines = deep;
record.inertialLines = inertial;
if (inertial) turnInertial(record);
record.polylines = polylines;
record.lineBox = settling ? own : null;
record.batch = null;
@@ -1995,6 +2125,7 @@ export function createCesiumDraw({
return false;
// A viewer destroyed under the set took its batch with it.
if (was.batched?.isDestroyed()) return false;
if (was.home?.isDestroyed()) return false;
looks.push(look);
if (was.deep !== undefined && record.deepLines?.isDestroyed())
return false;
@@ -2021,7 +2152,7 @@ export function createCesiumDraw({
const item = list[k];
const was = parts.get(item.id);
const show = item.show !== false;
if (was.polyline || was.batched) {
if (was.polyline || was.parked || was.batched) {
patchUndraped(record, was, item, looks[k]);
continue;
}
@@ -2080,9 +2211,15 @@ export function createCesiumDraw({
/**
* An undraped line without a depth-fail colour in the set's polyline
* collection, under pick id `id`; `reveal` is the material its reveal
* is set on, or null.
* is set on, or null. A hidden line that never settles (`park`) is
* parked instead, out of the collection (`polyline` null, `parked`
* true): the collection draws every line it holds, shown or not, each
* on a material and command of its own, every frame; a hidden line
* that settles costs nothing once in its static batch.
*/
function addPolyline(record, polylines, item, id) {
function addPolyline(record, polylines, item, id, park = false) {
if (park && item.show === false)
return { polyline: null, reveal: null, parked: true };
const positions = linePositions(item);
const reveal = revealed(item)
? revealUniform(item.revealFraction, positions)
@@ -2095,7 +2232,11 @@ export function createCesiumDraw({
show: item.show !== false,
id,
});
return { polyline, reveal: reveal === undefined ? null : material };
return {
polyline,
reveal: reveal === undefined ? null : material,
parked: false,
};
}
/**
@@ -2105,6 +2246,7 @@ export function createCesiumDraw({
*/
const settles = (item) =>
item.mode !== 'draped' &&
item.frame !== 'inertial' &&
!item.depthFailColor &&
item.style.kind === 'solid' &&
!revealed(item) &&
@@ -2174,6 +2316,25 @@ export function createCesiumDraw({
unsettle(record);
return;
}
if (!show && !was.shape) {
// Parked out of the collection, which would draw it on regardless
// (a line that settles is hidden in its batch instead).
if (was.polyline) {
dropFlow(record, was.polyline.material, item.style);
was.home.remove(was.polyline);
was.polyline = null;
was.reveal = null;
requestRender();
}
was.parked = true;
return;
}
if (was.parked) {
// Back in the collection, as it now is.
Object.assign(was, addPolyline(record, was.home, item, was.id));
requestRender();
return;
}
// Only a change a batch would draw unsettles the set: a show is taken
// when the batch swaps in, and lines that cannot settle are not in it.
if (was.shape && (recolour || !flatEquals(item.positions, was.positions))) {
@@ -2578,8 +2739,11 @@ export function createCesiumDraw({
}
}
/** A clamped shape's fill geometry, on the ellipsoid for draping. */
function groundGeometry(item) {
/**
* 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.
*/
function groundGeometry(item, rimFill = null) {
const g = item.geometry;
switch (g.kind) {
case 'polygon': {
@@ -2599,6 +2763,14 @@ export function createCesiumDraw({
semiMajorAxis: g.semiMajor,
semiMinorAxis: g.semiMinor,
rotation: g.rotation ?? 0,
...(rimFill
? {
granularity: RIM_GRANULARITY,
vertexFormat:
Cesium.MaterialAppearance.MaterialSupport.TEXTURED
.vertexFormat,
}
: {}),
});
case 'rectangle':
return new Cesium.RectangleGeometry({
@@ -2634,10 +2806,15 @@ export function createCesiumDraw({
parts.set(item.id, { look: lookOf(item), id: null, ground: null });
continue;
}
const imageFill =
const objectFill =
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;
if (imageFill && !imageFill.image)
throw new Error('the Cesium renderer fills shapes with colours only');
if (item.extrudeHeight !== undefined)
@@ -2654,7 +2831,7 @@ export function createCesiumDraw({
// load when they show.
let geometry;
try {
geometry = groundGeometry(item);
geometry = groundGeometry(item, rimFill);
} catch (error) {
if (item.show === false) continue;
throw error;
@@ -2670,17 +2847,29 @@ export function createCesiumDraw({
);
const instance = new Cesium.GeometryInstance({
geometry,
attributes: imageFill
? { show }
: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
toColor(item.fill),
),
show,
},
attributes:
imageFill || rimFill
? { 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
@@ -2726,7 +2915,9 @@ export function createCesiumDraw({
...(batch.imageFill.repeat ?? [1, 1]),
),
})
: null;
: batch.rimFill
? radialRimMaterial(batch.rimFill)
: null;
const ground = new Ground({
geometryInstances: batch.instances,
classificationType: classificationOf(batch.clampTo),
@@ -2739,6 +2930,15 @@ export function createCesiumDraw({
Cesium.MaterialAppearance.MaterialSupport.TEXTURED,
translucent: true,
flat: true,
...(batch.rimFill
? {
closed: false,
faceForward: true,
...(batch.depthBias
? { renderState: DEPTH_BIASED_STATE }
: {}),
}
: {}),
}),
}
: {}),
@@ -3074,6 +3274,8 @@ export function createCesiumDraw({
beforeRender() {
cullHorizon();
runFlows();
for (const record of sets.values())
if (record.inertialLines) turnInertial(record);
modelSets.beforeRender(sets.values());
},
/** Each frame, after it drew: clamp state, and ground swaps. */