astraeus 0.5.1 → 0.6.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/src/api/scene.js CHANGED
@@ -7,7 +7,7 @@ import { createOrbTwoBodyAdapter } from "../core/twoBodyAdapter.js";
7
7
  import { createStateResolver } from "../core/stateResolver.js";
8
8
  import { createOrbAstronomyAdapter } from "../core/astronomyAdapter.js";
9
9
  import { isPlanetId, loadPlanetSeries, planetSeriesLoaded, planetSeriesSpan } from "../core/planetSeries.js";
10
- import { catalogue as builtInCatalogue, extendCatalogue, rootBodyId } from "../assets/catalogue.js";
10
+ import { catalogue as builtInCatalogue, extendCatalogue, extendCatalogueWithMoons, rootBodyId } from "../assets/catalogue.js";
11
11
  import { buildElementsBody, ElementsBodyError, parseElementsBodyRecord } from "../core/elementsBody.js";
12
12
  import { createComposition } from "../assets/compositions.js";
13
13
  import { bodyMetrics } from "../app/bodyMetrics.js";
@@ -15,6 +15,7 @@ import { needsPlanetSeries } from "../app/planetNeeds.js";
15
15
  import { catalogueItem } from "../app/catalogueItem.js";
16
16
  import { createReadoutMetrics } from "../app/trackedMetrics.js";
17
17
  import { circlesTheSun, farthestSunDistanceKm, sunOrbitIdOf, sunOrbitLayer } from "./sunOrbit.js";
18
+ import { listedMoonBodyOf } from "../core/bodies/listedMoonBodies.js";
18
19
  import { FALLBACK_SCENE_CENTRE, readyMade } from "./bodies.js";
19
20
  import { installData } from "./data.js";
20
21
  import { planActivity, rateMetricOf } from "./activity.js";
@@ -156,9 +157,25 @@ export class Scene {
156
157
  /** Adds a catalogued body: a ready-made one (`earth`, `moon`, ...) or its id. The first body added is the scene's centre. `{ orbit: true }` also draws its orbit line. */
157
158
  addBody(body, options = {}) {
158
159
  const id = typeof body === "string" ? body : body.id;
159
- this.#register("addBody", id, typeof body === "string" ? readyMade(id) ?? { id, label: this.#catalogue.has(id) ? this.#catalogue.get(id).definition.label : id } : body, options);
160
+ const before = this.#catalogue;
161
+ this.#addListedMoon(id);
162
+ try {
163
+ this.#register("addBody", id, typeof body === "string" ? readyMade(id) ?? { id, label: this.#catalogue.has(id) ? this.#catalogue.get(id).definition.label : id } : body, options);
164
+ }
165
+ catch (error) {
166
+ this.#catalogue = before;
167
+ throw error;
168
+ }
160
169
  return this;
161
170
  }
171
+ /** A moon in the listed-moon table that the built-in catalogue does not define by hand is defined now, by the one rule, and joins this scene's catalogue only (an unused moon costs nothing). */
172
+ #addListedMoon(id) {
173
+ if (this.#catalogue.has(id))
174
+ return;
175
+ const moon = listedMoonBodyOf(id);
176
+ if (moon !== undefined && this.#catalogue.has(moon.definition.parentId))
177
+ this.#catalogue = extendCatalogueWithMoons(this.#catalogue, [moon]);
178
+ }
162
179
  /**
163
180
  * Adds your own body that circles the Sun, from its published orbit elements and where they came from: a record with the id, label, elements at an epoch, the source
164
181
  * (name, URL, solution, access date), a stated accuracy and optionally a radius and marker. Drawn as a marker on unperturbed two-body motion about the Sun; the provenance
@@ -188,7 +205,7 @@ export class Scene {
188
205
  if (options.orbit === true && moonOrbitPath(this.#catalogue, id) === undefined && !(circlesTheSun(this.#catalogue, id)))
189
206
  throw new SceneError("no-orbit", `${call}("${id}", { orbit: true }): the engine draws the orbit line of any catalogued moon whose data give a period about its planet and of any body that circles the Sun (every planet: its own source over a full turn where the source covers one, else the two-body ellipse osculating at the opening time)`);
190
207
  if (!this.#catalogue.has(id))
191
- throw new SceneError("unknown-body", `${call}("${id}"): not a catalogued body (known: ${this.#catalogue.ids().join(", ")})`);
208
+ throw new SceneError("unknown-body", `${call}("${id}"): not a catalogued body (known: ${builtInCatalogue.ids().join(", ")}; any moon in the moon lists is added by its id, and \`listedMoons(planet)\` names them with the data package each needs)`);
192
209
  if (this.#taken(id))
193
210
  throw new SceneError("duplicate-id", `${call}("${id}"): already in the scene`);
194
211
  checkBodyLook(id, options);
@@ -637,7 +654,7 @@ export class Scene {
637
654
  ...pacingEntry(timeline, this.#events),
638
655
  ...groupLayersEntry(layers, this.#groups.size > 0, sunOrbitIds.length > 0),
639
656
  ...(sunOrbitIds.length === 0 ? {} : { paths: sunPaths }),
640
- ...(this.#own.size === 0 ? {} : { catalogue: this.#catalogue }),
657
+ ...(this.#catalogue === builtInCatalogue ? {} : { catalogue: this.#catalogue }),
641
658
  ...visualOverridesEntry(this.#shape),
642
659
  composition: createComposition(this.#catalogue, { id: "scene", bodies: ids, defaultCenter: ids[0], ...(paths.length === 0 ? {} : { paths }) }),
643
660
  scaleChoices: scaleChoicesOf(this.#scale, this.#scaleOnly, this.#enlargedInSun(sunCentred)),
@@ -662,7 +679,7 @@ export class Scene {
662
679
  sunPaths.push(...this.#planetRead(ids, window, () => sunOrbitIds.map((id) => this.#sunPath(id, startUtcMs))));
663
680
  if (fit !== undefined)
664
681
  this.#planetRead(ids, window, () => fit.settle());
665
- await installData(data, ids, window);
682
+ await installData(data, ids, window, catalogue);
666
683
  },
667
684
  };
668
685
  return definition;
@@ -2,6 +2,7 @@ import { Group, type Camera } from "three";
2
2
  import type { CenterId } from "../core/body.js";
3
3
  import type { ScalePolicy } from "../core/scalePolicy.js";
4
4
  import type { StateResolver } from "../core/stateResolver.js";
5
+ import { type BodyCatalogue } from "../assets/catalogue.js";
5
6
  import { type OrbitLook } from "../assets/orbitLook.js";
6
7
  import type { CompositionPath } from "../assets/compositions.js";
7
8
  import { type PathLayer } from "./experienceDefinition.js";
@@ -130,6 +131,6 @@ export declare const COMPOSITION_PATH_STYLE: PathStyle;
130
131
  * A composition's declared path as an orbit layer: the body's positions about its parent from the resolver, over a window about the
131
132
  * clock, carried with the parent.
132
133
  */
133
- export declare function compositionPathLayer(path: CompositionPath, resolver: StateResolver): PathLayer;
134
+ export declare function compositionPathLayer(path: CompositionPath, resolver: StateResolver, bodies?: BodyCatalogue): PathLayer;
134
135
  /** A composition path drawn with its orbit look (the path's own settings over the defaults), on the scene's own layer. */
135
- export declare function compositionPathView(path: CompositionPath, resolver: StateResolver): PathView;
136
+ export declare function compositionPathView(path: CompositionPath, resolver: StateResolver, bodies?: BodyCatalogue): PathView;
@@ -1,6 +1,6 @@
1
1
  import { BufferAttribute, BufferGeometry, DoubleSide, Group, Line, LineBasicMaterial, Mesh, MeshBasicMaterial, Vector3 } from "three";
2
2
  import { eccentricPathTimesUtcMs, pathTimesUtcMs, samplePositionsKm, windowTimesUtcMs } from "../core/sunCentredSources.js";
3
- import { catalogue } from "../assets/catalogue.js";
3
+ import { catalogue as builtInCatalogue } from "../assets/catalogue.js";
4
4
  import { ORBIT_LOOK_LIMITS, resolveOrbitLook } from "../assets/orbitLook.js";
5
5
  import { DEFAULT_ECCENTRIC_SAMPLE_COUNT, DEFAULT_PATH_SAMPLE_COUNT, DEFAULT_WINDOW_SAMPLE_COUNT, isRollingSpan, validatePathSpec, } from "./experienceDefinition.js";
6
6
  import { arcSegmentAlpha, inertialTrailKm, mapPathKm, ringAlpha, windowEdgeAlpha, orbitKm, pathNeedsRefresh, relativeTrailKm, rootFrameKm, DEFAULT_PATH_REFRESH } from "./pathRules.js";
@@ -552,8 +552,8 @@ export const COMPOSITION_PATH_STYLE = Object.freeze({ opacity: 0.45, depthTest:
552
552
  * A composition's declared path as an orbit layer: the body's positions about its parent from the resolver, over a window about the
553
553
  * clock, carried with the parent.
554
554
  */
555
- export function compositionPathLayer(path, resolver) {
556
- const parent = catalogue.get(path.body).definition.parentId;
555
+ export function compositionPathLayer(path, resolver, bodies = builtInCatalogue) {
556
+ const parent = bodies.get(path.body).definition.parentId;
557
557
  if (parent === undefined)
558
558
  throw new RangeError(`path body "${path.body}" has no parent to orbit`);
559
559
  const source = { body: path.body, stateAt: (timeUtcMs, center = parent) => resolver.stateOf(path.body, timeUtcMs, center) };
@@ -569,6 +569,6 @@ export function compositionPathLayer(path, resolver) {
569
569
  };
570
570
  }
571
571
  /** A composition path drawn with its orbit look (the path's own settings over the defaults), on the scene's own layer. */
572
- export function compositionPathView(path, resolver) {
573
- return new PathView(compositionPathLayer(path, resolver), { ...COMPOSITION_PATH_STYLE, orbitLook: resolveOrbitLook(path.look, `path for "${path.body}"`) });
572
+ export function compositionPathView(path, resolver, bodies = builtInCatalogue) {
573
+ return new PathView(compositionPathLayer(path, resolver, bodies), { ...COMPOSITION_PATH_STYLE, orbitLook: resolveOrbitLook(path.look, `path for "${path.body}"`) });
574
574
  }
@@ -56,7 +56,7 @@ export function useSceneViews(runtime, gl) {
56
56
  const trackedViews = useMemo(() => runtime.trackedBodies.map((body) => new TrackedBodyView(body)), [runtime.trackedBodies]);
57
57
  const groupViews = useMemo(() => runtime.groups.map((layer) => new PointsView(layer)), [runtime.groups]);
58
58
  const sunCentredViews = useMemo(() => createPathViews(runtime.paths ?? []), [runtime.paths]);
59
- const compositionPaths = useMemo(() => (runtime.composition?.paths ?? []).map((path) => compositionPathView(path, runtime.resolver)), [runtime.composition, runtime.resolver]);
59
+ const compositionPaths = useMemo(() => (runtime.composition?.paths ?? []).map((path) => compositionPathView(path, runtime.resolver, runtime.catalogue)), [runtime.composition, runtime.resolver, runtime.catalogue]);
60
60
  const skyView = useMemo(() => (runtime.sky?.visible ? new SkyView({ starBrightness: runtime.sky.starBrightness, milkyWayBrightness: runtime.sky.milkyWayBrightness, pixelRatio: gl.getPixelRatio(), maxAnisotropy: gl.capabilities.getMaxAnisotropy(), milkyWay: runtime.sky.milkyWay, picture: null }) : null), [runtime.sky, gl]);
61
61
  const bodySetViews = useMemo(() => (runtime.bodySets ?? []).map((layer) => new BodySetView(layer)), [runtime.bodySets]);
62
62
  const orbitSetViews = useMemo(() => (runtime.bodySets ?? []).map((layer) => new OrbitSetView(layer)), [runtime.bodySets]);
@@ -0,0 +1,4 @@
1
+ import type { ListedMoonBody } from "../../core/bodies/listedMoonBodies.js";
2
+ import type { VisualEntry } from "../catalogue.js";
3
+ /** A listed moon's look (O-049 T-211): a grey sphere, or its picture when the picture pack holds one under the moon's id (read when asked for, so a pack registered later still shows). */
4
+ export declare const listedMoonEntry: ({ definition }: ListedMoonBody) => VisualEntry;
@@ -0,0 +1,7 @@
1
+ import { withPicture } from "../pictures.js";
2
+ const LIGHT = Object.freeze({ ambient: 0.08, directional: 1.4 });
3
+ /** A listed moon's look (O-049 T-211): a grey sphere, or its picture when the picture pack holds one under the moon's id (read when asked for, so a pack registered later still shows). */
4
+ export const listedMoonEntry = ({ definition }) => ({
5
+ body: definition.id,
6
+ visual: withPicture(definition.id, { kind: "sphere", material: Object.freeze({ color: "#a8a8a8", roughness: 0.95, metalness: 0 }), light: LIGHT }),
7
+ });
@@ -1,4 +1,5 @@
1
1
  import type { BodyId, CelestialBodyDefinition, StateSourceBinding } from "../core/body.js";
2
+ import type { ListedMoonBody } from "../core/bodies/listedMoonBodies.js";
2
3
  import { type ElementsBodyRecord } from "../core/elementsBody.js";
3
4
  import type { BodyVisual } from "./visual.js";
4
5
  /** Definition, optional state source, and appearance of one body, joined by id. */
@@ -31,6 +32,8 @@ export declare function createCatalogue(definitions: readonly CelestialBodyDefin
31
32
  * already holds, like any other duplicate.
32
33
  */
33
34
  export declare function extendCatalogue(base: BodyCatalogue, records: readonly ElementsBodyRecord[]): BodyCatalogue;
35
+ /** A catalogue that holds everything `base` holds plus the listed moons given (each added to a scene on request; `base` is not changed). */
36
+ export declare function extendCatalogueWithMoons(base: BodyCatalogue, moons: readonly ListedMoonBody[]): BodyCatalogue;
34
37
  /** The id of the catalogue's one root body (the one with no parent), the origin every chain ends at. */
35
38
  export declare function rootBodyId(source?: BodyCatalogue): BodyId;
36
39
  /** Explicit, import-built, no discovery. */
@@ -2,6 +2,7 @@ import { BUILT_IN_BINDINGS, BUILT_IN_BODIES } from "../core/bodies/index.js";
2
2
  import { buildElementsBody } from "../core/elementsBody.js";
3
3
  import { EARTH_ENTRY } from "./bodies/earth.js";
4
4
  import { GALILEAN_ENTRIES } from "./bodies/galileanMoons.js";
5
+ import { listedMoonEntry } from "./bodies/listedMoons.js";
5
6
  import { IO_ENTRY } from "./bodies/io.js";
6
7
  import { JUPITER_ENTRY } from "./bodies/jupiter.js";
7
8
  import { MARS_ENTRY } from "./bodies/mars.js";
@@ -95,6 +96,13 @@ export function extendCatalogue(base, records) {
95
96
  }
96
97
  return createCatalogue([...base.definitions(), ...built.map(({ body }) => body.definition)], [...base.sources(), ...built.map(({ body }) => body.binding)], visuals);
97
98
  }
99
+ /** A catalogue that holds everything `base` holds plus the listed moons given (each added to a scene on request; `base` is not changed). */
100
+ export function extendCatalogueWithMoons(base, moons) {
101
+ if (moons.length === 0)
102
+ return base;
103
+ const visuals = [...base.ids().map((id) => ({ body: id, visual: base.get(id).visual })), ...moons.map(listedMoonEntry)];
104
+ return createCatalogue([...base.definitions(), ...moons.map(({ definition }) => definition)], [...base.sources(), ...moons.map(({ binding }) => binding)], visuals);
105
+ }
98
106
  /** The id of the catalogue's one root body (the one with no parent), the origin every chain ends at. */
99
107
  export function rootBodyId(source = catalogue) {
100
108
  const root = source.definitions().find((definition) => definition.parentId === undefined);
@@ -20,7 +20,9 @@ export interface MoonRecord {
20
20
  /** False for a provisional designation such as "S/2003 J 19" that has no name yet. */
21
21
  readonly named: boolean;
22
22
  readonly discoveryYear?: number;
23
- /** Ids into the catalogue's `sources`: the list, the family, the size and the discovery. */
23
+ /** Sidereal orbit period in days (JPL SSD mean elements); absent when no period is published for the moon. */
24
+ readonly orbitPeriodDays?: number;
25
+ /** Ids into the catalogue's `sources`: the list, the family, the size and the discovery (the period source is in the list but not in the info-panel provenance until a panel shows the period). */
24
26
  readonly sourceIds: readonly string[];
25
27
  }
26
28
  export interface MoonSource {
@@ -43,6 +43,7 @@ export function parseMoonCatalogue(raw) {
43
43
  return Object.freeze({
44
44
  named: moon.named !== false,
45
45
  ...(typeof moon.discoveryYear === "number" ? { discoveryYear: moon.discoveryYear } : {}),
46
+ ...(typeof moon.orbitPeriodDays === "number" && moon.orbitPeriodDays > 0 ? { orbitPeriodDays: moon.orbitPeriodDays } : {}),
46
47
  sourceIds: Object.freeze(sourceIds),
47
48
  id: text(moon.id, `${where}.id`),
48
49
  name: text(moon.name, `${where}.name`),
@@ -20,7 +20,7 @@ export declare const loadJupiterMoons: (load: MoonSystemLoad) => Promise<import(
20
20
  export declare const osculatingPeriodMs: (ephemeris: import("../chebyshevEphemeris.js").ChebyshevEphemeris, body: BodyId, timeUtcMs: number) => number;
21
21
  export declare const FITTED_MOON_TIDAL_LOCK: string;
22
22
  /** What every mapped Jupiter moon's record says about its position, with its own worst figure from T-096. */
23
- export declare const fittedMoonPosition: (label: string, worstM: number, span?: TimeBounds) => ReturnType<typeof import("../provenance.js").createProvenance>;
23
+ export declare const fittedMoonPosition: (label: string, worstM?: number, span?: TimeBounds) => ReturnType<typeof import("../provenance.js").createProvenance>;
24
24
  /** The Galilean moons turn synchronously: their prime meridians are the IAU records saved with their orbits (`data/orbits/`), the one source. */
25
25
  export declare const IO_ROTATION: import("../iauRotation.js").IauRotationElements;
26
26
  export declare const EUROPA: import("../body.js").CelestialBodyDefinition;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The one rule that turns a slim-table entry (`listedMoons.ts`) into a catalogue body (O-049 T-211): its planet's moon system builds the definition and the
3
+ * state source, from the table's mean radius and period. Nothing here names a moon. The result is made only when a scene adds the moon, so a moon nobody adds costs nothing.
4
+ * Detailed moons (`planetMoons.ts`, `jupiterMoons.ts`) are defined by hand and are in the built-in catalogue first, so they win.
5
+ */
6
+ import type { CelestialBodyDefinition, StateSourceBinding } from "../body.js";
7
+ import { type ListedMoon } from "./listedMoons.js";
8
+ import { type MoonSystem } from "./moonSystem.js";
9
+ /** Each planet's moon system by planet id: the loader every moon of that planet shares. */
10
+ export declare const MOON_SYSTEMS: Readonly<Record<string, MoonSystem>>;
11
+ export interface ListedMoonBody {
12
+ readonly definition: CelestialBodyDefinition;
13
+ readonly binding: StateSourceBinding;
14
+ }
15
+ /** The definition and state source of a listed moon: a sphere at its mean radius, positioned from its planet's fits, with the table's period when it has one. */
16
+ export declare function listedMoonBody(moon: ListedMoon): ListedMoonBody;
17
+ /** The body for a moon id, or undefined when the table does not list it. */
18
+ export declare const listedMoonBodyOf: (id: string) => ListedMoonBody | undefined;
@@ -0,0 +1,36 @@
1
+ import { JUPITER_MOON_SYSTEM } from "./jupiterMoons.js";
2
+ import { listedMoon } from "./listedMoons.js";
3
+ import { HISTORICAL_MOON_FIT_SPAN } from "./moonSystem.js";
4
+ import { MARS_MOON_SYSTEM, NEPTUNE_MOON_SYSTEM, PLUTO_MOON_SYSTEM, SATURN_MOON_SYSTEM, URANUS_MOON_SYSTEM } from "./planetMoons.js";
5
+ /** Each planet's moon system by planet id: the loader every moon of that planet shares. */
6
+ export const MOON_SYSTEMS = Object.freeze({
7
+ jupiter: JUPITER_MOON_SYSTEM,
8
+ saturn: SATURN_MOON_SYSTEM,
9
+ uranus: URANUS_MOON_SYSTEM,
10
+ neptune: NEPTUNE_MOON_SYSTEM,
11
+ mars: MARS_MOON_SYSTEM,
12
+ pluto: PLUTO_MOON_SYSTEM,
13
+ });
14
+ const RADIUS_SOURCE = "JPL SSD satellite physical parameters (https://ssd.jpl.nasa.gov/sats/phys_par/), mean radius";
15
+ const PERIOD_SOURCE = "JPL SSD satellite mean elements (https://ssd.jpl.nasa.gov/sats/elem/), sidereal period P";
16
+ /** The definition and state source of a listed moon: a sphere at its mean radius, positioned from its planet's fits, with the table's period when it has one. */
17
+ export function listedMoonBody(moon) {
18
+ const system = MOON_SYSTEMS[moon.parent];
19
+ if (system === undefined)
20
+ throw new RangeError(`${moon.id}: no moon system for "${moon.parent}"`);
21
+ const definition = system.mappedMoon({
22
+ id: moon.id,
23
+ label: moon.label,
24
+ radiusKm: moon.meanRadiusKm,
25
+ ...(moon.orbitPeriodDays === null ? {} : { orbitPeriodDays: moon.orbitPeriodDays }),
26
+ ...(moon.early ? { span: HISTORICAL_MOON_FIT_SPAN } : {}),
27
+ header: `${RADIUS_SOURCE}${moon.orbitPeriodDays === null ? "" : `; ${PERIOD_SOURCE}`}`,
28
+ dimensionsNote: `Mean radius ${moon.meanRadiusKm} km (${RADIUS_SOURCE}); ${moon.label} is drawn as a sphere at that radius. No gravitational parameter is held, and its rotation is not modelled: the sphere is turned to keep one face to ${system.config.centreLabel}.`,
29
+ });
30
+ return Object.freeze({ definition, binding: system.binding(moon.id) });
31
+ }
32
+ /** The body for a moon id, or undefined when the table does not list it. */
33
+ export const listedMoonBodyOf = (id) => {
34
+ const moon = listedMoon(id);
35
+ return moon === undefined ? undefined : listedMoonBody(moon);
36
+ };
@@ -0,0 +1,18 @@
1
+ export interface ListedMoon {
2
+ readonly id: string;
3
+ readonly label: string;
4
+ readonly meanRadiusKm: number;
5
+ readonly parent: string;
6
+ /** Sidereal orbit period, days; null when no period is published. */
7
+ readonly orbitPeriodDays: number | null;
8
+ /** The data package that holds the moon's fit: `astraeus-data-<parent>`. */
9
+ readonly dataPackage: string;
10
+ readonly fitSet: string;
11
+ readonly fitBody: string;
12
+ /** True when the fit starts in 1950 (the main moons); false when it starts in 2010. */
13
+ readonly early: boolean;
14
+ }
15
+ /** The listed moon with this id, or undefined. */
16
+ export declare const listedMoon: (id: string) => ListedMoon | undefined;
17
+ /** Every listed moon, in list order by parent. */
18
+ export declare const listedMoons: () => readonly ListedMoon[];