@johnmorrisdotca/wakusei-planets 0.60.0 → 0.62.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/NOTICE.md +9 -0
  3. package/README.md +18 -3
  4. package/dist/belts/filter.d.ts +128 -0
  5. package/dist/belts/filter.js +117 -0
  6. package/dist/belts/index.d.ts +2 -0
  7. package/dist/belts/index.js +1 -0
  8. package/dist/bodies/earth.js +22 -1
  9. package/dist/data/places-moon.d.ts +12 -9
  10. package/dist/data/places-moon.js +3 -3
  11. package/dist/element.d.ts +1 -1
  12. package/dist/flat/system-define.d.ts +3 -0
  13. package/dist/flat/system-define.js +6 -0
  14. package/dist/flat/system-element.d.ts +133 -0
  15. package/dist/flat/system-element.js +1435 -0
  16. package/dist/flat/system-words.d.ts +28 -0
  17. package/dist/flat/system-words.js +102 -0
  18. package/dist/flat/system.d.ts +440 -0
  19. package/dist/flat/system.js +521 -0
  20. package/dist/landing-sites.js +6 -6
  21. package/dist/space/travel.js +36 -5
  22. package/dist/surface/drive.d.ts +8 -4
  23. package/dist/surface/drive.js +18 -19
  24. package/dist/surface/dust.d.ts +2 -1
  25. package/dist/surface/dust.js +3 -2
  26. package/dist/surface/element.d.ts +41 -4
  27. package/dist/surface/element.js +173 -25
  28. package/dist/surface/flat.d.ts +34 -0
  29. package/dist/surface/flat.js +63 -0
  30. package/dist/surface/glsl.d.ts +6 -3
  31. package/dist/surface/glsl.js +35 -2
  32. package/dist/surface/height.d.ts +1 -1
  33. package/dist/surface/index.d.ts +4 -2
  34. package/dist/surface/index.js +4 -2
  35. package/dist/surface/land.d.ts +7 -5
  36. package/dist/surface/land.js +10 -8
  37. package/dist/surface/model.d.ts +54 -0
  38. package/dist/surface/model.js +147 -0
  39. package/dist/surface/rig.d.ts +125 -0
  40. package/dist/surface/rig.js +107 -0
  41. package/dist/surface/scene.d.ts +9 -2
  42. package/dist/surface/scene.js +63 -5
  43. package/dist/surface/site.d.ts +32 -3
  44. package/dist/surface/site.js +99 -2
  45. package/dist/surface/sky.d.ts +92 -1
  46. package/dist/surface/sky.js +78 -4
  47. package/package.json +26 -2
@@ -1,3 +1,4 @@
1
+ import type { Rig } from "./rig.ts";
1
2
  import { type Part, type V3 } from "./shapes.ts";
2
3
  /**
3
4
  * The rover's measures: those published (its length and width, the wheels' size and the wheelbase, the gravity of the Moon) and those chosen here (the speeds, the steering, the slope it will not climb, the spring).
@@ -100,14 +101,16 @@ export declare function startDrive(east: number, north: number, heading: number,
100
101
  /** Where a point of the rover's frame is in the site's plane and height (before the wheels' own turns): the heading, then the pitch, then the roll. */
101
102
  export declare function toWorld(state: Pick<DriveState, "east" | "north" | "heading" | "pitch" | "roll" | "y">, p: V3): V3;
102
103
  /**
103
- * One step of driving: the speed follows the throttle (slowed uphill by the Moon's gravity, stopped by a slope over 25 degrees and by anything in `blocked`), the heading follows the steering (the four wheels steer, the
104
- * back ones the other way), the rover moves, and its height, pitch and roll follow the four places its wheels touch, the height on a spring and in free fall (at lunar gravity) when the ground drops away.
104
+ * One step of driving: the speed follows the throttle (slowed uphill by the body's gravity, stopped by a slope over 25 degrees and by anything in `blocked`), the heading follows the steering (the four wheels steer, the
105
+ * back ones the other way), the rover moves, and its height, pitch and roll follow the four places its wheels touch, the height on a spring and in free fall (at the body's gravity) when the ground drops away.
105
106
  *
106
107
  * @param state - The rover now.
107
108
  * @param input - The throttle and the steering.
108
109
  * @param dt - Seconds (at most 0.05 are used; call it more often for a longer time).
109
110
  * @param ground - The ground's height over the site's ground at a place.
110
111
  * @param blocked - True at a place the rover cannot go (a big rock, the lunar module).
112
+ * @param rig - The vehicle's measures (its wheels' places and size); the lunar rover's by default, a model's from `rigOf`.
113
+ * @param gravity - The body's surface gravity in m/s2 (the Moon's 1.62 by default; Mars's is `MARS_GRAVITY`, 3.71): what slows it uphill and what it falls at.
111
114
  * @returns The rover a moment later.
112
115
  *
113
116
  * @example
@@ -119,7 +122,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
119
122
  * console.log(`${rover.north.toFixed(1)} m north after two seconds, at ${rover.speed.toFixed(1)} m/s`);
120
123
  * ```
121
124
  */
122
- export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean): DriveState;
125
+ export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean, rig?: Rig, gravity?: number): DriveState;
123
126
  /**
124
127
  * The rover's shape as it is now, turned and placed: the parts of `roverParts` with each wheel turned by how far it has rolled and steered (the back wheels the other way), then moved by the rover's heading, pitch, roll
125
128
  * and place. Everything is in the site's plane (x east, y up, z north).
@@ -181,6 +184,7 @@ export type DriveDrag = "head" | "orbit";
181
184
  * @param offset - The driver's turn of the view, degrees right and up.
182
185
  * @param ground - The ground's height over the site's ground at a place.
183
186
  * @param drag - What a drag does in the chase view: `head` or `orbit` (the default).
187
+ * @param rig - The vehicle's measures (where its eyes are); the lunar rover's by default, a model's from `rigOf`.
184
188
  * @returns The eyes.
185
189
  *
186
190
  * @example
@@ -196,4 +200,4 @@ export type DriveDrag = "head" | "orbit";
196
200
  export declare function driveView(state: DriveState, view: "chase" | "seat", offset: {
197
201
  azimuth: number;
198
202
  pitch: number;
199
- }, ground: (east: number, north: number) => number, drag?: DriveDrag): DriveView;
203
+ }, ground: (east: number, north: number) => number, drag?: DriveDrag, rig?: Rig): DriveView;
@@ -1,7 +1,3 @@
1
- // Driving the lunar rover: a vehicle on four wheels over the same ground the eyes walk on. The step is pure and small: throttle and steering in, the rover's place, heading, height, pitch and roll out, the chassis
2
- // settling on a spring over the four places its wheels touch, free in the air where the ground falls away (the Moon's gravity is a sixth of ours, so a crest throws it). The ground is whatever function the page gives:
3
- // the measured heights and the made craters, so the rover follows the craters exactly. What is real: the rover's size, the gravity and a top speed near the published one. What is made: the feel of the spring, the
4
- // steering, the limits on a slope. No DOM.
5
1
  import { roverParts } from "./shapes.js";
6
2
  /**
7
3
  * The rover's measures: those published (its length and width, the wheels' size and the wheelbase, the gravity of the Moon) and those chosen here (the speeds, the steering, the slope it will not climb, the spring).
@@ -76,20 +72,22 @@ export function toWorld(state, p) {
76
72
  return [state.east + x1 * c + z2 * s, state.y + y2, state.north - x1 * s + z2 * c];
77
73
  }
78
74
  /** The ground under each wheel, at the places the four wheels are. */
79
- function wheelGrounds(state, ground) {
75
+ function wheelGrounds(state, ground, rig) {
80
76
  const h = state.heading * RAD;
81
77
  const [c, s] = [Math.cos(h), Math.sin(h)];
82
- return ROVER.wheels.map(([x, , z]) => ground(state.east + x * c + z * s, state.north - x * s + z * c));
78
+ return rig.wheels.map(([x, , z]) => ground(state.east + x * c + z * s, state.north - x * s + z * c));
83
79
  }
84
80
  /**
85
- * One step of driving: the speed follows the throttle (slowed uphill by the Moon's gravity, stopped by a slope over 25 degrees and by anything in `blocked`), the heading follows the steering (the four wheels steer, the
86
- * back ones the other way), the rover moves, and its height, pitch and roll follow the four places its wheels touch, the height on a spring and in free fall (at lunar gravity) when the ground drops away.
81
+ * One step of driving: the speed follows the throttle (slowed uphill by the body's gravity, stopped by a slope over 25 degrees and by anything in `blocked`), the heading follows the steering (the four wheels steer, the
82
+ * back ones the other way), the rover moves, and its height, pitch and roll follow the four places its wheels touch, the height on a spring and in free fall (at the body's gravity) when the ground drops away.
87
83
  *
88
84
  * @param state - The rover now.
89
85
  * @param input - The throttle and the steering.
90
86
  * @param dt - Seconds (at most 0.05 are used; call it more often for a longer time).
91
87
  * @param ground - The ground's height over the site's ground at a place.
92
88
  * @param blocked - True at a place the rover cannot go (a big rock, the lunar module).
89
+ * @param rig - The vehicle's measures (its wheels' places and size); the lunar rover's by default, a model's from `rigOf`.
90
+ * @param gravity - The body's surface gravity in m/s2 (the Moon's 1.62 by default; Mars's is `MARS_GRAVITY`, 3.71): what slows it uphill and what it falls at.
93
91
  * @returns The rover a moment later.
94
92
  *
95
93
  * @example
@@ -101,7 +99,7 @@ function wheelGrounds(state, ground) {
101
99
  * console.log(`${rover.north.toFixed(1)} m north after two seconds, at ${rover.speed.toFixed(1)} m/s`);
102
100
  * ```
103
101
  */
104
- export function driveStep(state, input, dt, ground, blocked) {
102
+ export function driveStep(state, input, dt, ground, blocked, rig = ROVER, gravity = ROVER.gravity) {
105
103
  const d = Math.min(Math.max(dt, 0), 0.05);
106
104
  const next = { ...state, spin: [...state.spin] };
107
105
  const throttle = Math.min(1, Math.max(-1, input.throttle));
@@ -115,18 +113,18 @@ export function driveStep(state, input, dt, ground, blocked) {
115
113
  next.speed += Math.sign(delta) * Math.min(Math.abs(delta), a * d);
116
114
  if (Math.abs(throttle) < 0.02)
117
115
  next.speed -= Math.sign(next.speed) * Math.min(Math.abs(next.speed), 0.35 * d); // a little rolling resistance
118
- next.speed -= ROVER.gravity * Math.sin(state.pitch) * d;
116
+ next.speed -= gravity * Math.sin(state.pitch) * d;
119
117
  if ((state.pitch > ROVER.maxSlope && next.speed > 0) || (state.pitch < -ROVER.maxSlope && next.speed < 0))
120
118
  next.speed = 0; // uphill past 25 degrees: it does not go
121
119
  // the brake holds it once it has nearly stopped, on any slope it could climb: a rover left alone stays where it is
122
120
  if (Math.abs(throttle) < 0.02 && Math.abs(next.speed) < 0.08 && Math.abs(state.pitch) < ROVER.maxSlope)
123
121
  next.speed = 0;
124
122
  // the heading: four wheels steer, so the turn is tight; the move
125
- const yaw = (next.speed * 2 * Math.tan(next.steer)) / ROVER.wheelbase;
123
+ const yaw = (next.speed * 2 * Math.tan(next.steer)) / rig.wheelbase;
126
124
  next.heading = (((state.heading + yaw * d * (180 / Math.PI)) % 360) + 360) % 360;
127
125
  const h = next.heading * RAD;
128
126
  const [e, n] = [state.east + Math.sin(h) * next.speed * d, state.north + Math.cos(h) * next.speed * d];
129
- const front = [e + Math.sin(h) * ROVER.length * 0.5, n + Math.cos(h) * ROVER.length * 0.5];
127
+ const front = [e + Math.sin(h) * rig.length * 0.5, n + Math.cos(h) * rig.length * 0.5];
130
128
  if (next.speed !== 0 && blocked !== undefined && (blocked(e, n) || blocked(front[0], front[1]))) {
131
129
  next.speed = 0;
132
130
  }
@@ -136,18 +134,18 @@ export function driveStep(state, input, dt, ground, blocked) {
136
134
  next.distance += Math.abs(next.speed) * d;
137
135
  }
138
136
  // the ground under the four wheels: the plane they make, and where the rover sits over it
139
- const g = wheelGrounds(next, ground);
137
+ const g = wheelGrounds(next, ground, rig);
140
138
  const [fl, fr, rl, rr] = [g[0], g[1], g[2], g[3]];
141
139
  const rest = (fl + fr + rl + rr) / 4;
142
- const pitchTarget = Math.atan2((fl + fr) / 2 - (rl + rr) / 2, ROVER.wheelbase);
143
- const rollTarget = Math.atan2((fr + rr) / 2 - (fl + rl) / 2, ROVER.track);
140
+ const pitchTarget = Math.atan2((fl + fr) / 2 - (rl + rr) / 2, rig.wheelbase);
141
+ const rollTarget = Math.atan2((fr + rr) / 2 - (fl + rl) / 2, rig.track);
144
142
  const settle = 1 - Math.exp(-d * 10);
145
143
  next.pitch += (pitchTarget - next.pitch) * settle;
146
144
  next.roll += (rollTarget - next.roll) * settle;
147
145
  // the height: on its springs while the wheels are down (stiffness 81, damping 12.6, a quick and well damped settle), free where the ground has dropped more than a few centimetres away
148
146
  next.airborne = next.y - rest > 0.03;
149
147
  if (next.airborne)
150
- next.vy -= ROVER.gravity * d;
148
+ next.vy -= gravity * d;
151
149
  else
152
150
  next.vy += (81 * (rest - next.y) - 12.6 * next.vy) * d;
153
151
  next.y += next.vy * d;
@@ -156,7 +154,7 @@ export function driveStep(state, input, dt, ground, blocked) {
156
154
  if (next.vy < 0)
157
155
  next.vy *= -0.15; // the springs take most of a landing
158
156
  }
159
- const turn = (next.speed * d) / ROVER.wheelRadius;
157
+ const turn = (next.speed * d) / rig.wheelRadius;
160
158
  for (let i = 0; i < 4; i += 1)
161
159
  next.spin[i] = (next.spin[i] + turn) % (Math.PI * 2);
162
160
  return next;
@@ -227,6 +225,7 @@ export function driveParts(state) {
227
225
  * @param offset - The driver's turn of the view, degrees right and up.
228
226
  * @param ground - The ground's height over the site's ground at a place.
229
227
  * @param drag - What a drag does in the chase view: `head` or `orbit` (the default).
228
+ * @param rig - The vehicle's measures (where its eyes are); the lunar rover's by default, a model's from `rigOf`.
230
229
  * @returns The eyes.
231
230
  *
232
231
  * @example
@@ -239,9 +238,9 @@ export function driveParts(state) {
239
238
  * console.log(view.eye.north.toFixed(1), turned.eye.north.toFixed(1), turned.azimuth);
240
239
  * ```
241
240
  */
242
- export function driveView(state, view, offset, ground, drag = "orbit") {
241
+ export function driveView(state, view, offset, ground, drag = "orbit", rig = ROVER) {
243
242
  if (view === "seat") {
244
- const eye = toWorld(state, ROVER.seat);
243
+ const eye = toWorld(state, rig.seat);
245
244
  return { eye: { east: eye[0], north: eye[2], up: eye[1] }, azimuth: (((state.heading + offset.azimuth) % 360) + 360) % 360, pitch: state.pitch / RAD + offset.pitch };
246
245
  }
247
246
  // the eyes stand behind the rover along the heading turned by the drag (`orbit`: they go round it) or along the heading alone (`head`: they keep their place and only the look turns)
@@ -41,6 +41,7 @@ export declare class DustField {
41
41
  *
42
42
  * @param dt - Seconds.
43
43
  * @param ground - The ground's height over the site's ground at a place.
44
+ * @param gravity - The body's surface gravity, m/s2 (the Moon's by default). Air's drag on a grain is not modelled.
44
45
  */
45
- step(dt: number, ground: (east: number, north: number) => number): void;
46
+ step(dt: number, ground: (east: number, north: number) => number, gravity?: number): void;
46
47
  }
@@ -72,14 +72,15 @@ export class DustField {
72
72
  *
73
73
  * @param dt - Seconds.
74
74
  * @param ground - The ground's height over the site's ground at a place.
75
+ * @param gravity - The body's surface gravity, m/s2 (the Moon's by default). Air's drag on a grain is not modelled.
75
76
  */
76
- step(dt, ground) {
77
+ step(dt, ground, gravity = G) {
77
78
  let live = 0;
78
79
  for (let i = 0; i < this.age.length; i += 1) {
79
80
  if (this.age[i] >= this.life[i])
80
81
  continue;
81
82
  this.age[i] += dt;
82
- this.velocity[i * 3 + 1] -= G * dt;
83
+ this.velocity[i * 3 + 1] -= gravity * dt;
83
84
  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
85
  if (this.age[i] >= this.life[i] || y < ground(x, z)) {
85
86
  this.age[i] = 1e9;
@@ -2,11 +2,12 @@ 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
4
  import { type DriveDrag, type DriveState } from "./drive.ts";
5
+ import type { Rig } from "./rig.ts";
5
6
  import { type HeightLevel, type TerrainManifest } from "./height.ts";
6
7
  import { type TerrainProgress } from "./load.ts";
7
8
  import { type SurfaceScene } from "./scene.ts";
8
9
  import { type SiteObject } from "./objects.ts";
9
- import { type MoonSky } from "./sky.ts";
10
+ import { type StandSky } from "./sky.ts";
10
11
  import { type Look } from "./view.ts";
11
12
  export { setThreeLoader };
12
13
  /**
@@ -25,7 +26,7 @@ export type SurfaceState = "idle" | "loading" | "live" | "lost" | "unavailable";
25
26
  /**
26
27
  * The `<wakusei-surface>` custom element: standing on a body.
27
28
  *
28
- * Attributes: `body` (`moon`), `site` (a name from `SURFACE_SITES`, `apollo-17`), `time` (an ISO date and time, or milliseconds since 1970; the site's own landing moment when left out; `now` for the real time),
29
+ * Attributes: `body` (`moon`; the site's own body is the one used), `site` (a name from `SURFACE_SITES`: `apollo-17`, `apollo-15`, `apollo-16`, `chang-e-3`, `chang-e-4`, `perseverance`, `curiosity`; all but `apollo-17` stand on a flat stand-in ground until a height model is added), `time` (an ISO date and time, or milliseconds since 1970; the site's own landing moment when left out; `now` for the real time),
29
30
  * `heading` (degrees clockwise from north to look toward), `pitch` (degrees up), `fov` (the view's height in degrees: zoom), `tiles` (the folder the height tiles are served from; the demo site's `tiles/` by default),
30
31
  * `lang` (`en` or `ja`: the words on the picture).
31
32
  *
@@ -58,7 +59,7 @@ export declare class WakuseiSurface extends HTMLElement {
58
59
  up: number;
59
60
  };
60
61
  /** The sky now: the Sun and the Earth in it. */
61
- get sky(): MoonSky | undefined;
62
+ get sky(): StandSky | undefined;
62
63
  /** The moment shown, milliseconds since 1970. */
63
64
  get time(): number;
64
65
  set time(value: number);
@@ -118,6 +119,23 @@ export declare class WakuseiSurface extends HTMLElement {
118
119
  set driveDrag(value: DriveDrag);
119
120
  /** The rover being driven, or `undefined` when it is not. */
120
121
  get vehicle(): DriveState | undefined;
122
+ /**
123
+ * The rover model being drawn in place of the shapes, with the node names it has and the angles its wheels and pivots were last set to; `undefined` while none is asked for (`drive-model`), while it loads or when it could not be loaded.
124
+ *
125
+ * @example
126
+ * ```ts no-run
127
+ * const surface = document.querySelector("wakusei-surface") as HTMLElement & { driveModel?: { url: string; nodes: readonly string[] } };
128
+ * surface.addEventListener("wakusei-model", () => console.log(surface.driveModel?.nodes.join(" ")));
129
+ * surface.setAttribute("drive-model", "/models/perseverance.glb");
130
+ * ```
131
+ */
132
+ get driveModel(): {
133
+ url: string;
134
+ nodes: readonly string[];
135
+ angles: Readonly<Record<string, number>>;
136
+ rig: Rig;
137
+ renders: number;
138
+ } | undefined;
121
139
  /**
122
140
  * 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
123
141
  * stick do the same by the real time between frames.
@@ -130,7 +148,26 @@ export declare class WakuseiSurface extends HTMLElement {
130
148
  throttle: number;
131
149
  steer: number;
132
150
  }): boolean;
133
- /** 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. */
151
+ /**
152
+ * 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.
153
+ *
154
+ * Two events say what happens to it, both bubbling and composed. `wakusei-landing-state` is sent when it starts or stops running (`playLanding()`, `pauseLanding()`, and the clock reaching the touchdown),
155
+ * when `landingRate` changes and when `watch-camera` changes; its `detail` is `{ t, playing, rate, camera, ended }` (`t` in seconds from ignition, `ended` true at the touchdown), so a page can keep the pause
156
+ * state without reading `landing` every second. `wakusei-landing-ended` is sent once each time the clock arrives at the touchdown (T+12:05, 725 s), by running or by a seek; its `detail` is
157
+ * `{ t: 725, rate, camera }`, and it is sent again only after the clock has left the touchdown and come back.
158
+ *
159
+ * @example
160
+ * ```ts no-run
161
+ * import type { WakuseiSurface } from "@johnmorrisdotca/wakusei-planets/surface/element";
162
+ *
163
+ * const view = document.querySelector("wakusei-surface") as WakuseiSurface;
164
+ * view.addEventListener("wakusei-landing-state", (event) => {
165
+ * const { playing, rate, camera } = (event as CustomEvent).detail;
166
+ * location.hash = `${playing ? "play" : "pause"}-${rate}-${camera}`;
167
+ * });
168
+ * view.addEventListener("wakusei-landing-ended", () => console.log("the lunar module is down"));
169
+ * ```
170
+ */
134
171
  get landing(): {
135
172
  t: number;
136
173
  playing: boolean;