mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Read Street Level's camera and ground through the renderer's ports
The Street Level view maths no longer reads Cesium. The camera's place comes from the camera port's pose; the visible box and the view focus cast the query port's screen rays and meet them with the ground, the WGS84 ellipsoid raised to the ground height, in geo; heights come from the query port; the horizon cull for the marker and the cones tests against an ellipsoid 1,000 m below WGS84 in geo and re-culls on the frame port's pre-render. Ground clicks, the screen-centre aim, the nearest-image point, photo framing, the coverage refresh and the ground re-measure read the same ports and convert positions with geo. geo's ellipsoid functions (toLonLatH, rayEllipsoid and those under them) and horizonFrom take an optional ellipsoid, made with ellipsoidOf or offsetEllipsoid; anything else, a map index included, means WGS84. Tests check them against Cesium on raised and lowered ellipsoids. view, index, cameraFraming, groundClick and selection leave the Cesium allow-list. The Street Level entries are Cesium-free callers of the unbound factories: given a viewer of a caller's own, with no renderer bound, the caller loads ./render/cesium/unbound first. GhostMaps, which uses the horizon cull and is still on the list, loads the camera factory itself. Differences the contract does not let us avoid: - The ground under the camera no longer reads whether the globe is shown (the globe port has no visibility getter). Where 3D tiles answer under the camera they decide, as they did under Google 3D; elsewhere the terrain answers, then the drawn surface below the camera. Over 3D tiles shown on a map with the globe (and under other primitives at the nadir) those now count as ground. - Without depth-texture support the query port answers no heights, the terrain included, so the ground then reads as the ellipsoid. - selection and groundClick still read the click dispatcher's own pick for now; they move to draw-set hits with the coverage lines.
This commit is contained in:
1 parent
30b6be1da0
commit
a10f3a16e1
22 files changed
+567
-260
No files matched your search
@@ -10,12 +10,14 @@ import {
|
||||
visibleBbox,
|
||||
} from './view.js';
|
||||
import { latToTileY, lonToTileX, tilesForBbox } from './tileMath.js';
|
||||
import { rayCamera } from '../../testSupport/streetLevelFakes.mjs';
|
||||
import { rayCamera, streetPorts } from '../../testSupport/streetLevelFakes.mjs';
|
||||
import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
|
||||
const RAD = Math.PI / 180;
|
||||
/** A viewer 300 m above a street 1,600 m up (Denver-like). */
|
||||
function viewer({ globeShown, globeHeight }) {
|
||||
return {
|
||||
const view = {
|
||||
camera: {
|
||||
positionCartographic: {
|
||||
longitude: -104.99 * RAD,
|
||||
@@ -25,6 +27,7 @@ function viewer({ globeShown, globeHeight }) {
|
||||
},
|
||||
scene: { globe: { show: globeShown, getHeight: () => globeHeight } },
|
||||
};
|
||||
return bindFakeCesiumCamera(view, streetPorts(view));
|
||||
}
|
||||
|
||||
test('a shown globe answers the ground under the camera', () => {
|
||||
@@ -34,22 +37,23 @@ test('a shown globe answers the ground under the camera', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('a hidden globe (Google 3D) or a missing sample gives no ground', () => {
|
||||
// A hidden globe's getHeight is ignored even when it returns a number.
|
||||
test('without 3D tiles under the camera the terrain answers; a missing sample gives no ground', () => {
|
||||
// No tiles drawn there: the terrain answers, globe shown or hidden.
|
||||
assert.equal(
|
||||
groundUnderCamera(viewer({ globeShown: false, globeHeight: 0 })),
|
||||
null,
|
||||
0,
|
||||
);
|
||||
assert.equal(
|
||||
groundUnderCamera(viewer({ globeShown: true, globeHeight: undefined })),
|
||||
null,
|
||||
);
|
||||
assert.equal(groundUnderCamera({}), null);
|
||||
assert.equal(groundUnderCamera(null), null);
|
||||
});
|
||||
|
||||
/** The Denver viewer with Google 3D: no globe, a sampleable rendered surface. */
|
||||
function google3d(sample) {
|
||||
const view = viewer({ globeShown: false, globeHeight: 0 });
|
||||
const view = viewer({ globeShown: false, globeHeight: undefined });
|
||||
view.scene.sampleHeightSupported = true;
|
||||
view.scene.sampleHeight = () => sample;
|
||||
return view;
|
||||
@@ -59,6 +63,22 @@ test('on Google 3D the rendered surface answers the ground under the camera', ()
|
||||
assert.equal(groundUnderCamera(google3d(1612)), 1612);
|
||||
});
|
||||
|
||||
test('where the 3D tiles answer, they decide, whatever the terrain says', () => {
|
||||
const view = google3d(1612);
|
||||
// A hidden globe's terrain can be stale (or the bare ellipsoid's 0).
|
||||
view.scene.globe.getHeight = () => 0;
|
||||
assert.equal(groundUnderCamera(view), 1612);
|
||||
// A roof above the camera is not the ground, and tiles still loading
|
||||
// (kilometres underground) are not either: unknown, so measured again.
|
||||
view.scene.sampleHeight = () => 1950;
|
||||
assert.equal(groundUnderCamera(view), null);
|
||||
view.scene.sampleHeight = () => -14_886;
|
||||
assert.equal(groundUnderCamera(view), null);
|
||||
// No tiles there at all: the terrain answers.
|
||||
view.scene.sampleHeight = () => undefined;
|
||||
assert.equal(groundUnderCamera(view), 0);
|
||||
});
|
||||
|
||||
test('an implausible or above-camera surface sample gives no ground', () => {
|
||||
// Before tiles stream in, sampleHeight can read kilometres underground.
|
||||
assert.equal(groundUnderCamera(google3d(-14_886)), null);
|
||||
@@ -70,17 +90,29 @@ test('an implausible or above-camera surface sample gives no ground', () => {
|
||||
/** A camera whose screen rays land on a grid of lon/lat points. */
|
||||
function gridViewer(lons, lats) {
|
||||
const points = [];
|
||||
for (const lat of lats)
|
||||
for (const lon of lons)
|
||||
points.push(Cesium.Cartesian3.fromDegrees(lon, lat));
|
||||
for (const lat of lats) for (const lon of lons) points.push([lon, lat]);
|
||||
let next = 0;
|
||||
return {
|
||||
scene: { canvas: { clientWidth: 100, clientHeight: 100 }, globe: {} },
|
||||
const viewer = {};
|
||||
bindRenderer(viewer, {
|
||||
canvas: { clientWidth: 100, clientHeight: 100 },
|
||||
camera: {
|
||||
pickEllipsoid: () => points[next++ % points.length],
|
||||
positionCartographic: { longitude: 0, latitude: 0, height: 1000 },
|
||||
pose: () => ({ lon: 0, lat: 0, height: 1000 }),
|
||||
},
|
||||
};
|
||||
query: {
|
||||
// Straight down onto the next grid point, from 1 km above it.
|
||||
pickRay() {
|
||||
const [lon, lat] = points[next++ % points.length];
|
||||
const origin = Cesium.Cartesian3.fromDegrees(lon, lat, 1000);
|
||||
const ground = Cesium.Cartesian3.fromDegrees(lon, lat);
|
||||
const direction = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(ground, origin, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
return { origin, direction };
|
||||
},
|
||||
},
|
||||
});
|
||||
return viewer;
|
||||
}
|
||||
|
||||
test('a view across the date line is a narrow box with west > east', () => {
|
||||
@@ -97,7 +129,7 @@ test('an ordinary view keeps west < east', () => {
|
||||
|
||||
/** A pinhole viewer `agl` m above ground `ground` m up, looking north. */
|
||||
function pinhole({ lon, lat, ground, agl, pitch, w = 1600, h = 900 }) {
|
||||
return {
|
||||
const view = {
|
||||
scene: {
|
||||
canvas: { clientWidth: w, clientHeight: h },
|
||||
globe: { show: false, ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
@@ -111,6 +143,7 @@ function pinhole({ lon, lat, ground, agl, pitch, w = 1600, h = 900 }) {
|
||||
height: h,
|
||||
}),
|
||||
};
|
||||
return bindFakeCesiumCamera(view, streetPorts(view));
|
||||
}
|
||||
|
||||
test('a tilted street view over high ground boxes the streets it looks at, not the horizon', () => {
|
||||
@@ -236,49 +269,49 @@ test('metresBetween measures the short way round the date line', () => {
|
||||
|
||||
/**
|
||||
* A horizon cull over `items` for a camera the test moves, with the frame's
|
||||
* pre-render listeners and a count of the points tested against the horizon.
|
||||
* pre-render listeners and a count of the camera poses read.
|
||||
*/
|
||||
function cullHarness(t, items) {
|
||||
const visible = t.mock.method(
|
||||
Cesium.EllipsoidalOccluder.prototype,
|
||||
'isPointVisible',
|
||||
);
|
||||
const preRender = new Set();
|
||||
const camera = { positionWC: Cesium.Cartesian3.fromDegrees(0, 0, 1e7) };
|
||||
const viewer = {
|
||||
camera,
|
||||
scene: {
|
||||
preRender: {
|
||||
addEventListener(listener) {
|
||||
preRender.add(listener);
|
||||
return () => preRender.delete(listener);
|
||||
},
|
||||
let eye = Cesium.Cartesian3.fromDegrees(0, 0, 1e7);
|
||||
let poses = 0;
|
||||
const viewer = {};
|
||||
bindRenderer(viewer, {
|
||||
camera: {
|
||||
pose: () => {
|
||||
poses++;
|
||||
return { lon: 0, lat: 0, height: 1e7, position: { ...eye } };
|
||||
},
|
||||
},
|
||||
};
|
||||
frame: {
|
||||
on(phase, listener) {
|
||||
assert.equal(phase, 'preRender');
|
||||
preRender.add(listener);
|
||||
return () => preRender.delete(listener);
|
||||
},
|
||||
},
|
||||
});
|
||||
// Items handed to a cull pass: what a still camera must not test again.
|
||||
const tested = { count: 0 };
|
||||
let changes = 0;
|
||||
const cull = createHorizonCull({
|
||||
getViewer: () => viewer,
|
||||
items: () => items,
|
||||
items: () => {
|
||||
tested.count += items.length;
|
||||
return items;
|
||||
},
|
||||
onChange: () => changes++,
|
||||
});
|
||||
return {
|
||||
cull,
|
||||
preRender,
|
||||
tested: () => visible.mock.callCount(),
|
||||
poses: () => poses,
|
||||
tested: () => tested.count,
|
||||
changes: () => changes,
|
||||
frame: () => {
|
||||
for (const listener of [...preRender]) listener();
|
||||
},
|
||||
// Moved in place, as Cesium updates positionWC.
|
||||
moveTo: (lon, lat) =>
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
lon,
|
||||
lat,
|
||||
1e7,
|
||||
undefined,
|
||||
camera.positionWC,
|
||||
),
|
||||
moveTo: (lon, lat) => (eye = Cesium.Cartesian3.fromDegrees(lon, lat, 1e7)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -337,11 +370,20 @@ function cullFrom(camera, points) {
|
||||
position: Cesium.Cartesian3.fromDegrees(lon, lat, height),
|
||||
show: true,
|
||||
}));
|
||||
const viewer = {};
|
||||
bindRenderer(viewer, {
|
||||
camera: {
|
||||
pose: () => ({
|
||||
lon: camera[0],
|
||||
lat: camera[1],
|
||||
height: camera[2],
|
||||
position: Cesium.Cartesian3.fromDegrees(...camera),
|
||||
}),
|
||||
},
|
||||
frame: { on: () => () => {} },
|
||||
});
|
||||
const horizon = createHorizonCull({
|
||||
getViewer: () => ({
|
||||
camera: { positionWC: Cesium.Cartesian3.fromDegrees(...camera) },
|
||||
scene: { preRender: { addEventListener: () => () => {} } },
|
||||
}),
|
||||
getViewer: () => viewer,
|
||||
items: () => items,
|
||||
});
|
||||
horizon.update();
|
||||
|
||||
Reference in new issue
Block a user