mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Move points in place and show them by display range through the Cesium draw port
Unclamped points that move on an upsert now move on the point they have, keeping their pick id and horizon cull, instead of rebuilding the set. Points and clamped dots honour displayRange as icons do. The shared conformance suite checks moved points and point display ranges, and the lodGroup check now passes on the Cesium renderer too.
This commit is contained in:
1 parent
b9248bfce5
commit
adedd51551
4 files changed
+146
-13
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* @description The Cesium renderer's draw port
|
||||
* (`src/render/contract/draw.d.ts`): batched sets of items, each set one
|
||||
* primitive collection in the scene, rebuilt when its items change (icon
|
||||
* sets, and points restyled where they are, change in place). Every
|
||||
* sets, and unclamped points restyled or moved, change in place). Every
|
||||
* item carries a pick id `{set, id, meta, lodGroup}`, which the query port
|
||||
* (`ports.js`) reads picks back through.
|
||||
*
|
||||
@@ -220,7 +220,8 @@ export function createCesiumDraw({
|
||||
record.gpu.write(list);
|
||||
return patched();
|
||||
}
|
||||
// Items that only change how they look are changed where they are.
|
||||
// Points restyled or moved, and lines that only change how they show
|
||||
// or where an undraped one runs, are changed where they are.
|
||||
if (patchPoints(record, list) || patchLines(record, list)) {
|
||||
for (const item of list) items.set(item.id, item);
|
||||
setsVersion += 1;
|
||||
@@ -738,7 +739,8 @@ export function createCesiumDraw({
|
||||
let dots = null;
|
||||
for (const item of record.items.values()) {
|
||||
const position = toCartesian(item.pos);
|
||||
const show = item.show !== false;
|
||||
// An empty range shows it nowhere.
|
||||
const show = item.show !== false && displayable(item.displayRange);
|
||||
const heightReference = heightReferenceOf(
|
||||
item.height,
|
||||
record.spec.clampTo,
|
||||
@@ -770,6 +772,7 @@ export function createCesiumDraw({
|
||||
position,
|
||||
heightReference,
|
||||
show,
|
||||
distanceDisplayCondition: displayConditionOf(item.displayRange),
|
||||
id: pickId(record, item),
|
||||
});
|
||||
}
|
||||
@@ -794,6 +797,7 @@ export function createCesiumDraw({
|
||||
disableDepthTestDistance: item.disableDepthTest ?? 0,
|
||||
scaleByDistance: nearFarOf(item.scaleByDistance),
|
||||
translucencyByDistance: nearFarOf(item.fadeByDistance),
|
||||
distanceDisplayCondition: displayConditionOf(item.displayRange),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -808,9 +812,10 @@ export function createCesiumDraw({
|
||||
|
||||
/**
|
||||
* Upsert unclamped points in place, without a rebuild, when every item
|
||||
* is one the set draws as a point primitive now and keeps its position,
|
||||
* height mode and LOD group: then only how it looks, its `meta` and
|
||||
* whether it shows change. False, changing nothing, otherwise.
|
||||
* is one the set draws as a point primitive now and stays unclamped in
|
||||
* the same LOD group: then how it looks, where it is, its `meta` and
|
||||
* whether it shows change on the point it has. False, changing nothing,
|
||||
* otherwise.
|
||||
*/
|
||||
function patchPoints(record, list) {
|
||||
const patchable = record.patchable;
|
||||
@@ -821,14 +826,20 @@ export function createCesiumDraw({
|
||||
!was ||
|
||||
heightReferenceOf(item.height, record.spec.clampTo) !==
|
||||
Cesium.HeightReference.NONE ||
|
||||
item.lodGroup !== was.lodGroup ||
|
||||
placeOf(item).some((value, i) => value !== was.at[i])
|
||||
item.lodGroup !== was.lodGroup
|
||||
)
|
||||
return false;
|
||||
}
|
||||
for (const item of list) {
|
||||
const was = patchable.get(item.id);
|
||||
const show = item.show !== false;
|
||||
const show = item.show !== false && displayable(item.displayRange);
|
||||
const at = placeOf(item);
|
||||
if (at.some((value, i) => !Object.is(value, was.at[i]))) {
|
||||
const position = toCartesian(item.pos);
|
||||
was.primitive.position = position;
|
||||
was.placed.position = position;
|
||||
was.at = at;
|
||||
}
|
||||
Object.assign(was.primitive, pointLook(item));
|
||||
was.primitive.id.meta = item.meta;
|
||||
was.placed.shown = show;
|
||||
|
||||
@@ -843,7 +843,7 @@ test('changing an option rebuilds only the kinds that build it in, in their plac
|
||||
}
|
||||
});
|
||||
|
||||
test('restyling points that stay put changes them in place; moving one rebuilds', () => {
|
||||
test('restyling or moving unclamped points changes them in place; a new one rebuilds', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.points({ id: 'restyled', blend: 'translucent' });
|
||||
const dot = (id, lon, extra = {}) => ({
|
||||
@@ -867,10 +867,26 @@ test('restyling points that stay put changes them in place; moving one rebuilds'
|
||||
assert.equal(a.id.meta, 7, 'picks read the new meta');
|
||||
assert.equal(set.size(), 2);
|
||||
|
||||
const b = host.get(1);
|
||||
set.upsert([dot('b', 2)]);
|
||||
assert.notEqual(scene.added[0], host, 'moved: rebuilt');
|
||||
assert.equal(scene.added[0], host, 'moved: the same collection');
|
||||
assert.equal(host.get(1), b, 'the same point');
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.equalsEpsilon(
|
||||
b.position,
|
||||
Cesium.Cartesian3.fromDegrees(2, 0, 2),
|
||||
1e-6,
|
||||
),
|
||||
'where it now is',
|
||||
);
|
||||
// Clamped now: a billboard dot, so rebuilt.
|
||||
set.upsert([dot('b', 2, { height: 'clampGround' })]);
|
||||
assert.notEqual(scene.added[0], host, 'clamped: rebuilt');
|
||||
set.upsert([dot('b', 2)]);
|
||||
const rebuilt = scene.added[0];
|
||||
set.upsert([dot('c', 3)]);
|
||||
assert.equal(set.size(), 3, 'a new item rebuilds too');
|
||||
assert.equal(set.size(), 3);
|
||||
assert.notEqual(scene.added[0], rebuilt, 'a new item rebuilds');
|
||||
assert.equal(scene.added[0].length, 3);
|
||||
set.dispose();
|
||||
});
|
||||
@@ -888,12 +904,71 @@ test('a position object changed and sent again moves its point', () => {
|
||||
const host = scene.added[0];
|
||||
item.pos.lon = 90;
|
||||
set.upsert([item]);
|
||||
assert.notEqual(scene.added[0], host, 'rebuilt where it now is');
|
||||
assert.equal(scene.added[0], host, 'moved where it is');
|
||||
const at = Cesium.Cartographic.fromCartesian(scene.added[0].get(0).position);
|
||||
assert.ok(Math.abs(Cesium.Math.toDegrees(at.longitude) - 90) < 1e-9);
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('a point moved in place is horizon culled where it now is', () => {
|
||||
const { scene, draw, frame } = drawOver();
|
||||
const set = draw.points({ id: 'culled-moving', horizonCull: true });
|
||||
const dot = (lon) => ({
|
||||
id: 'a',
|
||||
pos: { lon, lat: 0, height: 10 },
|
||||
pixelSize: 4,
|
||||
color: '#fff',
|
||||
});
|
||||
// The eye is over lon 0.
|
||||
set.set([dot(0)]);
|
||||
const point = scene.added[0].get(0);
|
||||
frame();
|
||||
assert.equal(point.show, true, 'under the eye');
|
||||
set.upsert([dot(180)]);
|
||||
assert.equal(scene.added[0].get(0), point, 'the same point');
|
||||
frame();
|
||||
assert.equal(point.show, false, 'past the horizon');
|
||||
set.upsert([dot(1)]);
|
||||
frame();
|
||||
assert.equal(point.show, true, 'back in view');
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('points show only within their display range', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.points({ id: 'ranged' });
|
||||
const dot = (id, extra = {}) => ({
|
||||
id,
|
||||
pos: { lon: 0, lat: 0 },
|
||||
pixelSize: 4,
|
||||
color: '#fff',
|
||||
...extra,
|
||||
});
|
||||
set.set([
|
||||
dot('near', { displayRange: [0, 2e6] }),
|
||||
dot('empty', { displayRange: [5, 5] }),
|
||||
dot('clamped', { displayRange: [0, 1e3], height: 'clampGround' }),
|
||||
]);
|
||||
const [host] = scene.added;
|
||||
const points = host.get(0);
|
||||
const dots = host.get(1);
|
||||
const near = points.get(0);
|
||||
assert.equal(near.distanceDisplayCondition.near, 0);
|
||||
assert.equal(near.distanceDisplayCondition.far, 2e6);
|
||||
assert.equal(points.get(1).show, false, 'an empty range shows nowhere');
|
||||
assert.equal(points.get(1).distanceDisplayCondition, undefined);
|
||||
assert.equal(dots.get(0).distanceDisplayCondition.far, 1e3, 'clamped too');
|
||||
// Changed and dropped in place.
|
||||
set.upsert([dot('near', { displayRange: [10, 20] })]);
|
||||
assert.equal(points.get(0), near);
|
||||
assert.equal(near.distanceDisplayCondition.far, 20);
|
||||
set.upsert([dot('near')]);
|
||||
assert.equal(near.distanceDisplayCondition, undefined, 'dropped');
|
||||
set.upsert([dot('empty')]);
|
||||
assert.equal(points.get(1).show, true, 'no range shows it');
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('the fire perimeters layer draws holed ground fills and draped fire lines on a viewer of its own', async () => {
|
||||
const { createFirePerimetersLayer } =
|
||||
await import('../../layers/perimeters/index.js');
|
||||
|
||||
@@ -48,6 +48,8 @@ export const CESIUM_CHECKS = new Set([
|
||||
'draw.motion.live',
|
||||
'draw.motion.shared',
|
||||
'draw.pick',
|
||||
'draw.points.update',
|
||||
'draw.lodGroup',
|
||||
'draw.sets',
|
||||
'effects.crossfade',
|
||||
'effects.defineStyle',
|
||||
|
||||
@@ -1348,6 +1348,51 @@ export function portChecks() {
|
||||
set.dispose();
|
||||
},
|
||||
),
|
||||
check(
|
||||
'draw.points.update',
|
||||
'an upserted point is drawn where it now is once drawn again, and shows only within its display range',
|
||||
async (h, r) => {
|
||||
await overAustin(h, r);
|
||||
const set = r.draw.points({ id: 'conf:points-update' });
|
||||
const a = h.toEcef({ ...AUSTIN, height: 0 });
|
||||
const b = h.toEcef({ lon: AUSTIN.lon + 0.004, lat: AUSTIN.lat });
|
||||
const point = (pos, extra = {}) => ({
|
||||
id: 'one',
|
||||
pos,
|
||||
pixelSize: 16,
|
||||
color: '#ff0000',
|
||||
meta: { n: 1 },
|
||||
...extra,
|
||||
});
|
||||
set.set([point(a)]);
|
||||
await drawn(h, r);
|
||||
const sa = r.query.project(a);
|
||||
const sb = r.query.project(b);
|
||||
ok(sa && sb, 'both places project');
|
||||
const mine = (s) =>
|
||||
r.query.pick(s.x, s.y)?.set === 'conf:points-update';
|
||||
ok(mine(sa) && !mine(sb), 'drawn where it was put');
|
||||
set.upsert([point(b, { meta: { n: 2 } })]);
|
||||
await drawn(h, r);
|
||||
ok(!mine(sa), 'moved: gone from where it was');
|
||||
deepEqual(
|
||||
r.query.pick(sb.x, sb.y)?.meta,
|
||||
{ n: 2 },
|
||||
'moved: picked where it now is, with its new meta',
|
||||
);
|
||||
// The eye is 2 km off.
|
||||
set.upsert([point(b, { displayRange: [0, 100] })]);
|
||||
await drawn(h, r);
|
||||
ok(!mine(sb), 'out of its display range: not drawn');
|
||||
set.upsert([point(b, { displayRange: [0, 1e6] })]);
|
||||
await drawn(h, r);
|
||||
ok(mine(sb), 'in its display range: drawn');
|
||||
set.upsert([point(b, { displayRange: [1e4, 1e6] })]);
|
||||
await drawn(h, r);
|
||||
ok(!mine(sb), 'nearer than its display range: not drawn');
|
||||
set.dispose();
|
||||
},
|
||||
),
|
||||
check(
|
||||
'draw.columns',
|
||||
'column updates are rows: sized, picked, removed',
|
||||
|
||||
Reference in new issue
Block a user