mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Move the launches replay and selection cameras onto the camera port
Replay and selection no longer import Cesium. Their maths uses the geo helpers; the full-globe framing reads the camera's position and field of view from the port's pose. Choosing the selected entity, showing only the selected mission's entities and reading the projected orbit for framing move into the rendering part, which owns the entities, so selection no longer touches them. The full-globe framing now checks the canvas size before it asks for the camera. The replay camera still steps in the scene's preUpdate, as before; it moves onto the frame port once unbound viewers have one. Replay and selection leave the allow-list.
This commit is contained in:
1 parent
a2503476de
commit
e2dea507b9
4 files changed
+99
-104
No files matched your search
@@ -1,7 +1,18 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { WGS84, fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import {
|
||||
PI_OVER_TWO,
|
||||
add,
|
||||
cross,
|
||||
distance,
|
||||
dot,
|
||||
negate,
|
||||
normalize,
|
||||
scale,
|
||||
toRadians,
|
||||
vec,
|
||||
} from '../../geo/vector.js';
|
||||
import { MISSION_GLOBE_VIEW_RANGE_M, MISSION_FOCUS_RANGE_M } from './policy.js';
|
||||
import { cameraOf } from '../../render/cesium/camera.js';
|
||||
import { findCamera } from '../../render/rendererOf.js';
|
||||
import { cameraOf, findCamera } from '../../render/rendererOf.js';
|
||||
|
||||
export function createSelection({
|
||||
state: layerState,
|
||||
@@ -15,18 +26,18 @@ export function createSelection({
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const height = canvas?.clientHeight || canvas?.height;
|
||||
const width = canvas?.clientWidth || canvas?.width;
|
||||
const cartographic = viewer?.camera?.positionCartographic;
|
||||
const fovy = viewer?.camera?.frustum?.fovy;
|
||||
if (!(width > 0) || !(height > 0)) return;
|
||||
const pose = findCamera(viewer)?.pose();
|
||||
const fovy = pose?.fovy;
|
||||
if (
|
||||
!(width > 0) ||
|
||||
!(height > 0) ||
|
||||
!cartographic ||
|
||||
!pose ||
|
||||
!Number.isFinite(pose.lon) ||
|
||||
!Number.isFinite(fovy) ||
|
||||
fovy <= 0 ||
|
||||
fovy >= Math.PI
|
||||
)
|
||||
return;
|
||||
const earthRadius = Cesium.Ellipsoid.WGS84.maximumRadius;
|
||||
const earthRadius = WGS84.radii.x;
|
||||
const keyholeRadius = getKeyholeGeometry(width, height).radius;
|
||||
const targetScreenRadius = keyholeRadius * 0.61;
|
||||
const angularRadius = Math.atan(
|
||||
@@ -36,15 +47,11 @@ export function createSelection({
|
||||
const altitude = Math.max(earthRadius * 1.55, distance - earthRadius);
|
||||
const camera = cameraOf(viewer);
|
||||
camera.flyTo(
|
||||
Cesium.Cartesian3.fromRadians(
|
||||
cartographic.longitude,
|
||||
cartographic.latitude,
|
||||
altitude,
|
||||
),
|
||||
{ lon: pose.lon, lat: pose.lat, height: altitude },
|
||||
{
|
||||
orientation: {
|
||||
heading: camera.pose().heading,
|
||||
pitch: -Cesium.Math.PI_OVER_TWO,
|
||||
heading: pose.heading,
|
||||
pitch: -PI_OVER_TWO,
|
||||
roll: 0,
|
||||
},
|
||||
durationS: duration,
|
||||
@@ -76,15 +83,10 @@ export function createSelection({
|
||||
if (launchId) layerState._animationStarts.set(launchId, Date.now());
|
||||
if (!launchId && layerState._viewer) {
|
||||
stopMissionZoomAnchor();
|
||||
layerState._viewer.selectedEntity = undefined;
|
||||
parts.rendering.selectLaunchEntity(null);
|
||||
}
|
||||
if (!layerState._dataSource) return;
|
||||
for (const entity of layerState._dataSource.entities.values) {
|
||||
const relatedId = entityLaunchId(entity);
|
||||
entity.show = launchId
|
||||
? relatedId === launchId
|
||||
: entity.id.startsWith('rocket-launch:');
|
||||
}
|
||||
parts.rendering.isolateMission(launchId);
|
||||
parts.orbitRendering.syncMissionOrbitPrimitiveVisibility();
|
||||
parts.overlays.syncMissionOverlayEntries();
|
||||
parts.panel.renderMissionPanel();
|
||||
@@ -103,7 +105,7 @@ export function createSelection({
|
||||
if (!layerState._viewer || !launch || layerState._replayCameraLaunchId)
|
||||
return;
|
||||
stopMissionZoomAnchor();
|
||||
const target = Cesium.Cartesian3.fromDegrees(launch.lon, launch.lat);
|
||||
const target = fromDegrees(launch.lon, launch.lat);
|
||||
const range = Math.max(
|
||||
2000,
|
||||
Number(initialRange) || MISSION_GLOBE_VIEW_RANGE_M,
|
||||
@@ -119,24 +121,14 @@ export function createSelection({
|
||||
function focusMission(launch) {
|
||||
if (!layerState._viewer || !launch) return;
|
||||
stopMissionZoomAnchor();
|
||||
layerState._viewer.selectedEntity = layerState._dataSource.entities.getById(
|
||||
`rocket-launch:${launch.id}`,
|
||||
);
|
||||
const orbitEntity = layerState._dataSource.entities.getById(
|
||||
`rocket-orbit:${launch.id}`,
|
||||
);
|
||||
const orbitPositions = orbitEntity?.polyline?.positions?.getValue(
|
||||
Cesium.JulianDate.now(),
|
||||
);
|
||||
const launchPosition = Cesium.Cartesian3.fromDegrees(
|
||||
launch.lon,
|
||||
launch.lat,
|
||||
);
|
||||
parts.rendering.selectLaunchEntity(launch.id);
|
||||
const camera = cameraOf(layerState._viewer);
|
||||
const orbitPositions = parts.rendering.projectedOrbitPath(launch.id);
|
||||
const launchPosition = fromDegrees(launch.lon, launch.lat);
|
||||
let range = 18000000;
|
||||
if (orbitPositions?.length > 1) {
|
||||
const canvas = layerState._viewer.scene.canvas;
|
||||
const fovy =
|
||||
layerState._viewer.camera.frustum?.fovy || Cesium.Math.toRadians(60);
|
||||
const fovy = camera.pose().fovy || toRadians(60);
|
||||
const aspect = Math.max(
|
||||
0.1,
|
||||
(canvas.clientWidth || canvas.width) /
|
||||
@@ -145,8 +137,7 @@ export function createSelection({
|
||||
const fovx = 2 * Math.atan(Math.tan(fovy * 0.5) * aspect);
|
||||
const paddedHalfAngle = Math.min(fovy, fovx) * 0.5 * 0.62;
|
||||
const orbitExtent = orbitPositions.reduce(
|
||||
(largest, point) =>
|
||||
Math.max(largest, Cesium.Cartesian3.distance(launchPosition, point)),
|
||||
(largest, point) => Math.max(largest, distance(launchPosition, point)),
|
||||
0,
|
||||
);
|
||||
range = Math.max(
|
||||
@@ -154,41 +145,14 @@ export function createSelection({
|
||||
18000000,
|
||||
);
|
||||
}
|
||||
const targetNormal = Cesium.Cartesian3.normalize(
|
||||
launchPosition,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const destination = Cesium.Cartesian3.add(
|
||||
launchPosition,
|
||||
Cesium.Cartesian3.multiplyByScalar(
|
||||
targetNormal,
|
||||
range,
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const direction = Cesium.Cartesian3.negate(
|
||||
targetNormal,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
let right = Cesium.Cartesian3.cross(
|
||||
direction,
|
||||
Cesium.Cartesian3.UNIT_Z,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
if (Cesium.Cartesian3.magnitudeSquared(right) < 1e-8) {
|
||||
right = Cesium.Cartesian3.cross(
|
||||
direction,
|
||||
Cesium.Cartesian3.UNIT_Y,
|
||||
right,
|
||||
);
|
||||
}
|
||||
Cesium.Cartesian3.normalize(right, right);
|
||||
const up = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.cross(right, direction, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
cameraOf(layerState._viewer).flyTo(destination, {
|
||||
const targetNormal = normalize(launchPosition);
|
||||
const destination = add(launchPosition, scale(targetNormal, range));
|
||||
const direction = negate(targetNormal);
|
||||
let right = cross(direction, vec(0, 0, 1));
|
||||
if (dot(right, right) < 1e-8) right = cross(direction, vec(0, 1, 0));
|
||||
right = normalize(right);
|
||||
const up = normalize(cross(right, direction));
|
||||
camera.flyTo(destination, {
|
||||
orientation: { direction, up },
|
||||
durationS: 1.1,
|
||||
onComplete: () => {
|
||||
@@ -202,15 +166,13 @@ export function createSelection({
|
||||
if (!layerState._viewer || !launch) return;
|
||||
parts.replay.stopMissionReplay();
|
||||
stopMissionZoomAnchor();
|
||||
layerState._viewer.selectedEntity = layerState._dataSource.entities.getById(
|
||||
`rocket-launch:${launch.id}`,
|
||||
);
|
||||
parts.rendering.selectLaunchEntity(launch.id);
|
||||
cameraOf(layerState._viewer).flyToBounds(
|
||||
{ center: { lon: launch.lon, lat: launch.lat }, radius: 0 },
|
||||
{
|
||||
offset: {
|
||||
heading: 0,
|
||||
pitch: Cesium.Math.toRadians(-42),
|
||||
pitch: toRadians(-42),
|
||||
range: MISSION_FOCUS_RANGE_M,
|
||||
},
|
||||
durationS: 1.4,
|
||||
|
||||
Reference in new issue
Block a user