astraeus 0.8.0 → 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 +80 -0
- package/README.md +46 -17
- package/data/ephemerides/planets/planets.json +1 -1
- 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 +10 -0
- 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 +34 -5
- package/src/api/viewerHandle.js +7 -0
- package/src/api/viewerLink.d.ts +50 -4
- package/src/api/viewerLink.js +33 -2
- package/src/api/viewerPanels.d.ts +26 -0
- package/src/api/viewerPanels.js +42 -0
- package/src/api/viewerSelection.d.ts +6 -1
- package/src/api/viewerSelection.js +15 -0
- package/src/api/views.d.ts +3 -1
- package/src/api/views.js +5 -1
- package/src/app/App.js +118 -16
- package/src/app/App.node.js +118 -16
- package/src/app/AstraeusScene.d.ts +22 -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 +7 -3
- package/src/app/sceneCamera.js +68 -4
- 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 +32 -3
- package/src/app/views.d.ts +2 -0
- 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/astronomyAdapter.d.ts +1 -1
- package/src/core/astronomyAdapter.js +3 -3
- package/src/core/bodies/index.js +13 -12
- package/src/core/bodies/jupiter.js +1 -1
- package/src/core/bodies/mars.js +1 -1
- package/src/core/bodies/mercury.js +1 -1
- package/src/core/bodies/moonSystem.js +1 -15
- package/src/core/bodies/outerPlanets.d.ts +2 -3
- package/src/core/bodies/outerPlanets.js +4 -13
- package/src/core/bodies/planetMoons.d.ts +0 -2
- package/src/core/bodies/planetMoons.js +1 -18
- package/src/core/bodies/planetRecords.d.ts +8 -2
- package/src/core/bodies/planetRecords.js +13 -5
- package/src/core/bodies/planetTrajectory.d.ts +21 -4
- package/src/core/bodies/planetTrajectory.js +28 -4
- package/src/core/bodies/venus.js +1 -1
- package/src/core/lookValues.d.ts +9 -0
- package/src/core/lookValues.js +24 -0
- package/src/core/planetModels.d.ts +1 -1
- package/src/core/planetModels.js +1 -1
- package/src/core/planetSeries.d.ts +2 -2
- package/src/core/planetSeries.js +1 -1
- 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 +27 -6
- package/src/shell/AstraeusShell.js +104 -18
- package/src/shell/AstraeusShell.node.js +104 -18
- 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
|
@@ -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
|
@@ -11,3 +11,5 @@ 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;
|
package/src/app/viewHiding.js
CHANGED
|
@@ -32,6 +32,12 @@ 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
|
+
}
|
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;
|
package/src/app/viewLink.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_ELEVATION_DEG, validateStartView, wrapAzimuth } from "../core/startView.js";
|
|
1
|
+
import { isSkyView, MAX_ELEVATION_DEG, validateSkyView, validateStartView, wrapAzimuth } from "../core/startView.js";
|
|
2
2
|
export { validateStartView };
|
|
3
3
|
const round = (value, places) => Number(value.toFixed(places));
|
|
4
4
|
/** The view as the camera reports it (radians), as a StartView rounded the way a link rounds it. */
|
|
@@ -11,15 +11,19 @@ export function viewFromAngles(focus, azimuthRad, elevationRad, distance) {
|
|
|
11
11
|
distance: Number(distance.toPrecision(5)),
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
/** `focus,az,el,distance
|
|
14
|
+
/** `focus,az,el,distance` for an orbit view; `body,raDeg,decDeg,fovDeg,sky` for a sky view (the fifth part tells them apart). */
|
|
15
15
|
export function formatView(view) {
|
|
16
|
+
if (isSkyView(view))
|
|
17
|
+
return [encodeURIComponent(view.lookOut), view.raDeg, view.decDeg, view.fovDeg, "sky"].join(",");
|
|
16
18
|
return [encodeURIComponent(view.focus), view.azimuthDeg, view.elevationDeg, view.distance].join(",");
|
|
17
19
|
}
|
|
18
|
-
/** Parses `
|
|
20
|
+
/** Parses either form of `formatView`; throws a RangeError naming the field. */
|
|
19
21
|
export function parseView(text) {
|
|
20
22
|
const parts = text.split(",");
|
|
23
|
+
if (parts.length === 5 && parts[4] === "sky")
|
|
24
|
+
return parseSkyView(parts);
|
|
21
25
|
if (parts.length !== 4)
|
|
22
|
-
throw new RangeError(`view must be focus,azimuthDeg,elevationDeg,distance (4 parts), got ${parts.length}`);
|
|
26
|
+
throw new RangeError(`view must be focus,azimuthDeg,elevationDeg,distance (4 parts) or body,raDeg,decDeg,fovDeg,sky (5 parts), got ${parts.length}`);
|
|
23
27
|
const [focus, az, el, distance] = parts;
|
|
24
28
|
const numeric = (name, value) => {
|
|
25
29
|
if (value.trim() === "")
|
|
@@ -35,6 +39,22 @@ export function parseView(text) {
|
|
|
35
39
|
}
|
|
36
40
|
return validateStartView({ focus: decoded, azimuthDeg: numeric("azimuth", az), elevationDeg: numeric("elevation", el), distance: numeric("distance", distance) }, "view");
|
|
37
41
|
}
|
|
42
|
+
function parseSkyView(parts) {
|
|
43
|
+
const [body, ra, dec, fov] = parts;
|
|
44
|
+
const numeric = (name, value) => {
|
|
45
|
+
if (value.trim() === "")
|
|
46
|
+
throw new RangeError(`view ${name} is empty`);
|
|
47
|
+
return Number(value);
|
|
48
|
+
};
|
|
49
|
+
let decoded;
|
|
50
|
+
try {
|
|
51
|
+
decoded = decodeURIComponent(body);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new RangeError("view body is not valid text");
|
|
55
|
+
}
|
|
56
|
+
return validateSkyView({ lookOut: decoded, raDeg: numeric("right ascension", ra), decDeg: numeric("declination", dec), fovDeg: numeric("field of view", fov) }, "view");
|
|
57
|
+
}
|
|
38
58
|
/** The view in `?view=`, or undefined when absent or malformed (a bad link opens the experience's own view rather than failing). */
|
|
39
59
|
export function viewFromSearch(search) {
|
|
40
60
|
const raw = new URLSearchParams(search).get("view");
|
package/src/app/viewerPort.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { TimelineEvent } from "../core/events.js";
|
|
2
2
|
import type { TimeBounds } from "../core/trajectory.js";
|
|
3
3
|
import type { CameraRequest } from "./CameraController.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { CameraView } from "./viewLink.js";
|
|
5
5
|
import type { LookInput, LookRead } from "../api/look.js";
|
|
6
|
+
import type { SkyTraceAfter } from "../core/skyTrace.js";
|
|
7
|
+
import type { Provenance } from "../core/provenance.js";
|
|
6
8
|
/** The one clock's reading as a host sees it. */
|
|
7
9
|
export interface ViewerState {
|
|
8
10
|
readonly timeUtcMs: number;
|
|
@@ -17,6 +19,8 @@ export interface ViewerState {
|
|
|
17
19
|
readonly zones?: readonly string[];
|
|
18
20
|
/** The id of the object whose information the viewer has selected; absent when nothing is selected. */
|
|
19
21
|
readonly selected?: string;
|
|
22
|
+
/** The id of the story panel open; absent when none is. */
|
|
23
|
+
readonly panel?: string;
|
|
20
24
|
/** The id of the scale showing. */
|
|
21
25
|
readonly scale: string;
|
|
22
26
|
/** The looks in force, every one filled in. */
|
|
@@ -55,6 +59,23 @@ export interface ViewerControl {
|
|
|
55
59
|
setLook(look: LookInput): void;
|
|
56
60
|
/** Turns the display switch `id` (one of the keys of `read().switches`) on or off, as a visitor's switch does. */
|
|
57
61
|
setSwitch(id: string, on: boolean): void;
|
|
62
|
+
/** The sky figures the viewer draws, in the order added (id, label, kind); empty or absent when the scene added none. */
|
|
63
|
+
readonly skyFigures?: readonly {
|
|
64
|
+
readonly id: string;
|
|
65
|
+
readonly label: string;
|
|
66
|
+
readonly kind: "figure" | "boundary";
|
|
67
|
+
readonly listed: boolean;
|
|
68
|
+
readonly provenance: Provenance;
|
|
69
|
+
readonly description?: string;
|
|
70
|
+
readonly facts?: readonly {
|
|
71
|
+
readonly label: string;
|
|
72
|
+
readonly value: string;
|
|
73
|
+
}[];
|
|
74
|
+
}[];
|
|
75
|
+
/** Starts tracing a sky figure (an id from `skyFigures`, already checked), as `SkyTraceOptions` says; a trace already running on it restarts. Takes effect at the next frame, in call order with the other host calls. */
|
|
76
|
+
traceSkyFigure(id: string, seconds: number, after: SkyTraceAfter): void;
|
|
77
|
+
/** Removes a sky figure's trace (an id from `skyFigures`, already checked) over `seconds` (0: at once); none running does nothing. Takes effect at the next frame, in call order with the other host calls. */
|
|
78
|
+
clearSkyTrace(id: string, seconds: number): void;
|
|
58
79
|
/** The host's picker (`Scene.setPicker`): its id, the option values and the one pressed at the start; absent without a picker. */
|
|
59
80
|
readonly picker?: {
|
|
60
81
|
readonly id: string;
|
|
@@ -63,8 +84,14 @@ export interface ViewerControl {
|
|
|
63
84
|
};
|
|
64
85
|
/** The ids of the objects the showing view shows, which a host may point the camera at. */
|
|
65
86
|
cameraTargets(): readonly string[];
|
|
66
|
-
/** The camera as the viewer's view link writes it; undefined until the scene has drawn its first frame. */
|
|
67
|
-
readCamera():
|
|
87
|
+
/** The camera as the viewer's view link writes it (an orbit view, or a sky view while looking out); undefined until the scene has drawn its first frame. */
|
|
88
|
+
readCamera(): CameraView | undefined;
|
|
89
|
+
/** Selects the object with this id (one of `cameraTargets()`), or clears the selection (`undefined`); `read()` shows it at once. */
|
|
90
|
+
setSelected(id: string | undefined): void;
|
|
91
|
+
/** The ids of the story panels (moment panels and steps) the showing view shows, which a host may open. */
|
|
92
|
+
panels(): readonly string[];
|
|
93
|
+
/** Opens the story panel with this id (one of `panels()`), or closes the open one (`undefined`); `read()` shows it at once. */
|
|
94
|
+
setPanel(id: string | undefined): void;
|
|
68
95
|
/** Asks the scene camera for a follow, focus or pose through its own request path (the same one a view's camera rule uses). */
|
|
69
96
|
setCamera(request: CameraRequest): void;
|
|
70
97
|
}
|
|
@@ -78,6 +105,8 @@ export interface ViewerPort {
|
|
|
78
105
|
publish(state: ViewerState, cause: ViewerChangeCause): void;
|
|
79
106
|
/** The viewer's selected object changed. `byMove`: the selection followed a move of the clock or the view (a drop, or a view rule's framing target; the cause is whatever last moved them); otherwise the visitor chose it. */
|
|
80
107
|
publishSelection(state: ViewerState, byMove: boolean): void;
|
|
108
|
+
/** The viewer's open story panel changed (a visitor, a host call, playback crossing a panel, or `"move"`: a view switch dropped it, and the cause is whatever last moved the view). */
|
|
109
|
+
publishPanel(state: ViewerState, cause: ViewerChangeCause | "move"): void;
|
|
81
110
|
/** The pressed option of the host's picker now (undefined until attached and without a picker). */
|
|
82
111
|
pickNow(): string | undefined;
|
|
83
112
|
/** Calls `watcher` when the pressed option moves (the host's `setPick`, or an attach or detach); returns the function that stops it. */
|
package/src/app/views.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ export type ViewCameraRule = {
|
|
|
9
9
|
readonly rule: "start";
|
|
10
10
|
readonly framing?: {
|
|
11
11
|
readonly follow: string;
|
|
12
|
+
readonly always?: true;
|
|
12
13
|
} | {
|
|
13
14
|
readonly focus: string;
|
|
15
|
+
readonly always?: true;
|
|
14
16
|
};
|
|
15
17
|
};
|
|
16
18
|
/** One view, resolved once when the scene is built. The sets hold every id of that kind the view shows (an id no view names is in every view's set); switching only changes which set is read. */
|
package/src/assets/sky.d.ts
CHANGED
|
@@ -46,18 +46,27 @@ export interface PictureSet {
|
|
|
46
46
|
readonly licence: string;
|
|
47
47
|
readonly source: string;
|
|
48
48
|
}
|
|
49
|
-
/** One catalogue row: J2000 right ascension and declination (degrees), V magnitude, B-V colour index (null when unknown). */
|
|
50
|
-
export type StarRow = readonly [raDeg: number, decDeg: number, vMag: number, bMinusV: number | null];
|
|
49
|
+
/** One catalogue row: J2000 right ascension and declination (degrees), V magnitude, B-V colour index (null when unknown), Hipparcos number (0 or absent when HYG gives none). */
|
|
50
|
+
export type StarRow = readonly [raDeg: number, decDeg: number, vMag: number, bMinusV: number | null, hip?: number];
|
|
51
51
|
export interface StarCatalogue {
|
|
52
52
|
readonly stars: readonly StarRow[];
|
|
53
53
|
/** The file's own provenance header, if it has one. */
|
|
54
54
|
readonly provenance?: Readonly<Record<string, unknown>>;
|
|
55
55
|
}
|
|
56
|
-
/** Validates a parsed star file (`{ provenance?, stars: [[ra, dec, v, bv|null], ...] }`); throws naming the first bad row. */
|
|
56
|
+
/** Validates a parsed star file (`{ provenance?, stars: [[ra, dec, v, bv|null, hip?], ...] }`); throws naming the first bad row. */
|
|
57
57
|
export declare function parseStarFile(json: unknown): StarCatalogue;
|
|
58
58
|
/** Rights for the committed HYG star file (PROV-02). The licence covers the star file only; the Astraeus code is MIT. */
|
|
59
59
|
export declare const HYG_STAR_LICENCE: AssetLicence;
|
|
60
|
-
/**
|
|
60
|
+
/** A listed star found by its Hipparcos number: its EQJ unit direction (x, y, z) and V magnitude. */
|
|
61
|
+
export interface StarById {
|
|
62
|
+
readonly direction: Vec3;
|
|
63
|
+
readonly vMag: number;
|
|
64
|
+
}
|
|
65
|
+
/** One table from Hipparcos number to direction and magnitude, built once per star load (rows with no number, 0 or absent, are not listed). On a repeated number the first row wins. */
|
|
66
|
+
export declare function starIdTable(stars: readonly StarRow[]): ReadonlyMap<number, StarById>;
|
|
67
|
+
/** The id table of a loaded catalogue, built on first use and kept for that catalogue. */
|
|
68
|
+
export declare function starIdsOf(catalogue: StarCatalogue): ReadonlyMap<number, StarById>;
|
|
69
|
+
/** The star catalogue: the committed HYG file served with the app (read from disk in Node, by the engine's one bundled-file reader). Absent (null) when it cannot be read or is not a valid star file. */
|
|
61
70
|
export declare function loadStarCatalogue(): Promise<StarCatalogue | null>;
|
|
62
71
|
/** Temperature in kelvin from B-V (Ballesteros 2012). */
|
|
63
72
|
export declare function temperatureFromBV(bMinusV: number): number;
|
package/src/assets/sky.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// The sky behind every experience: directions at infinity in the EQJ (J2000 equatorial) frame. Frame layer only; it never
|
|
2
|
+
// touches State (ARCH-02). The stars come from the committed HYG file (tools/data/fetch-hyg-stars.mjs, CC BY-SA 4.0); the Milky Way image is committed
|
|
3
|
+
// with its licence (PROV-02).
|
|
4
|
+
import { fetchBytesOf } from "../core/readBytes.js";
|
|
1
5
|
const hygStarsUrl = new URL("./stars/hyg-v42-naked-eye.json", import.meta.url).href;
|
|
2
6
|
const RAD = Math.PI / 180;
|
|
3
7
|
// ---------------------------------------------------------------- galactic frame
|
|
@@ -53,18 +57,19 @@ export function milkyWayUv(eqj) {
|
|
|
53
57
|
// ---------------------------------------------------------------- picture (tiled)
|
|
54
58
|
/** The most a tile may measure on a side: phone GPUs commonly cap textures at 4096. */
|
|
55
59
|
export const MAX_TILE_PX = 4096;
|
|
56
|
-
/** Validates a parsed star file (`{ provenance?, stars: [[ra, dec, v, bv|null], ...] }`); throws naming the first bad row. */
|
|
60
|
+
/** Validates a parsed star file (`{ provenance?, stars: [[ra, dec, v, bv|null, hip?], ...] }`); throws naming the first bad row. */
|
|
57
61
|
export function parseStarFile(json) {
|
|
58
62
|
const file = json;
|
|
59
63
|
if (file === null || typeof file !== "object" || !Array.isArray(file.stars))
|
|
60
64
|
throw new TypeError("star file needs a stars array");
|
|
61
65
|
file.stars.forEach((row, index) => {
|
|
62
|
-
const ok = Array.isArray(row) && row.length === 4
|
|
66
|
+
const ok = Array.isArray(row) && (row.length === 4 || row.length === 5)
|
|
63
67
|
&& [0, 1, 2].every((i) => Number.isFinite(row[i]))
|
|
64
68
|
&& (row[3] === null || Number.isFinite(row[3]))
|
|
69
|
+
&& (row.length === 4 || (Number.isInteger(row[4]) && row[4] >= 0))
|
|
65
70
|
&& row[1] >= -90 && row[1] <= 90;
|
|
66
71
|
if (!ok)
|
|
67
|
-
throw new RangeError(`star ${index} must be [raDeg, decDeg, vMag, bMinusV|null]`);
|
|
72
|
+
throw new RangeError(`star ${index} must be [raDeg, decDeg, vMag, bMinusV|null, hip?]`);
|
|
68
73
|
});
|
|
69
74
|
const provenance = file.provenance !== null && typeof file.provenance === "object" ? file.provenance : undefined;
|
|
70
75
|
return { stars: file.stars, ...(provenance === undefined ? {} : { provenance }) };
|
|
@@ -74,20 +79,40 @@ export const HYG_STAR_LICENCE = Object.freeze({
|
|
|
74
79
|
source: "HYG database v4.2 (Hipparcos, Yale Bright Star, Gliese catalogues), astronexus",
|
|
75
80
|
url: "https://www.astronexus.com/projects/hyg",
|
|
76
81
|
licence: "CC BY-SA 4.0",
|
|
77
|
-
attribution: "HYG database v4.2, astronexus (astronexus.com), CC BY-SA 4.0. Stars of V 6.5 or brighter kept, right ascension converted from hours to degrees; no other change.",
|
|
78
|
-
accessed: "2026-10
|
|
82
|
+
attribution: "HYG database v4.2, astronexus (astronexus.com), CC BY-SA 4.0. Stars of V 6.5 or brighter kept, right ascension converted from hours to degrees, Hipparcos number added; no other change.",
|
|
83
|
+
accessed: "2026-11-10",
|
|
79
84
|
});
|
|
85
|
+
/** One table from Hipparcos number to direction and magnitude, built once per star load (rows with no number, 0 or absent, are not listed). On a repeated number the first row wins. */
|
|
86
|
+
export function starIdTable(stars) {
|
|
87
|
+
const table = new Map();
|
|
88
|
+
for (const row of stars) {
|
|
89
|
+
const hip = row[4];
|
|
90
|
+
if (hip === undefined || hip <= 0 || table.has(hip))
|
|
91
|
+
continue;
|
|
92
|
+
table.set(hip, { direction: eqjUnit(row[0], row[1]), vMag: row[2] });
|
|
93
|
+
}
|
|
94
|
+
return table;
|
|
95
|
+
}
|
|
96
|
+
const starIdCache = new WeakMap();
|
|
97
|
+
/** The id table of a loaded catalogue, built on first use and kept for that catalogue. */
|
|
98
|
+
export function starIdsOf(catalogue) {
|
|
99
|
+
let table = starIdCache.get(catalogue);
|
|
100
|
+
if (table === undefined) {
|
|
101
|
+
table = starIdTable(catalogue.stars);
|
|
102
|
+
starIdCache.set(catalogue, table);
|
|
103
|
+
}
|
|
104
|
+
return table;
|
|
105
|
+
}
|
|
80
106
|
let starRequest;
|
|
81
107
|
async function fetchStarFile(url) {
|
|
82
108
|
try {
|
|
83
|
-
|
|
84
|
-
return response.ok ? parseStarFile(JSON.parse(await response.text())) : null;
|
|
109
|
+
return parseStarFile(JSON.parse(new TextDecoder().decode(await fetchBytesOf(url))));
|
|
85
110
|
}
|
|
86
111
|
catch {
|
|
87
112
|
return null;
|
|
88
113
|
}
|
|
89
114
|
}
|
|
90
|
-
/** The star catalogue: the committed HYG file served with the app. Absent (null) when it cannot be read or is not a valid star file. */
|
|
115
|
+
/** The star catalogue: the committed HYG file served with the app (read from disk in Node, by the engine's one bundled-file reader). Absent (null) when it cannot be read or is not a valid star file. */
|
|
91
116
|
export function loadStarCatalogue() {
|
|
92
117
|
starRequest ??= fetchStarFile(hygStarsUrl);
|
|
93
118
|
return starRequest;
|