astraeus 0.7.0 → 0.8.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 +189 -0
- package/README.md +202 -38
- package/data/ephemerides/planets/planets.json +1 -1
- package/package.json +5 -4
- package/src/api/AstraeusScene.d.ts +21 -5
- package/src/api/AstraeusScene.js +34 -10
- package/src/api/AstraeusScene.node.js +34 -10
- package/src/api/assembleScene.d.ts +36 -0
- package/src/api/assembleScene.js +175 -0
- package/src/api/bodySetChecks.d.ts +10 -0
- package/src/api/bodySetChecks.js +117 -0
- package/src/api/bodySetInput.d.ts +81 -0
- package/src/api/bodySetInput.js +1 -0
- package/src/api/containingBlock.d.ts +6 -0
- package/src/api/containingBlock.js +16 -0
- package/src/api/data.d.ts +17 -5
- package/src/api/data.js +28 -10
- package/src/api/definitionOf.d.ts +16 -0
- package/src/api/definitionOf.js +20 -0
- package/src/api/errors.d.ts +63 -1
- package/src/api/frozenCopy.d.ts +6 -0
- package/src/api/frozenCopy.js +26 -0
- package/src/api/group.d.ts +8 -2
- package/src/api/group.js +24 -5
- package/src/api/index.d.ts +18 -7
- package/src/api/index.js +2 -2
- package/src/api/index.node.js +2 -2
- package/src/api/listeners.d.ts +5 -0
- package/src/api/listeners.js +25 -0
- package/src/api/look.d.ts +47 -0
- package/src/api/look.js +1 -0
- package/src/api/lookInput.d.ts +3 -0
- package/src/api/lookInput.js +41 -0
- package/src/api/moonPanelInput.d.ts +60 -0
- package/src/api/moonPanelInput.js +1 -0
- package/src/api/mount.d.ts +9 -19
- package/src/api/mount.js +27 -13
- package/src/api/mount.node.js +27 -13
- package/src/api/pathProvenance.js +1 -1
- package/src/api/pickerInput.d.ts +25 -0
- package/src/api/pickerInput.js +1 -0
- package/src/api/planBodies.d.ts +72 -0
- package/src/api/planBodies.js +300 -0
- package/src/api/planBodySets.d.ts +68 -0
- package/src/api/planBodySets.js +234 -0
- package/src/api/planCamera.d.ts +83 -0
- package/src/api/planCamera.js +184 -0
- package/src/api/planGroups.d.ts +36 -0
- package/src/api/planGroups.js +103 -0
- package/src/api/planMoonPanel.d.ts +19 -0
- package/src/api/planMoonPanel.js +104 -0
- package/src/api/planPaths.d.ts +40 -0
- package/src/api/planPaths.js +212 -0
- package/src/api/planPicker.d.ts +12 -0
- package/src/api/planPicker.js +40 -0
- package/src/api/planPlaces.d.ts +16 -0
- package/src/api/planPlaces.js +99 -0
- package/src/api/planStory.d.ts +26 -0
- package/src/api/planStory.js +66 -0
- package/src/api/planTimeline.d.ts +27 -0
- package/src/api/planTimeline.js +68 -0
- package/src/api/planViews.d.ts +25 -0
- package/src/api/planViews.js +35 -0
- package/src/api/prepared.js +4 -1
- package/src/api/renamedInputs.d.ts +15 -0
- package/src/api/renamedInputs.js +39 -0
- package/src/api/scene.d.ts +162 -68
- package/src/api/scene.js +247 -793
- package/src/api/sceneFreeze.d.ts +4 -0
- package/src/api/sceneFreeze.js +10 -0
- package/src/api/sceneReads.d.ts +171 -0
- package/src/api/sceneReads.js +6 -0
- package/src/api/story.d.ts +49 -19
- package/src/api/story.js +54 -22
- package/src/api/sunOrbit.js +9 -11
- package/src/api/time.d.ts +2 -1
- package/src/api/time.js +2 -1
- package/src/api/viewerCamera.d.ts +22 -0
- package/src/api/viewerCamera.js +84 -0
- package/src/api/viewerClock.d.ts +30 -0
- package/src/api/viewerClock.js +85 -0
- package/src/api/viewerFirstDraw.d.ts +14 -0
- package/src/api/viewerFirstDraw.js +26 -0
- package/src/api/viewerHandle.d.ts +85 -0
- package/src/api/viewerHandle.js +32 -0
- package/src/api/viewerLink.d.ts +88 -15
- package/src/api/viewerLink.js +117 -75
- package/src/api/viewerLooks.d.ts +19 -0
- package/src/api/viewerLooks.js +37 -0
- package/src/api/viewerPicker.d.ts +22 -0
- package/src/api/viewerPicker.js +49 -0
- package/src/api/viewerSelection.d.ts +30 -0
- package/src/api/viewerSelection.js +46 -0
- package/src/api/viewerViews.d.ts +10 -0
- package/src/api/viewerViews.js +18 -0
- package/src/api/viewerZones.d.ts +20 -0
- package/src/api/viewerZones.js +47 -0
- package/src/api/views.d.ts +7 -6
- package/src/api/views.js +12 -6
- package/src/app/App.d.ts +5 -3
- package/src/app/App.js +211 -82
- package/src/app/App.node.js +211 -82
- package/src/app/AstraeusScene.d.ts +18 -2
- package/src/app/AstraeusScene.js +4 -4
- package/src/app/BodyView.d.ts +4 -1
- package/src/app/BodyView.js +2 -2
- package/src/app/CameraController.d.ts +6 -0
- package/src/app/DeveloperSettings.d.ts +1 -4
- package/src/app/DeveloperSettings.js +6 -10
- package/src/app/FeatureMarkers.d.ts +4 -3
- package/src/app/FeatureMarkers.js +8 -13
- package/src/app/FrameRateSection.js +2 -1
- package/src/app/OrbitSetView.js +1 -1
- package/src/app/SettingControls.d.ts +11 -3
- package/src/app/SettingControls.js +10 -2
- package/src/app/SkyView.d.ts +3 -10
- package/src/app/SkyView.js +6 -28
- package/src/app/address.d.ts +16 -0
- package/src/app/address.js +31 -0
- package/src/app/bodyDraw.d.ts +10 -7
- package/src/app/bodyDraw.js +12 -32
- package/src/app/bodyMetrics.js +2 -2
- package/src/app/bodySet.d.ts +4 -20
- package/src/app/bodySet.js +5 -16
- package/src/app/debugReadout.js +1 -1
- package/src/app/displaySwitches.d.ts +4 -0
- package/src/app/displaySwitches.js +6 -0
- package/src/app/experienceDefinition.d.ts +11 -23
- package/src/app/listSwitch.d.ts +8 -14
- package/src/app/listSwitch.js +3 -10
- package/src/app/liveLook.d.ts +39 -0
- package/src/app/liveLook.js +66 -0
- package/src/app/look.d.ts +36 -0
- package/src/app/look.js +61 -0
- package/src/app/mission.d.ts +1 -1
- package/src/app/mission.js +1 -1
- package/src/app/openClock.d.ts +3 -2
- package/src/app/openClock.js +3 -3
- package/src/app/sceneCamera.d.ts +2 -0
- package/src/app/sceneCamera.js +11 -1
- package/src/app/sceneFrame.d.ts +4 -4
- package/src/app/sceneFrame.js +13 -8
- package/src/app/sceneHooks.js +3 -2
- package/src/app/style.css +114 -139
- package/src/app/trackedMetrics.d.ts +10 -3
- package/src/app/trackedMetrics.js +22 -11
- package/src/app/viewLink.d.ts +10 -32
- package/src/app/viewLink.js +10 -49
- package/src/app/viewerPort.d.ts +52 -0
- package/src/app/views.d.ts +3 -0
- package/src/assets/bodies/galileanMoons.js +1 -2
- package/src/assets/bodies/io.js +2 -2
- package/src/assets/bodies/listedMoons.d.ts +1 -1
- package/src/assets/bodies/listedMoons.js +2 -3
- package/src/assets/bodies/planetSystemMaps.js +2 -3
- package/src/assets/bodies/venus.js +2 -6
- package/src/assets/catalogue.js +1 -2
- package/src/assets/licence.d.ts +3 -3
- package/src/assets/licence.js +3 -3
- package/src/assets/pictures.d.ts +15 -12
- package/src/assets/pictures.js +24 -20
- package/src/assets/sky.d.ts +6 -5
- package/src/assets/sky.js +6 -9
- package/src/assets/visual.d.ts +4 -0
- package/src/core/astronomyAdapter.d.ts +1 -1
- package/src/core/astronomyAdapter.js +3 -3
- package/src/core/bodies/index.d.ts +0 -4
- package/src/core/bodies/index.js +14 -18
- package/src/core/bodies/jupiter.js +1 -1
- package/src/core/bodies/jupiterData.d.ts +0 -1
- package/src/core/bodies/jupiterData.js +2 -5
- package/src/core/bodies/mars.js +1 -1
- package/src/core/bodies/mercury.js +1 -1
- package/src/core/bodies/moonSystem.d.ts +1 -1
- package/src/core/bodies/moonSystem.js +102 -55
- package/src/core/bodies/outerPlanetRingData.js +2 -2
- package/src/core/bodies/outerPlanets.d.ts +2 -3
- package/src/core/bodies/outerPlanets.js +4 -13
- package/src/core/bodies/planetMoons.d.ts +0 -2
- package/src/core/bodies/planetMoons.js +1 -18
- package/src/core/bodies/planetRecords.d.ts +8 -2
- package/src/core/bodies/planetRecords.js +13 -5
- package/src/core/bodies/planetTrajectory.d.ts +21 -4
- package/src/core/bodies/planetTrajectory.js +29 -5
- package/src/core/bodies/venus.js +1 -1
- package/src/core/bodySetFamilies.d.ts +20 -0
- package/src/core/bodySetFamilies.js +14 -0
- package/src/core/chebyshevEphemeris.js +1 -1
- package/src/core/elementsBody.d.ts +8 -4
- package/src/core/elementsBody.js +32 -11
- package/src/core/elementsGroup.d.ts +27 -0
- package/src/core/elementsGroup.js +85 -0
- package/src/core/events.d.ts +2 -0
- package/src/core/events.js +2 -0
- package/src/core/illumination.js +1 -1
- package/src/core/listedOrbitGroup.d.ts +2 -0
- package/src/core/listedOrbitGroup.js +11 -7
- package/src/core/moonListText.d.ts +6 -0
- package/src/core/moonListText.js +19 -0
- package/src/core/moonTrajectory.js +1 -1
- package/src/core/pacing.d.ts +38 -3
- package/src/core/pacing.js +55 -4
- package/src/core/planetModels.d.ts +1 -1
- package/src/core/planetModels.js +3 -3
- package/src/core/planetSeries.d.ts +10 -2
- package/src/core/planetSeries.js +17 -3
- package/src/core/pointGroup.js +1 -1
- package/src/core/provenance.d.ts +2 -1
- package/src/core/provenance.js +2 -2
- package/src/core/referenceCenters.js +5 -5
- package/src/core/sampledTrajectory.js +1 -1
- package/src/core/scalePolicy.d.ts +1 -0
- package/src/core/startView.d.ts +19 -0
- package/src/core/startView.js +28 -0
- package/src/core/state.d.ts +6 -2
- package/src/core/state.js +3 -3
- package/src/core/storyPanels.d.ts +63 -0
- package/src/core/storyPanels.js +111 -0
- package/src/core/sunCentredSources.d.ts +4 -0
- package/src/core/sunCentredSources.js +9 -2
- package/src/core/timeInput.d.ts +4 -0
- package/src/core/timeInput.js +4 -0
- package/src/shell/AstraeusShell.d.ts +18 -2
- package/src/shell/AstraeusShell.js +53 -14
- package/src/shell/AstraeusShell.node.js +53 -14
- package/src/shell/Collapsible.d.ts +4 -3
- package/src/shell/Collapsible.js +5 -5
- package/src/shell/ControlsDrawer.d.ts +1 -1
- package/src/shell/ControlsDrawer.js +3 -1
- package/src/shell/DisplaySwitches.js +2 -1
- package/src/shell/InfoPanel.d.ts +3 -1
- package/src/shell/InfoPanel.js +5 -4
- package/src/shell/MoonFamilyPanel.js +1 -1
- package/src/shell/ObjectControls.d.ts +3 -1
- package/src/shell/ObjectControls.js +2 -2
- package/src/shell/Sources.d.ts +5 -3
- package/src/shell/Sources.js +5 -5
- package/src/shell/StoryPanelView.d.ts +4 -3
- package/src/shell/StoryPanelView.js +8 -6
- package/src/shell/SwitchControl.d.ts +5 -11
- package/src/shell/SwitchControl.js +2 -20
- package/src/shell/TimelineBar.css +81 -81
- package/src/shell/TimelineBar.d.ts +5 -2
- package/src/shell/TimelineBar.js +9 -8
- package/src/shell/TimelineBar.node.js +9 -8
- package/src/shell/TopBar.css +22 -22
- package/src/shell/TopBar.d.ts +5 -1
- package/src/shell/TopBar.js +2 -2
- package/src/shell/TopBar.node.js +2 -2
- package/src/shell/bootLoader.d.ts +4 -10
- package/src/shell/bootLoader.js +6 -52
- package/src/shell/embedded.css +18 -18
- package/src/shell/experience.d.ts +1 -1
- package/src/shell/moonFamilies.d.ts +2 -6
- package/src/shell/moonFamilies.js +2 -18
- package/src/shell/phone.css +58 -58
- package/src/shell/storyPanels.d.ts +2 -53
- package/src/shell/storyPanels.js +1 -106
- package/src/shell/style.css +153 -134
- package/src/shell/useDrawers.d.ts +3 -2
- package/src/shell/useDrawers.js +4 -3
- package/src/shell/viewerKeys.d.ts +8 -0
- package/src/shell/viewerKeys.js +16 -0
- package/src/synthetic/syntheticDefinition.js +20 -24
- package/src/synthetic/syntheticJourneyScene.js +3 -3
- package/src/synthetic/syntheticProbeDefinition.js +2 -1
- package/src/synthetic/syntheticViewsDefinition.d.ts +0 -3
- package/src/synthetic/syntheticViewsDefinition.js +10 -16
- package/data/moons/jupiter.json +0 -3333
- package/data/moons/neptune.json +0 -555
- package/data/moons/pluto.json +0 -205
- package/data/moons/saturn.json +0 -8267
- package/data/moons/uranus.json +0 -887
- package/src/app/addressNavigation.d.ts +0 -17
- package/src/app/addressNavigation.js +0 -16
- package/src/assets/bodies/jupiterMoonCatalogue.d.ts +0 -3
- package/src/assets/bodies/jupiterMoonCatalogue.js +0 -4
- package/src/assets/bodies/outerPlanetCatalogues.d.ts +0 -7
- package/src/assets/bodies/outerPlanetCatalogues.js +0 -8
- package/src/assets/bodies/swiftTuttle.d.ts +0 -12
- package/src/assets/bodies/swiftTuttle.js +0 -13
- package/src/assets/moonCatalogue.d.ts +0 -49
- package/src/assets/moonCatalogue.js +0 -80
- package/src/core/bodies/outerPlanetData.d.ts +0 -4
- package/src/core/bodies/outerPlanetData.js +0 -13
- package/src/core/bodies/swiftTuttle.d.ts +0 -46
- package/src/core/bodies/swiftTuttle.js +0 -106
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astraeus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A 3D solar system engine for the browser: place bodies and recorded paths in a scene, mount it, and get time controls, camera, scale choice and body info. Planet positions and the main pictures included.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"@react-three/fiber": ">=9.8.2 <10",
|
|
12
|
-
"react": ">=19 <
|
|
13
|
-
"react-dom": ">=19 <
|
|
12
|
+
"react": ">=19 <20",
|
|
13
|
+
"react-dom": ">=19 <20",
|
|
14
14
|
"three": ">=0.169.0 <1"
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"node": "./src/api/index.node.js",
|
|
20
20
|
"import": "./src/api/index.js"
|
|
21
21
|
},
|
|
22
|
-
"./style.css": "./src/app/style.css"
|
|
22
|
+
"./style.css": "./src/app/style.css",
|
|
23
|
+
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
24
25
|
"sideEffects": [
|
|
25
26
|
"**/*.css"
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { type CSSProperties, type ReactElement } from "react";
|
|
1
|
+
import { type CSSProperties, type ReactElement, type Ref } from "react";
|
|
2
2
|
import "../app/style.css";
|
|
3
3
|
import type { DataSource, Scene } from "./scene.js";
|
|
4
4
|
import { type TimeInput } from "./time.js";
|
|
5
|
-
import { type
|
|
5
|
+
import { type ViewerHandle } from "./viewerHandle.js";
|
|
6
|
+
import type { PickChange } from "./pickerInput.js";
|
|
7
|
+
import { type CameraTarget, type EventZoneChange, type ViewerChange } from "./viewerLink.js";
|
|
6
8
|
/** Props of `AstraeusScene`. */
|
|
7
9
|
export interface AstraeusSceneProps {
|
|
8
10
|
/** The scene to draw. Passing a different `Scene` object rebuilds the viewer; changing the same object in place does not. */
|
|
9
11
|
readonly scene: Scene;
|
|
10
12
|
/** Data packages the scene's bodies need, such as moon pictures or positions. Read when the scene is built, so a new array alone does not rebuild. */
|
|
11
13
|
readonly data?: readonly DataSource[];
|
|
12
|
-
/**
|
|
13
|
-
readonly
|
|
14
|
+
/** The viewer's handle (the same `ViewerHandle` `mount` returns): one object for the component's life, also across a rebuild with a new `scene`. Reads are undefined and calls throw `not-mounted` until the viewer is drawn and after unmount. A React 19 ref prop. */
|
|
15
|
+
readonly ref?: Ref<ViewerHandle>;
|
|
16
|
+
/** Called with the handle once the scene's data has loaded, it is drawn and the viewer's clock is attached, so a host can read and set from here (again, with the same handle, after each rebuild). */
|
|
17
|
+
readonly onReady?: (handle: ViewerHandle) => void;
|
|
14
18
|
/** Called when the scene cannot be built (a `SceneError`) or its data fails to load. */
|
|
15
19
|
readonly onError?: (error: Error) => void;
|
|
16
20
|
/** Moves the viewer to this moment (ISO text, a `Date` or Unix milliseconds) once it is drawn, and again whenever the moment changes. Outside the timeline reports `bad-time` to `onError`. Not a controlled value: the viewer keeps running from there, so the current time arrives through `onChange`. */
|
|
@@ -19,8 +23,20 @@ export interface AstraeusSceneProps {
|
|
|
19
23
|
readonly rate?: number | "auto";
|
|
20
24
|
/** Switches to this view (an id from `setViews`) once drawn, and again whenever it changes. Not a controlled value: a visitor can switch too, and the view showing arrives through `onChange`. An unknown id, or a scene without views, reports `bad-view` to `onError`. */
|
|
21
25
|
readonly view?: string;
|
|
26
|
+
/** Points the camera once drawn, and whenever the target changes by value (a new object with the same target does not re-apply): `{ follow: id }`, `{ focus: id }` or a pose read from a `mount` handle. Not a controlled value: a visitor can move the camera afterwards. A bad one reports `bad-camera` to `onError`. */
|
|
27
|
+
readonly camera?: CameraTarget;
|
|
22
28
|
/** Called whenever the viewer's time, speed, playing state or view changes: playback running, a visitor using the timeline or the view choice, or the `time` / `rate` / `view` props. About ten times a second while playing. */
|
|
23
29
|
readonly onChange?: (change: ViewerChange) => void;
|
|
30
|
+
/** Called when playback enters or leaves the zone of an event the showing view has (its `withinSeconds`, or a pacing rule): `{ event, type?, object?, entered, timeUtcMs, cause }` (see `MountedScene.onEventZone`). A zone already active when the viewer opens reports `entered` once, just after `onReady`. */
|
|
31
|
+
readonly onEventZone?: (change: EventZoneChange) => void;
|
|
32
|
+
/** Called when a visitor presses a picker option other than the pressed one (`Scene.setPicker`; see `ViewerHandle.onPick`). The pressed option does not move until the host calls `handle.setPick`, or passes a new `scene`. */
|
|
33
|
+
readonly onPick?: (change: PickChange) => void;
|
|
34
|
+
/** Called once when the scene's first frame has been drawn (`MountedScene.onFirstDraw`), and again after each rebuild with a new `scene`. */
|
|
35
|
+
readonly onFirstDraw?: () => void;
|
|
36
|
+
/** Whether the viewer reads the page address and offers a copy-link button that writes it (default false: the address stays the host page's own). Read when the viewer is built. See the README's "Page address" section. */
|
|
37
|
+
readonly address?: boolean;
|
|
38
|
+
/** Whether the viewer shows the Developer toggle and drawer (default false: no cog, and the drawer's code is never fetched). Read when the viewer is built. "Copy view link" lives in the drawer, so `address` without this has no copy button; a switch placed `"developer"` shows only when this is on. */
|
|
39
|
+
readonly developerTools?: boolean;
|
|
24
40
|
/** Class for the wrapper element, which fills its parent's width and height unless `style` says otherwise. */
|
|
25
41
|
readonly className?: string;
|
|
26
42
|
/** Style for the wrapper element. */
|
|
@@ -34,4 +50,4 @@ export interface AstraeusSceneProps {
|
|
|
34
50
|
* return <div style={{ height: "100vh" }}><AstraeusScene scene={scene} onError={console.error} /></div>;
|
|
35
51
|
* }
|
|
36
52
|
*/
|
|
37
|
-
export declare function AstraeusScene({ scene, data, onReady, onError, time, rate, view, onChange, className, style }: AstraeusSceneProps): ReactElement;
|
|
53
|
+
export declare function AstraeusScene({ ref, scene, data, onReady, onError, time, rate, view, camera, onChange, onEventZone, onPick, onFirstDraw, address, developerTools, className, style }: AstraeusSceneProps): ReactElement;
|
package/src/api/AstraeusScene.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
3
3
|
import "../app/style.css";
|
|
4
4
|
import { App } from "../app/App.js";
|
|
5
|
+
import { makeContainingBlock } from "./containingBlock.js";
|
|
5
6
|
import { prepareScene } from "./prepared.js";
|
|
7
|
+
import { viewerHandleOf } from "./viewerHandle.js";
|
|
6
8
|
import { ViewerLink } from "./viewerLink.js";
|
|
7
9
|
const FILL = { width: "100%", height: "100%" };
|
|
8
10
|
const asError = (cause) => (cause instanceof Error ? cause : new Error(String(cause)));
|
|
11
|
+
/** A camera target as text by value: keys in sorted order, so the same pose with its keys in another order is the same key. */
|
|
12
|
+
const cameraValueKey = (camera) => JSON.stringify(Object.entries(camera).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
9
13
|
/**
|
|
10
14
|
* The full viewer `mount` draws, as a React component: `<AstraeusScene scene={scene} data={[...]} />`. Waits for the scene's data, then draws; cleans up on unmount.
|
|
11
15
|
* @example
|
|
@@ -14,15 +18,21 @@ const asError = (cause) => (cause instanceof Error ? cause : new Error(String(ca
|
|
|
14
18
|
* return <div style={{ height: "100vh" }}><AstraeusScene scene={scene} onError={console.error} /></div>;
|
|
15
19
|
* }
|
|
16
20
|
*/
|
|
17
|
-
export function AstraeusScene({ scene, data, onReady, onError, time, rate, view, onChange, className, style }) {
|
|
21
|
+
export function AstraeusScene({ ref, scene, data, onReady, onError, time, rate, view, camera, onChange, onEventZone, onPick, onFirstDraw, address, developerTools, className, style }) {
|
|
18
22
|
const [definition, setDefinition] = useState();
|
|
19
23
|
// The latest data and callbacks, read when the scene is built, so a new array or arrow function each render does not rebuild it.
|
|
20
|
-
const latest = useRef({ data, onReady, onError, onChange });
|
|
21
|
-
latest.current = { data, onReady, onError, onChange };
|
|
24
|
+
const latest = useRef({ data, onReady, onError, onChange, onEventZone, onPick, onFirstDraw });
|
|
25
|
+
latest.current = { data, onReady, onError, onChange, onEventZone, onPick, onFirstDraw };
|
|
22
26
|
const [link] = useState(() => new ViewerLink());
|
|
27
|
+
const [handle] = useState(() => viewerHandleOf(link));
|
|
28
|
+
useImperativeHandle(ref, () => handle, [handle]);
|
|
23
29
|
useEffect(() => {
|
|
30
|
+
link.reopen(); // StrictMode replays this effect after its cleanup closed the link: only a real unmount leaves it closed
|
|
24
31
|
const stop = link.onChange((change) => latest.current.onChange?.(change));
|
|
25
|
-
|
|
32
|
+
const stopZones = link.onEventZone((change) => latest.current.onEventZone?.(change));
|
|
33
|
+
const stopPick = link.onPick((change) => latest.current.onPick?.(change));
|
|
34
|
+
const stopFrame = link.onFirstDraw(() => latest.current.onFirstDraw?.());
|
|
35
|
+
return () => { stop(); stopZones(); stopFrame(); stopPick(); link.close(); };
|
|
26
36
|
}, [link]);
|
|
27
37
|
// A Date made fresh each render must not seek again, so the moment is compared by value.
|
|
28
38
|
const timeKey = time instanceof Date ? time.getTime() : time;
|
|
@@ -36,6 +46,9 @@ export function AstraeusScene({ scene, data, onReady, onError, time, rate, view,
|
|
|
36
46
|
latest.current.onError?.(asError(cause));
|
|
37
47
|
}
|
|
38
48
|
};
|
|
49
|
+
const cameraKey = camera === undefined ? undefined : cameraValueKey(camera);
|
|
50
|
+
const cameraRef = useRef(camera);
|
|
51
|
+
cameraRef.current = camera;
|
|
39
52
|
const drawn = definition !== undefined;
|
|
40
53
|
useEffect(() => { if (drawn && timeKey !== undefined)
|
|
41
54
|
apply(() => link.setTime(timeKey)); }, [drawn, link, timeKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -43,21 +56,32 @@ export function AstraeusScene({ scene, data, onReady, onError, time, rate, view,
|
|
|
43
56
|
apply(() => link.setRate(rate)); }, [drawn, link, rate]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
44
57
|
useEffect(() => { if (drawn && view !== undefined)
|
|
45
58
|
apply(() => link.setView(view)); }, [drawn, link, view]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
59
|
+
useEffect(() => { if (drawn && cameraRef.current !== undefined)
|
|
60
|
+
apply(() => link.setCamera(cameraRef.current)); }, [drawn, link, cameraKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
46
61
|
useEffect(() => {
|
|
47
62
|
let open = true;
|
|
48
63
|
setDefinition(undefined);
|
|
64
|
+
link.detach(); // a rebuild: the old viewer is going, so `onReady` below waits for the new one's attach
|
|
49
65
|
try {
|
|
50
66
|
const prepared = prepareScene(scene, latest.current.data);
|
|
51
|
-
prepared.ready.then(() => {
|
|
67
|
+
prepared.ready.then(() => {
|
|
68
|
+
if (!open)
|
|
69
|
+
return;
|
|
52
70
|
setDefinition(prepared.definition);
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
// The viewer attaches its clock in an effect after this render; onReady waits for it, so the handle's reads and sets work inside it.
|
|
72
|
+
void link.whenAttached().then(() => { if (open)
|
|
73
|
+
latest.current.onReady?.(handle); }, () => undefined); // a closed link (unmounted) rejects the wait: onReady does not fire
|
|
74
|
+
}, (cause) => { if (open)
|
|
55
75
|
latest.current.onError?.(asError(cause)); });
|
|
56
76
|
}
|
|
57
77
|
catch (cause) {
|
|
58
78
|
latest.current.onError?.(asError(cause));
|
|
59
79
|
}
|
|
60
80
|
return () => { open = false; };
|
|
61
|
-
}, [scene]);
|
|
62
|
-
|
|
81
|
+
}, [scene, link, handle]);
|
|
82
|
+
// The viewer's root fills this wrapper, so it is the containing block (unless the host's own class or style positions it already).
|
|
83
|
+
const wrapper = useRef(null);
|
|
84
|
+
useEffect(() => { if (wrapper.current !== null)
|
|
85
|
+
makeContainingBlock(wrapper.current); }, []);
|
|
86
|
+
return _jsx("div", { ref: wrapper, className: className, style: { ...FILL, isolation: "isolate", ...style }, children: definition ? _jsx(App, { definition: definition, writeTitle: false, address: address === true, developerTools: developerTools === true, host: link }) : null });
|
|
63
87
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
3
3
|
import { App } from "../app/App.node.js";
|
|
4
|
+
import { makeContainingBlock } from "./containingBlock.js";
|
|
4
5
|
import { prepareScene } from "./prepared.js";
|
|
6
|
+
import { viewerHandleOf } from "./viewerHandle.js";
|
|
5
7
|
import { ViewerLink } from "./viewerLink.js";
|
|
6
8
|
const FILL = { width: "100%", height: "100%" };
|
|
7
9
|
const asError = (cause) => (cause instanceof Error ? cause : new Error(String(cause)));
|
|
10
|
+
/** A camera target as text by value: keys in sorted order, so the same pose with its keys in another order is the same key. */
|
|
11
|
+
const cameraValueKey = (camera) => JSON.stringify(Object.entries(camera).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
8
12
|
/**
|
|
9
13
|
* The full viewer `mount` draws, as a React component: `<AstraeusScene scene={scene} data={[...]} />`. Waits for the scene's data, then draws; cleans up on unmount.
|
|
10
14
|
* @example
|
|
@@ -13,15 +17,21 @@ const asError = (cause) => (cause instanceof Error ? cause : new Error(String(ca
|
|
|
13
17
|
* return <div style={{ height: "100vh" }}><AstraeusScene scene={scene} onError={console.error} /></div>;
|
|
14
18
|
* }
|
|
15
19
|
*/
|
|
16
|
-
export function AstraeusScene({ scene, data, onReady, onError, time, rate, view, onChange, className, style }) {
|
|
20
|
+
export function AstraeusScene({ ref, scene, data, onReady, onError, time, rate, view, camera, onChange, onEventZone, onPick, onFirstDraw, address, developerTools, className, style }) {
|
|
17
21
|
const [definition, setDefinition] = useState();
|
|
18
22
|
// The latest data and callbacks, read when the scene is built, so a new array or arrow function each render does not rebuild it.
|
|
19
|
-
const latest = useRef({ data, onReady, onError, onChange });
|
|
20
|
-
latest.current = { data, onReady, onError, onChange };
|
|
23
|
+
const latest = useRef({ data, onReady, onError, onChange, onEventZone, onPick, onFirstDraw });
|
|
24
|
+
latest.current = { data, onReady, onError, onChange, onEventZone, onPick, onFirstDraw };
|
|
21
25
|
const [link] = useState(() => new ViewerLink());
|
|
26
|
+
const [handle] = useState(() => viewerHandleOf(link));
|
|
27
|
+
useImperativeHandle(ref, () => handle, [handle]);
|
|
22
28
|
useEffect(() => {
|
|
29
|
+
link.reopen(); // StrictMode replays this effect after its cleanup closed the link: only a real unmount leaves it closed
|
|
23
30
|
const stop = link.onChange((change) => latest.current.onChange?.(change));
|
|
24
|
-
|
|
31
|
+
const stopZones = link.onEventZone((change) => latest.current.onEventZone?.(change));
|
|
32
|
+
const stopPick = link.onPick((change) => latest.current.onPick?.(change));
|
|
33
|
+
const stopFrame = link.onFirstDraw(() => latest.current.onFirstDraw?.());
|
|
34
|
+
return () => { stop(); stopZones(); stopFrame(); stopPick(); link.close(); };
|
|
25
35
|
}, [link]);
|
|
26
36
|
// A Date made fresh each render must not seek again, so the moment is compared by value.
|
|
27
37
|
const timeKey = time instanceof Date ? time.getTime() : time;
|
|
@@ -35,6 +45,9 @@ export function AstraeusScene({ scene, data, onReady, onError, time, rate, view,
|
|
|
35
45
|
latest.current.onError?.(asError(cause));
|
|
36
46
|
}
|
|
37
47
|
};
|
|
48
|
+
const cameraKey = camera === undefined ? undefined : cameraValueKey(camera);
|
|
49
|
+
const cameraRef = useRef(camera);
|
|
50
|
+
cameraRef.current = camera;
|
|
38
51
|
const drawn = definition !== undefined;
|
|
39
52
|
useEffect(() => { if (drawn && timeKey !== undefined)
|
|
40
53
|
apply(() => link.setTime(timeKey)); }, [drawn, link, timeKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -42,21 +55,32 @@ export function AstraeusScene({ scene, data, onReady, onError, time, rate, view,
|
|
|
42
55
|
apply(() => link.setRate(rate)); }, [drawn, link, rate]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
43
56
|
useEffect(() => { if (drawn && view !== undefined)
|
|
44
57
|
apply(() => link.setView(view)); }, [drawn, link, view]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
58
|
+
useEffect(() => { if (drawn && cameraRef.current !== undefined)
|
|
59
|
+
apply(() => link.setCamera(cameraRef.current)); }, [drawn, link, cameraKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
45
60
|
useEffect(() => {
|
|
46
61
|
let open = true;
|
|
47
62
|
setDefinition(undefined);
|
|
63
|
+
link.detach(); // a rebuild: the old viewer is going, so `onReady` below waits for the new one's attach
|
|
48
64
|
try {
|
|
49
65
|
const prepared = prepareScene(scene, latest.current.data);
|
|
50
|
-
prepared.ready.then(() => {
|
|
66
|
+
prepared.ready.then(() => {
|
|
67
|
+
if (!open)
|
|
68
|
+
return;
|
|
51
69
|
setDefinition(prepared.definition);
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
// The viewer attaches its clock in an effect after this render; onReady waits for it, so the handle's reads and sets work inside it.
|
|
71
|
+
void link.whenAttached().then(() => { if (open)
|
|
72
|
+
latest.current.onReady?.(handle); }, () => undefined); // a closed link (unmounted) rejects the wait: onReady does not fire
|
|
73
|
+
}, (cause) => { if (open)
|
|
54
74
|
latest.current.onError?.(asError(cause)); });
|
|
55
75
|
}
|
|
56
76
|
catch (cause) {
|
|
57
77
|
latest.current.onError?.(asError(cause));
|
|
58
78
|
}
|
|
59
79
|
return () => { open = false; };
|
|
60
|
-
}, [scene]);
|
|
61
|
-
|
|
80
|
+
}, [scene, link, handle]);
|
|
81
|
+
// The viewer's root fills this wrapper, so it is the containing block (unless the host's own class or style positions it already).
|
|
82
|
+
const wrapper = useRef(null);
|
|
83
|
+
useEffect(() => { if (wrapper.current !== null)
|
|
84
|
+
makeContainingBlock(wrapper.current); }, []);
|
|
85
|
+
return _jsx("div", { ref: wrapper, className: className, style: { ...FILL, isolation: "isolate", ...style }, children: definition ? _jsx(App, { definition: definition, writeTitle: false, address: address === true, developerTools: developerTools === true, host: link }) : null });
|
|
62
86
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ScalePolicy } from "../core/scalePolicy.js";
|
|
2
|
+
import { type BodyMetricKind } from "../app/bodyMetrics.js";
|
|
3
|
+
import type { ExperienceDefinition } from "../app/experienceDefinition.js";
|
|
4
|
+
import type { LookInput } from "./look.js";
|
|
5
|
+
import { type DataSource } from "./data.js";
|
|
6
|
+
import { type SceneCamera } from "./planCamera.js";
|
|
7
|
+
import type { BodyPlan } from "./planBodies.js";
|
|
8
|
+
import type { BodySetPlan } from "./planBodySets.js";
|
|
9
|
+
import type { MoonPanelPlan } from "./planMoonPanel.js";
|
|
10
|
+
import type { PickerPlan } from "./planPicker.js";
|
|
11
|
+
import type { PlacesPlan } from "./planPlaces.js";
|
|
12
|
+
import { type GroupPlan } from "./planGroups.js";
|
|
13
|
+
import { type Tracked } from "./planPaths.js";
|
|
14
|
+
import type { StoryPlan } from "./planStory.js";
|
|
15
|
+
import type { TimelinePlan } from "./planTimeline.js";
|
|
16
|
+
import type { ViewPlan } from "./planViews.js";
|
|
17
|
+
/** What a `Scene` hands the assembler: the planners it has filled, its camera and its scale choice. Internal; never exported from the package. */
|
|
18
|
+
export interface ScenePlanners {
|
|
19
|
+
readonly plan: BodyPlan;
|
|
20
|
+
readonly tracked: ReadonlyMap<string, Tracked>;
|
|
21
|
+
readonly groupPlan: GroupPlan;
|
|
22
|
+
readonly bodySets: BodySetPlan;
|
|
23
|
+
readonly moonPanel: MoonPanelPlan;
|
|
24
|
+
readonly picker: PickerPlan;
|
|
25
|
+
readonly places: PlacesPlan;
|
|
26
|
+
readonly story: StoryPlan;
|
|
27
|
+
readonly timeline: TimelinePlan;
|
|
28
|
+
readonly viewPlan: ViewPlan;
|
|
29
|
+
readonly camera: SceneCamera;
|
|
30
|
+
readonly scale: ScalePolicy;
|
|
31
|
+
readonly scaleOnly: boolean;
|
|
32
|
+
readonly look: LookInput | undefined;
|
|
33
|
+
readonly bodyReadouts: readonly BodyMetricKind[];
|
|
34
|
+
}
|
|
35
|
+
/** The app's plug-in contract for a scene's planners. Throws if the scene is empty or a body needs a data package not passed in `data`. */
|
|
36
|
+
export declare function assembleScene(parts: ScenePlanners, data: readonly DataSource[]): ExperienceDefinition;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isPlanetId, loadPlanetSeries, planetSeriesLoaded, planetSeriesSpan } from "../core/planetSeries.js";
|
|
2
|
+
import { TimeScaleOutOfRangeError } from "../core/timeScale.js";
|
|
3
|
+
import { catalogue as builtInCatalogue } from "../assets/catalogue.js";
|
|
4
|
+
import { createComposition } from "../assets/compositions.js";
|
|
5
|
+
import { mergePictures } from "../assets/pictures.js";
|
|
6
|
+
import { bodyMetrics } from "../app/bodyMetrics.js";
|
|
7
|
+
import { needsPlanetSeries } from "../app/planetNeeds.js";
|
|
8
|
+
import { createReadoutMetrics } from "../app/trackedMetrics.js";
|
|
9
|
+
import { checkDataSources, installData } from "./data.js";
|
|
10
|
+
import { SceneError } from "./errors.js";
|
|
11
|
+
import { cameraPresetsOf, fitFarthestKm, startPresetEntry, startViewEntry, viewEntries } from "./planCamera.js";
|
|
12
|
+
import { groupLayersEntry, lateGroups } from "./planGroups.js";
|
|
13
|
+
import { autoPaths, checkNamedReadouts, checkReadouts, pathCover } from "./planPaths.js";
|
|
14
|
+
/** The `out-of-span` error naming the planets when the scene's window reaches outside the years the planet series cover (the series are loaded); undefined otherwise. */
|
|
15
|
+
function planetSpanError(ids, window) {
|
|
16
|
+
const planets = ids.filter(isPlanetId);
|
|
17
|
+
if (planets.length === 0 || !planetSeriesLoaded())
|
|
18
|
+
return undefined;
|
|
19
|
+
const span = planetSeriesSpan();
|
|
20
|
+
if (window.startUtcMs >= span.startUtcMs && window.endUtcMs <= span.endUtcMs)
|
|
21
|
+
return undefined;
|
|
22
|
+
const iso = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
23
|
+
return new SceneError("out-of-span", `${planets.join(", ")} is outside the years the built-in planet series covers: it covers ${iso(span.startUtcMs)} to ${iso(span.endUtcMs)}, but the scene runs ${iso(window.startUtcMs)} to ${iso(window.endUtcMs)}; set the timeline inside that span`);
|
|
24
|
+
}
|
|
25
|
+
/** Throws `out-of-span` naming the planets when the scene's window reaches outside the years the planet series cover (the series are loaded). */
|
|
26
|
+
function checkPlanetSpan(ids, window) {
|
|
27
|
+
const error = planetSpanError(ids, window);
|
|
28
|
+
if (error !== undefined)
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The one choke point for planet-series reads during setup (orbit lines, the fit distance, clump groups): checks the span first, and turns a
|
|
33
|
+
* `TimeScaleOutOfRangeError` from the read into the named `out-of-span` error when the window is outside the series, so no setup read can leak the raw one.
|
|
34
|
+
*/
|
|
35
|
+
function planetRead(ids, window, read) {
|
|
36
|
+
checkPlanetSpan(ids, window);
|
|
37
|
+
try {
|
|
38
|
+
return read();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof TimeScaleOutOfRangeError)
|
|
42
|
+
throw planetSpanError(ids, window) ?? error;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A setup read in `toDefinition`: an `out-of-span` failure is recorded in `fault` and the read gives `fallback`, so `toDefinition` (and so `mount`) never throws it;
|
|
48
|
+
* `prepare` rejects with the recorded error, which is how it always arrives (once, as `ready` rejecting).
|
|
49
|
+
*/
|
|
50
|
+
function deferredRead(ids, window, fault, fallback, read) {
|
|
51
|
+
try {
|
|
52
|
+
return planetRead(ids, window, read);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof SceneError && error.code === "out-of-span") {
|
|
56
|
+
fault.error ??= error;
|
|
57
|
+
return fallback;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** The app's plug-in contract for a scene's planners. Throws if the scene is empty or a body needs a data package not passed in `data`. */
|
|
63
|
+
export function assembleScene(parts, data) {
|
|
64
|
+
const { plan, groupPlan, bodySets, moonPanel, places, story, timeline: timelinePlan, viewPlan, camera, tracked: trackedMap } = parts;
|
|
65
|
+
if (plan.bodies.size === 0)
|
|
66
|
+
throw new SceneError("empty-scene", "the scene has no bodies; call addBody before mount");
|
|
67
|
+
checkDataSources(data);
|
|
68
|
+
plan.checkData(data);
|
|
69
|
+
bodySets.checkData(data);
|
|
70
|
+
groupPlan.checkReadouts();
|
|
71
|
+
const ids = [...plan.bodies.keys()];
|
|
72
|
+
const paths = plan.moonPaths();
|
|
73
|
+
const sunCentred = plan.checkSunCentred(ids);
|
|
74
|
+
plan.checkSolarSystemScale(parts.scale, sunCentred);
|
|
75
|
+
for (const entry of trackedMap.values())
|
|
76
|
+
checkReadouts(entry, ids);
|
|
77
|
+
for (const [id, readouts] of plan.readouts)
|
|
78
|
+
checkNamedReadouts(id, readouts, ids, "addBody");
|
|
79
|
+
const entries = [...trackedMap.values()];
|
|
80
|
+
const tracked = entries.map((entry) => entry.body);
|
|
81
|
+
const timeline = timelinePlan.setting;
|
|
82
|
+
const { window, startUtcMs } = timelinePlan.span([...tracked.map((body) => body.trajectory.bounds), ...[...groupPlan.activities.values()].map((activity) => activity.window)]);
|
|
83
|
+
const sunOrbitIds = plan.sunOrbitIds(ids);
|
|
84
|
+
// The farthest distance is worked out in setup, once: now when the planet series are in, else in `prepare` once they are; never in the frame loop.
|
|
85
|
+
const fault = {};
|
|
86
|
+
// `lineFixedTo: "auto"` paths read body states: now when the planet series are in, else in `prepare` once they are (the viewer draws only after it resolves); never per frame.
|
|
87
|
+
const auto = autoPaths(plan.catalogue, entries, tracked, ids);
|
|
88
|
+
auto.now((read) => deferredRead(ids, window, fault, undefined, read));
|
|
89
|
+
const fit = deferredRead(ids, window, fault, undefined, () => fitFarthestKm(camera, plan.catalogue, plan.own, startUtcMs));
|
|
90
|
+
// The lines read planet positions; when the planet series are not loaded yet (a consumer's mount), they are drawn in `prepare`, once the series are in. The viewer draws only after `prepare` resolves.
|
|
91
|
+
const sunPaths = deferredRead(ids, window, fault, [], () => plan.earlySunPaths(sunOrbitIds, startUtcMs, planetSeriesLoaded()));
|
|
92
|
+
const storyPanels = story.panels(window, trackedMap.values(), [...plan.bodies.keys(), ...trackedMap.keys(), ...groupPlan.groups.keys(), ...bodySets.memberIds()]);
|
|
93
|
+
groupPlan.check(ids);
|
|
94
|
+
bodySets.check({ ids, catalogue: plan.catalogue, orbits: plan.orbits });
|
|
95
|
+
// A clump near a body reads its position; with the planet series not loaded yet, those groups are built in `prepare` (the viewer draws only after it resolves).
|
|
96
|
+
const seriesIn = planetSeriesLoaded();
|
|
97
|
+
const late = lateGroups(seriesIn);
|
|
98
|
+
const layers = deferredRead(ids, window, fault, [], () => [...groupPlan.layers(ids, window, startUtcMs, (plan) => !late(plan))]);
|
|
99
|
+
const setLayers = bodySets.layers({ ids, catalogue: plan.catalogue, orbits: plan.orbits, window, startUtcMs });
|
|
100
|
+
const labelled = [...plan.bodies.values(), ...tracked, ...[...groupPlan.groups.values()]].map(({ id, label }) => ({ id, label }));
|
|
101
|
+
const catalogue = plan.catalogue;
|
|
102
|
+
if (camera.following && camera.target !== undefined && camera.followChoices !== undefined && !camera.followChoices.includes(camera.target))
|
|
103
|
+
throw new SceneError("bad-camera", `camera.follow("${camera.target}"): the opening view follows "${camera.target}", which camera.setFollowChoices does not list`);
|
|
104
|
+
story.checkObjects(new Set(labelled.map(({ id }) => id)));
|
|
105
|
+
const objects = [
|
|
106
|
+
...[...plan.bodies.values()].map((body) => plan.bodyObject(body, ids, sunCentred, camera)),
|
|
107
|
+
...[...trackedMap.values()].map(({ body, description, knownLimitations, provenanceSpans }) => ({ id: body.id, label: body.label, color: body.color, availability: body.trajectory.bounds, labelPriority: 80, ...plan.labelReach(body.id, sunCentred, camera), provenance: body.provenance, ...(provenanceSpans === undefined ? {} : { provenanceSpans }), ...(description === undefined ? {} : { description }), ...(knownLimitations === undefined ? {} : { knownLimitations }) })),
|
|
108
|
+
...bodySets.objects({ ids, catalogue: plan.catalogue }),
|
|
109
|
+
];
|
|
110
|
+
const pictures = mergePictures(data.map((source) => source.pictures));
|
|
111
|
+
const members = new Set(bodySets.memberIds());
|
|
112
|
+
const moonFamilies = moonPanel.list(new Map(objects.filter(({ id }) => plan.bodies.has(id) || members.has(id)).map(({ id, label }) => [id, label])), new Set(ids), plan.catalogue, (picture) => pictures[picture]?.url);
|
|
113
|
+
const bodyFeatures = places.featureSets(new Map(objects.map(({ id, label }) => [id, label])));
|
|
114
|
+
const definition = {
|
|
115
|
+
experience: {
|
|
116
|
+
objects,
|
|
117
|
+
cameraPresets: cameraPresetsOf(labelled, camera.followChoices),
|
|
118
|
+
...startPresetEntry(camera),
|
|
119
|
+
...(moonFamilies === undefined ? {} : { moonFamilies }),
|
|
120
|
+
...(bodyFeatures.length === 0 ? {} : { bodyFeatures }),
|
|
121
|
+
events: story.events,
|
|
122
|
+
...story.provenanceEntries(),
|
|
123
|
+
...(storyPanels === undefined ? {} : { storyPanels }),
|
|
124
|
+
...(timeline?.none === true ? { hideTimeline: true } : {}),
|
|
125
|
+
window,
|
|
126
|
+
...groupPlan.windowsEntry(),
|
|
127
|
+
rates: timelinePlan.rates(),
|
|
128
|
+
},
|
|
129
|
+
clock: timelinePlan.clock(startUtcMs),
|
|
130
|
+
...timelinePlan.pacing(story.events),
|
|
131
|
+
...groupLayersEntry(layers, groupPlan.groups.size > 0, sunOrbitIds.length > 0),
|
|
132
|
+
...(sunOrbitIds.length === 0 ? {} : { paths: sunPaths }),
|
|
133
|
+
...(setLayers.length === 0 ? {} : { bodySets: setLayers }),
|
|
134
|
+
...(plan.catalogue === builtInCatalogue ? {} : { catalogue: plan.catalogue }),
|
|
135
|
+
...plan.visualOverrides(),
|
|
136
|
+
// The viewer draws only the pictures of the packages passed to it (T-252); nothing is shared between viewers.
|
|
137
|
+
...picturesEntry(data),
|
|
138
|
+
composition: createComposition(plan.catalogue, { id: "scene", bodies: ids, defaultCenter: ids[0], ...(paths.length === 0 ? {} : { paths }) }),
|
|
139
|
+
scaleChoices: plan.scaleChoices(parts.scale, parts.scaleOnly),
|
|
140
|
+
...viewPlan.switchesEntry(),
|
|
141
|
+
...parts.picker.entry(),
|
|
142
|
+
...(parts.look === undefined ? {} : { look: parts.look }),
|
|
143
|
+
...viewPlan.viewsEntry({ objects: [...trackedMap.keys(), ...ids, ...groupPlan.groups.keys()], events: story.events.map(({ id }) => id) }, storyPanels),
|
|
144
|
+
...viewEntries(timeline, camera, fit?.read, pathCover(trackedMap.values(), sunCentred, ids[0])),
|
|
145
|
+
...startViewEntry(camera),
|
|
146
|
+
trackedBodies: tracked,
|
|
147
|
+
createMetrics: ({ resolver }) => {
|
|
148
|
+
const catalogued = bodyMetrics(resolver, ids, parts.bodyReadouts, catalogue);
|
|
149
|
+
const bodyReadouts = [...plan.readouts].map(([id, specs]) => ({ id, label: plan.bodies.get(id).label, center: ids[0], readouts: specs }));
|
|
150
|
+
const readouts = createReadoutMetrics([...trackedMap.values()].map(({ body, readouts: specs }) => ({ body, readouts: specs })), resolver, undefined, bodyReadouts);
|
|
151
|
+
return (objectId, timeUtcMs) => (groupPlan.groups.has(objectId) ? groupPlan.metrics(objectId, timeUtcMs) : trackedMap.has(objectId) || plan.readouts.has(objectId) ? readouts(objectId, timeUtcMs) : catalogued(objectId, timeUtcMs));
|
|
152
|
+
},
|
|
153
|
+
prepare: async () => {
|
|
154
|
+
if (fault.error !== undefined)
|
|
155
|
+
throw fault.error;
|
|
156
|
+
if (needsPlanetSeries(definition) || auto.later || sunPaths.length < sunOrbitIds.length || groupPlan.groups.size > layers.length)
|
|
157
|
+
await loadPlanetSeries();
|
|
158
|
+
checkPlanetSpan(ids, window);
|
|
159
|
+
auto.settle((read) => planetRead(ids, window, read));
|
|
160
|
+
if (groupPlan.groups.size > layers.length)
|
|
161
|
+
layers.push(...planetRead(ids, window, () => groupPlan.layers(ids, window, startUtcMs, late)));
|
|
162
|
+
if (sunPaths.length < sunOrbitIds.length)
|
|
163
|
+
sunPaths.push(...planetRead(ids, window, () => sunOrbitIds.map((id) => plan.sunPath(id, startUtcMs))));
|
|
164
|
+
if (fit !== undefined)
|
|
165
|
+
planetRead(ids, window, () => fit.settle());
|
|
166
|
+
await installData(data, ids, window, catalogue, bodySets.load());
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
return definition;
|
|
170
|
+
}
|
|
171
|
+
/** The viewer's own pictures (those of the packages passed to it); absent when no package brings any. */
|
|
172
|
+
function picturesEntry(data) {
|
|
173
|
+
const pictures = mergePictures(data.map((source) => source.pictures));
|
|
174
|
+
return Object.keys(pictures).length === 0 ? {} : { pictures };
|
|
175
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BodySetInput } from "./bodySetInput.js";
|
|
2
|
+
import { SceneError } from "./errors.js";
|
|
3
|
+
/** The `bad-body-set` error for a set, naming the call and the set. */
|
|
4
|
+
export declare const bad: (id: unknown, message: string) => SceneError;
|
|
5
|
+
/** The id of a body given as a reference or an id. */
|
|
6
|
+
export declare const idOf: (ref: string | {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
}) => string;
|
|
9
|
+
/** Checks what can be checked before the scene is complete, and says whether the members are listed moons or made-up ones. */
|
|
10
|
+
export declare function checkInput(input: BodySetInput): "listed" | "elements";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { MAX_BODY_SET_FAMILIES } from "../core/bodySetFamilies.js";
|
|
2
|
+
import { listedMoon } from "../core/bodies/listedMoons.js";
|
|
3
|
+
import { SceneError } from "./errors.js";
|
|
4
|
+
import { toUtcMs } from "./time.js";
|
|
5
|
+
const HEX = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
|
|
6
|
+
const ELEMENT_KEYS = ["semiMajorAxisKm", "eccentricity", "inclinationDeg", "raanDeg", "argumentOfPeriapsisDeg", "trueAnomalyDeg"];
|
|
7
|
+
/** The `bad-body-set` error for a set, naming the call and the set. */
|
|
8
|
+
export const bad = (id, message) => new SceneError("bad-body-set", `addBodySet("${String(id)}"): ${message}`);
|
|
9
|
+
/** The id of a body given as a reference or an id. */
|
|
10
|
+
export const idOf = (ref) => (typeof ref === "string" ? ref : ref?.id);
|
|
11
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
12
|
+
const isPositive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
13
|
+
const isTexts = (value) => Array.isArray(value) && value.every(isText);
|
|
14
|
+
/** Checks one family's id, label, colour and brightness. */
|
|
15
|
+
function checkFamily(id, family, seen) {
|
|
16
|
+
if (!isText(family?.id))
|
|
17
|
+
throw bad(id, "every family needs a non-empty id");
|
|
18
|
+
if (seen.has(family.id))
|
|
19
|
+
throw bad(id, `family "${family.id}" appears twice`);
|
|
20
|
+
seen.add(family.id);
|
|
21
|
+
if (!isText(family.label))
|
|
22
|
+
throw bad(id, `family "${family.id}" needs a label`);
|
|
23
|
+
if (family.color !== undefined && !(typeof family.color === "string" && HEX.test(family.color)))
|
|
24
|
+
throw bad(id, `family "${family.id}": color "${String(family.color)}" is not a hex colour such as "#9de3a8"`);
|
|
25
|
+
if (family.brightness !== undefined && !isPositive(family.brightness))
|
|
26
|
+
throw bad(id, `family "${family.id}": brightness must be above 0`);
|
|
27
|
+
}
|
|
28
|
+
/** Checks a member's card words: listed flag, facts, known limits, label and radius. */
|
|
29
|
+
function checkMemberCard(id, member) {
|
|
30
|
+
const at = `member "${member.id}"`;
|
|
31
|
+
if (member.listed !== undefined && typeof member.listed !== "boolean")
|
|
32
|
+
throw bad(id, `${at}: listed must be true or false`);
|
|
33
|
+
const facts = member.facts;
|
|
34
|
+
if (facts !== undefined && !(Array.isArray(facts) && facts.every((fact) => isText(fact?.label) && isText(fact.value))))
|
|
35
|
+
throw bad(id, `${at}: facts must be a list of { label, value } with both texts non-empty`);
|
|
36
|
+
if (member.knownLimitations !== undefined && !isTexts(member.knownLimitations))
|
|
37
|
+
throw bad(id, `${at}: knownLimitations must be a list of non-empty texts`);
|
|
38
|
+
if (member.label !== undefined && !isText(member.label))
|
|
39
|
+
throw bad(id, `${at}: label must be a non-empty text`);
|
|
40
|
+
if (member.radiusKm !== undefined && !isPositive(member.radiusKm))
|
|
41
|
+
throw bad(id, `${at}: radiusKm must be above 0`);
|
|
42
|
+
}
|
|
43
|
+
/** Checks the elements of a made-up member: finite numbers, a bound orbit, a known plane and a valid moment. */
|
|
44
|
+
function checkElements(id, member) {
|
|
45
|
+
const at = `member "${member.id}"`;
|
|
46
|
+
const elements = member.elements;
|
|
47
|
+
if (member.label === undefined || member.radiusKm === undefined)
|
|
48
|
+
throw bad(id, `${at} has elements, so it needs a label and a radiusKm`);
|
|
49
|
+
for (const key of ELEMENT_KEYS)
|
|
50
|
+
if (!(typeof elements[key] === "number" && Number.isFinite(elements[key])))
|
|
51
|
+
throw bad(id, `${at}: elements.${key} must be a finite number`);
|
|
52
|
+
if (!(elements.semiMajorAxisKm > 0))
|
|
53
|
+
throw bad(id, `${at}: elements.semiMajorAxisKm must be above 0`);
|
|
54
|
+
if (!(elements.eccentricity >= 0 && elements.eccentricity < 1))
|
|
55
|
+
throw bad(id, `${at}: elements.eccentricity must be at least 0 and below 1`);
|
|
56
|
+
if (!(elements.inclinationDeg >= 0 && elements.inclinationDeg <= 180))
|
|
57
|
+
throw bad(id, `${at}: elements.inclinationDeg must be from 0 to 180`);
|
|
58
|
+
if (elements.plane !== undefined && elements.plane !== "ecliptic-j2000" && elements.plane !== "EQJ")
|
|
59
|
+
throw bad(id, `${at}: elements.plane "${String(elements.plane)}" is not "ecliptic-j2000" or "EQJ"`);
|
|
60
|
+
if (elements.time !== undefined)
|
|
61
|
+
toUtcMs(elements.time, `addBodySet("${id}") member "${member.id}" elements.time`);
|
|
62
|
+
}
|
|
63
|
+
/** Checks one member and says which kind it is: a listed moon (no elements) or a made-up one. */
|
|
64
|
+
function checkMember(id, member, families) {
|
|
65
|
+
if (!isText(member?.id))
|
|
66
|
+
throw bad(id, "every member needs a non-empty id");
|
|
67
|
+
if (!families.has(member.family))
|
|
68
|
+
throw bad(id, `member "${member.id}" is in family "${String(member.family)}", which the set does not list`);
|
|
69
|
+
checkMemberCard(id, member);
|
|
70
|
+
if (member.elements === undefined) {
|
|
71
|
+
if (listedMoon(member.id) === undefined)
|
|
72
|
+
throw bad(id, `member "${member.id}" has no elements and is not a listed moon (listedMoons(planet) names them); give it \`elements\``);
|
|
73
|
+
return "listed";
|
|
74
|
+
}
|
|
75
|
+
checkElements(id, member);
|
|
76
|
+
return "elements";
|
|
77
|
+
}
|
|
78
|
+
/** Checks the bodies, centre gravity, history and balance point a set was given. */
|
|
79
|
+
function checkExtras(id, input, families) {
|
|
80
|
+
const bodies = input.bodies ?? [];
|
|
81
|
+
if (!Array.isArray(bodies) || bodies.some((body) => !isText(idOf(body?.id)) || !families.has(body.family)))
|
|
82
|
+
throw bad(id, "bodies must be a list of { id, family } with a family the set lists");
|
|
83
|
+
if (new Set(bodies.map((body) => idOf(body.id))).size !== bodies.length)
|
|
84
|
+
throw bad(id, "a body appears twice in bodies");
|
|
85
|
+
if (input.centerGmKm3S2 !== undefined && !isPositive(input.centerGmKm3S2))
|
|
86
|
+
throw bad(id, "centerGmKm3S2 must be above 0");
|
|
87
|
+
if (input.orbitHistoryMs !== undefined && !(Number.isFinite(input.orbitHistoryMs) && input.orbitHistoryMs >= 0))
|
|
88
|
+
throw bad(id, "orbitHistoryMs must be 0 or above");
|
|
89
|
+
const balance = input.balancePoint;
|
|
90
|
+
if (balance !== undefined && !(isText(idOf(balance?.body)) && isPositive(balance.gmKm3S2)))
|
|
91
|
+
throw bad(id, "balancePoint needs a body and a gmKm3S2 above 0");
|
|
92
|
+
}
|
|
93
|
+
/** Checks what can be checked before the scene is complete, and says whether the members are listed moons or made-up ones. */
|
|
94
|
+
export function checkInput(input) {
|
|
95
|
+
const id = input?.id;
|
|
96
|
+
if (!isText(id))
|
|
97
|
+
throw bad(id, "the set needs a non-empty id");
|
|
98
|
+
const { families, members } = input;
|
|
99
|
+
if (!Array.isArray(families) || families.length === 0 || families.length > MAX_BODY_SET_FAMILIES)
|
|
100
|
+
throw bad(id, `the set needs 1 to ${MAX_BODY_SET_FAMILIES} families`);
|
|
101
|
+
const familyIds = new Set();
|
|
102
|
+
for (const family of families)
|
|
103
|
+
checkFamily(id, family, familyIds);
|
|
104
|
+
if (!Array.isArray(members) || members.length === 0)
|
|
105
|
+
throw bad(id, "the set needs at least one member; the list is empty");
|
|
106
|
+
const kinds = new Set(members.map((member) => checkMember(id, member, familyIds)));
|
|
107
|
+
if (kinds.size > 1)
|
|
108
|
+
throw bad(id, "its members are a mix of listed moons and made-up ones with elements; a set is one kind or the other");
|
|
109
|
+
if (new Set(members.map((member) => member.id)).size !== members.length)
|
|
110
|
+
throw bad(id, "a member id appears twice");
|
|
111
|
+
if (members.some((member) => member.id === id))
|
|
112
|
+
throw bad(id, "a member cannot have the set's own id");
|
|
113
|
+
if (typeof input.provenance !== "object" || input.provenance === null)
|
|
114
|
+
throw bad(id, "the set needs a provenance");
|
|
115
|
+
checkExtras(id, input, familyIds);
|
|
116
|
+
return [...kinds][0];
|
|
117
|
+
}
|