mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
A line can show only the part of it within a time span of the scene clock (#1894)
* A line can show only the part of it within a time span of the scene clock LineAgeFade.showMs (capability lineTimeWindow) draws only the part of an aged line whose time, interpolated along it, lies between showMs before the scene clock and the clock itself, cut as the clock moves without the line being sent again. A moving trail can then be sent once as its whole track. The Cesium port discards by time in its aged line material, draped or not, and the conformance check draw.lines.timeWindow pins it. Without showMs the fade is unchanged. * Changelog for line time window (#1894)
This commit is contained in:
1 parent
561f5885c2
commit
e4caf5d3af
11 files changed
+221
-8
No files matched your search
@@ -431,7 +431,9 @@ const AGE_TEXTURE_WIDTH = 1024;
|
||||
* its recency eases the alpha (smoothstep to `ageAlphaFloor`, recency
|
||||
* squared to `ageSquaredFloor` where that is not negative) and the width
|
||||
* (to `ageWidthFloor` of it, about its middle: outside it is discarded, so
|
||||
* it neither draws nor picks).
|
||||
* it neither draws nor picks). With a window (`ageShow`, `LineAgeFade.showMs`,
|
||||
* seconds; negative, no older bound; 0, none) a fragment whose time is after
|
||||
* now, or older than the window, is discarded too.
|
||||
*/
|
||||
const AGE_SOURCE = `
|
||||
vec4 drawAgeTexel(float i) {
|
||||
@@ -462,6 +464,8 @@ czm_material czm_getMaterial(czm_materialInput materialInput) {
|
||||
u = clamp(f - lo, 0.0, 1.0);
|
||||
}
|
||||
float when = mix(drawAgeTexel(lo).g, drawAgeTexel(hi).g, u);
|
||||
if (ageShow != 0.0 && (when > ageNow || (ageShow > 0.0 && ageNow - when > ageShow)))
|
||||
discard;
|
||||
float recency = 1.0 - clamp((ageNow - when) / ageWindow, 0.0, 1.0);
|
||||
float fade = mix(ageAlphaFloor, 1.0, smoothstep(0.0, 1.0, recency));
|
||||
if (ageSquaredFloor >= 0.0)
|
||||
@@ -485,12 +489,20 @@ czm_material czm_getMaterial(czm_materialInput materialInput) {
|
||||
* takes the rest evenly along its texture; `byLength`, the points lie along
|
||||
* it by their distance over the ellipsoid, as a ground polyline's texture
|
||||
* runs. `base` is the newest time, so the times a texel holds are small.
|
||||
* `windowed`, the line draws only within its `showMs` of now (`ageShow`).
|
||||
* @param {Array<{x: number, y: number, z: number}>} points
|
||||
* @param {ArrayLike<number>} times Epoch ms, one a point.
|
||||
* @param {import('../contract/draw').LineAgeFade} fade
|
||||
* @param {boolean} [byLength]
|
||||
* @param {boolean} [windowed]
|
||||
*/
|
||||
export function lineAgeData(points, times, fade, byLength = false) {
|
||||
export function lineAgeData(
|
||||
points,
|
||||
times,
|
||||
fade,
|
||||
byLength = false,
|
||||
windowed = false,
|
||||
) {
|
||||
let kept = Array.from(times);
|
||||
let along = points;
|
||||
if (!byLength) {
|
||||
@@ -549,13 +561,23 @@ export function lineAgeData(points, times, fade, byLength = false) {
|
||||
ageAlphaFloor: fade.alphaFloor,
|
||||
ageSquaredFloor: fade.squaredAlphaFloor ?? -1,
|
||||
ageWidthFloor: fade.widthFloor ?? 1,
|
||||
ageShow: showUniform(windowed ? fade.showMs : undefined),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A window's `ageShow` uniform: its seconds; -1 for an endless one, cut at
|
||||
* now alone; 0 for none.
|
||||
* @param {number|undefined} showMs
|
||||
*/
|
||||
const showUniform = (showMs) =>
|
||||
showMs === undefined ? 0 : Number.isFinite(showMs) ? showMs / 1000 : -1;
|
||||
|
||||
/**
|
||||
* A line's `ageFade`, checked: one finite time a position, over a positive
|
||||
* window, its floors from 0 to 1. Refused otherwise.
|
||||
* window, its floors from 0 to 1, and a `showMs` positive where it has one.
|
||||
* Refused otherwise.
|
||||
* @param {import('../contract/draw').LineItem} item
|
||||
*/
|
||||
function checkAgeFade(item) {
|
||||
@@ -573,10 +595,11 @@ function checkAgeFade(item) {
|
||||
!(fade.windowMs > 0 && Number.isFinite(fade.windowMs)) ||
|
||||
!(fade.alphaFloor >= 0 && fade.alphaFloor <= 1) ||
|
||||
!floor(fade.squaredAlphaFloor) ||
|
||||
!floor(fade.widthFloor)
|
||||
!floor(fade.widthFloor) ||
|
||||
!(fade.showMs === undefined || fade.showMs > 0)
|
||||
)
|
||||
throw new TypeError(
|
||||
'a line fades with one finite time a position, over a positive window, with floors from 0 to 1',
|
||||
'a line fades with one finite time a position, over a positive window, with floors from 0 to 1, shown over a positive span',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -658,6 +681,8 @@ export function createCesiumDraw({
|
||||
const sets = new Map();
|
||||
// Lines fade with the age of their points (`LineItem.ageFade`).
|
||||
const ageFades = capabilities.has('lineAgeFade');
|
||||
// And draw only within a span of the scene clock (`LineAgeFade.showMs`).
|
||||
const timeWindows = ageFades && capabilities.has('lineTimeWindow');
|
||||
// Fields share the sets' ids.
|
||||
const fieldPart = createCesiumFields({
|
||||
scene,
|
||||
@@ -2824,6 +2849,7 @@ export function createCesiumDraw({
|
||||
times,
|
||||
item.ageFade,
|
||||
item.mode === 'draped' || item.overlaid === true,
|
||||
timeWindows,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3607,6 +3633,7 @@ export function createCesiumDraw({
|
||||
item.ageFade.alphaFloor,
|
||||
item.ageFade.squaredAlphaFloor,
|
||||
item.ageFade.widthFloor,
|
||||
showUniform(timeWindows ? item.ageFade.showMs : undefined),
|
||||
]
|
||||
: null,
|
||||
]);
|
||||
@@ -3637,7 +3664,8 @@ export function createCesiumDraw({
|
||||
x.windowMs === y.windowMs &&
|
||||
x.alphaFloor === y.alphaFloor &&
|
||||
x.squaredAlphaFloor === y.squaredAlphaFloor &&
|
||||
x.widthFloor === y.widthFloor
|
||||
x.widthFloor === y.widthFloor &&
|
||||
(!timeWindows || x.showMs === y.showMs)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -116,9 +116,27 @@ test('a polyline’s age texels: a point at the place of the one before it is dr
|
||||
ageAlphaFloor: 0.06,
|
||||
ageSquaredFloor: 0.14,
|
||||
ageWidthFloor: 1,
|
||||
ageShow: 0,
|
||||
});
|
||||
});
|
||||
|
||||
test('a windowed line’s age texels carry its span, in seconds; an endless one cuts at now alone', () => {
|
||||
const points = along(2);
|
||||
const fade = (showMs) => ({
|
||||
times: [],
|
||||
windowMs: 30_000,
|
||||
alphaFloor: 0.06,
|
||||
showMs,
|
||||
});
|
||||
const at = (showMs, windowed = true) =>
|
||||
lineAgeData(points, [T0, T0 + 1000], fade(showMs), false, windowed).uniforms
|
||||
.ageShow;
|
||||
assert.equal(at(45_000), 45);
|
||||
assert.equal(at(Infinity), -1);
|
||||
assert.equal(at(undefined), 0, 'no span, no cut');
|
||||
assert.equal(at(45_000, false), 0, 'not cut where the port does not');
|
||||
});
|
||||
|
||||
test('a draped line’s age texels lie along it by distance, and a long line takes more rows', () => {
|
||||
const points = [
|
||||
Cesium.Cartesian3.fromDegrees(0, 0),
|
||||
@@ -298,6 +316,49 @@ test('an aged line built anew lets its old material go once its primitive is gon
|
||||
void scene;
|
||||
});
|
||||
|
||||
test('a windowed line is cut on the scene clock: time passing changes its material, never its line', () => {
|
||||
const { part, scene, frameAt } = agedDraw(fakeScene(), [
|
||||
'lineAgeFade',
|
||||
'lineTimeWindow',
|
||||
]);
|
||||
const set = part.port.lines({ id: 'trails' });
|
||||
// A whole track, an hour of it, shown over its last minute.
|
||||
const positions = along(61);
|
||||
const times = positions.map((_, i) => T0 + i * 60_000);
|
||||
set.set([trail(positions, times, { alphaFloor: 1, showMs: 60_000 })]);
|
||||
const polylines = collectionOf(scene);
|
||||
const polyline = polylines.get(0);
|
||||
const material = polyline.material;
|
||||
assert.equal(material.type, 'DrawAgedLine_solid');
|
||||
assert.equal(material.uniforms.ageShow, 60);
|
||||
assert.equal(material.uniforms.ageCount, 61);
|
||||
const before = polyline.positions;
|
||||
for (let k = 1; k <= 120; k++) {
|
||||
frameAt(T0 + k * 30_000);
|
||||
assert.equal(
|
||||
material.uniforms.ageNow,
|
||||
(k * 30_000 - 3_600_000) / 1000,
|
||||
`seconds after its newest point, frame ${k}`,
|
||||
);
|
||||
}
|
||||
assert.equal(collectionOf(scene), polylines, 'the same collection');
|
||||
assert.equal(polylines.get(0), polyline, 'the same line');
|
||||
assert.equal(polyline.material, material, 'the same material');
|
||||
assert.equal(polyline.positions, before, 'its points untouched');
|
||||
// A new span is a new look: drawn anew, with it.
|
||||
set.upsert([trail(positions, times, { alphaFloor: 1, showMs: 120_000 })]);
|
||||
assert.equal(collectionOf(scene).get(0).material.uniforms.ageShow, 120);
|
||||
});
|
||||
|
||||
test('without the window’s capability a line ignores its span and draws whole', () => {
|
||||
const { part, scene } = agedDraw();
|
||||
const set = part.port.lines({ id: 'trails' });
|
||||
set.set([trail(along(3), [T0, T0 + 1, T0 + 2], { showMs: 60_000 })]);
|
||||
const material = collectionOf(scene).get(0).material;
|
||||
assert.equal(material.type, 'DrawAgedLine_solid', 'still faded');
|
||||
assert.equal(material.uniforms.ageShow, 0, 'never cut');
|
||||
});
|
||||
|
||||
test('without the capability a line ignores its age fade; with it a bad fade is refused', () => {
|
||||
const plain = agedDraw(fakeScene(), []);
|
||||
const lines = plain.part.port.lines({ id: 'trails' });
|
||||
@@ -322,5 +383,11 @@ test('without the capability a line ignores its age fade; with it a bad fade is
|
||||
TypeError,
|
||||
'floors from 0 to 1',
|
||||
);
|
||||
for (const showMs of [0, -1, Number.NaN])
|
||||
assert.throws(
|
||||
() => set.set([trail(along(2), [T0, T0], { showMs })]),
|
||||
TypeError,
|
||||
'a positive span',
|
||||
);
|
||||
assert.equal(set.size(), 0, 'nothing changed');
|
||||
});
|
||||
@@ -73,6 +73,7 @@ export const CESIUM_CHECKS = new Set([
|
||||
'draw.lines.split',
|
||||
'draw.lines.outlineDraped',
|
||||
'draw.lines.ageFade',
|
||||
'draw.lines.timeWindow',
|
||||
'draw.lines.segments',
|
||||
'draw.lines.segmentStyles',
|
||||
'draw.sets.blend',
|
||||
|
||||
@@ -85,7 +85,10 @@ export function cesiumCapabilities(scene, only) {
|
||||
'fields',
|
||||
// Lines faded with age in their material, from a floating-point
|
||||
// texture of their points' times (`draw.js`).
|
||||
...(scene?.context?.floatingPointTexture ? ['lineAgeFade'] : []),
|
||||
// And cut by time there, within a span of the scene clock.
|
||||
...(scene?.context?.floatingPointTexture
|
||||
? ['lineAgeFade', 'lineTimeWindow']
|
||||
: []),
|
||||
'followFrame',
|
||||
'pointVisibility',
|
||||
// Cesium's AUTODETECT tracking frame (`follow.js`).
|
||||
|
||||
Reference in new issue
Block a user