@johnmorrisdotca/wakusei-planets 0.24.0 → 0.26.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 +14 -0
- package/README.md +36 -8
- package/dist/blackbody.d.ts +2 -0
- package/dist/blackbody.js +10 -0
- package/dist/element.d.ts +8 -0
- package/dist/element.js +102 -16
- package/dist/embed.d.ts +3 -0
- package/dist/embed.js +30 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kids/data.d.ts +109 -0
- package/dist/kids/data.js +164 -0
- package/dist/kids/index.d.ts +4 -0
- package/dist/kids/index.js +5 -0
- package/dist/kids/land.d.ts +3 -0
- package/dist/kids/land.js +29 -0
- package/dist/kids/picture.d.ts +39 -0
- package/dist/kids/picture.js +255 -0
- package/dist/kids/sheet.d.ts +60 -0
- package/dist/kids/sheet.js +79 -0
- package/dist/kids/svg.d.ts +46 -0
- package/dist/kids/svg.js +193 -0
- package/dist/line.d.ts +9 -1
- package/dist/line.js +3 -4
- package/dist/scene/body.d.ts +8 -1
- package/dist/scene/body.js +33 -9
- package/dist/scene/glsl.d.ts +7 -2
- package/dist/scene/glsl.js +49 -3
- package/dist/scene/look.d.ts +43 -0
- package/dist/scene/look.js +39 -1
- package/dist/scene/painter.js +2 -0
- package/dist/scene/store.d.ts +3 -0
- package/dist/scene/store.js +3 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +4 -1
- package/dist/space/element.js +17 -14
- package/dist/space/frame.d.ts +3 -3
- package/dist/space/frame.js +3 -3
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/scale.d.ts +60 -7
- package/dist/space/scale.js +105 -9
- package/dist/space/scene.d.ts +7 -1
- package/dist/space/scene.js +36 -27
- package/dist/star-line.d.ts +20 -0
- package/dist/star-line.js +59 -0
- package/dist/star.d.ts +193 -0
- package/dist/star.js +261 -0
- package/dist/stars.js +3 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -2
package/dist/scene/glsl.js
CHANGED
|
@@ -52,8 +52,9 @@ float oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {
|
|
|
52
52
|
float dy = (lat(p) - radians(lat0)) / radians(ry);
|
|
53
53
|
return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));
|
|
54
54
|
}`;
|
|
55
|
-
/** The fragment shader of a body: the surface code goes between the prelude and `main`. */
|
|
56
|
-
export function bodyFragment(surface, painted, world = false) {
|
|
55
|
+
/** The fragment shader of a body: the surface code goes between the prelude and `main`. `limbTint` is the colour the edge of a glowing body shifts to (default the Sun's orange). */
|
|
56
|
+
export function bodyFragment(surface, painted, world = false, limbTint) {
|
|
57
|
+
const tint = limbTint === undefined ? "vec3(1.0, 0.55, 0.25)" : `vec3(${limbTint.map((v) => v.toFixed(4)).join(", ")})`;
|
|
57
58
|
return /* glsl */ `
|
|
58
59
|
precision highp float;
|
|
59
60
|
uniform vec3 uLight;
|
|
@@ -84,7 +85,7 @@ void main() {
|
|
|
84
85
|
float mu = ${world ? "clamp(dot(n, normalize(vV)), 0.0, 1.0)" : "clamp(n.z, 0.0, 1.0)"};
|
|
85
86
|
if (uEmissive > 0.5) {
|
|
86
87
|
float edge = pow(mu, uLimb);
|
|
87
|
-
vec3 c = s.rgb * mix(
|
|
88
|
+
vec3 c = s.rgb * mix(${tint}, vec3(1.0), edge) * (0.55 + 0.45 * edge);
|
|
88
89
|
gl_FragColor = vec4(c, 1.0);
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
@@ -235,6 +236,51 @@ void main() {
|
|
|
235
236
|
a *= streak * smoothstep(3.0, 1.6, r);
|
|
236
237
|
gl_FragColor = vec4(uColour * a, a);
|
|
237
238
|
}`;
|
|
239
|
+
/**
|
|
240
|
+
* The glow round a star that is not the Sun, drawn on a plane behind it: a wide soft bloom, a tight bright inner bloom, a thin glowing edge (the chromosphere), and, on an active star, prominences standing off the edge
|
|
241
|
+
* with an occasional flare. `uStrength` is how bright, `uSpread` how fast the bloom fades, `uRim` the edge, `uProm` how big the prominences are, `uSeed` where they are and `uTime` moves them.
|
|
242
|
+
*/
|
|
243
|
+
export const STAR_GLOW_FRAGMENT = /* glsl */ `
|
|
244
|
+
precision highp float;
|
|
245
|
+
varying vec2 vP;
|
|
246
|
+
uniform vec3 uColour;
|
|
247
|
+
uniform float uStrength;
|
|
248
|
+
uniform float uSpread;
|
|
249
|
+
uniform float uRim;
|
|
250
|
+
uniform float uProm;
|
|
251
|
+
uniform float uSeed;
|
|
252
|
+
uniform float uTime;
|
|
253
|
+
float h1(float n) { return fract(sin(n * 127.1 + uSeed * 91.7) * 43758.5453); }
|
|
254
|
+
float n1(float x) { float i = floor(x); float f = fract(x); f = f * f * (3.0 - 2.0 * f); return mix(h1(i), h1(i + 1.0), f); }
|
|
255
|
+
void main() {
|
|
256
|
+
float r = length(vP);
|
|
257
|
+
if (r < 0.98) discard;
|
|
258
|
+
float x = r - 1.0;
|
|
259
|
+
float fade = smoothstep(3.0, 1.6, r);
|
|
260
|
+
float halo = exp(-x * uSpread) * uStrength;
|
|
261
|
+
float tight = exp(-x * 14.0) * uStrength * 0.9;
|
|
262
|
+
float rim = exp(-x * 60.0) * uRim;
|
|
263
|
+
vec3 col = uColour * (halo + tight) + mix(uColour, vec3(1.0), 0.4) * rim;
|
|
264
|
+
float a = halo + tight + rim;
|
|
265
|
+
if (uProm > 0.0) {
|
|
266
|
+
float ang = atan(vP.y, vP.x);
|
|
267
|
+
float site = smoothstep(0.55, 0.85, n1(ang * 2.6 + uSeed * 20.0));
|
|
268
|
+
float drift = 0.75 + 0.25 * sin(uTime * 0.5 + ang * 4.0);
|
|
269
|
+
float height = site * uProm * 0.3 * drift;
|
|
270
|
+
float strands = 0.65 + 0.35 * n1(ang * 70.0 + uTime * 0.3);
|
|
271
|
+
float pr = step(0.0, x) * pow(smoothstep(height, 0.0, x), 1.6) * site * strands * 0.9;
|
|
272
|
+
vec3 pc = mix(vec3(1.0, 0.42, 0.26), uColour, 0.2);
|
|
273
|
+
float a0 = uSeed * 6.2831853 + uTime * 0.02;
|
|
274
|
+
float da = atan(sin(ang - a0), cos(ang - a0));
|
|
275
|
+
float burst = pow(max(0.0, sin(uTime * 0.9 + uSeed * 40.0)), 24.0) * uProm;
|
|
276
|
+
float fl = exp(-da * da * 14.0) * exp(-x * 6.0) * burst * 1.6;
|
|
277
|
+
col += pc * pr + vec3(1.0, 0.92, 0.75) * fl;
|
|
278
|
+
a += pr + fl;
|
|
279
|
+
}
|
|
280
|
+
// additive blending multiplies by alpha, so the root of the light is the alpha and the colour carries the rest: the sum arrives as written
|
|
281
|
+
float s = sqrt(min(a * fade, 1.0));
|
|
282
|
+
gl_FragColor = vec4(col / max(a, 1e-4) * s, s);
|
|
283
|
+
}`;
|
|
238
284
|
/** A cheap lit ball for a moon seen small beside its planet. */
|
|
239
285
|
export const BALL_FRAGMENT = /* glsl */ `
|
|
240
286
|
precision highp float;
|
package/dist/scene/look.d.ts
CHANGED
|
@@ -72,6 +72,17 @@ export interface BodyLook {
|
|
|
72
72
|
atmosphere?: Atmosphere;
|
|
73
73
|
/** How much the disc darkens toward the limb, 0 to 1. Default 0. */
|
|
74
74
|
limb?: number;
|
|
75
|
+
/** For a glowing body: the colour its edge shifts to as it darkens (0 to 1 each). Default the Sun's, orange. */
|
|
76
|
+
limbTint?: readonly [number, number, number];
|
|
77
|
+
/** For a glowing body: its soft corona. The colour (0 to 1 each), how strong it is and how fast it fades (higher is tighter). Default the Sun's glow. */
|
|
78
|
+
glow?: {
|
|
79
|
+
colour: readonly [number, number, number];
|
|
80
|
+
strength: number;
|
|
81
|
+
spread: number; /** How bright the thin glowing edge is. Default 0. */
|
|
82
|
+
rim?: number; /** How big the prominences and flares on the edge are, 0 to 1. Default 0. */
|
|
83
|
+
prominence?: number; /** 0 to 1: where on the edge they are. */
|
|
84
|
+
seed?: number;
|
|
85
|
+
};
|
|
75
86
|
/** How strongly the height shows as relief, 0 to 2. Default 0.6. */
|
|
76
87
|
relief?: number;
|
|
77
88
|
/** How far light wraps round the terminator: 0 is a hard edge (no air), 0.3 a soft one. Default 0.04, or 0.3 with an atmosphere. */
|
|
@@ -82,6 +93,7 @@ export interface BodyLook {
|
|
|
82
93
|
/** Draw the painted map in the realistic look too: for a body with no honest drawing from numbers (the Earth's continents). */
|
|
83
94
|
mapped?: boolean;
|
|
84
95
|
}
|
|
96
|
+
import type { StarLook, StarNumbers } from "../star.ts";
|
|
85
97
|
/**
|
|
86
98
|
* Teach the package how to draw a body in three.js. Each body's entry point (`@johnmorrisdotca/wakusei-planets/jupiter`) calls this once as it loads; call it yourself to add or replace a look.
|
|
87
99
|
*
|
|
@@ -111,3 +123,34 @@ export declare function registerLook(look: BodyLook): BodyLook;
|
|
|
111
123
|
* ```
|
|
112
124
|
*/
|
|
113
125
|
export declare const lookOf: (id: BodyId) => BodyLook | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Teach the package a star by name, so an element can be told `star="Betelgeuse"` and draw it from these numbers. The package holds no catalogue of stars: this is where a page puts the few it draws.
|
|
128
|
+
* The name is matched without regard to case. Registering a name again replaces it.
|
|
129
|
+
*
|
|
130
|
+
* @param name - What the star is called in the `star` attribute.
|
|
131
|
+
* @param numbers - The star's numbers.
|
|
132
|
+
* @returns The star, ready to draw.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { registerStarLook, starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
137
|
+
*
|
|
138
|
+
* registerStarLook("Proxima Centauri", { temperatureK: 3042, radiusSun: 0.154, luminosityClass: "V", rotationDays: 83 });
|
|
139
|
+
* console.log(starLookOf("proxima centauri")?.colour);
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare function registerStarLook(name: string, numbers: StarNumbers): StarLook;
|
|
143
|
+
/**
|
|
144
|
+
* The star registered under a name, or `undefined`.
|
|
145
|
+
*
|
|
146
|
+
* @param name - The name given to `registerStarLook`, in any case.
|
|
147
|
+
* @returns The star, or `undefined` when none is registered by that name.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
152
|
+
*
|
|
153
|
+
* console.log(starLookOf("Vega") === undefined);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare const starLookOf: (name: string) => StarLook | undefined;
|
package/dist/scene/look.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { starLook } from "../star.js";
|
|
2
|
+
import { looks, stars, waiting } from "./store.js";
|
|
2
3
|
/**
|
|
3
4
|
* Teach the package how to draw a body in three.js. Each body's entry point (`@johnmorrisdotca/wakusei-planets/jupiter`) calls this once as it loads; call it yourself to add or replace a look.
|
|
4
5
|
*
|
|
@@ -33,3 +34,40 @@ export function registerLook(look) {
|
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
36
|
export const lookOf = (id) => looks.get(id);
|
|
37
|
+
/**
|
|
38
|
+
* Teach the package a star by name, so an element can be told `star="Betelgeuse"` and draw it from these numbers. The package holds no catalogue of stars: this is where a page puts the few it draws.
|
|
39
|
+
* The name is matched without regard to case. Registering a name again replaces it.
|
|
40
|
+
*
|
|
41
|
+
* @param name - What the star is called in the `star` attribute.
|
|
42
|
+
* @param numbers - The star's numbers.
|
|
43
|
+
* @returns The star, ready to draw.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { registerStarLook, starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
48
|
+
*
|
|
49
|
+
* registerStarLook("Proxima Centauri", { temperatureK: 3042, radiusSun: 0.154, luminosityClass: "V", rotationDays: 83 });
|
|
50
|
+
* console.log(starLookOf("proxima centauri")?.colour);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function registerStarLook(name, numbers) {
|
|
54
|
+
const made = starLook({ name, ...numbers });
|
|
55
|
+
stars.set(name.trim().toLowerCase(), made);
|
|
56
|
+
for (const wake of waiting)
|
|
57
|
+
wake();
|
|
58
|
+
return made;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The star registered under a name, or `undefined`.
|
|
62
|
+
*
|
|
63
|
+
* @param name - The name given to `registerStarLook`, in any case.
|
|
64
|
+
* @returns The star, or `undefined` when none is registered by that name.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
69
|
+
*
|
|
70
|
+
* console.log(starLookOf("Vega") === undefined);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const starLookOf = (name) => stars.get(name.trim().toLowerCase());
|
package/dist/scene/painter.js
CHANGED
|
@@ -204,6 +204,8 @@ function paint(T, id, context, bases) {
|
|
|
204
204
|
const show = (t) => {
|
|
205
205
|
paintedMaterial.uniforms.uMap.value = t;
|
|
206
206
|
mesh.material = paintedMaterial;
|
|
207
|
+
// the shaded look was drawn only until the picture came: if it was drawn at all, its program is let go now, so what a body holds does not depend on which came first
|
|
208
|
+
shader.dispose();
|
|
207
209
|
redraw();
|
|
208
210
|
};
|
|
209
211
|
if (wantPainted && paintedMaterial !== undefined && widths[0] !== undefined) {
|
package/dist/scene/store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BodyId } from "../facts.ts";
|
|
2
|
+
import type { StarLook } from "../star.ts";
|
|
2
3
|
import type { BodyLook } from "./look.ts";
|
|
3
4
|
/** A body whose line look another package's element draws (the Earth, by chikyu-earth) instead of this one: the element asks it for what to show. The shaded and painted looks are always this package's. */
|
|
4
5
|
export interface Delegate {
|
|
@@ -9,5 +10,7 @@ export interface Delegate {
|
|
|
9
10
|
}): Promise<HTMLElement | null>;
|
|
10
11
|
}
|
|
11
12
|
export declare const looks: Map<BodyId, BodyLook>, waiting: Set<() => void>, delegates: Map<BodyId, Delegate>;
|
|
13
|
+
/** Stars registered by name. A copy of the package from before stars had no table, so one is added to it. */
|
|
14
|
+
export declare const stars: Map<string, StarLook>;
|
|
12
15
|
/** Call `wake` whenever a look is registered; returns a function that stops it. */
|
|
13
16
|
export declare function onRegister(wake: () => void): () => void;
|
package/dist/scene/store.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const KEY = Symbol.for("johnmorrisdotca.wakusei-planets.looks");
|
|
2
|
-
const store = (globalThis[KEY] ??= { looks: new Map(), waiting: new Set(), delegates: new Map() });
|
|
2
|
+
const store = (globalThis[KEY] ??= { looks: new Map(), stars: new Map(), waiting: new Set(), delegates: new Map() });
|
|
3
3
|
export const { looks, waiting, delegates } = store;
|
|
4
|
+
/** Stars registered by name. A copy of the package from before stars had no table, so one is added to it. */
|
|
5
|
+
export const stars = (store.stars ??= new Map());
|
|
4
6
|
/** Call `wake` whenever a look is registered; returns a function that stops it. */
|
|
5
7
|
export function onRegister(wake) {
|
|
6
8
|
waiting.add(wake);
|
package/dist/scene/textures.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type * as THREE from "three";
|
|
|
9
9
|
* console.log(TEXTURE_BASE);
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
|
-
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.
|
|
12
|
+
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.26.0/dist/textures/";
|
|
13
13
|
/**
|
|
14
14
|
* Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
|
|
15
15
|
* never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
|
|
@@ -21,7 +21,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
|
|
|
21
21
|
* console.log(TEXTURE_FAR_BASE);
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.
|
|
24
|
+
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.26.0/textures/";
|
|
25
25
|
export declare const slash: (base: string) => string;
|
|
26
26
|
export declare function texturePaths(element: Element): {
|
|
27
27
|
textureBase(): string;
|
package/dist/space/element.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
137
137
|
get light(): SpaceLight;
|
|
138
138
|
set light(value: SpaceLight);
|
|
139
139
|
/**
|
|
140
|
-
* The shared controls' camera: yaw and tilt turn the view (the Earth's surface moves right for a drag right and up for a drag up), zoom brings the camera in (1 shows the body looked at, less shows the sky round it)
|
|
140
|
+
* The shared controls' camera: yaw and tilt turn the view (the Earth's surface moves right for a drag right and up for a drag up), zoom brings the camera in (1 shows the body looked at, less shows the sky round it), `roll` (degrees) turns the picture clockwise about the line of sight, and `panX` and `panY` move everything in the picture by exactly that many CSS pixels (right and down are positive). A turn that
|
|
141
141
|
* moves nothing on the screen by half a pixel is kept for the next draw but does not cause one unless `final` is true (the default).
|
|
142
142
|
*
|
|
143
143
|
* @param view - The controls' yaw and tilt in degrees and zoom.
|
|
@@ -147,6 +147,9 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
147
147
|
yaw: number;
|
|
148
148
|
tilt: number;
|
|
149
149
|
zoom: number;
|
|
150
|
+
roll?: number;
|
|
151
|
+
panX?: number;
|
|
152
|
+
panY?: number;
|
|
150
153
|
}, final?: boolean): void;
|
|
151
154
|
/** The body the camera looks at (`earth`, `sun`, `moon`, `mercury` to `neptune`, `pluto`): at zoom 1 it fills the view; the yaw and tilt turn the camera round it. */
|
|
152
155
|
get body(): SpaceBody;
|
package/dist/space/element.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createPainter } from "../scene/painter.js";
|
|
|
5
5
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
6
6
|
import { texturePaths } from "../scene/textures.js";
|
|
7
7
|
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_PLANETS } from "./frame.js";
|
|
8
|
-
import {
|
|
8
|
+
import { moonDistance, placeBodies, radiusIn } from "./scale.js";
|
|
9
9
|
import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
10
10
|
export { setThreeLoader, SPACE_BODIES };
|
|
11
11
|
const readLight = (value) => (value === "lit" ? "lit" : "sun");
|
|
@@ -92,6 +92,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
92
92
|
this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
|
|
93
93
|
if (!this.hasAttribute("role"))
|
|
94
94
|
this.setAttribute("role", "img");
|
|
95
|
+
if (!this.hasAttribute("tabindex"))
|
|
96
|
+
this.setAttribute("tabindex", "0");
|
|
95
97
|
if (!this.hasAttribute("aria-label"))
|
|
96
98
|
this.setAttribute("aria-label", "The Earth, the Moon, the Sun and the planets in their places for the date shown");
|
|
97
99
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
@@ -241,7 +243,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
241
243
|
this.#gate?.request();
|
|
242
244
|
}
|
|
243
245
|
/**
|
|
244
|
-
* The shared controls' camera: yaw and tilt turn the view (the Earth's surface moves right for a drag right and up for a drag up), zoom brings the camera in (1 shows the body looked at, less shows the sky round it)
|
|
246
|
+
* The shared controls' camera: yaw and tilt turn the view (the Earth's surface moves right for a drag right and up for a drag up), zoom brings the camera in (1 shows the body looked at, less shows the sky round it), `roll` (degrees) turns the picture clockwise about the line of sight, and `panX` and `panY` move everything in the picture by exactly that many CSS pixels (right and down are positive). A turn that
|
|
245
247
|
* moves nothing on the screen by half a pixel is kept for the next draw but does not cause one unless `final` is true (the default).
|
|
246
248
|
*
|
|
247
249
|
* @param view - The controls' yaw and tilt in degrees and zoom.
|
|
@@ -249,14 +251,15 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
249
251
|
*/
|
|
250
252
|
setView(view, final = true) {
|
|
251
253
|
const now = this.#model.view;
|
|
252
|
-
|
|
254
|
+
const [roll, panX, panY] = [view.roll ?? 0, view.panX ?? 0, view.panY ?? 0];
|
|
255
|
+
if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom && roll === now.roll && panX === now.panX && panY === now.panY)
|
|
253
256
|
return;
|
|
254
|
-
this.#model.view = { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom };
|
|
255
|
-
this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom } }));
|
|
257
|
+
this.#model.view = { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom, roll, panX, panY };
|
|
258
|
+
this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom, roll, panX, panY } }));
|
|
256
259
|
const drawn = this.#model.drawnView;
|
|
257
260
|
if (drawn && !final && view.zoom === drawn.zoom) {
|
|
258
|
-
const turned = Math.max(Math.abs(view.yaw - drawn.yaw), Math.abs(view.tilt - drawn.tilt)) * RAD;
|
|
259
|
-
if (turned * (this.#model.heightPx / 2) < 0.5)
|
|
261
|
+
const turned = Math.max(Math.abs(view.yaw - drawn.yaw), Math.abs(view.tilt - drawn.tilt), Math.abs(roll - drawn.roll)) * RAD;
|
|
262
|
+
if (turned * (this.#model.heightPx / 2) < 0.5 && Math.max(Math.abs(panX - drawn.panX), Math.abs(panY - drawn.panY)) < 0.5)
|
|
260
263
|
return;
|
|
261
264
|
}
|
|
262
265
|
this.#gate?.request();
|
|
@@ -367,19 +370,19 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
367
370
|
if (preset.endsWith("-moons")) {
|
|
368
371
|
const id = preset.slice(0, -6);
|
|
369
372
|
const sites = this.#painterNow().moons(id, this.#model.time);
|
|
370
|
-
const reach = Math.max(1, ...sites.map((site) => Math.hypot(...site.offset)).filter((r) => r <= 22));
|
|
373
|
+
const reach = Math.max(1, ...sites.map((site) => moonDistance(mode, id, Math.hypot(...site.offset))).filter((r) => r <= 22));
|
|
371
374
|
const radius = radiusIn(id, mode);
|
|
372
375
|
return Math.min(1, (FIT_DISTANCE * radius) / ((reach * radius * 1.15) / Math.tan(17.5 * RAD)));
|
|
373
376
|
}
|
|
374
377
|
const frame = this.#model.drawn?.frame ?? frameAt(this.#model.time);
|
|
375
|
-
const
|
|
376
|
-
const
|
|
378
|
+
const places = placeBodies(mode, frame);
|
|
379
|
+
const away = (id) => Math.hypot(...places[id]);
|
|
377
380
|
const reach = {
|
|
378
381
|
earth: 0,
|
|
379
|
-
moon:
|
|
380
|
-
sun:
|
|
381
|
-
inner: Math.max(
|
|
382
|
-
"solar-system": Math.max(...SPACE_PLANETS.map(
|
|
382
|
+
moon: away("moon"),
|
|
383
|
+
sun: away("sun"),
|
|
384
|
+
inner: Math.max(away("mercury"), away("venus"), away("mars"), away("sun")),
|
|
385
|
+
"solar-system": Math.max(...SPACE_PLANETS.map(away), away("sun")),
|
|
383
386
|
}[preset];
|
|
384
387
|
return preset === "earth" ? 1 : FIT_DISTANCE / Math.max(FIT_DISTANCE, reach * 3.4);
|
|
385
388
|
}
|
package/dist/space/frame.d.ts
CHANGED
|
@@ -134,9 +134,9 @@ export declare function createTrack(initialStepMs?: number): {
|
|
|
134
134
|
setStep(ms: number): void;
|
|
135
135
|
};
|
|
136
136
|
/**
|
|
137
|
-
* The path a planet takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
|
|
137
|
+
* The path a planet or the Earth takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
|
|
138
138
|
*
|
|
139
|
-
* @param id - The planet
|
|
139
|
+
* @param id - The planet or `earth`.
|
|
140
140
|
* @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
|
|
141
141
|
* @param count - How many segments to cut the trip into.
|
|
142
142
|
* @returns `count + 1` points; the last is near the first.
|
|
@@ -149,4 +149,4 @@ export declare function createTrack(initialStepMs?: number): {
|
|
|
149
149
|
* console.log(points.length);
|
|
150
150
|
* ```
|
|
151
151
|
*/
|
|
152
|
-
export declare function planetOrbit(id: SpacePlanet, ms: number, count?: number): Vec3[];
|
|
152
|
+
export declare function planetOrbit(id: SpacePlanet | "earth", ms: number, count?: number): Vec3[];
|
package/dist/space/frame.js
CHANGED
|
@@ -144,11 +144,11 @@ export function createTrack(initialStepMs = 1000) {
|
|
|
144
144
|
},
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
const PERIOD_DAYS = { mercury: 87.97, venus: 224.7, mars: 686.98, jupiter: 4332.6, saturn: 10_759, uranus: 30_688, neptune: 60_182, pluto: 90_560 };
|
|
147
|
+
const PERIOD_DAYS = { mercury: 87.97, venus: 224.7, earth: 365.256, mars: 686.98, jupiter: 4332.6, saturn: 10_759, uranus: 30_688, neptune: 60_182, pluto: 90_560 };
|
|
148
148
|
/**
|
|
149
|
-
* The path a planet takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
|
|
149
|
+
* The path a planet or the Earth takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
|
|
150
150
|
*
|
|
151
|
-
* @param id - The planet
|
|
151
|
+
* @param id - The planet or `earth`.
|
|
152
152
|
* @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
|
|
153
153
|
* @param count - How many segments to cut the trip into.
|
|
154
154
|
* @returns `count + 1` points; the last is near the first.
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, planetOrbit, SPACE_PLANETS, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
2
|
-
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
2
|
+
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { groundDirection } from "./aim.ts";
|
|
4
4
|
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The space view's pure parts: where the bodies are (this package's own models), the two scales and, for riding along, where a camera looks. They import on a server. The element is `@johnmorrisdotca/wakusei-planets/space/element`.
|
|
2
2
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, planetOrbit, SPACE_PLANETS } from "./frame.js";
|
|
3
|
-
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
3
|
+
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
4
4
|
export { groundDirection } from "./aim.js";
|
|
5
5
|
export { RIDE_FOV, ridePose } from "./ride.js";
|
package/dist/space/scale.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Vec3 } from "../vec.ts";
|
|
2
|
-
import { type SpacePlanet } from "./frame.ts";
|
|
2
|
+
import { type SpaceFrame, type SpacePlanet } from "./frame.ts";
|
|
3
3
|
/**
|
|
4
4
|
* The scale the space view is drawn in: `compressed` squeezes the distances so the Moon, the Sun and Neptune fit one view, and `true` keeps the real ones.
|
|
5
5
|
*
|
|
@@ -13,7 +13,7 @@ import { type SpacePlanet } from "./frame.ts";
|
|
|
13
13
|
*/
|
|
14
14
|
export type ScaleMode = "compressed" | "true";
|
|
15
15
|
/**
|
|
16
|
-
* The Moon's distance in a compressed view, in Earth radii (the true one is about 60).
|
|
16
|
+
* The Moon's distance in a compressed view, in Earth radii (the true one is about 60). It is well inside the gap between the Earth's orbit and the next one in.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
@@ -22,9 +22,9 @@ export type ScaleMode = "compressed" | "true";
|
|
|
22
22
|
* console.log(MOON_COMPRESSED);
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare const MOON_COMPRESSED =
|
|
25
|
+
export declare const MOON_COMPRESSED = 3.5;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* One astronomical unit in a compressed view, in Earth radii (the true one is about 23,500): the Sun is this far from the Earth, and each planet's distance from the Sun is this times its distance in astronomical units to the power 0.45.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
@@ -33,7 +33,7 @@ export declare const MOON_COMPRESSED = 10;
|
|
|
33
33
|
* console.log(SUN_COMPRESSED);
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export declare const SUN_COMPRESSED =
|
|
36
|
+
export declare const SUN_COMPRESSED = 70;
|
|
37
37
|
/**
|
|
38
38
|
* A place in astronomical units from the Earth's centre, at true distance, in Earth radii.
|
|
39
39
|
*
|
|
@@ -78,7 +78,7 @@ export declare function compress(v: Vec3): Vec3;
|
|
|
78
78
|
*/
|
|
79
79
|
export declare const placeMoon: (mode: ScaleMode, geo: Vec3) => Vec3;
|
|
80
80
|
/**
|
|
81
|
-
* The Sun, from the Earth's centre
|
|
81
|
+
* The Sun, from the Earth's centre. In a compressed view it is in its real direction at the distance the Earth's orbit has from the Sun there, so the Earth lies on its own orbit.
|
|
82
82
|
*
|
|
83
83
|
* @param mode - The scale.
|
|
84
84
|
* @param geo - The Sun's place in astronomical units from the Earth's centre.
|
|
@@ -94,7 +94,7 @@ export declare const placeMoon: (mode: ScaleMode, geo: Vec3) => Vec3;
|
|
|
94
94
|
export declare function placeSun(mode: ScaleMode, geo: Vec3): Vec3;
|
|
95
95
|
/**
|
|
96
96
|
* A place `helio` astronomical units from the Sun (a planet, or a point on its orbit), round the Sun at `sun`. True: as it is. Compressed: the same direction from
|
|
97
|
-
* the Sun, at
|
|
97
|
+
* the Sun, at `SUN_COMPRESSED` Earth radii times its distance in astronomical units to the power 0.45, so Neptune's orbit is about 4.6 times the Earth's (30 times as far, really).
|
|
98
98
|
*
|
|
99
99
|
* @param mode - The scale.
|
|
100
100
|
* @param sun - Where the Sun is drawn, in Earth radii.
|
|
@@ -109,6 +109,7 @@ export declare function placeSun(mode: ScaleMode, geo: Vec3): Vec3;
|
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
111
|
export declare function placeAround(mode: ScaleMode, sun: Vec3, helio: Vec3): Vec3;
|
|
112
|
+
type BaseBody = "sun" | "earth" | "moon" | SpacePlanet;
|
|
112
113
|
/**
|
|
113
114
|
* A body's radius in Earth radii: the real one, or one large enough to see in a compressed view.
|
|
114
115
|
*
|
|
@@ -124,3 +125,55 @@ export declare function placeAround(mode: ScaleMode, sun: Vec3, helio: Vec3): Ve
|
|
|
124
125
|
* ```
|
|
125
126
|
*/
|
|
126
127
|
export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet, mode: ScaleMode): number;
|
|
128
|
+
/**
|
|
129
|
+
* How far from its planet a moon is drawn, in the planet's radii, when it is really `distance` radii away. True: as it is. Compressed: the same, until the farthest of the planet's moons would
|
|
130
|
+
* reach across the gap to the next planet's orbit; then every moon is drawn nearer, the farthest at about a third of the gap and the nearer ones in the order they are, so no moon's orbit crosses another planet's.
|
|
131
|
+
*
|
|
132
|
+
* @param mode - The scale.
|
|
133
|
+
* @param host - The planet or dwarf planet the moon goes round.
|
|
134
|
+
* @param distance - The moon's distance from the centre of the planet, in the planet's radii.
|
|
135
|
+
* @returns The distance to draw it at, in the planet's radii.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { moonDistance } from "@johnmorrisdotca/wakusei-planets/space";
|
|
140
|
+
*
|
|
141
|
+
* console.log(moonDistance("compressed", "neptune", 222).toFixed(1));
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function moonDistance(mode: ScaleMode, host: SpacePlanet, distance: number): number;
|
|
145
|
+
/**
|
|
146
|
+
* Where every body of the view is, in Earth radii from the Earth's centre, at one moment: the Earth at the centre, the Moon, the Sun and the planets. The same mapping places
|
|
147
|
+
* the bodies and the lines of their orbits (`orbitLine`), so a body is always on its own orbit.
|
|
148
|
+
*
|
|
149
|
+
* @param mode - The scale.
|
|
150
|
+
* @param frame - Where everything is, from `frameAt`.
|
|
151
|
+
* @returns The place of each body.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { frameAt, placeBodies } from "@johnmorrisdotca/wakusei-planets/space";
|
|
156
|
+
*
|
|
157
|
+
* const places = placeBodies("compressed", frameAt(Date.UTC(2026, 10, 2)));
|
|
158
|
+
* console.log(Object.keys(places).length);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function placeBodies(mode: ScaleMode, frame: SpaceFrame): Record<BaseBody, Vec3>;
|
|
162
|
+
/**
|
|
163
|
+
* The line of a body's orbit as the view draws it: the points from `planetOrbit` (astronomical units from the Sun) placed round the Sun at `sun` by the same mapping as the bodies.
|
|
164
|
+
*
|
|
165
|
+
* @param mode - The scale.
|
|
166
|
+
* @param sun - Where the Sun is drawn, from `placeSun` or `placeBodies`.
|
|
167
|
+
* @param points - The orbit, from `planetOrbit`.
|
|
168
|
+
* @returns The same points, in Earth radii from the Earth's centre.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { frameAt, orbitLine, placeSun, planetOrbit } from "@johnmorrisdotca/wakusei-planets/space";
|
|
173
|
+
*
|
|
174
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
175
|
+
* console.log(orbitLine("compressed", placeSun("compressed", frameAt(ms).sun), planetOrbit("earth", ms, 24)).length);
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare const orbitLine: (mode: ScaleMode, sun: Vec3, points: readonly Vec3[]) => Vec3[];
|
|
179
|
+
export {};
|