@johnmorrisdotca/wakusei-planets 0.59.0 → 0.61.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 (43) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/NOTICE.md +9 -0
  3. package/README.md +31 -3
  4. package/dist/bodies/earth.js +22 -1
  5. package/dist/data/places-moon.d.ts +12 -9
  6. package/dist/data/places-moon.js +3 -3
  7. package/dist/element.d.ts +1 -1
  8. package/dist/flat/bodies.d.ts +122 -0
  9. package/dist/flat/bodies.js +115 -0
  10. package/dist/flat/define.d.ts +3 -0
  11. package/dist/flat/define.js +6 -0
  12. package/dist/flat/element.d.ts +145 -0
  13. package/dist/flat/element.js +1614 -0
  14. package/dist/flat/geometry.d.ts +127 -0
  15. package/dist/flat/geometry.js +121 -0
  16. package/dist/flat/index.d.ts +5 -0
  17. package/dist/flat/index.js +6 -0
  18. package/dist/flat/scene.d.ts +152 -0
  19. package/dist/flat/scene.js +195 -0
  20. package/dist/flat/system-define.d.ts +3 -0
  21. package/dist/flat/system-define.js +6 -0
  22. package/dist/flat/system-element.d.ts +133 -0
  23. package/dist/flat/system-element.js +1435 -0
  24. package/dist/flat/system-words.d.ts +28 -0
  25. package/dist/flat/system-words.js +102 -0
  26. package/dist/flat/system.d.ts +440 -0
  27. package/dist/flat/system.js +521 -0
  28. package/dist/flat/words.d.ts +55 -0
  29. package/dist/flat/words.js +133 -0
  30. package/dist/space/travel.js +36 -5
  31. package/dist/surface/drive.d.ts +5 -2
  32. package/dist/surface/drive.js +13 -15
  33. package/dist/surface/element.d.ts +38 -1
  34. package/dist/surface/element.js +144 -14
  35. package/dist/surface/index.d.ts +1 -0
  36. package/dist/surface/index.js +1 -0
  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 +3 -0
  42. package/dist/surface/scene.js +22 -1
  43. package/package.json +38 -2
@@ -0,0 +1,133 @@
1
+ // The flat map's own words, in English and Japanese. The names of the bodies, the orbiters and the places come from the package's own tables (`BODIES`, `ORBITER_FACTS`, each place's `name`), not from here.
2
+ // The keys that chikyu-earth's flat map also has (`map`, `controls`, `myPlace`, `footprint`, `groundTrack`, `zoomIn`, `zoomOut`, `all`, `help`) say the same thing in the same words, so a page that swaps one map for the other keeps its wording.
3
+ /**
4
+ * The words the flat map writes, one table for each language: `{body}`, `{name}`, `{altitude}` and the like are filled in. The Japanese is standard, polite Japanese.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { FLAT_WORDS } from "@johnmorrisdotca/wakusei-planets/flat";
9
+ *
10
+ * console.log(FLAT_WORDS.en.footprint, FLAT_WORDS.ja.footprint);
11
+ * ```
12
+ */
13
+ export const FLAT_WORDS = {
14
+ en: {
15
+ map: "Flat map of {body}",
16
+ controls: "Map controls",
17
+ myPlace: "My place",
18
+ centreHome: "Centre the map on my place",
19
+ centreOn: "Centre the map on {where}",
20
+ nearSide: "Near side",
21
+ farSide: "Far side",
22
+ primeMeridian: "Prime meridian",
23
+ layersFilter: "What to show",
24
+ orbiters: "Orbiters",
25
+ landing: "Landing and rover sites",
26
+ crash: "Crash and impact sites",
27
+ planned: "Planned landings",
28
+ feature: "Named features",
29
+ footprint: "Footprint",
30
+ groundTrack: "Ground track",
31
+ zoomIn: "Zoom in",
32
+ zoomOut: "Zoom out",
33
+ all: "All",
34
+ kind_crewed: "crewed landing",
35
+ kind_landing: "landing",
36
+ kind_rover: "rover",
37
+ kind_crash: "crash",
38
+ kind_impact: "impact",
39
+ kind_entry: "entry",
40
+ kind_planned: "planned landing",
41
+ kind_feature: "named feature",
42
+ kind_orbiter: "orbiter",
43
+ status_tracked: "path fitted to tracking",
44
+ status_predicted: "path carried on from tracking",
45
+ status_modelled: "mean orbit only, position approximate",
46
+ status_none: "no public path",
47
+ announceOrbiter: "{name}, orbiting {body}, {altitude} km up{note}",
48
+ announcePlace: "{name}, {kind} on {body}, {lat}, {lon}",
49
+ approximate: ", position approximate",
50
+ mapMissing: "The map picture could not be loaded. The marks are still in place.",
51
+ nothing: "Nothing to show.",
52
+ help: "Arrow keys move from one orbiter or mark to the next, Enter chooses it, plus and minus zoom.",
53
+ shown: "{orbiters} orbiters and {places} places shown",
54
+ },
55
+ ja: {
56
+ map: "{body}の平面地図",
57
+ controls: "地図の操作",
58
+ myPlace: "自分の場所",
59
+ centreHome: "地図の中心を自分の場所にする",
60
+ centreOn: "地図の中心を{where}にする",
61
+ nearSide: "表側",
62
+ farSide: "裏側",
63
+ primeMeridian: "本初子午線",
64
+ layersFilter: "表示するもの",
65
+ orbiters: "周回機",
66
+ landing: "着陸地点と探査車の地点",
67
+ crash: "墜落・衝突地点",
68
+ planned: "着陸予定地点",
69
+ feature: "地形の名前",
70
+ footprint: "可視範囲",
71
+ groundTrack: "地上軌跡",
72
+ zoomIn: "拡大",
73
+ zoomOut: "縮小",
74
+ all: "すべて",
75
+ kind_crewed: "有人着陸",
76
+ kind_landing: "着陸",
77
+ kind_rover: "探査車",
78
+ kind_crash: "墜落",
79
+ kind_impact: "衝突",
80
+ kind_entry: "大気圏突入",
81
+ kind_planned: "着陸予定",
82
+ kind_feature: "地形",
83
+ kind_orbiter: "周回機",
84
+ status_tracked: "追跡データに合わせた軌道",
85
+ status_predicted: "追跡データから延長した軌道",
86
+ status_modelled: "平均軌道のみ、位置はおおよそ",
87
+ status_none: "公開された軌道データなし",
88
+ announceOrbiter: "{name}、{body}の周回機、高度 {altitude} km{note}",
89
+ announcePlace: "{name}、{body}の{kind}、{lat}、{lon}",
90
+ approximate: "、位置はおおよそ",
91
+ mapMissing: "地図の画像を読み込めませんでした。印はそのまま表示します。",
92
+ nothing: "表示するものがありません。",
93
+ help: "矢印キーで次の周回機や印へ移り、Enter キーで選びます。プラスとマイナスのキーで拡大・縮小します。",
94
+ shown: "周回機{orbiters}機と地点{places}か所を表示中",
95
+ },
96
+ };
97
+ /**
98
+ * The words with their `{name}` places filled in; a key a language does not have is said in English, and a key neither has comes back as it is.
99
+ *
100
+ * @param lang - `en` or `ja`.
101
+ * @param key - A key of `FLAT_WORDS`.
102
+ * @param values - What goes in the `{...}` places.
103
+ * @returns The sentence.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { say } from "@johnmorrisdotca/wakusei-planets/flat";
108
+ *
109
+ * console.log(say("en", "map", { body: "Mars" }), "|", say("ja", "map", { body: "火星" }));
110
+ * ```
111
+ */
112
+ export const say = (lang, key, values = {}) => (FLAT_WORDS[lang][key] ?? FLAT_WORDS.en[key] ?? key).replace(/\{(\w+)\}/g, (all, name) => String(values[name] ?? all));
113
+ /**
114
+ * A latitude or longitude with its hemisphere, in the language's way: `3.01° S` and `23.47° E`, or `南緯3.01°` and `東経23.47°`.
115
+ *
116
+ * @param lang - `en` or `ja`.
117
+ * @param axis - `lat` or `lon`.
118
+ * @param degrees - Degrees, north and east positive.
119
+ * @returns The text.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { coordinateText } from "@johnmorrisdotca/wakusei-planets/flat";
124
+ *
125
+ * console.log(coordinateText("en", "lat", -3.01), "|", coordinateText("ja", "lon", 23.47));
126
+ * ```
127
+ */
128
+ export function coordinateText(lang, axis, degrees) {
129
+ const value = Math.abs(degrees).toFixed(2);
130
+ if (lang === "ja")
131
+ return `${axis === "lat" ? (degrees < 0 ? "南緯" : "北緯") : degrees < 0 ? "西経" : "東経"}${value}°`;
132
+ return `${value}° ${axis === "lat" ? (degrees < 0 ? "S" : "N") : degrees < 0 ? "W" : "E"}`;
133
+ }
@@ -232,6 +232,13 @@ function aimDistance(a, p) {
232
232
  const top = Math.max(a.r0, a.r1) * a.far;
233
233
  return Math.exp(Math.log(a.r0) + (Math.log(top) - Math.log(a.r0)) * smooth(p / 0.5) + (Math.log(a.r1) - Math.log(top)) * smooth((p - 0.5) / 0.5));
234
234
  }
235
+ /**
236
+ * The distance from the aim point that keeps the nearer moon inside the tangent `fit` of the look direction, as the aim goes `w` of the way along the `apart` between the two moons: nothing at either end, and
237
+ * the most in the middle. A turn fitted to it backs off no further than the two moons need, where the plain backing off (a smooth step in the log of the distance) must go many times as far to be far enough early.
238
+ */
239
+ const aimNeed = (apart, w, fit) => ((apart * Math.sin(Math.PI * w)) / 2) * (1 + 1 / fit);
240
+ /** How far inside the nearer edge of the picture a fitted turn keeps the nearer moon. */
241
+ const AIM_FIT = 0.9;
235
242
  /** The backing off to try, in turn, and how far from the middle of the picture the nearer moon may get (1 is the edge), and how many moments of the turn are looked at. */
236
243
  const AIM_FAR = Array.from({ length: 19 }, (_, k) => 1.5 ** k);
237
244
  const AIM_BEND = [0, 0.5, 1, 2, 4];
@@ -255,7 +262,8 @@ function turnAt(turn, p, t, share) {
255
262
  const u = mix(a.facings[i].u, a.facings[i + 1].u, x - i);
256
263
  const w = aimPan(q);
257
264
  const aim = mix(placeOf(a.from, t), placeOf(a.to, t), w);
258
- return { position: add(aim, scale(aimSide(a, w), aimDistance(a, q))), o: { f, u: unit(sub(u, scale(f, dot(u, f)))) }, fov: fovBetween(turn.fov0, turn.fov1, p) };
265
+ const d = a.fit === undefined ? aimDistance(a, q) : Math.hypot(aimDistance({ r0: a.r0, r1: a.r1, far: 1 }, q), aimNeed(length(sub(placeOf(a.to, t), placeOf(a.from, t))), w, a.fit));
266
+ return { position: add(aim, scale(aimSide(a, w), d)), o: { f, u: unit(sub(u, scale(f, dot(u, f)))) }, fov: fovBetween(turn.fov0, turn.fov1, p) };
259
267
  }
260
268
  const o = swingAt(turn.swing, p);
261
269
  // the lift is early: the camera backs off as it starts to turn, so the body left goes into the picture, not out of its side
@@ -965,7 +973,7 @@ function emptyMoments(route) {
965
973
  }
966
974
  return empty;
967
975
  }
968
- function withAim(input, first, stop) {
976
+ function withAim(input, first, stop, fitted = false) {
969
977
  const route = first.route;
970
978
  if (route.turn === null || first.plan.path !== "circle" || route.cut || route.share <= 0)
971
979
  return first;
@@ -975,6 +983,9 @@ function withAim(input, first, stop) {
975
983
  const share = route.share;
976
984
  const swing = route.turn;
977
985
  const flawsOf = (candidate) => aimFlaws(input, candidate, route.shells, route.leg, share);
986
+ const frame = frameOf(input.start.fov, input.aspect);
987
+ const fit = AIM_FIT * Math.min(frame.th, frame.tv);
988
+ const apart = length(sub(placeOf(input.destination, share / 2), placeOf(input.leaving, share / 2)));
978
989
  // each way of leaning out and each pace, with the least backing off that keeps the nearer moon inside 0.95 of the way to the edge and every pace of the walk inside its limit; of those the one
979
990
  // that costs least (the log of the backing off, the lean and the slowing) is taken, and none if none will do
980
991
  let cost = Number.POSITIVE_INFINITY;
@@ -990,13 +1001,14 @@ function withAim(input, first, stop) {
990
1001
  if (!bases.has(bend))
991
1002
  bases.set(bend, aimOf(input, swing, share, bend, 1));
992
1003
  const base = { ...bases.get(bend), slow };
993
- for (const far of AIM_FAR) {
1004
+ // a fitted turn has one backing off, the one the two moons need
1005
+ for (const far of fitted ? [Math.hypot(1, aimNeed(apart, 0.5, fit) / Math.max(base.r0, base.r1))] : AIM_FAR) {
994
1006
  const spent = Math.log(far) + lean;
995
1007
  if (best !== null && spent >= cost)
996
1008
  break;
997
1009
  if (stop?.() === true)
998
1010
  break;
999
- const candidate = { ...swing, aim: { ...base, far } };
1011
+ const candidate = { ...swing, aim: fitted ? { ...base, far, fit } : { ...base, far } };
1000
1012
  const flaws = flawsOf(candidate);
1001
1013
  if (flaws.edge <= AIM_EDGE && flaws.fair) {
1002
1014
  best = candidate;
@@ -1122,7 +1134,8 @@ function routeMade(input) {
1122
1134
  // before the other ways were tried and what they are measured against
1123
1135
  const started = input.budget?.now();
1124
1136
  const stop = input.budget === undefined || started === undefined ? undefined : () => input.budget.now() - started >= input.budget.ms;
1125
- let first = withAim(input, routeBase(input));
1137
+ const base = routeBase(input);
1138
+ let first = withAim(input, base);
1126
1139
  if (first.plan.path === "pivot" && first.route.turn !== null && first.route.share > 0) {
1127
1140
  // a move that turns beside the body left is framed (B1) where there is a picture that holds both bodies, its look direction and stand being those of the picture; it is taken if it has no fault more than the other
1128
1141
  const framed = routeBase(input, 0, true);
@@ -1146,6 +1159,7 @@ function routeMade(input) {
1146
1159
  // budget, keeping the best so far
1147
1160
  let best = first;
1148
1161
  let least = was;
1162
+ const made = [base];
1149
1163
  for (const variant of WAYS) {
1150
1164
  if (stop?.() === true)
1151
1165
  break;
@@ -1169,6 +1183,23 @@ function routeMade(input) {
1169
1183
  }
1170
1184
  if (total(least) === 0)
1171
1185
  break;
1186
+ made.push(raw);
1187
+ }
1188
+ // a picture is still empty in the best of them: each way's turn is made once more by an aim point whose backing off is fitted to the two moons, which is quick (one backing off for each lean and pace), so it
1189
+ // is done whatever the budget; a move that had no empty picture left is not looked at, so it is the move it was
1190
+ if (least.empty === 0)
1191
+ return best;
1192
+ for (const raw of made) {
1193
+ const other = withAim(input, raw, undefined, true);
1194
+ if (other.route.turn?.aim === undefined)
1195
+ continue;
1196
+ const faults = faultsOf(other.route);
1197
+ if (betterThan(faults, was) && total(faults) < total(least)) {
1198
+ best = other;
1199
+ least = faults;
1200
+ }
1201
+ if (total(least) === 0)
1202
+ break;
1172
1203
  }
1173
1204
  return best;
1174
1205
  }
@@ -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).
@@ -108,6 +109,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
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`.
111
113
  * @returns The rover a moment later.
112
114
  *
113
115
  * @example
@@ -119,7 +121,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
119
121
  * console.log(`${rover.north.toFixed(1)} m north after two seconds, at ${rover.speed.toFixed(1)} m/s`);
120
122
  * ```
121
123
  */
122
- export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean): DriveState;
124
+ export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean, rig?: Rig): DriveState;
123
125
  /**
124
126
  * 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
127
  * and place. Everything is in the site's plane (x east, y up, z north).
@@ -181,6 +183,7 @@ export type DriveDrag = "head" | "orbit";
181
183
  * @param offset - The driver's turn of the view, degrees right and up.
182
184
  * @param ground - The ground's height over the site's ground at a place.
183
185
  * @param drag - What a drag does in the chase view: `head` or `orbit` (the default).
186
+ * @param rig - The vehicle's measures (where its eyes are); the lunar rover's by default, a model's from `rigOf`.
184
187
  * @returns The eyes.
185
188
  *
186
189
  * @example
@@ -196,4 +199,4 @@ export type DriveDrag = "head" | "orbit";
196
199
  export declare function driveView(state: DriveState, view: "chase" | "seat", offset: {
197
200
  azimuth: number;
198
201
  pitch: number;
199
- }, ground: (east: number, north: number) => number, drag?: DriveDrag): DriveView;
202
+ }, 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,10 +72,10 @@ 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
81
  * 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
@@ -90,6 +86,7 @@ function wheelGrounds(state, ground) {
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`.
93
90
  * @returns The rover a moment later.
94
91
  *
95
92
  * @example
@@ -101,7 +98,7 @@ function wheelGrounds(state, ground) {
101
98
  * console.log(`${rover.north.toFixed(1)} m north after two seconds, at ${rover.speed.toFixed(1)} m/s`);
102
99
  * ```
103
100
  */
104
- export function driveStep(state, input, dt, ground, blocked) {
101
+ export function driveStep(state, input, dt, ground, blocked, rig = ROVER) {
105
102
  const d = Math.min(Math.max(dt, 0), 0.05);
106
103
  const next = { ...state, spin: [...state.spin] };
107
104
  const throttle = Math.min(1, Math.max(-1, input.throttle));
@@ -122,11 +119,11 @@ export function driveStep(state, input, dt, ground, blocked) {
122
119
  if (Math.abs(throttle) < 0.02 && Math.abs(next.speed) < 0.08 && Math.abs(state.pitch) < ROVER.maxSlope)
123
120
  next.speed = 0;
124
121
  // the heading: four wheels steer, so the turn is tight; the move
125
- const yaw = (next.speed * 2 * Math.tan(next.steer)) / ROVER.wheelbase;
122
+ const yaw = (next.speed * 2 * Math.tan(next.steer)) / rig.wheelbase;
126
123
  next.heading = (((state.heading + yaw * d * (180 / Math.PI)) % 360) + 360) % 360;
127
124
  const h = next.heading * RAD;
128
125
  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];
126
+ const front = [e + Math.sin(h) * rig.length * 0.5, n + Math.cos(h) * rig.length * 0.5];
130
127
  if (next.speed !== 0 && blocked !== undefined && (blocked(e, n) || blocked(front[0], front[1]))) {
131
128
  next.speed = 0;
132
129
  }
@@ -136,11 +133,11 @@ export function driveStep(state, input, dt, ground, blocked) {
136
133
  next.distance += Math.abs(next.speed) * d;
137
134
  }
138
135
  // the ground under the four wheels: the plane they make, and where the rover sits over it
139
- const g = wheelGrounds(next, ground);
136
+ const g = wheelGrounds(next, ground, rig);
140
137
  const [fl, fr, rl, rr] = [g[0], g[1], g[2], g[3]];
141
138
  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);
139
+ const pitchTarget = Math.atan2((fl + fr) / 2 - (rl + rr) / 2, rig.wheelbase);
140
+ const rollTarget = Math.atan2((fr + rr) / 2 - (fl + rl) / 2, rig.track);
144
141
  const settle = 1 - Math.exp(-d * 10);
145
142
  next.pitch += (pitchTarget - next.pitch) * settle;
146
143
  next.roll += (rollTarget - next.roll) * settle;
@@ -156,7 +153,7 @@ export function driveStep(state, input, dt, ground, blocked) {
156
153
  if (next.vy < 0)
157
154
  next.vy *= -0.15; // the springs take most of a landing
158
155
  }
159
- const turn = (next.speed * d) / ROVER.wheelRadius;
156
+ const turn = (next.speed * d) / rig.wheelRadius;
160
157
  for (let i = 0; i < 4; i += 1)
161
158
  next.spin[i] = (next.spin[i] + turn) % (Math.PI * 2);
162
159
  return next;
@@ -227,6 +224,7 @@ export function driveParts(state) {
227
224
  * @param offset - The driver's turn of the view, degrees right and up.
228
225
  * @param ground - The ground's height over the site's ground at a place.
229
226
  * @param drag - What a drag does in the chase view: `head` or `orbit` (the default).
227
+ * @param rig - The vehicle's measures (where its eyes are); the lunar rover's by default, a model's from `rigOf`.
230
228
  * @returns The eyes.
231
229
  *
232
230
  * @example
@@ -239,9 +237,9 @@ export function driveParts(state) {
239
237
  * console.log(view.eye.north.toFixed(1), turned.eye.north.toFixed(1), turned.azimuth);
240
238
  * ```
241
239
  */
242
- export function driveView(state, view, offset, ground, drag = "orbit") {
240
+ export function driveView(state, view, offset, ground, drag = "orbit", rig = ROVER) {
243
241
  if (view === "seat") {
244
- const eye = toWorld(state, ROVER.seat);
242
+ const eye = toWorld(state, rig.seat);
245
243
  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
244
  }
247
245
  // 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)
@@ -2,6 +2,7 @@ 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";
@@ -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;