feat(launches): render on Navara

This commit is contained in:
German Khokhlov committed 2026-10-23 01:19:57 +04:00
1 parent 4baefeb8f9
commit 766c786093
20 files changed
+1050 -33

No files matched your search

+13 -3
View File
@@ -85,12 +85,17 @@ export function orientationVectors(position, heading, pitch, roll) {
* 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) {
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) <= 1e-3;
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;
@@ -109,7 +114,12 @@ export function headingPitchRoll(position, direction, up) {
*/
export function navaraPose(position, direction, up) {
const place = cartographic.fromCartesian(position, WGS84);
const angles = headingPitchRoll(position, direction, up);
// 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 {
+25 -5
View File
@@ -116,12 +116,11 @@ test('navaraPose gives Navara setCamera degrees in the same convention', () => {
near(pose.lng, -70, 1e-9, 'lng');
near(pose.lat, 45, 1e-9, 'lat');
near(pose.height, 25000, 1e-6, 'height');
near(pose.heading, math.toDegrees(1.2), 1e-9, 'heading (deg)');
near(pose.pitch, math.toDegrees(-0.6), 1e-9, 'pitch (deg)');
near(pose.roll, math.toDegrees(-0.05), 1e-9, 'roll (deg) in (−180, 180]');
// Back through the same convention, the basis is unchanged.
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(
camera.position,
cartesian3.fromDegrees(pose.lng, pose.lat, 0),
math.toRadians(pose.heading),
math.toRadians(pose.pitch),
math.toRadians(pose.roll),
@@ -358,3 +357,24 @@ test("horizonVisible agrees with Cesium's EllipsoidalOccluder, also at the limb"
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');
}
});
+9 -3
View File
@@ -51,7 +51,7 @@ function createFakePort() {
port.drawn = {
position,
...orientationVectors(
position,
cartesian3.fromDegrees(pose.lng, pose.lat, 0),
math.toRadians(pose.heading),
math.toRadians(pitch),
math.toRadians(pose.roll),
@@ -127,8 +127,14 @@ test('setView updates the pose at once and pushes the Navara pose in degrees', (
near(pose.roll, 0.05, 1e-12, 'roll');
const pushed = port.applied.at(-1);
near(pushed.lng, -70, 1e-9, 'lng');
near(pushed.heading, math.toDegrees(1.2), 1e-9, 'heading (deg)');
near(pushed.roll, math.toDegrees(0.05), 1e-9, 'roll (deg)');
port.update();
near(
cartesian3.distance(port.drawn.direction, pose.direction),
0,
1e-12,
'drawn direction',
);
near(cartesian3.distance(port.drawn.up, pose.up), 0, 1e-12, 'drawn up');
assert.ok(port.frames > 0, 'no frame was requested');
});
+14 -1
View File
@@ -214,7 +214,20 @@ test("the camera starts from Navara's drawn camera and pushes poses with setCame
engine.camera.setView({ destination: cartesian3.fromDegrees(20, 10, 1e6) });
const [, pose] = view.calls.findLast(([name]) => name === 'setCamera');
near(pose.lng, 20, 1e-9, 'lng');
near(pose.pitch, -90, 1e-9, 'pitch');
const drawn = orientationVectors(
cartesian3.fromDegrees(pose.lng, pose.lat, 0),
math.toRadians(pose.heading),
math.toRadians(pose.pitch),
math.toRadians(pose.roll),
);
const desired = engine.camera.pose();
near(
cartesian3.distance(drawn.direction, desired.direction),
0,
1e-12,
'world direction',
);
near(cartesian3.distance(drawn.up, desired.up), 0, 1e-12, 'world up');
});
test("Navara's fov follows Cesium's vertical fov, also after a resize", () => {
+2 -1
View File
@@ -2,7 +2,7 @@
// the product way (viewOptions.js) and the GlobeEngine on it. Load it with a
// dynamic import() so Navara stays out of the Cesium-mode bundle.
import ThreeView from '@navaramap/three';
import ThreeView, { MeshDesc } from '@navaramap/three';
import * as geo from '../../geo/index.js';
import { DefaultPlugin } from '@navaramap/three-default-plugin';
import { createNavaraEngine } from './createNavaraEngine.js';
@@ -179,6 +179,7 @@ export async function createNavaraGlobe({
return {
view,
engine,
MeshDesc,
destroy() {
if (destroyed) return;
destroyed = true;