Open the cockpit on a tracked Navara aircraft

This commit is contained in:
German Khokhlov committed 2026-11-02 22:04:23 +04:00
1 parent 8b179a7e01
commit 2087b55b47
19 files changed
+142 -65

No files matched your search

+1
View File
@@ -371,6 +371,7 @@ export class StyleManager extends ShellFacade {
this._recording.hud = this.hud;
this._cockpitCoordinator = new CockpitCoordinator({
viewer,
engine,
services: {
flightsLayer: services.flightsLayer,
militaryFlightsLayer: services.militaryFlightsLayer,
+6 -6
View File
@@ -45,7 +45,7 @@ export function update() {
if (
!info ||
!this.trackedEntity ||
!this.viewer.entities.contains(this.trackedEntity)
!this.host.contains(this.trackedEntity)
) {
if (nowMs < this.contextNavigationDeadlineMs) return;
this.exit({ restoreTracking: false });
@@ -61,8 +61,8 @@ export function update() {
return;
this.lastCameraUpdateMs = nowMs;
const target = this.trackedEntity.position.getValue(
this.viewer.clock.currentTime,
const target = this.host.position(
this.trackedEntity,
this.scratchTarget,
);
if (!target) return;
@@ -182,8 +182,8 @@ export function update() {
)
) {
this.lastGroundProbeMs = nowMs;
const viewerCartographic = this.viewer.camera.positionCartographic;
this.services.sampleMeshFloorCells(this.viewer.scene, groundPoint, {
const viewerCartographic = this.host.cartographic();
this.services.sampleMeshFloorCells(this.host.surface, groundPoint, {
excludeObjects: [this.trackedEntity],
viewerLat: geo.math.toDegrees(viewerCartographic.latitude),
viewerLon: geo.math.toDegrees(viewerCartographic.longitude),
@@ -345,7 +345,7 @@ export function update() {
}
}
this.viewer.camera.setView({
this.host.camera.setView({
destination: this.scratchCamera,
orientation: { direction: this.scratchForward, up: this.scratchUp },
});
+6 -3
View File
@@ -63,11 +63,14 @@ import {
import { onKeyDown } from './cockpitInput.js';
import * as geo from '../geo/index.js';
import { cockpitHost } from './cockpitHost.js';
export class CockpitViewController {
constructor(
viewer,
{
services,
engine = null,
onVisionChange = null,
getInitialVisionMode = null,
onCameraTakeover = null,
@@ -79,7 +82,7 @@ export class CockpitViewController {
publish = {},
} = {},
) {
this.viewer = viewer;
this.host = cockpitHost(viewer, engine);
this.services = services;
this.destroyed = false;
this.disposed = false;
@@ -198,8 +201,8 @@ export class CockpitViewController {
// from preRender makes 3D Tiles discover a new view after traversal and can
// create a self-sustaining refinement loop under a moving cockpit camera.
this._listenerRemovers.push(
viewer.scene.preUpdate.addEventListener(() => this.update()),
viewer.trackedEntityChanged.addEventListener(() => {
this.host.preUpdate.addEventListener(() => this.update()),
this.host.followChanged.addEventListener(() => {
if (this.active) this._adoptTrackedEntity(performance.now());
else this.syncEntry();
}),
+9 -6
View File
@@ -9,6 +9,7 @@ import { cockpitVisionModeForStyle } from '../cockpitVisionPolicy.js';
export class CockpitCoordinator {
constructor({
viewer,
engine,
services,
elements,
operations,
@@ -23,6 +24,7 @@ export class CockpitCoordinator {
this,
{
viewer,
engine,
services,
readDataManager,
readContext,
@@ -35,10 +37,7 @@ export class CockpitCoordinator {
operations,
);
this._cockpitDisplayPortal = null;
// The cockpit flies the Cesium camera after tracked aircraft; without a
// viewer (the Navara engine) there is no cockpit and controlCockpit
// reports it unavailable.
this.cockpitView = viewer
this.cockpitView = viewer || engine?.kind === 'navara'
? this._createCockpitView(viewer, services)
: null;
}
@@ -62,6 +61,7 @@ export class CockpitCoordinator {
weatherCodeLabel,
} = services;
return new CockpitViewController(viewer, {
engine: this.engine,
services: {
flightsLayer,
militaryFlightsLayer,
@@ -88,6 +88,7 @@ export class CockpitCoordinator {
this._stampNavigation({ cancelPendingSelection: false }),
isEntryAllowed: () =>
cockpitEntryAllowed({
standaloneAircraft: this.engine?.kind === 'navara',
contextMode: this._contextMode,
contextModeChanging: this._contextModeChanging,
flightsEnabled: !!this._dataManager?.isEnabled('flights'),
@@ -136,7 +137,7 @@ export class CockpitCoordinator {
// (including the voice model) read that as a broken half-entered state.
const entryAllowed =
!active &&
Boolean(gateOpen && info && this.viewer?.trackedEntity?.position);
Boolean(gateOpen && info && this.cockpitView?.host.current());
return {
active,
entryAllowed,
@@ -278,7 +279,9 @@ export class CockpitCoordinator {
action: 'control_cockpit',
error: this._contextModeChanging
? 'Contacts is still starting up — try Cockpit again in a moment'
: 'Contacts must be active to enter Cockpit — say "open contacts" first',
: this.engine?.kind === 'navara'
? 'Enable an aircraft layer and track a flight to enter Cockpit'
: 'Contacts must be active to enter Cockpit — say "open contacts" first',
state: this.getCockpitState(),
};
}
+46
View File
@@ -0,0 +1,46 @@
// Camera and aircraft ownership used by the shared first-person controller.
export function cockpitHost(viewer, engine) {
if (viewer) {
return {
preUpdate: viewer.scene.preUpdate,
followChanged: viewer.trackedEntityChanged,
followed: () => viewer.trackedEntity,
current: () =>
viewer.trackedEntity?.position ? viewer.trackedEntity : null,
contains: (entity) => viewer.entities.contains(entity),
position: (entity, result) =>
entity.position.getValue(viewer.clock.currentTime, result),
release: () => {
viewer.trackedEntity = undefined;
},
restore: (entity, refocus) => {
viewer.trackedEntity = entity;
refocus(entity);
},
camera: viewer.camera,
cartographic: () => viewer.camera.positionCartographic,
surface: viewer.scene,
inputs: (enabled) => {
viewer.scene.screenSpaceCameraController.enableInputs = enabled;
},
};
}
const aircraft = () => {
const target = engine.camera.following()?.native;
return target?.resumeAircraftFollow ? target : null;
};
return {
preUpdate: engine.frames.preUpdate,
followChanged: engine.camera.followChanged,
followed: aircraft,
current: aircraft,
contains: (target) => target.live,
position: (target) => target.spec.position(),
release: () => engine.camera.following()?.stop(),
restore: (target) => target.resumeAircraftFollow(),
camera: engine.camera,
cartographic: () => engine.camera.pose().cartographic,
surface: engine,
inputs: (enabled) => engine.input.setCameraInputs(enabled),
};
}
+1 -1
View File
@@ -49,7 +49,7 @@ export function onKeyDown(event) {
if (key === 'c' && !event.metaKey && !event.ctrlKey && !event.altKey) {
if (!this.active) {
const cockpitAttempt = !!(
this.readAircraftInfo() && this.viewer.trackedEntity?.position
this.readAircraftInfo() && this.host.current()
);
if (!cockpitAttempt) return;
}
+15 -16
View File
@@ -9,7 +9,7 @@ import {
export function readAircraftInfo() {
// In cockpit mode the controller takes the entity off `viewer.trackedEntity`
// (see update()), so the cockpit's own handle is the tracked identity there.
const trackedEntity = this.viewer?.trackedEntity || this.trackedEntity;
const trackedEntity = this.host.followed() || this.trackedEntity;
return resolveTrackedAircraftInfo({
civilian: this.services.flightsLayer.getTrackedInfo?.() || null,
military: this.services.militaryFlightsLayer.getTrackedInfo?.() || null,
@@ -77,7 +77,7 @@ export function syncEntry() {
if (this.destroyed) return false;
if (this.active) return;
const info = this.readAircraftInfo();
const trackedContact = !!(info && this.viewer.trackedEntity?.position);
const trackedContact = !!(info && this.host.current());
this.syncTr3bToggle(trackedContact ? info : null);
const available = !!(this.isEntryAllowed() && trackedContact);
// Change-only publishes: this runs on a preUpdate cadence, and a fresh
@@ -108,22 +108,22 @@ export function navigateContext(direction, options = {}) {
}
export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
const nextEntity = this.viewer.trackedEntity;
const nextEntity = this.host.current();
if (
!this.active ||
!nextEntity?.position ||
!nextEntity ||
nextEntity === this.trackedEntity
)
return false;
const info = suppliedInfo || this.readAircraftInfo();
if (!info) return false;
if (this.trackedEntity && this.viewer.entities.contains(this.trackedEntity)) {
if (this.trackedEntity && this.host.contains(this.trackedEntity)) {
this.trackedEntity.show = this.trackedEntityWasShown;
}
this.trackedEntity = nextEntity;
this.trackedEntityWasShown = nextEntity.show;
nextEntity.show = false;
this.viewer.trackedEntity = undefined;
this.host.release();
this.cockpitAnchorValid = false;
this.heading = normalizeHeading(info.track ?? 0);
this.lastFrameMs = nowMs;
@@ -140,15 +140,15 @@ export function enter() {
if (this.active) return false;
if (!this.isEntryAllowed()) return false;
const info = this.readAircraftInfo();
const entity = this.viewer.trackedEntity;
if (!info || !entity?.position) return false;
const entity = this.host.current();
if (!info || !entity) return false;
this.entryFocusOrigin =
document.activeElement instanceof HTMLElement
? document.activeElement
: null;
// Retire deferred navigation before cancelFlight can run its callbacks.
this.onCameraTakeover?.();
this.viewer.camera.cancelFlight();
this.host.camera.cancelFlight();
this.trackedEntity = entity;
this.trackedEntityWasShown = entity.show;
entity.show = false;
@@ -169,8 +169,8 @@ export function enter() {
// runs on rendered frames, so idle mode would freeze the cockpit solid.
// (perf wave 2)
this.services.holdContinuousRender('cockpit');
this.viewer.trackedEntity = undefined;
this.viewer.scene.screenSpaceCameraController.enableInputs = false;
this.host.release();
this.host.inputs(false);
document.body.classList.add('cockpit-mode');
// Activation hides the entry and TR-3B chip; clearing the chip's signature
// lets the exit-path syncEntry publish it again.
@@ -237,14 +237,13 @@ export function exit({ restoreTracking = true } = {}) {
this.routeView.visible = false;
this.clearPredictiveRoute();
this.setVisionMode('optical');
this.viewer.scene.screenSpaceCameraController.enableInputs = true;
if (entity && this.viewer.entities.contains(entity))
this.host.inputs(true);
if (entity && this.host.contains(entity))
entity.show = this.trackedEntityWasShown;
this.trackedEntityWasShown = true;
this.dispatchCockpitModeChanged(false);
if (restoreTracking && entity && this.viewer.entities.contains(entity)) {
this.viewer.trackedEntity = entity;
this.restoreTrackingFrame(entity);
if (restoreTracking && entity && this.host.contains(entity)) {
this.host.restore(entity, this.restoreTrackingFrame);
}
this.syncEntry();
const restoreTarget =
+1 -10
View File
@@ -1,7 +1,6 @@
import { t, translateKnown } from '../i18n/index.js';
import {
SPACE_MISSIONS_LAYER_BLOCK_REASON,
cockpitEntryAllowed,
isExplicitUserIntentOrigin,
parseContextLayerBlockReason,
recordContextRestoreExplicitChange,
@@ -245,15 +244,7 @@ export function _handleContextLayerChange(change) {
);
}
}
if (
this.cockpitView?.active &&
!cockpitEntryAllowed({
contextMode: this._contextMode,
contextModeChanging: this._contextModeChanging,
flightsEnabled: !!this._dataManager?.isEnabled('flights'),
militaryEnabled: !!this._dataManager?.isEnabled('military'),
})
) {
if (this.cockpitView?.active && !this.cockpitView.isEntryAllowed()) {
this.cockpitView.exit({ restoreTracking: false });
}
this._syncContextModeButtons();
+6 -4
View File
@@ -55,10 +55,12 @@ const sceneRuntime = computed(() => scenePanel.value?.runtime ?? '');
</div>
<section id="context-flights-view" class="context-mode-view" role="tabpanel" aria-labelledby="global-context-flights-btn" :hidden="!ctx?.flightsActive">
<div class="global-context-actions" :aria-label="t('Contact Context actions')">
<button id="cockpit-entry" type="button" :hidden="!cockpit?.entryAvailable">
<span class="material-symbols-outlined" aria-hidden="true">flight</span>
<span>{{ t('COCKPIT') }}</span>
</button>
<Teleport to="body" :disabled="!cockpit?.entryAvailable || ctx?.flightsActive">
<button id="cockpit-entry" type="button" :hidden="!cockpit?.entryAvailable">
<span class="material-symbols-outlined" aria-hidden="true">flight</span>
<span>{{ t('COCKPIT') }}</span>
</button>
</Teleport>
<button id="installations-search-btn" class="panel-layer-toggle" type="button" :aria-disabled="ctx && String(ctx.installationsBusy)" :aria-busy="ctx && String(ctx.installationsBusy)">{{ t('SEARCH NEARBY SITES') }}</button>
<UiButton id="tr3b-toggle" class="tr3b-toggle" :pressed="!!cockpit?.tr3b?.converted" :hidden="!cockpit?.tr3b" :aria-label="t('Reclassify tracked contact as TR-3B')" :title="cockpit?.tr3b?.converted ? t('Restore real aircraft') : t('Reclassify as TR-3B')">🛸</UiButton>
</div>