mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Name the surface heights answer against: globe.surfaceVersion and the surface settle kind
A new capability, surfaceIdentity, adds globe.surfaceVersion(): a number that changes whenever what surface heights answer against changes (base, terrain or photoreal swapped, the globe shown or hidden) and never on camera moves or tile loads, so the app can key cached heights by it. The settle kind 'surface' says whether that surface has loaded what is in view: the terrain while the globe is shown, otherwise the drawn tiles, false with neither; a renderer without the capability answers it as base. The Cesium globe port reads both off the scene, so a base changed around the port counts too; its versions come from one counter shared by every port. The stub bumps on real base, terrain, photoreal and visibility changes. A conformance check and a globe port test cover them.
This commit is contained in:
1 parent
e15cfb3e32
commit
456645f291
11 files changed
+165
-3
No files matched your search
@@ -114,6 +114,9 @@ async function terrainProvider(spec, { worldDataToken }) {
|
||||
throw new TypeError(`Unknown terrain kind: ${spec.kind}`);
|
||||
}
|
||||
|
||||
/** The last `surfaceVersion` any globe port handed out. */
|
||||
let surfaceVersions = 0;
|
||||
|
||||
/**
|
||||
* @param {object} widget A Cesium `CesiumWidget` or `Viewer`.
|
||||
* @param {{capabilities: ReadonlySet<string>,
|
||||
@@ -370,7 +373,56 @@ export function createCesiumGlobe(
|
||||
};
|
||||
const imageryLoaded = () => imagery.pending() === 0 && terrainLoaded();
|
||||
|
||||
/**
|
||||
* `surface`: what surface heights answer from has loaded what is in view:
|
||||
* the globe's terrain while it is shown, otherwise the shown 3D tiles;
|
||||
* false with neither drawn.
|
||||
*/
|
||||
function surfaceLoaded() {
|
||||
if (scene.globe?.show) return scene.globe.tilesLoaded !== false;
|
||||
let found = false;
|
||||
for (const tileset of tilesets()) {
|
||||
if (!tileset.show || tileset.isDestroyed?.()) continue;
|
||||
found = true;
|
||||
if (tileset.tilesLoaded === false) return false;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// `surfaceVersion`: bumped when what heights answer against changes, read
|
||||
// off the scene (so a base changed around the port counts too): whether
|
||||
// the globe is shown, its terrain provider, and the shown 3D tilesets.
|
||||
// Taken from one counter for every port, so no two surfaces share one.
|
||||
let surfaceVersion = 0;
|
||||
const surfaceSeen = { globe: null, terrain: null, tiles: new Set() };
|
||||
function readSurfaceVersion() {
|
||||
const globe = Boolean(scene.globe?.show);
|
||||
const terrain = scene.globe?.terrainProvider ?? null;
|
||||
let changed =
|
||||
surfaceSeen.globe !== globe || surfaceSeen.terrain !== terrain;
|
||||
// The shown tilesets as a set: their order among the primitives is no
|
||||
// change to the surface.
|
||||
let count = 0;
|
||||
for (const tileset of tilesets()) {
|
||||
if (!tileset.show || tileset.isDestroyed?.()) continue;
|
||||
count += 1;
|
||||
if (!surfaceSeen.tiles.has(tileset)) changed = true;
|
||||
}
|
||||
if (count !== surfaceSeen.tiles.size) changed = true;
|
||||
if (changed) {
|
||||
surfaceSeen.globe = globe;
|
||||
surfaceSeen.terrain = terrain;
|
||||
surfaceSeen.tiles.clear();
|
||||
for (const tileset of tilesets())
|
||||
if (tileset.show && !tileset.isDestroyed?.())
|
||||
surfaceSeen.tiles.add(tileset);
|
||||
surfaceVersion = ++surfaceVersions;
|
||||
}
|
||||
return surfaceVersion;
|
||||
}
|
||||
|
||||
function isSettled(kind) {
|
||||
if (kind === 'surface' && can('surfaceIdentity')) return surfaceLoaded();
|
||||
if (kind === 'terrain') return terrainLoaded();
|
||||
if (kind === 'tiles') return tilesLoaded();
|
||||
if (kind === 'imagery') return imageryLoaded();
|
||||
@@ -440,6 +492,7 @@ export function createCesiumGlobe(
|
||||
};
|
||||
if (can('globeVisibility'))
|
||||
port.isGlobeVisible = () => scene.globe?.show === true;
|
||||
if (can('surfaceIdentity')) port.surfaceVersion = readSurfaceVersion;
|
||||
if (can('splitSwipe')) {
|
||||
// Cesium's split starts at the canvas's left edge, as the scene was
|
||||
// made: a `left` layer shows once the split moves.
|
||||
@@ -473,7 +526,12 @@ provideUnboundGlobe((viewer) => {
|
||||
if (!viewer?.scene) return null;
|
||||
// Visibility reads back only from a globe that keeps it: a scene made
|
||||
// without one gives no reading, so its callers keep their own default.
|
||||
const capabilities = new Set(['imageHooks', 'imageryOnTiles', 'splitSwipe']);
|
||||
const capabilities = new Set([
|
||||
'imageHooks',
|
||||
'imageryOnTiles',
|
||||
'splitSwipe',
|
||||
'surfaceIdentity',
|
||||
]);
|
||||
if (typeof viewer.scene.globe?.show === 'boolean')
|
||||
capabilities.add('globeVisibility');
|
||||
const { port, dispose } = createCesiumGlobe(viewer, {
|
||||
|
||||
@@ -602,3 +602,30 @@ test('a provider that fails to build is told as an error of its root tile', asyn
|
||||
assert.deepEqual(errors, [{ tile: { x: 0, y: 0, level: 0 } }]);
|
||||
layer.remove();
|
||||
});
|
||||
|
||||
test('surfaceVersion follows what heights answer against; surface settles on it', () => {
|
||||
const { scene, port } = setup(new Set([...ALL, 'surfaceIdentity']));
|
||||
const first = port.surfaceVersion();
|
||||
assert.equal(port.surfaceVersion(), first, 'steady while nothing changes');
|
||||
assert.equal(port.isSettled('surface'), true, 'the globe has loaded');
|
||||
scene.globe.tilesLoaded = false;
|
||||
assert.equal(port.isSettled('surface'), false, 'the globe still loading');
|
||||
assert.equal(port.surfaceVersion(), first, 'tile loads are not a change');
|
||||
scene.globe.show = false;
|
||||
const hidden = port.surfaceVersion();
|
||||
assert.notEqual(hidden, first, 'the globe hidden');
|
||||
assert.equal(port.isSettled('surface'), false, 'no globe and no tiles');
|
||||
const tileset = fakeTileset();
|
||||
scene.primitives.add(tileset);
|
||||
const tiled = port.surfaceVersion();
|
||||
assert.notEqual(tiled, hidden, 'tiles shown');
|
||||
assert.equal(port.isSettled('surface'), true, 'the tiles have loaded');
|
||||
scene.globe.show = true;
|
||||
scene.globe.terrainProvider = {};
|
||||
assert.notEqual(port.surfaceVersion(), tiled, 'new terrain under the globe');
|
||||
// Without the capability there is no version and surface answers as base.
|
||||
const plain = setup();
|
||||
assert.equal(plain.port.surfaceVersion, undefined);
|
||||
plain.scene.globe.show = false;
|
||||
assert.equal(plain.port.isSettled('surface'), plain.port.isSettled('base'));
|
||||
});
|
||||
@@ -76,6 +76,7 @@ export const CESIUM_CHECKS = new Set([
|
||||
'globe.imagery',
|
||||
'globe.sky',
|
||||
'globe.split',
|
||||
'globe.surfaceVersion',
|
||||
'globe.visible',
|
||||
'globe.withoutImageHooks',
|
||||
'input.behaviours',
|
||||
|
||||
@@ -44,6 +44,7 @@ const GLOBE_CAPABILITIES = [
|
||||
'imageryOnTiles',
|
||||
'splitSwipe',
|
||||
'imageHooks',
|
||||
'surfaceIdentity',
|
||||
'globeVisibility',
|
||||
];
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ test('capabilities follow what the scene supports', () => {
|
||||
'imageryOnTiles',
|
||||
'splitSwipe',
|
||||
'imageHooks',
|
||||
'surfaceIdentity',
|
||||
];
|
||||
const globe = { show: true };
|
||||
const draw = ['models', 'quads', 'meshes'];
|
||||
|
||||
Reference in new issue
Block a user