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
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Color } from "three";
|
|
3
|
+
import { isFontFamily } from "../core/lookValues.js";
|
|
4
|
+
import { LABEL_SIZE_LIMITS } from "./labelStyle.js";
|
|
2
5
|
import { GLOW_LIMITS } from "./bodyDraw.js";
|
|
3
6
|
import { BODY_SET_LOOK_LIMITS, DEFAULT_BODY_SET_LOOK, familyColorOf } from "./bodySet.js";
|
|
4
7
|
import { ringBandsWithLook } from "../assets/rings.js";
|
|
@@ -7,6 +10,7 @@ import { MAX_PANEL_PAUSE_SECONDS } from "../shell/storyPanels.js";
|
|
|
7
10
|
import { DebugOverlay } from "./DebugOverlay.js";
|
|
8
11
|
import { FrameRateSection } from "./FrameRateSection.js";
|
|
9
12
|
import { formatView } from "./viewLink.js";
|
|
13
|
+
import { isSkyView } from "../core/startView.js";
|
|
10
14
|
import { HudSection, SettingButtons, SettingColor, SettingGroup, SettingSlider } from "./SettingControls.js";
|
|
11
15
|
export function StoryPanelSettings({ storyAutoOpen, setStoryAutoOpen, storyPauseSeconds, setStoryPauseSeconds }) {
|
|
12
16
|
return (_jsxs(SettingGroup, { name: "story-panels", title: "Story panels", children: [_jsx(SettingButtons, { children: _jsx("button", { "aria-pressed": storyAutoOpen, onClick: () => setStoryAutoOpen(!storyAutoOpen), children: "Open panels automatically" }) }), _jsx(SettingSlider, { label: "Pause when a panel opens (s)", ariaLabel: "Story panel pause", testId: "story-pause-value", display: storyPauseSeconds === 0 ? "off" : storyPauseSeconds.toFixed(1), min: 0, max: MAX_PANEL_PAUSE_SECONDS, step: 0.5, value: storyPauseSeconds, onChange: setStoryPauseSeconds })] }));
|
|
@@ -17,8 +21,14 @@ export function MoonsAndRingsSettings({ bodySets, ringSystems, setLook, changeSe
|
|
|
17
21
|
export function SkyAndSunSettings({ illuminateAll, setIlluminateAll, visible, glowShown, setGlowShown, controls, milkyWayOn, setMilkyWayOn, starBrightness, setStarBrightness, milkyWayBrightness, setMilkyWayBrightness }) {
|
|
18
22
|
return (_jsxs(_Fragment, { children: [_jsx(SettingGroup, { name: "lighting", title: "Lighting", children: _jsx(SettingButtons, { children: _jsx("button", { "aria-pressed": illuminateAll, "aria-label": "Illuminate all", onClick: () => { controls.current.illuminateAll = !illuminateAll; setIlluminateAll(!illuminateAll); }, children: "Illuminate all" }) }) }), visible && (_jsxs(SettingGroup, { name: "sky", title: "Sky", children: [_jsx(SettingButtons, { children: _jsx("button", { "aria-pressed": milkyWayOn, onClick: () => { controls.current.showMilkyWay = !milkyWayOn; setMilkyWayOn(!milkyWayOn); }, children: "Milky Way picture" }) }), _jsx(SettingSlider, { label: "Star brightness", ariaLabel: "Star brightness", testId: "star-brightness-value", display: starBrightness.toFixed(2), min: 0, max: 2, step: 0.05, value: starBrightness, onChange: (value) => { controls.current.starBrightness = value; setStarBrightness(value); } }), _jsx(SettingSlider, { label: "Milky Way brightness", ariaLabel: "Milky Way brightness", testId: "milky-way-brightness-value", display: milkyWayBrightness.toFixed(2), min: 0, max: 2, step: 0.05, value: milkyWayBrightness, onChange: (value) => { controls.current.milkyWayBrightness = value; setMilkyWayBrightness(value); } })] })), glowShown !== null && (_jsxs(SettingGroup, { name: "glow", title: "Sun glow", children: [_jsx(SettingSlider, { label: "Glow size (px)", ariaLabel: "Sun glow size", testId: "sun-glow-size-value", display: glowShown.sizePx.toFixed(0), min: GLOW_LIMITS.sizePx.min, max: GLOW_LIMITS.sizePx.max, step: 1, value: glowShown.sizePx, onChange: (value) => { controls.current.glowLook.sizePx = value; setGlowShown({ ...controls.current.glowLook }); } }), _jsx(SettingSlider, { label: "Glow brightness", ariaLabel: "Sun glow brightness", testId: "sun-glow-brightness-value", display: glowShown.brightness.toFixed(2), min: GLOW_LIMITS.brightness.min, max: GLOW_LIMITS.brightness.max, step: 0.05, value: glowShown.brightness, onChange: (value) => { controls.current.glowLook.brightness = value; setGlowShown({ ...controls.current.glowLook }); } }), _jsx(SettingSlider, { label: "Glow reach (\u00D7 disc)", ariaLabel: "Sun glow reach", testId: "sun-glow-scale-value", display: glowShown.scale.toFixed(1), min: GLOW_LIMITS.scale.min, max: GLOW_LIMITS.scale.max, step: 0.1, value: glowShown.scale, onChange: (value) => { controls.current.glowLook.scale = value; setGlowShown({ ...controls.current.glowLook }); } })] }))] }));
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
/** A colour input takes `#rrggbb` only; the look may hold any CSS colour the viewer accepts, so show it as hex. */
|
|
25
|
+
const hexOf = (colour) => `#${new Color(colour).getHexString()}`;
|
|
26
|
+
const SKY_COLOUR_ROWS = [["figure", "Figure lines"], ["label", "Figure names"], ["boundary", "Outlines"], ["ecliptic", "Ecliptic"], ["equator", "Celestial equator"], ["traced", "Traced lines"], ["faded", "Faded lines"], ["selected", "Selected figure"]];
|
|
27
|
+
export function LabelSettings({ controls, hoverBrightness, setHoverBrightness, labelToggles, trackedCount, anchorLabels, setAnchorLabels, hiddenLabels, setHiddenLabels, labelStyle, setLabelStyle, skyColours, setSkyColours, hasSky }) {
|
|
28
|
+
return (_jsxs(_Fragment, { children: [_jsx(SettingSlider, { label: "Hover name brightness", ariaLabel: "Hover name brightness", testId: "hover-brightness-value", display: hoverBrightness.toFixed(2), min: HOVER_BRIGHTNESS_LIMITS.min, max: HOVER_BRIGHTNESS_LIMITS.max, step: 0.05, value: hoverBrightness, onChange: (value) => { controls.current.hoverBrightness = value; setHoverBrightness(value); } }), _jsx(SettingSlider, { label: "Label size (px)", ariaLabel: "Label size", testId: "label-size-value", display: labelStyle.sizePx.toFixed(0), min: LABEL_SIZE_LIMITS.min, max: LABEL_SIZE_LIMITS.max, step: 1, value: labelStyle.sizePx, onChange: (sizePx) => { controls.current.labelStyle = { ...controls.current.labelStyle, sizePx }; setLabelStyle(controls.current.labelStyle); } }), _jsxs("label", { className: "setting", children: [_jsx("span", { className: "setting-label", children: "Label font" }), _jsx("input", { type: "text", "aria-label": "Label font", "data-testid": "label-font", defaultValue: labelStyle.fontFamily, spellCheck: false, onChange: (event) => { if (isFontFamily(event.target.value)) {
|
|
29
|
+
controls.current.labelStyle = { ...controls.current.labelStyle, fontFamily: event.target.value.trim() };
|
|
30
|
+
setLabelStyle(controls.current.labelStyle);
|
|
31
|
+
} } })] }), hasSky && (_jsx(SettingGroup, { name: "sky-line-colours", title: "Sky line colours", children: SKY_COLOUR_ROWS.map(([key, label]) => (_jsx(SettingColor, { label: label, ariaLabel: `Sky ${label} colour`, testId: `sky-colour-${key}`, value: hexOf(skyColours[key]), onChange: (value) => { controls.current.skyColours = { ...controls.current.skyColours, [key]: value }; setSkyColours(controls.current.skyColours); } }, key))) })), (labelToggles.length > 0 || trackedCount > 0) && _jsxs(SettingButtons, { children: [trackedCount > 0 && _jsx("button", { "aria-pressed": anchorLabels, onClick: () => { controls.current.showAnchorLabels = !anchorLabels; setAnchorLabels(!anchorLabels); }, children: "Anchor labels" }), labelToggles.map((object) => (_jsx("button", { "aria-pressed": !hiddenLabels.has(object.id), onClick: () => {
|
|
22
32
|
const hidden = controls.current.hiddenLabels ?? new Set();
|
|
23
33
|
if (hidden.has(object.id))
|
|
24
34
|
hidden.delete(object.id);
|
|
@@ -29,7 +39,7 @@ export function LabelSettings({ controls, hoverBrightness, setHoverBrightness, l
|
|
|
29
39
|
}, children: `${object.label} label` }, object.id)))] })] }));
|
|
30
40
|
}
|
|
31
41
|
export function ViewLinkReadout({ viewNow, viewLink, scale, upChoice }) {
|
|
32
|
-
return (_jsxs(_Fragment, { children: [viewNow !== null && _jsx("p", { className: "view-link-values", "data-testid": "view-values", children: `View: ${formatView(viewNow).replace(/%2C/g, ",")} (focus, azimuth °, elevation °, distance) · scale ${scale} · up ${upChoice}` }), viewLink !== null && (_jsxs("p", { className: "view-link-field", children: [_jsx("input", { readOnly: true, "aria-label": "View link", "data-testid": "view-link", value: viewLink.url, onFocus: (event) => event.currentTarget.select() }), _jsx("span", { children: viewLink.copied ? "Copied to the clipboard." : "Clipboard unavailable: select the link above and copy it." })] }))] }));
|
|
42
|
+
return (_jsxs(_Fragment, { children: [viewNow !== null && _jsx("p", { className: "view-link-values", "data-testid": "view-values", children: `View: ${formatView(viewNow).replace(/%2C/g, ",")} ${isSkyView(viewNow) ? "(body, right ascension °, declination °, field of view °, sky)" : "(focus, azimuth °, elevation °, distance)"} · scale ${scale} · up ${upChoice}` }), viewLink !== null && (_jsxs("p", { className: "view-link-field", children: [_jsx("input", { readOnly: true, "aria-label": "View link", "data-testid": "view-link", value: viewLink.url, onFocus: (event) => event.currentTarget.select() }), _jsx("span", { children: viewLink.copied ? "Copied to the clipboard." : "Clipboard unavailable: select the link above and copy it." })] }))] }));
|
|
33
43
|
}
|
|
34
44
|
export function UnderTheHoodSettings({ hud, frames, fills, fpsHistory }) {
|
|
35
45
|
return (_jsxs(_Fragment, { children: [hud !== null && (_jsx(HudSection, { level: 4, heading: "Scene instrumentation", children: _jsx(DebugOverlay, { readout: hud }) })), _jsx(FrameRateSection, { frames: frames, fills: fills, fpsHistory: fpsHistory })] }));
|
package/src/app/SceneLabels.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { type Camera } from "three";
|
|
|
2
2
|
import type { ExperienceObject } from "../shell/experience.js";
|
|
3
3
|
import type { FloatingOrigin } from "./floatingOrigin.js";
|
|
4
4
|
import type { RenderVector } from "./renderCoordinates.js";
|
|
5
|
+
import type { SkyLabelSpec } from "./SkyFiguresView.js";
|
|
6
|
+
import type { SkyLineSwitches } from "./skyFigures.js";
|
|
5
7
|
interface Rect {
|
|
6
8
|
readonly left: number;
|
|
7
9
|
readonly top: number;
|
|
@@ -18,15 +20,31 @@ export declare const LABEL_PADDING_PX = 6;
|
|
|
18
20
|
* One rule for every label; the selected label is placed first and never loses a collision (I-108).
|
|
19
21
|
*/
|
|
20
22
|
export declare const LABEL_REAPPEAR_MARGIN_PX = 14;
|
|
23
|
+
/** Sky labels rank below every object label, so a name on the sky never hides a body's (figures above outlines). */
|
|
24
|
+
export declare const SKY_LABEL_PRIORITY: {
|
|
25
|
+
readonly figure: -10;
|
|
26
|
+
readonly boundary: -20;
|
|
27
|
+
};
|
|
28
|
+
/** Where the sky labels stand this frame: which kinds show, and the distance (render units) from the camera they are projected at. */
|
|
29
|
+
export interface SkyLabelFrame {
|
|
30
|
+
readonly on: Readonly<SkyLineSwitches>;
|
|
31
|
+
readonly distance: number;
|
|
32
|
+
/** The look's colour for a sky label that has no colour of its own. */
|
|
33
|
+
readonly labelColor: string;
|
|
34
|
+
/** The look's colour for the selected sky figure's name. */
|
|
35
|
+
readonly selectedColor?: string;
|
|
36
|
+
/** How much of a sky label shows, 0 (not drawn) to 1; absent: all show. */
|
|
37
|
+
readonly opacity?: (id: string) => number;
|
|
38
|
+
}
|
|
21
39
|
/** App adapter that places configured labels; the label presentation itself stays generic. */
|
|
22
40
|
export declare class SceneLabelLayer {
|
|
23
41
|
#private;
|
|
24
|
-
constructor(host: HTMLElement, objects: readonly ExperienceObject[]);
|
|
42
|
+
constructor(host: HTMLElement, objects: readonly ExperienceObject[], skyLabels?: readonly SkyLabelSpec[]);
|
|
25
43
|
/** The page rectangles of the labels shown after the latest update, by object id: the targets a tap on a name can hit. */
|
|
26
44
|
get shownRects(): ReadonlyMap<string, Rect>;
|
|
27
45
|
/** Brightens the name of the hovered object by `gain` (1 leaves it alone); null clears it. */
|
|
28
46
|
setHover(id: string | null, gain: number): void;
|
|
29
|
-
update(positionFor: (objectId: string) => RenderVector | null, camera: Camera, widthPx: number, heightPx: number, origin: FloatingOrigin, selectedObjectId: string, hiddenIds?: ReadonlySet<string
|
|
47
|
+
update(positionFor: (objectId: string) => RenderVector | null, camera: Camera, widthPx: number, heightPx: number, origin: FloatingOrigin, selectedObjectId: string, hiddenIds?: ReadonlySet<string>, sky?: SkyLabelFrame): void;
|
|
30
48
|
dispose(): void;
|
|
31
49
|
}
|
|
32
50
|
export {};
|
package/src/app/SceneLabels.js
CHANGED
|
@@ -11,19 +11,36 @@ export const LABEL_PADDING_PX = 6;
|
|
|
11
11
|
* One rule for every label; the selected label is placed first and never loses a collision (I-108).
|
|
12
12
|
*/
|
|
13
13
|
export const LABEL_REAPPEAR_MARGIN_PX = 14;
|
|
14
|
+
/** Sky labels rank below every object label, so a name on the sky never hides a body's (figures above outlines). */
|
|
15
|
+
export const SKY_LABEL_PRIORITY = { figure: -10, boundary: -20 };
|
|
16
|
+
/** How much of a sky label shows, 0 to 1 (1 for an object label and where the frame names no rule). */
|
|
17
|
+
const skyOpacity = (spec, sky) => (spec === undefined ? 1 : sky?.opacity?.(spec.id) ?? 1);
|
|
14
18
|
/** App adapter that places configured labels; the label presentation itself stays generic. */
|
|
15
19
|
export class SceneLabelLayer {
|
|
16
20
|
#root = document.createElement("div");
|
|
17
21
|
#entries;
|
|
18
22
|
#local = new Vector3();
|
|
23
|
+
#direction = new Vector3();
|
|
19
24
|
#shown = new Map();
|
|
20
25
|
/** Per object id, whether the latest layout showed it; absent when it was not a candidate (unplaced, out of reach or switched off). */
|
|
21
26
|
#lastShown = new Map();
|
|
22
|
-
|
|
27
|
+
#sky;
|
|
28
|
+
/** The colour last set on each sky label (by id), so a change of look or selection repaints only what changed. */
|
|
29
|
+
#skyColours = new Map();
|
|
30
|
+
constructor(host, objects, skyLabels = []) {
|
|
23
31
|
this.#root.className = "scene-labels";
|
|
24
|
-
|
|
32
|
+
// A sky label is an object-like entry (its id, text and colour) with a priority below every object's and a place at infinity; it joins the one layout below, so it collides and keeps its place by the same rule.
|
|
33
|
+
const asObjects = [...objects, ...skyLabels.map((spec) => ({ id: spec.id, label: spec.label, ...(spec.color === undefined ? {} : { color: spec.color }), labelPriority: SKY_LABEL_PRIORITY[spec.kind] }))];
|
|
34
|
+
this.#sky = new Map(skyLabels.map((spec) => [spec.id, spec]));
|
|
35
|
+
this.#entries = asObjects.map((object) => {
|
|
25
36
|
const element = createLabelElement(object.label, object.color, "scene-object-label");
|
|
26
37
|
element.dataset.labelId = object.id;
|
|
38
|
+
// A figure's own font and size go on its label through the same variables the viewer root sets for every label.
|
|
39
|
+
const own = this.#sky.get(object.id);
|
|
40
|
+
if (own?.font !== undefined)
|
|
41
|
+
element.style.setProperty("--label-font", own.font);
|
|
42
|
+
if (own?.sizePx !== undefined)
|
|
43
|
+
element.style.setProperty("--label-size", `${own.sizePx}px`);
|
|
27
44
|
element.hidden = true; // not shown until the first layout places it (I-108: unplaced labels all showed for a moment, so a reader could see a label the settled layout then hides)
|
|
28
45
|
this.#root.appendChild(element);
|
|
29
46
|
return { object, element };
|
|
@@ -39,8 +56,21 @@ export class SceneLabelLayer {
|
|
|
39
56
|
for (const entry of this.#entries)
|
|
40
57
|
entry.element.style.filter = entry.object.id === id && gain !== 1 ? `brightness(${gain})` : "";
|
|
41
58
|
}
|
|
42
|
-
update(positionFor, camera, widthPx, heightPx, origin, selectedObjectId, hiddenIds) {
|
|
59
|
+
update(positionFor, camera, widthPx, heightPx, origin, selectedObjectId, hiddenIds, sky) {
|
|
43
60
|
camera.updateMatrixWorld(true);
|
|
61
|
+
if (sky !== undefined) {
|
|
62
|
+
// A sky label takes its figure's own colour, else the look's; the selected figure's name takes the look's selected colour.
|
|
63
|
+
for (const entry of this.#entries) {
|
|
64
|
+
const spec = this.#sky.get(entry.object.id);
|
|
65
|
+
if (spec === undefined)
|
|
66
|
+
continue;
|
|
67
|
+
const colour = entry.object.id === selectedObjectId ? sky.selectedColor ?? sky.labelColor : spec.color ?? sky.labelColor;
|
|
68
|
+
if (this.#skyColours.get(spec.id) !== colour) {
|
|
69
|
+
this.#skyColours.set(spec.id, colour);
|
|
70
|
+
entry.element.style.setProperty("--label-color", colour);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
44
74
|
this.#shown.clear();
|
|
45
75
|
const previous = new Map(this.#lastShown);
|
|
46
76
|
this.#lastShown.clear();
|
|
@@ -49,12 +79,22 @@ export class SceneLabelLayer {
|
|
|
49
79
|
entry.element.hidden = true;
|
|
50
80
|
return [];
|
|
51
81
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
82
|
+
const spec = this.#sky.get(entry.object.id);
|
|
83
|
+
const absolute = spec === undefined ? positionFor(entry.object.id) : null;
|
|
84
|
+
const opacity = skyOpacity(spec, sky);
|
|
85
|
+
const skyShown = spec !== undefined && sky !== undefined && opacity > 0 && sky.on[spec.kind === "figure" ? "figures" : "boundaries"];
|
|
86
|
+
if (spec === undefined ? absolute === null : !skyShown) {
|
|
54
87
|
entry.element.hidden = true;
|
|
55
88
|
return [];
|
|
56
89
|
}
|
|
57
|
-
|
|
90
|
+
if (spec !== undefined)
|
|
91
|
+
entry.element.style.opacity = String(opacity);
|
|
92
|
+
// A sky label is projected from the camera's own place, at a fixed distance along its direction: it never moves with the scene, only with the camera's turn.
|
|
93
|
+
if (spec !== undefined)
|
|
94
|
+
this.#local.copy(camera.position).addScaledVector(this.#direction.fromArray(spec.direction), sky.distance);
|
|
95
|
+
else
|
|
96
|
+
this.#local.fromArray(origin.toLocal(absolute));
|
|
97
|
+
const screen = projectToScreen(this.#local, camera, widthPx, heightPx);
|
|
58
98
|
const distance = this.#local.distanceTo(camera.position);
|
|
59
99
|
const maxDistance = entry.object.labelMaxDistance ?? Number.POSITIVE_INFINITY;
|
|
60
100
|
if (screen === null || distance > maxDistance) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Group } from "three";
|
|
2
|
+
import type { PerspectiveCamera } from "three";
|
|
3
|
+
import { type SkyColours, type SkyFigureLayer, type SkyClearRequest, type SkyLineSwitches, type SkyTraceRequest } from "./skyFigures.js";
|
|
4
|
+
import { type RenderVector } from "./renderCoordinates.js";
|
|
5
|
+
import { type PickRect, type SkyPickFigure } from "./scenePicking.js";
|
|
6
|
+
/** One label to place on the sky: its text and unit render-frame direction, the kind (the switch that shows it) and the figure's own colour, font and size when it has them (else the looks apply). */
|
|
7
|
+
export interface SkyLabelSpec {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly color?: string;
|
|
11
|
+
readonly font?: string;
|
|
12
|
+
readonly sizePx?: number;
|
|
13
|
+
readonly kind: "figure" | "boundary";
|
|
14
|
+
/** True: the label shows only while a trace of the figure runs or stays (`labelOpacity`). */
|
|
15
|
+
readonly whenTraced?: boolean;
|
|
16
|
+
readonly direction: RenderVector;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Figures, outlines and the two reference circles, drawn at infinity like the stars: the group stands on the camera every frame and is scaled to sit between the near and far planes,
|
|
20
|
+
* so only the camera's orientation matters. Carries no State (ARCH-02). The ecliptic and the equator are built the first time they are switched on.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SkyFiguresView {
|
|
23
|
+
#private;
|
|
24
|
+
readonly group: Group<import("three").Object3DEventMap>;
|
|
25
|
+
readonly labels: readonly SkyLabelSpec[];
|
|
26
|
+
constructor(layers: readonly SkyFigureLayer[]);
|
|
27
|
+
/** Stands the group on the camera, sized between its planes, shows the kinds the switches say (building a reference circle the first time it shows) and paints the lines in the colours given. */
|
|
28
|
+
place(camera: PerspectiveCamera, on: Readonly<SkyLineSwitches>, colours: Readonly<SkyColours>, selectedId?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* The figures a tap can select, as screen lines (CSS px from the canvas's top left) and the rectangle of each shown name (`labelRects` are page rectangles; `box` is the canvas's). A figure whose switch is off, or that is
|
|
31
|
+
* shown only when traced and has no trace showing, is left out. A segment is kept whenever any part of it is in front of the camera (cut at the camera plane), even with both ends off screen. Worked out when asked, not each frame.
|
|
32
|
+
*/
|
|
33
|
+
screenFigures(camera: PerspectiveCamera, widthPx: number, heightPx: number, on: Readonly<SkyLineSwitches>, labelRects: ReadonlyMap<string, PickRect> | undefined, box: {
|
|
34
|
+
readonly left: number;
|
|
35
|
+
readonly top: number;
|
|
36
|
+
}): readonly SkyPickFigure[];
|
|
37
|
+
/** Begins tracing the figure `request.id` (a trace already on it restarts). The trace is a separate set of lines drawn over the figure (the whole drawing of a figure shown only when traced); the figure itself is untouched. An id the view does not hold does nothing. */
|
|
38
|
+
startTrace(request: SkyTraceRequest): void;
|
|
39
|
+
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. */
|
|
40
|
+
clearTrace(request: SkyClearRequest): void;
|
|
41
|
+
/**
|
|
42
|
+
* Moves every trace on by `deltaSeconds` of real time (the scene clock never enters): draws the segments reached so far, the last one part-grown from its first end, in the traced colour (the faded colour while fading),
|
|
43
|
+
* shows each with its figure's switch, and removes finished ones. Returns true while anything changed, so the caller wakes the draw rule.
|
|
44
|
+
*/
|
|
45
|
+
advanceTraces(deltaSeconds: number, colours: Readonly<SkyColours>, on: Readonly<SkyLineSwitches>, selectedId?: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Moves the fade-in of every kind of line on by `deltaSeconds` of real time over `seconds` (0: at once), and sets the lines' opacity; a kind whose switch is off goes back to 0 so it fades in again
|
|
48
|
+
* when it next turns on. Returns true while a fade-in is still running, so the caller wakes the draw rule.
|
|
49
|
+
*/
|
|
50
|
+
advanceFadeIn(deltaSeconds: number, seconds: number, on: Readonly<SkyLineSwitches>): boolean;
|
|
51
|
+
/** How much of a label shows, 0 to 1: for a figure that is always shown, how far its kind has faded in; for one shown only when traced, 0 until a trace starts, then rising with the trace to 1 at half drawn (fading to 0 with a `fade` trace; 0 again once the trace is removed). */
|
|
52
|
+
labelOpacity(id: string): number;
|
|
53
|
+
/** Which lines are shown now, by name (read by tests and the canvas data). */
|
|
54
|
+
get shown(): readonly string[];
|
|
55
|
+
dispose(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { BufferAttribute, BufferGeometry, Color, Group, LineBasicMaterial, LineSegments, Vector3 } from "three";
|
|
2
|
+
import { celestialEquatorSegments, eclipticSegments } from "./skyFigures.js";
|
|
3
|
+
import { stepFadeIn, stepHide, stepTrace } from "../core/skyTrace.js";
|
|
4
|
+
import { eqjToRenderVector } from "./renderCoordinates.js";
|
|
5
|
+
import { TRACK_LAYER } from "./TrackedBodyView.js";
|
|
6
|
+
import { projectSegmentClipped } from "./scenePicking.js";
|
|
7
|
+
const FADED = new Color();
|
|
8
|
+
const TRACE_OPACITY = 0.85;
|
|
9
|
+
/** The share of a trace over which the name of a figure shown only when traced fades in (owner, T-306: it no longer appears at once). */
|
|
10
|
+
const TRACE_LABEL_IN_SHARE = 0.5;
|
|
11
|
+
/** The opacity of an always-shown line once it has faded in. */
|
|
12
|
+
const LINE_OPACITY = 0.85;
|
|
13
|
+
function lines(segments, color, key) {
|
|
14
|
+
const positions = new Float32Array(segments.length * 6);
|
|
15
|
+
segments.forEach(([from, to], i) => positions.set([...eqjToRenderVector(from), ...eqjToRenderVector(to)], i * 6));
|
|
16
|
+
const geometry = new BufferGeometry();
|
|
17
|
+
geometry.setAttribute("position", new BufferAttribute(positions, 3));
|
|
18
|
+
// Depth is tested (a body in front of the sky hides the line) but never written. The lines are on the last render pass (TRACK_LAYER), after every body's pass, so the Sun's halo
|
|
19
|
+
// (drawn earlier, without depth) never covers them (owner decision 3, O-065).
|
|
20
|
+
const material = new LineBasicMaterial({ color, transparent: true, opacity: LINE_OPACITY, depthTest: true, depthWrite: false });
|
|
21
|
+
const object = new LineSegments(geometry, material);
|
|
22
|
+
object.name = key;
|
|
23
|
+
object.layers.set(TRACK_LAYER);
|
|
24
|
+
object.frustumCulled = false;
|
|
25
|
+
object.renderOrder = 1;
|
|
26
|
+
return object;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Figures, outlines and the two reference circles, drawn at infinity like the stars: the group stands on the camera every frame and is scaled to sit between the near and far planes,
|
|
30
|
+
* so only the camera's orientation matters. Carries no State (ARCH-02). The ecliptic and the equator are built the first time they are switched on.
|
|
31
|
+
*/
|
|
32
|
+
export class SkyFiguresView {
|
|
33
|
+
group = new Group();
|
|
34
|
+
#drawn = [];
|
|
35
|
+
#applied = null;
|
|
36
|
+
labels;
|
|
37
|
+
#layers;
|
|
38
|
+
#traces = new Map();
|
|
39
|
+
/** The emphasis lines over the selected figure (one set at most), built when the selection first names a figure. */
|
|
40
|
+
#selected = null;
|
|
41
|
+
#point = new Vector3();
|
|
42
|
+
/** How far each kind of line (and its names) has faded in since its switch last turned on, 0 to 1; 0 while the switch is off, so the next turn-on fades in again. */
|
|
43
|
+
#shownShare = { figures: 0, boundaries: 0, ecliptic: 0, celestialEquator: 0 };
|
|
44
|
+
constructor(layers) {
|
|
45
|
+
this.#layers = new Map(layers.map((layer) => [layer.id, layer]));
|
|
46
|
+
const add = (segments, shows, colour, key, own) => {
|
|
47
|
+
if (segments.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
const object = lines(segments, own ?? "#ffffff", key);
|
|
50
|
+
this.#drawn.push({ object, shows, colour, own: own !== undefined });
|
|
51
|
+
this.group.add(object);
|
|
52
|
+
};
|
|
53
|
+
// Figures that take the look's colour share one set of lines per kind; a figure with its own colour is drawn on its own so a live look change leaves it alone.
|
|
54
|
+
for (const [kind, shows, key] of [["figure", "figures", "sky-figures"], ["boundary", "boundaries", "sky-boundaries"]]) {
|
|
55
|
+
const of = layers.filter((layer) => layer.kind === kind && layer.whenTraced !== true); // a figure shown only when traced has no lines of its own: its trace is the whole drawing
|
|
56
|
+
add(of.filter((layer) => layer.color === undefined).flatMap((layer) => layer.segments), shows, kind, key);
|
|
57
|
+
for (const layer of of)
|
|
58
|
+
if (layer.color !== undefined)
|
|
59
|
+
add(layer.segments, shows, kind, `${key}:${layer.id}`, layer.color);
|
|
60
|
+
}
|
|
61
|
+
this.labels = layers.map((layer) => ({
|
|
62
|
+
id: layer.id, label: layer.label, kind: layer.kind, direction: eqjToRenderVector(layer.labelAt), ...(layer.whenTraced === true ? { whenTraced: true } : {}),
|
|
63
|
+
...(layer.labelColor === undefined ? {} : { color: layer.labelColor }), ...(layer.labelFont === undefined ? {} : { font: layer.labelFont }), ...(layer.labelSizePx === undefined ? {} : { sizePx: layer.labelSizePx }),
|
|
64
|
+
}));
|
|
65
|
+
this.group.name = "sky-lines";
|
|
66
|
+
}
|
|
67
|
+
/** Stands the group on the camera, sized between its planes, shows the kinds the switches say (building a reference circle the first time it shows) and paints the lines in the colours given. */
|
|
68
|
+
place(camera, on, colours, selectedId = "") {
|
|
69
|
+
this.group.position.copy(camera.position);
|
|
70
|
+
this.group.scale.setScalar(0.5 * (camera.near + camera.far));
|
|
71
|
+
for (const [shows, colour, make, key] of [["ecliptic", "ecliptic", eclipticSegments, "sky-ecliptic"], ["celestialEquator", "equator", celestialEquatorSegments, "sky-celestial-equator"]]) {
|
|
72
|
+
if (on[shows] && !this.#drawn.some((entry) => entry.shows === shows)) {
|
|
73
|
+
const object = lines(make(), "#ffffff", key);
|
|
74
|
+
this.#drawn.push({ object, shows, colour, own: false });
|
|
75
|
+
this.group.add(object);
|
|
76
|
+
this.#applied = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (this.#applied === null || Object.keys(colours).some((name) => colours[name] !== this.#applied[name])) {
|
|
80
|
+
for (const entry of this.#drawn)
|
|
81
|
+
if (!entry.own)
|
|
82
|
+
entry.object.material.color.set(colours[entry.colour]);
|
|
83
|
+
this.#applied = { ...colours };
|
|
84
|
+
}
|
|
85
|
+
for (const entry of this.#drawn)
|
|
86
|
+
entry.object.visible = on[entry.shows];
|
|
87
|
+
this.#emphasise(selectedId, on, colours);
|
|
88
|
+
}
|
|
89
|
+
/** Whether a tap or the emphasis can reach the figure now: its kind's switch is on and, for one shown only when traced, a trace shows it. */
|
|
90
|
+
#tappable(layer, on) {
|
|
91
|
+
return on[layer.kind === "figure" ? "figures" : "boundaries"] && (layer.whenTraced !== true || (this.#traces.get(layer.id)?.fade ?? 1) < 1);
|
|
92
|
+
}
|
|
93
|
+
/** True while a trace of `id` is still growing (not yet fully drawn, and not being cleared). */
|
|
94
|
+
#drawing(id) {
|
|
95
|
+
const trace = this.#traces.get(id);
|
|
96
|
+
return trace !== undefined && trace.hide === undefined && trace.drawn < 1;
|
|
97
|
+
}
|
|
98
|
+
/** Draws the selected figure's lines over it in the look's `selected` colour (and removes them when the selection moves or is not a figure); the name takes the same colour in the label layer. */
|
|
99
|
+
#emphasise(selectedId, on, colours) {
|
|
100
|
+
const layer = this.#layers.get(selectedId);
|
|
101
|
+
if (this.#selected !== null && this.#selected.id !== layer?.id) {
|
|
102
|
+
this.group.remove(this.#selected.object);
|
|
103
|
+
this.#selected.object.geometry.dispose();
|
|
104
|
+
this.#selected.object.material.dispose();
|
|
105
|
+
this.#selected = null;
|
|
106
|
+
}
|
|
107
|
+
if (layer === undefined)
|
|
108
|
+
return;
|
|
109
|
+
if (this.#selected === null) {
|
|
110
|
+
const object = lines(layer.segments, colours.selected, `sky-selected:${layer.id}`);
|
|
111
|
+
object.renderOrder = 3;
|
|
112
|
+
this.group.add(object);
|
|
113
|
+
this.#selected = { id: layer.id, object };
|
|
114
|
+
}
|
|
115
|
+
const material = this.#selected.object.material;
|
|
116
|
+
material.color.set(colours.selected);
|
|
117
|
+
material.opacity = LINE_OPACITY * (layer.whenTraced === true ? 1 : this.#shownShare[layer.kind === "figure" ? "figures" : "boundaries"]);
|
|
118
|
+
// While the figure's trace is still drawing, the trace itself grows in the selected colour (`advanceTraces`) and the whole-figure emphasis waits, so it never covers the growing line (owner, T-306).
|
|
119
|
+
this.#selected.object.visible = this.#tappable(layer, on) && !this.#drawing(layer.id);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The figures a tap can select, as screen lines (CSS px from the canvas's top left) and the rectangle of each shown name (`labelRects` are page rectangles; `box` is the canvas's). A figure whose switch is off, or that is
|
|
123
|
+
* shown only when traced and has no trace showing, is left out. A segment is kept whenever any part of it is in front of the camera (cut at the camera plane), even with both ends off screen. Worked out when asked, not each frame.
|
|
124
|
+
*/
|
|
125
|
+
screenFigures(camera, widthPx, heightPx, on, labelRects, box) {
|
|
126
|
+
camera.updateMatrixWorld(true);
|
|
127
|
+
const reach = 0.5 * (camera.near + camera.far); // where the lines are drawn, as the names are placed
|
|
128
|
+
const tanHalfFov = Math.tan((camera.fov * Math.PI) / 360);
|
|
129
|
+
const aspect = widthPx / heightPx;
|
|
130
|
+
const inCamera = (direction) => { const p = this.#point.fromArray(eqjToRenderVector(direction)).multiplyScalar(reach).add(camera.position).applyMatrix4(camera.matrixWorldInverse); return [p.x, p.y, p.z]; };
|
|
131
|
+
return [...this.#layers.values()].filter((layer) => this.#tappable(layer, on)).map((layer) => {
|
|
132
|
+
const rect = labelRects?.get(layer.id);
|
|
133
|
+
const lines = layer.segments.flatMap(([from, to]) => { const line = projectSegmentClipped(inCamera(from), inCamera(to), tanHalfFov, aspect, widthPx, heightPx); return line === null ? [] : [line]; });
|
|
134
|
+
return { id: layer.id, lines, label: rect === undefined ? null : { left: rect.left - box.left, top: rect.top - box.top, right: rect.right - box.left, bottom: rect.bottom - box.top } };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Begins tracing the figure `request.id` (a trace already on it restarts). The trace is a separate set of lines drawn over the figure (the whole drawing of a figure shown only when traced); the figure itself is untouched. An id the view does not hold does nothing. */
|
|
138
|
+
startTrace(request) {
|
|
139
|
+
const layer = this.#layers.get(request.id);
|
|
140
|
+
if (layer === undefined)
|
|
141
|
+
return;
|
|
142
|
+
this.#removeTrace(request.id);
|
|
143
|
+
const object = lines(layer.segments, "#ffffff", `sky-trace:${request.id}`);
|
|
144
|
+
object.renderOrder = 2;
|
|
145
|
+
object.geometry.setDrawRange(0, 0);
|
|
146
|
+
const full = Float32Array.from(object.geometry.getAttribute("position").array);
|
|
147
|
+
this.group.add(object);
|
|
148
|
+
this.#traces.set(request.id, { object, full, kind: layer.kind, run: { seconds: request.seconds, after: request.after, reduced: request.reduced, elapsed: 0 }, drawn: 0, fade: 0 });
|
|
149
|
+
}
|
|
150
|
+
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. */
|
|
151
|
+
clearTrace(request) {
|
|
152
|
+
const trace = this.#traces.get(request.id);
|
|
153
|
+
if (trace === undefined)
|
|
154
|
+
return;
|
|
155
|
+
if (request.reduced || request.seconds <= 0)
|
|
156
|
+
this.#removeTrace(request.id);
|
|
157
|
+
else
|
|
158
|
+
trace.hide = { seconds: request.seconds, from: trace.fade, elapsed: 0 };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Moves every trace on by `deltaSeconds` of real time (the scene clock never enters): draws the segments reached so far, the last one part-grown from its first end, in the traced colour (the faded colour while fading),
|
|
162
|
+
* shows each with its figure's switch, and removes finished ones. Returns true while anything changed, so the caller wakes the draw rule.
|
|
163
|
+
*/
|
|
164
|
+
advanceTraces(deltaSeconds, colours, on, selectedId = "") {
|
|
165
|
+
let moving = false;
|
|
166
|
+
for (const [id, trace] of this.#traces) {
|
|
167
|
+
const frame = trace.hide === undefined ? stepTrace(trace.run, deltaSeconds) : stepHide(trace.hide, deltaSeconds, trace.drawn);
|
|
168
|
+
moving ||= frame.moving;
|
|
169
|
+
trace.fade = frame.fade;
|
|
170
|
+
trace.drawn = frame.drawn;
|
|
171
|
+
if (frame.done) {
|
|
172
|
+
this.#removeTrace(id);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const count = trace.full.length / 6;
|
|
176
|
+
const reached = frame.drawn * count;
|
|
177
|
+
const last = Math.min(count - 1, Math.floor(reached));
|
|
178
|
+
const grown = frame.drawn >= 1 ? 1 : reached - last;
|
|
179
|
+
const positions = trace.object.geometry.getAttribute("position");
|
|
180
|
+
positions.array.set(trace.full.subarray(0, (last + 1) * 6));
|
|
181
|
+
const at = last * 6;
|
|
182
|
+
const end = [0, 1, 2].map((axis) => trace.full[at + axis] + (trace.full[at + 3 + axis] - trace.full[at + axis]) * grown);
|
|
183
|
+
const length = Math.hypot(end[0], end[1], end[2]);
|
|
184
|
+
end.forEach((value, axis) => { positions.array[at + 3 + axis] = length > 1e-9 ? value / length : value; });
|
|
185
|
+
positions.needsUpdate = true;
|
|
186
|
+
trace.object.geometry.setDrawRange(0, (last + 1) * 2);
|
|
187
|
+
const material = trace.object.material;
|
|
188
|
+
material.color.set(id === selectedId && frame.drawn < 1 && trace.hide === undefined ? colours.selected : colours.traced).lerp(FADED.set(colours.faded), frame.fade);
|
|
189
|
+
material.opacity = TRACE_OPACITY * (1 - frame.fade);
|
|
190
|
+
trace.object.visible = on[trace.kind === "figure" ? "figures" : "boundaries"];
|
|
191
|
+
}
|
|
192
|
+
return moving;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Moves the fade-in of every kind of line on by `deltaSeconds` of real time over `seconds` (0: at once), and sets the lines' opacity; a kind whose switch is off goes back to 0 so it fades in again
|
|
196
|
+
* when it next turns on. Returns true while a fade-in is still running, so the caller wakes the draw rule.
|
|
197
|
+
*/
|
|
198
|
+
advanceFadeIn(deltaSeconds, seconds, on) {
|
|
199
|
+
let moving = false;
|
|
200
|
+
for (const kind of Object.keys(this.#shownShare)) {
|
|
201
|
+
const before = this.#shownShare[kind];
|
|
202
|
+
const after = on[kind] ? stepFadeIn(before, deltaSeconds, seconds) : 0;
|
|
203
|
+
this.#shownShare[kind] = after;
|
|
204
|
+
if (after !== before)
|
|
205
|
+
moving = true;
|
|
206
|
+
}
|
|
207
|
+
for (const entry of this.#drawn)
|
|
208
|
+
entry.object.material.opacity = LINE_OPACITY * this.#shownShare[entry.shows];
|
|
209
|
+
return moving;
|
|
210
|
+
}
|
|
211
|
+
/** How much of a label shows, 0 to 1: for a figure that is always shown, how far its kind has faded in; for one shown only when traced, 0 until a trace starts, then rising with the trace to 1 at half drawn (fading to 0 with a `fade` trace; 0 again once the trace is removed). */
|
|
212
|
+
labelOpacity(id) {
|
|
213
|
+
const layer = this.#layers.get(id);
|
|
214
|
+
if (layer === undefined)
|
|
215
|
+
return 1;
|
|
216
|
+
if (layer.whenTraced !== true)
|
|
217
|
+
return this.#shownShare[layer.kind === "figure" ? "figures" : "boundaries"];
|
|
218
|
+
const trace = this.#traces.get(id);
|
|
219
|
+
return trace === undefined ? 0 : Math.min(1, trace.drawn / TRACE_LABEL_IN_SHARE) * (1 - trace.fade);
|
|
220
|
+
}
|
|
221
|
+
#removeTrace(id) {
|
|
222
|
+
const trace = this.#traces.get(id);
|
|
223
|
+
if (trace === undefined)
|
|
224
|
+
return;
|
|
225
|
+
this.#traces.delete(id);
|
|
226
|
+
this.group.remove(trace.object);
|
|
227
|
+
trace.object.geometry.dispose();
|
|
228
|
+
trace.object.material.dispose();
|
|
229
|
+
}
|
|
230
|
+
/** Which lines are shown now, by name (read by tests and the canvas data). */
|
|
231
|
+
get shown() {
|
|
232
|
+
return this.group.children.filter((child) => child.visible).map((child) => child.name);
|
|
233
|
+
}
|
|
234
|
+
dispose() {
|
|
235
|
+
for (const child of this.group.children) {
|
|
236
|
+
const line = child;
|
|
237
|
+
line.geometry.dispose();
|
|
238
|
+
line.material.dispose();
|
|
239
|
+
}
|
|
240
|
+
this.group.clear();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -6,8 +6,8 @@ export interface StoryMarkerSpec {
|
|
|
6
6
|
readonly panelId: string;
|
|
7
7
|
readonly objectId: string;
|
|
8
8
|
readonly title: string;
|
|
9
|
-
/** The panel's moment, so a marker shared by several panels can pick the one the clock has reached. */
|
|
10
|
-
readonly timeUtcMs
|
|
9
|
+
/** The panel's moment, so a marker shared by several panels can pick the one the clock has reached; absent on a step, which comes after the moment panels. */
|
|
10
|
+
readonly timeUtcMs?: number;
|
|
11
11
|
}
|
|
12
12
|
/** One scene marker: an object and every panel that names it, in time order. */
|
|
13
13
|
export interface StoryMarkerGroup {
|
package/src/app/StoryMarkers.js
CHANGED
|
@@ -15,7 +15,7 @@ export function groupStoryMarkers(specs) {
|
|
|
15
15
|
else
|
|
16
16
|
list.push(spec);
|
|
17
17
|
}
|
|
18
|
-
return [...groups].map(([objectId, panels]) => ({ objectId, panels: [...panels
|
|
18
|
+
return [...groups].map(([objectId, panels]) => ({ objectId, panels: [...panels.filter((panel) => panel.timeUtcMs !== undefined).sort((a, b) => a.timeUtcMs - b.timeUtcMs), ...panels.filter((panel) => panel.timeUtcMs === undefined)] }));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* The panel a press on a shared marker opens. When one of the group's panels is open, the next one in time order
|
|
@@ -28,7 +28,7 @@ export function panelForMarkerPress(group, timeUtcMs, openPanelId) {
|
|
|
28
28
|
if (openIndex >= 0)
|
|
29
29
|
return panels[(openIndex + 1) % panels.length].panelId;
|
|
30
30
|
let reached = 0;
|
|
31
|
-
panels.forEach((panel, index) => { if (panel.timeUtcMs <= timeUtcMs)
|
|
31
|
+
panels.forEach((panel, index) => { if (panel.timeUtcMs !== undefined && panel.timeUtcMs <= timeUtcMs)
|
|
32
32
|
reached = index; });
|
|
33
33
|
return panels[reached].panelId;
|
|
34
34
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { DisplaySwitchItem } from "../shell/DisplaySwitches.js";
|
|
2
2
|
import type { OrbitLook } from "../assets/orbitLook.js";
|
|
3
3
|
import type { BodySetLook } from "./bodySet.js";
|
|
4
|
+
import type { SkyLineSwitches } from "./skyFigures.js";
|
|
4
5
|
/** The display switches a story can place. Each one drives the same state as its Developer-drawer buttons, so the two never disagree. */
|
|
5
|
-
export declare const DISPLAY_SWITCH_IDS: readonly ["orbitLines", "labels", "milkyWay"];
|
|
6
|
-
/** The name of one display switch: "orbitLines", "labels" or "
|
|
6
|
+
export declare const DISPLAY_SWITCH_IDS: readonly ["orbitLines", "labels", "milkyWay", "skyFigures", "skyBoundaries", "ecliptic", "celestialEquator"];
|
|
7
|
+
/** The name of one display switch: "orbitLines", "labels", "milkyWay", "skyFigures", "skyBoundaries", "ecliptic" or "celestialEquator" (a key of `SwitchesInput`). */
|
|
7
8
|
export type DisplaySwitchId = (typeof DISPLAY_SWITCH_IDS)[number];
|
|
8
9
|
/** Where a switch shows: a button in the top bar, a row in the story switch panel opened from the bar, or only in the Developer drawer (where every switch stays). */
|
|
9
10
|
export declare const DISPLAY_SWITCH_PLACES: readonly ["top-bar", "panel", "developer"];
|
|
@@ -43,6 +44,13 @@ export interface SwitchBindings {
|
|
|
43
44
|
readonly on: boolean;
|
|
44
45
|
readonly set: (on: boolean) => void;
|
|
45
46
|
};
|
|
47
|
+
/** The sky lines: which kinds the scene has figures of (the ecliptic and the equator are always there), the state now, and a setter for one. */
|
|
48
|
+
readonly skyLines: {
|
|
49
|
+
readonly figures: boolean;
|
|
50
|
+
readonly boundaries: boolean;
|
|
51
|
+
readonly on: Readonly<SkyLineSwitches>;
|
|
52
|
+
readonly set: (key: keyof SkyLineSwitches, on: boolean) => void;
|
|
53
|
+
};
|
|
46
54
|
readonly labels: {
|
|
47
55
|
readonly objectIds: readonly string[];
|
|
48
56
|
readonly hidden: ReadonlySet<string>;
|
|
@@ -52,7 +60,9 @@ export interface SwitchBindings {
|
|
|
52
60
|
readonly setAnchors: (on: boolean) => void;
|
|
53
61
|
};
|
|
54
62
|
}
|
|
55
|
-
/** The
|
|
63
|
+
/** The sky lines' starting state: the defaults, with a story's `on` laid over the ones it named. */
|
|
64
|
+
export declare function skyLineStart(settings: DisplaySwitchSettings | undefined, defaults: Readonly<SkyLineSwitches>): SkyLineSwitches;
|
|
65
|
+
/** The switches to draw in the top bar and the switch panel: the placed ones the scene has something for, in the order orbit lines, labels, Milky Way, sky figures, sky outlines, ecliptic, celestial equator. */
|
|
56
66
|
export declare function displaySwitchItems(bindings: SwitchBindings): readonly DisplaySwitchItem[];
|
|
57
67
|
/** The settings with every placed switch counted as shown: a host reads and sets a switch placed only in the Developer drawer too. */
|
|
58
68
|
export declare function hostReachable(settings: DisplaySwitchSettings | undefined): DisplaySwitchSettings | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** The display switches a story can place. Each one drives the same state as its Developer-drawer buttons, so the two never disagree. */
|
|
2
|
-
export const DISPLAY_SWITCH_IDS = ["orbitLines", "labels", "milkyWay"];
|
|
2
|
+
export const DISPLAY_SWITCH_IDS = ["orbitLines", "labels", "milkyWay", "skyFigures", "skyBoundaries", "ecliptic", "celestialEquator"];
|
|
3
3
|
/** Where a switch shows: a button in the top bar, a row in the story switch panel opened from the bar, or only in the Developer drawer (where every switch stays). */
|
|
4
4
|
export const DISPLAY_SWITCH_PLACES = ["top-bar", "panel", "developer"];
|
|
5
|
-
export const DISPLAY_SWITCH_LABELS = { orbitLines: "Orbit lines", labels: "Labels", milkyWay: "Milky Way" };
|
|
5
|
+
export const DISPLAY_SWITCH_LABELS = { orbitLines: "Orbit lines", labels: "Labels", milkyWay: "Milky Way", skyFigures: "Sky figures", skyBoundaries: "Sky outlines", ecliptic: "Ecliptic", celestialEquator: "Celestial equator" };
|
|
6
6
|
/** Orbit lines are on while the ring, the trailing arc or the moon orbits show: the Developer buttons for any of them keep the switch in step. */
|
|
7
7
|
export function orbitLinesOn(orbit, moonOrbitsOn) {
|
|
8
8
|
return (orbit !== null && (orbit.baseOn || orbit.arcOn)) || moonOrbitsOn === true;
|
|
@@ -27,7 +27,17 @@ function setLabels(bindings, on) {
|
|
|
27
27
|
if (labels.anchorsPresent)
|
|
28
28
|
labels.setAnchors(on);
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
30
|
+
/** One sky-line switch: `applies` says whether the scene has anything of that kind; the state and the toggle are the live sky-line switches'. */
|
|
31
|
+
function skyLineState(bindings, key, applies) {
|
|
32
|
+
const on = bindings.skyLines.on[key];
|
|
33
|
+
return { applies, on, toggle: () => bindings.skyLines.set(key, !on) };
|
|
34
|
+
}
|
|
35
|
+
/** The sky lines' starting state: the defaults, with a story's `on` laid over the ones it named. */
|
|
36
|
+
export function skyLineStart(settings, defaults) {
|
|
37
|
+
const pick = (id, fallback) => settings?.[id]?.on ?? fallback;
|
|
38
|
+
return { figures: pick("skyFigures", defaults.figures), boundaries: pick("skyBoundaries", defaults.boundaries), ecliptic: pick("ecliptic", defaults.ecliptic), celestialEquator: pick("celestialEquator", defaults.celestialEquator) };
|
|
39
|
+
}
|
|
40
|
+
/** The switches to draw in the top bar and the switch panel: the placed ones the scene has something for, in the order orbit lines, labels, Milky Way, sky figures, sky outlines, ecliptic, celestial equator. */
|
|
31
41
|
export function displaySwitchItems(bindings) {
|
|
32
42
|
const { settings } = bindings;
|
|
33
43
|
if (settings === undefined)
|
|
@@ -38,6 +48,10 @@ export function displaySwitchItems(bindings) {
|
|
|
38
48
|
orbitLines: { applies: bindings.orbit.present || bindings.moons.present, on: orbitOn, toggle: () => setOrbitLines(bindings, !orbitOn) },
|
|
39
49
|
labels: { applies: bindings.labels.objectIds.length > 0 || bindings.labels.anchorsPresent, on: labelsNow, toggle: () => setLabels(bindings, !labelsNow) },
|
|
40
50
|
milkyWay: { applies: bindings.sky.present, on: bindings.sky.on, toggle: () => bindings.sky.set(!bindings.sky.on) },
|
|
51
|
+
skyFigures: skyLineState(bindings, "figures", bindings.skyLines.figures),
|
|
52
|
+
skyBoundaries: skyLineState(bindings, "boundaries", bindings.skyLines.boundaries),
|
|
53
|
+
ecliptic: skyLineState(bindings, "ecliptic", true),
|
|
54
|
+
celestialEquator: skyLineState(bindings, "celestialEquator", true),
|
|
41
55
|
};
|
|
42
56
|
return DISPLAY_SWITCH_IDS.flatMap((id) => {
|
|
43
57
|
const place = settings[id]?.place;
|