mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Move the transit head across subdivisions in the frame, and keep segmented lines safe beside the draped rework
The transit trail's head is upserted where the vehicle crosses into the next subdivision, so the Cesium draw port moves it there in the same frame instead of building it anew; between crossings a frame changes only how far it is revealed. A test runs the trail through the Cesium draw port across a crossing and a second's fade, with nothing built anew. A segmented line that was replaced by a plain one and moved while its set rebuilds is hidden segment by segment where it was. A segmented line of no length is patched as nothing to draw instead of rebuilt on every upsert, and segmented lines are noted as rebuilt when they move.
This commit is contained in:
1 parent
87c80856c2
commit
e37349a061
3 files changed
+156
-8
No files matched your search
@@ -9,8 +9,8 @@
|
|||||||
* with its age; both change in place (`segmentShow`, `segmentColors`), so
|
* with its age; both change in place (`segmentShow`, `segmentColors`), so
|
||||||
* the body is rebuilt only when the history changes. The head is the
|
* the body is rebuilt only when the history changes. The head is the
|
||||||
* subdivision the vehicle is on, revealed up to the vehicle
|
* subdivision the vehicle is on, revealed up to the vehicle
|
||||||
* (`revealFraction`): it is drawn anew only where the vehicle crosses into
|
* (`revealFraction`): it moves only where the vehicle crosses into the
|
||||||
* the next subdivision, and a frame writes how far it is revealed.
|
* next subdivision, and a frame writes how far it is revealed.
|
||||||
*/
|
*/
|
||||||
import { cssColor } from '../render/color.js';
|
import { cssColor } from '../render/color.js';
|
||||||
import { findDraw } from '../render/rendererOf.js';
|
import { findDraw } from '../render/rendererOf.js';
|
||||||
@@ -222,7 +222,9 @@ export function createContactTrailRenderer(viewer) {
|
|||||||
active = segment;
|
active = segment;
|
||||||
restyled = false;
|
restyled = false;
|
||||||
revealed = fraction;
|
revealed = fraction;
|
||||||
headLines?.set(headItems(segment, fraction));
|
// Upserted, not set: a renderer can move a draped line to where it
|
||||||
|
// now runs in the same frame, instead of building it anew.
|
||||||
|
headLines?.upsert(headItems(segment, fraction));
|
||||||
} else if (fraction !== revealed) {
|
} else if (fraction !== revealed) {
|
||||||
revealed = fraction;
|
revealed = fraction;
|
||||||
headLines?.upsert(headItems(segment, fraction));
|
headLines?.upsert(headItems(segment, fraction));
|
||||||
|
|||||||
@@ -1499,14 +1499,16 @@ export function createCesiumDraw({
|
|||||||
for (const item of list) {
|
for (const item of list) {
|
||||||
const was = parts.get(item.id);
|
const was = parts.get(item.id);
|
||||||
if (!was || was.look !== lineLook(item)) return false;
|
if (!was || was.look !== lineLook(item)) return false;
|
||||||
// A segmented line that drew nothing is built anew.
|
|
||||||
if (was.segments && !was.ground) return false;
|
|
||||||
if (was.deep !== undefined && record.deepLines?.isDestroyed())
|
if (was.deep !== undefined && record.deepLines?.isDestroyed())
|
||||||
return false;
|
return false;
|
||||||
if (!was.clampTo) continue;
|
if (!was.clampTo) continue;
|
||||||
const flat = flatPositions(item.positions);
|
const flat = flatPositions(item.positions);
|
||||||
// A segmented line that moves is built anew, segment by segment.
|
// A segmented line that moves is built anew, segment by segment (so
|
||||||
|
// one that moves every frame is not drawn until it stops: segments
|
||||||
|
// are for lines that move only now and then).
|
||||||
if (was.segments && !samePositions(flat, was.positions)) return false;
|
if (was.segments && !samePositions(flat, was.positions)) return false;
|
||||||
|
// One with no length draws nothing, whatever its segments' looks.
|
||||||
|
if (was.segments && !was.ground) continue;
|
||||||
if (!drapedPatchable(record, was, flat)) return false;
|
if (!drapedPatchable(record, was, flat)) return false;
|
||||||
flats.set(item.id, flat);
|
flats.set(item.id, flat);
|
||||||
}
|
}
|
||||||
@@ -1541,6 +1543,7 @@ export function createCesiumDraw({
|
|||||||
}
|
}
|
||||||
was.id.meta = item.meta;
|
was.id.meta = item.meta;
|
||||||
if (was.segments) {
|
if (was.segments) {
|
||||||
|
if (!was.ground) continue;
|
||||||
// A newer write supersedes one queued while the ground built.
|
// A newer write supersedes one queued while the ground built.
|
||||||
was.pendingItem = was.ground.ready ? undefined : item;
|
was.pendingItem = was.ground.ready ? undefined : item;
|
||||||
if (was.ground.ready) writeSegments(was, item);
|
if (was.ground.ready) writeSegments(was, item);
|
||||||
@@ -1611,8 +1614,13 @@ export function createCesiumDraw({
|
|||||||
function hideRetiring(record, id) {
|
function hideRetiring(record, id) {
|
||||||
const part = record.retiring && record.retiringParts?.get(id);
|
const part = record.retiring && record.retiringParts?.get(id);
|
||||||
const ground = part?.ground;
|
const ground = part?.ground;
|
||||||
if (ground && !ground.isDestroyed() && ground.ready)
|
if (!ground || ground.isDestroyed() || !ground.ready) return;
|
||||||
showOn(ground, part.id, false);
|
// A segmented line draws under a pick id a segment.
|
||||||
|
if (part.segments)
|
||||||
|
for (const segment of part.segments) {
|
||||||
|
if (segment) showOn(ground, segment, false);
|
||||||
|
}
|
||||||
|
else showOn(ground, part.id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A draped line part's show, on its ready ground primitive. */
|
/** A draped line part's show, on its ready ground primitive. */
|
||||||
|
|||||||
@@ -1649,6 +1649,9 @@ test('a draped line with segment colours and shows draws a ground instance a seg
|
|||||||
empty instanceof Cesium.PolylineCollection,
|
empty instanceof Cesium.PolylineCollection,
|
||||||
'no ground primitive',
|
'no ground primitive',
|
||||||
);
|
);
|
||||||
|
// Its looks changing builds nothing either.
|
||||||
|
none.upsert([{ ...still, segmentShow: [false] }]);
|
||||||
|
assert.equal(scene.added.at(-1), empty, 'not rebuilt');
|
||||||
none.upsert([{ ...still, positions: trail(1, []).positions }]);
|
none.upsert([{ ...still, positions: trail(1, []).positions }]);
|
||||||
assert.notEqual(scene.added.at(-1), empty, 'drawn once it has length');
|
assert.notEqual(scene.added.at(-1), empty, 'drawn once it has length');
|
||||||
none.dispose();
|
none.dispose();
|
||||||
@@ -3485,3 +3488,138 @@ test('a contact trail draws its history and moving head as depth-fail geodesic l
|
|||||||
assert.equal(scene.added.length, 0);
|
assert.equal(scene.added.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a transit trail moves its head, across subdivisions too, and fades its body in place, frame to frame', async () => {
|
||||||
|
const { createContactTrailRenderer } =
|
||||||
|
await import('../../data/contactTrailRenderer.js');
|
||||||
|
withImageClasses(() =>
|
||||||
|
withTerrainHeights(() => {
|
||||||
|
const scene = fakeScene();
|
||||||
|
const viewer = { scene, isDestroyed: () => false };
|
||||||
|
const frame = () => {
|
||||||
|
scene.preRender.raiseEvent();
|
||||||
|
scene.postRender.raiseEvent();
|
||||||
|
};
|
||||||
|
const hostOf = (suffix) =>
|
||||||
|
scene.added.find((host) => host.drawSetId?.endsWith(suffix));
|
||||||
|
// Every ground primitive built so far reads as ready, with attributes.
|
||||||
|
const settle = () => {
|
||||||
|
for (const host of scene.added)
|
||||||
|
for (let i = 0; i < host.length; i++) {
|
||||||
|
const part = host.get(i);
|
||||||
|
if (!(part instanceof Cesium.GroundPolylinePrimitive)) continue;
|
||||||
|
if (part.ready) continue;
|
||||||
|
Object.defineProperty(part, 'ready', { value: true });
|
||||||
|
const attributes = new Map();
|
||||||
|
part.getGeometryInstanceAttributes = (id) => {
|
||||||
|
if (!attributes.has(id))
|
||||||
|
attributes.set(id, {
|
||||||
|
color: new Uint8Array(4),
|
||||||
|
show: new Uint8Array([1]),
|
||||||
|
});
|
||||||
|
return attributes.get(id);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
frame();
|
||||||
|
};
|
||||||
|
const at = (lon) => Cesium.Cartesian3.fromDegrees(lon, 0, 0);
|
||||||
|
const renderer = createContactTrailRenderer(viewer);
|
||||||
|
renderer.replaceHistory({
|
||||||
|
revision: 1,
|
||||||
|
segments: [
|
||||||
|
{
|
||||||
|
fromSeq: 0,
|
||||||
|
toSeq: 1,
|
||||||
|
fromT: 0,
|
||||||
|
toT: 10000,
|
||||||
|
positions: [at(0), at(0.0002)],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fromSeq: 0,
|
||||||
|
toSeq: 1,
|
||||||
|
fromT: 10000,
|
||||||
|
toT: 20000,
|
||||||
|
positions: [at(0.0002), at(0.0004)],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
settle();
|
||||||
|
const sample = (t) => ({
|
||||||
|
displayT: t,
|
||||||
|
fromSeq: 0,
|
||||||
|
toSeq: 1,
|
||||||
|
fraction: t / 20000,
|
||||||
|
});
|
||||||
|
renderer.setDisplaySample(sample(5000), at(0.0001));
|
||||||
|
settle();
|
||||||
|
const body = hostOf(':body'),
|
||||||
|
head = hostOf(':head');
|
||||||
|
assert.ok(body && head);
|
||||||
|
// Into the next subdivision: the head moves there in the same frame.
|
||||||
|
const before = scene.added.length;
|
||||||
|
renderer.setDisplaySample(sample(12000), at(0.00024));
|
||||||
|
assert.equal(scene.added.length, before, 'not built anew');
|
||||||
|
assert.equal(hostOf(':head'), head);
|
||||||
|
settle();
|
||||||
|
const lanes = Array.from({ length: head.length }, (_, i) =>
|
||||||
|
head.get(i),
|
||||||
|
).filter((part) => part instanceof Cesium.GroundPolylinePrimitive);
|
||||||
|
assert.equal(lanes.length, 2, 'a backing lane and a line lane');
|
||||||
|
const added = scene.added.length;
|
||||||
|
// A second and a half of frames within the subdivision.
|
||||||
|
for (let t = 12016; t < 13500; t += 16)
|
||||||
|
renderer.setDisplaySample(
|
||||||
|
sample(t),
|
||||||
|
at(0.0002 + (0.0002 * (t - 10000)) / 10000),
|
||||||
|
);
|
||||||
|
frame();
|
||||||
|
assert.equal(scene.added.length, added, 'nothing built anew');
|
||||||
|
assert.equal(hostOf(':body'), body);
|
||||||
|
assert.equal(hostOf(':head'), head);
|
||||||
|
for (const lane of lanes) {
|
||||||
|
const reveal = lane.appearance.material.uniforms.reveal;
|
||||||
|
assert.ok(Math.abs(reveal - 0.348) < 0.01, `revealed to ${reveal}`);
|
||||||
|
}
|
||||||
|
assert.equal(renderer.diagnostics().rebuilds, 1);
|
||||||
|
assert.equal(renderer.diagnostics().headRebuilds, 2, 'one a subdivision');
|
||||||
|
renderer.destroy();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a segmented line, then plain and moved while its set rebuilds, is hidden segment by segment where it was', () =>
|
||||||
|
withImageClasses(() =>
|
||||||
|
withTerrainHeights(() => {
|
||||||
|
const { scene, draw, frame } = drawOver();
|
||||||
|
const set = draw.lines({ id: 'resegmented' });
|
||||||
|
const line = (id, lon, extra = {}) => ({
|
||||||
|
id,
|
||||||
|
positions: [
|
||||||
|
{ lon: 0, lat: 0 },
|
||||||
|
{ lon: lon / 2, lat: 0.5 },
|
||||||
|
{ lon, lat: 1 },
|
||||||
|
],
|
||||||
|
widthPx: 3,
|
||||||
|
mode: 'draped',
|
||||||
|
style: { kind: 'solid', color: '#fff' },
|
||||||
|
...extra,
|
||||||
|
});
|
||||||
|
set.set([line('a', 1, { segmentShow: [true, true] })]);
|
||||||
|
const first = scene.added[0];
|
||||||
|
const ground = first.get(1);
|
||||||
|
Object.defineProperty(ground, 'ready', { value: true });
|
||||||
|
const shows = new Map();
|
||||||
|
ground.getGeometryInstanceAttributes = (id) => {
|
||||||
|
if (!shows.has(id)) shows.set(id, { show: new Uint8Array([1]) });
|
||||||
|
return shows.get(id);
|
||||||
|
};
|
||||||
|
frame();
|
||||||
|
// Plain now: a new look, rebuilt; then moved before that is ready.
|
||||||
|
set.upsert([line('a', 1)]);
|
||||||
|
assert.ok(scene.added.includes(first), 'the first still draws');
|
||||||
|
assert.doesNotThrow(() => set.upsert([line('a', 2)]));
|
||||||
|
assert.equal(shows.size, 2, 'both segments');
|
||||||
|
for (const { show } of shows.values()) assert.deepEqual([...show], [0]);
|
||||||
|
set.dispose();
|
||||||
|
}),
|
||||||
|
));
|
||||||
Reference in new issue
Block a user