Files
gods-eye-view/src/layers/satellites/interaction.js
T
Itallo BrandãoandClaude Opus 5.5 c737a354c4 Merge upstream main into feat/iss-3d-model
Main's renderer seam (#1760) keeps Cesium inside src/render/cesium/, so the
ISS model now draws through the renderer contract:

- issModel.js draws the station as an item of a draw-port `models` set
  (url, position, heading/pitch/roll from its flight axes, scale, minimum
  pixel size, display range), hands the near range over through the dots'
  `displayRange`, and reads the eye from the camera port.
- issArticulation.js computes each joint's matrix as plain numbers and the
  Sun from geo/celestial, and hands them over by node name.
- The contract's ModelItem gains `nodes`: transforms of a model's named
  glTF nodes, which the Cesium port writes once the model is ready and
  again only when they change; a dropped name gets its authored pose back.
- issCommand.js asks the frame port for frames and zooms by shortening the
  camera port's follow offset.
- A click on the model is told by its draw hit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-16 04:34:13 -03:00

98 lines
3.6 KiB
JavaScript

import { inputFor } from '../../input/dispatcher.js';
import { onFollowChanged } from '../../data/followed.js';
import { ISS_NORAD } from './policy.js';
export function createInteraction({
state: layerState,
services,
parts,
source,
}) {
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
function _onKeyDown(e) {
// The Cockpit owns Escape while it rides the tracked satellite.
if (parts.cockpit?._cockpitHeld()) return;
if (layerState._enabled && e.key === 'Escape' && layerState._trackedNorad) {
parts.tracking._cancelPendingTrackingRestore();
parts.tracking._clearTracking(false, { origin: 'user' });
}
}
function _installClickHandler(viewer) {
if (layerState._clickSubscription) return; // already installed
// Cross-layer untrack (H2, mirror of flights): if ANOTHER layer (flights,
// military, …) grabs the follow-camera, drop our tracking so the orbit ring /
// tracked dot don't orphan — without touching viewer.trackedEntity (the
// new owner controls it). Guarded so our OWN switch (viewer.trackedEntity
// briefly undefined mid-_trackSatellite) doesn't self-clear.
if (!layerState._trackedEntityChangedRemove) {
layerState._trackedEntityChangedRemove = onFollowChanged(
viewer,
(followed) => {
if (!layerState._enabled) return;
if (
layerState._trackedNorad &&
layerState._viewer &&
followed &&
followed !== layerState._followTarget
) {
parts.tracking._clearTracking(true, {
origin: followed.selectionOrigin || 'programmatic',
});
}
},
);
}
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
if (!layerState._enabled) return;
// The Cockpit camera rides the tracked satellite: a click on the
// picture below must not untrack it or switch satellites.
if (parts.cockpit?._cockpitHeld()) return;
const picked = event.topHit;
const hit = event.drawHit;
// Clicking the tracked satellite's own dot — ignore
if (parts.rendering._hitIsTracked(hit)) return;
// A click on the ISS's 3D model: it tracks the ISS, as its dot does,
// and is ignored while the ISS is tracked already.
if (parts.issModel?._hitIsIss?.(hit)) {
if (layerState._trackedNorad === ISS_NORAD) return;
if (layerState._catalog.has(ISS_NORAD)) {
parts.tracking._cancelPendingTrackingRestore();
parts.tracking._trackSatellite(ISS_NORAD, { origin: 'user' });
return;
}
}
// A satellite dot (its item id is the NORAD catalog number)
const noradId = parts.rendering._hitPointId(hit);
if (noradId !== null && layerState._catalog.has(noradId)) {
parts.tracking._cancelPendingTrackingRestore();
parts.tracking._trackSatellite(noradId, { origin: 'user' });
return;
}
// A pick that belongs to a sibling layer (plane, vessel, station, CCTV
// camera…) is not "empty space" — leave OUR tracking (and crucially
// viewer.trackedEntity, which that sibling may have JUST set) alone (H2).
if (picked) {
const pickedId = resolvePickId(picked);
if (pickedId && isOwnedByOtherLayer('satellites', pickedId)) return;
}
// Clicked empty space — deselect
if (layerState._trackedNorad) {
parts.tracking._cancelPendingTrackingRestore();
parts.tracking._clearTracking(false, { origin: 'user' });
}
});
document.addEventListener('keydown', _onKeyDown);
}
return { _onKeyDown, _installClickHandler };
}