mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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:
1 parent
fa762f808e
commit
4a9b1389ba
22 files changed
+1476
-717
No files matched your search
+222
-20
@@ -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. */
|
||||
|
||||
@@ -595,8 +595,24 @@ test('clamped shapes refuse what they cannot draw', () => {
|
||||
fill: '#fff',
|
||||
height: 'clampGround',
|
||||
};
|
||||
// A rim fill is drawn on ellipses alone.
|
||||
assert.throws(
|
||||
() => set.set([{ ...disc, fill: { preset: 'radialRim' } }]),
|
||||
() =>
|
||||
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,
|
||||
},
|
||||
},
|
||||
]),
|
||||
/colours only/,
|
||||
);
|
||||
assert.throws(
|
||||
@@ -2114,8 +2130,9 @@ test('unchanged solid 3D lines settle into a static batch, changed there in plac
|
||||
s.built(translucentAgain);
|
||||
frame();
|
||||
assert.equal(opaqueAgain.show, true, 'swapped in once built');
|
||||
assert.equal(polylines.length, 1, 'the glow alone left in the collection');
|
||||
assert.equal(polylines.get(0).id.id, 'glow');
|
||||
// The glow, hidden, is parked out of the collection, which would draw
|
||||
// it on regardless; the batch took the rest.
|
||||
assert.equal(polylines.length, 0, 'none left in the collection');
|
||||
// Show, colour and meta change in place on the batch.
|
||||
set.upsert([
|
||||
stem('a', 100, { show: false }),
|
||||
@@ -2124,7 +2141,7 @@ test('unchanged solid 3D lines settle into a static batch, changed there in plac
|
||||
assert.equal(s.host(), host);
|
||||
assert.deepEqual([...s.attrs(opaqueAgain, 'a').show], [0]);
|
||||
assert.deepEqual([...s.attrs(opaqueAgain, 'c').color], [0, 0, 255, 255]);
|
||||
assert.equal(polylines.length, 1, 'nothing left the batch');
|
||||
assert.equal(polylines.length, 0, 'nothing left the batch');
|
||||
set.upsert([stem('a', 100, { meta: 'new' })]);
|
||||
assert.deepEqual([...s.attrs(opaqueAgain, 'a').show], [1]);
|
||||
assert.equal(opaqueAgain.geometryInstances[0].id.meta, 'new');
|
||||
@@ -2133,8 +2150,8 @@ test('unchanged solid 3D lines settle into a static batch, changed there in plac
|
||||
set.upsert([stem('a', 900)]);
|
||||
assert.equal(s.host(), host);
|
||||
assert.deepEqual([...s.attrs(opaqueAgain, 'a').show], [0]);
|
||||
assert.equal(polylines.length, 2);
|
||||
const moved = polylines.get(1);
|
||||
assert.equal(polylines.length, 1);
|
||||
const moved = polylines.get(0);
|
||||
assert.equal(moved.id.id, 'a');
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.equalsEpsilon(
|
||||
@@ -2147,7 +2164,7 @@ test('unchanged solid 3D lines settle into a static batch, changed there in plac
|
||||
set.upsert([
|
||||
stem('c', 300, { style: { kind: 'solid', color: [0, 0, 1, 0.4] } }),
|
||||
]);
|
||||
assert.equal(polylines.length, 3);
|
||||
assert.equal(polylines.length, 2);
|
||||
// Two lines are few beside a batch: they wait longer.
|
||||
s.settle();
|
||||
assert.equal(s.batches().length, 2, 'not yet');
|
||||
@@ -2173,7 +2190,12 @@ test('unchanged solid 3D lines settle into a static batch, changed there in plac
|
||||
assert.deepEqual(s.batches(), next, 'the old batches are gone');
|
||||
assert.equal(opaqueAgain.isDestroyed(), true);
|
||||
assert.deepEqual([...s.attrs(next[1], 'b').show], [0]);
|
||||
assert.equal(polylines.length, 0);
|
||||
// The glow shown again draws in the collection, in place.
|
||||
set.upsert([glow]);
|
||||
assert.equal(s.host(), host);
|
||||
assert.equal(polylines.length, 1);
|
||||
assert.equal(polylines.get(0).id.id, 'glow');
|
||||
// A line that looks different is still a rebuild.
|
||||
set.upsert([stem('b', 200, { widthPx: 5 })]);
|
||||
assert.notEqual(s.host(), host);
|
||||
@@ -5163,3 +5185,167 @@ test('a raised polygon outlines its holes as well as its outer ring', () =>
|
||||
}
|
||||
set.dispose();
|
||||
}));
|
||||
|
||||
test('a pattern line draws its image along it, repeated, and an inertial line turns with the sky', () =>
|
||||
withImageClasses(() => {
|
||||
const { scene, draw, frame } = drawOver();
|
||||
const set = draw.lines({ id: 'orbit-rings' });
|
||||
const ring = [
|
||||
{ x: 7e6, y: 0, z: 0 },
|
||||
{ x: 0, y: 7e6, z: 0 },
|
||||
{ x: -7e6, y: 0, z: 0 },
|
||||
];
|
||||
const pattern = { kind: 'pattern', image: 'marks.png', repeat: 4 };
|
||||
set.set([
|
||||
{ id: 'fixed', positions: ring, widthPx: 3, mode: '3d', style: pattern },
|
||||
{
|
||||
id: 'sky',
|
||||
positions: ring,
|
||||
widthPx: 3,
|
||||
mode: '3d',
|
||||
style: pattern,
|
||||
frame: 'inertial',
|
||||
},
|
||||
]);
|
||||
const host = scene.added[0];
|
||||
assert.ok(host instanceof Cesium.PrimitiveCollection);
|
||||
const fixed = host.get(0);
|
||||
const inertial = host.get(1);
|
||||
assert.ok(inertial instanceof Cesium.PolylineCollection);
|
||||
const material = fixed.get(0).material;
|
||||
assert.equal(material.type, 'Image');
|
||||
assert.equal(material.uniforms.image, 'marks.png');
|
||||
assert.deepEqual(material.uniforms.repeat, new Cesium.Cartesian2(4, 1));
|
||||
assert.equal(material.isTranslucent(), true, 'its image has its alpha');
|
||||
assert.equal(inertial.get(0).id.id, 'sky');
|
||||
// Turned by sidereal time: the inertial x axis is drawn where the
|
||||
// pseudo-fixed frame puts it now.
|
||||
const turnedTo = () =>
|
||||
Cesium.Matrix4.multiplyByPointAsVector(
|
||||
inertial.modelMatrix,
|
||||
Cesium.Cartesian3.UNIT_X,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const expected = Cesium.Matrix3.multiplyByVector(
|
||||
Cesium.Transforms.computeTemeToPseudoFixedMatrix(Cesium.JulianDate.now()),
|
||||
Cesium.Cartesian3.UNIT_X,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.equalsEpsilon(turnedTo(), expected, 1e-6),
|
||||
'turned as Cesium turns TEME',
|
||||
);
|
||||
const realNow = Date.now;
|
||||
try {
|
||||
const at = realNow();
|
||||
Date.now = () => at + 3_600_000;
|
||||
frame();
|
||||
const later = turnedTo();
|
||||
// An hour turns the frame about 15 degrees about the pole.
|
||||
const angle = Cesium.Cartesian3.angleBetween(later, expected);
|
||||
assert.ok(Math.abs(Cesium.Math.toDegrees(angle) - 15.04) < 0.05);
|
||||
assert.ok(Math.abs(later.z) < 1e-9);
|
||||
} finally {
|
||||
Date.now = realNow;
|
||||
}
|
||||
// Never settled into a static batch; shown and hidden in place. A
|
||||
// hidden line that never settles leaves its collection, which would
|
||||
// draw it on regardless, until it shows again.
|
||||
for (let i = 0; i < SETTLE_FRAMES + 2; i++) frame();
|
||||
const sky = (show) => ({
|
||||
id: 'sky',
|
||||
positions: ring,
|
||||
widthPx: 3,
|
||||
mode: '3d',
|
||||
style: pattern,
|
||||
frame: 'inertial',
|
||||
show,
|
||||
});
|
||||
set.upsert([sky(false), { ...sky(false), id: 'fixed', frame: undefined }]);
|
||||
assert.equal(scene.added[0], host, 'patched, not rebuilt');
|
||||
assert.equal(inertial.length, 0);
|
||||
assert.equal(fixed.length, 0);
|
||||
set.upsert([sky(true)]);
|
||||
assert.equal(scene.added[0], host);
|
||||
assert.equal(inertial.length, 1);
|
||||
assert.equal(inertial.get(0).show, true);
|
||||
assert.equal(inertial.get(0).id.id, 'sky');
|
||||
assert.equal(inertial.get(0).material.type, 'Image');
|
||||
// Built hidden, it starts out of its collection.
|
||||
const later = draw.lines({ id: 'orbit-rings-hidden' });
|
||||
later.set([{ ...sky(false), id: 'parked' }]);
|
||||
assert.equal(scene.added.at(-1).get(1).length, 0);
|
||||
later.upsert([{ ...sky(true), id: 'parked' }]);
|
||||
assert.equal(scene.added.at(-1).get(1).length, 1);
|
||||
later.dispose();
|
||||
assert.throws(
|
||||
() =>
|
||||
set.upsert([
|
||||
{
|
||||
id: 'draped',
|
||||
positions: ring,
|
||||
widthPx: 3,
|
||||
mode: 'draped',
|
||||
style: { kind: 'solid', color: '#fff' },
|
||||
frame: 'inertial',
|
||||
},
|
||||
]),
|
||||
/inertial lines undraped/,
|
||||
);
|
||||
set.dispose();
|
||||
assert.equal(scene.added.length, 0);
|
||||
}));
|
||||
|
||||
test('a clamped ellipse filled with a radial rim drapes its material, finely cut, pulled toward the eye', () =>
|
||||
withImageClasses(() => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.shapes({ id: 'pad-zone' });
|
||||
const zone = {
|
||||
id: 'zone',
|
||||
geometry: {
|
||||
kind: 'ellipse',
|
||||
center: { lon: -80.6, lat: 28.6 },
|
||||
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,
|
||||
},
|
||||
height: 'clampGround',
|
||||
depthBias: 1,
|
||||
};
|
||||
set.set([zone]);
|
||||
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);
|
||||
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(ground.classificationType, Cesium.ClassificationType.BOTH);
|
||||
const [instance] = ground.geometryInstances;
|
||||
assert.ok(instance.geometry instanceof Cesium.EllipseGeometry);
|
||||
assert.ok(
|
||||
Math.abs(instance.geometry._granularity - Cesium.Math.toRadians(0.08)) <
|
||||
1e-12,
|
||||
);
|
||||
assert.equal(instance.id.id, 'zone');
|
||||
// Hidden and shown in place, once its primitive is ready.
|
||||
Object.defineProperty(ground, 'ready', { value: true });
|
||||
const shows = { show: Uint8Array.of(1) };
|
||||
ground.getGeometryInstanceAttributes = () => shows;
|
||||
set.upsert([{ ...zone, show: false }]);
|
||||
assert.equal(scene.added[0], host, 'patched, not rebuilt');
|
||||
assert.deepEqual([...shows.show], [0]);
|
||||
set.dispose();
|
||||
}));
|
||||
Reference in new issue
Block a user