@johnmorrisdotca/wakusei-planets 0.31.0 → 0.32.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 +3 -0
- package/NOTICE.md +5 -0
- package/README.md +57 -3
- package/dist/data-door.d.ts +357 -0
- package/dist/data-door.js +393 -0
- package/dist/door/book.d.ts +133 -0
- package/dist/door/book.js +256 -0
- package/dist/door/host.d.ts +30 -0
- package/dist/door/host.js +44 -0
- package/dist/door/index.d.ts +6 -0
- package/dist/door/index.js +10 -0
- package/dist/door/map.d.ts +152 -0
- package/dist/door/map.js +162 -0
- package/dist/door/own.d.ts +36 -0
- package/dist/door/own.js +86 -0
- package/dist/door/points.d.ts +61 -0
- package/dist/door/points.js +175 -0
- package/dist/door/small-bodies.d.ts +157 -0
- package/dist/door/small-bodies.js +148 -0
- package/dist/element.d.ts +21 -0
- package/dist/element.js +74 -4
- package/dist/scene/body.d.ts +4 -1
- package/dist/scene/body.js +2 -1
- package/dist/scene/detail.d.ts +29 -12
- package/dist/scene/detail.js +217 -135
- package/dist/scene/painter.d.ts +3 -0
- package/dist/scene/painter.js +7 -4
- package/dist/scene/textures.d.ts +9 -2
- package/dist/scene/textures.js +17 -0
- package/dist/space/element.d.ts +24 -0
- package/dist/space/element.js +56 -3
- package/dist/space/scene.d.ts +8 -0
- package/dist/space/scene.js +28 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Credit, SourceInfo } from "../data-door.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The package's own data, as sources, written from the rows of `NOTICE.md`: `wakusei-pictures` (the surface pictures of the bodies), `wakusei-tiles` (the finer map tiles cut from the same maps) and `wakusei-orbits` (the series and
|
|
4
|
+
* tables the positions come from). A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { OWN_SOURCES } from "@johnmorrisdotca/wakusei-planets/door";
|
|
9
|
+
*
|
|
10
|
+
* console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const OWN_SOURCES: readonly SourceInfo[];
|
|
14
|
+
/** The rows of `OWN_SOURCES` by id. */
|
|
15
|
+
export declare const OWN_BY_ID: ReadonlyMap<string, SourceInfo>;
|
|
16
|
+
/** Marks a source object as made by this package. */
|
|
17
|
+
export declare function madeHere<T extends object>(source: T): T;
|
|
18
|
+
/** True for a source object this package made (`tilesSource`), false for any other. */
|
|
19
|
+
export declare const isOwnSource: (source: object) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The credit of one of the package's own sources, for a page that draws something itself: the pictures and positions of the elements are credited by the elements' own `credits()`, and a page that draws a body from the
|
|
22
|
+
* painter puts `ownCredit("wakusei-pictures", 1)` in its credit line.
|
|
23
|
+
*
|
|
24
|
+
* @param id - `wakusei-pictures`, `wakusei-tiles` or `wakusei-orbits`.
|
|
25
|
+
* @param used - How many marks were drawn from it.
|
|
26
|
+
* @returns The credit, marked as the package's own.
|
|
27
|
+
* @throws RangeError for an id that is not one of `OWN_SOURCES`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { creditLine, ownCredit } from "@johnmorrisdotca/wakusei-planets/door";
|
|
32
|
+
*
|
|
33
|
+
* console.log(creditLine([ownCredit("wakusei-tiles", 6)], "en"));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function ownCredit(id: string, used: number): Credit;
|
package/dist/door/own.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const NOTICE = "https://github.com/johnmorrisdotca/wakusei-planets/blob/main/NOTICE.md";
|
|
2
|
+
function freeze(value) {
|
|
3
|
+
if (typeof value === "object" && value !== null)
|
|
4
|
+
for (const inner of Object.values(value))
|
|
5
|
+
freeze(inner);
|
|
6
|
+
return Object.freeze(value);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The package's own data, as sources, written from the rows of `NOTICE.md`: `wakusei-pictures` (the surface pictures of the bodies), `wakusei-tiles` (the finer map tiles cut from the same maps) and `wakusei-orbits` (the series and
|
|
10
|
+
* tables the positions come from). A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { OWN_SOURCES } from "@johnmorrisdotca/wakusei-planets/door";
|
|
15
|
+
*
|
|
16
|
+
* console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const OWN_SOURCES = freeze([
|
|
20
|
+
{
|
|
21
|
+
id: "wakusei-pictures",
|
|
22
|
+
name: { en: "Surface pictures", ja: "表面の地図" },
|
|
23
|
+
credit: {
|
|
24
|
+
en: "Surface pictures: maps by NASA, USGS and JPL (public domain), Solar System Scope and Nestaeric",
|
|
25
|
+
ja: "表面の地図:NASA、USGS、JPLの地図(パブリックドメイン)、Solar System ScopeとNestaericの地図",
|
|
26
|
+
},
|
|
27
|
+
licence: { name: "CC BY 4.0", url: `${NOTICE}#surface-pictures`, spdx: "CC-BY-4.0" },
|
|
28
|
+
url: "https://github.com/johnmorrisdotca/wakusei-planets/tree/main/textures",
|
|
29
|
+
retrieved: "2026-11-02",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "wakusei-tiles",
|
|
33
|
+
name: { en: "Finer map tiles", ja: "細かい地図のタイル" },
|
|
34
|
+
credit: {
|
|
35
|
+
en: "Finer map tiles: maps by NASA, USGS and JPL (public domain), cut by Wakusei Planets",
|
|
36
|
+
ja: "細かい地図のタイル:NASA、USGS、JPLの地図(パブリックドメイン)、Wakusei Planetsで切り出したもの",
|
|
37
|
+
},
|
|
38
|
+
licence: { name: "Public domain", url: `${NOTICE}#finer-map-tiles` },
|
|
39
|
+
url: "https://johnmorrisdotca.github.io/wakusei-planets/tiles/",
|
|
40
|
+
retrieved: "2026-11-09",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "wakusei-orbits",
|
|
44
|
+
name: { en: "Positions", ja: "天体の位置" },
|
|
45
|
+
credit: {
|
|
46
|
+
en: "Positions: VSOP87B and ELP2000-82B (IMCCE, Observatoire de Paris), JPL Horizons (NASA/JPL-Caltech)",
|
|
47
|
+
ja: "位置:VSOP87BとELP2000-82B(パリ天文台IMCCE)、JPL Horizons(NASA/JPL-Caltech)",
|
|
48
|
+
},
|
|
49
|
+
licence: { name: "Published for use with credit", url: `${NOTICE}#the-numbers` },
|
|
50
|
+
url: "https://ftp.imcce.fr/pub/ephem/planets/vsop87/",
|
|
51
|
+
retrieved: "2026-11-07",
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
/** The rows of `OWN_SOURCES` by id. */
|
|
55
|
+
export const OWN_BY_ID = new Map(OWN_SOURCES.map((source) => [source.id, source]));
|
|
56
|
+
/** The source objects this package made itself: only these are its own, whatever id a caller's source gives itself. */
|
|
57
|
+
const MADE_HERE = new WeakSet();
|
|
58
|
+
/** Marks a source object as made by this package. */
|
|
59
|
+
export function madeHere(source) {
|
|
60
|
+
MADE_HERE.add(source);
|
|
61
|
+
return source;
|
|
62
|
+
}
|
|
63
|
+
/** True for a source object this package made (`tilesSource`), false for any other. */
|
|
64
|
+
export const isOwnSource = (source) => MADE_HERE.has(source);
|
|
65
|
+
/**
|
|
66
|
+
* The credit of one of the package's own sources, for a page that draws something itself: the pictures and positions of the elements are credited by the elements' own `credits()`, and a page that draws a body from the
|
|
67
|
+
* painter puts `ownCredit("wakusei-pictures", 1)` in its credit line.
|
|
68
|
+
*
|
|
69
|
+
* @param id - `wakusei-pictures`, `wakusei-tiles` or `wakusei-orbits`.
|
|
70
|
+
* @param used - How many marks were drawn from it.
|
|
71
|
+
* @returns The credit, marked as the package's own.
|
|
72
|
+
* @throws RangeError for an id that is not one of `OWN_SOURCES`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { creditLine, ownCredit } from "@johnmorrisdotca/wakusei-planets/door";
|
|
77
|
+
*
|
|
78
|
+
* console.log(creditLine([ownCredit("wakusei-tiles", 6)], "en"));
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function ownCredit(id, used) {
|
|
82
|
+
const source = OWN_BY_ID.get(id);
|
|
83
|
+
if (source === undefined)
|
|
84
|
+
throw new RangeError(`"${id}" is not one of the package's own sources`);
|
|
85
|
+
return { source, own: true, used };
|
|
86
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import { type Vec3 } from "../vec.ts";
|
|
3
|
+
import { type ScaleMode } from "../space/scale.ts";
|
|
4
|
+
import { type SmallBody } from "./small-bodies.ts";
|
|
5
|
+
/** The parts of three.js the points use, over and above the ones every body needs. A page's own subset of three that lacks the two instanced classes cannot draw them. */
|
|
6
|
+
export type PointsThree = Pick<typeof THREE, "BufferAttribute" | "InstancedBufferAttribute" | "InstancedBufferGeometry" | "Mesh" | "ShaderMaterial" | "Vector2" | "Vector3">;
|
|
7
|
+
/** How the view places a body round the Sun in a compressed view: its distance in astronomical units to the power `SPREAD`, times `SUN_COMPRESSED` Earth radii (the same two numbers as `space/scale.ts`). */
|
|
8
|
+
export declare const POINT_SCALE: {
|
|
9
|
+
readonly sunCompressed: 70;
|
|
10
|
+
readonly spread: 0.45;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Where the space view draws a small body: its place on the date (`smallBodyAt`, ecliptic of J2000) turned into the view's axes (equatorial, y north) and placed round the Sun by the same mapping as the planets (`placeAround`). The
|
|
14
|
+
* point's shader does the same sum on the graphics card; this is the one a test or a page can check it against.
|
|
15
|
+
*
|
|
16
|
+
* @param mode - The scale of the view.
|
|
17
|
+
* @param sun - Where the Sun is drawn, in Earth radii.
|
|
18
|
+
* @param body - The small body.
|
|
19
|
+
* @param jd - The date, as a Julian date (TT).
|
|
20
|
+
* @returns Where to draw it, in Earth radii.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { smallBodyPlace } from "@johnmorrisdotca/wakusei-planets/door";
|
|
25
|
+
*
|
|
26
|
+
* const place = smallBodyPlace("compressed", [70, 0, 0], { name: "T", a: 2, e: 0, i: 0, node: 0, peri: 0, M0: 0, epoch: 2461000.5, H: 9 }, 2461000.5);
|
|
27
|
+
* console.log(place.map(Math.round));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function smallBodyPlace(mode: ScaleMode, sun: Vec3, body: SmallBody, jd: number): Vec3;
|
|
31
|
+
/** What the points need to know at each draw. */
|
|
32
|
+
export interface PointsState {
|
|
33
|
+
/** The date, as a Julian date (TT). */
|
|
34
|
+
jd: number;
|
|
35
|
+
/** `true` or `compressed`, as the space view's scale. */
|
|
36
|
+
mode: "compressed" | "true";
|
|
37
|
+
/** Where the Sun is drawn, in the view's units (Earth radii from the Earth's centre). */
|
|
38
|
+
sun: Vec3;
|
|
39
|
+
/** The view's size in device pixels, and the pixels of a CSS pixel. */
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
ratio: number;
|
|
43
|
+
}
|
|
44
|
+
/** The points of a view's small bodies. */
|
|
45
|
+
export interface SmallBodyPoints {
|
|
46
|
+
readonly object: THREE.Object3D;
|
|
47
|
+
/** The bodies drawn: the records of every record source in use, as many as `MAX_POINTS`. Packs them for the graphics card. */
|
|
48
|
+
set(bodies: readonly SmallBody[]): void;
|
|
49
|
+
/** Called at each draw. */
|
|
50
|
+
update(state: PointsState): void;
|
|
51
|
+
/** How many bodies are in the one draw. */
|
|
52
|
+
readonly count: number;
|
|
53
|
+
dispose(): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Makes the points: one instanced draw of a quad for each small body.
|
|
57
|
+
*
|
|
58
|
+
* @param T - The parts of three.js.
|
|
59
|
+
* @returns The points, with no bodies yet.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createSmallBodyPoints(T: PointsThree): SmallBodyPoints;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { OBLIQUITY, RAD } from "../vec.js";
|
|
2
|
+
import { AU_IN_EARTH_RADII } from "../space/frame.js";
|
|
3
|
+
import { placeAround } from "../space/scale.js";
|
|
4
|
+
import { MAX_POINTS, packSmallBodies, smallBodyAt } from "./small-bodies.js";
|
|
5
|
+
/** How the view places a body round the Sun in a compressed view: its distance in astronomical units to the power `SPREAD`, times `SUN_COMPRESSED` Earth radii (the same two numbers as `space/scale.ts`). */
|
|
6
|
+
export const POINT_SCALE = { sunCompressed: 70, spread: 0.45 };
|
|
7
|
+
/**
|
|
8
|
+
* Where the space view draws a small body: its place on the date (`smallBodyAt`, ecliptic of J2000) turned into the view's axes (equatorial, y north) and placed round the Sun by the same mapping as the planets (`placeAround`). The
|
|
9
|
+
* point's shader does the same sum on the graphics card; this is the one a test or a page can check it against.
|
|
10
|
+
*
|
|
11
|
+
* @param mode - The scale of the view.
|
|
12
|
+
* @param sun - Where the Sun is drawn, in Earth radii.
|
|
13
|
+
* @param body - The small body.
|
|
14
|
+
* @param jd - The date, as a Julian date (TT).
|
|
15
|
+
* @returns Where to draw it, in Earth radii.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { smallBodyPlace } from "@johnmorrisdotca/wakusei-planets/door";
|
|
20
|
+
*
|
|
21
|
+
* const place = smallBodyPlace("compressed", [70, 0, 0], { name: "T", a: 2, e: 0, i: 0, node: 0, peri: 0, M0: 0, epoch: 2461000.5, H: 9 }, 2461000.5);
|
|
22
|
+
* console.log(place.map(Math.round));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function smallBodyPlace(mode, sun, body, jd) {
|
|
26
|
+
const [x, y, z] = smallBodyAt(body, jd);
|
|
27
|
+
const c = Math.cos(OBLIQUITY * RAD);
|
|
28
|
+
const s = Math.sin(OBLIQUITY * RAD);
|
|
29
|
+
return placeAround(mode, sun, [x, y * s + z * c, -(y * c - z * s)]);
|
|
30
|
+
}
|
|
31
|
+
/** The days from the date the bodies were packed at after which they are packed again, so the mean anomaly a float holds keeps its digits. */
|
|
32
|
+
const REPACK_DAYS = 3000;
|
|
33
|
+
const VERTEX = /* glsl */ `
|
|
34
|
+
attribute vec2 aCorner;
|
|
35
|
+
attribute vec4 aA;
|
|
36
|
+
attribute vec4 aB;
|
|
37
|
+
uniform float uDays;
|
|
38
|
+
uniform float uTrue;
|
|
39
|
+
uniform vec3 uSun;
|
|
40
|
+
uniform vec2 uViewport;
|
|
41
|
+
uniform float uRatio;
|
|
42
|
+
uniform float uAu;
|
|
43
|
+
uniform float uSunCompressed;
|
|
44
|
+
uniform float uSpread;
|
|
45
|
+
uniform vec2 uObliquity;
|
|
46
|
+
varying vec2 vCorner;
|
|
47
|
+
varying float vFade;
|
|
48
|
+
|
|
49
|
+
const float K = 0.01720209895;
|
|
50
|
+
const float TAU = 6.28318530718;
|
|
51
|
+
|
|
52
|
+
void main() {
|
|
53
|
+
float a = aA.x;
|
|
54
|
+
float e = aA.y;
|
|
55
|
+
float n = K / (a * sqrt(a));
|
|
56
|
+
float M = aB.y + n * (aB.z + uDays);
|
|
57
|
+
M = M - TAU * floor(M / TAU + 0.5);
|
|
58
|
+
float E = e < 0.8 ? M : 3.14159265;
|
|
59
|
+
for (int k = 0; k < 8; k++) E -= (E - e * sin(E) - M) / (1.0 - e * cos(E));
|
|
60
|
+
float px = a * (cos(E) - e);
|
|
61
|
+
float py = a * sqrt(1.0 - e * e) * sin(E);
|
|
62
|
+
float cw = cos(aB.x); float sw = sin(aB.x);
|
|
63
|
+
float co = cos(aA.w); float so = sin(aA.w);
|
|
64
|
+
float ci = cos(aA.z); float si = sin(aA.z);
|
|
65
|
+
float qx = cw * px - sw * py;
|
|
66
|
+
float qy = sw * px + cw * py;
|
|
67
|
+
vec3 ecl = vec3(co * qx - so * ci * qy, so * qx + co * ci * qy, si * qy);
|
|
68
|
+
// the ecliptic of J2000 in the scene's axes (equatorial, y north), as frame.ts does it
|
|
69
|
+
vec3 helio = vec3(ecl.x, ecl.y * uObliquity.x + ecl.z * uObliquity.y, -(ecl.y * uObliquity.y - ecl.z * uObliquity.x));
|
|
70
|
+
float l = length(helio);
|
|
71
|
+
float k = uTrue > 0.5 ? uAu : (l > 0.0 ? uSunCompressed * pow(l, uSpread) / l : 0.0);
|
|
72
|
+
vec3 world = uSun + helio * k;
|
|
73
|
+
vec4 clip = projectionMatrix * viewMatrix * vec4(world, 1.0);
|
|
74
|
+
// a brighter body (a lower H) is a larger point, two to five device pixels across
|
|
75
|
+
float size = clamp(4.6 - 0.28 * (aB.w - 6.0), 2.0, 5.0) * uRatio;
|
|
76
|
+
clip.xy += aCorner * (size / uViewport) * clip.w;
|
|
77
|
+
vCorner = aCorner;
|
|
78
|
+
vFade = clip.w > 0.0 ? 1.0 : 0.0;
|
|
79
|
+
gl_Position = clip;
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
const FRAGMENT = /* glsl */ `
|
|
83
|
+
varying vec2 vCorner;
|
|
84
|
+
varying float vFade;
|
|
85
|
+
void main() {
|
|
86
|
+
float d = length(vCorner);
|
|
87
|
+
if (d > 1.0 || vFade < 0.5) discard;
|
|
88
|
+
gl_FragColor = vec4(0.86, 0.84, 0.78, 0.9 * smoothstep(1.0, 0.45, d));
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
/**
|
|
92
|
+
* Makes the points: one instanced draw of a quad for each small body.
|
|
93
|
+
*
|
|
94
|
+
* @param T - The parts of three.js.
|
|
95
|
+
* @returns The points, with no bodies yet.
|
|
96
|
+
*/
|
|
97
|
+
export function createSmallBodyPoints(T) {
|
|
98
|
+
const fresh = (count, data) => {
|
|
99
|
+
const made = new T.InstancedBufferGeometry();
|
|
100
|
+
made.setAttribute("position", new T.BufferAttribute(new Float32Array(12), 3));
|
|
101
|
+
made.setAttribute("aCorner", new T.BufferAttribute(new Float32Array([-1, -1, 1, -1, 1, 1, -1, 1]), 2));
|
|
102
|
+
made.setIndex([0, 1, 2, 0, 2, 3]);
|
|
103
|
+
const a = new Float32Array(count * 4);
|
|
104
|
+
const b = new Float32Array(count * 4);
|
|
105
|
+
for (let k = 0; data !== undefined && k < count; k += 1) {
|
|
106
|
+
a.set(data.subarray(k * 8, k * 8 + 4), k * 4);
|
|
107
|
+
b.set(data.subarray(k * 8 + 4, k * 8 + 8), k * 4);
|
|
108
|
+
}
|
|
109
|
+
made.setAttribute("aA", new T.InstancedBufferAttribute(a, 4));
|
|
110
|
+
made.setAttribute("aB", new T.InstancedBufferAttribute(b, 4));
|
|
111
|
+
made.instanceCount = count;
|
|
112
|
+
return made;
|
|
113
|
+
};
|
|
114
|
+
const material = new T.ShaderMaterial({
|
|
115
|
+
vertexShader: VERTEX,
|
|
116
|
+
fragmentShader: FRAGMENT,
|
|
117
|
+
transparent: true,
|
|
118
|
+
depthWrite: false,
|
|
119
|
+
uniforms: {
|
|
120
|
+
uDays: { value: 0 },
|
|
121
|
+
uTrue: { value: 0 },
|
|
122
|
+
uSun: { value: new T.Vector3() },
|
|
123
|
+
uViewport: { value: new T.Vector2(1, 1) },
|
|
124
|
+
uRatio: { value: 1 },
|
|
125
|
+
uAu: { value: AU_IN_EARTH_RADII },
|
|
126
|
+
uSunCompressed: { value: POINT_SCALE.sunCompressed },
|
|
127
|
+
uSpread: { value: POINT_SCALE.spread },
|
|
128
|
+
uObliquity: { value: new T.Vector2(Math.sin(OBLIQUITY * RAD), Math.cos(OBLIQUITY * RAD)) },
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
const mesh = new T.Mesh(fresh(0), material);
|
|
132
|
+
mesh.frustumCulled = false;
|
|
133
|
+
mesh.renderOrder = -1;
|
|
134
|
+
mesh.visible = false;
|
|
135
|
+
let jd0 = 0;
|
|
136
|
+
let count = 0;
|
|
137
|
+
let bodies = [];
|
|
138
|
+
let packed = false;
|
|
139
|
+
const pack = (jd) => {
|
|
140
|
+
// the shader counts days from the date the bodies were packed at: close to the one being drawn, so a float has the digits
|
|
141
|
+
jd0 = jd;
|
|
142
|
+
const data = packSmallBodies(bodies, jd0);
|
|
143
|
+
count = data.length / 8;
|
|
144
|
+
const old = mesh.geometry;
|
|
145
|
+
mesh.geometry = fresh(count, data);
|
|
146
|
+
old.dispose();
|
|
147
|
+
mesh.visible = count > 0;
|
|
148
|
+
packed = true;
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
object: mesh,
|
|
152
|
+
set(next) {
|
|
153
|
+
bodies = next.length > MAX_POINTS ? next.slice(0, MAX_POINTS) : next;
|
|
154
|
+
packed = false;
|
|
155
|
+
},
|
|
156
|
+
update(state) {
|
|
157
|
+
if (!packed || Math.abs(state.jd - jd0) > REPACK_DAYS)
|
|
158
|
+
pack(state.jd);
|
|
159
|
+
const u = material.uniforms;
|
|
160
|
+
u.uDays.value = state.jd - jd0;
|
|
161
|
+
u.uTrue.value = state.mode === "true" ? 1 : 0;
|
|
162
|
+
u.uSun.value.set(state.sun[0], state.sun[1], state.sun[2]);
|
|
163
|
+
u.uViewport.value.set(Math.max(1, state.width), Math.max(1, state.height));
|
|
164
|
+
u.uRatio.value = state.ratio;
|
|
165
|
+
},
|
|
166
|
+
get count() {
|
|
167
|
+
return count;
|
|
168
|
+
},
|
|
169
|
+
dispose() {
|
|
170
|
+
mesh.geometry.dispose();
|
|
171
|
+
material.dispose();
|
|
172
|
+
mesh.visible = false;
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type RecordSource, type RecordsRead } from "../data-door.ts";
|
|
2
|
+
import type { Vec3 } from "../vec.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A small body on an orbit round the Sun: its name, and the elements of the orbit at an epoch (as the Minor Planet Center and JPL list them). Distances are in astronomical units, angles in degrees, `epoch` is a Julian date (TT)
|
|
5
|
+
* and `H` is the absolute magnitude. The orbit is an ellipse: `a` above 0 and `e` from 0 to just under 1.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { SmallBody } from "@johnmorrisdotca/wakusei-planets/door";
|
|
10
|
+
*
|
|
11
|
+
* const ceres: SmallBody = { name: "Ceres", a: 2.7656, e: 0.0795, i: 10.588, node: 80.25, peri: 73.3, M0: 291.4, epoch: 2461000.5, H: 3.34 };
|
|
12
|
+
* console.log(ceres.name);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface SmallBody {
|
|
16
|
+
name: string;
|
|
17
|
+
/** The semi-major axis, in astronomical units. */
|
|
18
|
+
a: number;
|
|
19
|
+
/** The eccentricity: 0 (a circle) to just under 1. */
|
|
20
|
+
e: number;
|
|
21
|
+
/** The inclination to the ecliptic of J2000, in degrees. */
|
|
22
|
+
i: number;
|
|
23
|
+
/** The longitude of the ascending node, in degrees. */
|
|
24
|
+
node: number;
|
|
25
|
+
/** The argument of perihelion, in degrees. */
|
|
26
|
+
peri: number;
|
|
27
|
+
/** The mean anomaly at the epoch, in degrees. */
|
|
28
|
+
M0: number;
|
|
29
|
+
/** The epoch, as a Julian date. */
|
|
30
|
+
epoch: number;
|
|
31
|
+
/** The absolute magnitude. */
|
|
32
|
+
H: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A source of small bodies: a list that fits in memory (at most 200,000 records), read once, when the source is added.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import type { SmallBodySource } from "@johnmorrisdotca/wakusei-planets/door";
|
|
40
|
+
*
|
|
41
|
+
* const count = async (source: SmallBodySource): Promise<number> => (await source.records(new AbortController().signal)).length;
|
|
42
|
+
* console.log(typeof count);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export type SmallBodySource = RecordSource<SmallBody>;
|
|
46
|
+
/**
|
|
47
|
+
* The Gaussian gravitational constant: the mean motion, in radians a day, of a body whose semi-major axis is one astronomical unit.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { GAUSS_K } from "@johnmorrisdotca/wakusei-planets/door";
|
|
52
|
+
*
|
|
53
|
+
* console.log(((2 * Math.PI) / GAUSS_K).toFixed(2)); // the days of a year at one astronomical unit
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const GAUSS_K = 0.01720209895;
|
|
57
|
+
/**
|
|
58
|
+
* The numbers of a record that must be finite.
|
|
59
|
+
*
|
|
60
|
+
* @param body - The record.
|
|
61
|
+
* @returns Its eight numbers.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { smallBodyNumbers } from "@johnmorrisdotca/wakusei-planets/door";
|
|
66
|
+
*
|
|
67
|
+
* console.log(smallBodyNumbers({ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461000.5, H: 9 }).length);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const smallBodyNumbers: (body: SmallBody) => number[];
|
|
71
|
+
/**
|
|
72
|
+
* True for a record the package can draw: a name, finite numbers, and an ellipse.
|
|
73
|
+
*
|
|
74
|
+
* @param value - Anything.
|
|
75
|
+
* @returns Whether it is a `SmallBody` that can be drawn.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { isSmallBody } from "@johnmorrisdotca/wakusei-planets/door";
|
|
80
|
+
*
|
|
81
|
+
* console.log(isSmallBody({ name: "T", a: 2.7, e: 1.2, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461000.5, H: 9 })); // false: not an ellipse
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function isSmallBody(value: unknown): value is SmallBody;
|
|
85
|
+
/**
|
|
86
|
+
* What `readSmallBodies` found: the frozen records that can be drawn, and `skipped`, the records left out for a number that is not finite, a name that is not text, or an orbit that is not an ellipse.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import type { SmallBodiesRead } from "@johnmorrisdotca/wakusei-planets/door";
|
|
91
|
+
*
|
|
92
|
+
* const say = (read: SmallBodiesRead): string => `${read.status}: ${read.records.length} kept, ${read.skipped} skipped`;
|
|
93
|
+
* console.log(typeof say);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export type SmallBodiesRead = RecordsRead<SmallBody>;
|
|
97
|
+
/**
|
|
98
|
+
* Reads a small-body source once: the list is frozen, a record that cannot be drawn (see `SmallBody`) is left out and counted, and a list of more than 200,000 is refused whole. It never throws: a source that fails is a
|
|
99
|
+
* failed read, and one the signal aborted is `aborted`.
|
|
100
|
+
*
|
|
101
|
+
* @param source - The source.
|
|
102
|
+
* @param signal - Aborts the read.
|
|
103
|
+
* @returns The records and the count left out.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts no-run
|
|
107
|
+
* import { readSmallBodies, type SmallBodySource } from "@johnmorrisdotca/wakusei-planets/door";
|
|
108
|
+
*
|
|
109
|
+
* declare const source: SmallBodySource;
|
|
110
|
+
* const read = await readSmallBodies(source, new AbortController().signal);
|
|
111
|
+
* console.log(read.records.length, read.skipped);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function readSmallBodies(source: SmallBodySource, signal: AbortSignal): Promise<SmallBodiesRead>;
|
|
115
|
+
/**
|
|
116
|
+
* Where a small body is on a date: heliocentric ecliptic coordinates of J2000, in astronomical units, from its elements by Kepler's equation (the orbit is two-body: no planet moves it).
|
|
117
|
+
*
|
|
118
|
+
* @param body - The body.
|
|
119
|
+
* @param jd - The date, as a Julian date (TT).
|
|
120
|
+
* @returns x, y, z in astronomical units from the Sun.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { smallBodyAt } from "@johnmorrisdotca/wakusei-planets/door";
|
|
125
|
+
*
|
|
126
|
+
* const [x, y, z] = smallBodyAt({ name: "Test", a: 2.77, e: 0.08, i: 10.6, node: 80.3, peri: 73.6, M0: 0, epoch: 2461000.5, H: 3.3 }, 2461000.5);
|
|
127
|
+
* console.log(Math.hypot(x, y, z).toFixed(2));
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function smallBodyAt(body: SmallBody, jd: number): Vec3;
|
|
131
|
+
/**
|
|
132
|
+
* The most small bodies drawn, whatever the source holds (the source's own cap is 200,000 records).
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { MAX_POINTS } from "@johnmorrisdotca/wakusei-planets/door";
|
|
137
|
+
*
|
|
138
|
+
* console.log(MAX_POINTS);
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare const MAX_POINTS = 200000;
|
|
142
|
+
/**
|
|
143
|
+
* The elements of the bodies packed for the graphics card, eight numbers each: `a`, `e`, `i`, `node`, `peri`, `M0`, the days from the epoch to `jd0`, and `H`, angles in radians. The point's shader moves each one from there
|
|
144
|
+
* with the mean motion, so no work is done on the processor when the date changes.
|
|
145
|
+
*
|
|
146
|
+
* @param bodies - The bodies.
|
|
147
|
+
* @param jd0 - The Julian date the shader counts from.
|
|
148
|
+
* @returns A `Float32Array` of eight numbers a body.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { packSmallBodies } from "@johnmorrisdotca/wakusei-planets/door";
|
|
153
|
+
*
|
|
154
|
+
* console.log(packSmallBodies([{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461000.5, H: 9 }], 2461000.5).length);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function packSmallBodies(bodies: readonly SmallBody[], jd0: number): Float32Array;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// The small-body record source of the data door: asteroids, comets and the like as a list of orbital elements, drawn as points in `<wakusei-space>`. A source hands in `SmallBody` records (at most 200,000, read once); this
|
|
2
|
+
// file checks them, and works out where one is for a date (`smallBodyAt`, the same Kepler orbit the point's shader solves). Pure: no DOM, no three.js.
|
|
3
|
+
import { loadRecords } from "../data-door.js";
|
|
4
|
+
import { RAD } from "../vec.js";
|
|
5
|
+
/**
|
|
6
|
+
* The Gaussian gravitational constant: the mean motion, in radians a day, of a body whose semi-major axis is one astronomical unit.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { GAUSS_K } from "@johnmorrisdotca/wakusei-planets/door";
|
|
11
|
+
*
|
|
12
|
+
* console.log(((2 * Math.PI) / GAUSS_K).toFixed(2)); // the days of a year at one astronomical unit
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const GAUSS_K = 0.01720209895;
|
|
16
|
+
/**
|
|
17
|
+
* The numbers of a record that must be finite.
|
|
18
|
+
*
|
|
19
|
+
* @param body - The record.
|
|
20
|
+
* @returns Its eight numbers.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { smallBodyNumbers } from "@johnmorrisdotca/wakusei-planets/door";
|
|
25
|
+
*
|
|
26
|
+
* console.log(smallBodyNumbers({ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461000.5, H: 9 }).length);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const smallBodyNumbers = (body) => [body.a, body.e, body.i, body.node, body.peri, body.M0, body.epoch, body.H];
|
|
30
|
+
/**
|
|
31
|
+
* True for a record the package can draw: a name, finite numbers, and an ellipse.
|
|
32
|
+
*
|
|
33
|
+
* @param value - Anything.
|
|
34
|
+
* @returns Whether it is a `SmallBody` that can be drawn.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { isSmallBody } from "@johnmorrisdotca/wakusei-planets/door";
|
|
39
|
+
*
|
|
40
|
+
* console.log(isSmallBody({ name: "T", a: 2.7, e: 1.2, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461000.5, H: 9 })); // false: not an ellipse
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function isSmallBody(value) {
|
|
44
|
+
if (typeof value !== "object" || value === null)
|
|
45
|
+
return false;
|
|
46
|
+
const one = value;
|
|
47
|
+
if (typeof one["name"] !== "string")
|
|
48
|
+
return false;
|
|
49
|
+
for (const field of ["a", "e", "i", "node", "peri", "M0", "epoch", "H"])
|
|
50
|
+
if (typeof one[field] !== "number" || !Number.isFinite(one[field]))
|
|
51
|
+
return false;
|
|
52
|
+
return one["a"] > 0 && one["e"] >= 0 && one["e"] < 1;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads a small-body source once: the list is frozen, a record that cannot be drawn (see `SmallBody`) is left out and counted, and a list of more than 200,000 is refused whole. It never throws: a source that fails is a
|
|
56
|
+
* failed read, and one the signal aborted is `aborted`.
|
|
57
|
+
*
|
|
58
|
+
* @param source - The source.
|
|
59
|
+
* @param signal - Aborts the read.
|
|
60
|
+
* @returns The records and the count left out.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts no-run
|
|
64
|
+
* import { readSmallBodies, type SmallBodySource } from "@johnmorrisdotca/wakusei-planets/door";
|
|
65
|
+
*
|
|
66
|
+
* declare const source: SmallBodySource;
|
|
67
|
+
* const read = await readSmallBodies(source, new AbortController().signal);
|
|
68
|
+
* console.log(read.records.length, read.skipped);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export async function readSmallBodies(source, signal) {
|
|
72
|
+
const read = await loadRecords(source, signal, smallBodyNumbers);
|
|
73
|
+
if (read.status !== "ok")
|
|
74
|
+
return read;
|
|
75
|
+
const kept = read.records.filter(isSmallBody);
|
|
76
|
+
const skipped = read.skipped + read.records.length - kept.length;
|
|
77
|
+
return { status: "ok", records: Object.freeze(kept), skipped };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Where a small body is on a date: heliocentric ecliptic coordinates of J2000, in astronomical units, from its elements by Kepler's equation (the orbit is two-body: no planet moves it).
|
|
81
|
+
*
|
|
82
|
+
* @param body - The body.
|
|
83
|
+
* @param jd - The date, as a Julian date (TT).
|
|
84
|
+
* @returns x, y, z in astronomical units from the Sun.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { smallBodyAt } from "@johnmorrisdotca/wakusei-planets/door";
|
|
89
|
+
*
|
|
90
|
+
* const [x, y, z] = smallBodyAt({ name: "Test", a: 2.77, e: 0.08, i: 10.6, node: 80.3, peri: 73.6, M0: 0, epoch: 2461000.5, H: 3.3 }, 2461000.5);
|
|
91
|
+
* console.log(Math.hypot(x, y, z).toFixed(2));
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function smallBodyAt(body, jd) {
|
|
95
|
+
const n = GAUSS_K / Math.pow(body.a, 1.5);
|
|
96
|
+
const mean = body.M0 * RAD + n * (jd - body.epoch);
|
|
97
|
+
const m = mean - 2 * Math.PI * Math.floor(mean / (2 * Math.PI) + 0.5);
|
|
98
|
+
let E = body.e < 0.8 ? m : Math.PI;
|
|
99
|
+
for (let k = 0; k < 30; k += 1) {
|
|
100
|
+
const step = (E - body.e * Math.sin(E) - m) / (1 - body.e * Math.cos(E));
|
|
101
|
+
E -= step;
|
|
102
|
+
if (Math.abs(step) < 1e-13)
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
const x = body.a * (Math.cos(E) - body.e);
|
|
106
|
+
const y = body.a * Math.sqrt(1 - body.e * body.e) * Math.sin(E);
|
|
107
|
+
const [cw, sw] = [Math.cos(body.peri * RAD), Math.sin(body.peri * RAD)];
|
|
108
|
+
const [co, so] = [Math.cos(body.node * RAD), Math.sin(body.node * RAD)];
|
|
109
|
+
const [ci, si] = [Math.cos(body.i * RAD), Math.sin(body.i * RAD)];
|
|
110
|
+
const px = cw * x - sw * y;
|
|
111
|
+
const py = sw * x + cw * y;
|
|
112
|
+
return [co * px - so * ci * py, so * px + co * ci * py, si * py];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The most small bodies drawn, whatever the source holds (the source's own cap is 200,000 records).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { MAX_POINTS } from "@johnmorrisdotca/wakusei-planets/door";
|
|
120
|
+
*
|
|
121
|
+
* console.log(MAX_POINTS);
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export const MAX_POINTS = 200_000;
|
|
125
|
+
/**
|
|
126
|
+
* The elements of the bodies packed for the graphics card, eight numbers each: `a`, `e`, `i`, `node`, `peri`, `M0`, the days from the epoch to `jd0`, and `H`, angles in radians. The point's shader moves each one from there
|
|
127
|
+
* with the mean motion, so no work is done on the processor when the date changes.
|
|
128
|
+
*
|
|
129
|
+
* @param bodies - The bodies.
|
|
130
|
+
* @param jd0 - The Julian date the shader counts from.
|
|
131
|
+
* @returns A `Float32Array` of eight numbers a body.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { packSmallBodies } from "@johnmorrisdotca/wakusei-planets/door";
|
|
136
|
+
*
|
|
137
|
+
* console.log(packSmallBodies([{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461000.5, H: 9 }], 2461000.5).length);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export function packSmallBodies(bodies, jd0) {
|
|
141
|
+
const count = Math.min(bodies.length, MAX_POINTS);
|
|
142
|
+
const out = new Float32Array(count * 8);
|
|
143
|
+
for (let k = 0; k < count; k += 1) {
|
|
144
|
+
const b = bodies[k];
|
|
145
|
+
out.set([b.a, b.e, b.i * RAD, b.node * RAD, b.peri * RAD, b.M0 * RAD, jd0 - b.epoch, b.H], k * 8);
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|