mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Merge remote-tracking branch 'origin/main' into german/cctv-nearest-same-camera
# Conflicts: # src/layers/cctv/selection.test.mjs
This commit is contained in:
commit
ab33ac5332
176 files changed
+10251
-900
No files matched your search
@@ -1,6 +1,14 @@
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import { toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { rangeForBoundingSphere } from '../../data/cameraFraming.js';
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { CCTV_FOCUS_RESULT } from './policy.js';
|
||||
import { cameraOf } from '../../render/rendererOf.js';
|
||||
import {
|
||||
cellBounds,
|
||||
cellCenter,
|
||||
cellHalfExtents,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { CCTV_FOCUS_RESULT, VIEW_CELL_PX, VIEW_MIN_CELL_M } from './policy.js';
|
||||
import { cameraOf, canvasOf } from '../../render/rendererOf.js';
|
||||
|
||||
export function createNavigation({
|
||||
state: layerState,
|
||||
@@ -78,6 +86,16 @@ export function createNavigation({
|
||||
return true;
|
||||
}
|
||||
|
||||
/** What holds the view instead of a CCTV flight, or null when it is free. */
|
||||
function viewHeldBy(viewer) {
|
||||
if (
|
||||
typeof document !== 'undefined' &&
|
||||
document.body?.classList.contains('cockpit-mode')
|
||||
)
|
||||
return CCTV_FOCUS_RESULT.COCKPIT_ACTIVE;
|
||||
return isFollowing(viewer) ? CCTV_FOCUS_RESULT.TRACKING_HOLDS_VIEW : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flies the viewer's camera to frame the specified CCTV camera,
|
||||
* looking along its heading from above.
|
||||
@@ -89,14 +107,12 @@ export function createNavigation({
|
||||
|
||||
function focusCctvRecord(viewer, record, duration = 2.2) {
|
||||
if (!viewer || !record) return CCTV_FOCUS_RESULT.NO_ACTIVE_CAMERA;
|
||||
if (
|
||||
typeof document !== 'undefined' &&
|
||||
document.body?.classList.contains('cockpit-mode')
|
||||
) {
|
||||
const held = viewHeldBy(viewer);
|
||||
if (held === CCTV_FOCUS_RESULT.COCKPIT_ACTIVE) {
|
||||
console.debug('[Data:CCTV] focus ignored while cockpit owns the camera');
|
||||
return CCTV_FOCUS_RESULT.COCKPIT_ACTIVE;
|
||||
}
|
||||
if (isFollowing(viewer)) {
|
||||
if (held === CCTV_FOCUS_RESULT.TRACKING_HOLDS_VIEW) {
|
||||
console.debug(
|
||||
'[Data:CCTV] focus ignored while a tracked entity owns the camera',
|
||||
);
|
||||
@@ -119,6 +135,68 @@ export function createNavigation({
|
||||
return CCTV_FOCUS_RESULT.FOCUSED;
|
||||
}
|
||||
|
||||
/** The nearest ground cell with two or more cameras, or the group itself if unmerged. */
|
||||
function nearestPart(cell, eye) {
|
||||
let nearest = cell;
|
||||
let best = Infinity;
|
||||
for (const part of cell.parts ?? []) {
|
||||
if (part.count < 2) continue;
|
||||
const d = distance(eye, cellCenter(part));
|
||||
if (d < best) {
|
||||
best = d;
|
||||
nearest = part;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
/** Frame a group's padded bounds from above, including coincident mounts. */
|
||||
function zoomToCell(cell) {
|
||||
const viewer = layerState._viewer;
|
||||
if (!viewer || viewHeldBy(viewer)) return;
|
||||
const camera = cameraOf(viewer);
|
||||
const pose = camera.pose();
|
||||
const tanHalfY = Math.tan((pose.fovy || Math.PI / 3) / 2);
|
||||
const canvas = canvasOf(viewer);
|
||||
const height = canvas?.clientHeight || canvas?.height || 1;
|
||||
// Half the range where cells stop grouping, so even coincident mounts split.
|
||||
const closeRange =
|
||||
(VIEW_MIN_CELL_M * height) / (4 * VIEW_CELL_PX * tanHalfY);
|
||||
const tanHalfX = tanHalfY * (pose.aspectRatio || 1);
|
||||
// Range where a cell's ground extent, times `pad`, fits the frame at the
|
||||
// depth of its highest mount above the bounds centre.
|
||||
const extentRange = (target, bounds, pad = 1) => {
|
||||
const { halfWidthM, halfHeightM } = cellHalfExtents(target);
|
||||
const rise = Math.max(0, target.high - toLonLatH(bounds.center).height);
|
||||
return (
|
||||
rise + pad * Math.max(halfWidthM / tanHalfX, halfHeightM / tanHalfY)
|
||||
);
|
||||
};
|
||||
// The sphere fit spans the wider side, so a very wide window also needs the extent.
|
||||
const fitRange = (target, bounds) =>
|
||||
Math.max(
|
||||
closeRange,
|
||||
rangeForBoundingSphere(viewer, bounds.radius),
|
||||
extentRange(target, bounds, 1.2),
|
||||
);
|
||||
// Approach long groups in halves so every click gets closer.
|
||||
const halfway = (bounds) =>
|
||||
pose.position ? distance(pose.position, bounds.center) / 2 : Infinity;
|
||||
let bounds = cellBounds(cell);
|
||||
let range = Math.min(halfway(bounds), fitRange(cell, bounds));
|
||||
// If the group overflows the frame at that range, approach its nearest counted cell.
|
||||
if (range < extentRange(cell, bounds)) {
|
||||
const part = nearestPart(cell, pose.position);
|
||||
bounds = cellBounds(part);
|
||||
range = Math.min(halfway(bounds), fitRange(part, bounds));
|
||||
}
|
||||
camera.flyToBounds(bounds, {
|
||||
offset: { heading: 0, pitch: -Math.PI / 2, range },
|
||||
durationS: 1.2,
|
||||
easing: 'cubicInOut',
|
||||
});
|
||||
}
|
||||
|
||||
function focusCamera(cameraId, duration = 2.2) {
|
||||
return focusCctvRecord(
|
||||
layerState._viewer,
|
||||
@@ -195,6 +273,7 @@ export function createNavigation({
|
||||
openingCameraId,
|
||||
reopenNearestCamera,
|
||||
focusCctvRecord,
|
||||
zoomToCell,
|
||||
focusCamera,
|
||||
maybeAutoHop,
|
||||
cctvCycleIndex,
|
||||
|
||||
Reference in new issue
Block a user