@johnmorrisdotca/wakusei-planets 0.19.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 +23 -0
- package/NOTICE.md +14 -3
- package/README.md +39 -6
- package/dist/bodies/earth.js +13 -5
- package/dist/calendar.d.ts +119 -0
- package/dist/calendar.js +155 -0
- package/dist/clock.d.ts +244 -0
- package/dist/clock.js +325 -0
- package/dist/coordinates.d.ts +172 -0
- package/dist/coordinates.js +170 -0
- 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/lunar.d.ts +4 -0
- package/dist/data/lunar.js +548 -0
- package/dist/data/pluto.d.ts +6 -0
- package/dist/data/pluto.js +29 -0
- package/dist/data/stars.d.ts +4 -0
- package/dist/data/stars.js +5088 -0
- package/dist/data/tables.d.ts +41 -0
- package/dist/data/tables.js +37 -0
- package/dist/data/vsop.d.ts +19 -1
- package/dist/data/vsop.js +25 -8
- package/dist/element.d.ts +2 -23
- package/dist/element.js +75 -110
- package/dist/ephemeris.d.ts +22 -14
- package/dist/ephemeris.js +106 -58
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mars.d.ts +41 -0
- package/dist/mars.js +52 -0
- package/dist/portrait/element.d.ts +1 -0
- package/dist/portrait/element.js +27 -39
- package/dist/scales.d.ts +46 -0
- package/dist/scales.js +75 -0
- 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 +70 -0
- package/dist/sidereal.js +94 -0
- package/dist/sky/engine.d.ts +37 -0
- package/dist/sky/engine.js +116 -0
- package/dist/sky/events.d.ts +37 -0
- package/dist/sky/events.js +133 -0
- 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-legacy.d.ts +187 -0
- package/dist/suncalc-legacy.js +168 -0
- package/dist/suncalc.d.ts +209 -0
- package/dist/suncalc.js +167 -0
- package/dist/tables/all.d.ts +2 -0
- package/dist/tables/all.js +2 -0
- package/dist/tables/ceres.d.ts +1 -0
- package/dist/tables/ceres.js +57 -0
- package/dist/tables/dwarfs.d.ts +1 -0
- package/dist/tables/dwarfs.js +59 -0
- package/dist/theory.d.ts +20 -0
- package/dist/theory.js +98 -0
- package/dist/time.d.ts +6 -108
- package/dist/time.js +7 -180
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/when.d.ts +16 -0
- package/dist/when.js +13 -0
- package/package.json +95 -4
package/dist/mars.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { When } from "./when.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The Mars Sol Date: the count of Martian days, as the Julian date counts Earth's. 44796.0 is about 2000-01-06 00:00 TT.
|
|
4
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
5
|
+
* @returns Sols, with the fraction of the sol.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { marsSolDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
10
|
+
*
|
|
11
|
+
* console.log(marsSolDate(Date.UTC(2021, 1, 18, 20, 55)).toFixed(3));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function marsSolDate(when: When): number;
|
|
15
|
+
/**
|
|
16
|
+
* Coordinated Mars Time: the mean solar time on Mars's prime meridian, in hours from 0 up to 24 (a Martian hour is 1/24 of a sol).
|
|
17
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
18
|
+
* @returns Hours.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { coordinatedMarsTime } from "@johnmorrisdotca/wakusei-planets/time";
|
|
23
|
+
*
|
|
24
|
+
* console.log(coordinatedMarsTime(Date.UTC(2021, 1, 18, 20, 55)).toFixed(2));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function coordinatedMarsTime(when: When): number;
|
|
28
|
+
/**
|
|
29
|
+
* The local mean solar time on Mars at a longitude east of its prime meridian, in hours from 0 up to 24.
|
|
30
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
31
|
+
* @param longitude - Degrees east (Jezero Crater is 77.45).
|
|
32
|
+
* @returns Hours.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { marsLocalMeanSolarTime } from "@johnmorrisdotca/wakusei-planets/time";
|
|
37
|
+
*
|
|
38
|
+
* console.log(marsLocalMeanSolarTime(Date.UTC(2021, 1, 18, 20, 55), 77.45).toFixed(1));
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function marsLocalMeanSolarTime(when: When, longitude: number): number;
|
package/dist/mars.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Mars time: the Mars Sol Date and Coordinated Mars Time of Allison and McEwen (2000, Planetary and Space Science 48, 215), from terrestrial time, and the local mean solar time at a longitude.
|
|
2
|
+
// A sol is 1.0274912517 days (88,775.244 seconds). Pure: no DOM, no three.js.
|
|
3
|
+
import { toJulianDate, toTerrestrialTime } from "./clock.js";
|
|
4
|
+
/**
|
|
5
|
+
* The Mars Sol Date: the count of Martian days, as the Julian date counts Earth's. 44796.0 is about 2000-01-06 00:00 TT.
|
|
6
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
7
|
+
* @returns Sols, with the fraction of the sol.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { marsSolDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
12
|
+
*
|
|
13
|
+
* console.log(marsSolDate(Date.UTC(2021, 1, 18, 20, 55)).toFixed(3));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function marsSolDate(when) {
|
|
17
|
+
return (toJulianDate(toTerrestrialTime(when)) - 2451549.5) / 1.0274912517 + 44796.0 - 0.0009626;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Coordinated Mars Time: the mean solar time on Mars's prime meridian, in hours from 0 up to 24 (a Martian hour is 1/24 of a sol).
|
|
21
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
22
|
+
* @returns Hours.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { coordinatedMarsTime } from "@johnmorrisdotca/wakusei-planets/time";
|
|
27
|
+
*
|
|
28
|
+
* console.log(coordinatedMarsTime(Date.UTC(2021, 1, 18, 20, 55)).toFixed(2));
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function coordinatedMarsTime(when) {
|
|
32
|
+
const sol = marsSolDate(when);
|
|
33
|
+
return (sol - Math.floor(sol)) * 24;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The local mean solar time on Mars at a longitude east of its prime meridian, in hours from 0 up to 24.
|
|
37
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
38
|
+
* @param longitude - Degrees east (Jezero Crater is 77.45).
|
|
39
|
+
* @returns Hours.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { marsLocalMeanSolarTime } from "@johnmorrisdotca/wakusei-planets/time";
|
|
44
|
+
*
|
|
45
|
+
* console.log(marsLocalMeanSolarTime(Date.UTC(2021, 1, 18, 20, 55), 77.45).toFixed(1));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function marsLocalMeanSolarTime(when, longitude) {
|
|
49
|
+
if (!Number.isFinite(longitude))
|
|
50
|
+
throw new RangeError(`longitude must be a finite number of degrees east, got ${longitude}`);
|
|
51
|
+
return (((coordinatedMarsTime(when) + longitude / 15) % 24) + 24) % 24;
|
|
52
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SharedRenderer } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
2
2
|
import type { ThreeParts } from "../scene/body.ts";
|
|
3
3
|
import { setThreeLoader } from "../scene/shared.ts";
|
|
4
|
+
import "../element.ts";
|
|
4
5
|
import { type Guide, type Placed, type Portrait, type Resolved } from "./model.ts";
|
|
5
6
|
export { setThreeLoader };
|
|
6
7
|
/**
|
package/dist/portrait/element.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BODIES } from "../facts.js";
|
|
2
2
|
import { createGate, frameCap } from "../gate.js";
|
|
3
3
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
4
|
-
|
|
4
|
+
// /portrait has always registered the body element as well.
|
|
5
|
+
import "../element.js";
|
|
6
|
+
import { texturePaths } from "../scene/textures.js";
|
|
5
7
|
import { backgroundCss, drawShapes, lineScene, paintBackground, shapesOf, shapesSvg, starfield } from "./overlay.js";
|
|
6
8
|
import { decodeScene, defaultPortrait, encodeScene, fromScreen, hitTest, resolve, toScreen } from "./model.js";
|
|
7
9
|
import { REDUCED_TURN } from "../live.js";
|
|
@@ -151,15 +153,8 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
151
153
|
this.#stopTick();
|
|
152
154
|
this.#io?.disconnect();
|
|
153
155
|
document.removeEventListener("visibilitychange", this.#onHidden);
|
|
154
|
-
this
|
|
155
|
-
this
|
|
156
|
-
this.removeEventListener("pointerdown", this.#hover);
|
|
157
|
-
this.#view?.dispose();
|
|
158
|
-
this.#view = undefined;
|
|
159
|
-
this.#viewKey = "";
|
|
160
|
-
this.#release?.();
|
|
161
|
-
this.#release = undefined;
|
|
162
|
-
this.#renderer = undefined;
|
|
156
|
+
this.#applyHover(false);
|
|
157
|
+
this.#disposeView(true);
|
|
163
158
|
}
|
|
164
159
|
attributeChangedCallback(name) {
|
|
165
160
|
if (!this.isConnected)
|
|
@@ -313,14 +308,8 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
313
308
|
this.setAttribute("aria-label", this.#label());
|
|
314
309
|
const wants3d = p.look !== "line" && this.#state !== "unavailable" && p.items.length > 0;
|
|
315
310
|
if (!wants3d) {
|
|
316
|
-
if (this.#view !== undefined)
|
|
317
|
-
this.#
|
|
318
|
-
this.#view = undefined;
|
|
319
|
-
this.#viewKey = "";
|
|
320
|
-
this.#release?.();
|
|
321
|
-
this.#release = undefined;
|
|
322
|
-
this.#renderer = undefined;
|
|
323
|
-
}
|
|
311
|
+
if (this.#view !== undefined)
|
|
312
|
+
this.#disposeView(true);
|
|
324
313
|
this.#drawLine();
|
|
325
314
|
if (p.look === "line" || p.items.length === 0)
|
|
326
315
|
this.#set("line");
|
|
@@ -352,14 +341,13 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
352
341
|
#priority() {
|
|
353
342
|
return (this.getAttribute("live") ?? "always") === "always" && this.#visible;
|
|
354
343
|
}
|
|
355
|
-
#applyHover() {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if ((this.getAttribute("live") ?? "always") === "hover") {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
this.addEventListener("pointerdown", this.#hover);
|
|
344
|
+
#applyHover(allow = true) {
|
|
345
|
+
const events = ["pointerenter", "focusin", "pointerdown"];
|
|
346
|
+
for (const name of events)
|
|
347
|
+
this.removeEventListener(name, this.#hover);
|
|
348
|
+
if (allow && (this.getAttribute("live") ?? "always") === "hover") {
|
|
349
|
+
for (const name of events)
|
|
350
|
+
this.addEventListener(name, this.#hover);
|
|
363
351
|
}
|
|
364
352
|
}
|
|
365
353
|
#poses() {
|
|
@@ -388,6 +376,17 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
388
376
|
const { width } = this.#size();
|
|
389
377
|
return `${encodeScene(this.#portrait)}|${width}`;
|
|
390
378
|
}
|
|
379
|
+
// Replacing a view keeps the renderer lease; leaving 3D gives it back.
|
|
380
|
+
#disposeView(releaseRenderer = false) {
|
|
381
|
+
this.#view?.dispose();
|
|
382
|
+
this.#view = undefined;
|
|
383
|
+
this.#viewKey = "";
|
|
384
|
+
if (releaseRenderer) {
|
|
385
|
+
this.#release?.();
|
|
386
|
+
this.#release = undefined;
|
|
387
|
+
this.#renderer = undefined;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
391
390
|
async #ensureView() {
|
|
392
391
|
if (this.#renderer === undefined) {
|
|
393
392
|
const taken = takeRenderer(this.#onContext);
|
|
@@ -401,20 +400,10 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
401
400
|
this.#viewKey = this.#key();
|
|
402
401
|
this.#stilled = false;
|
|
403
402
|
this.#stage.innerHTML = "";
|
|
404
|
-
const base = () => {
|
|
405
|
-
const own = this.getAttribute("texture-base");
|
|
406
|
-
return own === null || own === "" ? TEXTURE_BASE : own.endsWith("/") ? own : `${own}/`;
|
|
407
|
-
};
|
|
408
403
|
const item = createPortraitItem({
|
|
409
404
|
key: this.#viewKey,
|
|
410
405
|
state: () => this.#draw(),
|
|
411
|
-
|
|
412
|
-
farBase: () => {
|
|
413
|
-
const own = this.getAttribute("texture-far-base");
|
|
414
|
-
if (own !== null && own !== "")
|
|
415
|
-
return own.endsWith("/") ? own : `${own}/`;
|
|
416
|
-
return this.hasAttribute("texture-base") ? base() : TEXTURE_FAR_BASE;
|
|
417
|
-
},
|
|
406
|
+
...texturePaths(this),
|
|
418
407
|
redraw: () => this.#view?.invalidate(),
|
|
419
408
|
});
|
|
420
409
|
this.#view = this.#renderer.view(this.#stage, item);
|
|
@@ -436,8 +425,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
436
425
|
return;
|
|
437
426
|
if (this.#key() === this.#viewKey)
|
|
438
427
|
return;
|
|
439
|
-
this.#
|
|
440
|
-
this.#view = undefined;
|
|
428
|
+
this.#disposeView();
|
|
441
429
|
this.#makeView();
|
|
442
430
|
}
|
|
443
431
|
#sync() {
|
package/dist/scales.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type When } from "./when.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A time scale: `utc` (the clock), `ut1` (the Earth's turn, within 0.9 s of UTC), `tai` (atomic time), `gps` (TAI less 19 s), `tt` (terrestrial time, TAI plus 32.184 s) and `tdb` (barycentric dynamical time, TT plus a few milliseconds that follow the year).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { type TimeScale } from "@johnmorrisdotca/wakusei-planets/time";
|
|
8
|
+
*
|
|
9
|
+
* const scales: TimeScale[] = ["utc", "ut1", "tai", "gps", "tt", "tdb"];
|
|
10
|
+
* console.log(scales.length);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type TimeScale = "utc" | "ut1" | "tai" | "gps" | "tt" | "tdb";
|
|
14
|
+
/**
|
|
15
|
+
* TDB minus TT in seconds: a term that follows the Earth round the Sun and is never more than 1.7 milliseconds (Meeus's two terms, 0.001657 sin g and 0.000014 sin 2g, good to about 30 microseconds).
|
|
16
|
+
* @param when - A `Date` or milliseconds since 1970 (read as TT).
|
|
17
|
+
* @returns Seconds.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { tdbMinusTt } from "@johnmorrisdotca/wakusei-planets/time";
|
|
22
|
+
*
|
|
23
|
+
* console.log(Math.abs(tdbMinusTt(Date.UTC(2026, 0, 3))) < 0.002);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function tdbMinusTt(when: When): number;
|
|
27
|
+
/**
|
|
28
|
+
* A moment on one time scale as the same moment on another, in milliseconds since 1970 read on the target scale's own clock. UTC to TT is the leap seconds plus 32.184 s from 1972 and delta T before;
|
|
29
|
+
* UT1 needs `dut1` (UT1 minus UTC, from the IERS) and is UTC when it is left out, which is within 0.9 s; the TDB term is under 2 ms.
|
|
30
|
+
* @param when - A `Date` or a number of milliseconds since 1970, on the `from` scale.
|
|
31
|
+
* @param from - The scale it is on.
|
|
32
|
+
* @param to - The scale wanted.
|
|
33
|
+
* @param options - `dut1`, UT1 minus UTC in seconds, default 0.
|
|
34
|
+
* @returns Milliseconds since 1970 on the `to` scale.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { convertTimeScale } from "@johnmorrisdotca/wakusei-planets/time";
|
|
39
|
+
*
|
|
40
|
+
* const utc = Date.UTC(2026, 10, 7, 12);
|
|
41
|
+
* console.log((convertTimeScale(utc, "utc", "tt") - utc) / 1000, (convertTimeScale(utc, "utc", "gps") - utc) / 1000);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function convertTimeScale(when: When, from: TimeScale, to: TimeScale, options?: {
|
|
45
|
+
dut1?: number;
|
|
46
|
+
}): number;
|
package/dist/scales.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Time scales: UTC (the clock, as JavaScript counts it, no leap seconds), UT1 (the Earth's turn), TAI (atomic time), GPS, TT (terrestrial time) and TDB (barycentric dynamical time), with the leap seconds from 1972 (IERS Bulletin C)
|
|
2
|
+
// and delta T before. Every moment is a number of milliseconds since 1970 read on the named scale's own clock, so `convertTimeScale` adds or takes off the difference. Pure: no DOM, no three.js.
|
|
3
|
+
import { J2000_JD, TT_MINUS_TAI_SECONDS, taiMinusUtc, toJulianDate } from "./clock.js";
|
|
4
|
+
import { moment } from "./when.js";
|
|
5
|
+
const GPS_MINUS_TAI_SECONDS = -19;
|
|
6
|
+
/**
|
|
7
|
+
* TDB minus TT in seconds: a term that follows the Earth round the Sun and is never more than 1.7 milliseconds (Meeus's two terms, 0.001657 sin g and 0.000014 sin 2g, good to about 30 microseconds).
|
|
8
|
+
* @param when - A `Date` or milliseconds since 1970 (read as TT).
|
|
9
|
+
* @returns Seconds.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { tdbMinusTt } from "@johnmorrisdotca/wakusei-planets/time";
|
|
14
|
+
*
|
|
15
|
+
* console.log(Math.abs(tdbMinusTt(Date.UTC(2026, 0, 3))) < 0.002);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function tdbMinusTt(when) {
|
|
19
|
+
const g = ((357.53 + 0.98560028 * (toJulianDate(when) - J2000_JD)) * Math.PI) / 180;
|
|
20
|
+
return 0.001657 * Math.sin(g) + 0.000014 * Math.sin(2 * g);
|
|
21
|
+
}
|
|
22
|
+
function toUtc(ms, from, dut1) {
|
|
23
|
+
if (from === "utc")
|
|
24
|
+
return ms;
|
|
25
|
+
if (from === "ut1")
|
|
26
|
+
return ms - dut1 * 1000;
|
|
27
|
+
let tai = ms;
|
|
28
|
+
if (from === "gps")
|
|
29
|
+
tai = ms - GPS_MINUS_TAI_SECONDS * 1000;
|
|
30
|
+
else if (from === "tt")
|
|
31
|
+
tai = ms - TT_MINUS_TAI_SECONDS * 1000;
|
|
32
|
+
else if (from === "tdb")
|
|
33
|
+
tai = ms - tdbMinusTt(ms) * 1000 - TT_MINUS_TAI_SECONDS * 1000;
|
|
34
|
+
let utc = tai;
|
|
35
|
+
for (let i = 0; i < 3; i += 1)
|
|
36
|
+
utc = tai - taiMinusUtc(utc) * 1000;
|
|
37
|
+
return utc;
|
|
38
|
+
}
|
|
39
|
+
function fromUtc(utc, to, dut1) {
|
|
40
|
+
if (to === "utc")
|
|
41
|
+
return utc;
|
|
42
|
+
if (to === "ut1")
|
|
43
|
+
return utc + dut1 * 1000;
|
|
44
|
+
const tai = utc + taiMinusUtc(utc) * 1000;
|
|
45
|
+
if (to === "tai")
|
|
46
|
+
return tai;
|
|
47
|
+
if (to === "gps")
|
|
48
|
+
return tai + GPS_MINUS_TAI_SECONDS * 1000;
|
|
49
|
+
const tt = tai + TT_MINUS_TAI_SECONDS * 1000;
|
|
50
|
+
return to === "tt" ? tt : tt + tdbMinusTt(tt) * 1000;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A moment on one time scale as the same moment on another, in milliseconds since 1970 read on the target scale's own clock. UTC to TT is the leap seconds plus 32.184 s from 1972 and delta T before;
|
|
54
|
+
* UT1 needs `dut1` (UT1 minus UTC, from the IERS) and is UTC when it is left out, which is within 0.9 s; the TDB term is under 2 ms.
|
|
55
|
+
* @param when - A `Date` or a number of milliseconds since 1970, on the `from` scale.
|
|
56
|
+
* @param from - The scale it is on.
|
|
57
|
+
* @param to - The scale wanted.
|
|
58
|
+
* @param options - `dut1`, UT1 minus UTC in seconds, default 0.
|
|
59
|
+
* @returns Milliseconds since 1970 on the `to` scale.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { convertTimeScale } from "@johnmorrisdotca/wakusei-planets/time";
|
|
64
|
+
*
|
|
65
|
+
* const utc = Date.UTC(2026, 10, 7, 12);
|
|
66
|
+
* console.log((convertTimeScale(utc, "utc", "tt") - utc) / 1000, (convertTimeScale(utc, "utc", "gps") - utc) / 1000);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function convertTimeScale(when, from, to, options = {}) {
|
|
70
|
+
const dut1 = options.dut1 ?? 0;
|
|
71
|
+
if (!Number.isFinite(dut1))
|
|
72
|
+
throw new RangeError(`dut1 must be a finite number of seconds, got ${dut1}`);
|
|
73
|
+
const ms = moment(when);
|
|
74
|
+
return from === to ? ms : fromUtc(toUtc(ms, from, dut1), to, dut1);
|
|
75
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The axes are already numeric triples; do not allocate Vector3 objects every frame.
|
|
2
|
+
export function writeBasis(matrix, x, y, z, sx = 1, sy = 1, sz = 1) {
|
|
3
|
+
return matrix.set(x[0] * sx, y[0] * sy, z[0] * sz, 0, x[1] * sx, y[1] * sy, z[1] * sz, 0, x[2] * sx, y[2] * sy, z[2] * sz, 0, 0, 0, 0, 1);
|
|
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
|
+
}
|