mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Project the launches replay overlay through the query port
The replay vehicle overlay asks the renderer's query port where the vehicle and its path tangent land on screen, instead of Cesium's scene transforms, and the anchor horizon test uses the geo vector helpers and the WGS84 radii. A point behind the eye, or a scene with no query port, hides the overlay as an unprojectable point did before. Overlays leaves the allow-list.
This commit is contained in:
1 parent
2443028d0f
commit
d6f09f9860
3 files changed
+102
-34
No files matched your search
@@ -1,4 +1,6 @@
|
|||||||
import * as Cesium from 'cesium';
|
import { WGS84 } from '../../geo/ellipsoid.js';
|
||||||
|
import { dot, magnitude, normalize, toDegrees } from '../../geo/vector.js';
|
||||||
|
import { findQuery } from '../../render/rendererOf.js';
|
||||||
import { t, msg } from '../../i18n/index.js';
|
import { t, msg } from '../../i18n/index.js';
|
||||||
import {
|
import {
|
||||||
createCyberSonarSampler,
|
createCyberSonarSampler,
|
||||||
@@ -12,13 +14,16 @@ import {
|
|||||||
ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_OPTIONS,
|
ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_OPTIONS,
|
||||||
} from './policy.js';
|
} from './policy.js';
|
||||||
|
|
||||||
|
/** The ellipsoid's largest radius, metres. */
|
||||||
|
const MAX_RADIUS = Math.max(WGS84.radii.x, WGS84.radii.y, WGS84.radii.z);
|
||||||
|
|
||||||
export function createOverlays({ state: layerState, services, parts, source }) {
|
export function createOverlays({ state: layerState, services, parts, source }) {
|
||||||
/**
|
/**
|
||||||
* Resolve whether a surface mission anchor is safely on the camera-facing
|
* Resolve whether a surface mission anchor is safely on the camera-facing
|
||||||
* side of Earth. The small positive limb margin prevents labels anchored just
|
* side of Earth. The small positive limb margin prevents labels anchored just
|
||||||
* beyond the horizon from leaking through the hidden Cesium globe.
|
* beyond the horizon from leaking through the hidden globe.
|
||||||
* @param {Cesium.Cartesian3} cameraPosition Camera world position.
|
* @param {{x: number, y: number, z: number}} cameraPosition Camera world position.
|
||||||
* @param {Cesium.Cartesian3} markerPosition Mission anchor world position.
|
* @param {{x: number, y: number, z: number}} markerPosition Mission anchor world position.
|
||||||
* @param {number} [limbMargin] Additional normalized horizon clearance.
|
* @param {number} [limbMargin] Additional normalized horizon clearance.
|
||||||
* @returns {boolean} Whether the marker belongs on the visible hemisphere.
|
* @returns {boolean} Whether the marker belongs on the visible hemisphere.
|
||||||
*/
|
*/
|
||||||
@@ -29,33 +34,21 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
|||||||
limbMargin = 0.012,
|
limbMargin = 0.012,
|
||||||
) {
|
) {
|
||||||
if (!cameraPosition || !markerPosition) return false;
|
if (!cameraPosition || !markerPosition) return false;
|
||||||
const cameraMagnitude = Cesium.Cartesian3.magnitude(cameraPosition);
|
const cameraMagnitude = magnitude(cameraPosition);
|
||||||
if (
|
if (!Number.isFinite(cameraMagnitude) || cameraMagnitude <= MAX_RADIUS) {
|
||||||
!Number.isFinite(cameraMagnitude) ||
|
|
||||||
cameraMagnitude <= Cesium.Ellipsoid.WGS84.maximumRadius
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const cameraDirection = Cesium.Cartesian3.normalize(
|
const limbThreshold = MAX_RADIUS / cameraMagnitude;
|
||||||
cameraPosition,
|
|
||||||
new Cesium.Cartesian3(),
|
|
||||||
);
|
|
||||||
const markerDirection = Cesium.Cartesian3.normalize(
|
|
||||||
markerPosition,
|
|
||||||
new Cesium.Cartesian3(),
|
|
||||||
);
|
|
||||||
const limbThreshold =
|
|
||||||
Cesium.Ellipsoid.WGS84.maximumRadius / cameraMagnitude;
|
|
||||||
return (
|
return (
|
||||||
Cesium.Cartesian3.dot(cameraDirection, markerDirection) >
|
dot(normalize(cameraPosition), normalize(markerPosition)) >
|
||||||
limbThreshold + limbMargin
|
limbThreshold + limbMargin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve launch-anchor visibility for overview and selected-mission views.
|
* Resolve launch-anchor visibility for overview and selected-mission views.
|
||||||
* @param {Cesium.Cartesian3} cameraPosition Camera world position.
|
* @param {{x: number, y: number, z: number}} cameraPosition Camera world position.
|
||||||
* @param {Cesium.Cartesian3} markerPosition Mission anchor world position.
|
* @param {{x: number, y: number, z: number}} markerPosition Mission anchor world position.
|
||||||
* @param {string} markerId Mission represented by this anchor.
|
* @param {string} markerId Mission represented by this anchor.
|
||||||
* @param {string|null} selectedLaunchId Explicitly selected mission.
|
* @param {string|null} selectedLaunchId Explicitly selected mission.
|
||||||
* @returns {boolean} Whether the launch anchor should render.
|
* @returns {boolean} Whether the launch anchor should render.
|
||||||
@@ -104,7 +97,7 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
|||||||
* compete in the bounded ambient-label domain; the selected mission moves to
|
* compete in the bounded ambient-label domain; the selected mission moves to
|
||||||
* the protected selected lane and gains the former launch-site detail line.
|
* the protected selected lane and gains the former launch-site detail line.
|
||||||
* @param {object} launch Normalized Launch Library mission.
|
* @param {object} launch Normalized Launch Library mission.
|
||||||
* @param {Cesium.Cartesian3|function():Cesium.Cartesian3} position Existing display position.
|
* @param {object|function():object} position Existing display position.
|
||||||
* @param {boolean} [selected=false] Whether the mission owns the selected view.
|
* @param {boolean} [selected=false] Whether the mission owns the selected view.
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
@@ -164,7 +157,7 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
|||||||
* caller; newline semantics become explicit host detail rows.
|
* caller; newline semantics become explicit host detail rows.
|
||||||
* @param {object} input
|
* @param {object} input
|
||||||
* @param {string} input.id Stable mission-element identity.
|
* @param {string} input.id Stable mission-element identity.
|
||||||
* @param {Cesium.Cartesian3|function():Cesium.Cartesian3} input.position Existing cached position.
|
* @param {object|function():object} input.position Existing cached position.
|
||||||
* @param {string} input.text Former native-label text, including newlines.
|
* @param {string} input.text Former native-label text, including newlines.
|
||||||
* @param {string} input.accent Source-owned label color.
|
* @param {string} input.accent Source-owned label color.
|
||||||
* @param {number} [input.priority=0] Protected placement order.
|
* @param {number} [input.priority=0] Protected placement order.
|
||||||
@@ -490,10 +483,8 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
|||||||
hideReplayVehicleOverlay();
|
hideReplayVehicleOverlay();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const windowPosition = Cesium.SceneTransforms.worldToWindowCoordinates(
|
const query = findQuery(layerState._viewer);
|
||||||
layerState._viewer.scene,
|
const windowPosition = query?.project(position) ?? null;
|
||||||
position,
|
|
||||||
);
|
|
||||||
if (!windowPosition) {
|
if (!windowPosition) {
|
||||||
hideReplayVehicleOverlay();
|
hideReplayVehicleOverlay();
|
||||||
return null;
|
return null;
|
||||||
@@ -547,10 +538,7 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
|||||||
useForward ? forwardProgress : backwardProgress,
|
useForward ? forwardProgress : backwardProgress,
|
||||||
);
|
);
|
||||||
const tangentWindowPosition = tangentPosition
|
const tangentWindowPosition = tangentPosition
|
||||||
? Cesium.SceneTransforms.worldToWindowCoordinates(
|
? query.project(tangentPosition)
|
||||||
layerState._viewer.scene,
|
|
||||||
tangentPosition,
|
|
||||||
)
|
|
||||||
: null;
|
: null;
|
||||||
if (tangentWindowPosition) {
|
if (tangentWindowPosition) {
|
||||||
const screenDelta = Math.hypot(
|
const screenDelta = Math.hypot(
|
||||||
@@ -577,7 +565,7 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
frame.rotation = `${Cesium.Math.toDegrees(vehicleRotation)}deg`;
|
frame.rotation = `${toDegrees(vehicleRotation)}deg`;
|
||||||
|
|
||||||
const mission = shortMissionLabel(launch.name, 22).toUpperCase();
|
const mission = shortMissionLabel(launch.name, 22).toUpperCase();
|
||||||
const siteName = compactLaunchSiteName(launch.launchSite);
|
const siteName = compactLaunchSiteName(launch.launchSite);
|
||||||
|
|||||||
@@ -119,3 +119,84 @@ test('the scene chrome renders the overlay in the globe container', async (t) =>
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
assert.equal(node(), null);
|
assert.equal(node(), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the replay overlay sits where the query port projects the vehicle, facing along its path', async () => {
|
||||||
|
const { bindRenderer } = await import('../../render/rendererOf.js');
|
||||||
|
const viewer = { scene: { canvas: { clientWidth: 800, clientHeight: 600 } } };
|
||||||
|
const projected = [];
|
||||||
|
let behindEye = false;
|
||||||
|
// The path runs along x; the port puts x metres at x pixels, y = 300.
|
||||||
|
const unbind = bindRenderer(viewer, {
|
||||||
|
query: {
|
||||||
|
project(position) {
|
||||||
|
projected.push(position);
|
||||||
|
return behindEye ? null : { x: position.x, y: 300 };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const path = [
|
||||||
|
{ x: 0, y: 0, z: 0 },
|
||||||
|
{ x: 400, y: 0, z: 0 },
|
||||||
|
];
|
||||||
|
const state = {
|
||||||
|
_viewer: viewer,
|
||||||
|
_replayVehicleOverlay: null,
|
||||||
|
_replayVehicleOverlayListeners: new Set(),
|
||||||
|
_selectedLaunchId: 'l1',
|
||||||
|
_replayCameraLaunchId: 'l1',
|
||||||
|
_replayPaused: false,
|
||||||
|
_launches: [{ id: 'l1', name: 'Test', trajectory: [{}, {}] }],
|
||||||
|
_replayTracks: new Map([
|
||||||
|
[
|
||||||
|
'l1',
|
||||||
|
{
|
||||||
|
ascentPath: path,
|
||||||
|
getReplayState: () => ({
|
||||||
|
ascending: true,
|
||||||
|
countdownActive: false,
|
||||||
|
phaseProgress: 0.5,
|
||||||
|
elapsedSinceStart: 10,
|
||||||
|
eventTime: 0,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
const parts = createOverlays({
|
||||||
|
state,
|
||||||
|
services: {},
|
||||||
|
parts: {
|
||||||
|
paths: {
|
||||||
|
samplePath: (points, t) => ({ x: points[1].x * t, y: 0, z: 0 }),
|
||||||
|
},
|
||||||
|
replay: {
|
||||||
|
replayVehicleScreenRotation: (from, to) =>
|
||||||
|
Math.atan2(to.x - from.x, -(to.y - from.y)),
|
||||||
|
},
|
||||||
|
policyHelpers: { formatMissionEventTime: () => 'T+00:10' },
|
||||||
|
},
|
||||||
|
source: {},
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
parts.createReplayVehicleOverlay();
|
||||||
|
const occluder = { isPointVisible: () => true };
|
||||||
|
assert.equal(parts.updateReplayVehicleOverlay(occluder), 'ascent');
|
||||||
|
const view = state._replayVehicleOverlay;
|
||||||
|
assert.equal(view.visible, true);
|
||||||
|
assert.equal(
|
||||||
|
view.transform,
|
||||||
|
'translate3d(200px, 300px, 0) translate(-50%, -50%)',
|
||||||
|
);
|
||||||
|
assert.equal(view.rotation, '90deg', 'the path heads right on screen');
|
||||||
|
assert.equal(projected.length, 2, 'vehicle and tangent point');
|
||||||
|
behindEye = true;
|
||||||
|
assert.equal(parts.updateReplayVehicleOverlay(occluder), null);
|
||||||
|
assert.equal(
|
||||||
|
state._replayVehicleOverlay.visible,
|
||||||
|
false,
|
||||||
|
'a vehicle behind the eye hides the overlay',
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -60,7 +60,6 @@
|
|||||||
"src/layers/installations/rendering.js",
|
"src/layers/installations/rendering.js",
|
||||||
"src/layers/launches/launchPad.js",
|
"src/layers/launches/launchPad.js",
|
||||||
"src/layers/launches/orbitRendering.js",
|
"src/layers/launches/orbitRendering.js",
|
||||||
"src/layers/launches/overlays.js",
|
|
||||||
"src/layers/launches/rendering.js",
|
"src/layers/launches/rendering.js",
|
||||||
"src/layers/localAdsb/index.js",
|
"src/layers/localAdsb/index.js",
|
||||||
"src/layers/localAdsb/models.js",
|
"src/layers/localAdsb/models.js",
|
||||||
|
|||||||
Reference in new issue
Block a user