mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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.
128 lines
4.8 KiB
JavaScript
128 lines
4.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as Cesium from 'cesium';
|
|
import * as geo from '../../geo/index.js';
|
|
import { createCesiumSurface } from './surface.js';
|
|
import { createFakeViewer } from './testing/fakeViewer.mjs';
|
|
|
|
function setup() {
|
|
const viewer = createFakeViewer();
|
|
const { surface } = createCesiumSurface(viewer);
|
|
return { viewer, surface, scene: viewer.scene };
|
|
}
|
|
|
|
test('sampleHeight forwards the point and exclusions to the scene', () => {
|
|
const { viewer, surface, scene } = setup();
|
|
const place = geo.cartographic.fromDegrees(20, 10, 0);
|
|
const exclude = [{ primitive: 1 }];
|
|
assert.equal(surface.sampleHeight(place, exclude), 42);
|
|
const [position, excluded] = viewer.callsOf('scene.sampleHeight')[0].args;
|
|
assert.equal(position.longitude, place.longitude);
|
|
assert.equal(position.latitude, place.latitude);
|
|
assert.equal(excluded, exclude);
|
|
scene.sampleHeight = () => undefined;
|
|
assert.equal(surface.sampleHeight(place), undefined);
|
|
scene.sampleHeight = () => NaN;
|
|
assert.equal(surface.sampleHeight(place), undefined);
|
|
scene.sampleHeight = () => {
|
|
throw new Error('sampleHeight unsupported');
|
|
};
|
|
assert.equal(surface.sampleHeight(place), undefined, 'a throw is a miss');
|
|
});
|
|
|
|
test('supported flags follow the scene', () => {
|
|
const { surface, scene } = setup();
|
|
assert.equal(surface.supported, true);
|
|
assert.equal(surface.clampToHeightSupported, true);
|
|
assert.equal(surface.terrainHeightSupported, true);
|
|
scene.sampleHeightSupported = false;
|
|
scene.clampToHeightSupported = false;
|
|
scene.globe = undefined;
|
|
assert.equal(surface.supported, false);
|
|
assert.equal(surface.clampToHeightSupported, false);
|
|
assert.equal(surface.terrainHeightSupported, false);
|
|
const place = geo.cartographic.fromDegrees(20, 10, 0);
|
|
assert.equal(surface.sampleHeight(place), undefined);
|
|
assert.equal(surface.terrainHeight(place), undefined);
|
|
assert.equal(
|
|
surface.clampToHeight(geo.cartesian3.fromDegrees(20, 10, 10)),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
test('terrainHeight asks the globe', () => {
|
|
const { viewer, surface, scene } = setup();
|
|
const place = geo.cartographic.fromDegrees(20, 10, 0);
|
|
assert.equal(surface.terrainHeight(place), 12.5);
|
|
assert.equal(viewer.callsOf('globe.getHeight')[0].args[0], place);
|
|
scene.globe.getHeight = () => undefined;
|
|
assert.equal(surface.terrainHeight(place), undefined);
|
|
});
|
|
|
|
test('clampToHeight returns a geo value', () => {
|
|
const { viewer, surface } = setup();
|
|
const exclude = [];
|
|
const clamped = surface.clampToHeight(
|
|
geo.cartesian3.fromDegrees(20, 10, 5000),
|
|
exclude,
|
|
);
|
|
assert.ok(!(clamped instanceof Cesium.Cartesian3));
|
|
assert.equal(clamped.x, 6378200);
|
|
assert.equal(viewer.callsOf('scene.clampToHeight')[0].args[1], exclude);
|
|
});
|
|
|
|
test('tilesLoaded follows the first visible tileset, else the shown globe', () => {
|
|
const { viewer, surface, scene } = setup();
|
|
assert.equal(surface.tilesLoaded(), true, 'globe loaded');
|
|
scene.globe.tilesLoaded = false;
|
|
assert.equal(surface.tilesLoaded(), false, 'globe streaming');
|
|
scene.globe.show = false;
|
|
assert.equal(surface.tilesLoaded(), true, 'nothing streams');
|
|
const tileset = { show: true, tilesLoaded: false };
|
|
viewer.primitiveList.push({ show: true }, tileset);
|
|
assert.equal(surface.tilesLoaded(), false);
|
|
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);
|
|
});
|