astraeus 0.8.1 → 0.9.1
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 +85 -0
- package/README.md +104 -31
- 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 +28 -6
- 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/planBodies.d.ts +2 -1
- package/src/api/planBodies.js +6 -1
- package/src/api/planCamera.d.ts +35 -7
- package/src/api/planCamera.js +94 -11
- package/src/api/planPaths.d.ts +2 -0
- package/src/api/planPaths.js +14 -9
- 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/providerPathTimes.d.ts +10 -0
- package/src/api/providerPathTimes.js +109 -0
- package/src/api/scene.d.ts +23 -4
- package/src/api/scene.js +23 -5
- package/src/api/sceneReads.d.ts +21 -2
- package/src/api/shownDuring.d.ts +12 -0
- package/src/api/shownDuring.js +30 -0
- 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 +13 -4
- package/src/api/story.js +45 -2
- 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 +129 -30
- package/src/app/App.node.js +129 -30
- package/src/app/AstraeusScene.d.ts +20 -5
- package/src/app/AstraeusScene.js +3 -3
- package/src/app/CameraController.d.ts +19 -1
- package/src/app/CameraController.js +38 -11
- 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 +22 -4
- package/src/app/sceneFrame.js +67 -22
- 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 +10 -1
- package/src/app/viewHiding.js +30 -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/pacing.d.ts +38 -6
- package/src/core/pacing.js +141 -21
- 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 +17 -6
- package/src/shell/AstraeusShell.js +100 -26
- package/src/shell/AstraeusShell.node.js +100 -26
- 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 +31 -0
- package/src/shell/experience.js +4 -1
- package/src/shell/infoModel.js +9 -1
- package/src/shell/objectModel.d.ts +9 -4
- package/src/shell/objectModel.js +16 -5
- 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/sceneFrame.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { drawnRadii } from "./bodyDraw.js";
|
|
2
2
|
import { DEFAULT_BODY_SET_LOOK, familyColorOf } from "./bodySet.js";
|
|
3
|
-
import { applyPacing } from "../core/pacing.js";
|
|
3
|
+
import { applyPacing, stepPacing } from "../core/pacing.js";
|
|
4
4
|
import { poseCamera, resolveCamera } from "./CameraController.js";
|
|
5
5
|
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, hiddenWithShownSpans } 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
|
};
|
|
@@ -33,14 +36,24 @@ export function viewUpOf(ctx) {
|
|
|
33
36
|
export function bodiesMounted(runtime, refs) {
|
|
34
37
|
return runtime.bodies.every((id) => refs.groups.has(id) && refs.orients.has(id));
|
|
35
38
|
}
|
|
36
|
-
/**
|
|
37
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Stage 0: the time of this frame. While pacing is in charge the clock is first stepped through the frame's real time under the paced rate (so no frame passes over a slow-down); looping playback then wraps inside its window,
|
|
41
|
+
* and other playback stops on the window's edge (a scene with a timeline bar). A wrap or stop lands on the paced rate for its new time at once.
|
|
42
|
+
*/
|
|
43
|
+
export function frameTime(runtime, controls, nowMs = performance.now()) {
|
|
44
|
+
const paced = controls.paceAuto === true && runtime.pacing !== undefined;
|
|
45
|
+
if (paced && controls.pace !== undefined)
|
|
46
|
+
stepPacing(runtime.clock, runtime.pacing, controls.pace, nowMs);
|
|
47
|
+
let moved = false;
|
|
38
48
|
if (controls.loop === true && runtime.loopWindow !== undefined)
|
|
39
|
-
runtime.clock.wrapWithin(runtime.loopWindow);
|
|
49
|
+
moved = runtime.clock.wrapWithin(runtime.loopWindow);
|
|
40
50
|
else if (runtime.stopAtWindow === true && runtime.loopWindow !== undefined)
|
|
41
|
-
runtime.clock.stopWithin(runtime.loopWindow);
|
|
42
|
-
if (
|
|
43
|
-
|
|
51
|
+
moved = runtime.clock.stopWithin(runtime.loopWindow);
|
|
52
|
+
if (paced && (moved || controls.pace === undefined)) {
|
|
53
|
+
if (controls.pace !== undefined)
|
|
54
|
+
delete controls.pace.last;
|
|
55
|
+
applyPacing(runtime.clock, runtime.pacing, controls.pace, nowMs);
|
|
56
|
+
}
|
|
44
57
|
return runtime.clock.now();
|
|
45
58
|
}
|
|
46
59
|
/** Stage 1: brings every view to the time of the frame. Returns the live body-set look. */
|
|
@@ -100,16 +113,20 @@ export function stepAndPoseCamera(ctx, t, placed) {
|
|
|
100
113
|
const firstFrame = !state.started;
|
|
101
114
|
state.started = true;
|
|
102
115
|
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 });
|
|
116
|
+
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
117
|
state.lastUp = viewUp;
|
|
105
|
-
resolveCamera(orbit, cameraTargetAbsolute(orbit, targets), ctx.origin, ctx.delta, REBASE_THRESHOLD, viewUp);
|
|
118
|
+
resolveCamera(orbit, cameraTargetAbsolute(orbit, targets), ctx.origin, ctx.delta, REBASE_THRESHOLD, viewUp, prefersReducedMotion());
|
|
106
119
|
placeBodies(ctx.assets, placed.composed.states, ctx.bodyRefs, policy, ctx.origin);
|
|
107
|
-
|
|
120
|
+
const baseFar = reach.far ?? DEFAULT_CAMERA_FAR;
|
|
121
|
+
// 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.
|
|
122
|
+
const far = orbit.lookOut === null ? baseFar : lookOutFar(baseFar, orbit.cameraAbsolute, placed.composed.absolutes);
|
|
123
|
+
poseCamera(camera, orbit, focusRadius(focusBody, policy, catalogue), ctx.origin, far, viewUp);
|
|
108
124
|
if (firstFrame && state.onFirstDraw !== undefined) {
|
|
109
125
|
const told = state.onFirstDraw;
|
|
110
126
|
requestAnimationFrame(told);
|
|
111
127
|
}
|
|
112
|
-
|
|
128
|
+
// Looking out, the angles are the way the camera looks, not an offset from a target: a sky reading, never orbit values.
|
|
129
|
+
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
130
|
return { targets };
|
|
114
131
|
}
|
|
115
132
|
/** 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 +152,26 @@ export function publishCanvasReadouts(ctx) {
|
|
|
135
152
|
updateSky(views.skyView, camera, canvas, controls, controls.frameStats !== null);
|
|
136
153
|
}
|
|
137
154
|
}
|
|
155
|
+
/** 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). */
|
|
156
|
+
export function placeSkyFigures(ctx) {
|
|
157
|
+
const { controls, camera, canvas, views } = ctx;
|
|
158
|
+
views.skyFiguresView.place(camera, controls.skyLines, controls.skyColours, controls.selectedObjectId);
|
|
159
|
+
canvas.dataset.skyLines = views.skyFiguresView.shown.join(",");
|
|
160
|
+
}
|
|
161
|
+
/** 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). */
|
|
162
|
+
export function advanceSkyTraces(ctx) {
|
|
163
|
+
const { controls, state, views, delta } = ctx;
|
|
164
|
+
for (const request of controls.skyTraces.splice(0)) {
|
|
165
|
+
if ("after" in request)
|
|
166
|
+
views.skyFiguresView.startTrace(request);
|
|
167
|
+
else
|
|
168
|
+
views.skyFiguresView.clearTrace(request);
|
|
169
|
+
}
|
|
170
|
+
if (views.skyFiguresView.advanceTraces(delta, controls.skyColours, controls.skyLines, controls.selectedObjectId))
|
|
171
|
+
state.wakes += 1;
|
|
172
|
+
if (views.skyFiguresView.advanceFadeIn(delta, prefersReducedMotion() ? 0 : controls.skyFadeInSeconds, controls.skyLines))
|
|
173
|
+
state.wakes += 1;
|
|
174
|
+
}
|
|
138
175
|
/** Stage 5: places every view about the floating origin and publishes the views' readouts. Returns the hover brightness gain. */
|
|
139
176
|
export function placeViews(ctx, t, placed, setLook) {
|
|
140
177
|
const { controls, camera, canvas, size, views, origin } = ctx;
|
|
@@ -161,9 +198,13 @@ export function placeViews(ctx, t, placed, setLook) {
|
|
|
161
198
|
publishPointsData(canvas, views.groupViews, camera, views.bodySetViews);
|
|
162
199
|
return hoverGain;
|
|
163
200
|
}
|
|
201
|
+
/** What this frame hides: the view's hidden ids, the objects not shown at clock time `t` (`shownDuring`; none when `t` is not given), and the body the camera stands inside while looking out (the one hidden-set path, read by the visibility, label and tap stages). */
|
|
202
|
+
export function hiddenOf(ctx, t) {
|
|
203
|
+
return hiddenWithLookOut(hiddenWithShownSpans(ctx.controls.viewHidden, ctx.controls.labelObjects, t), ctx.orbit.lookOut === null ? null : ctx.orbit.focus);
|
|
204
|
+
}
|
|
164
205
|
/** 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
|
-
export function applyViewVisibility(ctx) {
|
|
166
|
-
const hidden = ctx
|
|
206
|
+
export function applyViewVisibility(ctx, t) {
|
|
207
|
+
const hidden = hiddenOf(ctx, t)?.objects;
|
|
167
208
|
const { views, bodyRefs } = ctx;
|
|
168
209
|
const show = (id, group) => { group.visible = hidden?.has(id) !== true; };
|
|
169
210
|
for (const [id, group] of bodyRefs.groups)
|
|
@@ -190,9 +231,9 @@ export function featureHostOf(assets, parts, id, policy) {
|
|
|
190
231
|
return sphere === undefined || asset === undefined ? null : { sphere, radius: drawnRadii(asset.definition, policy).equatorial };
|
|
191
232
|
}
|
|
192
233
|
/** 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
|
-
function shownUnderView(ctx) {
|
|
234
|
+
export function shownUnderView(ctx, t) {
|
|
194
235
|
const { controls, views } = ctx;
|
|
195
|
-
const hidden =
|
|
236
|
+
const hidden = hiddenOf(ctx, t)?.objects;
|
|
196
237
|
if (hidden === undefined || hidden.size === 0)
|
|
197
238
|
return { objects: controls.labelObjects, bodySetViews: views.bodySetViews, hiddenLabels: controls.hiddenLabels };
|
|
198
239
|
return {
|
|
@@ -203,19 +244,21 @@ function shownUnderView(ctx) {
|
|
|
203
244
|
}
|
|
204
245
|
/** Stage 6: updates the overlay layers (names, story and feature markers) and rebuilds what a tap or hover can pick. */
|
|
205
246
|
export function updateOverlays(ctx, t, step, hoverGain) {
|
|
206
|
-
const { controls, camera, canvas, size, origin, state, layers } = ctx;
|
|
247
|
+
const { controls, camera, canvas, size, origin, state, layers, views } = ctx;
|
|
207
248
|
const bodyScreens = bodyScreenReadouts(ctx.assets, ctx.bodyRefs, camera, camera.fov, size.height, controls.policy, controls.glowLook);
|
|
208
249
|
publishBodyData(canvas, bodyScreens);
|
|
209
250
|
layers.anchorLabels.current?.update(controls.showAnchorLabels, camera, size.width, size.height);
|
|
210
251
|
const positionFor = (id) => labelPositionOf(step.targets, id);
|
|
211
|
-
const shown = shownUnderView(ctx);
|
|
212
|
-
layers.sceneLabels.current?.update(positionFor, camera, size.width, size.height, origin, controls.selectedObjectId, shown.hiddenLabels);
|
|
252
|
+
const shown = shownUnderView(ctx, t);
|
|
253
|
+
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
254
|
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 });
|
|
255
|
+
// Sky figures are projected only when a tap asks, from this frame's camera and shown names (no per-frame work).
|
|
256
|
+
state.skyFigures = () => views.skyFiguresView.screenFigures(camera, size.width, size.height, controls.skyLines, layers.sceneLabels.current?.shownRects, canvas.getBoundingClientRect());
|
|
214
257
|
const hover = state.hoverPoint === null ? null : hoverTarget(state.pickables, state.hoverPoint.x, state.hoverPoint.y, "mouse");
|
|
215
258
|
canvas.style.cursor = hover === null ? "" : "pointer";
|
|
216
259
|
canvas.dataset.pickHover = hover ?? "";
|
|
217
260
|
layers.sceneLabels.current?.setHover(hover, hoverGain);
|
|
218
|
-
layers.storyMarkers.current?.update(positionFor, camera, size.width, size.height, origin, controls.openStoryPanelId ?? null, t,
|
|
261
|
+
layers.storyMarkers.current?.update(positionFor, camera, size.width, size.height, origin, controls.openStoryPanelId ?? null, t, hiddenOf(ctx, t));
|
|
219
262
|
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
263
|
if (featureReadout !== null && featureReadout !== undefined)
|
|
221
264
|
canvas.dataset.featureMarkers = JSON.stringify(featureReadout);
|
|
@@ -311,7 +354,9 @@ export function runFrame(ctx) {
|
|
|
311
354
|
const placed = placeScene(ctx, t);
|
|
312
355
|
const step = stepAndPoseCamera(ctx, t, placed);
|
|
313
356
|
publishCanvasReadouts(ctx);
|
|
314
|
-
|
|
357
|
+
placeSkyFigures(ctx);
|
|
358
|
+
advanceSkyTraces(ctx);
|
|
359
|
+
applyViewVisibility(ctx, t);
|
|
315
360
|
const hoverGain = placeViews(ctx, t, placed, setLook);
|
|
316
361
|
updateOverlays(ctx, t, step, hoverGain);
|
|
317
362
|
placeLightsAndReadout(ctx, t, placed);
|
|
@@ -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;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Sky figures as the app draws them: figures, outlines and the two reference circles, all as unit directions in the EQJ frame at infinity (ARCH-02: presentation only, no State).
|
|
2
|
+
import { createOrbTwoBodyAdapter } from "../core/twoBodyAdapter.js";
|
|
3
|
+
import { DEFAULT_SKY_FADE_IN_SECONDS } from "../core/skyTrace.js";
|
|
4
|
+
/** The starting state of the four switches: the figures show, the rest wait for the app to ask. */
|
|
5
|
+
export const DEFAULT_SKY_LINES = Object.freeze({ figures: true, boundaries: false, ecliptic: false, celestialEquator: false });
|
|
6
|
+
export const DEFAULT_SKY_COLOURS = Object.freeze({ figure: "#8fb4ff", label: "#cfe0ff", boundary: "#5f7a9c", ecliptic: "#e0b25a", equator: "#7fd1b9", traced: "#ffd166", faded: "#44546d", selected: "#ffffff" });
|
|
7
|
+
/** True when the person asked the system for less motion (`prefers-reduced-motion: reduce`); false where the browser cannot say. */
|
|
8
|
+
export function prefersReducedMotion() {
|
|
9
|
+
return typeof globalThis.matchMedia === "function" && globalThis.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
10
|
+
}
|
|
11
|
+
/** The sky colours in force: the look's `skyLines`, every one not named at its default. */
|
|
12
|
+
export function skyColoursOf(look) {
|
|
13
|
+
return { ...DEFAULT_SKY_COLOURS, ...look.skyLines };
|
|
14
|
+
}
|
|
15
|
+
/** How long sky lines and their names fade in when they appear: the look's `skyFadeInSeconds`, else the default. */
|
|
16
|
+
export function skyFadeInSecondsOf(look) {
|
|
17
|
+
return look.skyFadeInSeconds ?? DEFAULT_SKY_FADE_IN_SECONDS;
|
|
18
|
+
}
|
|
19
|
+
/** How many segments a built-in great circle is cut into (about 2 degrees each). */
|
|
20
|
+
const CIRCLE_SEGMENTS = 180;
|
|
21
|
+
/** The mean of the unit directions, normalised; the first when they cancel out. */
|
|
22
|
+
export function meanDirection(directions) {
|
|
23
|
+
const sum = directions.reduce((acc, d) => [acc[0] + d[0], acc[1] + d[1], acc[2] + d[2]], [0, 0, 0]);
|
|
24
|
+
const length = Math.hypot(sum[0], sum[1], sum[2]);
|
|
25
|
+
return length > 1e-9 ? [sum[0] / length, sum[1] / length, sum[2] / length] : directions[0];
|
|
26
|
+
}
|
|
27
|
+
function circleSegments(point) {
|
|
28
|
+
const around = Array.from({ length: CIRCLE_SEGMENTS + 1 }, (_, i) => point((2 * Math.PI * i) / CIRCLE_SEGMENTS));
|
|
29
|
+
return around.slice(1).map((end, i) => [around[i], end]);
|
|
30
|
+
}
|
|
31
|
+
/** The celestial equator: declination 0, as segments. */
|
|
32
|
+
export function celestialEquatorSegments() {
|
|
33
|
+
return circleSegments((angle) => [Math.cos(angle), Math.sin(angle), 0]);
|
|
34
|
+
}
|
|
35
|
+
/** 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). */
|
|
36
|
+
export function eclipticSegments() {
|
|
37
|
+
const m = createOrbTwoBodyAdapter().eclipticJ2000ToEqjMatrix();
|
|
38
|
+
return circleSegments((angle) => {
|
|
39
|
+
const x = Math.cos(angle);
|
|
40
|
+
const y = Math.sin(angle);
|
|
41
|
+
return [m[0] * x + m[1] * y, m[3] * x + m[4] * y, m[6] * x + m[7] * y];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** 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. */
|
|
45
|
+
export function aimAtFigure(request, figures) {
|
|
46
|
+
if (request.kind !== "lookOut" || typeof request.direction !== "string")
|
|
47
|
+
return request;
|
|
48
|
+
const figure = figures.find(({ id }) => id === request.direction);
|
|
49
|
+
return figure === undefined ? request : { ...request, direction: figure.labelAt };
|
|
50
|
+
}
|
package/src/app/style.css
CHANGED
package/src/app/viewHiding.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExperienceConfig } from "../shell/experience.js";
|
|
1
|
+
import type { ExperienceConfig, ExperienceObject } from "../shell/experience.js";
|
|
2
2
|
import type { ResolvedView, ViewSettings } from "./views.js";
|
|
3
3
|
/** The ids the current view hides: objects (bodies, paths, groups) and story panels. Empty sets: everything shows. */
|
|
4
4
|
export interface ViewHidden {
|
|
@@ -11,3 +11,12 @@ export declare function viewById(settings: ViewSettings | undefined, id: string)
|
|
|
11
11
|
export declare function hiddenByView(settings: ViewSettings | undefined, view: ResolvedView | undefined, experience?: ExperienceConfig): ViewHidden;
|
|
12
12
|
/** The experience as the view shows it: its objects, timeline events and story panels. The same object when there are no views, so a scene without views is untouched. */
|
|
13
13
|
export declare function experienceInView(experience: ExperienceConfig, settings: ViewSettings | undefined, view: ResolvedView | undefined): ExperienceConfig;
|
|
14
|
+
/** `hidden` with the body the camera stands inside added while it looks out. The same object when nothing is added, so a normal frame allocates nothing. */
|
|
15
|
+
export declare function hiddenWithLookOut(hidden: ViewHidden | undefined, body: string | null): ViewHidden | undefined;
|
|
16
|
+
/** Whether `object` is shown at `timeUtcMs`: `startUtcMs <= t < endUtcMs`, an absent end unbounded, no span always shown (`shownDuring`). The one rule, so an object that ends at T and one that starts at T never both show or both hide. */
|
|
17
|
+
export declare function shownAt(object: Pick<ExperienceObject, "shownDuring">, timeUtcMs: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `hidden` with every object not shown at `timeUtcMs` added, and what belongs to one (`partOf`: a body's orbit line) with it. The same object when no object has a span or
|
|
20
|
+
* every span shows, so a frame without `shownDuring` allocates nothing. The one place the time-aware hidden set is built; the frame's `hiddenOf` calls it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hiddenWithShownSpans(hidden: ViewHidden | undefined, objects: readonly ExperienceObject[] | undefined, timeUtcMs: number | undefined): ViewHidden | undefined;
|
package/src/app/viewHiding.js
CHANGED
|
@@ -32,6 +32,35 @@ export function experienceInView(experience, settings, view) {
|
|
|
32
32
|
...experience,
|
|
33
33
|
objects: experience.objects.filter((object) => !objects.has(object.id)),
|
|
34
34
|
events: experience.events.filter((event) => !hiddenEvents.has(event.id)),
|
|
35
|
-
...(storySet === undefined ? {} : { storyPanels: { ...storySet, panels: storySet.panels.filter((panel) => !panels.has(panel.id)) } }),
|
|
35
|
+
...(storySet === undefined ? {} : { storyPanels: { ...storySet, panels: storySet.panels.filter((panel) => !panels.has(panel.id)), ...(storySet.steps === undefined ? {} : { steps: storySet.steps.filter((step) => !panels.has(step.id)) }) } }),
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
/** `hidden` with the body the camera stands inside added while it looks out. The same object when nothing is added, so a normal frame allocates nothing. */
|
|
39
|
+
export function hiddenWithLookOut(hidden, body) {
|
|
40
|
+
if (body === null)
|
|
41
|
+
return hidden;
|
|
42
|
+
return { objects: new Set([...(hidden?.objects ?? []), body]), panels: hidden?.panels ?? new Set() };
|
|
43
|
+
}
|
|
44
|
+
/** Whether `object` is shown at `timeUtcMs`: `startUtcMs <= t < endUtcMs`, an absent end unbounded, no span always shown (`shownDuring`). The one rule, so an object that ends at T and one that starts at T never both show or both hide. */
|
|
45
|
+
export function shownAt(object, timeUtcMs) {
|
|
46
|
+
const span = object.shownDuring;
|
|
47
|
+
return span === undefined || ((span.startUtcMs === undefined || span.startUtcMs <= timeUtcMs) && (span.endUtcMs === undefined || timeUtcMs < span.endUtcMs));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `hidden` with every object not shown at `timeUtcMs` added, and what belongs to one (`partOf`: a body's orbit line) with it. The same object when no object has a span or
|
|
51
|
+
* every span shows, so a frame without `shownDuring` allocates nothing. The one place the time-aware hidden set is built; the frame's `hiddenOf` calls it.
|
|
52
|
+
*/
|
|
53
|
+
export function hiddenWithShownSpans(hidden, objects, timeUtcMs) {
|
|
54
|
+
if (objects === undefined || timeUtcMs === undefined)
|
|
55
|
+
return hidden;
|
|
56
|
+
let ids;
|
|
57
|
+
for (const object of objects)
|
|
58
|
+
if (!shownAt(object, timeUtcMs))
|
|
59
|
+
(ids ??= new Set(hidden?.objects)).add(object.id);
|
|
60
|
+
if (ids === undefined)
|
|
61
|
+
return hidden;
|
|
62
|
+
for (const object of objects)
|
|
63
|
+
if (object.partOf !== undefined && ids.has(object.partOf))
|
|
64
|
+
ids.add(object.id);
|
|
65
|
+
return { objects: ids, panels: hidden?.panels ?? new Set() };
|
|
66
|
+
}
|
package/src/app/viewLink.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { validateStartView, type StartView } from "../core/startView.js";
|
|
2
|
-
export { validateStartView, type StartView };
|
|
1
|
+
import { validateStartView, type CameraView, type SkyView, type StartView } from "../core/startView.js";
|
|
2
|
+
export { validateStartView, type CameraView, type SkyView, type StartView };
|
|
3
3
|
/** The view as the camera reports it (radians), as a StartView rounded the way a link rounds it. */
|
|
4
4
|
export declare function viewFromAngles(focus: string, azimuthRad: number, elevationRad: number, distance: number): StartView;
|
|
5
|
-
/** `focus,az,el,distance
|
|
6
|
-
export declare function formatView(view:
|
|
7
|
-
/** Parses `
|
|
8
|
-
export declare function parseView(text: string):
|
|
5
|
+
/** `focus,az,el,distance` for an orbit view; `body,raDeg,decDeg,fovDeg,sky` for a sky view (the fifth part tells them apart). */
|
|
6
|
+
export declare function formatView(view: CameraView): string;
|
|
7
|
+
/** Parses either form of `formatView`; throws a RangeError naming the field. */
|
|
8
|
+
export declare function parseView(text: string): CameraView;
|
|
9
9
|
/** The view in `?view=`, or undefined when absent or malformed (a bad link opens the experience's own view rather than failing). */
|
|
10
|
-
export declare function viewFromSearch(search: string):
|
|
10
|
+
export declare function viewFromSearch(search: string): CameraView | undefined;
|
|
11
11
|
/** `?t=<ISO UTC>` as milliseconds, or undefined. */
|
|
12
12
|
export declare function timeFromSearch(search: string): number | undefined;
|
|
13
13
|
/** `?scale=<id>`, or undefined. The caller checks the id against the scale choices it offers. */
|
|
14
14
|
export declare function scaleFromSearch(search: string): string | undefined;
|
|
15
15
|
/** What a copied link carries. `show` is the id of the scene view showing, left out in a scene without views. */
|
|
16
16
|
export interface ViewLinkState {
|
|
17
|
-
view:
|
|
17
|
+
view: CameraView;
|
|
18
18
|
scaleId: string;
|
|
19
19
|
up: string;
|
|
20
20
|
timeUtcMs: number;
|