mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Cut duplicated and dead code across the engines, the layers and the QA scripts
- src/geo drops the ported debug argument checks and the tests that bitExact already covers; package boundaries accept a directory entry, so src/geo/ is listed once per group. - Cesium no longer carries movers and lines nobody draws with: they are optional engine capabilities. The fake engine and the Cesium camera use the shared cameraMath; unused contract tables, clock.ticked, the 'finest' surface detail and Navara click statistics are gone. - ALPR keeps one overlay core and one presentation model for both engines, bikeshare one station bookkeeping, the Navara ground effects one definition helper; image atlases, view centres, mover banks and colours are shared. - The legacy switch route, the clock offset and rate controls and other unused exports are removed. - The acceptance runs the Navara draw, geo import and scope checks; scenarios use the harness switch and page helpers; the main chunk check keeps the size budget only and runs once in CI.
This commit is contained in:
1 parent
c502404e1d
commit
7abf74518f
272 files changed
+4828
-10213
No files matched your search
@@ -11,7 +11,7 @@ import { createBloomPort } from './bloomSettings.js';
|
||||
import { pipelinePassNames } from './internals.js';
|
||||
import { withPassDisposal } from './frameDescriptor.js';
|
||||
|
||||
export const BLOOM_EFFECT_KEY = 'gevBloom';
|
||||
const BLOOM_EFFECT_KEY = 'gevBloom';
|
||||
|
||||
function apply(effect, settings) {
|
||||
effect.luminanceMaterial.threshold = settings.luminanceThreshold;
|
||||
|
||||
@@ -1,461 +0,0 @@
|
||||
// Camera math for the Navara engine, on src/geo only: Cesium's heading/pitch/
|
||||
// roll convention, the perspective projection and picks of a camera given as
|
||||
// { position, direction, up, fovy, width, height } (Earth-fixed metres, unit
|
||||
// vectors, vertical fov in radians, CSS pixels), Cesium's view rectangle and
|
||||
// horizon test, and the Navara setCamera pose (degrees). Ported from the S4
|
||||
// spike (src/bench/cameraConvention.js) and the contract's fake engine; the
|
||||
// projection matches what Navara draws because the engine keeps Navara's
|
||||
// camera on the same pose and fov.
|
||||
|
||||
import * as geo from '../../geo/index.js';
|
||||
|
||||
const { cartesian2, cartesian3, cartographic, math, matrix4 } = geo;
|
||||
const WGS84 = geo.ellipsoid.WGS84;
|
||||
const RADII = WGS84.radii;
|
||||
const MAXIMUM_RADIUS = Math.max(RADII.x, RADII.y, RADII.z);
|
||||
// The near/far planes of viewProjection (only its z row depends on them).
|
||||
const NEAR = 1;
|
||||
const FAR = 1e9;
|
||||
// Cesium's MINIMUM_ZOOM (range for a radius-0 sphere) and the camera
|
||||
// controller's default zoom distances.
|
||||
const ZERO_RADIUS_SPHERE_RANGE = 100;
|
||||
const MINIMUM_ZOOM_DISTANCE = 1;
|
||||
const MAXIMUM_ZOOM_DISTANCE = Infinity;
|
||||
// Cesium's default PerspectiveFrustum fov, across the wider canvas side.
|
||||
const CESIUM_FOV = Math.PI / 3;
|
||||
|
||||
const copy3 = (value) => cartesian3.create(value.x, value.y, value.z);
|
||||
const scaled = (vector, scalar) =>
|
||||
cartesian3.multiplyByScalar(vector, scalar, cartesian3.create());
|
||||
const sum = (...vectors) =>
|
||||
vectors.reduce(
|
||||
(total, vector) => cartesian3.add(total, vector, total),
|
||||
cartesian3.create(),
|
||||
);
|
||||
const unit = (vector) => cartesian3.normalize(vector, cartesian3.create());
|
||||
const cross = (left, right) =>
|
||||
cartesian3.cross(left, right, cartesian3.create());
|
||||
|
||||
/** An angle in [0, 2π), as Cesium's camera reports heading and roll. */
|
||||
export function wrapAngle(angle) {
|
||||
const value = math.zeroToTwoPi(angle);
|
||||
return value < 1e-12 || math.TWO_PI - value < 1e-12 ? 0 : value;
|
||||
}
|
||||
|
||||
function localAxes(position) {
|
||||
const frame = geo.transforms.eastNorthUpToFixedFrame(position, WGS84);
|
||||
return {
|
||||
east: cartesian3.create(frame[0], frame[1], frame[2]),
|
||||
north: cartesian3.create(frame[4], frame[5], frame[6]),
|
||||
up: cartesian3.create(frame[8], frame[9], frame[10]),
|
||||
};
|
||||
}
|
||||
const combine = (axes, e, n, u) =>
|
||||
sum(scaled(axes.east, e), scaled(axes.north, n), scaled(axes.up, u));
|
||||
const toLocal = (axes, vector) => ({
|
||||
e: cartesian3.dot(vector, axes.east),
|
||||
n: cartesian3.dot(vector, axes.north),
|
||||
u: cartesian3.dot(vector, axes.up),
|
||||
});
|
||||
|
||||
/**
|
||||
* Direction and up for heading/pitch/roll (radians) in the local frame at
|
||||
* `position`, as Cesium's setView builds them: heading 0 looks north and turns
|
||||
* clockwise, positive pitch looks up, positive roll tilts up to the right.
|
||||
*/
|
||||
export function orientationVectors(position, heading, pitch, roll) {
|
||||
const axes = localAxes(position);
|
||||
const cosPitch = Math.cos(pitch);
|
||||
const direction = combine(
|
||||
axes,
|
||||
Math.sin(heading) * cosPitch,
|
||||
Math.cos(heading) * cosPitch,
|
||||
Math.sin(pitch),
|
||||
);
|
||||
const levelRight = combine(axes, Math.cos(heading), -Math.sin(heading), 0);
|
||||
const levelUp = cross(levelRight, direction);
|
||||
const up = sum(
|
||||
scaled(levelUp, Math.cos(roll)),
|
||||
scaled(levelRight, Math.sin(roll)),
|
||||
);
|
||||
return { direction: unit(direction), up: unit(up) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Cesium's camera heading/pitch/roll getters: heading and roll in [0, 2π);
|
||||
* within 1e-3 of straight up or down roll is 0 and heading follows `up`.
|
||||
*/
|
||||
export function headingPitchRoll(
|
||||
position,
|
||||
direction,
|
||||
up,
|
||||
verticalEpsilon = 1e-3,
|
||||
) {
|
||||
const axes = localAxes(position);
|
||||
const d = toLocal(axes, direction);
|
||||
const u = toLocal(axes, up);
|
||||
const r = toLocal(axes, cross(direction, up));
|
||||
const vertical = Math.abs(Math.abs(d.u) - 1) <= verticalEpsilon;
|
||||
const raw = vertical
|
||||
? Math.atan2(u.n, u.e) - math.PI_OVER_TWO
|
||||
: Math.atan2(d.n, d.e) - math.PI_OVER_TWO;
|
||||
return {
|
||||
heading: wrapAngle(math.TWO_PI - math.zeroToTwoPi(raw)),
|
||||
pitch: math.PI_OVER_TWO - Math.acos(math.clamp(d.u, -1, 1)),
|
||||
roll: vertical ? 0 : wrapAngle(Math.atan2(-r.u, u.u)),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Navara setCamera/flyTo pose for a camera pose: the eye's longitude,
|
||||
* latitude and ellipsoid height, and the same heading/pitch/roll in degrees
|
||||
* (Navara 0.2.1 uses Cesium's convention, S4), heading in [0, 360) and roll
|
||||
* in (−180, 180].
|
||||
*/
|
||||
export function navaraPose(position, direction, up) {
|
||||
const place = cartographic.fromCartesian(position, WGS84);
|
||||
// Navara orients its camera in the surface ENU frame at lng/lat. Cesium's
|
||||
// Cartesian ENU normal at a high-altitude eye differs from that frame.
|
||||
const surface = cartesian3.fromRadians(place.longitude, place.latitude, 0);
|
||||
// Keep near-nadir tilt when serializing; the public pose keeps Cesium's
|
||||
// wider singularity tolerance, which would discard it here.
|
||||
const angles = headingPitchRoll(surface, direction, up, 1e-14);
|
||||
let roll = math.toDegrees(angles.roll);
|
||||
if (roll > 180) roll -= 360;
|
||||
return {
|
||||
lng: math.toDegrees(place.longitude),
|
||||
lat: math.toDegrees(place.latitude),
|
||||
height: place.height,
|
||||
heading: math.toDegrees(angles.heading),
|
||||
pitch: math.toDegrees(angles.pitch),
|
||||
roll,
|
||||
};
|
||||
}
|
||||
|
||||
/** Cesium's vertical fov for a canvas: 60° across the wider side. */
|
||||
export function cesiumFovy(width, height) {
|
||||
return width > height
|
||||
? 2 * Math.atan(Math.tan(CESIUM_FOV / 2) * (height / width))
|
||||
: CESIUM_FOV;
|
||||
}
|
||||
|
||||
const aspectOf = (camera) => camera.width / camera.height;
|
||||
const rightOf = (camera) => unit(cross(camera.direction, camera.up));
|
||||
|
||||
/** Window position (CSS px) of a world point; undefined behind the camera. */
|
||||
export function projectToWindow(camera, position, result) {
|
||||
const offset = cartesian3.subtract(
|
||||
position,
|
||||
camera.position,
|
||||
cartesian3.create(),
|
||||
);
|
||||
const depth = cartesian3.dot(offset, camera.direction);
|
||||
if (!(depth > 0)) return undefined;
|
||||
const tangent = Math.tan(camera.fovy / 2);
|
||||
const ndcX =
|
||||
cartesian3.dot(offset, rightOf(camera)) /
|
||||
(depth * tangent * aspectOf(camera));
|
||||
const ndcY = cartesian3.dot(offset, camera.up) / (depth * tangent);
|
||||
const x = ((ndcX + 1) / 2) * camera.width;
|
||||
const y = ((1 - ndcY) / 2) * camera.height;
|
||||
if (!result) return cartesian2.create(x, y);
|
||||
result.x = x;
|
||||
result.y = y;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** World → clip matrix consistent with projectToWindow (column-major). */
|
||||
export function viewProjection(camera, result = matrix4.create()) {
|
||||
const f = 1 / Math.tan(camera.fovy / 2);
|
||||
const rows = [
|
||||
[rightOf(camera), f / aspectOf(camera)],
|
||||
[camera.up, f],
|
||||
];
|
||||
const D = camera.direction;
|
||||
const P = camera.position;
|
||||
for (const [row, [axis, scale]] of rows.entries()) {
|
||||
result[row] = axis.x * scale;
|
||||
result[4 + row] = axis.y * scale;
|
||||
result[8 + row] = axis.z * scale;
|
||||
result[12 + row] = -cartesian3.dot(axis, P) * scale;
|
||||
}
|
||||
// Eye z is −direction·(p − position); clip.w = −z_eye.
|
||||
const A = (FAR + NEAR) / (NEAR - FAR);
|
||||
const B = (2 * FAR * NEAR) / (NEAR - FAR);
|
||||
result[2] = -D.x * A;
|
||||
result[6] = -D.y * A;
|
||||
result[10] = -D.z * A;
|
||||
result[14] = cartesian3.dot(D, P) * A + B;
|
||||
result[3] = D.x;
|
||||
result[7] = D.y;
|
||||
result[11] = D.z;
|
||||
result[15] = -cartesian3.dot(D, P);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** The unit ray from the eye through a window position (CSS px). */
|
||||
export function pickRay(camera, screen) {
|
||||
const tangent = Math.tan(camera.fovy / 2);
|
||||
const ndcX = (2 * screen.x) / camera.width - 1;
|
||||
const ndcY = 1 - (2 * screen.y) / camera.height;
|
||||
const direction = sum(
|
||||
camera.direction,
|
||||
scaled(rightOf(camera), ndcX * tangent * aspectOf(camera)),
|
||||
scaled(camera.up, ndcY * tangent),
|
||||
);
|
||||
return { origin: copy3(camera.position), direction: unit(direction) };
|
||||
}
|
||||
|
||||
/** Nearest intersection of a ray with the WGS84 ellipsoid, if any. */
|
||||
export function intersectEllipsoid(origin, direction) {
|
||||
const o = [origin.x / RADII.x, origin.y / RADII.y, origin.z / RADII.z];
|
||||
const d = [
|
||||
direction.x / RADII.x,
|
||||
direction.y / RADII.y,
|
||||
direction.z / RADII.z,
|
||||
];
|
||||
const a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
|
||||
const b = 2 * (o[0] * d[0] + o[1] * d[1] + o[2] * d[2]);
|
||||
const c = o[0] * o[0] + o[1] * o[1] + o[2] * o[2] - 1;
|
||||
const discriminant = b * b - 4 * a * c;
|
||||
if (discriminant < 0) return undefined;
|
||||
const root = Math.sqrt(discriminant);
|
||||
const nearest = (-b - root) / (2 * a);
|
||||
const t = nearest > 0 ? nearest : (-b + root) / (2 * a);
|
||||
if (!(t > 0)) return undefined;
|
||||
return sum(origin, scaled(direction, t));
|
||||
}
|
||||
|
||||
/** Cesium's camera.pickEllipsoid for a window position. */
|
||||
export function pickEllipsoid(camera, screen) {
|
||||
return intersectEllipsoid(camera.position, pickRay(camera, screen).direction);
|
||||
}
|
||||
|
||||
// horizonVisible runs per label per frame (worldOverlay): no allocation.
|
||||
const horizonCamera = cartesian3.create();
|
||||
const horizonTarget = cartesian3.create();
|
||||
const horizonVt = cartesian3.create();
|
||||
|
||||
/** Cesium's EllipsoidalOccluder.isPointVisible from `eye`. */
|
||||
export function horizonVisible(eye, position) {
|
||||
const camera = cartesian3.fromElements(
|
||||
eye.x / RADII.x,
|
||||
eye.y / RADII.y,
|
||||
eye.z / RADII.z,
|
||||
horizonCamera,
|
||||
);
|
||||
const limbSquared = cartesian3.magnitudeSquared(camera) - 1;
|
||||
const target = cartesian3.fromElements(
|
||||
position.x / RADII.x,
|
||||
position.y / RADII.y,
|
||||
position.z / RADII.z,
|
||||
horizonTarget,
|
||||
);
|
||||
const vt = cartesian3.subtract(target, camera, horizonVt);
|
||||
const vtDotVc = -cartesian3.dot(vt, camera);
|
||||
const occluded =
|
||||
limbSquared < 0
|
||||
? vtDotVc > 0
|
||||
: vtDotVc > limbSquared &&
|
||||
(vtDotVc * vtDotVc) / cartesian3.magnitudeSquared(vt) > limbSquared;
|
||||
return !occluded;
|
||||
}
|
||||
|
||||
// Cesium's computeHorizonQuad: four limb points around the eye's nadir, in the
|
||||
// corner order upper-left, lower-left, lower-right, upper-right.
|
||||
function horizonQuad(position) {
|
||||
const q = cartesian3.create(
|
||||
position.x / RADII.x,
|
||||
position.y / RADII.y,
|
||||
position.z / RADII.z,
|
||||
);
|
||||
const qMagnitude = cartesian3.magnitude(q);
|
||||
const qUnit = unit(q);
|
||||
let east;
|
||||
let north;
|
||||
if (cartesian3.equalsEpsilon(qUnit, cartesian3.UNIT_Z, math.EPSILON10)) {
|
||||
east = cartesian3.create(0, 1, 0);
|
||||
north = cartesian3.create(0, 0, 1);
|
||||
} else {
|
||||
east = unit(cross(cartesian3.UNIT_Z, qUnit));
|
||||
north = unit(cross(qUnit, east));
|
||||
}
|
||||
const center = scaled(qUnit, 1 / qMagnitude);
|
||||
const offset =
|
||||
Math.sqrt(Math.max(0, cartesian3.magnitudeSquared(q) - 1)) / qMagnitude;
|
||||
const point = (n, e) => {
|
||||
const p = sum(center, scaled(north, n * offset), scaled(east, e * offset));
|
||||
return cartesian3.create(p.x * RADII.x, p.y * RADII.y, p.z * RADII.z);
|
||||
};
|
||||
return [point(1, -1), point(-1, -1), point(-1, 1), point(1, 1)];
|
||||
}
|
||||
|
||||
// Cesium's Rectangle.fromCartographicArray, including the antimeridian case.
|
||||
function rectangleFromCartographics(points) {
|
||||
let west = Infinity;
|
||||
let east = -Infinity;
|
||||
let westOverIDL = Infinity;
|
||||
let eastOverIDL = -Infinity;
|
||||
let south = Infinity;
|
||||
let north = -Infinity;
|
||||
for (const { longitude, latitude } of points) {
|
||||
west = Math.min(west, longitude);
|
||||
east = Math.max(east, longitude);
|
||||
south = Math.min(south, latitude);
|
||||
north = Math.max(north, latitude);
|
||||
const adjusted = longitude >= 0 ? longitude : longitude + math.TWO_PI;
|
||||
westOverIDL = Math.min(westOverIDL, adjusted);
|
||||
eastOverIDL = Math.max(eastOverIDL, adjusted);
|
||||
}
|
||||
if (east - west > eastOverIDL - westOverIDL) {
|
||||
west = westOverIDL > Math.PI ? westOverIDL - math.TWO_PI : westOverIDL;
|
||||
east = eastOverIDL > Math.PI ? eastOverIDL - math.TWO_PI : eastOverIDL;
|
||||
}
|
||||
return { west, south, east, north };
|
||||
}
|
||||
|
||||
// Whether the sphere around the Earth is wholly outside the view frustum.
|
||||
function globeOutsideFrustum(camera) {
|
||||
const toCentre = cartesian3.negate(camera.position, cartesian3.create());
|
||||
const D = camera.direction;
|
||||
const tanY = Math.tan(camera.fovy / 2);
|
||||
const tanX = tanY * aspectOf(camera);
|
||||
const R = rightOf(camera);
|
||||
const U = camera.up;
|
||||
const planes = [
|
||||
[D, NEAR],
|
||||
[unit(sum(scaled(R, -1), scaled(D, tanX))), 0],
|
||||
[unit(sum(R, scaled(D, tanX))), 0],
|
||||
[unit(sum(scaled(U, -1), scaled(D, tanY))), 0],
|
||||
[unit(sum(U, scaled(D, tanY))), 0],
|
||||
];
|
||||
return planes.some(
|
||||
([normal, offset]) =>
|
||||
cartesian3.dot(normal, toCentre) - offset < -MAXIMUM_RADIUS,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cesium's Camera.computeViewRectangle (radians): undefined when the globe is
|
||||
* outside the frustum, the whole globe when fewer than two canvas corners
|
||||
* hit it, west > east across the antimeridian, opened to a pole the corners
|
||||
* walk around.
|
||||
*/
|
||||
export function viewRectangle(camera) {
|
||||
if (globeOutsideFrustum(camera)) return undefined;
|
||||
const horizon = horizonQuad(camera.position);
|
||||
let hits = 0;
|
||||
const points = [
|
||||
[0, 0],
|
||||
[0, camera.height],
|
||||
[camera.width, camera.height],
|
||||
[camera.width, 0],
|
||||
].map(([x, y], index) => {
|
||||
const hit = pickEllipsoid(camera, cartesian2.create(x, y));
|
||||
if (hit) hits++;
|
||||
return cartographic.fromCartesian(hit ?? horizon[index], WGS84);
|
||||
});
|
||||
if (hits < 2)
|
||||
return {
|
||||
west: -Math.PI,
|
||||
south: -math.PI_OVER_TWO,
|
||||
east: Math.PI,
|
||||
north: math.PI_OVER_TWO,
|
||||
};
|
||||
const rectangle = rectangleFromCartographics(points);
|
||||
let travelled = 0;
|
||||
let last = points[3].longitude;
|
||||
for (const { longitude } of points) {
|
||||
const step = Math.abs(longitude - last);
|
||||
travelled += step > Math.PI ? math.TWO_PI - step : step;
|
||||
last = longitude;
|
||||
}
|
||||
if (math.equalsEpsilon(Math.abs(travelled), math.TWO_PI, 1e-9)) {
|
||||
rectangle.west = -Math.PI;
|
||||
rectangle.east = Math.PI;
|
||||
if (points[0].latitude >= 0) rectangle.north = math.PI_OVER_TWO;
|
||||
else rectangle.south = -math.PI_OVER_TWO;
|
||||
}
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a {west, south, east, north} destination is seen from, looking
|
||||
* straight down: above the rectangle's centre, high enough for its wider
|
||||
* side to fill the view (with a margin for curvature). Cesium fits the
|
||||
* corners exactly; this framing is within a few percent of it.
|
||||
*/
|
||||
export function rectangleViewPosition(
|
||||
{ west, south, east, north },
|
||||
fovy,
|
||||
aspect,
|
||||
) {
|
||||
const lonSpan = east >= west ? east - west : east + math.TWO_PI - west;
|
||||
const longitude = math.negativePiToPi(west + lonSpan / 2);
|
||||
const latitude = (south + north) / 2;
|
||||
const tanY = Math.tan(fovy / 2);
|
||||
const radius = WGS84.maximumRadius;
|
||||
const widest =
|
||||
south * north <= 0
|
||||
? 1
|
||||
: Math.cos(Math.min(Math.abs(south), Math.abs(north)));
|
||||
const across =
|
||||
1.05 *
|
||||
Math.max(
|
||||
(radius * widest * lonSpan) / 2 / (tanY * aspect),
|
||||
(radius * (north - south)) / 2 / tanY,
|
||||
);
|
||||
return cartesian3.fromRadians(longitude, latitude, across, WGS84);
|
||||
}
|
||||
|
||||
// The camera offset from a target for a HeadingPitchRange, in the target frame.
|
||||
function offsetFromHeadingPitchRange(heading, pitch, range) {
|
||||
const p = math.clamp(pitch, -math.PI_OVER_TWO, math.PI_OVER_TWO);
|
||||
const cosPitch = Math.cos(p);
|
||||
return cartesian3.create(
|
||||
-Math.sin(heading) * cosPitch * range,
|
||||
-Math.cos(heading) * cosPitch * range,
|
||||
-Math.sin(p) * range,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cesium's lookAtTransform pose: the camera at `offset` in `frame`
|
||||
* (a HeadingPitchRange or a Cartesian position), looking at the frame origin
|
||||
* with the frame's +Z as up.
|
||||
*/
|
||||
export function lookAtFrame(frame, offset) {
|
||||
const local =
|
||||
'heading' in offset
|
||||
? offsetFromHeadingPitchRange(offset.heading, offset.pitch, offset.range)
|
||||
: copy3(offset);
|
||||
const localDirection = unit(cartesian3.negate(local, cartesian3.create()));
|
||||
let localRight = cross(localDirection, cartesian3.UNIT_Z);
|
||||
if (cartesian3.magnitudeSquared(localRight) < math.EPSILON10)
|
||||
localRight = copy3(cartesian3.UNIT_X);
|
||||
localRight = unit(localRight);
|
||||
const localUp = unit(cross(localRight, localDirection));
|
||||
const vector = (value) =>
|
||||
unit(matrix4.multiplyByPointAsVector(frame, value, cartesian3.create()));
|
||||
return {
|
||||
position: matrix4.multiplyByPoint(frame, local, cartesian3.create()),
|
||||
direction: vector(localDirection),
|
||||
up: vector(localUp),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cesium's flyToBoundingSphere default range: 100 m for a radius-0 sphere,
|
||||
* otherwise the distance that fits the sphere in view, clamped to the
|
||||
* camera controller's zoom distances.
|
||||
*/
|
||||
export function sphereRange(radius, fovy, aspect) {
|
||||
if (radius === 0) return ZERO_RADIUS_SPHERE_RANGE;
|
||||
const tanPhi = Math.tan(fovy / 2);
|
||||
const tanTheta = aspect * tanPhi;
|
||||
return math.clamp(
|
||||
Math.max(radius / tanTheta, radius / tanPhi),
|
||||
MINIMUM_ZOOM_DISTANCE,
|
||||
MAXIMUM_ZOOM_DISTANCE,
|
||||
);
|
||||
}
|
||||
@@ -1,380 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import {
|
||||
cesiumFovy,
|
||||
headingPitchRoll,
|
||||
horizonVisible,
|
||||
lookAtFrame,
|
||||
navaraPose,
|
||||
orientationVectors,
|
||||
pickRay,
|
||||
projectToWindow,
|
||||
rectangleViewPosition,
|
||||
sphereRange,
|
||||
viewProjection,
|
||||
viewRectangle,
|
||||
} from './cameraMath.js';
|
||||
|
||||
const { cartesian2, cartesian3, cartographic, math } = geo;
|
||||
const WGS84 = geo.ellipsoid.WGS84;
|
||||
const near = (actual, expected, tolerance, label) =>
|
||||
assert.ok(
|
||||
Math.abs(actual - expected) <= tolerance,
|
||||
`${label}: ${actual} is not within ${tolerance} of ${expected}`,
|
||||
);
|
||||
const axesAt = (position) => {
|
||||
const frame = geo.transforms.eastNorthUpToFixedFrame(position, WGS84);
|
||||
return {
|
||||
frame,
|
||||
east: cartesian3.create(frame[0], frame[1], frame[2]),
|
||||
north: cartesian3.create(frame[4], frame[5], frame[6]),
|
||||
up: cartesian3.create(frame[8], frame[9], frame[10]),
|
||||
};
|
||||
};
|
||||
const dot = cartesian3.dot;
|
||||
const unit = (v) => cartesian3.normalize(v, cartesian3.create());
|
||||
const along = (origin, direction, distance) =>
|
||||
cartesian3.add(
|
||||
origin,
|
||||
cartesian3.multiplyByScalar(direction, distance, cartesian3.create()),
|
||||
cartesian3.create(),
|
||||
);
|
||||
|
||||
// A camera as the math takes it: pose vectors, vertical fov and CSS size.
|
||||
function cameraAt(lon, lat, height, heading, pitch, roll, size = [1280, 800]) {
|
||||
const position = cartesian3.fromDegrees(lon, lat, height);
|
||||
const [width, height_] = size;
|
||||
return {
|
||||
position,
|
||||
...orientationVectors(position, heading, pitch, roll),
|
||||
fovy: cesiumFovy(width, height_),
|
||||
width,
|
||||
height: height_,
|
||||
};
|
||||
}
|
||||
|
||||
test('heading π/2 at pitch 0 looks east with up along the local up', () => {
|
||||
const position = cartesian3.fromDegrees(-120, 35, 3000);
|
||||
const { direction, up } = orientationVectors(
|
||||
position,
|
||||
math.PI_OVER_TWO,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
const axes = axesAt(position);
|
||||
near(dot(direction, axes.east), 1, 1e-12, 'direction·east');
|
||||
near(dot(up, axes.up), 1, 1e-12, 'up·up');
|
||||
});
|
||||
|
||||
test('pitch −π/2 looks down the local up with up to the north at heading 0', () => {
|
||||
const position = cartesian3.fromDegrees(-120, 35, 3000);
|
||||
const { direction, up } = orientationVectors(
|
||||
position,
|
||||
0,
|
||||
-math.PI_OVER_TWO,
|
||||
0,
|
||||
);
|
||||
const axes = axesAt(position);
|
||||
near(dot(direction, axes.up), -1, 1e-12, 'direction·up');
|
||||
near(dot(up, axes.north), 1, 1e-12, 'up·north');
|
||||
});
|
||||
|
||||
test('positive roll tilts up toward the camera right', () => {
|
||||
const position = cartesian3.fromDegrees(10, 45, 3000);
|
||||
const level = orientationVectors(position, 0.4, -0.2, 0);
|
||||
const rolled = orientationVectors(position, 0.4, -0.2, 0.3);
|
||||
const right = cartesian3.cross(
|
||||
level.direction,
|
||||
level.up,
|
||||
cartesian3.create(),
|
||||
);
|
||||
near(dot(rolled.up, right), Math.sin(0.3), 1e-12, 'up·levelRight');
|
||||
near(dot(rolled.direction, level.direction), 1, 1e-12, 'direction kept');
|
||||
});
|
||||
|
||||
test('headingPitchRoll inverts orientationVectors with Cesium ranges', () => {
|
||||
const position = cartesian3.fromDegrees(-70, 45, 25000);
|
||||
const { direction, up } = orientationVectors(position, 1.2, -0.6, 0.05);
|
||||
const angles = headingPitchRoll(position, direction, up);
|
||||
near(angles.heading, 1.2, 1e-12, 'heading');
|
||||
near(angles.pitch, -0.6, 1e-12, 'pitch');
|
||||
near(angles.roll, 0.05, 1e-12, 'roll');
|
||||
const negative = orientationVectors(position, -0.5, -0.4, -0.2);
|
||||
const wrapped = headingPitchRoll(position, negative.direction, negative.up);
|
||||
near(wrapped.heading, math.TWO_PI - 0.5, 1e-12, 'heading of −0.5');
|
||||
near(wrapped.roll, math.TWO_PI - 0.2, 1e-12, 'roll of −0.2');
|
||||
const nadir = orientationVectors(position, 0.7, -math.PI_OVER_TWO, 0.3);
|
||||
const down = headingPitchRoll(position, nadir.direction, nadir.up);
|
||||
assert.equal(down.roll, 0);
|
||||
assert.ok(down.heading >= 0 && down.heading < math.TWO_PI);
|
||||
});
|
||||
|
||||
test('navaraPose gives Navara setCamera degrees in the same convention', () => {
|
||||
const camera = cameraAt(-70, 45, 25000, 1.2, -0.6, -0.05);
|
||||
const pose = navaraPose(camera.position, camera.direction, camera.up);
|
||||
near(pose.lng, -70, 1e-9, 'lng');
|
||||
near(pose.lat, 45, 1e-9, 'lat');
|
||||
near(pose.height, 25000, 1e-6, 'height');
|
||||
assert.ok(pose.heading >= 0 && pose.heading <= 360);
|
||||
assert.ok(pose.roll > -180 && pose.roll <= 180);
|
||||
// Navara uses the surface frame at lng/lat to reconstruct the basis.
|
||||
const back = orientationVectors(
|
||||
cartesian3.fromDegrees(pose.lng, pose.lat, 0),
|
||||
math.toRadians(pose.heading),
|
||||
math.toRadians(pose.pitch),
|
||||
math.toRadians(pose.roll),
|
||||
);
|
||||
near(dot(back.direction, camera.direction), 1, 1e-12, 'direction');
|
||||
near(dot(back.up, camera.up), 1, 1e-12, 'up');
|
||||
});
|
||||
|
||||
test('cesiumFovy spans 60° across the wider canvas side', () => {
|
||||
near(
|
||||
cesiumFovy(1280, 800),
|
||||
2 * Math.atan(Math.tan(Math.PI / 6) / 1.6),
|
||||
1e-15,
|
||||
'landscape',
|
||||
);
|
||||
near(cesiumFovy(600, 900), Math.PI / 3, 0, 'portrait');
|
||||
});
|
||||
|
||||
test('projection: ahead is the centre, behind is undefined, result is filled', () => {
|
||||
const camera = cameraAt(20, 10, 1e6, 0, -math.PI_OVER_TWO, 0);
|
||||
const ahead = along(camera.position, camera.direction, 1000);
|
||||
const result = cartesian2.create();
|
||||
assert.equal(projectToWindow(camera, ahead, result), result);
|
||||
near(result.x, 640, 1e-9, 'x');
|
||||
near(result.y, 400, 1e-9, 'y');
|
||||
assert.equal(
|
||||
projectToWindow(camera, along(camera.position, camera.direction, -1)),
|
||||
undefined,
|
||||
);
|
||||
const upper = projectToWindow(camera, along(ahead, camera.up, 100));
|
||||
assert.ok(upper.y < 400);
|
||||
});
|
||||
|
||||
test('pickRay and projection round-trip through a screen point', () => {
|
||||
const camera = cameraAt(20, 10, 30000, 0.6, -0.5, 0.1);
|
||||
const ray = pickRay(camera, cartesian2.create(200, 150));
|
||||
near(cartesian3.magnitude(ray.direction), 1, 1e-12, '|direction|');
|
||||
const back = projectToWindow(camera, along(ray.origin, ray.direction, 5000));
|
||||
near(back.x, 200, 1e-6, 'x');
|
||||
near(back.y, 150, 1e-6, 'y');
|
||||
});
|
||||
|
||||
test('viewProjection agrees with projectToWindow', () => {
|
||||
const camera = cameraAt(20, 10, 30000, 0.6, -0.5, 0.1);
|
||||
const matrix = viewProjection(camera, new Array(16).fill(0));
|
||||
const point = along(
|
||||
camera.position,
|
||||
pickRay(camera, cartesian2.create(300, 500)).direction,
|
||||
12000,
|
||||
);
|
||||
const window = projectToWindow(camera, point);
|
||||
const clip = [0, 1, 2, 3].map(
|
||||
(row) =>
|
||||
matrix[row] * point.x +
|
||||
matrix[4 + row] * point.y +
|
||||
matrix[8 + row] * point.z +
|
||||
matrix[12 + row],
|
||||
);
|
||||
assert.ok(clip[3] > 0);
|
||||
near(((clip[0] / clip[3] + 1) / 2) * 1280, window.x, 1e-6, 'x');
|
||||
near(((1 - clip[1] / clip[3]) / 2) * 800, window.y, 1e-6, 'y');
|
||||
});
|
||||
|
||||
test('horizonVisible: the nadir is visible and the antipode hidden', () => {
|
||||
const eye = cartesian3.fromDegrees(20, 10, 1e6);
|
||||
assert.equal(horizonVisible(eye, cartesian3.fromDegrees(20, 10, 0)), true);
|
||||
assert.equal(
|
||||
horizonVisible(eye, cartesian3.fromDegrees(-160, -10, 0)),
|
||||
false,
|
||||
);
|
||||
assert.equal(horizonVisible(eye, cartesian3.fromDegrees(-70, 10, 2e7)), true);
|
||||
});
|
||||
|
||||
test("viewRectangle matches Cesium's computeViewRectangle (S4 reference poses)", () => {
|
||||
// S4 measured these on Cesium at 1280×720 with Cesium's fov.
|
||||
const deg = (rectangle) =>
|
||||
['west', 'south', 'east', 'north'].map((side) =>
|
||||
math.toDegrees(rectangle[side]),
|
||||
);
|
||||
const nadir = viewRectangle(
|
||||
cameraAt(-74, 40.7, 1500, 0, -math.PI_OVER_TWO, 0, [1280, 720]),
|
||||
);
|
||||
const expected = [-74.0102, 40.6956, -73.9898, 40.7044];
|
||||
deg(nadir).forEach((value, index) =>
|
||||
near(value, expected[index], 1e-4, `nadir ${index}`),
|
||||
);
|
||||
const pole = viewRectangle(
|
||||
cameraAt(0, 89, 3e6, 0, -math.PI_OVER_TWO, 0, [1280, 720]),
|
||||
);
|
||||
const poleExpected = [-180, 68.7968, 180, 90];
|
||||
deg(pole).forEach((value, index) =>
|
||||
near(value, poleExpected[index], 2e-3, `pole ${index}`),
|
||||
);
|
||||
});
|
||||
|
||||
test('viewRectangle: antimeridian wrap, undefined away from the Earth, whole globe from afar', () => {
|
||||
const idl = viewRectangle(cameraAt(180, 0, 1e6, 0, -math.PI_OVER_TWO, 0));
|
||||
assert.ok(idl.west > 0 && idl.east < 0 && idl.west > idl.east);
|
||||
assert.equal(
|
||||
viewRectangle(cameraAt(20, 10, 1e6, 0, math.PI_OVER_TWO, 0)),
|
||||
undefined,
|
||||
);
|
||||
const whole = viewRectangle(cameraAt(20, 10, 2e7, 0, -math.PI_OVER_TWO, 0));
|
||||
assert.deepEqual(whole, {
|
||||
west: -Math.PI,
|
||||
south: -math.PI_OVER_TWO,
|
||||
east: Math.PI,
|
||||
north: math.PI_OVER_TWO,
|
||||
});
|
||||
});
|
||||
|
||||
test('rectangleViewPosition frames a rectangle at the centre of a nadir view', () => {
|
||||
const rectangle = {
|
||||
west: math.toRadians(2.2),
|
||||
south: math.toRadians(48.8),
|
||||
east: math.toRadians(2.5),
|
||||
north: math.toRadians(48.9),
|
||||
};
|
||||
const fovy = cesiumFovy(1280, 800);
|
||||
const position = rectangleViewPosition(rectangle, fovy, 1280 / 800);
|
||||
const camera = {
|
||||
position,
|
||||
...orientationVectors(position, 0, -math.PI_OVER_TWO, 0),
|
||||
fovy,
|
||||
width: 1280,
|
||||
height: 800,
|
||||
};
|
||||
const middle = projectToWindow(
|
||||
camera,
|
||||
cartesian3.fromRadians(math.toRadians(2.35), math.toRadians(48.85)),
|
||||
);
|
||||
near(middle.x, 640, 64, 'centre x');
|
||||
near(middle.y, 400, 40, 'centre y');
|
||||
for (const [lon, lat] of [
|
||||
[rectangle.west, rectangle.south],
|
||||
[rectangle.east, rectangle.north],
|
||||
]) {
|
||||
const corner = projectToWindow(camera, cartesian3.fromRadians(lon, lat));
|
||||
assert.ok(
|
||||
corner.x >= 0 && corner.x <= 1280 && corner.y >= 0 && corner.y <= 800,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('lookAtFrame: heading/pitch/range and Cartesian offsets aim at the origin', () => {
|
||||
const target = cartesian3.fromDegrees(-0.12, 51.5, 0);
|
||||
const { frame, up } = axesAt(target);
|
||||
const pose = lookAtFrame(frame, { heading: 0.4, pitch: -0.7, range: 2000 });
|
||||
near(cartesian3.distance(pose.position, target), 2000, 1e-6, 'range');
|
||||
const aim = (p) =>
|
||||
dot(
|
||||
unit(cartesian3.subtract(target, p.position, cartesian3.create())),
|
||||
p.direction,
|
||||
);
|
||||
near(aim(pose), 1, 1e-12, 'aim');
|
||||
const angles = headingPitchRoll(pose.position, pose.direction, pose.up);
|
||||
near(angles.pitch, -0.7, 1e-3, 'pitch about the target');
|
||||
const offset = lookAtFrame(frame, cartesian3.create(0, -1000, 1000));
|
||||
near(
|
||||
cartesian3.distance(offset.position, target),
|
||||
Math.SQRT2 * 1000,
|
||||
1e-6,
|
||||
'Cartesian range',
|
||||
);
|
||||
near(aim(offset), 1, 1e-12, 'Cartesian aim');
|
||||
assert.ok(dot(offset.up, up) > 0);
|
||||
});
|
||||
|
||||
test("sphereRange follows Cesium's flyToBoundingSphere defaults", () => {
|
||||
const fovy = cesiumFovy(1280, 800);
|
||||
const tanPhi = Math.tan(fovy / 2);
|
||||
const tanTheta = 1.6 * tanPhi;
|
||||
assert.equal(sphereRange(0, fovy, 1.6), 100);
|
||||
near(
|
||||
sphereRange(1000, fovy, 1.6),
|
||||
Math.max(1000 / tanTheta, 1000 / tanPhi),
|
||||
1e-9,
|
||||
'range',
|
||||
);
|
||||
assert.equal(sphereRange(1e-6, fovy, 1.6), 1);
|
||||
});
|
||||
|
||||
test('cartographic heights of the math agree with src/geo', () => {
|
||||
const camera = cameraAt(139.7, 35.6, 8000, 4, -0.3, 0);
|
||||
near(
|
||||
cartographic.fromCartesian(camera.position, WGS84).height,
|
||||
8000,
|
||||
1e-6,
|
||||
'height',
|
||||
);
|
||||
});
|
||||
|
||||
test("horizonVisible agrees with Cesium's EllipsoidalOccluder, also at the limb", async () => {
|
||||
const Cesium = await import('cesium');
|
||||
const occluder = new Cesium.EllipsoidalOccluder(Cesium.Ellipsoid.WGS84);
|
||||
let seed = 7;
|
||||
const random = () => {
|
||||
seed = (seed * 16807) % 2147483647;
|
||||
return seed / 2147483647;
|
||||
};
|
||||
let disagreements = 0;
|
||||
let checked = 0;
|
||||
for (let i = 0; i < 400; i++) {
|
||||
const eye = cartesian3.fromDegrees(
|
||||
random() * 360 - 180,
|
||||
random() * 160 - 80,
|
||||
[600, 15_000, 400_000, 20_000_000][i % 4],
|
||||
);
|
||||
occluder.cameraPosition = new Cesium.Cartesian3(eye.x, eye.y, eye.z);
|
||||
for (let j = 0; j < 20; j++) {
|
||||
// Points on the ground and above it, many near the horizon of the eye.
|
||||
const point = cartesian3.fromDegrees(
|
||||
random() * 360 - 180,
|
||||
random() * 160 - 80,
|
||||
[0, -40, 50, 10_000][j % 4],
|
||||
);
|
||||
checked++;
|
||||
if (
|
||||
horizonVisible(eye, point) !==
|
||||
occluder.isPointVisible(
|
||||
new Cesium.Cartesian3(point.x, point.y, point.z),
|
||||
)
|
||||
)
|
||||
disagreements++;
|
||||
}
|
||||
}
|
||||
assert.equal(disagreements, 0, `${disagreements}/${checked} disagree`);
|
||||
// At the limb: a point 40 m under the ellipsoid just past the horizon is
|
||||
// hidden, its cullPosition lifted 100 m is visible (worldOverlay's rule).
|
||||
const eye = cartesian3.fromDegrees(0, 0, 10_000);
|
||||
const horizonDeg = math.toDegrees(Math.acos(6378137 / (6378137 + 10_000)));
|
||||
const buried = cartesian3.fromDegrees(horizonDeg + 0.02, 0, -40);
|
||||
const lifted = cartesian3.fromDegrees(horizonDeg + 0.02, 0, 100);
|
||||
assert.equal(horizonVisible(eye, buried), false);
|
||||
assert.equal(horizonVisible(eye, lifted), true);
|
||||
});
|
||||
|
||||
test('Navara high-orbit angles reconstruct the exact requested world basis', () => {
|
||||
for (const height of [0, 25000, 420000, 2e7, 4.5e7])
|
||||
for (const lat of [-70, -45, 15, 45, 70]) {
|
||||
const camera = cameraAt(-70, lat, height, 1.2, -1.4, -0.05);
|
||||
const pose = navaraPose(camera.position, camera.direction, camera.up);
|
||||
const back = orientationVectors(
|
||||
cartesian3.fromDegrees(pose.lng, pose.lat, 0),
|
||||
math.toRadians(pose.heading),
|
||||
math.toRadians(pose.pitch),
|
||||
math.toRadians(pose.roll),
|
||||
);
|
||||
near(
|
||||
cartesian3.distance(back.direction, camera.direction),
|
||||
0,
|
||||
1e-12,
|
||||
'high orbit direction',
|
||||
);
|
||||
near(cartesian3.distance(back.up, camera.up), 0, 1e-12, 'high orbit up');
|
||||
}
|
||||
});
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
sphereRange,
|
||||
viewProjection,
|
||||
viewRectangle,
|
||||
} from './cameraMath.js';
|
||||
} from '../cameraMath.js';
|
||||
|
||||
const { cartesian3, cartographic, math, matrix4 } = geo;
|
||||
const WGS84 = geo.ellipsoid.WGS84;
|
||||
|
||||
@@ -2,7 +2,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { isEngineEvent } from '../contract.js';
|
||||
import { orientationVectors } from './cameraMath.js';
|
||||
import { orientationVectors } from '../cameraMath.js';
|
||||
import { createCameraModel } from './cameraModel.js';
|
||||
|
||||
const { cartesian2, cartesian3, math, matrix4 } = geo;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Navara 0.2.1 leak fix (phase 3 review): Navara's transparent pass keeps a
|
||||
// Navara 0.2.1 leak fix: Navara's transparent pass keeps a
|
||||
// copy of each scene light and refreshes it every frame with
|
||||
// `copy.copy(light, true)`. For the sun's cascaded shadow lights
|
||||
// (@navaramap/three-csm CascadedDirectionalLights) that copy clones every
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// contract's preUpdate; every listener of the frame then reads that time.
|
||||
// The look (look.js) reads the same clock for the sun.
|
||||
|
||||
import { createEngineEvent } from '../contract.js';
|
||||
import { appClock as pageClock } from '../../time/clock.js';
|
||||
|
||||
/**
|
||||
@@ -14,15 +13,13 @@ import { appClock as pageClock } from '../../time/clock.js';
|
||||
* @returns {{ clock: import('../contract.js').GlobeClock, beginFrame: () => void }}
|
||||
*/
|
||||
export function createNavaraClock({ appClock = pageClock } = {}) {
|
||||
const ticked = createEngineEvent();
|
||||
return {
|
||||
clock: {
|
||||
now: () => appClock.now(),
|
||||
frameTime: () => appClock.frameTime(),
|
||||
ticked,
|
||||
},
|
||||
beginFrame() {
|
||||
ticked.raiseValue(appClock.beginFrame());
|
||||
appClock.beginFrame();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,21 +1,16 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { isEngineEvent } from '../contract.js';
|
||||
import { createAppClock } from '../../time/clock.js';
|
||||
import { createNavaraClock } from './clock.js';
|
||||
|
||||
test('beginFrame latches the app clock and raises ticked with the frame time', () => {
|
||||
test('beginFrame latches the app clock', () => {
|
||||
let wall = 10_000;
|
||||
const appClock = createAppClock({ now: () => wall });
|
||||
const { clock, beginFrame } = createNavaraClock({ appClock });
|
||||
assert.ok(isEngineEvent(clock.ticked));
|
||||
const seen = [];
|
||||
clock.ticked.addEventListener((time) => seen.push(time));
|
||||
assert.equal(clock.frameTime(), 10_000);
|
||||
wall = 10_016;
|
||||
beginFrame();
|
||||
wall = 10_020;
|
||||
assert.deepEqual(seen, [10_016]);
|
||||
assert.equal(clock.frameTime(), 10_016);
|
||||
assert.equal(clock.now(), 10_020);
|
||||
});
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
mergeSharpen,
|
||||
mergeStyle,
|
||||
} from '../contract.js';
|
||||
import { cesiumFovy } from './cameraMath.js';
|
||||
import { cesiumFovy, intersectEllipsoid } from '../cameraMath.js';
|
||||
import { createCameraModel } from './cameraModel.js';
|
||||
import { createNavaraClock } from './clock.js';
|
||||
import { createNavaraCredits } from './credits.js';
|
||||
@@ -62,31 +62,6 @@ function readCamera(raw) {
|
||||
};
|
||||
}
|
||||
|
||||
// Nearest hit of a ray with the WGS84 ellipsoid raised by `height` metres
|
||||
// (each radius grown by it), or undefined.
|
||||
function rayRaisedEllipsoid({ origin, direction }, height) {
|
||||
const radii = geo.ellipsoid.WGS84.radii;
|
||||
const rx = radii.x + height;
|
||||
const ry = radii.y + height;
|
||||
const rz = radii.z + height;
|
||||
const o = [origin.x / rx, origin.y / ry, origin.z / rz];
|
||||
const d = [direction.x / rx, direction.y / ry, direction.z / rz];
|
||||
const a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
|
||||
const b = 2 * (o[0] * d[0] + o[1] * d[1] + o[2] * d[2]);
|
||||
const c = o[0] * o[0] + o[1] * o[1] + o[2] * o[2] - 1;
|
||||
const discriminant = b * b - 4 * a * c;
|
||||
if (discriminant < 0) return undefined;
|
||||
const root = Math.sqrt(discriminant);
|
||||
const near = (-b - root) / (2 * a);
|
||||
const t = near > 0 ? near : (-b + root) / (2 * a);
|
||||
if (!(t > 0)) return undefined;
|
||||
return cartesian3.add(
|
||||
origin,
|
||||
cartesian3.multiplyByScalar(direction, t, cartesian3.create()),
|
||||
cartesian3.create(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} view An initialised Navara ThreeView.
|
||||
* @param {{
|
||||
@@ -156,7 +131,7 @@ export function createNavaraEngine(
|
||||
read: () => readCamera(view.camera.raw),
|
||||
fly: (pose, options) => view.flyTo(pose, options),
|
||||
// Navara 0.2.1 has no cancel call: any camera change interrupts a
|
||||
// flight, and an empty setCamera changes nothing else (S4).
|
||||
// flight, and an empty setCamera changes nothing else.
|
||||
stop: () => view.setCamera({}),
|
||||
size,
|
||||
requestFrame: () => view.forceUpdate(),
|
||||
@@ -170,8 +145,7 @@ export function createNavaraEngine(
|
||||
};
|
||||
const engineClock = createNavaraClock(appClock ? { appClock } : {});
|
||||
// camera.follow (src/globe/follow.js): Navara's own cameraFollow takes
|
||||
// no user rotation or zoom (phase 3 Task 5 probe), so the engine steps
|
||||
// its own follow each frame.
|
||||
// no user rotation or zoom, so the engine steps its own follow each frame.
|
||||
const followStep = createEngineEvent();
|
||||
const follow = createFollowController({
|
||||
camera: model.camera,
|
||||
@@ -259,8 +233,6 @@ export function createNavaraEngine(
|
||||
// Clicks with { pick } get Navara's GPU pick of the gesture instead.
|
||||
pick: (screen) => picking.pick(screen),
|
||||
drillPick: (screen, limit) => picking.drillPick(screen, limit),
|
||||
// Navara-only diagnostics: how clicks with { pick } were answered.
|
||||
clickStats: () => picking.clickStats(),
|
||||
pickPosition(screen) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const hit = view.pickDepthPosition(
|
||||
@@ -282,7 +254,7 @@ export function createNavaraEngine(
|
||||
geo.cartographic.fromCartesian(hit, geo.ellipsoid.WGS84),
|
||||
);
|
||||
if (!Number.isFinite(height)) break;
|
||||
const next = rayRaisedEllipsoid(ray, height);
|
||||
const next = intersectEllipsoid(ray.origin, ray.direction, height);
|
||||
if (!next) break;
|
||||
const moved = cartesian3.distance(next, hit);
|
||||
hit = next;
|
||||
|
||||
@@ -2,7 +2,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { assertGlobeEngine, engineCapabilities } from '../contract.js';
|
||||
import { cesiumFovy, orientationVectors } from './cameraMath.js';
|
||||
import { cesiumFovy, orientationVectors } from '../cameraMath.js';
|
||||
import { createNavaraEngine } from './createNavaraEngine.js';
|
||||
|
||||
const { cartesian2, cartesian3, math } = geo;
|
||||
@@ -138,7 +138,6 @@ test('the engine clock is the app clock, latched on the view preUpdate before fr
|
||||
const engine = createNavaraEngine(view, { hooks, appClock });
|
||||
assert.equal(engine.clock.now(), 2_000_000);
|
||||
const seen = [];
|
||||
engine.clock.ticked.addEventListener((time) => seen.push(['ticked', time]));
|
||||
for (const name of ['preUpdate', 'preRender', 'postRender'])
|
||||
engine.frames[name].addEventListener(() =>
|
||||
seen.push([name, engine.clock.frameTime()]),
|
||||
@@ -149,7 +148,6 @@ test('the engine clock is the app clock, latched on the view preUpdate before fr
|
||||
view.emit('preRender', 2);
|
||||
view.emit('postRender', 3);
|
||||
assert.deepEqual(seen, [
|
||||
['ticked', 2_000_016],
|
||||
['preUpdate', 2_000_016],
|
||||
['preRender', 2_000_016],
|
||||
['postRender', 2_000_016],
|
||||
@@ -158,7 +156,7 @@ test('the engine clock is the app clock, latched on the view preUpdate before fr
|
||||
engine.destroy();
|
||||
wall += 16;
|
||||
view.emit('preUpdate', 4);
|
||||
assert.equal(seen.length, 4, 'no tick after destroy');
|
||||
assert.equal(seen.length, 3, 'no frame after destroy');
|
||||
});
|
||||
|
||||
test('render requests are forceUpdate and continuous mode is Navara animation', () => {
|
||||
|
||||
@@ -44,7 +44,7 @@ import {
|
||||
} from './viewOptions.js';
|
||||
|
||||
// Navara 0.2.1 has no preserveDrawingBuffer option but takes a canvas whose
|
||||
// WebGL2 context is already created (S4); three then uses that context.
|
||||
// WebGL2 context is already created; three then uses that context.
|
||||
function preservedCanvas(container) {
|
||||
const canvas = document.createElement('canvas');
|
||||
Object.assign(canvas.style, {
|
||||
@@ -107,24 +107,13 @@ function groundInView(engine) {
|
||||
/**
|
||||
* @param {{
|
||||
* container: HTMLElement,
|
||||
* effects?: 'minimal' | 'photoreal' | 'cinematic',
|
||||
* search?: string,
|
||||
* pixelRatio?: number,
|
||||
* appClock?: import('../../time/clock.js').AppClock,
|
||||
* }} options `effects` names the look (cinematic by default); `search`, the
|
||||
* page's query string, picks it from `?look=` instead (the app's way).
|
||||
* `pixelRatio` only for measurements; the product uses the device's.
|
||||
* `appClock` (the page's by default) is the engine clock's time and so the
|
||||
* sun's: the look reads the engine clock's frame time.
|
||||
* }} options `search`, the page's query string, picks the look from
|
||||
* `?look=` (cinematic by default). The sun follows the engine clock (the
|
||||
* page's app clock): the look reads its frame time.
|
||||
* @returns {Promise<{ view: object, engine: import('../contract.js').GlobeEngine, destroy: () => void }>}
|
||||
*/
|
||||
export async function createNavaraGlobe({
|
||||
container,
|
||||
effects,
|
||||
search,
|
||||
pixelRatio,
|
||||
appClock,
|
||||
}) {
|
||||
export async function createNavaraGlobe({ container, search }) {
|
||||
if (!container) throw new TypeError('createNavaraGlobe needs a container');
|
||||
const canvas = preservedCanvas(container);
|
||||
let view;
|
||||
@@ -136,13 +125,13 @@ export async function createNavaraGlobe({
|
||||
// Parked for a switch back: its render loop is off (setRenderLoop).
|
||||
let parked = false;
|
||||
try {
|
||||
view = new ThreeView(navaraViewOptions({ container, canvas, pixelRatio }));
|
||||
view = new ThreeView(navaraViewOptions({ container, canvas }));
|
||||
const plugin = new DefaultPlugin();
|
||||
view.addPlugin(plugin);
|
||||
await view.init();
|
||||
const automaticLandscape =
|
||||
!effects && new URLSearchParams(search).get('sun') !== 'live';
|
||||
const plan = navaraScenePlan(effects ?? resolveNavaraLook(search), {
|
||||
new URLSearchParams(search).get('sun') !== 'live';
|
||||
const plan = navaraScenePlan(resolveNavaraLook(search), {
|
||||
mobile: Boolean(view.isMobileOptimized?.()),
|
||||
});
|
||||
// The sun follows the engine clock (one time source for layers and the
|
||||
@@ -158,7 +147,6 @@ export async function createNavaraGlobe({
|
||||
engine = createNavaraEngine(view, {
|
||||
hooks: navaraHooks(view),
|
||||
container,
|
||||
...(appClock ? { appClock } : {}),
|
||||
sharpen: createNavaraSharpen(view),
|
||||
bloom: createNavaraBloom(view),
|
||||
clouds: createNavaraCloudCover(look),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// canvas's top-left corner, and a listener with a modifier fires only while
|
||||
// that key is held (shift over ctrl over alt), one without only while none is.
|
||||
//
|
||||
// Camera inputs map to Navara's controller flags (view.camera.options, S4).
|
||||
// Camera inputs map to Navara's controller flags (view.camera.options).
|
||||
// Navara 0.2.1 lets a flyTo run on under user input, where Cesium cancels it;
|
||||
// `onCameraInput` reports user camera input so the engine can do the same.
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Every private Navara member the engine relies on, in one place. Written
|
||||
// against @navaramap/three 0.2.1 (package.json pins it exactly; the test in
|
||||
// internals.test.mjs fails if the two drift apart): re-check each access below
|
||||
// before moving to another Navara version. Each names the parity spike that
|
||||
// found it and the public API that would replace it upstream.
|
||||
// before moving to another Navara version. Each names the public API that
|
||||
// would replace it upstream.
|
||||
|
||||
import { ModelMesh } from '@navaramap/three';
|
||||
import { patchCascadedLightCopy } from './cascadedLightCopy.js';
|
||||
@@ -21,7 +21,7 @@ export function setRenderLoopEnabled(view, enabled) {
|
||||
let restoreRelease = null;
|
||||
|
||||
/**
|
||||
* S2: keep 3D-tile positions and indices on the CPU after upload so the
|
||||
* Keeps 3D-tile positions and indices on the CPU after upload so the
|
||||
* surface ray can hit them. Private: ModelMesh.prototype._releaseGeometryArrays,
|
||||
* which frees every attribute array once the tile is on the GPU. Patched on
|
||||
* the prototype, for all views; idempotent. Upstream ask: an option to retain
|
||||
@@ -56,7 +56,7 @@ export function retainTileGeometry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* S2: the loaded 3D-tile roots (ModelMesh objects). Private: view._scenes.mrt,
|
||||
* The loaded 3D-tile roots (ModelMesh objects). Private: view._scenes.mrt,
|
||||
* the scene Navara renders tiles into. Upstream ask: as for
|
||||
* retainTileGeometry.
|
||||
*/
|
||||
@@ -67,7 +67,7 @@ export function tileRoots(view) {
|
||||
}
|
||||
|
||||
/**
|
||||
* S2/S5: whether Navara has stopped updating (tiles loaded, camera still).
|
||||
* Whether Navara has stopped updating (tiles loaded, camera still).
|
||||
* Private: view._isIdle, which the public `idle` event reports only as an
|
||||
* edge. Upstream ask: a public isIdle/tilesLoaded getter.
|
||||
*/
|
||||
@@ -88,7 +88,7 @@ export function isIdle(view) {
|
||||
* throws in the dev server and warns once in a build. Upstream ask: a sky
|
||||
* luminance or atmosphere exposure that leaves unlit content alone.
|
||||
*/
|
||||
export const LUMINANCE_UNIFORMS = Object.freeze([
|
||||
const LUMINANCE_UNIFORMS = Object.freeze([
|
||||
'SUN_SPECTRAL_RADIANCE_TO_LUMINANCE',
|
||||
'SKY_SPECTRAL_RADIANCE_TO_LUMINANCE',
|
||||
]);
|
||||
@@ -141,7 +141,7 @@ export function forEachLuminanceUniform(handles, visit) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3 review (leak): the sun's cascaded shadow lights are re-cloned by
|
||||
* A leak: the sun's cascaded shadow lights are re-cloned by
|
||||
* the transparent pass every frame (cascadedLightCopy.js). Finds the
|
||||
* CascadedDirectionalLights class among the view's scene lights (private:
|
||||
* view._scenes.light) and patches its copy to update in place. Returns the
|
||||
@@ -189,7 +189,7 @@ export const navaraHooks = (view) => ({
|
||||
});
|
||||
|
||||
/**
|
||||
* Stage 6 (QA diagnostics only): the names of the passes in the view's
|
||||
* QA diagnostics only: the names of the passes in the view's
|
||||
* post-processing pipeline, in draw order, or null when the path is gone.
|
||||
* Private: ctx.renderPassOrchestrator.passMap.list ({ name, pass }).
|
||||
* Upstream ask: a public read of the pipeline order.
|
||||
|
||||
@@ -242,7 +242,7 @@ export function buildNavaraLook(
|
||||
}
|
||||
|
||||
/** Navara's own stars intensity, for a look that does not set one. */
|
||||
export const NAVARA_STARS_INTENSITY = 10;
|
||||
const NAVARA_STARS_INTENSITY = 10;
|
||||
|
||||
const IRRADIANCE_ON = Object.freeze({
|
||||
aerialPerspective: Object.freeze({ irradiance: true }),
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
// - terrain: the keyless Re:Earth quantized mesh, Cesium World Terrain through
|
||||
// the ion endpoint with an explicit token (Navara sends it as a Bearer
|
||||
// token), or none (the ellipsoid). Navara 0.2.1 panics on a quantized-mesh
|
||||
// URL without the {z}/{x}/{y}.terrain template (S2), so URLs always carry it.
|
||||
// - photoreal: Google 3D tiles with a browser key only in this phase (the
|
||||
// server proxy of S3 comes later), with Google's logo and the tiles' own
|
||||
// URL without the {z}/{x}/{y}.terrain template, so URLs always carry it.
|
||||
// - photoreal: Google 3D tiles with a browser key only (no server proxy),
|
||||
// with Google's logo and the tiles' own
|
||||
// copyright lines (creditLayerId) on screen. Showing them hides the base
|
||||
// imagery, as MapSourceController removes it; clearing them does not bring
|
||||
// it back until setBaseImagery. Hidden, not deleted: deleting the last
|
||||
@@ -42,7 +42,7 @@ const ION_WORLD_TERRAIN_ENDPOINT =
|
||||
const GOOGLE_TILES_ROOT = 'https://tile.googleapis.com/v1/3dtiles/root.json';
|
||||
// The mark Cesium shows for Google tiles (GoogleMaps.getDefaultCredit).
|
||||
const GOOGLE_LOGO = 'https://assets.ion.cesium.com/google-credit.png';
|
||||
// Cesium3DTileset's default maximumScreenSpaceError, as the S1–S5 benches use.
|
||||
// Cesium3DTileset's default maximumScreenSpaceError.
|
||||
const PHOTOREAL_MAX_SSE = 16;
|
||||
|
||||
const kindOf = (source) => (source?.descriptor ?? source)?.kind;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// PickableInstancedMeshWrapper so Navara's pick pass sees each instance;
|
||||
// pickIds.js turns its batch ids back into instances. commit() uploads and
|
||||
// asks for one frame (view.forceUpdate); per-frame work runs only on frames
|
||||
// the view draws anyway (S5), so an idle view stays idle.
|
||||
// the view draws anyway, so an idle view stays idle.
|
||||
|
||||
import { withFrameUpdates } from '../frameDescriptor.js';
|
||||
import {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// The three side of a Navara model set: the glTF loaded once, one
|
||||
// InstancedMesh per mesh in it (all instances share the model's meshes),
|
||||
// each instance placed by position, orientation and scale relative to an
|
||||
// origin near the camera. Cesium's minimumPixelSize/maximumScale are kept on
|
||||
// the CPU once per drawn frame (models are few: tracked and proximity
|
||||
// aircraft), and the instance colour is mixed into the surface colour
|
||||
// (colorBlend), or the model drawn unlit.
|
||||
// origin near the camera. Cesium's minimumPixelSize is kept on the CPU once
|
||||
// per drawn frame (models are few: tracked and proximity aircraft), and the
|
||||
// instance colour is mixed into the surface colour (colorBlend), or the model
|
||||
// drawn unlit.
|
||||
|
||||
import {
|
||||
Box3,
|
||||
@@ -25,7 +25,7 @@ import { createModelTint } from './modelTint.js';
|
||||
* besides the sun. Navara's sky light alone left it grey-brown at dawn.
|
||||
* The instance colour is applied after lighting, independently of this share.
|
||||
*/
|
||||
export const MODEL_AMBIENT = 0.5;
|
||||
const MODEL_AMBIENT = 0.5;
|
||||
|
||||
/**
|
||||
* The distance Cesium sizes a model's minimumPixelSize at (Camera
|
||||
@@ -159,7 +159,6 @@ export function createModelMover(
|
||||
const pixels = (2 * radius * scale) / (footprint * distance);
|
||||
if (pixels < model.minimumPixelSize)
|
||||
scale *= model.minimumPixelSize / pixels;
|
||||
scale = Math.min(scale, model.maximumScale);
|
||||
drawnPx[index] = (pixels * scale) / scales[index];
|
||||
}
|
||||
scratchTranslation.set(
|
||||
|
||||
@@ -23,7 +23,7 @@ export function atlasUvRects(cells, keys) {
|
||||
}
|
||||
|
||||
/** The camera distance from the origin past which the origin moves. */
|
||||
export const recentreDistance = (cameraHeight) =>
|
||||
const recentreDistance = (cameraHeight) =>
|
||||
Math.max(1_000, 0.1 * Math.abs(cameraHeight));
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
// depth; their lit display colour is resolved here so HDR effects and MSAA
|
||||
// cannot spread a tint into neighbouring pixels.
|
||||
// FIRMS opts into a separate native-stage overlay before sharpening/AA.
|
||||
// Only that stage owns an encoded-RGBA8 blend target; W1 stays in place.
|
||||
// Only that stage owns an encoded-RGBA8 blend target; this overlay stays in
|
||||
// place.
|
||||
|
||||
import { withFrameUpdates, withPassDisposal } from './frameDescriptor.js';
|
||||
import { EffectDesc, Pass as NavaraPass } from '@navaramap/three';
|
||||
@@ -18,7 +19,7 @@ import { GevOverlayPass } from './overlayPass.js';
|
||||
import { sonarUniformsFor } from './sonar.js';
|
||||
import { RGBADepthPacking, Scene } from 'three';
|
||||
|
||||
export const OVERLAY_EFFECT_KEY = 'gevOverlay';
|
||||
const OVERLAY_EFFECT_KEY = 'gevOverlay';
|
||||
const PRE_SHARPEN_KEY = 'gevPreSharpenOverlay';
|
||||
const registeredViews = new WeakMap();
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ test('empty display overlay does not swap an unwritten frame buffer', () => {
|
||||
h.pass.dispose();
|
||||
});
|
||||
|
||||
test('ordinary W1 overlays keep the direct pass without a display copy or target', () => {
|
||||
test('ordinary overlays keep the direct pass without a display copy or target', () => {
|
||||
const h = harness(),
|
||||
input = { width: 1280, height: 800, samples: 4, texture: {} };
|
||||
h.overlay.displayBlend = false;
|
||||
|
||||
@@ -52,13 +52,6 @@ export function createNavaraPicking({
|
||||
|
||||
// Clicks waiting for Navara's GPU answer, oldest first.
|
||||
const waiting = [];
|
||||
// Diagnostics: how clicks were answered and how long it took (ms).
|
||||
const stats = { gpu: 0, timeout: 0, stale: 0, latencies: [] };
|
||||
const answered = (entry, how) => {
|
||||
stats[how]++;
|
||||
stats.latencies.push(now() - entry.startedAt);
|
||||
if (stats.latencies.length > 200) stats.latencies.shift();
|
||||
};
|
||||
// Navara 0.2.1 answers clicks in quick succession (within a frame or so)
|
||||
// with the first click's pick: a GPU answer whose instance is not drawn
|
||||
// near the click is stale, and the CPU pick answers instead.
|
||||
@@ -70,7 +63,7 @@ export function createNavaraPicking({
|
||||
// the CPU sees must be drawn under the click (its pick radius, no slack)
|
||||
// and be the one the CPU finds on top. A stale answer from the previous
|
||||
// gesture (the followed aircraft at the centre) lay within twice its
|
||||
// radius of a neighbour's click and won (10b/11b flake). A model hit is
|
||||
// radius of a neighbour's click and won. A model hit is
|
||||
// checked against its projected position within its drawn radius
|
||||
// (pickRadiusPx); the CPU's top hit (drawn order first) is not asked of
|
||||
// it, as a model is drawn depth-tested among the glyphs.
|
||||
@@ -83,10 +76,7 @@ export function createNavaraPicking({
|
||||
(top !== undefined &&
|
||||
!(top.owner === hit.set && top.instance === hit.instance) &&
|
||||
(!isModelSet(hit.set) || top.instance === undefined));
|
||||
if (stale) {
|
||||
stats.stale++;
|
||||
return drillPick(at, 1)[0];
|
||||
}
|
||||
if (stale) return drillPick(at, 1)[0];
|
||||
}
|
||||
return hit
|
||||
? { id: hit.pickId, owner: hit.set, instance: hit.instance }
|
||||
@@ -103,7 +93,6 @@ export function createNavaraPicking({
|
||||
return;
|
||||
}
|
||||
cancel(next.timer);
|
||||
answered(next, 'gpu');
|
||||
next.resolve(answerFrom(resolveInfo(info), next.at));
|
||||
};
|
||||
view.on('featureClick', onFeatureClick);
|
||||
@@ -119,29 +108,22 @@ export function createNavaraPicking({
|
||||
clickPick(at) {
|
||||
const gesture = early;
|
||||
early = null;
|
||||
if (gesture && now() - gesture.at <= EARLY_ANSWER_MS) {
|
||||
const entry = { startedAt: gesture.at };
|
||||
answered(entry, 'gpu');
|
||||
if (gesture && now() - gesture.at <= EARLY_ANSWER_MS)
|
||||
return Promise.resolve(answerFrom(gesture.hit, at));
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
const entry = {
|
||||
at: { x: at.x, y: at.y },
|
||||
resolve,
|
||||
timer: null,
|
||||
startedAt: now(),
|
||||
};
|
||||
entry.timer = later(() => {
|
||||
const index = waiting.indexOf(entry);
|
||||
if (index >= 0) waiting.splice(index, 1);
|
||||
answered(entry, 'timeout');
|
||||
resolve(drillPick(entry.at, 1)[0]);
|
||||
}, timeoutMs);
|
||||
waiting.push(entry);
|
||||
});
|
||||
},
|
||||
/** How clicks were answered: GPU picks, timeouts, recent latencies (ms). */
|
||||
clickStats: () => ({ ...stats, latencies: [...stats.latencies] }),
|
||||
destroy() {
|
||||
meshPickers.clear();
|
||||
view.off('featureClick', onFeatureClick);
|
||||
|
||||
@@ -162,36 +162,6 @@ test('without a GPU answer in time the click falls back to the CPU pick', async
|
||||
assert.equal(view.handlers.size, 0);
|
||||
});
|
||||
|
||||
test('click stats count GPU answers and timeouts with their latency', async () => {
|
||||
const view = fakeView();
|
||||
const clock = timers();
|
||||
let time = 0;
|
||||
const picking = createNavaraPicking({
|
||||
view,
|
||||
projector,
|
||||
camera,
|
||||
movers: () => [],
|
||||
lines: () => [],
|
||||
resolveBatch: () => null,
|
||||
now: () => time,
|
||||
...clock,
|
||||
});
|
||||
const first = picking.clickPick({ x: 0, y: 0 });
|
||||
time = 30;
|
||||
view.emit('featureClick', null);
|
||||
await first;
|
||||
const second = picking.clickPick({ x: 0, y: 0 });
|
||||
time = 280;
|
||||
clock.pending[0].fn();
|
||||
await second;
|
||||
assert.deepEqual(picking.clickStats(), {
|
||||
gpu: 1,
|
||||
timeout: 1,
|
||||
stale: 0,
|
||||
latencies: [30, 250],
|
||||
});
|
||||
});
|
||||
|
||||
test("Navara's answer may come before the engine's click of the same gesture", async () => {
|
||||
const view = fakeView();
|
||||
const clock = timers();
|
||||
@@ -247,7 +217,6 @@ test('a GPU answer naming an instance drawn far from the click is stale', async
|
||||
const answer = picking.clickPick({ x: 10, y: 10 });
|
||||
view.emit('featureClick', { batchId: 2 });
|
||||
assert.equal((await answer).id, 'drawn-here');
|
||||
assert.equal(picking.clickStats().stale, 1);
|
||||
});
|
||||
|
||||
test('a thin line is picked within 8 px of its segments', () => {
|
||||
@@ -328,7 +297,6 @@ test('a stale GPU answer for a neighbour of the click never wins over the instan
|
||||
view.emit('featureClick', { batchId: 1 }); // stale: A again
|
||||
assert.equal((await onB).id, 'b', `gesture ${gesture}: b, not the stale a`);
|
||||
}
|
||||
assert.equal(picking.clickStats().stale, 20);
|
||||
});
|
||||
|
||||
function modelSet(id, rows, radiusPx) {
|
||||
@@ -406,7 +374,6 @@ test('a model hit is checked against its projected position within its drawn rad
|
||||
const outside = picking.clickPick({ x: 160, y: 100 });
|
||||
view.emit('featureClick', { batchId: 1 });
|
||||
assert.equal(await outside, undefined);
|
||||
assert.equal(picking.clickStats().stale, 1);
|
||||
// The CPU pick sees the model at its drawn radius, not the 24 px minimum.
|
||||
assert.equal(picking.drillPick({ x: 121, y: 100 })[0]?.id, 'jet');
|
||||
assert.equal(picking.drillPick({ x: 125, y: 100 }).length, 0);
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
// center + (center − blur) × amount, clamped to [0, 1].
|
||||
//
|
||||
// After tone mapping and native-stage fields such as FIRMS, before AA and
|
||||
// the ordinary W1 display overlay. Native SHARPEN_SHADER filters encoded
|
||||
// display RGB. Navara buffers stay linear, so use the exact sRGB transfer
|
||||
// before the box mask and its inverse afterward. A gamma-2.2 approximation
|
||||
// changes the colors of small, high-contrast glows even at the same amount.
|
||||
// the ordinary display overlay (overlay.js). Native SHARPEN_SHADER filters
|
||||
// encoded display RGB. Navara buffers stay linear, so use the exact sRGB
|
||||
// transfer before the box mask and its inverse afterward. A gamma-2.2
|
||||
// approximation changes the colors of small, high-contrast glows even at the
|
||||
// same amount.
|
||||
//
|
||||
// The sky is left alone: Navara's clouds are dithered (a fine grain at the
|
||||
// `low` quality the look uses), and the mask turned that grain into visible
|
||||
// noise. A pixel whose scene depth (the MRT pass's packed depth buffer, as
|
||||
// the S1 drape reads it) is the far plane is sky or cloud; it keeps its
|
||||
// the drape reads it) is the far plane is sky or cloud; it keeps its
|
||||
// colour, and costs one texture read instead of nine.
|
||||
//
|
||||
// Its own pass: a convolution reads the pass input, so merged into the tone
|
||||
@@ -25,7 +26,7 @@ import { Effect as NavaraEffect, EffectDesc } from '@navaramap/three';
|
||||
import { Effect, EffectAttribute } from 'postprocessing';
|
||||
import { RGBADepthPacking, Uniform } from 'three';
|
||||
|
||||
export const SHARPEN_EFFECT_KEY = 'gevSharpen';
|
||||
const SHARPEN_EFFECT_KEY = 'gevSharpen';
|
||||
|
||||
const fragmentShader = /* glsl */ `
|
||||
uniform float amount;
|
||||
@@ -87,9 +88,7 @@ class UnsharpMaskEffect extends Effect {
|
||||
}
|
||||
|
||||
/** config.gevSharpen: { amount } (Cesium's `amount` uniform). */
|
||||
export class SharpenEffectDesc extends withPassDisposal(
|
||||
withFrameUpdates(EffectDesc),
|
||||
) {
|
||||
class SharpenEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
|
||||
static key = SHARPEN_EFFECT_KEY;
|
||||
static insertAfter = ['toneMapping'];
|
||||
static insertBefore = ['smaa', 'fxaa', 'gevOverlay', 'final'];
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
|
||||
export const STYLES_EFFECT_KEY = 'gevStyles';
|
||||
/** Intensity under which a style draws nothing (as VisualEffects disables a stage). */
|
||||
export const STYLE_VISIBLE_INTENSITY = 0.001;
|
||||
const STYLE_VISIBLE_INTENSITY = 0.001;
|
||||
|
||||
const VERTEX_SHADER = /* glsl */ `precision highp float;
|
||||
in vec3 position;
|
||||
|
||||
+21
-27
@@ -1,4 +1,4 @@
|
||||
// GlobeSurface on Navara (S2): the height of the rendered scene is a CPU ray
|
||||
// GlobeSurface on Navara: the height of the rendered scene is a CPU ray
|
||||
// straight down the ellipsoid normal against the 3D-tile meshes Navara shows.
|
||||
// Where the shown tiles do not reach (outside the frustum), the loaded
|
||||
// tiles Navara hides answer, the finest first. Tile positions are float32
|
||||
@@ -187,15 +187,14 @@ const NO_EXCLUDE = new Set();
|
||||
// the top one among them. Tiles the ray passes are tried finest first, and
|
||||
// coarser ones stop being tried once a hit sets the limit, so the coarse
|
||||
// parents' triangles are never walked.
|
||||
// With `includeShown` (lod 'finest') the shown tiles take part too.
|
||||
const hiddenTiles = [];
|
||||
function finestHiddenHit(roots, exclude, ray, includeShown = false) {
|
||||
function finestHiddenHit(roots, exclude, ray) {
|
||||
worldRay.origin.set(ray.origin.x, ray.origin.y, ray.origin.z);
|
||||
worldRay.direction.set(ray.direction.x, ray.direction.y, ray.direction.z);
|
||||
hiddenTiles.length = 0;
|
||||
for (let i = 0; i < roots.length; i++) {
|
||||
const root = roots[i];
|
||||
if ((root.visible && !includeShown) || exclude.has(root)) continue;
|
||||
if (root.visible || exclude.has(root)) continue;
|
||||
const extent = tileExtent(root);
|
||||
if (extent && worldRay.intersectsSphere(extent)) hiddenTiles.push(root);
|
||||
}
|
||||
@@ -257,33 +256,29 @@ export function createNavaraSurface(view, hooks) {
|
||||
return height === undefined ? undefined : { height, source: 'terrain' };
|
||||
};
|
||||
const sampleHeightDetailed = (place, options) => {
|
||||
const { exclude, lod } = normalizeSurfaceOptions(options);
|
||||
const { exclude } = normalizeSurfaceOptions(options);
|
||||
if (!supported) return terrainDetail(place);
|
||||
const ray = surfaceRay(place);
|
||||
const roots = hooks.tileRoots();
|
||||
const excluded = exclude.length ? new Set(exclude) : NO_EXCLUDE;
|
||||
let hit = { distance: Infinity, root: null };
|
||||
if (lod === 'visible') {
|
||||
// The tiles on screen first; where they do not reach (the ground
|
||||
// under a camera looking ahead is outside the frustum), the hidden
|
||||
// ones.
|
||||
shownMeshes.length = 0;
|
||||
shownRoots.length = 0;
|
||||
for (let i = 0; i < roots.length; i++)
|
||||
collectMeshes(
|
||||
roots[i],
|
||||
excluded,
|
||||
true,
|
||||
shownMeshes,
|
||||
shownRoots,
|
||||
roots[i],
|
||||
);
|
||||
hit = nearestHit(shownMeshes, shownRoots, ray);
|
||||
shownMeshes.length = 0;
|
||||
shownRoots.length = 0;
|
||||
}
|
||||
// The tiles on screen first; where they do not reach (the ground under
|
||||
// a camera looking ahead is outside the frustum), the hidden ones.
|
||||
shownMeshes.length = 0;
|
||||
shownRoots.length = 0;
|
||||
for (let i = 0; i < roots.length; i++)
|
||||
collectMeshes(
|
||||
roots[i],
|
||||
excluded,
|
||||
true,
|
||||
shownMeshes,
|
||||
shownRoots,
|
||||
roots[i],
|
||||
);
|
||||
let hit = nearestHit(shownMeshes, shownRoots, ray);
|
||||
shownMeshes.length = 0;
|
||||
shownRoots.length = 0;
|
||||
if (!Number.isFinite(hit.distance))
|
||||
hit = finestHiddenHit(roots, excluded, ray, lod === 'finest');
|
||||
hit = finestHiddenHit(roots, excluded, ray);
|
||||
const height = heightAlongRay(ray, hit.distance);
|
||||
if (height === undefined) return terrainDetail(place);
|
||||
return { height, source: 'tiles', tileSizeM: tileSizeOf(hit.root) };
|
||||
@@ -342,7 +337,6 @@ export function createNavaraSurface(view, hooks) {
|
||||
return {
|
||||
surface: {
|
||||
raycast,
|
||||
raycastSupported: supported,
|
||||
sampleHeight,
|
||||
sampleHeightDetailed,
|
||||
supported,
|
||||
|
||||
@@ -230,15 +230,12 @@ test('sampleHeightDetailed names the source and the size of the answering tile',
|
||||
assert.equal(shown.source, 'tiles');
|
||||
near(shown.height, 43, 0.05, 'the shown tile');
|
||||
near(shown.tileSizeM, 600 * Math.SQRT2, 1, 'its size');
|
||||
const finest = surface.sampleHeightDetailed(place, { lod: 'finest' });
|
||||
near(finest.height, 40, 0.05, 'the finest loaded tile');
|
||||
near(finest.tileSizeM, 200 * Math.SQRT2, 1, 'its size');
|
||||
assert.deepEqual(
|
||||
surface.sampleHeightDetailed(place, { exclude: [coarse.tile, fine.tile] }),
|
||||
{ height: 7, source: 'terrain' },
|
||||
);
|
||||
assert.throws(
|
||||
() => surface.sampleHeightDetailed(place, { lod: 'best' }),
|
||||
() => surface.sampleHeightDetailed(place, { exclude: 'x' }),
|
||||
TypeError,
|
||||
);
|
||||
const bare = setup({ tiles: [] }).surface;
|
||||
|
||||
@@ -97,7 +97,6 @@ test('invalid and unsupported surface rays never invent terrain intersections',
|
||||
undefined,
|
||||
);
|
||||
const missing = fixture(t, { supported: false });
|
||||
assert.equal(missing.surface.raycastSupported, false);
|
||||
assert.equal(missing.surface.raycast(missing.ray), undefined);
|
||||
assert.equal(missing.terrainQueries(), 0);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// How the product builds its Navara view (S4, S5): render on demand (the
|
||||
// engine's render.setContinuous turns animation on), MSAA 4 as Cesium's
|
||||
// msaaSamples, the device pixel ratio unless a measurement pins one, a canvas
|
||||
// whose WebGL2 context keeps its drawing buffer (Cesium's
|
||||
// contextOptions.webgl.preserveDrawingBuffer, for captures), and a look:
|
||||
// `cinematic` by default (navaraScenePlan below), Navara's own `photoreal`
|
||||
// scene (aerial perspective, tone mapping and SMAA, about 5 ms a frame, S5)
|
||||
// with `?look=photoreal`, and `minimal` (sky, stars, sky light and sun
|
||||
// How the product builds its Navara view: render on demand (the engine's
|
||||
// render.setContinuous turns animation on), MSAA 4 as Cesium's msaaSamples,
|
||||
// the device pixel ratio, a canvas whose WebGL2 context keeps its drawing
|
||||
// buffer (Cesium's contextOptions.webgl.preserveDrawingBuffer, for captures),
|
||||
// and a look: `cinematic` by default (navaraScenePlan below), Navara's own
|
||||
// `photoreal` scene (aerial perspective, tone mapping and SMAA, about 5 ms a
|
||||
// frame) with `?look=photoreal`, and `minimal` (sky, stars, sky light and sun
|
||||
// without post effects) for benches.
|
||||
|
||||
/** WebGL2 attributes Navara 0.2.1 asks for, plus preserveDrawingBuffer. */
|
||||
@@ -21,14 +20,13 @@ export const NAVARA_CONTEXT_ATTRIBUTES = Object.freeze({
|
||||
|
||||
const MSAA_SAMPLES = 4;
|
||||
|
||||
/** ThreeView options; `pixelRatio` only when a measurement pins it. */
|
||||
export function navaraViewOptions({ container, canvas, pixelRatio } = {}) {
|
||||
/** ThreeView options. */
|
||||
export function navaraViewOptions({ container, canvas } = {}) {
|
||||
return {
|
||||
container,
|
||||
...(canvas ? { canvas } : {}),
|
||||
animation: false,
|
||||
multisampling: MSAA_SAMPLES,
|
||||
...(pixelRatio !== undefined ? { pixelRatio } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,11 +32,6 @@ test('the product view renders on demand with MSAA 4 at the native pixel ratio',
|
||||
animation: false,
|
||||
multisampling: 4,
|
||||
});
|
||||
assert.equal(
|
||||
navaraViewOptions({ container, pixelRatio: 1 }).pixelRatio,
|
||||
1,
|
||||
'measurements pin the pixel ratio',
|
||||
);
|
||||
});
|
||||
|
||||
test('the canvas context keeps its drawing buffer, with the attributes Navara asks for', () => {
|
||||
@@ -51,7 +46,7 @@ test('the canvas context keeps its drawing buffer, with the attributes Navara as
|
||||
});
|
||||
});
|
||||
|
||||
test('cinematic is the default look; photoreal is the default plugin scene; minimal has no post effects (S5)', () => {
|
||||
test('cinematic is the default look; photoreal is the default plugin scene; minimal has no post effects', () => {
|
||||
assert.equal(DEFAULT_NAVARA_LOOK, 'cinematic');
|
||||
assert.deepEqual(navaraScenePlan(), navaraScenePlan('cinematic'));
|
||||
assert.deepEqual(navaraScenePlan('photoreal'), {
|
||||
|
||||
Reference in new issue
Block a user