mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
feat(globe): surface height quality
engine.surface.sampleHeightDetailed(place, { exclude, lod }) answers
{ height, source: 'tiles' | 'terrain', tileSizeM? } (src/globe/surfaceDetail.js).
On Navara tileSizeM is the extent of the tile that answered and
lod 'finest' takes the finest loaded tile, drawn or not; Cesium answers
tiles without a size, else the globe's terrain. acceptedSurfaceHeight()
turns an answer into a height or a miss: tiles larger than
MAX_FLOOR_TILE_SIZE_M (4 km) are too coarse, terrain is not the mesh.
The mesh floor sampler and the ground snap are engine-only now (a viewer
or scene reaches its engine through engineFromViewer, which also registers
the scene) and treat a coarse answer as a miss, as they treat undefined.
Measured on Navara at Austin: while the tiles stream, a 27.9 km tile reads
143.2 m where the ground is 122.5 m (a 1.8 km tile).
`exclude` takes the engine's own mover sets (MoverSet.id): Cesium hides a
set's primitive for the synchronous sample (Cesium matches excluded objects
per billboard, not per collection); Navara's ray only meets tiles.
"sampleHeight undefined in the app on Navara" did not reproduce: the
startup Austin sample is 121.9 m (tile 889 m) on Navara and 122.4 m on
Cesium; one ModelMesh class is patched.
S2 QA (scripts/qa-surface-heights.mjs, 20 places at JFK, SFO, AUS, roofs
and streets): Navara within 2 m of Cesium at 19/20 from 800 m and 18/20
from 15 km with lod 'finest' (gates 18 and 15); offsets per region
-0.21 / +0.4 / +0.1 m; the Empire State roof differs by 39 m (spire
geometry). Navara tile sizes at 800 m: 112-314 m.
This commit is contained in:
1 parent
f640890cf6
commit
645f042450
20 files changed
+635
-244
No files matched your search
@@ -64,7 +64,10 @@ export function createCesiumEngine(viewer, options = {}) {
|
||||
...(options.moverFactories ? { factories: options.moverFactories } : {}),
|
||||
})),
|
||||
render,
|
||||
surface: createCesiumSurface(viewer),
|
||||
// Mover sets in a surface `exclude` are hidden for the sample.
|
||||
surface: createCesiumSurface(viewer, {
|
||||
engineExclude: (entry) => movers?.primitiveOf(entry) ?? null,
|
||||
}),
|
||||
input: createCesiumInput(viewer, { ...options, picker: picker.picker }),
|
||||
credits,
|
||||
maps: createCesiumMaps(viewer, {
|
||||
|
||||
@@ -13,11 +13,15 @@ const engines = new WeakMap();
|
||||
* @returns {() => void} Unregister (only while it is still the registered one).
|
||||
*/
|
||||
export function registerViewerEngine(viewer, engine) {
|
||||
// The viewer's Cesium camera names the same engine, so callers that hold
|
||||
// only viewer.camera (camera sensitivity claims) reach the engine camera.
|
||||
const keys = [viewer, viewer?.camera, viewer?.scene?.camera].filter(
|
||||
(key, index, all) => key != null && all.indexOf(key) === index,
|
||||
);
|
||||
// The viewer's scene and Cesium camera name the same engine, so callers
|
||||
// that hold only viewer.scene (surface samplers) or viewer.camera (camera
|
||||
// sensitivity claims) reach the engine.
|
||||
const keys = [
|
||||
viewer,
|
||||
viewer?.scene,
|
||||
viewer?.camera,
|
||||
viewer?.scene?.camera,
|
||||
].filter((key, index, all) => key != null && all.indexOf(key) === index);
|
||||
for (const key of keys) engines.set(key, engine);
|
||||
return () => {
|
||||
for (const key of keys)
|
||||
@@ -26,8 +30,8 @@ export function registerViewerEngine(viewer, engine) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object | null | undefined} viewer A Cesium viewer or its camera,
|
||||
* or an engine (returned as is).
|
||||
* @param {object | null | undefined} viewer A Cesium viewer, its scene or
|
||||
* camera, or an engine (returned as is).
|
||||
* @returns {import('../contract.js').GlobeEngine | null} The registered
|
||||
* engine, or null.
|
||||
*/
|
||||
|
||||
@@ -307,6 +307,7 @@ export function createCesiumMovers(
|
||||
ordered.splice(at, 0, { order: options.order, primitive });
|
||||
rootCollection().add(primitive, at);
|
||||
return {
|
||||
primitive,
|
||||
commit: () => part.commit(store.dirty()),
|
||||
destroy() {
|
||||
part.destroy();
|
||||
@@ -321,6 +322,11 @@ export function createCesiumMovers(
|
||||
});
|
||||
return {
|
||||
movers: registry.movers,
|
||||
/** The primitive drawing a live mover set of this engine, or null. */
|
||||
primitiveOf(set) {
|
||||
const entry = set?.id ? registry.sets.get(set.id) : null;
|
||||
return entry && entry.set === set ? entry.part.primitive : null;
|
||||
},
|
||||
/** The set and instance a Cesium pick result belongs to, or null. */
|
||||
identify(picked) {
|
||||
const known = picked?.primitive ? owners.get(picked.primitive) : null;
|
||||
|
||||
+67
-16
@@ -1,42 +1,93 @@
|
||||
// GlobeSurface on a Cesium scene: the rendered-surface queries that
|
||||
// services/groundSnap and services/meshFloorSampler make today.
|
||||
// services/groundSnap and services/meshFloorSampler make.
|
||||
//
|
||||
// `exclude` takes the engine's own mover sets (engine.movers) as well as
|
||||
// Cesium objects: Cesium's sampleHeight matches excluded objects by the
|
||||
// picked primitive, which for a set is each billboard, point or model, so a
|
||||
// set is hidden for the sample instead (synchronous: nothing draws in
|
||||
// between) and shown again after it.
|
||||
|
||||
import { firstVisibleTileset } from '../../services/groundSnap.js';
|
||||
import { normalizeSurfaceOptions } from '../surfaceDetail.js';
|
||||
import { toGeo3 } from './convert.js';
|
||||
|
||||
const finite = (value) => (Number.isFinite(value) ? value : undefined);
|
||||
|
||||
/**
|
||||
* @param {Cesium.Viewer} viewer
|
||||
* @param {{ engineExclude?: (entry: any) => ({ show: boolean } | null) }} [options]
|
||||
* `engineExclude` maps an engine object (a mover set) to the Cesium
|
||||
* primitive that draws it, or null for a Cesium object.
|
||||
* @returns {{ surface: import('../contract.js').GlobeSurface, destroy: () => void }}
|
||||
*/
|
||||
export function createCesiumSurface(viewer) {
|
||||
export function createCesiumSurface(
|
||||
viewer,
|
||||
{ engineExclude = () => null } = {},
|
||||
) {
|
||||
const { scene } = viewer;
|
||||
const surface = {
|
||||
sampleHeight(cartographic, exclude) {
|
||||
if (!scene.sampleHeightSupported) return undefined;
|
||||
try {
|
||||
// Throws when unsupported (no depth textures); that is a miss.
|
||||
return finite(scene.sampleHeight(cartographic, exclude));
|
||||
} catch {
|
||||
return undefined;
|
||||
|
||||
// Runs `query(nativeExclude)` with the engine objects in `exclude` hidden.
|
||||
function excluding(exclude, query) {
|
||||
if (!exclude?.length) return query(exclude);
|
||||
let native = exclude;
|
||||
const hidden = [];
|
||||
for (const entry of exclude) {
|
||||
const primitive = engineExclude(entry);
|
||||
if (!primitive) continue;
|
||||
if (native === exclude)
|
||||
native = exclude.filter((other) => !engineExclude(other));
|
||||
if (primitive.show) {
|
||||
primitive.show = false;
|
||||
hidden.push(primitive);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return query(native);
|
||||
} finally {
|
||||
for (const primitive of hidden) primitive.show = true;
|
||||
}
|
||||
}
|
||||
|
||||
const sampleHeight = (cartographic, exclude) => {
|
||||
if (!scene.sampleHeightSupported) return undefined;
|
||||
try {
|
||||
// Throws when unsupported (no depth textures); that is a miss.
|
||||
return excluding(exclude, (native) =>
|
||||
finite(scene.sampleHeight(cartographic, native)),
|
||||
);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
const terrainHeight = (cartographic) =>
|
||||
scene.globe ? finite(scene.globe.getHeight(cartographic)) : undefined;
|
||||
|
||||
const surface = {
|
||||
sampleHeight,
|
||||
// Cesium samples the tiles it has loaded (lod 'finest' cannot do better
|
||||
// synchronously) and does not say which tile answered.
|
||||
sampleHeightDetailed(cartographic, options) {
|
||||
const { exclude } = normalizeSurfaceOptions(options);
|
||||
const height = sampleHeight(cartographic, exclude);
|
||||
if (height !== undefined) return { height, source: 'tiles' };
|
||||
const terrain = terrainHeight(cartographic);
|
||||
return terrain === undefined
|
||||
? undefined
|
||||
: { height: terrain, source: 'terrain' };
|
||||
},
|
||||
get supported() {
|
||||
return Boolean(scene.sampleHeightSupported);
|
||||
},
|
||||
terrainHeight(cartographic) {
|
||||
return scene.globe
|
||||
? finite(scene.globe.getHeight(cartographic))
|
||||
: undefined;
|
||||
},
|
||||
terrainHeight,
|
||||
get terrainHeightSupported() {
|
||||
return Boolean(scene.globe);
|
||||
},
|
||||
clampToHeight(position, exclude) {
|
||||
if (!scene.clampToHeightSupported) return undefined;
|
||||
try {
|
||||
return toGeo3(scene.clampToHeight(position, exclude));
|
||||
return excluding(exclude, (native) =>
|
||||
toGeo3(scene.clampToHeight(position, native)),
|
||||
);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -84,3 +84,44 @@ test('tilesLoaded follows the first visible tileset, else the shown globe', () =
|
||||
tileset.tilesLoaded = true;
|
||||
assert.equal(surface.tilesLoaded(), true);
|
||||
});
|
||||
|
||||
test('sampleHeightDetailed: tiles from sampleHeight, else terrain; no tile size', () => {
|
||||
const { surface, scene } = setup();
|
||||
const place = geo.cartographic.fromDegrees(20, 10, 0);
|
||||
assert.deepEqual(surface.sampleHeightDetailed(place), {
|
||||
height: 42,
|
||||
source: 'tiles',
|
||||
});
|
||||
scene.sampleHeight = () => undefined;
|
||||
assert.deepEqual(surface.sampleHeightDetailed(place, { lod: 'finest' }), {
|
||||
height: 12.5,
|
||||
source: 'terrain',
|
||||
});
|
||||
assert.throws(
|
||||
() => surface.sampleHeightDetailed(place, { lod: 2 }),
|
||||
TypeError,
|
||||
);
|
||||
});
|
||||
|
||||
test('an engine mover set in exclude is hidden for the sample, native objects pass', () => {
|
||||
const viewer = createFakeViewer();
|
||||
const collection = { show: true };
|
||||
const set = { id: 'flights' };
|
||||
const { surface } = createCesiumSurface(viewer, {
|
||||
engineExclude: (entry) => (entry === set ? collection : null),
|
||||
});
|
||||
const shownDuring = [];
|
||||
viewer.scene.sampleHeight = (position, excluded) => {
|
||||
shownDuring.push(collection.show, excluded);
|
||||
return 30;
|
||||
};
|
||||
const native = { primitive: 1 };
|
||||
const place = geo.cartographic.fromDegrees(20, 10, 0);
|
||||
assert.equal(surface.sampleHeight(place, [set, native]), 30);
|
||||
assert.deepEqual(shownDuring, [false, [native]]);
|
||||
assert.equal(collection.show, true, 'shown again after the sample');
|
||||
shownDuring.length = 0;
|
||||
surface.sampleHeightDetailed(place, { exclude: [set] });
|
||||
assert.deepEqual(shownDuring, [false, []]);
|
||||
assert.equal(collection.show, true);
|
||||
});
|
||||
Reference in new issue
Block a user