astraeus 0.2.0 → 0.3.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 +28 -0
- package/README.md +41 -5
- package/package.json +2 -1
- package/src/api/AstraeusScene.js +1 -1
- package/src/api/AstraeusScene.node.js +37 -0
- package/src/api/group.d.ts +7 -1
- package/src/api/index.d.ts +1 -0
- package/src/api/index.js +1 -0
- package/src/api/index.node.js +8 -0
- package/src/api/mount.js +3 -1
- package/src/api/mount.node.js +36 -0
- package/src/api/scene.d.ts +32 -6
- package/src/api/scene.js +123 -26
- package/src/api/story.d.ts +8 -2
- package/src/api/story.js +11 -0
- package/src/api/sunOrbit.d.ts +6 -0
- package/src/api/sunOrbit.js +24 -0
- package/src/app/App.d.ts +6 -2
- package/src/app/App.js +8 -4
- package/src/app/App.node.js +401 -0
- package/src/app/PanelLoadBoundary.d.ts +2 -1
- package/src/app/PanelLoadBoundary.js +2 -2
- package/src/app/SkyView.d.ts +3 -3
- package/src/app/SkyView.js +19 -10
- package/src/app/experienceDefinition.d.ts +8 -0
- package/src/app/sceneContentsHooks.js +2 -2
- package/src/app/sceneFrame.js +4 -3
- package/src/app/sceneFraming.d.ts +13 -0
- package/src/app/sceneFraming.js +22 -0
- package/src/app/skyModel.js +1 -1
- package/src/assets/pictures.d.ts +1 -1
- package/src/assets/sky.d.ts +4 -4
- package/src/assets/sky.js +12 -13
- package/src/core/bodies/io.js +1 -1
- package/src/core/bodies/jupiterData.js +2 -2
- package/src/core/bodies/jupiterMoons.js +8 -12
- package/src/core/bodies/moon.d.ts +8 -0
- package/src/core/bodies/moon.js +28 -5
- package/src/core/bodies/outerPlanetData.js +7 -7
- package/src/core/bodies/planetMoons.js +18 -27
- package/src/core/bodies/swiftTuttle.js +2 -0
- package/src/core/elementsBody.d.ts +2 -0
- package/src/core/elementsBody.js +3 -0
- package/src/core/moonTrajectory.js +3 -5
- package/src/core/planetModels.js +1 -1
- package/src/core/provenance.d.ts +6 -2
- package/src/core/provenance.js +3 -1
- package/src/shell/AstraeusShell.js +5 -3
- package/src/shell/AstraeusShell.node.js +225 -0
- package/src/shell/DisplaySwitches.js +1 -1
- package/src/shell/StoryPanelView.js +3 -1
- package/src/shell/TimelineBar.node.js +75 -0
- package/src/shell/TopBar.node.js +14 -0
- package/src/shell/experience.d.ts +2 -0
- package/src/shell/infoModel.js +3 -1
- package/src/shell/phone.css +1 -1
- package/src/shell/useDrawers.js +1 -1
- package/src/shell/useZoomThrough.d.ts +7 -0
- package/src/shell/useZoomThrough.js +51 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { createOrbAstronomyAdapter } from "../core/astronomyAdapter.js";
|
|
4
|
+
import { viewUpFromSearch, viewUpVector } from "./viewUp.js";
|
|
5
|
+
import { openClock } from "./openClock.js";
|
|
6
|
+
import { createSolarSystemScale } from "../core/scalePolicy.js";
|
|
7
|
+
import { bodySetsOf, cameraReachOf, catalogueOf, compositionOf, experienceWithGroups, groupsOf, initialObjectIdOf, mountedBodiesOf, pageTitleOf, scaleChoiceIdsOf, sceneCenterOf, sunCentredOf, trackedBodiesOf, visualOverridesOf } from "./experienceDefinition.js";
|
|
8
|
+
import { AstraeusShell } from "../shell/AstraeusShell.node.js";
|
|
9
|
+
import { scaleChoicesFor, scalePolicyFor, startScaleFor } from "../shell/scaleModel.js";
|
|
10
|
+
import { scaleFromSearch, timeFromSearch, viewFromSearch, shareViewLink } from "./viewLink.js";
|
|
11
|
+
import { Collapsible } from "../shell/Collapsible.js";
|
|
12
|
+
import { PanelLoadBoundary } from "./PanelLoadBoundary.js";
|
|
13
|
+
import { BOOT_FADE_LIMITS, bootFadeSeconds, saveBootFadeSeconds } from "../shell/bootLoader.js";
|
|
14
|
+
import { LabelSettings, UnderTheHoodSettings, ViewLinkReadout, MoonsAndRingsSettings, SkyAndSunSettings, StoryPanelSettings } from "./developerPanels.js";
|
|
15
|
+
import { DEFAULT_ILLUMINATE_ALL } from "./lighting.js";
|
|
16
|
+
import { SettingButtons, SettingColor, SettingGroup, SettingSlider } from "./SettingControls.js";
|
|
17
|
+
import { DEFAULT_TIMELINE_GLOW } from "../shell/timelineGlow.js";
|
|
18
|
+
import { DEFAULT_PHONE_LAYOUT, PHONE_LAYOUT_LIMITS } from "../shell/phoneLayout.js";
|
|
19
|
+
import { featureMarkerSpecs, featureMinBodyPxFromSearch } from "./FeatureMarkers.js";
|
|
20
|
+
import { FrameStats } from "./frameStats.js";
|
|
21
|
+
import { AstraeusScene } from "./AstraeusScene.js";
|
|
22
|
+
import { HOVER_BRIGHTNESS_DEFAULT } from "./scenePicking.js";
|
|
23
|
+
import { createSceneResolver } from "./sceneLayout.js";
|
|
24
|
+
import { loadStarCatalogue } from "../assets/sky.js";
|
|
25
|
+
import { resolveSkySettings, withSkyObject } from "./skyModel.js";
|
|
26
|
+
import { ORBIT_LOOK_LIMITS, resolveOrbitLook } from "../assets/orbitLook.js";
|
|
27
|
+
import { DEFAULT_BODY_SET_LOOK } from "./bodySet.js";
|
|
28
|
+
import { displaySwitchItems, orbitStart } from "./displaySwitches.js";
|
|
29
|
+
import { baseGlowOf, glowLookFromSearch, markerSettingsFromSearch } from "./bodyDraw.js";
|
|
30
|
+
import { brightnessFromSearch, milkyWayFromSearch, skyHiddenBySearch } from "./SkyView.js";
|
|
31
|
+
/** Frames-per-second readings kept for the graph: one per 250 ms poll, so about 15 seconds. */
|
|
32
|
+
const FPS_HISTORY = 60;
|
|
33
|
+
/** The sky settings in force: the experience's own, hidden when the address says `?sky=off`. */
|
|
34
|
+
function skySettingsOf(definition) {
|
|
35
|
+
const settings = resolveSkySettings(definition.sky);
|
|
36
|
+
const milkyWay = milkyWayFromSearch(window.location.search) ?? definition.displaySwitches?.milkyWay?.on ?? settings.milkyWay;
|
|
37
|
+
const starBrightness = brightnessFromSearch(window.location.search, "stars") ?? settings.starBrightness;
|
|
38
|
+
const milkyWayBrightness = brightnessFromSearch(window.location.search, "milkywaybrightness") ?? settings.milkyWayBrightness;
|
|
39
|
+
return { ...settings, milkyWay, starBrightness, milkyWayBrightness, visible: settings.visible && !skyHiddenBySearch(window.location.search) };
|
|
40
|
+
}
|
|
41
|
+
/** The labels switched off at the start: objects that set `showLabel: false`, then `?labels=<id>:on|off,...` over them. */
|
|
42
|
+
export function hiddenLabelsFrom(search, objects) {
|
|
43
|
+
const hidden = new Set(objects.filter((object) => object.showLabel === false).map((object) => object.id));
|
|
44
|
+
for (const part of (new URLSearchParams(search).get("labels") ?? "").split(",")) {
|
|
45
|
+
const [id, state] = part.split(":");
|
|
46
|
+
if (id === undefined || id === "" || (state !== "on" && state !== "off"))
|
|
47
|
+
continue;
|
|
48
|
+
if (state === "off")
|
|
49
|
+
hidden.add(id);
|
|
50
|
+
else
|
|
51
|
+
hidden.delete(id);
|
|
52
|
+
}
|
|
53
|
+
return hidden;
|
|
54
|
+
}
|
|
55
|
+
/** `?loop=on` or `?loop=off` overrides the experience's own looping setting. */
|
|
56
|
+
export function loopFromSearch(search, fallback) {
|
|
57
|
+
const value = new URLSearchParams(search).get("loop");
|
|
58
|
+
return value === "on" ? true : value === "off" ? false : fallback;
|
|
59
|
+
}
|
|
60
|
+
/** The labels switch's starting state, if the story gave one. */
|
|
61
|
+
function labelStart(definition) {
|
|
62
|
+
return definition.displaySwitches?.labels?.on;
|
|
63
|
+
}
|
|
64
|
+
/** The orbit lines a story starts off: the ring and arc, and the moon orbits. */
|
|
65
|
+
function startOrbitControls(definition) {
|
|
66
|
+
const start = orbitStart(definition.displaySwitches?.orbitLines);
|
|
67
|
+
return start === undefined ? {} : { orbitLook: start.look, bodySetLook: { ...DEFAULT_BODY_SET_LOOK, orbitsOn: false } };
|
|
68
|
+
}
|
|
69
|
+
function copyOfGlow(look) {
|
|
70
|
+
return look === undefined ? null : { ...look };
|
|
71
|
+
}
|
|
72
|
+
function orbitPathsOf(runtime) {
|
|
73
|
+
return runtime.composition?.paths ?? [];
|
|
74
|
+
}
|
|
75
|
+
/** The up direction at the start: `?up=` in the address, else the experience's own, else the equatorial pole. */
|
|
76
|
+
function startViewUp(definition) {
|
|
77
|
+
return viewUpFromSearch(window.location.search, definition.viewUp ?? "equatorial");
|
|
78
|
+
}
|
|
79
|
+
function storyStartOf(storySet) {
|
|
80
|
+
return { autoOpen: storySet?.autoOpen ?? false, pauseSeconds: storySet?.pauseSeconds ?? 0 };
|
|
81
|
+
}
|
|
82
|
+
function switcherOf(definition, runtime, open) {
|
|
83
|
+
return definition.switcher === undefined ? undefined : { ...definition.switcher, currentTimeUtcMs: () => runtime.clock.snapshot().timeUtcMs, open };
|
|
84
|
+
}
|
|
85
|
+
/** Everything one mounted experience shares: clock, resolver, catalogue and the settings read from its definition and the address. */
|
|
86
|
+
function buildRuntime(definition) {
|
|
87
|
+
const adapter = createOrbAstronomyAdapter();
|
|
88
|
+
// A copied view link carries the time it was copied at.
|
|
89
|
+
const clock = openClock(definition, timeFromSearch(window.location.search));
|
|
90
|
+
// One resolver per mount: every position in the scene comes from it, whatever the scene centre.
|
|
91
|
+
const resolver = createSceneResolver(adapter, catalogueOf(definition));
|
|
92
|
+
return {
|
|
93
|
+
clock,
|
|
94
|
+
adapter,
|
|
95
|
+
resolver,
|
|
96
|
+
catalogue: catalogueOf(definition),
|
|
97
|
+
bodies: mountedBodiesOf(definition),
|
|
98
|
+
composition: compositionOf(definition),
|
|
99
|
+
overrides: visualOverridesOf(definition),
|
|
100
|
+
desktopTextures: definition.desktopTextures === true,
|
|
101
|
+
sceneCenter: sceneCenterOf(definition),
|
|
102
|
+
trackedBodies: trackedBodiesOf(definition),
|
|
103
|
+
groups: groupsOf(definition),
|
|
104
|
+
bodySets: bodySetsOf(definition),
|
|
105
|
+
...sunCentredOf(definition),
|
|
106
|
+
cameraReach: cameraReachOf(definition),
|
|
107
|
+
sky: skySettingsOf(definition),
|
|
108
|
+
loopWindow: definition.experience.window,
|
|
109
|
+
up: viewUpVector(startViewUp(definition)),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Whether the experience has anything the Display controls (markers, labels, timeline, phone layout) act on. */
|
|
113
|
+
function showsDisplayControls(definition, runtime, orbitPathCount, storyMarkerCount) {
|
|
114
|
+
return orbitPathCount > 0 || runtime.trackedBodies.length > 0 || runtime.sky.visible || storyMarkerCount > 0 || (definition.experience.storyPanels?.panels.length ?? 0) > 0
|
|
115
|
+
|| runtime.bodies.some((id) => runtime.catalogue.get(id).visual.kind === "sphere");
|
|
116
|
+
}
|
|
117
|
+
/** The scene's live controls at mount: the address overrides the experience's own start values. */
|
|
118
|
+
function initialSceneControls(definition, runtime, experience, startScale, glowBase, storyMarkers, suppliedPolicies) {
|
|
119
|
+
const search = window.location.search;
|
|
120
|
+
const startView = viewFromSearch(search) ?? definition.startView;
|
|
121
|
+
return {
|
|
122
|
+
policy: scalePolicyFor(startScale, suppliedPolicies),
|
|
123
|
+
cameraRequest: null,
|
|
124
|
+
showAnchorLabels: labelStart(definition) === true && runtime.trackedBodies.length > 0,
|
|
125
|
+
loop: loopFromSearch(search, definition.loop === true),
|
|
126
|
+
up: viewUpVector(startViewUp(definition)),
|
|
127
|
+
showMilkyWay: runtime.sky.milkyWay,
|
|
128
|
+
bodyMarker: markerSettingsFromSearch(search),
|
|
129
|
+
...(glowBase === null ? {} : { glowLook: glowLookFromSearch(search, glowBase) }),
|
|
130
|
+
starBrightness: runtime.sky.starBrightness,
|
|
131
|
+
milkyWayBrightness: runtime.sky.milkyWayBrightness,
|
|
132
|
+
illuminateAll: DEFAULT_ILLUMINATE_ALL,
|
|
133
|
+
hiddenLabels: hiddenLabelsFrom(search, labelStart(definition) === undefined ? experience.objects : experience.objects.map(({ id }) => ({ id, showLabel: labelStart(definition) }))),
|
|
134
|
+
...startOrbitControls(definition),
|
|
135
|
+
labelObjects: experience.objects,
|
|
136
|
+
storyMarkers,
|
|
137
|
+
featureMarkers: featureMarkerSpecs(definition.experience.bodyFeatures),
|
|
138
|
+
featureMinBodyPx: featureMinBodyPxFromSearch(search),
|
|
139
|
+
selectedObjectId: initialObjectIdOf(definition),
|
|
140
|
+
frameStats: null,
|
|
141
|
+
groupFills: [],
|
|
142
|
+
...(startView === undefined ? {} : { startView }),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* `onOpenAddress`: the entry's way to open a switch's address in place; without it a switch navigates the page.
|
|
147
|
+
* `writeTitle`: whether the page heading is set to the experience's name (default true); `mount` and `AstraeusScene` pass false so a host page keeps its own title.
|
|
148
|
+
*/
|
|
149
|
+
export function App({ definition, onOpenAddress, writeTitle = true }) {
|
|
150
|
+
// The page heading names the experience once it is open; app.html says only "Astraeus" until then.
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (writeTitle)
|
|
153
|
+
document.title = pageTitleOf(definition);
|
|
154
|
+
}, [definition, writeTitle]);
|
|
155
|
+
const runtime = useMemo(() => buildRuntime(definition), [definition]);
|
|
156
|
+
const experienceRuntime = useMemo(() => ({ clock: runtime.clock, resolver: runtime.resolver, catalogue: runtime.catalogue }), [runtime]);
|
|
157
|
+
// The choices offered, in the experience's order; the solar-system policy enlarges only the bodies the experience names.
|
|
158
|
+
const scaleChoiceIds = useMemo(() => scaleChoiceIdsOf(definition), [definition]);
|
|
159
|
+
const scaleChoices = useMemo(() => (scaleChoiceIds === undefined ? undefined : scaleChoicesFor(scaleChoiceIds)), [scaleChoiceIds]);
|
|
160
|
+
const suppliedPolicies = useMemo(() => {
|
|
161
|
+
const exaggeration = {};
|
|
162
|
+
for (const [id, override] of runtime.overrides)
|
|
163
|
+
if (override.exaggeration !== undefined)
|
|
164
|
+
exaggeration[id] = override.exaggeration;
|
|
165
|
+
return [createSolarSystemScale({ exaggeration, defaultExaggeration: 1 })];
|
|
166
|
+
}, [runtime]);
|
|
167
|
+
const linkedScale = scaleFromSearch(window.location.search);
|
|
168
|
+
const startScale = startScaleFor(linkedScale, scaleChoiceIds);
|
|
169
|
+
const experience = useMemo(() => experienceWithGroups(definition), [definition]);
|
|
170
|
+
// The shell also lists the sky, citing its sources and saying whether the stars were fetched.
|
|
171
|
+
const [starStatus, setStarStatus] = useState({ kind: "loading" });
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
let cancelled = false;
|
|
174
|
+
void loadStarCatalogue().then((loaded) => {
|
|
175
|
+
if (!cancelled)
|
|
176
|
+
setStarStatus(loaded === null ? { kind: "absent" } : { kind: "loaded", count: loaded.stars.length });
|
|
177
|
+
});
|
|
178
|
+
return () => { cancelled = true; };
|
|
179
|
+
}, []);
|
|
180
|
+
const shellExperience = useMemo(() => withSkyObject(experience, runtime.sky.visible, starStatus), [experience, runtime.sky.visible, starStatus]);
|
|
181
|
+
const metricsFor = useMemo(() => definition.createMetrics(experienceRuntime), [definition, experienceRuntime]);
|
|
182
|
+
const glowBase = useMemo(() => baseGlowOf(runtime.bodies.map((id) => runtime.catalogue.get(id))), [runtime]);
|
|
183
|
+
const storySet = definition.experience.storyPanels;
|
|
184
|
+
const storyMarkerSpecs = useMemo(() => (storySet?.panels ?? []).flatMap((panel) => (panel.objectId === undefined ? [] : [{ panelId: panel.id, objectId: panel.objectId, title: panel.title, timeUtcMs: panel.timeUtcMs }])), [storySet]);
|
|
185
|
+
const controls = useRef(initialSceneControls(definition, runtime, experience, startScale, glowBase, storyMarkerSpecs, suppliedPolicies));
|
|
186
|
+
const readout = useRef(null);
|
|
187
|
+
const [clockSnapshot, setClockSnapshot] = useState(() => runtime.clock.snapshot());
|
|
188
|
+
const [scale, setScale] = useState(startScale);
|
|
189
|
+
const [developerMode, setDeveloperMode] = useState(false);
|
|
190
|
+
const [timelineGlow, setTimelineGlow] = useState(DEFAULT_TIMELINE_GLOW);
|
|
191
|
+
const [phoneLayout, setPhoneLayout] = useState(DEFAULT_PHONE_LAYOUT);
|
|
192
|
+
const [anchorLabels, setAnchorLabels] = useState(controls.current.showAnchorLabels);
|
|
193
|
+
const [glowShown, setGlowShown] = useState(copyOfGlow(controls.current.glowLook));
|
|
194
|
+
const orbitPaths = orbitPathsOf(runtime);
|
|
195
|
+
const orbitDefault = useMemo(() => resolveOrbitLook(orbitPaths[0]?.look), [orbitPaths]);
|
|
196
|
+
const [orbitShown, setOrbitShown] = useState({ ...orbitDefault, ...controls.current.orbitLook });
|
|
197
|
+
const setOrbit = (change) => {
|
|
198
|
+
controls.current.orbitLook = { ...controls.current.orbitLook, ...change };
|
|
199
|
+
setOrbitShown({ ...orbitDefault, ...controls.current.orbitLook });
|
|
200
|
+
};
|
|
201
|
+
const resetOrbit = () => { delete controls.current.orbitLook; setOrbitShown(orbitDefault); };
|
|
202
|
+
const bodySets = runtime.bodySets;
|
|
203
|
+
const [setLook, setSetLook] = useState(controls.current.bodySetLook ?? DEFAULT_BODY_SET_LOOK);
|
|
204
|
+
const changeSetLook = (change) => {
|
|
205
|
+
const next = { ...(controls.current.bodySetLook ?? DEFAULT_BODY_SET_LOOK), ...change };
|
|
206
|
+
controls.current.bodySetLook = next;
|
|
207
|
+
setSetLook(next);
|
|
208
|
+
};
|
|
209
|
+
const highlightFamily = (family) => changeSetLook({ highlightFamily: family });
|
|
210
|
+
const ringSystems = useMemo(() => runtime.bodies.flatMap((id) => { const rings = runtime.overrides.get(id)?.rings ?? runtime.catalogue.get(id).visual.rings; return rings === undefined ? [] : [rings]; }), [runtime]);
|
|
211
|
+
const [ringLook, setRingLook] = useState({});
|
|
212
|
+
const changeRing = (band, change) => {
|
|
213
|
+
const next = { ...ringLook, [band]: { ...ringLook[band], ...change } };
|
|
214
|
+
controls.current.ringLook = next;
|
|
215
|
+
setRingLook(next);
|
|
216
|
+
};
|
|
217
|
+
const labelToggles = useMemo(() => experience.objects.filter((object) => object.showLabel !== undefined), [experience]);
|
|
218
|
+
const [hiddenLabels, setHiddenLabels] = useState(() => new Set(controls.current.hiddenLabels));
|
|
219
|
+
const [loopOn, setLoopOn] = useState(controls.current.loop === true);
|
|
220
|
+
const [upChoice, setUpChoice] = useState(startViewUp(definition));
|
|
221
|
+
const [illuminateAll, setIlluminateAll] = useState(controls.current.illuminateAll);
|
|
222
|
+
const [milkyWayOn, setMilkyWayOn] = useState(runtime.sky.milkyWay);
|
|
223
|
+
const [hoverBrightness, setHoverBrightness] = useState(HOVER_BRIGHTNESS_DEFAULT);
|
|
224
|
+
const [starBrightness, setStarBrightness] = useState(runtime.sky.starBrightness);
|
|
225
|
+
const [milkyWayBrightness, setMilkyWayBrightness] = useState(runtime.sky.milkyWayBrightness);
|
|
226
|
+
const [loadFade, setLoadFade] = useState(() => bootFadeSeconds());
|
|
227
|
+
const [markerPx, setMarkerPx] = useState(() => controls.current.bodyMarker.minSpherePx);
|
|
228
|
+
const [storyAutoOpen, setStoryAutoOpen] = useState(storyStartOf(storySet).autoOpen);
|
|
229
|
+
const [storyPauseSeconds, setStoryPauseSeconds] = useState(storyStartOf(storySet).pauseSeconds);
|
|
230
|
+
const [panelRequest, setPanelRequest] = useState(null);
|
|
231
|
+
const [pickRequest, setPickRequest] = useState(null);
|
|
232
|
+
const [featureRequest, setFeatureRequest] = useState(null);
|
|
233
|
+
const [hud, setHud] = useState(null);
|
|
234
|
+
const [frames, setFrames] = useState(null);
|
|
235
|
+
const [fpsHistory, setFpsHistory] = useState([]);
|
|
236
|
+
const [viewNow, setViewNow] = useState(null);
|
|
237
|
+
const [viewLink, setViewLink] = useState(null);
|
|
238
|
+
const [fills, setFills] = useState([]);
|
|
239
|
+
const updateCameraRequest = useCallback((request) => {
|
|
240
|
+
controls.current.cameraRequest = request;
|
|
241
|
+
}, []);
|
|
242
|
+
const requestPanel = useCallback((id) => setPanelRequest((previous) => ({ id, serial: (previous?.serial ?? 0) + 1 })), []);
|
|
243
|
+
const requestPick = useCallback((id) => setPickRequest((previous) => ({ id, serial: (previous?.serial ?? 0) + 1 })), []);
|
|
244
|
+
const requestFeature = useCallback((key) => setFeatureRequest((previous) => ({ key, serial: (previous?.serial ?? 0) + 1 })), []);
|
|
245
|
+
const markOpenFeature = useCallback((key) => { controls.current.openFeatureKey = key; }, []);
|
|
246
|
+
const markOpenPanel = useCallback((id) => { controls.current.openStoryPanelId = id; }, []);
|
|
247
|
+
const setPlaying = useCallback((playing) => {
|
|
248
|
+
if (playing)
|
|
249
|
+
runtime.clock.play();
|
|
250
|
+
else
|
|
251
|
+
runtime.clock.pause();
|
|
252
|
+
setClockSnapshot(runtime.clock.snapshot());
|
|
253
|
+
}, [runtime]);
|
|
254
|
+
controls.current.onStoryMarker = requestPanel;
|
|
255
|
+
controls.current.onFeatureMarker = requestFeature;
|
|
256
|
+
controls.current.onPickObject = requestPick;
|
|
257
|
+
const updateSelectedObject = useCallback((objectId) => {
|
|
258
|
+
controls.current.selectedObjectId = objectId;
|
|
259
|
+
}, []);
|
|
260
|
+
const updateScale = useCallback((id) => {
|
|
261
|
+
controls.current.policy = scalePolicyFor(id, suppliedPolicies);
|
|
262
|
+
setScale(id);
|
|
263
|
+
}, [suppliedPolicies]);
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
const id = window.setInterval(() => {
|
|
266
|
+
// The readout wraps with the scene, so the shown time never rests past the end while looping.
|
|
267
|
+
if (controls.current.loop === true)
|
|
268
|
+
runtime.clock.wrapWithin(runtime.loopWindow);
|
|
269
|
+
setClockSnapshot(runtime.clock.snapshot());
|
|
270
|
+
}, 100);
|
|
271
|
+
return () => window.clearInterval(id);
|
|
272
|
+
}, [runtime]);
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (!developerMode)
|
|
275
|
+
return undefined;
|
|
276
|
+
const stats = new FrameStats();
|
|
277
|
+
controls.current.frameStats = stats;
|
|
278
|
+
const id = window.setInterval(() => {
|
|
279
|
+
setHud(readout.current);
|
|
280
|
+
const snapshot = stats.snapshot();
|
|
281
|
+
setFrames(snapshot);
|
|
282
|
+
if (snapshot.frames > 0)
|
|
283
|
+
setFpsHistory((history) => [...history.slice(-(FPS_HISTORY - 1)), snapshot.fps]);
|
|
284
|
+
setFills(controls.current.groupFills.map((fill) => ({ ...fill })));
|
|
285
|
+
setViewNow(controls.current.viewReadout === undefined ? null : { ...controls.current.viewReadout });
|
|
286
|
+
}, 250);
|
|
287
|
+
return () => {
|
|
288
|
+
window.clearInterval(id);
|
|
289
|
+
controls.current.frameStats = null;
|
|
290
|
+
setFrames(null);
|
|
291
|
+
setFpsHistory([]);
|
|
292
|
+
};
|
|
293
|
+
}, [developerMode, runtime]);
|
|
294
|
+
/** Writes the current view, scale, up direction and time into the address, then copies the full link (or shows it to copy by hand). */
|
|
295
|
+
const copyViewLink = async () => {
|
|
296
|
+
const view = controls.current.viewReadout;
|
|
297
|
+
if (view === undefined)
|
|
298
|
+
return;
|
|
299
|
+
setViewLink(await shareViewLink({ view, scaleId: scale, up: upChoice, timeUtcMs: runtime.clock.snapshot().timeUtcMs }));
|
|
300
|
+
};
|
|
301
|
+
const displaySwitches = displaySwitchItems({
|
|
302
|
+
settings: definition.displaySwitches,
|
|
303
|
+
orbit: { present: orbitPaths.length > 0, look: orbitShown, set: setOrbit },
|
|
304
|
+
moons: { present: bodySets.length > 0, look: setLook, set: changeSetLook },
|
|
305
|
+
sky: { present: runtime.sky.visible, on: milkyWayOn, set: (on) => { controls.current.showMilkyWay = on; setMilkyWayOn(on); } },
|
|
306
|
+
labels: {
|
|
307
|
+
objectIds: experience.objects.map((object) => object.id), hidden: hiddenLabels,
|
|
308
|
+
setHidden: (hidden) => { controls.current.hiddenLabels = new Set(hidden); setHiddenLabels(new Set(hidden)); },
|
|
309
|
+
anchorsPresent: runtime.trackedBodies.length > 0, anchors: anchorLabels, setAnchors: (on) => { controls.current.showAnchorLabels = on; setAnchorLabels(on); },
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
const sections = definition.developerSections ?? [];
|
|
313
|
+
const renderSection = (section) => (_jsxs("section", { className: section.id === "clock" ? "hud-section hud-section-clock" : "hud-section", "aria-labelledby": `developer-${section.id}-heading`, children: [_jsx("h3", { id: `developer-${section.id}-heading`, children: section.heading }), section.render(experienceRuntime)] }, section.id));
|
|
314
|
+
const hasStoryPanels = (storySet?.panels.length ?? 0) > 0;
|
|
315
|
+
const showDisplay = showsDisplayControls(definition, runtime, orbitPaths.length, storyMarkerSpecs.length);
|
|
316
|
+
// Orbit-line sliders: the first four stay in view, the rest sit in a nested "Fine-tune" fold (T-090).
|
|
317
|
+
const orbitSliders = {
|
|
318
|
+
main: [
|
|
319
|
+
["baseOpacity", "Ring opacity", "orbit-base-opacity", 0.01],
|
|
320
|
+
["endFade", "End fade (of ring)", "orbit-end-fade", 0.01],
|
|
321
|
+
["arcFraction", "Arc length (of orbit)", "orbit-arc-fraction", 0.01],
|
|
322
|
+
["arcPeak", "Arc opacity", "orbit-arc-peak", 0.01],
|
|
323
|
+
],
|
|
324
|
+
fine: [
|
|
325
|
+
["arcExponent", "Fade curve (power)", "orbit-arc-exponent", 0.1],
|
|
326
|
+
["arcSegments", "Arc segments", "orbit-arc-segments", 1],
|
|
327
|
+
["arcWidth", "Arc width (of orbit)", "orbit-arc-width", 0.0001],
|
|
328
|
+
["arcMaxWidthPx", "Arc max width (px)", "orbit-arc-max-width", 0.5],
|
|
329
|
+
["zoomBoostBase", "Zoom boost (ring)", "orbit-zoom-boost-base", 0.01],
|
|
330
|
+
["zoomBoostArc", "Zoom boost (arc)", "orbit-zoom-boost-arc", 0.01],
|
|
331
|
+
],
|
|
332
|
+
};
|
|
333
|
+
const orbitSlider = ([key, label, testId, step]) => (_jsx(SettingSlider, { label: label, ariaLabel: label, testId: `${testId}-value`, display: orbitShown[key].toFixed(step === 1 ? 0 : step === 0.5 ? 1 : step < 0.01 ? 4 : 2), min: ORBIT_LOOK_LIMITS[key].min, max: ORBIT_LOOK_LIMITS[key].max, step: step, value: orbitShown[key], onChange: (value) => setOrbit({ [key]: value }) }, key));
|
|
334
|
+
// The panel's folds, in order; the first one present opens by default and the rest start closed (T-090).
|
|
335
|
+
const groups = [
|
|
336
|
+
sections.length === 0 ? null : {
|
|
337
|
+
id: "demo", title: "This demo", className: "dev-group-cards",
|
|
338
|
+
body: (_jsxs(_Fragment, { children: [sections.filter((section) => section.placement === "before-scene").map(renderSection), sections.filter((section) => section.placement === "after-scene").map(renderSection)] })),
|
|
339
|
+
},
|
|
340
|
+
!showDisplay ? null : {
|
|
341
|
+
id: "camera", title: "Camera and view",
|
|
342
|
+
body: (_jsxs(_Fragment, { children: [_jsx(SettingButtons, { label: "Up direction", children: [["ecliptic", "Planets' plane (ecliptic)"], ["equatorial", "Earth's pole (equatorial)"]].map(([choice, text]) => (_jsx("button", { "aria-pressed": upChoice === choice, onClick: () => { controls.current.up = viewUpVector(choice); setUpChoice(choice); }, children: text }, choice))) }), _jsx(SettingSlider, { label: "Marker threshold (px)", ariaLabel: "Body marker threshold", testId: "body-marker-value", display: markerPx.toFixed(1), min: 0, max: 20, step: 0.5, value: markerPx, onChange: (value) => { controls.current.bodyMarker = { ...controls.current.bodyMarker, minSpherePx: value }; setMarkerPx(value); } }), _jsx(SettingSlider, { label: "Loading fade (s, next load)", ariaLabel: "Loading fade", testId: "load-fade-value", display: loadFade.toFixed(1), min: BOOT_FADE_LIMITS.min, max: BOOT_FADE_LIMITS.max, step: 0.1, value: loadFade, onChange: (value) => { saveBootFadeSeconds(value); setLoadFade(value); } }), _jsxs("div", { className: "view-link", role: "group", "aria-label": "Camera view", children: [_jsx(SettingButtons, { label: "Camera view", children: _jsx("button", { onClick: () => void copyViewLink(), children: "Copy view link" }) }), _jsx(ViewLinkReadout, { viewNow: viewNow, viewLink: viewLink, scale: scale, upChoice: upChoice })] }), _jsx(SettingButtons, { children: _jsx("button", { "aria-pressed": loopOn, onClick: () => { controls.current.loop = !loopOn; setLoopOn(!loopOn); }, children: "Loop playback" }) })] })),
|
|
343
|
+
},
|
|
344
|
+
!showDisplay ? null : {
|
|
345
|
+
id: "timeline", title: "Timeline and stories",
|
|
346
|
+
body: (_jsxs(_Fragment, { children: [_jsxs(SettingGroup, { id: "timeline-glow", title: "Timeline glow", children: [_jsx(SettingColor, { label: "Glow colour", ariaLabel: "Timeline glow colour", testId: "glow-color-value", value: timelineGlow.color, onChange: (color) => setTimelineGlow({ ...timelineGlow, color }) }), _jsx(SettingColor, { label: "Played colour", ariaLabel: "Timeline played colour", testId: "glow-played-value", value: timelineGlow.playedColor, onChange: (playedColor) => setTimelineGlow({ ...timelineGlow, playedColor }) }), [
|
|
347
|
+
["minBrightness", "Quiet brightness", "Timeline quiet brightness", "glow-min-value", 0, 1, 0.01],
|
|
348
|
+
["steadyBrightness", "Steady brightness (no rate)", "Timeline steady brightness", "glow-steady-value", 0, 1, 0.01],
|
|
349
|
+
["curve", "Curve (rate to brightness)", "Timeline glow curve", "glow-curve-value", 0.2, 3, 0.05],
|
|
350
|
+
["playedFloor", "Played brightness floor", "Timeline played floor", "glow-floor-value", 0, 1, 0.01],
|
|
351
|
+
["thicknessPx", "Thickness (px)", "Timeline glow thickness", "glow-thickness-value", 2, 14, 0.5],
|
|
352
|
+
["haloPx", "Halo blur (px)", "Timeline glow halo", "glow-halo-value", 0, 20, 0.5],
|
|
353
|
+
].map(([key, label, ariaLabel, testId, min, max, step]) => (_jsx(SettingSlider, { label: label, ariaLabel: ariaLabel, testId: testId, display: timelineGlow[key].toFixed(step < 0.1 ? 2 : step < 1 ? 1 : 0), min: min, max: max, step: step, value: timelineGlow[key], onChange: (value) => setTimelineGlow({ ...timelineGlow, [key]: value }) }, key))), _jsx(SettingButtons, { children: _jsx("button", { onClick: () => setTimelineGlow(DEFAULT_TIMELINE_GLOW), children: "Reset glow" }) })] }), hasStoryPanels && _jsx(StoryPanelSettings, { storyAutoOpen: storyAutoOpen, setStoryAutoOpen: setStoryAutoOpen, storyPauseSeconds: storyPauseSeconds, setStoryPauseSeconds: setStoryPauseSeconds })] })),
|
|
354
|
+
},
|
|
355
|
+
orbitPaths.length === 0 ? null : {
|
|
356
|
+
id: "orbit-lines", title: "Orbit lines",
|
|
357
|
+
body: (_jsxs(_Fragment, { children: [_jsxs(SettingButtons, { children: [_jsx("button", { "aria-pressed": orbitShown.baseOn, onClick: () => setOrbit({ baseOn: !orbitShown.baseOn }), children: "Orbit ring" }), _jsx("button", { "aria-pressed": orbitShown.endFadeOn, onClick: () => setOrbit({ endFadeOn: !orbitShown.endFadeOn }), children: "Fade ring ends" }), _jsx("button", { "aria-pressed": orbitShown.arcOn, onClick: () => setOrbit({ arcOn: !orbitShown.arcOn }), children: "Trailing arc" }), _jsx("button", { "aria-pressed": orbitShown.zoomOn, onClick: () => setOrbit({ zoomOn: !orbitShown.zoomOn }), children: "Brighten when zoomed out" })] }), orbitSliders.main.map(orbitSlider), _jsx(Collapsible, { id: "orbit-fine-tune", title: "Fine-tune", level: 4, nested: true, children: orbitSliders.fine.map(orbitSlider) }), _jsx(SettingButtons, { children: _jsx("button", { onClick: resetOrbit, children: "Reset orbit lines" }) })] })),
|
|
358
|
+
},
|
|
359
|
+
bodySets.length === 0 && ringSystems.length === 0 ? null : {
|
|
360
|
+
id: "moons-rings", title: "Moons and rings",
|
|
361
|
+
body: (_jsx(MoonsAndRingsSettings, { bodySets: bodySets, ringSystems: ringSystems, setLook: setLook, changeSetLook: changeSetLook, ringLook: ringLook, changeRing: changeRing, controls: controls, setSetLook: setSetLook, setRingLook: setRingLook })),
|
|
362
|
+
},
|
|
363
|
+
!(runtime.sky.visible || glowShown !== null) ? null : {
|
|
364
|
+
id: "sky-sun", title: "Sky and Sun",
|
|
365
|
+
body: (_jsx(SkyAndSunSettings, { illuminateAll: illuminateAll, setIlluminateAll: setIlluminateAll, visible: runtime.sky.visible, glowShown: glowShown, setGlowShown: setGlowShown, controls: controls, milkyWayOn: milkyWayOn, setMilkyWayOn: setMilkyWayOn, starBrightness: starBrightness, setStarBrightness: setStarBrightness, milkyWayBrightness: milkyWayBrightness, setMilkyWayBrightness: setMilkyWayBrightness })),
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
id: "labels", title: "Labels",
|
|
369
|
+
body: (_jsx(LabelSettings, { controls: controls, hoverBrightness: hoverBrightness, setHoverBrightness: setHoverBrightness, labelToggles: labelToggles, trackedCount: runtime.trackedBodies.length, anchorLabels: anchorLabels, setAnchorLabels: setAnchorLabels, hiddenLabels: hiddenLabels, setHiddenLabels: setHiddenLabels })),
|
|
370
|
+
},
|
|
371
|
+
!showDisplay ? null : {
|
|
372
|
+
id: "phone-layout", title: "Phone layout",
|
|
373
|
+
body: (_jsxs(_Fragment, { children: [[
|
|
374
|
+
["animationMs", "Drawer animation (ms)", "Phone drawer animation", "phone-animation-value"],
|
|
375
|
+
["controlsDrawerMaxPercent", "Top drawer height (% of screen)", "Phone top drawer height", "phone-controls-height-value"],
|
|
376
|
+
["timelineDrawerMaxPercent", "Timeline drawer height (% of screen)", "Phone timeline drawer height", "phone-timeline-height-value"],
|
|
377
|
+
["sheetMaxPercent", "Sheet height (% of screen)", "Phone sheet height", "phone-sheet-height-value"],
|
|
378
|
+
["swipeThresholdPx", "Swipe distance (px)", "Phone swipe distance", "phone-swipe-value"],
|
|
379
|
+
].map(([key, label, ariaLabel, testId]) => (_jsx(SettingSlider, { label: label, ariaLabel: ariaLabel, testId: testId, display: String(phoneLayout[key]), min: PHONE_LAYOUT_LIMITS[key].min, max: PHONE_LAYOUT_LIMITS[key].max, step: PHONE_LAYOUT_LIMITS[key].step, value: phoneLayout[key], onChange: (value) => setPhoneLayout({ ...phoneLayout, [key]: value }) }, key))), _jsx(SettingButtons, { children: _jsx("button", { onClick: () => setPhoneLayout(DEFAULT_PHONE_LAYOUT), children: "Reset phone layout" }) })] })),
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
id: "under-the-hood", title: "Under the hood",
|
|
383
|
+
body: (_jsx(UnderTheHoodSettings, { hud: hud, frames: frames, fills: fills, fpsHistory: fpsHistory, alternates: showDisplay ? definition.alternates : undefined })),
|
|
384
|
+
},
|
|
385
|
+
];
|
|
386
|
+
const presentGroups = groups.filter((group) => group !== null);
|
|
387
|
+
const developerTools = (_jsx(PanelLoadBoundary, { children: _jsx(Suspense, { fallback: _jsx("p", { className: "developer-loading", role: "status", children: "Loading developer tools..." }), children: _jsxs("div", { className: "hud", children: [_jsxs("header", { className: "developer-heading", children: [_jsx("h2", { children: "Developer tools" }), _jsx("p", { children: "Live readouts, controls and diagnostics for this scene." })] }), presentGroups.map((group, index) => (_jsx(Collapsible, { id: group.id, title: group.title, defaultOpen: index === 0, className: `dev-group${group.className === undefined ? "" : ` ${group.className}`}`, children: group.body }, group.id)))] }) }) }));
|
|
388
|
+
return (_jsx(AstraeusShell, { experience: shellExperience, snapshot: clockSnapshot, developerMode: developerMode, onDeveloperModeChange: setDeveloperMode, onTogglePlayback: () => {
|
|
389
|
+
if (runtime.clock.playing)
|
|
390
|
+
runtime.clock.pause();
|
|
391
|
+
else
|
|
392
|
+
runtime.clock.play();
|
|
393
|
+
setClockSnapshot(runtime.clock.snapshot());
|
|
394
|
+
}, onRateChange: (rate) => {
|
|
395
|
+
runtime.clock.setRate(rate);
|
|
396
|
+
setClockSnapshot(runtime.clock.snapshot());
|
|
397
|
+
}, onSeek: (timeUtcMs) => {
|
|
398
|
+
runtime.clock.seek(timeUtcMs);
|
|
399
|
+
setClockSnapshot(runtime.clock.snapshot());
|
|
400
|
+
}, onCameraRequest: updateCameraRequest, onSelectionChange: updateSelectedObject, scaleId: scale, onScaleChange: updateScale, scaleChoices: scaleChoices, switcher: switcherOf(definition, runtime, onOpenAddress), displaySwitches: displaySwitches, metricsFor: metricsFor, developerTools: developerTools, storyPanelSettings: { autoOpen: storyAutoOpen, pauseSeconds: storyPauseSeconds }, timelineGlow: timelineGlow, phoneLayout: phoneLayout, highlightedFamily: setLook.highlightFamily, onHighlightFamily: highlightFamily, onSetPlaying: setPlaying, panelRequest: panelRequest, onOpenPanelChange: markOpenPanel, featureRequest: featureRequest, pickRequest: pickRequest, onOpenFeatureChange: markOpenFeature, children: _jsx("div", { className: "canvas-host", children: _jsx(AstraeusScene, { runtime: runtime, controls: controls.current, readout: readout, scaleId: scale }) }) }));
|
|
401
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Component, type ReactNode } from "react";
|
|
2
2
|
/**
|
|
3
|
-
* Catches a failed on-demand load of the developer panels (offline, or a tab left open across a redeploy) so the
|
|
3
|
+
* Catches a failed on-demand load of a panel (the developer panels, the moon families; `message` replaces the default text) (offline, or a tab left open across a redeploy) so the
|
|
4
4
|
* rest of the app keeps drawing; React.lazy keeps the failed load, so the message asks for a reload.
|
|
5
5
|
*/
|
|
6
6
|
export declare class PanelLoadBoundary extends Component<{
|
|
7
7
|
children: ReactNode;
|
|
8
|
+
message?: string;
|
|
8
9
|
}, {
|
|
9
10
|
failed: boolean;
|
|
10
11
|
}> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Component } from "react";
|
|
3
3
|
/**
|
|
4
|
-
* Catches a failed on-demand load of the developer panels (offline, or a tab left open across a redeploy) so the
|
|
4
|
+
* Catches a failed on-demand load of a panel (the developer panels, the moon families; `message` replaces the default text) (offline, or a tab left open across a redeploy) so the
|
|
5
5
|
* rest of the app keeps drawing; React.lazy keeps the failed load, so the message asks for a reload.
|
|
6
6
|
*/
|
|
7
7
|
export class PanelLoadBoundary extends Component {
|
|
@@ -11,7 +11,7 @@ export class PanelLoadBoundary extends Component {
|
|
|
11
11
|
}
|
|
12
12
|
render() {
|
|
13
13
|
if (this.state.failed)
|
|
14
|
-
return _jsx("p", { className: "developer-loading", role: "alert", children: "Developer tools could not load. Reload the page to try again." });
|
|
14
|
+
return _jsx("p", { className: "developer-loading", role: "alert", children: this.props.message ?? "Developer tools could not load. Reload the page to try again." });
|
|
15
15
|
return this.props.children;
|
|
16
16
|
}
|
|
17
17
|
}
|
package/src/app/SkyView.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export interface SkyViewOptions {
|
|
|
11
11
|
readonly maxAnisotropy?: number;
|
|
12
12
|
/** Whether the picture is drawn. Defaults to true. */
|
|
13
13
|
readonly milkyWay?: boolean;
|
|
14
|
-
/** Legacy:
|
|
14
|
+
/** Legacy: ready textures, one per tile (a test may pass empty ones). Overrides `picture`. */
|
|
15
15
|
readonly pictures?: readonly Texture[];
|
|
16
|
-
/** The picture to draw, as a tile grid; defaults to the
|
|
16
|
+
/** The picture to draw, as a tile grid; defaults to the Milky Way picture. `null` draws none until `requestPicture` is called. */
|
|
17
17
|
readonly picture?: PictureSet | null;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -26,7 +26,7 @@ export declare class SkyView {
|
|
|
26
26
|
readonly group: Group<import("three").Object3DEventMap>;
|
|
27
27
|
/** `options.picture` is the tile set; the scene passes the one it resolved, a test may pass `pictures` (empty textures). */
|
|
28
28
|
constructor(options: SkyViewOptions);
|
|
29
|
-
/** Builds the
|
|
29
|
+
/** Builds the Milky Way picture the first time it is wanted (nothing is decoded while the picture stays off); a no-op once a picture is held. */
|
|
30
30
|
requestPicture(): void;
|
|
31
31
|
/** Sets the star strength in place (0 to 2); no rebuild. */
|
|
32
32
|
setStarBrightness(value: number): void;
|
package/src/app/SkyView.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { AdditiveBlending, BufferAttribute, BufferGeometry, DoubleSide, LinearFilter, LinearMipmapLinearFilter, Group, Mesh, Points, ShaderMaterial, NoColorSpace, TextureLoader, Vector3 } from "three";
|
|
2
|
-
import {
|
|
2
|
+
import { MILKY_WAY_PICTURE } from "../assets/sky.js";
|
|
3
3
|
import { buildPictureMesh, buildStarBuffers } from "./skyModel.js";
|
|
4
4
|
// Both draws sit before everything else in the first pass (the layer-0 pass), ignore depth, and write none.
|
|
5
5
|
const SKY_ORDER = -1000;
|
|
6
|
-
/** Strength of the picture at brightness 1
|
|
7
|
-
const PICTURE_GAIN =
|
|
6
|
+
/** Strength of the picture at brightness 1, applied after the dimming below (1: the slider scales what the dimming leaves). */
|
|
7
|
+
const PICTURE_GAIN = 1;
|
|
8
|
+
/**
|
|
9
|
+
* The picture is a bright render, so it is dimmed the way Star Explorer dims its sky texture (an sRGB texture times a dark grey, drawn
|
|
10
|
+
* additively): decode to linear light, multiply, encode again. 0.04 gives a mean grey of about 2.2%, the level of the owner's
|
|
11
|
+
* 2026-10-27 trial (linear x 0.04, which at the old gain of 0.5 was written x 2). With a pure 2.2 power the decode and encode cancel,
|
|
12
|
+
* so this is a flat scale of the stored (sRGB) value by 0.04^(1/2.2), about 0.2315, the same for faint and bright values. Look-tuning is the Milky Way brightness setting, which scales the result.
|
|
13
|
+
*/
|
|
14
|
+
const PICTURE_DIM = 0.04;
|
|
8
15
|
/** A fixed render-frame direction used to read the sky back: where it lands on screen depends only on the camera orientation. */
|
|
9
16
|
const PROBE_DIRECTION = new Vector3(0.62, 0.35, -0.7).normalize();
|
|
10
17
|
const PICTURE_VERTEX = `
|
|
@@ -16,9 +23,11 @@ void main() {
|
|
|
16
23
|
const PICTURE_FRAGMENT = `
|
|
17
24
|
uniform sampler2D uMap;
|
|
18
25
|
uniform float uGain;
|
|
26
|
+
uniform float uDim;
|
|
19
27
|
varying vec2 vUv;
|
|
20
28
|
void main() {
|
|
21
|
-
|
|
29
|
+
vec3 linear = pow(texture2D(uMap, vUv).rgb, vec3(2.2)) * uDim;
|
|
30
|
+
gl_FragColor = vec4(pow(linear, vec3(1.0 / 2.2)) * uGain, 1.0);
|
|
22
31
|
}`;
|
|
23
32
|
// A star is a small Gaussian core: `aSize` is its width at half maximum in CSS pixels, the sprite is wide enough to hold three
|
|
24
33
|
// sigma either side, and the fragment measures the distance from the star's centre in device pixels, so it is sharp at any pixel ratio.
|
|
@@ -71,9 +80,9 @@ export class SkyView {
|
|
|
71
80
|
this.#brightness = milkyWayBrightness;
|
|
72
81
|
this.#maxAnisotropy = maxAnisotropy;
|
|
73
82
|
if (options.pictures !== undefined)
|
|
74
|
-
this.#build(
|
|
83
|
+
this.#build(MILKY_WAY_PICTURE, options.pictures);
|
|
75
84
|
else if (options.picture !== null)
|
|
76
|
-
this.#build(options.picture ??
|
|
85
|
+
this.#build(options.picture ?? MILKY_WAY_PICTURE);
|
|
77
86
|
this.#starMaterial = new ShaderMaterial({
|
|
78
87
|
vertexShader: STAR_VERTEX,
|
|
79
88
|
fragmentShader: STAR_FRAGMENT,
|
|
@@ -93,7 +102,7 @@ export class SkyView {
|
|
|
93
102
|
set.tiles.forEach((tile, index) => {
|
|
94
103
|
const texture = textures?.[index] ?? new TextureLoader().load(tile.url);
|
|
95
104
|
this.#textures.push(texture);
|
|
96
|
-
//
|
|
105
|
+
// The texture is read as raw sRGB values and the shader does the dimming (PICTURE_DIM); mipmaps and anisotropic filtering keep the
|
|
97
106
|
// picture from sparkling when it is drawn smaller than the file, and the magnified case is plain bilinear.
|
|
98
107
|
texture.colorSpace = NoColorSpace;
|
|
99
108
|
texture.generateMipmaps = true;
|
|
@@ -104,7 +113,7 @@ export class SkyView {
|
|
|
104
113
|
const material = new ShaderMaterial({
|
|
105
114
|
vertexShader: PICTURE_VERTEX,
|
|
106
115
|
fragmentShader: PICTURE_FRAGMENT,
|
|
107
|
-
uniforms: { uMap: { value: texture }, uGain: { value: PICTURE_GAIN * this.#brightness } },
|
|
116
|
+
uniforms: { uMap: { value: texture }, uDim: { value: PICTURE_DIM }, uGain: { value: PICTURE_GAIN * this.#brightness } },
|
|
108
117
|
side: DoubleSide,
|
|
109
118
|
depthTest: false,
|
|
110
119
|
depthWrite: false,
|
|
@@ -137,10 +146,10 @@ export class SkyView {
|
|
|
137
146
|
this.#textures = [];
|
|
138
147
|
this.#held = false;
|
|
139
148
|
}
|
|
140
|
-
/** Builds the
|
|
149
|
+
/** Builds the Milky Way picture the first time it is wanted (nothing is decoded while the picture stays off); a no-op once a picture is held. */
|
|
141
150
|
requestPicture() {
|
|
142
151
|
if (!this.#held)
|
|
143
|
-
this.#build(
|
|
152
|
+
this.#build(MILKY_WAY_PICTURE);
|
|
144
153
|
}
|
|
145
154
|
/** Sets the star strength in place (0 to 2); no rebuild. */
|
|
146
155
|
setStarBrightness(value) {
|
|
@@ -129,6 +129,14 @@ export interface CameraReach {
|
|
|
129
129
|
readonly maxFocusDistance?: number;
|
|
130
130
|
/** Far clipping plane; must exceed `maxFocusDistance` when both are given. */
|
|
131
131
|
readonly far?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Fit the farthest zoom-out to one orbit about the Sun instead of a fixed `maxFocusDistance`: `farthestKm` is the orbit's farthest Sun distance
|
|
134
|
+
* (read once the viewer needs it, after the planet series load). The viewer turns it into a distance for the live canvas shape (`fitReach`) and
|
|
135
|
+
* re-fits when the canvas changes shape. Takes the place of `maxFocusDistance` and `far`, which a fitting reach does not carry.
|
|
136
|
+
*/
|
|
137
|
+
readonly fitOrbit?: {
|
|
138
|
+
readonly farthestKm: () => number;
|
|
139
|
+
};
|
|
132
140
|
}
|
|
133
141
|
/** The scene's far plane when an experience declares none. */
|
|
134
142
|
export declare const DEFAULT_CAMERA_FAR = 5000;
|
|
@@ -9,7 +9,7 @@ import { releaseGlowTexture } from "./bodyDraw.js";
|
|
|
9
9
|
import { assetWithOverride } from "./experienceDefinition.js";
|
|
10
10
|
import { FeatureMarkerLayer } from "./FeatureMarkers.js";
|
|
11
11
|
import { bodiesMounted, runFrame } from "./sceneFrame.js";
|
|
12
|
-
import { focusLimits } from "./sceneFraming.js";
|
|
12
|
+
import { focusLimits, liveReach } from "./sceneFraming.js";
|
|
13
13
|
import { useHostLayer } from "./sceneHooks.js";
|
|
14
14
|
import { readoutPairOf } from "./sceneLayout.js";
|
|
15
15
|
import { SceneLabelLayer } from "./SceneLabels.js";
|
|
@@ -76,7 +76,7 @@ export function useOverlayLayers(canvas, controls, trackedViews, bodySetViews) {
|
|
|
76
76
|
/** Wires the canvas's orbit gestures, hover and tap picking to the camera and frame state. */
|
|
77
77
|
export function useScenePointer(canvas, runtime, controls, catalogue, orbit, state) {
|
|
78
78
|
useEffect(() => {
|
|
79
|
-
const limits = () => focusLimits(bodyIdOf(runtime, catalogue, orbit.current.focus) ?? orbit.current.focus, { centre: runtime.sceneCenter, span: state.current.spanScaled, bodies: catalogue }, controls.policy, runtime.cameraReach);
|
|
79
|
+
const limits = () => focusLimits(bodyIdOf(runtime, catalogue, orbit.current.focus) ?? orbit.current.focus, { centre: runtime.sceneCenter, span: state.current.spanScaled, bodies: catalogue }, controls.policy, liveReach(runtime.cameraReach, controls.policy, canvas.clientHeight > 0 ? canvas.clientWidth / canvas.clientHeight : 1));
|
|
80
80
|
return attachScenePointer(canvas, orbit.current, state.current, limits, (id) => controls.onPickObject?.(id));
|
|
81
81
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
82
|
}, [canvas, controls]);
|
package/src/app/sceneFrame.js
CHANGED
|
@@ -6,7 +6,7 @@ import { DEFAULT_CAMERA_FAR } from "./experienceDefinition.js";
|
|
|
6
6
|
import { DEFAULT_FEATURE_MIN_BODY_PX } from "./FeatureMarkers.js";
|
|
7
7
|
import { rescaleCameraForPolicy, stepCameraTarget } from "./sceneCamera.js";
|
|
8
8
|
import { buildFrameReadout, publishBodyData, publishPathData, publishPointsData, publishSceneData, recordFrameStats } from "./sceneDebug.js";
|
|
9
|
-
import { focusRadius } from "./sceneFraming.js";
|
|
9
|
+
import { focusRadius, liveReach } from "./sceneFraming.js";
|
|
10
10
|
import { bodyScreenReadouts, placeBodies, swapSmallBodiesToMarkers } from "./sceneBodies.js";
|
|
11
11
|
import { publishBodySets } from "./sceneBodySets.js";
|
|
12
12
|
import { bodyAbsolute, placeComposition } from "./sceneLayout.js";
|
|
@@ -95,11 +95,12 @@ export function stepAndPoseCamera(ctx, t, placed) {
|
|
|
95
95
|
const targets = { bodyIdFor: ctx.bodyIdFor, placed: placed.composed.absolutes, absoluteOf: placed.absoluteOf, groupViews: views.groupViews, sunCentredViews: views.sunCentredViews, trackedViews: views.trackedViews, bodySetViews: views.bodySetViews, timeUtcMs: t, policy, placement: ctx.placement };
|
|
96
96
|
const firstFrame = !state.started;
|
|
97
97
|
state.started = true;
|
|
98
|
-
const
|
|
98
|
+
const reach = liveReach(runtime.cameraReach, policy, camera.aspect);
|
|
99
|
+
const focusBody = stepCameraTarget({ camState: orbit, controls, targets, frame, catalogue, reach, fovDeg: camera.fov, viewUp, firstFrame, previousUp: state.lastUp });
|
|
99
100
|
state.lastUp = viewUp;
|
|
100
101
|
resolveCamera(orbit, focusAbsoluteOf(targets, orbit.focus), ctx.origin, ctx.delta, REBASE_THRESHOLD, viewUp);
|
|
101
102
|
placeBodies(ctx.assets, placed.composed.states, ctx.bodyRefs, policy, ctx.origin);
|
|
102
|
-
poseCamera(camera, orbit, focusRadius(focusBody, policy, catalogue), ctx.origin,
|
|
103
|
+
poseCamera(camera, orbit, focusRadius(focusBody, policy, catalogue), ctx.origin, reach.far ?? DEFAULT_CAMERA_FAR, viewUp);
|
|
103
104
|
if (firstFrame)
|
|
104
105
|
requestAnimationFrame(() => hideBootLoader(state.coverShowing));
|
|
105
106
|
controls.viewReadout = viewFromAngles(orbit.focus, orbit.azimuth, orbit.elevation, orbit.distance);
|
|
@@ -32,6 +32,19 @@ export interface SceneFrame {
|
|
|
32
32
|
* `poseCamera`), so even a 1 km moon's ball is drawn rather than cut away.
|
|
33
33
|
*/
|
|
34
34
|
export declare const MEMBER_MIN_DISTANCE = 0.0015;
|
|
35
|
+
/** The camera's vertical field of view in degrees (the Canvas's `fov`). */
|
|
36
|
+
export declare const CAMERA_FOV_DEG = 45;
|
|
37
|
+
/** Room left round a fitted orbit, as a multiple. */
|
|
38
|
+
export declare const ORBIT_FIT_MARGIN = 1.1;
|
|
39
|
+
/** The far plane of a fitted reach, as a multiple of the reach (what `camera.setReach` uses too). */
|
|
40
|
+
export declare const FAR_PER_REACH = 2.5;
|
|
41
|
+
/**
|
|
42
|
+
* The camera-to-focus distance at which a sphere of radius `farthestUnits` about the focus fits the canvas from any view direction:
|
|
43
|
+
* the farthest distance divided by the sine of the narrower half field of view (vertical, or horizontal from the aspect ratio), times the margin.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fitReach(farthestUnits: number, aspect: number, fovDeg?: number): number;
|
|
46
|
+
/** The declared reach as the viewer applies it now: a fitting reach becomes a farthest zoom-out and far plane for the canvas shape `aspect` (width over height); any other is returned as is. */
|
|
47
|
+
export declare function liveReach(declared: CameraReach, policy: ScalePolicy, aspect: number): CameraReach;
|
|
35
48
|
/** Zoom limits per focus kind; a declared reach replaces only the farthest distance. */
|
|
36
49
|
export declare function focusLimits(focus: BodyId, frame: SceneFrame, policy: ScalePolicy, declared: CameraReach): {
|
|
37
50
|
min: number;
|