@johnmorrisdotca/wakusei-planets 0.48.0 → 0.50.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.
@@ -0,0 +1,96 @@
1
+ // The dust a wheel throws: grains in free flight. On the Moon there is no air, so a grain thrown up and back goes in a clean parabola at the Moon's gravity and falls where it falls: no cloud, no drift. The field is
2
+ // a fixed pool of grains, each with a place, a velocity and an age; a step moves them and lets them go when they reach the ground or are old. Made, not measured: how many grains, how fast, how big. No DOM.
3
+ /** The Moon's surface gravity, m/s2. */
4
+ const G = 1.62;
5
+ /**
6
+ * A pool of grains in flight, made with `new DustField(size, seed)`: `size` is how many grains it holds (the oldest is reused when it is full) and `seed` makes the scatter the same for the same drive.
7
+ *
8
+ * @param size - How many grains the pool holds.
9
+ * @param seed - A seed for the scatter.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { DustField } from "@johnmorrisdotca/wakusei-planets/surface";
14
+ *
15
+ * const dust = new DustField(64, 1);
16
+ * dust.emit([0, 0.3, 0], [2, 1.5, 0], 2);
17
+ * dust.step(0.5, () => 0);
18
+ * console.log(dust.live, dust.position[1]!.toFixed(2));
19
+ * ```
20
+ */
21
+ export class DustField {
22
+ /** Each grain's place, three numbers (east, up, north), and its velocity; a grain not in flight sits far below the ground. */
23
+ position;
24
+ velocity;
25
+ age;
26
+ life;
27
+ #next = 0;
28
+ #seed;
29
+ /** The grains in flight. */
30
+ live = 0;
31
+ /**
32
+ * @param size - How many grains the pool holds; the oldest is reused when it is full.
33
+ * @param seed - A seed for the scatter, so the same drive is the same.
34
+ */
35
+ constructor(size, seed = 1) {
36
+ this.position = new Float32Array(size * 3).fill(0);
37
+ this.velocity = new Float32Array(size * 3);
38
+ this.age = new Float32Array(size).fill(1e9);
39
+ this.life = new Float32Array(size).fill(0);
40
+ this.#seed = seed >>> 0 || 1;
41
+ for (let i = 0; i < size; i += 1)
42
+ this.position[i * 3 + 1] = -1e5;
43
+ }
44
+ /** A number from 0 to 1 that is the same for the same seed (mulberry32). */
45
+ #random() {
46
+ this.#seed = (this.#seed + 0x6d2b79f5) >>> 0;
47
+ let t = this.#seed;
48
+ t = Math.imul(t ^ (t >>> 15), t | 1);
49
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
50
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
51
+ }
52
+ /**
53
+ * Throw one grain: from a place, with a velocity, scattered a little, for up to `life` seconds.
54
+ *
55
+ * @param from - East, up, north in metres.
56
+ * @param velocity - East, up, north in metres a second.
57
+ * @param life - The longest it flies, in seconds.
58
+ */
59
+ emit(from, velocity, life) {
60
+ const i = this.#next;
61
+ this.#next = (this.#next + 1) % this.age.length;
62
+ const scatter = 0.35;
63
+ this.position.set(from, i * 3);
64
+ this.velocity[i * 3] = velocity[0] + (this.#random() - 0.5) * scatter * 2;
65
+ this.velocity[i * 3 + 1] = velocity[1] * (0.7 + 0.6 * this.#random());
66
+ this.velocity[i * 3 + 2] = velocity[2] + (this.#random() - 0.5) * scatter * 2;
67
+ this.age[i] = 0;
68
+ this.life[i] = life * (0.6 + 0.4 * this.#random());
69
+ }
70
+ /**
71
+ * Move every grain on: its velocity falls at the Moon's gravity and it goes where the velocity takes it; a grain that reaches the ground, or is older than its life, is let go.
72
+ *
73
+ * @param dt - Seconds.
74
+ * @param ground - The ground's height over the site's ground at a place.
75
+ */
76
+ step(dt, ground) {
77
+ let live = 0;
78
+ for (let i = 0; i < this.age.length; i += 1) {
79
+ if (this.age[i] >= this.life[i])
80
+ continue;
81
+ this.age[i] += dt;
82
+ this.velocity[i * 3 + 1] -= G * dt;
83
+ const [x, y, z] = [this.position[i * 3] + this.velocity[i * 3] * dt, this.position[i * 3 + 1] + this.velocity[i * 3 + 1] * dt, this.position[i * 3 + 2] + this.velocity[i * 3 + 2] * dt];
84
+ if (this.age[i] >= this.life[i] || y < ground(x, z)) {
85
+ this.age[i] = 1e9;
86
+ this.position[i * 3 + 1] = -1e5;
87
+ continue;
88
+ }
89
+ this.position[i * 3] = x;
90
+ this.position[i * 3 + 1] = y;
91
+ this.position[i * 3 + 2] = z;
92
+ live += 1;
93
+ }
94
+ this.live = live;
95
+ }
96
+ }
@@ -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 { type DriveState } from "./drive.ts";
4
5
  import { type HeightLevel, type TerrainManifest } from "./height.ts";
5
6
  import { type TerrainProgress } from "./load.ts";
6
7
  import { type SurfaceScene } from "./scene.ts";
@@ -77,6 +78,14 @@ export declare class WakuseiSurface extends HTMLElement {
77
78
  quality: string;
78
79
  scale: number;
79
80
  scaled: number;
81
+ landing: {
82
+ t: number;
83
+ playing: boolean;
84
+ camera: string;
85
+ altitude: number;
86
+ speed: number;
87
+ } | undefined;
88
+ vehicle: DriveState | undefined;
80
89
  drawMs: number | undefined;
81
90
  rocks: number;
82
91
  };
@@ -90,6 +99,43 @@ export declare class WakuseiSurface extends HTMLElement {
90
99
  * @param aside - Metres to the right.
91
100
  */
92
101
  walk(ahead: number, aside?: number): void;
102
+ /** Which view of the rover: `chase` (from behind and above, the default) or `seat` (the commander's). The key C turns from one to the other. */
103
+ get driveCamera(): "chase" | "seat";
104
+ set driveCamera(value: "chase" | "seat");
105
+ /** The rover being driven, or `undefined` when it is not. */
106
+ get vehicle(): DriveState | undefined;
107
+ /**
108
+ * Drive by a set time, whatever the clock says: advance the rover `seconds` with the throttle and steering given (each -1 to 1) and draw. For a test or a sequence of pictures taken one step at a time; the keys and the
109
+ * stick do the same by the real time between frames.
110
+ *
111
+ * @param seconds - How long to drive.
112
+ * @param input - The throttle and the steering.
113
+ * @returns Whether the element is driving.
114
+ */
115
+ driveFor(seconds: number, input?: {
116
+ throttle: number;
117
+ steer: number;
118
+ }): boolean;
119
+ /** The descent being watched: its clock in seconds from ignition, whether it runs, the camera and what the lunar module is doing at that moment; `undefined` when it is not watched. */
120
+ get landing(): {
121
+ t: number;
122
+ playing: boolean;
123
+ rate: number;
124
+ camera: "lander" | "ground";
125
+ altitude: number;
126
+ speed: number;
127
+ descent: number;
128
+ } | undefined;
129
+ /** The clock of the descent, in seconds from ignition (0 to 725). Setting it goes there at once, whether it runs or not. */
130
+ get landingTime(): number;
131
+ set landingTime(value: number);
132
+ /** How fast the descent runs: 1 is the real time of it (12 minutes 5 seconds); 2, 4 and 8 are quicker. */
133
+ get landingRate(): number;
134
+ set landingRate(value: number);
135
+ /** Run the descent from where the clock is (from the start again if it had ended). */
136
+ playLanding(): void;
137
+ /** Hold the descent where it is. */
138
+ pauseLanding(): void;
93
139
  /** The things at the site, at their published places (none where the site has none or `objects="off"`). */
94
140
  get objects(): readonly SiteObject[];
95
141
  /**