astraeus 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/README.md +28 -15
- package/package.json +1 -1
- package/src/api/AstraeusScene.d.ts +1 -1
- package/src/api/AstraeusScene.js +4 -1
- package/src/api/AstraeusScene.node.js +4 -1
- package/src/api/assembleScene.d.ts +2 -0
- package/src/api/assembleScene.js +27 -5
- package/src/api/cameraRequest.d.ts +15 -0
- package/src/api/cameraRequest.js +89 -0
- package/src/api/errors.d.ts +9 -1
- package/src/api/index.d.ts +6 -3
- package/src/api/look.d.ts +49 -0
- package/src/api/lookInput.d.ts +1 -1
- package/src/api/lookInput.js +6 -1
- package/src/api/planCamera.d.ts +35 -7
- package/src/api/planCamera.js +94 -11
- package/src/api/planSkyFigures.d.ts +22 -0
- package/src/api/planSkyFigures.js +145 -0
- package/src/api/planStory.d.ts +2 -2
- package/src/api/planStory.js +14 -9
- package/src/api/planViews.js +1 -1
- package/src/api/scene.d.ts +17 -4
- package/src/api/scene.js +23 -5
- package/src/api/sceneReads.d.ts +21 -2
- package/src/api/skyFigureInput.d.ts +45 -0
- package/src/api/skyFigureInput.js +1 -0
- package/src/api/skyTraceInput.d.ts +33 -0
- package/src/api/skyTraceInput.js +45 -0
- package/src/api/story.d.ts +12 -3
- package/src/api/story.js +44 -1
- package/src/api/viewerCamera.d.ts +4 -3
- package/src/api/viewerCamera.js +10 -32
- package/src/api/viewerHandle.d.ts +27 -4
- package/src/api/viewerHandle.js +6 -0
- package/src/api/viewerLink.d.ts +49 -4
- package/src/api/viewerLink.js +25 -0
- package/src/api/viewerPanels.d.ts +26 -0
- package/src/api/viewerPanels.js +42 -0
- package/src/api/viewerSelection.d.ts +1 -1
- package/src/api/viewerSelection.js +3 -3
- package/src/app/App.js +100 -18
- package/src/app/App.node.js +100 -18
- package/src/app/AstraeusScene.d.ts +20 -5
- package/src/app/AstraeusScene.js +3 -3
- package/src/app/CameraController.d.ts +17 -0
- package/src/app/CameraController.js +34 -9
- package/src/app/DeveloperSettings.d.ts +11 -3
- package/src/app/DeveloperSettings.js +13 -3
- package/src/app/SceneLabels.d.ts +20 -2
- package/src/app/SceneLabels.js +46 -6
- package/src/app/SkyFiguresView.d.ts +56 -0
- package/src/app/SkyFiguresView.js +242 -0
- package/src/app/StoryMarkers.d.ts +2 -2
- package/src/app/StoryMarkers.js +2 -2
- package/src/app/displaySwitches.d.ts +13 -3
- package/src/app/displaySwitches.js +17 -3
- package/src/app/experienceDefinition.d.ts +9 -3
- package/src/app/experienceDefinition.js +4 -2
- package/src/app/labelStyle.d.ts +17 -0
- package/src/app/labelStyle.js +13 -0
- package/src/app/liveLook.js +8 -0
- package/src/app/look.d.ts +9 -5
- package/src/app/look.js +11 -0
- package/src/app/lookOut.d.ts +32 -0
- package/src/app/lookOut.js +50 -0
- package/src/app/sceneCamera.d.ts +5 -3
- package/src/app/sceneCamera.js +66 -3
- package/src/app/sceneContentsHooks.d.ts +2 -1
- package/src/app/sceneContentsHooks.js +3 -2
- package/src/app/sceneFrame.d.ts +10 -1
- package/src/app/sceneFrame.js +45 -10
- package/src/app/sceneFraming.d.ts +7 -0
- package/src/app/sceneFraming.js +12 -0
- package/src/app/sceneHooks.d.ts +2 -0
- package/src/app/sceneHooks.js +4 -1
- package/src/app/scenePicking.d.ts +20 -0
- package/src/app/scenePicking.js +49 -0
- package/src/app/scenePointer.d.ts +3 -1
- package/src/app/scenePointer.js +3 -2
- package/src/app/skyFigures.d.ts +73 -0
- package/src/app/skyFigures.js +50 -0
- package/src/app/style.css +2 -1
- package/src/app/viewHiding.d.ts +2 -0
- package/src/app/viewHiding.js +7 -1
- package/src/app/viewLink.d.ts +8 -8
- package/src/app/viewLink.js +24 -4
- package/src/app/viewerPort.d.ts +30 -3
- package/src/assets/sky.d.ts +13 -4
- package/src/assets/sky.js +33 -8
- package/src/assets/stars/hyg-v42-naked-eye.json +1 -1
- package/src/core/bodies/moonSystem.js +1 -15
- package/src/core/lookValues.d.ts +9 -0
- package/src/core/lookValues.js +24 -0
- package/src/core/readBytes.d.ts +1 -0
- package/src/core/readBytes.js +15 -0
- package/src/core/skyTrace.d.ts +49 -0
- package/src/core/skyTrace.js +39 -0
- package/src/core/startView.d.ts +39 -0
- package/src/core/startView.js +56 -0
- package/src/core/storyPanels.d.ts +51 -3
- package/src/core/storyPanels.js +52 -12
- package/src/shell/AstraeusShell.d.ts +15 -6
- package/src/shell/AstraeusShell.js +76 -20
- package/src/shell/AstraeusShell.node.js +76 -20
- package/src/shell/ObjectControls.js +11 -8
- package/src/shell/StoryPanelView.d.ts +12 -3
- package/src/shell/StoryPanelView.js +2 -2
- package/src/shell/experience.d.ts +24 -0
- package/src/shell/experience.js +4 -1
- package/src/shell/infoModel.js +9 -1
- package/src/shell/objectModel.d.ts +6 -2
- package/src/shell/objectModel.js +10 -1
- package/src/shell/phone.css +1 -1
- package/src/shell/storyPanels.d.ts +1 -1
- package/src/shell/storyPanels.js +1 -1
- package/src/shell/style.css +9 -1
- package/src/shell/topBarIcons.d.ts +1 -0
- package/src/shell/topBarIcons.js +1 -0
- package/src/shell/useStoryPanels.d.ts +9 -6
- package/src/shell/useStoryPanels.js +10 -6
package/src/app/sceneCamera.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { BodyCatalogue } from "../assets/catalogue.js";
|
|
2
2
|
import type { BodyId } from "../core/body.js";
|
|
3
|
-
import { type CameraRequest, type OrbitCameraState } from "./CameraController.js";
|
|
3
|
+
import { type CameraRequest, type LookOutRequest, type OrbitCameraState } from "./CameraController.js";
|
|
4
4
|
import type { CameraReach } from "./experienceDefinition.js";
|
|
5
5
|
import type { RenderVector } from "./renderCoordinates.js";
|
|
6
6
|
import { type SceneFrame } from "./sceneFraming.js";
|
|
7
7
|
import { type SceneTargets } from "./sceneTargets.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type CameraView } from "../core/startView.js";
|
|
9
|
+
/** What the scene opens on: a view in numbers, or a look-out request whose direction is an id, resolved on the first frame as a `setCamera` look-out is (the figure aim already applied, `aimAtFigure`). */
|
|
10
|
+
export type OpeningView = CameraView | LookOutRequest;
|
|
9
11
|
/** The two control fields the camera step reads and clears. */
|
|
10
12
|
export interface CameraControls {
|
|
11
|
-
startView?:
|
|
13
|
+
startView?: OpeningView;
|
|
12
14
|
cameraRequest: CameraRequest | null;
|
|
13
15
|
/** The host's last `setCamera`, kept apart from `cameraRequest` so the opening view and a view's own camera rule cannot discard it (the host-call order rule). */
|
|
14
16
|
hostCameraRequest?: CameraRequest | null;
|
package/src/app/sceneCamera.js
CHANGED
|
@@ -2,7 +2,10 @@ import { clampDistance, switchFocus, } from "./CameraController.js";
|
|
|
2
2
|
import { PathView, pathReachKm } from "./PathView.js";
|
|
3
3
|
import { defaultDistance, fitDistance, focusLimits, GROUP_FRAMING, scaleLength, startsInsideFocus, TRACKED_DEFAULT_DISTANCE, } from "./sceneFraming.js";
|
|
4
4
|
import { canFocus, focusAbsoluteOf, framedViewOf } from "./sceneTargets.js";
|
|
5
|
+
import { clampFov, clampLookElevation, LOOK_OUT_OPENING_FOV_DEG } from "./lookOut.js";
|
|
6
|
+
import { eqjToRenderVector } from "./renderCoordinates.js";
|
|
5
7
|
import { orbitAnglesFor, orbitBasis } from "./viewUp.js";
|
|
8
|
+
import { eqjUnitVector, isSkyView } from "../core/startView.js";
|
|
6
9
|
/** Keeps the same relative framing when the visual scale changes (physical state is untouched). */
|
|
7
10
|
export function rescaleCameraForPolicy(camState, sceneCenter, factor) {
|
|
8
11
|
if (camState.focus === sceneCenter)
|
|
@@ -33,8 +36,13 @@ function applyStartView(camState, view) {
|
|
|
33
36
|
function openFirstFrame(input) {
|
|
34
37
|
const { camState, controls, targets, frame, reach } = input;
|
|
35
38
|
const view = controls.startView;
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
// A sky view opens through the same look-out step as a request does.
|
|
40
|
+
const opening = view === undefined || "kind" in view || !isSkyView(view) ? view : { kind: "lookOut", body: view.lookOut, direction: eqjUnitVector(view.raDeg, view.decDeg), fovDeg: view.fovDeg };
|
|
41
|
+
if (opening !== undefined && canFocus(targets, "kind" in opening ? opening.body : opening.focus)) {
|
|
42
|
+
if ("kind" in opening)
|
|
43
|
+
applyLookOut(input, opening);
|
|
44
|
+
else
|
|
45
|
+
applyStartView(camState, opening);
|
|
38
46
|
// The opening view replaces any request made before the first frame, except the host's: that one is applied after it.
|
|
39
47
|
controls.cameraRequest = controls.hostCameraRequest ?? null;
|
|
40
48
|
return false;
|
|
@@ -72,8 +80,61 @@ function faceParent(camState, targets, viewUp, body, parent) {
|
|
|
72
80
|
camState.targetElevation = Math.asin(along(viewUp) / distance);
|
|
73
81
|
camState.targetAzimuth = Math.atan2(along(east), along(south));
|
|
74
82
|
}
|
|
83
|
+
/** The render-frame direction a look-out request names: an EQJ vector, or the way from the body to the object to turn toward. Null when it names no direction. */
|
|
84
|
+
function lookDirectionOf(input, request) {
|
|
85
|
+
const { targets } = input;
|
|
86
|
+
let direction;
|
|
87
|
+
if (request.direction === undefined) {
|
|
88
|
+
direction = eqjToRenderVector([1, 0, 0]);
|
|
89
|
+
}
|
|
90
|
+
else if (typeof request.direction === "string") {
|
|
91
|
+
if (!canFocus(targets, request.direction))
|
|
92
|
+
return null;
|
|
93
|
+
const from = focusAbsoluteOf(targets, request.body);
|
|
94
|
+
const to = focusAbsoluteOf(targets, request.direction);
|
|
95
|
+
direction = [to[0] - from[0], to[1] - from[1], to[2] - from[2]];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
direction = eqjToRenderVector(request.direction);
|
|
99
|
+
}
|
|
100
|
+
return direction.every(Number.isFinite) && Math.hypot(...direction) > 0 ? direction : null;
|
|
101
|
+
}
|
|
102
|
+
/** Stands the camera at the body's centre looking along the requested direction; nothing happens for a body or direction it cannot resolve. */
|
|
103
|
+
function applyLookOut(input, request) {
|
|
104
|
+
const { camState, targets, viewUp } = input;
|
|
105
|
+
if (!canFocus(targets, request.body))
|
|
106
|
+
return;
|
|
107
|
+
// No direction: keep the one already looked along while looking out, else right ascension 0, declination 0.
|
|
108
|
+
const keep = request.direction === undefined && camState.lookOut !== null;
|
|
109
|
+
const direction = lookDirectionOf(input, request);
|
|
110
|
+
const angles = direction === null ? null : orbitAnglesFor(direction, viewUp);
|
|
111
|
+
if (angles === null && !keep)
|
|
112
|
+
return;
|
|
113
|
+
camState.focus = request.body;
|
|
114
|
+
camState.fixedPoint = null;
|
|
115
|
+
camState.transition.fill(0);
|
|
116
|
+
if (angles !== null && !keep) {
|
|
117
|
+
camState.azimuth = camState.targetAzimuth = angles.azimuth;
|
|
118
|
+
camState.elevation = camState.targetElevation = clampLookElevation(angles.elevation);
|
|
119
|
+
}
|
|
120
|
+
camState.lookOut = { fovDeg: clampFov(request.fovDeg ?? camState.lookOut?.fovDeg ?? LOOK_OUT_OPENING_FOV_DEG) };
|
|
121
|
+
}
|
|
122
|
+
/** Back to the orbit camera: the target tween starts from where the camera stood, not from the aiming point one unit out. */
|
|
123
|
+
function leaveLookOut(camState) {
|
|
124
|
+
if (camState.lookOut === null)
|
|
125
|
+
return;
|
|
126
|
+
camState.lookOut = null;
|
|
127
|
+
for (let i = 0; i < 3; i += 1)
|
|
128
|
+
camState.targetAbsolute[i] = camState.cameraAbsolute[i];
|
|
129
|
+
}
|
|
75
130
|
function applyCameraRequest(input, request) {
|
|
76
131
|
const { camState, targets, frame, catalogue, viewUp } = input;
|
|
132
|
+
if (request.kind === "lookOut")
|
|
133
|
+
return applyLookOut(input, request);
|
|
134
|
+
// A hold would keep the aiming point as a place; looking out already holds the camera where it stands.
|
|
135
|
+
if (request.kind === "hold" && camState.lookOut !== null)
|
|
136
|
+
return;
|
|
137
|
+
leaveLookOut(camState);
|
|
77
138
|
if (request.kind === "hold") {
|
|
78
139
|
// The target stops where it is (including any tween still running); angles and distance are untouched. Scene-frame state only: nothing in State changes.
|
|
79
140
|
const now = cameraTargetAbsolute(camState, targets);
|
|
@@ -104,7 +165,9 @@ function applyCameraRequest(input, request) {
|
|
|
104
165
|
function keepViewOnUpChange(camState, previousUp, viewUp) {
|
|
105
166
|
if (previousUp === null || !previousUp.some((v, k) => v !== viewUp[k]))
|
|
106
167
|
return;
|
|
107
|
-
|
|
168
|
+
// Orbiting, the angles are of the camera's offset from its target; looking out, of the way it looks (the target is a unit ahead).
|
|
169
|
+
const side = camState.lookOut === null ? 1 : -1;
|
|
170
|
+
const offset = [0, 1, 2].map((k) => side * (camState.cameraAbsolute[k] - camState.targetAbsolute[k]));
|
|
108
171
|
const angles = orbitAnglesFor(offset, viewUp);
|
|
109
172
|
if (angles === null)
|
|
110
173
|
return;
|
|
@@ -9,6 +9,7 @@ import type { BodyRefs } from "./sceneBodies.js";
|
|
|
9
9
|
import { type FrameLayers, type FrameState } from "./sceneFrame.js";
|
|
10
10
|
import { type useSceneViews } from "./sceneHooks.js";
|
|
11
11
|
import { type ScenePlacement } from "./sceneLayout.js";
|
|
12
|
+
import type { SkyLabelSpec } from "./SkyFiguresView.js";
|
|
12
13
|
import type { BodySetView } from "./BodySetView.js";
|
|
13
14
|
import { type TrackedBodyView } from "./TrackedBodyView.js";
|
|
14
15
|
/** The catalogued body a focus or label id names: the Sun's shell item stands for the Sun body. */
|
|
@@ -48,7 +49,7 @@ export declare function useSceneDerived(runtime: SceneRuntime, catalogue: BodyCa
|
|
|
48
49
|
}[];
|
|
49
50
|
};
|
|
50
51
|
/** Mounts every DOM layer the frame updates (names, anchor labels, story and feature markers) and returns the refs the frame reads. */
|
|
51
|
-
export declare function useOverlayLayers(canvas: HTMLCanvasElement, controls: SceneControls, trackedViews: readonly TrackedBodyView[], bodySetViews: readonly BodySetView[]): FrameLayers;
|
|
52
|
+
export declare function useOverlayLayers(canvas: HTMLCanvasElement, controls: SceneControls, trackedViews: readonly TrackedBodyView[], bodySetViews: readonly BodySetView[], skyLabels?: readonly SkyLabelSpec[]): FrameLayers;
|
|
52
53
|
/** Wires the canvas's orbit gestures, hover and tap picking to the camera and frame state. */
|
|
53
54
|
export declare function useScenePointer(canvas: HTMLCanvasElement, runtime: SceneRuntime, controls: SceneControls, catalogue: BodyCatalogue, orbit: {
|
|
54
55
|
current: OrbitCameraState;
|
|
@@ -52,8 +52,9 @@ export function useSceneDerived(runtime, catalogue) {
|
|
|
52
52
|
const bodyFamilies = useMemo(() => (runtime.bodySets ?? []).flatMap((layer) => Object.entries(layer.bodyFamilies ?? {}).map(([body, family]) => ({ layer, body, family }))), [runtime.bodySets]);
|
|
53
53
|
return { placement, readoutPair, pairLabels, assets, bodyFamilies };
|
|
54
54
|
}
|
|
55
|
+
const NO_SKY_LABELS = [];
|
|
55
56
|
/** Mounts every DOM layer the frame updates (names, anchor labels, story and feature markers) and returns the refs the frame reads. */
|
|
56
|
-
export function useOverlayLayers(canvas, controls, trackedViews, bodySetViews) {
|
|
57
|
+
export function useOverlayLayers(canvas, controls, trackedViews, bodySetViews, skyLabels = NO_SKY_LABELS) {
|
|
57
58
|
const bodySetLabels = useRef([]);
|
|
58
59
|
const anchorLabels = useRef(null);
|
|
59
60
|
const sceneLabels = useRef(null);
|
|
@@ -69,7 +70,7 @@ export function useOverlayLayers(canvas, controls, trackedViews, bodySetViews) {
|
|
|
69
70
|
layer.dispose(); bodySetLabels.current = []; };
|
|
70
71
|
}, [canvas, bodySetViews, controls]);
|
|
71
72
|
useHostLayer(canvas, anchorLabels, (host) => new AnchorLabelLayer(host, trackedViews), [canvas, trackedViews]);
|
|
72
|
-
useHostLayer(canvas, sceneLabels, (host) => new SceneLabelLayer(host, controls.labelObjects), [canvas, controls.labelObjects]);
|
|
73
|
+
useHostLayer(canvas, sceneLabels, (host) => new SceneLabelLayer(host, controls.labelObjects, skyLabels), [canvas, controls.labelObjects, skyLabels]);
|
|
73
74
|
useHostLayer(canvas, storyMarkers, (host) => (controls.storyMarkers === undefined || controls.storyMarkers.length === 0 ? null : new StoryMarkerLayer(host, controls.storyMarkers, (panelId) => controls.onStoryMarker?.(panelId))), [canvas, controls]);
|
|
74
75
|
useHostLayer(canvas, featureMarkers, (host) => (controls.featureMarkers === undefined || controls.featureMarkers.length === 0 ? null : new FeatureMarkerLayer(host, controls.featureMarkers, (key) => controls.onFeatureMarker?.(key))), [canvas, controls]);
|
|
75
76
|
return { bodySetLabels, anchorLabels, sceneLabels, storyMarkers, featureMarkers };
|
package/src/app/sceneFrame.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ import type { SceneControls, SceneReadout, SceneRuntime } from "./AstraeusScene.
|
|
|
15
15
|
import { type BodyRefs } from "./sceneBodies.js";
|
|
16
16
|
import type { useSceneViews } from "./sceneHooks.js";
|
|
17
17
|
import { type PlacedComposition, type ScenePlacement } from "./sceneLayout.js";
|
|
18
|
-
import { type PickCandidate } from "./scenePicking.js";
|
|
18
|
+
import { type PickCandidate, type SkyPickFigure } from "./scenePicking.js";
|
|
19
19
|
import type { SceneLabelLayer } from "./SceneLabels.js";
|
|
20
20
|
import { type SceneTargets } from "./sceneTargets.js";
|
|
21
21
|
import type { StoryMarkerLayer } from "./StoryMarkers.js";
|
|
22
|
+
import { type ViewHidden } from "./viewHiding.js";
|
|
22
23
|
/** What survives from one frame to the next. The component owns one and hands it to every frame. */
|
|
23
24
|
export interface FrameState {
|
|
24
25
|
started: boolean;
|
|
@@ -35,6 +36,8 @@ export interface FrameState {
|
|
|
35
36
|
x: number;
|
|
36
37
|
y: number;
|
|
37
38
|
} | null;
|
|
39
|
+
/** The sky figures a tap can select (names and lines, screen px from the canvas); read by a tap only. */
|
|
40
|
+
skyFigures: () => readonly SkyPickFigure[];
|
|
38
41
|
/** Whether the renderer should draw this frame (`decideDraw`). True until the first frame has decided. */
|
|
39
42
|
drawThisFrame: boolean;
|
|
40
43
|
/** Frames the renderer has drawn since mount (`data-frames-drawn`). */
|
|
@@ -140,8 +143,14 @@ export declare function stepAndPoseCamera(ctx: FrameContext, t: number, placed:
|
|
|
140
143
|
export declare function publishOrbitHeadGap(canvas: HTMLCanvasElement, views: readonly PathView[], absoluteOf: (id: BodyId) => RenderVector, policy: ScalePolicy): void;
|
|
141
144
|
/** Stage 4: swaps small bodies for markers, publishes the scene's canvas readouts and updates the sky. */
|
|
142
145
|
export declare function publishCanvasReadouts(ctx: FrameContext): void;
|
|
146
|
+
/** Stage 4b: stands the sky figures, outlines and reference circles on the camera and shows the kinds the switches say. Looks only at the camera's orientation and the switches (ARCH-02). */
|
|
147
|
+
export declare function placeSkyFigures(ctx: FrameContext): void;
|
|
148
|
+
/** Stage 4c: starts the traces and removes the ones the host asked for since the last frame (in call order) and moves every trace on by this frame's real time; a moving trace wakes the draw rule. Wall time only (CODE-02, ARCH-02). */
|
|
149
|
+
export declare function advanceSkyTraces(ctx: FrameContext): void;
|
|
143
150
|
/** Stage 5: places every view about the floating origin and publishes the views' readouts. Returns the hover brightness gain. */
|
|
144
151
|
export declare function placeViews(ctx: FrameContext, t: number, placed: PlacedScene, setLook: BodySetLook): number;
|
|
152
|
+
/** What this frame hides: the view's hidden ids, and the body the camera stands inside while looking out (the one hidden-set path, read by the visibility, label and tap stages). */
|
|
153
|
+
export declare function hiddenOf(ctx: Pick<FrameContext, "controls" | "orbit">): ViewHidden | undefined;
|
|
145
154
|
/** Stage 5b: shows or hides each drawn group by the current view's hidden ids (bodies, paths, point groups, body sets). One set, read here; nothing is rebuilt. */
|
|
146
155
|
export declare function applyViewVisibility(ctx: FrameContext): void;
|
|
147
156
|
/** A mounted body's drawn sphere and radius for the feature markers, or null when the body is not drawn as a sphere. */
|
package/src/app/sceneFrame.js
CHANGED
|
@@ -6,7 +6,7 @@ import { DEFAULT_CAMERA_FAR } from "./experienceDefinition.js";
|
|
|
6
6
|
import { DEFAULT_FEATURE_MIN_BODY_PX } from "./FeatureMarkers.js";
|
|
7
7
|
import { cameraTargetAbsolute, rescaleCameraForPolicy, stepCameraTarget } from "./sceneCamera.js";
|
|
8
8
|
import { buildFrameReadout, publishBodyData, publishPathData, publishPointsData, publishSceneData, recordFrameStats } from "./sceneDebug.js";
|
|
9
|
-
import { focusRadius, liveReach } from "./sceneFraming.js";
|
|
9
|
+
import { CAMERA_FOV_DEG, focusRadius, liveReach, lookOutFar } from "./sceneFraming.js";
|
|
10
10
|
import { bodyScreenReadouts, placeBodies, swapSmallBodiesToMarkers } from "./sceneBodies.js";
|
|
11
11
|
import { publishBodySets } from "./sceneBodySets.js";
|
|
12
12
|
import { bodyAbsolute, placeComposition } from "./sceneLayout.js";
|
|
@@ -14,13 +14,16 @@ import { placeBodyLights } from "./sceneLights.js";
|
|
|
14
14
|
import { clampHoverBrightness, HOVER_BRIGHTNESS_DEFAULT, hoverTarget, pickCandidatesOf } from "./scenePicking.js";
|
|
15
15
|
import { updateSky } from "./sceneSky.js";
|
|
16
16
|
import { labelPositionOf } from "./sceneTargets.js";
|
|
17
|
+
import { skyViewOf } from "./lookOut.js";
|
|
18
|
+
import { hiddenWithLookOut } from "./viewHiding.js";
|
|
17
19
|
import { viewFromAngles } from "./viewLink.js";
|
|
18
20
|
import { EQUATORIAL_UP } from "./viewUp.js";
|
|
21
|
+
import { prefersReducedMotion } from "./skyFigures.js";
|
|
19
22
|
/** Floating-origin rebase threshold in scaled units (Earth radii). */
|
|
20
23
|
const REBASE_THRESHOLD = 1;
|
|
21
24
|
export function createFrameState(policyId, onFirstDraw) {
|
|
22
25
|
return {
|
|
23
|
-
started: false, onFirstDraw, spanScaled: 6, lastPolicyId: policyId, lastUp: null, pickables: [], hoverPoint: null,
|
|
26
|
+
started: false, onFirstDraw, spanScaled: 6, lastPolicyId: policyId, lastUp: null, pickables: [], hoverPoint: null, skyFigures: () => [],
|
|
24
27
|
drawThisFrame: true, framesDrawn: 0, wakes: 0,
|
|
25
28
|
drawn: { timeUtcMs: Number.NaN, pose: [], size: "", controls: new Map(), wakes: 0, mounted: -1, quietFrames: 0 },
|
|
26
29
|
};
|
|
@@ -100,16 +103,20 @@ export function stepAndPoseCamera(ctx, t, placed) {
|
|
|
100
103
|
const firstFrame = !state.started;
|
|
101
104
|
state.started = true;
|
|
102
105
|
const reach = liveReach(runtime.cameraReach, policy, camera.aspect);
|
|
103
|
-
const focusBody = stepCameraTarget({ camState: orbit, controls, targets, frame, catalogue, reach, fovDeg: camera.fov, viewUp, firstFrame, previousUp: state.lastUp });
|
|
106
|
+
const focusBody = stepCameraTarget({ camState: orbit, controls, targets, frame, catalogue, reach, fovDeg: orbit.lookOut === null ? camera.fov : CAMERA_FOV_DEG, viewUp, firstFrame, previousUp: state.lastUp });
|
|
104
107
|
state.lastUp = viewUp;
|
|
105
108
|
resolveCamera(orbit, cameraTargetAbsolute(orbit, targets), ctx.origin, ctx.delta, REBASE_THRESHOLD, viewUp);
|
|
106
109
|
placeBodies(ctx.assets, placed.composed.states, ctx.bodyRefs, policy, ctx.origin);
|
|
107
|
-
|
|
110
|
+
const baseFar = reach.far ?? DEFAULT_CAMERA_FAR;
|
|
111
|
+
// Looking out, the camera stands at a body, so a far plane sized for orbit framing could cut off the Sun or any body beyond it: reach everything placed.
|
|
112
|
+
const far = orbit.lookOut === null ? baseFar : lookOutFar(baseFar, orbit.cameraAbsolute, placed.composed.absolutes);
|
|
113
|
+
poseCamera(camera, orbit, focusRadius(focusBody, policy, catalogue), ctx.origin, far, viewUp);
|
|
108
114
|
if (firstFrame && state.onFirstDraw !== undefined) {
|
|
109
115
|
const told = state.onFirstDraw;
|
|
110
116
|
requestAnimationFrame(told);
|
|
111
117
|
}
|
|
112
|
-
|
|
118
|
+
// Looking out, the angles are the way the camera looks, not an offset from a target: a sky reading, never orbit values.
|
|
119
|
+
controls.viewReadout = orbit.lookOut === null ? viewFromAngles(orbit.focus, orbit.azimuth, orbit.elevation, orbit.distance) : skyViewOf(orbit.focus, orbit.azimuth, orbit.elevation, viewUp, orbit.lookOut.fovDeg);
|
|
113
120
|
return { targets };
|
|
114
121
|
}
|
|
115
122
|
/** Diagnostic for the browser checks: how far the first orbit arc's head is from its body's drawn position, as a share of the orbit's size (`data-orbit-head-gap`) and its longest segment as a share of the same (`data-orbit-arc-segment`). */
|
|
@@ -135,6 +142,26 @@ export function publishCanvasReadouts(ctx) {
|
|
|
135
142
|
updateSky(views.skyView, camera, canvas, controls, controls.frameStats !== null);
|
|
136
143
|
}
|
|
137
144
|
}
|
|
145
|
+
/** Stage 4b: stands the sky figures, outlines and reference circles on the camera and shows the kinds the switches say. Looks only at the camera's orientation and the switches (ARCH-02). */
|
|
146
|
+
export function placeSkyFigures(ctx) {
|
|
147
|
+
const { controls, camera, canvas, views } = ctx;
|
|
148
|
+
views.skyFiguresView.place(camera, controls.skyLines, controls.skyColours, controls.selectedObjectId);
|
|
149
|
+
canvas.dataset.skyLines = views.skyFiguresView.shown.join(",");
|
|
150
|
+
}
|
|
151
|
+
/** Stage 4c: starts the traces and removes the ones the host asked for since the last frame (in call order) and moves every trace on by this frame's real time; a moving trace wakes the draw rule. Wall time only (CODE-02, ARCH-02). */
|
|
152
|
+
export function advanceSkyTraces(ctx) {
|
|
153
|
+
const { controls, state, views, delta } = ctx;
|
|
154
|
+
for (const request of controls.skyTraces.splice(0)) {
|
|
155
|
+
if ("after" in request)
|
|
156
|
+
views.skyFiguresView.startTrace(request);
|
|
157
|
+
else
|
|
158
|
+
views.skyFiguresView.clearTrace(request);
|
|
159
|
+
}
|
|
160
|
+
if (views.skyFiguresView.advanceTraces(delta, controls.skyColours, controls.skyLines, controls.selectedObjectId))
|
|
161
|
+
state.wakes += 1;
|
|
162
|
+
if (views.skyFiguresView.advanceFadeIn(delta, prefersReducedMotion() ? 0 : controls.skyFadeInSeconds, controls.skyLines))
|
|
163
|
+
state.wakes += 1;
|
|
164
|
+
}
|
|
138
165
|
/** Stage 5: places every view about the floating origin and publishes the views' readouts. Returns the hover brightness gain. */
|
|
139
166
|
export function placeViews(ctx, t, placed, setLook) {
|
|
140
167
|
const { controls, camera, canvas, size, views, origin } = ctx;
|
|
@@ -161,9 +188,13 @@ export function placeViews(ctx, t, placed, setLook) {
|
|
|
161
188
|
publishPointsData(canvas, views.groupViews, camera, views.bodySetViews);
|
|
162
189
|
return hoverGain;
|
|
163
190
|
}
|
|
191
|
+
/** What this frame hides: the view's hidden ids, and the body the camera stands inside while looking out (the one hidden-set path, read by the visibility, label and tap stages). */
|
|
192
|
+
export function hiddenOf(ctx) {
|
|
193
|
+
return hiddenWithLookOut(ctx.controls.viewHidden, ctx.orbit.lookOut === null ? null : ctx.orbit.focus);
|
|
194
|
+
}
|
|
164
195
|
/** Stage 5b: shows or hides each drawn group by the current view's hidden ids (bodies, paths, point groups, body sets). One set, read here; nothing is rebuilt. */
|
|
165
196
|
export function applyViewVisibility(ctx) {
|
|
166
|
-
const hidden = ctx
|
|
197
|
+
const hidden = hiddenOf(ctx)?.objects;
|
|
167
198
|
const { views, bodyRefs } = ctx;
|
|
168
199
|
const show = (id, group) => { group.visible = hidden?.has(id) !== true; };
|
|
169
200
|
for (const [id, group] of bodyRefs.groups)
|
|
@@ -192,7 +223,7 @@ export function featureHostOf(assets, parts, id, policy) {
|
|
|
192
223
|
/** What the labels and taps see under the current view: the objects and body sets it shows, and the label-hidden ids with the view's own added. Allocates only when a view hides something. */
|
|
193
224
|
function shownUnderView(ctx) {
|
|
194
225
|
const { controls, views } = ctx;
|
|
195
|
-
const hidden =
|
|
226
|
+
const hidden = hiddenOf(ctx)?.objects;
|
|
196
227
|
if (hidden === undefined || hidden.size === 0)
|
|
197
228
|
return { objects: controls.labelObjects, bodySetViews: views.bodySetViews, hiddenLabels: controls.hiddenLabels };
|
|
198
229
|
return {
|
|
@@ -203,19 +234,21 @@ function shownUnderView(ctx) {
|
|
|
203
234
|
}
|
|
204
235
|
/** Stage 6: updates the overlay layers (names, story and feature markers) and rebuilds what a tap or hover can pick. */
|
|
205
236
|
export function updateOverlays(ctx, t, step, hoverGain) {
|
|
206
|
-
const { controls, camera, canvas, size, origin, state, layers } = ctx;
|
|
237
|
+
const { controls, camera, canvas, size, origin, state, layers, views } = ctx;
|
|
207
238
|
const bodyScreens = bodyScreenReadouts(ctx.assets, ctx.bodyRefs, camera, camera.fov, size.height, controls.policy, controls.glowLook);
|
|
208
239
|
publishBodyData(canvas, bodyScreens);
|
|
209
240
|
layers.anchorLabels.current?.update(controls.showAnchorLabels, camera, size.width, size.height);
|
|
210
241
|
const positionFor = (id) => labelPositionOf(step.targets, id);
|
|
211
242
|
const shown = shownUnderView(ctx);
|
|
212
|
-
layers.sceneLabels.current?.update(positionFor, camera, size.width, size.height, origin, controls.selectedObjectId, shown.hiddenLabels);
|
|
243
|
+
layers.sceneLabels.current?.update(positionFor, camera, size.width, size.height, origin, controls.selectedObjectId, shown.hiddenLabels, { on: controls.skyLines, labelColor: controls.skyColours.label, selectedColor: controls.skyColours.selected, opacity: (id) => ctx.views.skyFiguresView.labelOpacity(id), distance: 0.5 * (camera.near + camera.far) });
|
|
213
244
|
state.pickables = pickCandidatesOf({ objects: shown.objects, bodyIdFor: ctx.bodyIdFor, bodyScreens, widthPx: size.width, heightPx: size.height, labelRects: layers.sceneLabels.current?.shownRects, canvas, bodySetViews: shown.bodySetViews });
|
|
245
|
+
// Sky figures are projected only when a tap asks, from this frame's camera and shown names (no per-frame work).
|
|
246
|
+
state.skyFigures = () => views.skyFiguresView.screenFigures(camera, size.width, size.height, controls.skyLines, layers.sceneLabels.current?.shownRects, canvas.getBoundingClientRect());
|
|
214
247
|
const hover = state.hoverPoint === null ? null : hoverTarget(state.pickables, state.hoverPoint.x, state.hoverPoint.y, "mouse");
|
|
215
248
|
canvas.style.cursor = hover === null ? "" : "pointer";
|
|
216
249
|
canvas.dataset.pickHover = hover ?? "";
|
|
217
250
|
layers.sceneLabels.current?.setHover(hover, hoverGain);
|
|
218
|
-
layers.storyMarkers.current?.update(positionFor, camera, size.width, size.height, origin, controls.openStoryPanelId ?? null, t,
|
|
251
|
+
layers.storyMarkers.current?.update(positionFor, camera, size.width, size.height, origin, controls.openStoryPanelId ?? null, t, hiddenOf(ctx));
|
|
219
252
|
const featureReadout = layers.featureMarkers.current?.update((id) => featureHostOf(ctx.assets, ctx.bodyRefs.parts, id, controls.policy), camera, camera.fov, size.width, size.height, controls.openFeatureKey ?? null, controls.featureMinBodyPx ?? DEFAULT_FEATURE_MIN_BODY_PX);
|
|
220
253
|
if (featureReadout !== null && featureReadout !== undefined)
|
|
221
254
|
canvas.dataset.featureMarkers = JSON.stringify(featureReadout);
|
|
@@ -311,6 +344,8 @@ export function runFrame(ctx) {
|
|
|
311
344
|
const placed = placeScene(ctx, t);
|
|
312
345
|
const step = stepAndPoseCamera(ctx, t, placed);
|
|
313
346
|
publishCanvasReadouts(ctx);
|
|
347
|
+
placeSkyFigures(ctx);
|
|
348
|
+
advanceSkyTraces(ctx);
|
|
314
349
|
applyViewVisibility(ctx);
|
|
315
350
|
const hoverGain = placeViews(ctx, t, placed, setLook);
|
|
316
351
|
updateOverlays(ctx, t, step, hoverGain);
|
|
@@ -38,6 +38,13 @@ export declare const CAMERA_FOV_DEG = 45;
|
|
|
38
38
|
export declare const ORBIT_FIT_MARGIN = 1.1;
|
|
39
39
|
/** The far plane of a fitted reach, as a multiple of the reach (what `camera.setReach` uses too). */
|
|
40
40
|
export declare const FAR_PER_REACH = 2.5;
|
|
41
|
+
/** Room a look-out far plane keeps past the farthest drawn body, as a multiple of its distance. */
|
|
42
|
+
export declare const LOOK_OUT_FAR_MARGIN = 1.5;
|
|
43
|
+
/**
|
|
44
|
+
* The far plane of a camera standing inside a body: the declared or default `far` (sized for orbit framing about a focus) but never nearer than the farthest placed body
|
|
45
|
+
* (times `LOOK_OUT_FAR_MARGIN`), since a sky shows everything the scene holds, however far from where the camera stands. One rule for every body (ARCH-06).
|
|
46
|
+
*/
|
|
47
|
+
export declare function lookOutFar(far: number, cameraAbsolute: readonly number[], placed: ReadonlyMap<string, readonly number[]>): number;
|
|
41
48
|
/**
|
|
42
49
|
* The camera-to-focus distance at which a sphere of radius `farthestUnits` about the focus fits the canvas from any view direction:
|
|
43
50
|
* the farthest distance divided by the sine of the narrower half field of view (vertical, or horizontal from the aspect ratio), times the margin.
|
package/src/app/sceneFraming.js
CHANGED
|
@@ -42,6 +42,18 @@ export const CAMERA_FOV_DEG = 45;
|
|
|
42
42
|
export const ORBIT_FIT_MARGIN = 1.1;
|
|
43
43
|
/** The far plane of a fitted reach, as a multiple of the reach (what `camera.setReach` uses too). */
|
|
44
44
|
export const FAR_PER_REACH = 2.5;
|
|
45
|
+
/** Room a look-out far plane keeps past the farthest drawn body, as a multiple of its distance. */
|
|
46
|
+
export const LOOK_OUT_FAR_MARGIN = 1.5;
|
|
47
|
+
/**
|
|
48
|
+
* The far plane of a camera standing inside a body: the declared or default `far` (sized for orbit framing about a focus) but never nearer than the farthest placed body
|
|
49
|
+
* (times `LOOK_OUT_FAR_MARGIN`), since a sky shows everything the scene holds, however far from where the camera stands. One rule for every body (ARCH-06).
|
|
50
|
+
*/
|
|
51
|
+
export function lookOutFar(far, cameraAbsolute, placed) {
|
|
52
|
+
let farthest = 0;
|
|
53
|
+
for (const position of placed.values())
|
|
54
|
+
farthest = Math.max(farthest, Math.hypot(position[0] - cameraAbsolute[0], position[1] - cameraAbsolute[1], position[2] - cameraAbsolute[2]));
|
|
55
|
+
return Math.max(far, farthest * LOOK_OUT_FAR_MARGIN);
|
|
56
|
+
}
|
|
45
57
|
/**
|
|
46
58
|
* The camera-to-focus distance at which a sphere of radius `farthestUnits` about the focus fits the canvas from any view direction:
|
|
47
59
|
* the farthest distance divided by the sine of the narrower half field of view (vertical, or horizontal from the aspect ratio), times the margin.
|
package/src/app/sceneHooks.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { BodySetView } from "./BodySetView.js";
|
|
|
4
4
|
import { OrbitSetView } from "./OrbitSetView.js";
|
|
5
5
|
import { PointsView } from "./PointsView.js";
|
|
6
6
|
import { SkyView } from "./SkyView.js";
|
|
7
|
+
import { SkyFiguresView } from "./SkyFiguresView.js";
|
|
7
8
|
import { TrackedBodyView } from "./TrackedBodyView.js";
|
|
8
9
|
/**
|
|
9
10
|
* Mounts a DOM layer (labels, markers) next to the canvas and keeps `ref` pointing at it; `create` returns null when there is nothing to
|
|
@@ -23,6 +24,7 @@ export declare function useSceneViews(runtime: SceneRuntime, gl: WebGLRenderer):
|
|
|
23
24
|
sunCentredViews: readonly import("./PathView.js").PathView[];
|
|
24
25
|
compositionPaths: import("./PathView.js").PathView[];
|
|
25
26
|
skyView: SkyView | null;
|
|
27
|
+
skyFiguresView: SkyFiguresView;
|
|
26
28
|
bodySetViews: BodySetView[];
|
|
27
29
|
orbitSetViews: OrbitSetView[];
|
|
28
30
|
};
|
package/src/app/sceneHooks.js
CHANGED
|
@@ -7,6 +7,7 @@ import { BodySetView } from "./BodySetView.js";
|
|
|
7
7
|
import { OrbitSetView } from "./OrbitSetView.js";
|
|
8
8
|
import { PointsView } from "./PointsView.js";
|
|
9
9
|
import { SkyView } from "./SkyView.js";
|
|
10
|
+
import { SkyFiguresView } from "./SkyFiguresView.js";
|
|
10
11
|
import { TrackedBodyView } from "./TrackedBodyView.js";
|
|
11
12
|
/**
|
|
12
13
|
* Mounts a DOM layer (labels, markers) next to the canvas and keeps `ref` pointing at it; `create` returns null when there is nothing to
|
|
@@ -59,11 +60,13 @@ export function useSceneViews(runtime, gl) {
|
|
|
59
60
|
const sunCentredViews = useMemo(() => createPathViews(runtime.paths ?? []), [runtime.paths]);
|
|
60
61
|
const compositionPaths = useMemo(() => (runtime.composition?.paths ?? []).map((path) => compositionPathView(path, runtime.resolver, runtime.catalogue)), [runtime.composition, runtime.resolver, runtime.catalogue]);
|
|
61
62
|
const skyView = useMemo(() => (runtime.sky !== undefined && (runtime.sky.visible || runtime.sky.live === true) ? new SkyView({ starBrightness: runtime.sky.starBrightness, milkyWayBrightness: runtime.sky.milkyWayBrightness, pixelRatio: gl.getPixelRatio(), maxAnisotropy: gl.capabilities.getMaxAnisotropy(), milkyWay: runtime.sky.milkyWay, picture: null, pictureSet: milkyWayPicture(runtime.pictures ?? NO_PICTURES) }) : null), [runtime.sky, runtime.pictures, gl]);
|
|
63
|
+
const skyFiguresView = useMemo(() => new SkyFiguresView(runtime.skyFigures), [runtime.skyFigures]);
|
|
64
|
+
useEffect(() => () => skyFiguresView.dispose(), [skyFiguresView]);
|
|
62
65
|
const bodySetViews = useMemo(() => (runtime.bodySets ?? []).map((layer) => new BodySetView(layer)), [runtime.bodySets]);
|
|
63
66
|
const orbitSetViews = useMemo(() => (runtime.bodySets ?? []).map((layer) => new OrbitSetView(layer)), [runtime.bodySets]);
|
|
64
67
|
useEffect(() => () => { for (const view of bodySetViews)
|
|
65
68
|
view.dispose(); }, [bodySetViews]);
|
|
66
69
|
useEffect(() => () => { for (const view of orbitSetViews)
|
|
67
70
|
view.dispose(); }, [orbitSetViews]);
|
|
68
|
-
return { trackedViews, groupViews, sunCentredViews, compositionPaths, skyView, bodySetViews, orbitSetViews };
|
|
71
|
+
return { trackedViews, groupViews, sunCentredViews, compositionPaths, skyView, skyFiguresView, bodySetViews, orbitSetViews };
|
|
69
72
|
}
|
|
@@ -27,6 +27,26 @@ export declare const TOUCH_TAP_SLOP_PX = 10;
|
|
|
27
27
|
* null when nothing is hit.
|
|
28
28
|
*/
|
|
29
29
|
export declare function pickTarget(candidates: readonly PickCandidate[], x: number, y: number, pointer: PickPointer): string | null;
|
|
30
|
+
/** A tap selects a sky figure within this many CSS px of one of its drawn lines (a finger's reach, for mouse and touch alike); farther, or inside a boundary outline, selects nothing. */
|
|
31
|
+
export declare const SKY_LINE_MARGIN_PX = 16;
|
|
32
|
+
/** One sky figure a tap can select: its drawn lines as screen segments `[x1, y1, x2, y2]` (CSS px from the canvas's top left) and the rectangle of its shown name, if any. */
|
|
33
|
+
export interface SkyPickFigure {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly lines: readonly (readonly [number, number, number, number])[];
|
|
36
|
+
readonly label?: PickRect | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The screen segment `[x1, y1, x2, y2]` (CSS px, ends may lie outside the canvas) of the 3D segment between two camera-space points (the camera looks along -z), or null when none of it is in front of the camera.
|
|
40
|
+
* A segment with one end behind the camera is cut at the camera plane, so its visible part is kept. `tanHalfFov` is the tangent of half the vertical field of view; `aspect` is width over height.
|
|
41
|
+
*/
|
|
42
|
+
export declare function projectSegmentClipped(a: readonly [number, number, number], b: readonly [number, number, number], tanHalfFov: number, aspect: number, widthPx: number, heightPx: number): readonly [number, number, number, number] | null;
|
|
43
|
+
/** The distance from `(x, y)` to the segment from `(x1, y1)` to `(x2, y2)`. */
|
|
44
|
+
export declare function distanceToSegment(x: number, y: number, x1: number, y1: number, x2: number, y2: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* The sky figure under `(x, y)`: one whose shown name holds the point, else the one with a line nearest the point within `SKY_LINE_MARGIN_PX`; null when none. Only names and lines answer: the inside of
|
|
47
|
+
* an outline never does. Callers try the bodies first (`pickTarget`), so a body in front of the sky wins where it is hit.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pickSkyFigure(figures: readonly SkyPickFigure[], x: number, y: number): string | null;
|
|
30
50
|
/** A mouse hovering a target brightens its name by this factor (a live setting, Developer > Labels); touch never hovers. */
|
|
31
51
|
export declare const HOVER_BRIGHTNESS_DEFAULT = 1.4;
|
|
32
52
|
export declare const HOVER_BRIGHTNESS_LIMITS: Readonly<{
|
package/src/app/scenePicking.js
CHANGED
|
@@ -29,6 +29,55 @@ export function pickTarget(candidates, x, y, pointer) {
|
|
|
29
29
|
}
|
|
30
30
|
return best;
|
|
31
31
|
}
|
|
32
|
+
/** A tap selects a sky figure within this many CSS px of one of its drawn lines (a finger's reach, for mouse and touch alike); farther, or inside a boundary outline, selects nothing. */
|
|
33
|
+
export const SKY_LINE_MARGIN_PX = 16;
|
|
34
|
+
/**
|
|
35
|
+
* The screen segment `[x1, y1, x2, y2]` (CSS px, ends may lie outside the canvas) of the 3D segment between two camera-space points (the camera looks along -z), or null when none of it is in front of the camera.
|
|
36
|
+
* A segment with one end behind the camera is cut at the camera plane, so its visible part is kept. `tanHalfFov` is the tangent of half the vertical field of view; `aspect` is width over height.
|
|
37
|
+
*/
|
|
38
|
+
export function projectSegmentClipped(a, b, tanHalfFov, aspect, widthPx, heightPx) {
|
|
39
|
+
const front = 1e-6 * Math.max(1, Math.abs(a[2]), Math.abs(b[2])); // how far in front of the camera a point must be
|
|
40
|
+
const inFront = (p) => -p[2] >= front;
|
|
41
|
+
if (!inFront(a) && !inFront(b))
|
|
42
|
+
return null;
|
|
43
|
+
const cut = (kept, lost) => {
|
|
44
|
+
const share = (-kept[2] - front) / (-kept[2] + lost[2]);
|
|
45
|
+
return [kept[0] + (lost[0] - kept[0]) * share, kept[1] + (lost[1] - kept[1]) * share, -front];
|
|
46
|
+
};
|
|
47
|
+
const from = inFront(a) ? a : cut(b, a);
|
|
48
|
+
const to = inFront(b) ? b : cut(a, b);
|
|
49
|
+
const screen = (p) => [(0.5 + (p[0] / -p[2]) / (2 * tanHalfFov * aspect)) * widthPx, (0.5 - (p[1] / -p[2]) / (2 * tanHalfFov)) * heightPx];
|
|
50
|
+
const [x1, y1] = screen(from);
|
|
51
|
+
const [x2, y2] = screen(to);
|
|
52
|
+
return [x1, y1, x2, y2];
|
|
53
|
+
}
|
|
54
|
+
/** The distance from `(x, y)` to the segment from `(x1, y1)` to `(x2, y2)`. */
|
|
55
|
+
export function distanceToSegment(x, y, x1, y1, x2, y2) {
|
|
56
|
+
const dx = x2 - x1;
|
|
57
|
+
const dy = y2 - y1;
|
|
58
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
59
|
+
const along = lengthSquared === 0 ? 0 : Math.min(1, Math.max(0, ((x - x1) * dx + (y - y1) * dy) / lengthSquared));
|
|
60
|
+
return Math.hypot(x - (x1 + along * dx), y - (y1 + along * dy));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The sky figure under `(x, y)`: one whose shown name holds the point, else the one with a line nearest the point within `SKY_LINE_MARGIN_PX`; null when none. Only names and lines answer: the inside of
|
|
64
|
+
* an outline never does. Callers try the bodies first (`pickTarget`), so a body in front of the sky wins where it is hit.
|
|
65
|
+
*/
|
|
66
|
+
export function pickSkyFigure(figures, x, y) {
|
|
67
|
+
let best = null;
|
|
68
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
69
|
+
for (const figure of figures) {
|
|
70
|
+
const label = figure.label;
|
|
71
|
+
const named = label !== undefined && label !== null && x >= label.left && x <= label.right && y >= label.top && y <= label.bottom;
|
|
72
|
+
const toLines = figure.lines.reduce((nearest, [x1, y1, x2, y2]) => Math.min(nearest, distanceToSegment(x, y, x1, y1, x2, y2)), Number.POSITIVE_INFINITY);
|
|
73
|
+
const distance = named ? 0 : toLines <= SKY_LINE_MARGIN_PX ? toLines : Number.POSITIVE_INFINITY;
|
|
74
|
+
if (distance < bestDistance) {
|
|
75
|
+
best = figure.id;
|
|
76
|
+
bestDistance = distance;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return best;
|
|
80
|
+
}
|
|
32
81
|
/** A mouse hovering a target brightens its name by this factor (a live setting, Developer > Labels); touch never hovers. */
|
|
33
82
|
export const HOVER_BRIGHTNESS_DEFAULT = 1.4;
|
|
34
83
|
export const HOVER_BRIGHTNESS_LIMITS = Object.freeze({ min: 1, max: 3 });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DistanceLimits, type OrbitCameraState } from "./CameraController.js";
|
|
2
|
-
import { type PickCandidate } from "./scenePicking.js";
|
|
2
|
+
import { type PickCandidate, type SkyPickFigure } from "./scenePicking.js";
|
|
3
3
|
/** The slice of the frame state the pointer listeners read and write. */
|
|
4
4
|
export interface PointerState {
|
|
5
5
|
readonly pickables: readonly PickCandidate[];
|
|
@@ -7,6 +7,8 @@ export interface PointerState {
|
|
|
7
7
|
x: number;
|
|
8
8
|
y: number;
|
|
9
9
|
} | null;
|
|
10
|
+
/** The sky figures a tap can select now, built when asked (a tap), never per frame. */
|
|
11
|
+
skyFigures?: () => readonly SkyPickFigure[];
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Wires orbit gestures, the mouse hover point and tap picking to the canvas. `state` is read live (the frame rebuilds `pickables`);
|
package/src/app/scenePointer.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Scene pointer: the hover and tap listeners on the canvas, separate from React.
|
|
2
2
|
import { attachOrbitGestures } from "./CameraController.js";
|
|
3
|
-
import { pickTarget } from "./scenePicking.js";
|
|
3
|
+
import { pickSkyFigure, pickTarget } from "./scenePicking.js";
|
|
4
4
|
/**
|
|
5
5
|
* Wires orbit gestures, the mouse hover point and tap picking to the canvas. `state` is read live (the frame rebuilds `pickables`);
|
|
6
6
|
* returns the detach function, which also clears the cursor and the hover readout.
|
|
7
7
|
*/
|
|
8
8
|
export function attachScenePointer(canvas, orbit, state, limits, onPickObject) {
|
|
9
9
|
const onTap = (x, y, pointer) => {
|
|
10
|
-
|
|
10
|
+
// Bodies first: a body hit wins over any sky figure behind it.
|
|
11
|
+
const id = pickTarget(state.pickables, x, y, pointer) ?? pickSkyFigure(state.skyFigures?.() ?? [], x, y);
|
|
11
12
|
if (id === null)
|
|
12
13
|
return;
|
|
13
14
|
canvas.dataset.pickTarget = id;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type SkyTraceAfter } from "../core/skyTrace.js";
|
|
2
|
+
import type { CameraRequest } from "./CameraController.js";
|
|
3
|
+
export type EqjDirection = readonly [number, number, number];
|
|
4
|
+
/** One figure ready to draw: segments (pairs of unit EQJ directions), the kind the display switches act on, and where its label stands. */
|
|
5
|
+
export interface SkyFigureLayer {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly label: string;
|
|
8
|
+
readonly kind: "figure" | "boundary";
|
|
9
|
+
readonly segments: readonly (readonly [EqjDirection, EqjDirection])[];
|
|
10
|
+
/** Unit EQJ direction of the label. */
|
|
11
|
+
readonly labelAt: EqjDirection;
|
|
12
|
+
/** This figure's own line colour, over the look's. */
|
|
13
|
+
readonly color?: string;
|
|
14
|
+
/** True: nothing of the figure (lines or label) is drawn until a trace of it starts (`SkyFigureInput.shown: "whenTraced"`). */
|
|
15
|
+
readonly whenTraced?: boolean;
|
|
16
|
+
/** This figure's own label colour, font and size, over the look's. */
|
|
17
|
+
readonly labelColor?: string;
|
|
18
|
+
readonly labelFont?: string;
|
|
19
|
+
readonly labelSizePx?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Which kinds of sky line are shown now (the four display switches; live, replaced in place by value). */
|
|
22
|
+
export interface SkyLineSwitches {
|
|
23
|
+
figures: boolean;
|
|
24
|
+
boundaries: boolean;
|
|
25
|
+
ecliptic: boolean;
|
|
26
|
+
celestialEquator: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The starting state of the four switches: the figures show, the rest wait for the app to ask. */
|
|
29
|
+
export declare const DEFAULT_SKY_LINES: Readonly<SkyLineSwitches>;
|
|
30
|
+
/** The colours of the sky lines and their labels, and of the lines a trace draws (T-297): every one a CSS colour text. The look `skyLines` sets them; `DEFAULT_SKY_COLOURS` is the one place the defaults are stated. */
|
|
31
|
+
export interface SkyColours {
|
|
32
|
+
readonly figure: string;
|
|
33
|
+
readonly label: string;
|
|
34
|
+
readonly boundary: string;
|
|
35
|
+
readonly ecliptic: string;
|
|
36
|
+
readonly equator: string;
|
|
37
|
+
readonly traced: string;
|
|
38
|
+
readonly faded: string;
|
|
39
|
+
/** The lines and name of the selected sky figure. */
|
|
40
|
+
readonly selected: string;
|
|
41
|
+
}
|
|
42
|
+
export declare const DEFAULT_SKY_COLOURS: Readonly<SkyColours>;
|
|
43
|
+
/** A trace the host asked for (checked): the figure, how long, what follows, and whether the person asked for less motion when it was asked. */
|
|
44
|
+
export interface SkyTraceRequest {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly seconds: number;
|
|
47
|
+
readonly after: SkyTraceAfter;
|
|
48
|
+
readonly reduced: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** A request to remove a figure's trace the host made (checked): the figure, how long it takes to go (0: at once), and whether the person asked for less motion (then it goes at once). */
|
|
51
|
+
export interface SkyClearRequest {
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly seconds: number;
|
|
54
|
+
readonly reduced: boolean;
|
|
55
|
+
}
|
|
56
|
+
/** True when the person asked the system for less motion (`prefers-reduced-motion: reduce`); false where the browser cannot say. */
|
|
57
|
+
export declare function prefersReducedMotion(): boolean;
|
|
58
|
+
/** The sky colours in force: the look's `skyLines`, every one not named at its default. */
|
|
59
|
+
export declare function skyColoursOf(look: {
|
|
60
|
+
readonly skyLines?: Partial<SkyColours>;
|
|
61
|
+
}): SkyColours;
|
|
62
|
+
/** How long sky lines and their names fade in when they appear: the look's `skyFadeInSeconds`, else the default. */
|
|
63
|
+
export declare function skyFadeInSecondsOf(look: {
|
|
64
|
+
readonly skyFadeInSeconds?: number;
|
|
65
|
+
}): number;
|
|
66
|
+
/** The mean of the unit directions, normalised; the first when they cancel out. */
|
|
67
|
+
export declare function meanDirection(directions: readonly EqjDirection[]): EqjDirection;
|
|
68
|
+
/** The celestial equator: declination 0, as segments. */
|
|
69
|
+
export declare function celestialEquatorSegments(): readonly (readonly [EqjDirection, EqjDirection])[];
|
|
70
|
+
/** The ecliptic of J2000 as segments, turned to EQJ by the engine's own ecliptic-to-equator matrix (STYLE-07: that is the one obliquity). */
|
|
71
|
+
export declare function eclipticSegments(): readonly (readonly [EqjDirection, EqjDirection])[];
|
|
72
|
+
/** A camera request with a look-out direction that names a sky figure turned into that figure's label point (the one place a figure id becomes a direction); any other request is returned as it is. */
|
|
73
|
+
export declare function aimAtFigure<T extends CameraRequest>(request: T, figures: readonly Pick<SkyFigureLayer, "id" | "labelAt">[]): T;
|