@johnmorrisdotca/wakusei-planets 0.20.0 → 0.21.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 +13 -0
- package/NOTICE.md +9 -0
- package/README.md +34 -4
- package/dist/bodies/earth.js +13 -5
- package/dist/calendar.js +7 -6
- package/dist/clock.js +5 -6
- package/dist/coordinates.d.ts +7 -12
- package/dist/coordinates.js +19 -18
- package/dist/craft/cassini.d.ts +1 -0
- package/dist/craft/cassini.js +1131 -0
- package/dist/craft/galileo.d.ts +1 -0
- package/dist/craft/galileo.js +224 -0
- package/dist/craft/juno.d.ts +1 -0
- package/dist/craft/juno.js +640 -0
- package/dist/craft/newhorizons.d.ts +1 -0
- package/dist/craft/newhorizons.js +18 -0
- package/dist/craft/parker.d.ts +1 -0
- package/dist/craft/parker.js +221 -0
- package/dist/craft/pioneer10.d.ts +1 -0
- package/dist/craft/pioneer10.js +24 -0
- package/dist/craft/pioneer11.d.ts +1 -0
- package/dist/craft/pioneer11.js +34 -0
- package/dist/craft/voyager1.d.ts +1 -0
- package/dist/craft/voyager1.js +28 -0
- package/dist/craft/voyager2.d.ts +1 -0
- package/dist/craft/voyager2.js +43 -0
- package/dist/craft/webb.d.ts +1 -0
- package/dist/craft/webb.js +28 -0
- package/dist/data/craft.d.ts +23 -0
- package/dist/data/craft.js +53 -0
- package/dist/data/stars.d.ts +4 -0
- package/dist/data/stars.js +5088 -0
- package/dist/element.d.ts +1 -23
- package/dist/element.js +74 -110
- package/dist/ephemeris.d.ts +20 -0
- package/dist/ephemeris.js +51 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/portrait/element.d.ts +1 -0
- package/dist/portrait/element.js +27 -39
- package/dist/scene/basis.d.ts +3 -0
- package/dist/scene/basis.js +4 -0
- package/dist/scene/body.d.ts +2 -4
- package/dist/scene/body.js +55 -67
- package/dist/scene/fallback.d.ts +4 -0
- package/dist/scene/fallback.js +5 -0
- package/dist/scene/painter.js +10 -23
- package/dist/scene/store.d.ts +2 -2
- package/dist/scene/textures.d.ts +30 -0
- package/dist/scene/textures.js +47 -0
- package/dist/sidereal.d.ts +4 -0
- package/dist/sidereal.js +15 -9
- package/dist/sky/engine.d.ts +6 -15
- package/dist/sky/engine.js +9 -38
- package/dist/sky/frames.d.ts +3 -0
- package/dist/sky/frames.js +26 -0
- package/dist/sky/types.d.ts +20 -0
- package/dist/sky/types.js +1 -0
- package/dist/space/aim.d.ts +18 -0
- package/dist/space/aim.js +28 -0
- package/dist/space/element.d.ts +212 -0
- package/dist/space/element.js +524 -0
- package/dist/space/frame.d.ts +152 -0
- package/dist/space/frame.js +169 -0
- package/dist/space/index.d.ts +4 -0
- package/dist/space/index.js +5 -0
- package/dist/space/ride.d.ts +89 -0
- package/dist/space/ride.js +58 -0
- package/dist/space/scale.d.ts +126 -0
- package/dist/space/scale.js +139 -0
- package/dist/space/scene.d.ts +189 -0
- package/dist/space/scene.js +422 -0
- package/dist/spacecraft-facts.d.ts +114 -0
- package/dist/spacecraft-facts.js +215 -0
- package/dist/spacecraft.d.ts +134 -0
- package/dist/spacecraft.js +198 -0
- package/dist/stars.d.ts +160 -0
- package/dist/stars.js +193 -0
- package/dist/suncalc.js +4 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/when.js +6 -11
- package/package.json +53 -4
package/dist/scene/body.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Item3D, Scene3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
2
2
|
import type * as THREE from "three";
|
|
3
3
|
import type { Pose } from "../ephemeris.ts";
|
|
4
|
-
import { type
|
|
5
|
-
|
|
4
|
+
import { type BodyId } from "../facts.ts";
|
|
5
|
+
export { fallbackLook } from "./fallback.ts";
|
|
6
6
|
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). */
|
|
7
7
|
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer">;
|
|
8
8
|
/** One moon in a system view: its place in planet radii (viewer's frame) and the points of its orbit, if they changed. */
|
|
@@ -58,8 +58,6 @@ export interface BodyItemOptions {
|
|
|
58
58
|
failed?: boolean;
|
|
59
59
|
}): void;
|
|
60
60
|
}
|
|
61
|
-
/** A body that has no registered look is still drawn: a lit ball in its mean colour. */
|
|
62
|
-
export declare function fallbackLook(facts: BodyFacts): BodyLook;
|
|
63
61
|
/**
|
|
64
62
|
* The shared-renderer item for a body: what `renderer.view(host, item)` shows. `state()` is read when the scene is built and `apply` moves it afterwards.
|
|
65
63
|
*
|
package/dist/scene/body.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { BODIES
|
|
1
|
+
import { BODIES } from "../facts.js";
|
|
2
2
|
import { cross } from "../vec.js";
|
|
3
3
|
import { BALL_FRAGMENT, bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, RING_FRAGMENT, RING_VERTEX, VERTEX } from "./glsl.js";
|
|
4
4
|
import { lookOf } from "./look.js";
|
|
5
|
+
import { fallbackLook } from "./fallback.js";
|
|
6
|
+
import { writeBasis } from "./basis.js";
|
|
7
|
+
import { loadImage } from "./textures.js";
|
|
5
8
|
import { ringStrip } from "./rings.js";
|
|
6
|
-
|
|
7
|
-
export function fallbackLook(facts) {
|
|
8
|
-
const c = [1, 3, 5].map((i) => (parseInt(facts.colour.slice(i, i + 2), 16) / 255).toFixed(3)).join(", ");
|
|
9
|
-
return { id: facts.id, surface: `vec4 surface(vec3 p) { float n = fbm(p * 5.0); return vec4(vec3(${c}) * (0.85 + 0.3 * n), 0.0); }` };
|
|
10
|
-
}
|
|
11
|
-
const col3 = (T, rgb) => new T.Vector3(rgb[0], rgb[1], rgb[2]);
|
|
12
|
-
const v3 = (T, v) => new T.Vector3(v[0], v[1], v[2]);
|
|
9
|
+
export { fallbackLook } from "./fallback.js";
|
|
13
10
|
function makeBodyMaterial(T, look, painted) {
|
|
14
11
|
const a = look.atmosphere;
|
|
15
12
|
return new T.ShaderMaterial({
|
|
@@ -21,7 +18,7 @@ function makeBodyMaterial(T, look, painted) {
|
|
|
21
18
|
uAmbient: { value: look.ambient ?? 0.04 },
|
|
22
19
|
uLimb: { value: look.limb ?? 0 },
|
|
23
20
|
uWrap: { value: look.wrap ?? (a === undefined ? 0.04 : 0.3) },
|
|
24
|
-
uAtmos: { value:
|
|
21
|
+
uAtmos: { value: new T.Vector3(...(a?.colour ?? [0, 0, 0])) },
|
|
25
22
|
uAtmosPow: { value: a?.power ?? 3 },
|
|
26
23
|
uRimBase: { value: 0.12 },
|
|
27
24
|
uEmissive: { value: look.emissive === true ? 1 : 0 },
|
|
@@ -35,11 +32,10 @@ function makeBodyMaterial(T, look, painted) {
|
|
|
35
32
|
});
|
|
36
33
|
}
|
|
37
34
|
/** Set an object's matrix from three axes (columns), without letting three.js overwrite it. */
|
|
38
|
-
function setBasis(
|
|
35
|
+
function setBasis(object, x, y, z, sx = 1, sy = 1, sz = 1) {
|
|
39
36
|
object.matrixAutoUpdate = false;
|
|
40
37
|
object.matrixWorldAutoUpdate = false;
|
|
41
|
-
object.
|
|
42
|
-
object.matrixWorld.copy(object.matrix);
|
|
38
|
+
object.matrixWorld.copy(writeBasis(object.matrix, x, y, z, sx, sy, sz));
|
|
43
39
|
}
|
|
44
40
|
/**
|
|
45
41
|
* The shared-renderer item for a body: what `renderer.view(host, item)` shows. `state()` is read when the scene is built and `apply` moves it afterwards.
|
|
@@ -58,6 +54,7 @@ export function createBodyItem(options) {
|
|
|
58
54
|
const geometry = assets.acquire("wk:sphere", () => new T.SphereGeometry(1, 128, 64), (g) => g.dispose());
|
|
59
55
|
const shader = assets.acquire(`wk:body:${options.id}:r`, () => makeBodyMaterial(T, look, false), (m) => m.dispose());
|
|
60
56
|
const paintedMaterial = wantPainted ? assets.acquire(`wk:body:${options.id}:p`, () => makeBodyMaterial(T, look, true), (m) => m.dispose()) : undefined;
|
|
57
|
+
const materials = paintedMaterial === undefined ? [shader] : [shader, paintedMaterial];
|
|
61
58
|
const baseWrap = look.wrap ?? (look.atmosphere === undefined ? 0.04 : 0.3);
|
|
62
59
|
const baseAmbient = look.ambient ?? 0.04;
|
|
63
60
|
const scene = new T.Scene();
|
|
@@ -67,17 +64,12 @@ export function createBodyItem(options) {
|
|
|
67
64
|
mesh.frustumCulled = false;
|
|
68
65
|
scene.add(mesh);
|
|
69
66
|
// rings: a picture of them when the look has one (painted), else the table's strip
|
|
70
|
-
const loadImage = (url) => new Promise((resolve, reject) => {
|
|
71
|
-
const loader = new T.TextureLoader();
|
|
72
|
-
loader.setCrossOrigin("anonymous");
|
|
73
|
-
loader.load(url, (t) => resolve(t), undefined, (e) => reject(e instanceof Error ? e : new Error("texture failed")));
|
|
74
|
-
});
|
|
75
67
|
const table = ringStrip(facts, 1024);
|
|
76
68
|
const photo = wantPainted && table !== null ? look.painted?.rings : undefined;
|
|
77
69
|
let photoTexture;
|
|
78
70
|
if (photo !== undefined) {
|
|
79
71
|
try {
|
|
80
|
-
photoTexture = await loadImage(`${options.textureBase()}${photo.map}-${photo.width}.webp`);
|
|
72
|
+
photoTexture = await loadImage(T, `${options.textureBase()}${photo.map}-${photo.width}.webp`);
|
|
81
73
|
}
|
|
82
74
|
catch {
|
|
83
75
|
photoTexture = undefined;
|
|
@@ -119,15 +111,16 @@ export function createBodyItem(options) {
|
|
|
119
111
|
uniforms: { uRingTex: { value: ringTexture }, uRingR: { value: new T.Vector2(ringInner, ringOuter) }, uLight: { value: new T.Vector3(0, 0, 1) }, uRingN: { value: new T.Vector3(0, 1, 0) } },
|
|
120
112
|
}), (m) => m.dispose());
|
|
121
113
|
// 0..pi is the +Y half. The basis maps local +Y onto +east.
|
|
122
|
-
const half = (key,
|
|
123
|
-
const geometry = assets.acquire(`wk:ring:${ringKey}:${key}`, () => new T.RingGeometry(ringInner, ringOuter, 128, 1,
|
|
114
|
+
const half = (key, depthTest) => {
|
|
115
|
+
const geometry = assets.acquire(`wk:ring:${ringKey}:${key}`, () => new T.RingGeometry(ringInner, ringOuter, 128, 1, 0, Math.PI), (g) => g.dispose());
|
|
124
116
|
const material = ringMaterial(key, depthTest);
|
|
125
117
|
const piece = new T.Mesh(geometry, material);
|
|
126
118
|
piece.frustumCulled = false;
|
|
119
|
+
piece.renderOrder = depthTest ? 1 : 2;
|
|
127
120
|
scene.add(piece);
|
|
128
121
|
return { mesh: piece, material };
|
|
129
122
|
};
|
|
130
|
-
ringHalves = [half("e",
|
|
123
|
+
ringHalves = [half("e", false), half("w", true)];
|
|
131
124
|
}
|
|
132
125
|
// the glow of a star
|
|
133
126
|
let glow;
|
|
@@ -146,6 +139,7 @@ export function createBodyItem(options) {
|
|
|
146
139
|
const orbitMaterial = new T.LineBasicMaterial({ color: 0x8fa1b8, transparent: true, opacity: 0.4 });
|
|
147
140
|
let viewWidth = width;
|
|
148
141
|
let viewHeight = height;
|
|
142
|
+
let aspect = viewWidth / Math.max(1, viewHeight);
|
|
149
143
|
// the picture
|
|
150
144
|
let textureWidth = 0;
|
|
151
145
|
let loading = false;
|
|
@@ -155,7 +149,7 @@ export function createBodyItem(options) {
|
|
|
155
149
|
let latest = options.state();
|
|
156
150
|
const loadTexture = (w) => {
|
|
157
151
|
const far = look.painted.far !== undefined && w >= look.painted.far;
|
|
158
|
-
return loadImage(`${far ? options.farBase() : options.textureBase()}${look.painted.map}-${w}.webp`);
|
|
152
|
+
return loadImage(T, `${far ? options.farBase() : options.textureBase()}${look.painted.map}-${w}.webp`);
|
|
159
153
|
};
|
|
160
154
|
const drop = (t) => {
|
|
161
155
|
t.dispose();
|
|
@@ -203,7 +197,7 @@ export function createBodyItem(options) {
|
|
|
203
197
|
const scaleX = ax ? ax[1] / mean : 1;
|
|
204
198
|
const scaleY = ax ? ax[2] / mean : 1 - facts.flattening;
|
|
205
199
|
const scaleZ = ax ? ax[0] / mean : 1;
|
|
206
|
-
setBasis(
|
|
200
|
+
setBasis(mesh, east, pole, meridian, scaleX, scaleY, scaleZ);
|
|
207
201
|
if (ringHalves !== undefined) {
|
|
208
202
|
const [near, far] = ringHalves;
|
|
209
203
|
// The camera sits on +Z. The ring's near direction is +Z laid onto the ring plane, and that half is drawn over the disc.
|
|
@@ -212,16 +206,11 @@ export function createBodyItem(options) {
|
|
|
212
206
|
const span = Math.hypot(zx, zy) || 1;
|
|
213
207
|
const toward = [(meridian[0] * zx + east[0] * zy) / span, (meridian[1] * zx + east[1] * zy) / span, (meridian[2] * zx + east[2] * zy) / span];
|
|
214
208
|
const across = cross(toward, pole);
|
|
215
|
-
setBasis(
|
|
216
|
-
setBasis(
|
|
217
|
-
near.mesh.renderOrder = 2;
|
|
218
|
-
far.mesh.renderOrder = 1;
|
|
219
|
-
near.material.depthTest = false;
|
|
220
|
-
far.material.depthTest = true;
|
|
209
|
+
setBasis(near.mesh, across, toward, pole);
|
|
210
|
+
setBasis(far.mesh, [-across[0], -across[1], -across[2]], [-toward[0], -toward[1], -toward[2]], pole);
|
|
221
211
|
}
|
|
222
212
|
};
|
|
223
213
|
const frame = (state) => {
|
|
224
|
-
const aspect = viewWidth / Math.max(1, viewHeight);
|
|
225
214
|
const half = state.extent / Math.max(0.05, state.zoom);
|
|
226
215
|
const halfW = aspect >= 1 ? half * aspect : half;
|
|
227
216
|
const halfH = aspect >= 1 ? half : half / aspect;
|
|
@@ -239,7 +228,7 @@ export function createBodyItem(options) {
|
|
|
239
228
|
return m;
|
|
240
229
|
const f = BODIES[id];
|
|
241
230
|
const c = [1, 3, 5].map((i) => parseInt(f.colour.slice(i, i + 2), 16) / 255);
|
|
242
|
-
const material = assets.acquire(`wk:ball:${id}`, () => new T.ShaderMaterial({ vertexShader: VERTEX, fragmentShader: BALL_FRAGMENT, uniforms: { uLight: { value: new T.Vector3(0, 0, 1) }, uColour: { value:
|
|
231
|
+
const material = assets.acquire(`wk:ball:${id}`, () => new T.ShaderMaterial({ vertexShader: VERTEX, fragmentShader: BALL_FRAGMENT, uniforms: { uLight: { value: new T.Vector3(0, 0, 1) }, uColour: { value: new T.Vector3(c[0], c[1], c[2]) } } }), (x) => x.dispose());
|
|
243
232
|
m = new T.Mesh(geometry, material);
|
|
244
233
|
m.frustumCulled = false;
|
|
245
234
|
moonMeshes.set(id, m);
|
|
@@ -248,7 +237,6 @@ export function createBodyItem(options) {
|
|
|
248
237
|
};
|
|
249
238
|
const place = (state) => {
|
|
250
239
|
const moons = state.moons ?? [];
|
|
251
|
-
const aspect = viewWidth / Math.max(1, viewHeight);
|
|
252
240
|
const half = state.extent / Math.max(0.05, state.zoom);
|
|
253
241
|
const unitsPerPx = (2 * half) / Math.max(1, aspect >= 1 ? viewHeight : viewWidth);
|
|
254
242
|
const minR = (state.minMoonPx ?? 2.5) * unitsPerPx;
|
|
@@ -273,7 +261,7 @@ export function createBodyItem(options) {
|
|
|
273
261
|
mesh2.updateMatrix();
|
|
274
262
|
mesh2.updateMatrixWorld(true);
|
|
275
263
|
const mat = mesh2.material;
|
|
276
|
-
mat.uniforms.uLight.value.
|
|
264
|
+
mat.uniforms.uLight.value.set(...state.pose.light);
|
|
277
265
|
if (moon.orbit !== undefined) {
|
|
278
266
|
const held = orbitLines.get(moon.id);
|
|
279
267
|
if (held === undefined || held.source !== moon.orbit) {
|
|
@@ -293,41 +281,9 @@ export function createBodyItem(options) {
|
|
|
293
281
|
if (state.orbitColour !== undefined)
|
|
294
282
|
orbitMaterial.color.set(state.orbitColour);
|
|
295
283
|
};
|
|
296
|
-
const
|
|
297
|
-
latest = state;
|
|
298
|
-
orient(state);
|
|
299
|
-
frame(state);
|
|
300
|
-
place(state);
|
|
301
|
-
if (ringHalves !== undefined) {
|
|
302
|
-
const light = v3(T, state.pose.light);
|
|
303
|
-
const pole = v3(T, state.pose.pole);
|
|
304
|
-
for (const piece of ringHalves) {
|
|
305
|
-
piece.material.uniforms.uLight.value.copy(light);
|
|
306
|
-
piece.material.uniforms.uRingN.value.copy(pole);
|
|
307
|
-
}
|
|
308
|
-
for (const mat of [shader, paintedMaterial]) {
|
|
309
|
-
if (mat === undefined)
|
|
310
|
-
continue;
|
|
311
|
-
mat.uniforms.uRingOn.value = 1;
|
|
312
|
-
mat.uniforms.uRingN.value.copy(pole);
|
|
313
|
-
mat.uniforms.uRingR.value.set(ringInner, ringOuter);
|
|
314
|
-
mat.uniforms.uRingTex.value = ringTexture;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
for (const mat of [shader, paintedMaterial]) {
|
|
318
|
-
if (mat === undefined)
|
|
319
|
-
continue;
|
|
320
|
-
mat.uniforms.uLight.value.copy(v3(T, state.pose.light));
|
|
321
|
-
const sky = state.sky === true;
|
|
322
|
-
mat.uniforms.uWrap.value = sky ? 0.02 : (mat === paintedMaterial ? baseWrap : baseWrap);
|
|
323
|
-
mat.uniforms.uAmbient.value = sky ? 0.012 : baseAmbient;
|
|
324
|
-
mat.uniforms.uRimBase.value = sky ? 0.02 : 0.12;
|
|
325
|
-
}
|
|
326
|
-
if (glow !== undefined)
|
|
327
|
-
glow.scale.setScalar(1);
|
|
284
|
+
const requestSharperTexture = (state) => {
|
|
328
285
|
// a sharper picture, when the disc is big enough to show it
|
|
329
286
|
if (wantPainted && !failed && !loading && look.painted !== undefined) {
|
|
330
|
-
const aspect = viewWidth / Math.max(1, viewHeight);
|
|
331
287
|
const discPx = (aspect >= 1 ? viewHeight : viewWidth) * (state.zoom / state.extent);
|
|
332
288
|
const wanted = options.wantedWidth(discPx);
|
|
333
289
|
const next = look.painted.widths.find((w) => w >= wanted) ?? look.painted.widths[look.painted.widths.length - 1];
|
|
@@ -348,8 +304,39 @@ export function createBodyItem(options) {
|
|
|
348
304
|
}
|
|
349
305
|
}
|
|
350
306
|
};
|
|
307
|
+
const light = new T.Vector3();
|
|
308
|
+
const pole = new T.Vector3();
|
|
309
|
+
const apply = (state) => {
|
|
310
|
+
latest = state;
|
|
311
|
+
orient(state);
|
|
312
|
+
frame(state);
|
|
313
|
+
place(state);
|
|
314
|
+
light.set(...state.pose.light);
|
|
315
|
+
if (ringHalves !== undefined) {
|
|
316
|
+
pole.set(...state.pose.pole);
|
|
317
|
+
for (const piece of ringHalves) {
|
|
318
|
+
piece.material.uniforms.uLight.value.copy(light);
|
|
319
|
+
piece.material.uniforms.uRingN.value.copy(pole);
|
|
320
|
+
}
|
|
321
|
+
for (const mat of materials) {
|
|
322
|
+
mat.uniforms.uRingOn.value = 1;
|
|
323
|
+
mat.uniforms.uRingN.value.copy(pole);
|
|
324
|
+
mat.uniforms.uRingR.value.set(ringInner, ringOuter);
|
|
325
|
+
mat.uniforms.uRingTex.value = ringTexture;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const sky = state.sky === true;
|
|
329
|
+
for (const mat of materials) {
|
|
330
|
+
mat.uniforms.uLight.value.copy(light);
|
|
331
|
+
mat.uniforms.uWrap.value = sky ? 0.02 : baseWrap;
|
|
332
|
+
mat.uniforms.uAmbient.value = sky ? 0.012 : baseAmbient;
|
|
333
|
+
mat.uniforms.uRimBase.value = sky ? 0.02 : 0.12;
|
|
334
|
+
}
|
|
335
|
+
if (glow !== undefined)
|
|
336
|
+
glow.scale.setScalar(1);
|
|
337
|
+
requestSharperTexture(state);
|
|
338
|
+
};
|
|
351
339
|
apply(latest);
|
|
352
|
-
void ringReach;
|
|
353
340
|
return {
|
|
354
341
|
scene,
|
|
355
342
|
camera,
|
|
@@ -363,6 +350,7 @@ export function createBodyItem(options) {
|
|
|
363
350
|
resize(w, h) {
|
|
364
351
|
viewWidth = w;
|
|
365
352
|
viewHeight = h;
|
|
353
|
+
aspect = viewWidth / Math.max(1, viewHeight);
|
|
366
354
|
frame(latest);
|
|
367
355
|
place(latest);
|
|
368
356
|
},
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** A body that has no registered look is still drawn: a lit ball in its mean colour. */
|
|
2
|
+
export function fallbackLook(facts) {
|
|
3
|
+
const c = [1, 3, 5].map((i) => (parseInt(facts.colour.slice(i, i + 2), 16) / 255).toFixed(3)).join(", ");
|
|
4
|
+
return { id: facts.id, surface: `vec4 surface(vec3 p) { float n = fbm(p * 5.0); return vec4(vec3(${c}) * (0.85 + 0.3 * n), 0.0); }` };
|
|
5
|
+
}
|
package/dist/scene/painter.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import "../bodies/all.js";
|
|
2
2
|
import { BODIES, MOONS_OF } from "../facts.js";
|
|
3
|
-
import {
|
|
3
|
+
import { writeBasis } from "./basis.js";
|
|
4
|
+
import { TEXTURE_BASE, TEXTURE_FAR_BASE, slash, loadImage } from "./textures.js";
|
|
4
5
|
import { cross } from "../vec.js";
|
|
5
6
|
import { bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, RING_FRAGMENT_WORLD, RING_VERTEX_WORLD, VERTEX_WORLD } from "./glsl.js";
|
|
7
|
+
import { fallbackLook } from "./fallback.js";
|
|
6
8
|
import { lookOf } from "./look.js";
|
|
7
9
|
import { moonOffset, orientation } from "./orient.js";
|
|
8
10
|
import { ringStrip } from "./rings.js";
|
|
@@ -19,9 +21,6 @@ export { moonOffset, orientation };
|
|
|
19
21
|
* ```
|
|
20
22
|
*/
|
|
21
23
|
export const LOOKS = ["realistic", "painted"];
|
|
22
|
-
const TEXTURE_BASE = `https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@${VERSION}/dist/textures/`;
|
|
23
|
-
const TEXTURE_FAR_BASE = `https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v${VERSION}/textures/`;
|
|
24
|
-
const slash = (base) => (base.endsWith("/") ? base : `${base}/`);
|
|
25
24
|
const titled = (id) => id.charAt(0).toUpperCase() + id.slice(1);
|
|
26
25
|
const pools = new WeakMap();
|
|
27
26
|
function acquire(three, key, make) {
|
|
@@ -49,10 +48,6 @@ function acquire(three, key, make) {
|
|
|
49
48
|
},
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
|
-
const fallbackLook = (id) => {
|
|
53
|
-
const c = [1, 3, 5].map((i) => (parseInt(BODIES[id].colour.slice(i, i + 2), 16) / 255).toFixed(3)).join(", ");
|
|
54
|
-
return { id, surface: `vec4 surface(vec3 p) { float n = fbm(p * 5.0); return vec4(vec3(${c}) * (0.85 + 0.3 * n), 0.0); }` };
|
|
55
|
-
};
|
|
56
51
|
/** The name of a body as the painter takes it: any case, `Sun`, a planet or Pluto, or a moon such as `Io`. */
|
|
57
52
|
function idOf(name) {
|
|
58
53
|
const id = name.toLowerCase();
|
|
@@ -66,7 +61,7 @@ const moonsOf = (planet) => {
|
|
|
66
61
|
};
|
|
67
62
|
function paint(T, id, context, bases) {
|
|
68
63
|
const facts = BODIES[id];
|
|
69
|
-
const look = lookOf(id) ?? fallbackLook(
|
|
64
|
+
const look = lookOf(id) ?? fallbackLook(facts);
|
|
70
65
|
const wantPainted = (context.look === "painted" || look.mapped === true) && look.painted !== undefined;
|
|
71
66
|
const ratio = context.ratio ?? 1;
|
|
72
67
|
const maxWidth = context.maxTexture ?? 2048;
|
|
@@ -106,7 +101,7 @@ function paint(T, id, context, bases) {
|
|
|
106
101
|
};
|
|
107
102
|
const shader = material(false);
|
|
108
103
|
const paintedMaterial = wantPainted ? material(true) : undefined;
|
|
109
|
-
const materials =
|
|
104
|
+
const materials = paintedMaterial ? [shader, paintedMaterial] : [shader];
|
|
110
105
|
const mesh = new T.Mesh(sphere.value, shader);
|
|
111
106
|
mesh.matrixAutoUpdate = false;
|
|
112
107
|
group.add(mesh);
|
|
@@ -117,11 +112,6 @@ function paint(T, id, context, bases) {
|
|
|
117
112
|
let ringInner = 1;
|
|
118
113
|
let ringOuter = 2;
|
|
119
114
|
const table = look.emissive === true ? null : ringStrip(facts, 1024);
|
|
120
|
-
const loadImage = (url) => new Promise((resolve, reject) => {
|
|
121
|
-
const loader = new T.TextureLoader();
|
|
122
|
-
loader.setCrossOrigin("anonymous");
|
|
123
|
-
loader.load(url, resolve, undefined, (e) => reject(e instanceof Error ? e : new Error("texture failed")));
|
|
124
|
-
});
|
|
125
115
|
let gone = false;
|
|
126
116
|
if (table !== null) {
|
|
127
117
|
ringInner = table.inner;
|
|
@@ -150,7 +140,7 @@ function paint(T, id, context, bases) {
|
|
|
150
140
|
group.add(ringMesh);
|
|
151
141
|
const photo = wantPainted ? look.painted?.rings : undefined;
|
|
152
142
|
if (photo !== undefined) {
|
|
153
|
-
void loadImage(`${bases.near}${photo.map}-${photo.width}.webp`).then((t) => {
|
|
143
|
+
void loadImage(T, `${bases.near}${photo.map}-${photo.width}.webp`).then((t) => {
|
|
154
144
|
if (gone) {
|
|
155
145
|
t.dispose();
|
|
156
146
|
return;
|
|
@@ -217,7 +207,7 @@ function paint(T, id, context, bases) {
|
|
|
217
207
|
redraw();
|
|
218
208
|
};
|
|
219
209
|
if (wantPainted && paintedMaterial !== undefined && widths[0] !== undefined) {
|
|
220
|
-
void loadImage(urlOf(widths[0])).then((t) => {
|
|
210
|
+
void loadImage(T, urlOf(widths[0])).then((t) => {
|
|
221
211
|
if (gone) {
|
|
222
212
|
t.dispose();
|
|
223
213
|
return;
|
|
@@ -237,7 +227,7 @@ function paint(T, id, context, bases) {
|
|
|
237
227
|
if (next > sharpWidth && next > widths[0] && !tried.has(next)) {
|
|
238
228
|
tried.add(next);
|
|
239
229
|
loading = true;
|
|
240
|
-
void loadImage(urlOf(next)).then((t) => {
|
|
230
|
+
void loadImage(T, urlOf(next)).then((t) => {
|
|
241
231
|
loading = false;
|
|
242
232
|
if (gone) {
|
|
243
233
|
t.dispose();
|
|
@@ -273,9 +263,6 @@ function paint(T, id, context, bases) {
|
|
|
273
263
|
const scaleX = axes ? axes[1] / facts.radiusKm : 1;
|
|
274
264
|
const scaleY = axes ? axes[2] / facts.radiusKm : 1 - facts.flattening;
|
|
275
265
|
const scaleZ = axes ? axes[0] / facts.radiusKm : 1;
|
|
276
|
-
const basis = (object, x, y, z, sx = 1, sy = 1, sz = 1) => {
|
|
277
|
-
object.matrix.makeBasis(new T.Vector3(x[0] * sx, x[1] * sx, x[2] * sx), new T.Vector3(y[0] * sy, y[1] * sy, y[2] * sy), new T.Vector3(z[0] * sz, z[1] * sz, z[2] * sz));
|
|
278
|
-
};
|
|
279
266
|
const light = new T.Vector3();
|
|
280
267
|
const poleVec = new T.Vector3();
|
|
281
268
|
return {
|
|
@@ -287,9 +274,9 @@ function paint(T, id, context, bases) {
|
|
|
287
274
|
if (look.emissive !== true) {
|
|
288
275
|
const { pole, meridian } = info.pose ?? orientation(id, info.ms);
|
|
289
276
|
const east = cross(pole, meridian);
|
|
290
|
-
|
|
277
|
+
writeBasis(mesh.matrix, east, pole, meridian, scaleX, scaleY, scaleZ);
|
|
291
278
|
if (ringMesh !== undefined)
|
|
292
|
-
|
|
279
|
+
writeBasis(ringMesh.matrix, meridian, east, pole);
|
|
293
280
|
poleVec.set(pole[0], pole[1], pole[2]);
|
|
294
281
|
}
|
|
295
282
|
const occluders = info.occluders ?? [];
|
package/dist/scene/store.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { BodyId } from "../facts.ts";
|
|
|
2
2
|
import type { BodyLook } from "./look.ts";
|
|
3
3
|
/** 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
4
|
export interface Delegate {
|
|
5
|
-
/** The line look: an element for the body, centred on a longitude and latitude (`"lon,lat"`). */
|
|
5
|
+
/** The line look: an element for the body, centred on a longitude and latitude (`"lon,lat"`), or null when the other package is not on the page and this one draws its own. */
|
|
6
6
|
line(options: {
|
|
7
7
|
center: string;
|
|
8
8
|
size: number;
|
|
9
|
-
}): Promise<HTMLElement>;
|
|
9
|
+
}): Promise<HTMLElement | null>;
|
|
10
10
|
}
|
|
11
11
|
export declare const looks: Map<BodyId, BodyLook>, waiting: Set<() => void>, delegates: Map<BodyId, Delegate>;
|
|
12
12
|
/** Call `wake` whenever a look is registered; returns a function that stops it. */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
/**
|
|
3
|
+
* The default home of the surface pictures: the files of this exact version on jsDelivr. Set `texture-base` on an element to serve them yourself.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts no-run
|
|
7
|
+
* import { TEXTURE_BASE } from "@johnmorrisdotca/wakusei-planets/element";
|
|
8
|
+
*
|
|
9
|
+
* console.log(TEXTURE_BASE);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.21.0/dist/textures/";
|
|
13
|
+
/**
|
|
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
|
+
* never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts no-run
|
|
19
|
+
* import { TEXTURE_FAR_BASE } from "@johnmorrisdotca/wakusei-planets/element";
|
|
20
|
+
*
|
|
21
|
+
* console.log(TEXTURE_FAR_BASE);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.21.0/textures/";
|
|
25
|
+
export declare const slash: (base: string) => string;
|
|
26
|
+
export declare function texturePaths(element: Element): {
|
|
27
|
+
textureBase(): string;
|
|
28
|
+
farBase(): string;
|
|
29
|
+
};
|
|
30
|
+
export declare function loadImage(three: Pick<typeof THREE, "TextureLoader">, url: string): Promise<THREE.Texture>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { VERSION } from "../version.js";
|
|
2
|
+
/**
|
|
3
|
+
* The default home of the surface pictures: the files of this exact version on jsDelivr. Set `texture-base` on an element to serve them yourself.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts no-run
|
|
7
|
+
* import { TEXTURE_BASE } from "@johnmorrisdotca/wakusei-planets/element";
|
|
8
|
+
*
|
|
9
|
+
* console.log(TEXTURE_BASE);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const TEXTURE_BASE = `https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@${VERSION}/dist/textures/`;
|
|
13
|
+
/**
|
|
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
|
+
* never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts no-run
|
|
19
|
+
* import { TEXTURE_FAR_BASE } from "@johnmorrisdotca/wakusei-planets/element";
|
|
20
|
+
*
|
|
21
|
+
* console.log(TEXTURE_FAR_BASE);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const TEXTURE_FAR_BASE = `https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v${VERSION}/textures/`;
|
|
25
|
+
export const slash = (base) => (base.endsWith("/") ? base : `${base}/`);
|
|
26
|
+
export function texturePaths(element) {
|
|
27
|
+
const textureBase = () => {
|
|
28
|
+
const own = element.getAttribute("texture-base");
|
|
29
|
+
return own === null || own === "" ? TEXTURE_BASE : slash(own);
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
textureBase,
|
|
33
|
+
farBase: () => {
|
|
34
|
+
const own = element.getAttribute("texture-far-base");
|
|
35
|
+
if (own !== null && own !== "")
|
|
36
|
+
return slash(own);
|
|
37
|
+
return element.hasAttribute("texture-base") ? textureBase() : TEXTURE_FAR_BASE;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function loadImage(three, url) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const loader = new three.TextureLoader();
|
|
44
|
+
loader.setCrossOrigin("anonymous");
|
|
45
|
+
loader.load(url, resolve, undefined, (error) => reject(error instanceof Error ? error : new Error("texture failed")));
|
|
46
|
+
});
|
|
47
|
+
}
|
package/dist/sidereal.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type When } from "./when.ts";
|
|
2
|
+
/** IAU 1980 mean obliquity, in arcseconds, at TT Julian centuries from J2000. */
|
|
3
|
+
export declare const meanObliquityArcseconds: (T: number) => number;
|
|
4
|
+
/** Unwrapped IAU 1982 Greenwich mean sidereal angle, in degrees, at UT1 days from J2000. */
|
|
5
|
+
export declare function meanSiderealDegrees(days: number): number;
|
|
2
6
|
/** Nutation in longitude and in obliquity, and the mean obliquity of date, in radians, at `T` Julian centuries of terrestrial time from J2000 (Meeus ch. 22, accurate to 0.5 arc-seconds). */
|
|
3
7
|
export declare function nutation(T: number): {
|
|
4
8
|
longitude: number;
|
package/dist/sidereal.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
// Sidereal time: the Earth's turn against the stars. Greenwich mean sidereal time (IAU 1982, Meeus ch. 12) from UT1, the equation of the equinoxes from the nutation (IAU 1980, its largest terms, 0.5 arc-seconds),
|
|
2
2
|
// the apparent time that adds it, and the local time at a longitude. Angles are degrees, 0 to 360 (15 degrees an hour). UT1 is UTC unless `dut1` is given, which is within 0.9 s of the Earth's turn (0.004 degrees). Pure: no DOM, no three.js.
|
|
3
|
-
import {
|
|
3
|
+
import { J2000_JD, julianCenturies, toJulianDate } from "./clock.js";
|
|
4
4
|
import { moment } from "./when.js";
|
|
5
5
|
const RAD = Math.PI / 180;
|
|
6
6
|
const ARCSEC = Math.PI / 648000;
|
|
7
|
+
/** IAU 1980 mean obliquity, in arcseconds, at TT Julian centuries from J2000. */
|
|
8
|
+
export const meanObliquityArcseconds = (T) => 84381.448 - 46.815 * T - 0.00059 * T * T + 0.001813 * T * T * T;
|
|
9
|
+
/** Unwrapped IAU 1982 Greenwich mean sidereal angle, in degrees, at UT1 days from J2000. */
|
|
10
|
+
export function meanSiderealDegrees(days) {
|
|
11
|
+
const T = days / 36525;
|
|
12
|
+
return 280.46061837 + 360.98564736629 * days + 0.000387933 * T * T - (T * T * T) / 38710000;
|
|
13
|
+
}
|
|
7
14
|
/** Nutation in longitude and in obliquity, and the mean obliquity of date, in radians, at `T` Julian centuries of terrestrial time from J2000 (Meeus ch. 22, accurate to 0.5 arc-seconds). */
|
|
8
15
|
export function nutation(T) {
|
|
9
16
|
const omega = (125.04452 - 1934.136261 * T) * RAD;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const longitude = (-17.2 * Math.sin(omega) - 1.32 * Math.sin(
|
|
13
|
-
const obliquity = (9.2 * Math.cos(omega) + 0.57 * Math.cos(
|
|
14
|
-
const meanObliquity = (
|
|
17
|
+
const twiceSunLongitude = (560.933 + 72001.5396 * T) * RAD;
|
|
18
|
+
const twiceMoonLongitude = (436.633 + 962535.7626 * T) * RAD;
|
|
19
|
+
const longitude = (-17.2 * Math.sin(omega) - 1.32 * Math.sin(twiceSunLongitude) - 0.23 * Math.sin(twiceMoonLongitude) + 0.21 * Math.sin(2 * omega)) * ARCSEC;
|
|
20
|
+
const obliquity = (9.2 * Math.cos(omega) + 0.57 * Math.cos(twiceSunLongitude) + 0.1 * Math.cos(twiceMoonLongitude) - 0.09 * Math.cos(2 * omega)) * ARCSEC;
|
|
21
|
+
const meanObliquity = meanObliquityArcseconds(T) * ARCSEC;
|
|
15
22
|
return { longitude, obliquity, meanObliquity };
|
|
16
23
|
}
|
|
17
24
|
const wrap = (degrees) => ((degrees % 360) + 360) % 360;
|
|
@@ -30,8 +37,7 @@ const wrap = (degrees) => ((degrees % 360) + 360) % 360;
|
|
|
30
37
|
*/
|
|
31
38
|
export function greenwichMeanSiderealTime(when, dut1 = 0) {
|
|
32
39
|
const jd = toJulianDate(moment(when) + dut1 * 1000);
|
|
33
|
-
|
|
34
|
-
return wrap(280.46061837 + 360.98564736629 * (jd - J2000_JD) + 0.000387933 * T * T - (T * T * T) / 38710000);
|
|
40
|
+
return wrap(meanSiderealDegrees(jd - J2000_JD));
|
|
35
41
|
}
|
|
36
42
|
/**
|
|
37
43
|
* The equation of the equinoxes in degrees: the nutation in longitude times the cosine of the obliquity, what apparent sidereal time has over mean (about 1 second of time at most).
|
|
@@ -46,7 +52,7 @@ export function greenwichMeanSiderealTime(when, dut1 = 0) {
|
|
|
46
52
|
* ```
|
|
47
53
|
*/
|
|
48
54
|
export function equationOfTheEquinoxes(when) {
|
|
49
|
-
const T = (
|
|
55
|
+
const T = julianCenturies(when);
|
|
50
56
|
const n = nutation(T);
|
|
51
57
|
return (n.longitude * Math.cos(n.meanObliquity + n.obliquity)) / RAD;
|
|
52
58
|
}
|
package/dist/sky/engine.d.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
longitude: number;
|
|
5
|
-
heightM?: number;
|
|
6
|
-
}
|
|
1
|
+
import { greenwichApparentSiderealTime as greenwichSiderealTime } from "../sidereal.ts";
|
|
2
|
+
import type { EquatorialAngles, HorizontalAngles, Observer } from "./types.ts";
|
|
3
|
+
export type { Observer } from "./types.ts";
|
|
7
4
|
/** A body's place on the sky of date, as the Earth's centre sees it (apparent: light time, aberration for the Sun, nutation): angles in degrees, distance in kilometres. */
|
|
8
|
-
export interface Equatorial {
|
|
9
|
-
/** Right ascension of date, 0 to 360. */
|
|
10
|
-
rightAscension: number;
|
|
11
|
-
/** Declination of date, -90 to 90. */
|
|
12
|
-
declination: number;
|
|
5
|
+
export interface Equatorial extends EquatorialAngles {
|
|
13
6
|
distanceKm: number;
|
|
14
7
|
}
|
|
15
8
|
/** Where a body is in a place's sky: azimuth 0 to 360 from north through east, altitude, the hour angle (0 on the meridian, positive west) and the parallactic angle, all in degrees. */
|
|
16
|
-
export interface Horizontal {
|
|
17
|
-
azimuth: number;
|
|
18
|
-
altitude: number;
|
|
9
|
+
export interface Horizontal extends HorizontalAngles {
|
|
19
10
|
hourAngle: number;
|
|
20
11
|
parallacticAngle: number;
|
|
21
12
|
/** The distance from the place to the body in kilometres. */
|
|
@@ -26,7 +17,7 @@ export declare function sunEquatorial(ms: number): Equatorial;
|
|
|
26
17
|
/** The Moon as seen from the Earth's centre: the apparent place of date, with the light time (the Moon is about 1.3 seconds away) and nutation. */
|
|
27
18
|
export declare function moonEquatorial(ms: number): Equatorial;
|
|
28
19
|
/** The apparent sidereal time at Greenwich in degrees, from the UTC instant taken as UT1. */
|
|
29
|
-
export
|
|
20
|
+
export { greenwichSiderealTime };
|
|
30
21
|
/**
|
|
31
22
|
* Altitude, azimuth, hour angle and parallactic angle of a body for an observer: topocentric (parallax taken out of the Earth's centre to the place) and geometric, with no refraction.
|
|
32
23
|
* `ms` is the instant the observer's sky turns for; the body's place `equatorial` is its apparent place at that instant.
|