@johnmorrisdotca/wakusei-planets 0.49.0 → 0.51.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 +12 -0
- package/README.md +3 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +32 -3
- package/dist/space/element.js +80 -4
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/scene.d.ts +2 -0
- package/dist/space/scene.js +9 -2
- package/dist/space/sight.d.ts +23 -0
- package/dist/space/sight.js +20 -0
- package/dist/surface/element.d.ts +27 -0
- package/dist/surface/element.js +255 -7
- package/dist/surface/glsl.d.ts +5 -2
- package/dist/surface/glsl.js +33 -2
- package/dist/surface/index.d.ts +2 -1
- package/dist/surface/index.js +2 -1
- package/dist/surface/land.d.ts +6 -0
- package/dist/surface/land.js +8 -0
- package/dist/surface/landing.d.ts +134 -0
- package/dist/surface/landing.js +237 -0
- package/dist/surface/scene.d.ts +9 -0
- package/dist/surface/scene.js +108 -3
- package/dist/surface/shapes.d.ts +14 -0
- package/dist/surface/shapes.js +33 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Apollo 17's powered descent as a function of time: where the lunar module is, how high, how fast and which way it points at each second from ignition to touchdown. What is REAL is what the Apollo 17 Mission
|
|
2
|
+
// Report (NASA, JSC-07904, NTRS 19730015117) prints: the times of the events (table 8-VI), the state at ignition (table 3-III: place, altitude, speed, heading), the altitudes it names in words (30,000 ft after the radar
|
|
3
|
+
// locked, 13,000 ft, pitchover at about 7,500 ft, manual takeover just under 300 ft, dust at 60 to 70 ft, touchdown at about 3 ft/s) and the place of touchdown. What is MADE is the smooth curve through those moments
|
|
4
|
+
// (the report prints no full table), the path on the ground between the start and the end, the attitude between events and the throttle. The page says so. Pure: no DOM.
|
|
5
|
+
const FT = 0.3048;
|
|
6
|
+
const NMI = 1852;
|
|
7
|
+
const R_MOON = 1_737_400;
|
|
8
|
+
/**
|
|
9
|
+
* The descent's fixed facts: its length in seconds, when it began in real time, where the lunar module was at ignition, and the clock the view starts at (T+4:00, where the report has the radar locked: the first
|
|
10
|
+
* four minutes are 530 km up-range of the ground the package has, so they are a time lapse of the clock with no ground).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { LANDING } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
15
|
+
*
|
|
16
|
+
* console.log(`${LANDING.duration} s from ${new Date(LANDING.ignition).toISOString()}`);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const LANDING = {
|
|
20
|
+
/** Seconds from ignition to touchdown (the report's 12:05). */
|
|
21
|
+
duration: 725,
|
|
22
|
+
/** Ignition in real time: 110:09:53 ground elapsed time, 12:05 before the touchdown at 19:54:57 UTC on 1972-12-11. */
|
|
23
|
+
ignition: Date.UTC(1972, 11, 11, 19, 42, 52),
|
|
24
|
+
/** The clock the view starts at, in seconds from ignition. */
|
|
25
|
+
viewStart: 240,
|
|
26
|
+
/** At ignition (table 3-III): latitude and east longitude in degrees, altitude in metres (8.7 nautical miles), speed in m/s (5,550.3 ft/s) and heading (276.07 degrees). */
|
|
27
|
+
start: { lat: 19.13, lon: 48.75, altitude: 8.7 * NMI, speed: 5550.3 * FT, heading: 276.07 },
|
|
28
|
+
/** The ground speed the made curve ends at, and the descent rate at touchdown the report gives ("approximately 3 ft/sec"), in m/s. */
|
|
29
|
+
touchdownDescent: 3 * FT,
|
|
30
|
+
};
|
|
31
|
+
// The altitude through the moments the report names; the times of those it gives no clock for (30,000 ft, 13,000 ft, manual takeover, dust) are placed by us between the times it does give.
|
|
32
|
+
const ALTITUDE = [
|
|
33
|
+
[0, LANDING.start.altitude],
|
|
34
|
+
[255, 30_000 * FT],
|
|
35
|
+
[500, 13_000 * FT],
|
|
36
|
+
[562, 7_500 * FT],
|
|
37
|
+
[658, 152],
|
|
38
|
+
[678, 90],
|
|
39
|
+
[715, 20],
|
|
40
|
+
[722, 2.5],
|
|
41
|
+
[725, 0],
|
|
42
|
+
];
|
|
43
|
+
// The speed along the ground: the start is the report's, the end is "near zero", the rest is made to fall smoothly and to cover the real distance from the start to the touchdown (the weights below are scaled to it).
|
|
44
|
+
const SPEED_SHAPE = [
|
|
45
|
+
[0, LANDING.start.speed],
|
|
46
|
+
[120, 1370],
|
|
47
|
+
[255, 1000],
|
|
48
|
+
[446, 430],
|
|
49
|
+
[562, 60],
|
|
50
|
+
[658, 8],
|
|
51
|
+
[700, 1.5],
|
|
52
|
+
[725, 0.5],
|
|
53
|
+
];
|
|
54
|
+
/** A piecewise cubic through points that never overshoots (Fritsch-Carlson), as a function of t. */
|
|
55
|
+
function monotone(points) {
|
|
56
|
+
const n = points.length;
|
|
57
|
+
const h = [];
|
|
58
|
+
const d = [];
|
|
59
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
60
|
+
h.push(points[i + 1][0] - points[i][0]);
|
|
61
|
+
d.push((points[i + 1][1] - points[i][1]) / h[i]);
|
|
62
|
+
}
|
|
63
|
+
const m = new Array(n).fill(0);
|
|
64
|
+
m[0] = d[0];
|
|
65
|
+
m[n - 1] = d[n - 2];
|
|
66
|
+
for (let i = 1; i < n - 1; i += 1) {
|
|
67
|
+
if (d[i - 1] * d[i] <= 0)
|
|
68
|
+
m[i] = 0;
|
|
69
|
+
else {
|
|
70
|
+
const w1 = 2 * h[i] + h[i - 1];
|
|
71
|
+
const w2 = h[i] + 2 * h[i - 1];
|
|
72
|
+
m[i] = (w1 + w2) / (w1 / d[i - 1] + w2 / d[i]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return (t) => {
|
|
76
|
+
if (t <= points[0][0])
|
|
77
|
+
return points[0][1];
|
|
78
|
+
if (t >= points[n - 1][0])
|
|
79
|
+
return points[n - 1][1];
|
|
80
|
+
let i = 0;
|
|
81
|
+
while (t > points[i + 1][0])
|
|
82
|
+
i += 1;
|
|
83
|
+
const s = (t - points[i][0]) / h[i];
|
|
84
|
+
const [s2, s3] = [s * s, s * s * s];
|
|
85
|
+
return (2 * s3 - 3 * s2 + 1) * points[i][1] + (s3 - 2 * s2 + s) * h[i] * m[i] + (-2 * s3 + 3 * s2) * points[i + 1][1] + (s3 - s2) * h[i] * m[i + 1];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** The great-circle distance in metres between two places on the Moon given in degrees (a sphere of 1,737.4 km). */
|
|
89
|
+
function distance(lat1, lon1, lat2, lon2) {
|
|
90
|
+
const [p1, p2, dl] = [(lat1 * Math.PI) / 180, (lat2 * Math.PI) / 180, ((lon2 - lon1) * Math.PI) / 180];
|
|
91
|
+
const a = Math.sin(p1) * Math.sin(p2) + Math.cos(p1) * Math.cos(p2) * Math.cos(dl);
|
|
92
|
+
return R_MOON * Math.acos(Math.min(1, Math.max(-1, a)));
|
|
93
|
+
}
|
|
94
|
+
/** The place of touchdown the report gives is the lunar module's own place in the package (the orbiter's picture of it): the site point of Apollo 17 as the places list has it. */
|
|
95
|
+
const SITE = { lat: 20.1911, lon: 30.7723 };
|
|
96
|
+
const altitudeAt = monotone(ALTITUDE);
|
|
97
|
+
const DISTANCE = distance(LANDING.start.lat, LANDING.start.lon, SITE.lat, SITE.lon);
|
|
98
|
+
/** The speed curve scaled in its middle so that it covers the real distance from ignition to touchdown, and the distance still to go at each second. */
|
|
99
|
+
const { speedAt, toGoAt } = (() => {
|
|
100
|
+
const total = (k) => {
|
|
101
|
+
const shape = SPEED_SHAPE.map(([t, v], i) => (i === 0 || i === SPEED_SHAPE.length - 1 ? [t, v] : [t, v * k]));
|
|
102
|
+
const f = monotone(shape);
|
|
103
|
+
const to = new Array(LANDING.duration + 1).fill(0);
|
|
104
|
+
for (let t = LANDING.duration - 1; t >= 0; t -= 1)
|
|
105
|
+
to[t] = to[t + 1] + (f(t) + f(t + 1)) / 2;
|
|
106
|
+
return { f, to };
|
|
107
|
+
};
|
|
108
|
+
let [lo, hi] = [0.5, 1.5];
|
|
109
|
+
for (let i = 0; i < 50; i += 1) {
|
|
110
|
+
const mid = (lo + hi) / 2;
|
|
111
|
+
if (total(mid).to[0] < DISTANCE)
|
|
112
|
+
lo = mid;
|
|
113
|
+
else
|
|
114
|
+
hi = mid;
|
|
115
|
+
}
|
|
116
|
+
const fit = total((lo + hi) / 2);
|
|
117
|
+
return {
|
|
118
|
+
speedAt: fit.f,
|
|
119
|
+
toGoAt: (t) => {
|
|
120
|
+
const c = Math.min(Math.max(t, 0), LANDING.duration);
|
|
121
|
+
const i = Math.min(LANDING.duration - 1, Math.floor(c));
|
|
122
|
+
return fit.to[i] - (fit.to[i] - fit.to[i + 1]) * (c - i);
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
})();
|
|
126
|
+
/** The direction from the touchdown back to the start of the descent on the site's plane (east, north), and the heading flown, from the two places. */
|
|
127
|
+
const BACK = (() => {
|
|
128
|
+
const dLat = SITE.lat - LANDING.start.lat;
|
|
129
|
+
const north = -R_MOON * (dLat * Math.PI) / 180;
|
|
130
|
+
const east = R_MOON * Math.cos(((SITE.lat + LANDING.start.lat) / 2 * Math.PI) / 180) * (((LANDING.start.lon - SITE.lon) * Math.PI) / 180);
|
|
131
|
+
const length = Math.hypot(east, north);
|
|
132
|
+
return { east: east / length, north: north / length, heading: ((Math.atan2(-east, -north) * 180) / Math.PI + 360) % 360 };
|
|
133
|
+
})();
|
|
134
|
+
/**
|
|
135
|
+
* The lunar module at a moment of the descent. The altitude passes through the altitudes the report names, the speed starts at the report's and covers the real distance to the touchdown point, and the rest is a
|
|
136
|
+
* smooth curve of ours: `east` and `north` are on a straight line back from the touchdown point toward where the descent began, in metres on the site's plane (the curve of the Moon is the ground's to take off).
|
|
137
|
+
*
|
|
138
|
+
* @param t - Seconds from ignition (held between 0 and the length of the descent).
|
|
139
|
+
* @returns The pose.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { landingAt } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
144
|
+
*
|
|
145
|
+
* const high = landingAt(562);
|
|
146
|
+
* console.log(`${Math.round(high.altitude)} m up at the high gate, ${high.speed.toFixed(0)} m/s along, ${Math.round(high.toGo)} m to go`);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export function landingAt(t) {
|
|
150
|
+
const c = Math.min(Math.max(t, 0), LANDING.duration);
|
|
151
|
+
const altitude = altitudeAt(c);
|
|
152
|
+
const ce = Math.min(Math.max(c, 0.25), LANDING.duration - 0.25);
|
|
153
|
+
const descent = -(altitudeAt(ce + 0.25) - altitudeAt(ce - 0.25)) / 0.5;
|
|
154
|
+
const toGo = toGoAt(c);
|
|
155
|
+
// the window: level in the braking, then the pitchover to look down at the site from the high gate, easing toward the horizon near the ground
|
|
156
|
+
const ease = (a, b, from, to) => {
|
|
157
|
+
const s = Math.min(1, Math.max(0, (c - from) / (to - from)));
|
|
158
|
+
return a + (b - a) * (s * s * (3 - 2 * s));
|
|
159
|
+
};
|
|
160
|
+
const pitch = c < 562 ? ease(10, 14, 0, 562) : c < 658 ? ease(14, -38, 562, 590) : ease(-38, -20, 658, 725);
|
|
161
|
+
const throttle = c < 28 ? 0.1 + 0.9 * (c / 28) : c < 446 ? 1 : c < 562 ? 0.57 : 0.34 + 0.12 * Math.sin(c / 7);
|
|
162
|
+
return {
|
|
163
|
+
t: c,
|
|
164
|
+
altitude,
|
|
165
|
+
descent,
|
|
166
|
+
speed: speedAt(c),
|
|
167
|
+
toGo,
|
|
168
|
+
east: BACK.east * toGo,
|
|
169
|
+
north: BACK.north * toGo,
|
|
170
|
+
heading: BACK.heading,
|
|
171
|
+
pitch,
|
|
172
|
+
throttle,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const when = (altitude) => {
|
|
176
|
+
let t = 0;
|
|
177
|
+
while (t < LANDING.duration && altitudeAt(t) > altitude)
|
|
178
|
+
t += 0.5;
|
|
179
|
+
return t;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* The events of the descent as the report gives them (the times in its table of events) and the altitudes it names (placed on the curve), in the order they pass.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* import { CALLOUTS } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
187
|
+
*
|
|
188
|
+
* console.log(CALLOUTS.map((c) => `T+${c.t}s ${c.en}`).join("; "));
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export const CALLOUTS = [
|
|
192
|
+
{ id: "ignition", t: 0, en: "Descent engine ignition", ja: "降下エンジン点火", reported: true },
|
|
193
|
+
{ id: "full", t: 28, en: "Full throttle", ja: "全開", reported: true },
|
|
194
|
+
{ id: "radar", t: 215, en: "Landing radar locks on", ja: "着陸レーダーが捉える", reported: true },
|
|
195
|
+
{ id: "throttle", t: 446, en: "Throttle down", ja: "スロットルを絞る", reported: true },
|
|
196
|
+
{ id: "high-gate", t: 562, en: "High gate: the approach phase, pitchover at about 7,500 ft", ja: "ハイゲート:進入フェーズ、高度約7,500フィートでピッチオーバー", reported: true },
|
|
197
|
+
{ id: "redesignation", t: 573, en: "First landing-point redesignation (eight in all)", ja: "最初の着陸点の変更(全部で8回)", reported: true },
|
|
198
|
+
{ id: "low-gate", t: 658, en: "Low gate: the landing phase", ja: "ローゲート:着陸フェーズ", reported: true },
|
|
199
|
+
{ id: "manual", t: when(300 * FT), en: "The Commander takes over by hand, just under 300 ft", ja: "司令官が手動操縦に切り替え(高度約300フィート未満)", reported: false },
|
|
200
|
+
{ id: "dust", t: when(70 * FT), en: "Dust first seen, at 60 to 70 ft", ja: "砂ぼこりが見え始める(高度60〜70フィート)", reported: false },
|
|
201
|
+
{ id: "touchdown", t: LANDING.duration, en: "Touchdown, 12:05 after ignition, at about 3 ft/s down", ja: "着陸(点火から12分5秒、降下速度は毎秒約3フィート)", reported: true },
|
|
202
|
+
];
|
|
203
|
+
/**
|
|
204
|
+
* The events that have passed by a moment, the latest last.
|
|
205
|
+
*
|
|
206
|
+
* @param t - Seconds from ignition.
|
|
207
|
+
* @returns The events with a time at or before `t`.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { calloutsBy } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
212
|
+
*
|
|
213
|
+
* console.log(calloutsBy(600).map((c) => c.id).join(", "));
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export function calloutsBy(t) {
|
|
217
|
+
return CALLOUTS.filter((c) => c.t <= t + 1e-9);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The clock as the page shows it: `T+04:00` from ignition, and the ground elapsed time of the mission (ignition was 110:09:53).
|
|
221
|
+
*
|
|
222
|
+
* @param t - Seconds from ignition.
|
|
223
|
+
* @returns The two clocks as text.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* import { clockText } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
228
|
+
*
|
|
229
|
+
* console.log(clockText(240));
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export function clockText(t) {
|
|
233
|
+
const two = (n) => String(Math.floor(n)).padStart(2, "0");
|
|
234
|
+
const s = Math.max(0, Math.floor(t));
|
|
235
|
+
const g = 110 * 3600 + 9 * 60 + 53 + s;
|
|
236
|
+
return { t: `T+${two(s / 60)}:${two(s % 60)}`, get: `${Math.floor(g / 3600)}:${two((g % 3600) / 60)}:${two(g % 60)}` };
|
|
237
|
+
}
|
package/dist/surface/scene.d.ts
CHANGED
|
@@ -31,6 +31,15 @@ export interface SurfaceState {
|
|
|
31
31
|
vehicle?: DriveState;
|
|
32
32
|
/** The path the driven rover has left, east, north, east, north, ... in metres: drawn as tracks. */
|
|
33
33
|
trail?: readonly number[];
|
|
34
|
+
/** The lunar module coming down (Apollo 17's descent): where it is, how high over the ground under it, which way it flies and the share of full thrust; drawn whole, with its plume, in place of the one standing at its place. */
|
|
35
|
+
lander?: {
|
|
36
|
+
east: number;
|
|
37
|
+
north: number;
|
|
38
|
+
altitude: number;
|
|
39
|
+
heading: number;
|
|
40
|
+
throttle: number;
|
|
41
|
+
inside?: boolean;
|
|
42
|
+
};
|
|
34
43
|
/** The grains of dust in flight, east, up, north for each (`DustField.position`), drawn as small squares. */
|
|
35
44
|
dust?: Float32Array;
|
|
36
45
|
/** Whether the things at the site (the lander, the rover, the flag, the station) and the rover's tracks are drawn (default true; the made ground keeps away from them while they are). */
|
package/dist/surface/scene.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { rocksAround } from "./detail.js";
|
|
2
|
-
import { DISC_FRAGMENT, DISC_VERTEX, GROUND_FRAGMENT, GROUND_VERTEX, OBJECT_FRAGMENT, OBJECT_VERTEX, ROCK_FRAGMENT, ROCK_VERTEX, SHADOW_FRAGMENT, SHADOW_VERTEX, TRACK_FRAGMENT, TRACK_VERTEX, DUST_FRAGMENT, DUST_VERTEX } from "./glsl.js";
|
|
2
|
+
import { DISC_FRAGMENT, DISC_VERTEX, GROUND_FRAGMENT, GROUND_VERTEX, OBJECT_FRAGMENT, OBJECT_VERTEX, ROCK_FRAGMENT, ROCK_VERTEX, SHADOW_FRAGMENT, SHADOW_VERTEX, TRACK_FRAGMENT, TRACK_VERTEX, DUST_FRAGMENT, DUST_VERTEX, PLUME_FRAGMENT, PLUME_VERTEX } from "./glsl.js";
|
|
3
3
|
import { driveParts } from "./drive.js";
|
|
4
|
+
import { placePart, ascentParts, landerParts } from "./shapes.js";
|
|
4
5
|
import { KEEP_OUT, objectParts, partShadows } from "./objects.js";
|
|
5
6
|
import { rockMesh } from "./rocks.js";
|
|
6
7
|
import { cameraAxes, viewProjection } from "./view.js";
|
|
@@ -236,7 +237,7 @@ export function createSurfaceItem(options) {
|
|
|
236
237
|
trackMesh.visible = on;
|
|
237
238
|
if (!on || ground === undefined)
|
|
238
239
|
return;
|
|
239
|
-
const key = `${state.sky.sun.azimuth.toFixed(1)}|${state.sky.sun.altitude.toFixed(1)}|${objectVersion}|${driving}|${state.shadows !== false}`;
|
|
240
|
+
const key = `${state.sky.sun.azimuth.toFixed(1)}|${state.sky.sun.altitude.toFixed(1)}|${objectVersion}|${driving}|${state.shadows !== false}|${state.lander !== undefined}`;
|
|
240
241
|
if (key === objectKey)
|
|
241
242
|
return;
|
|
242
243
|
objectKey = key;
|
|
@@ -248,6 +249,8 @@ export function createSurfaceItem(options) {
|
|
|
248
249
|
for (const object of list) {
|
|
249
250
|
if (driving && object.kind === "rover")
|
|
250
251
|
continue;
|
|
252
|
+
if (state.lander !== undefined && object.kind === "lander")
|
|
253
|
+
continue;
|
|
251
254
|
const base = ground(object.east, object.north);
|
|
252
255
|
const parts = objectParts(object, base);
|
|
253
256
|
for (const part of parts) {
|
|
@@ -470,7 +473,7 @@ export function createSurfaceItem(options) {
|
|
|
470
473
|
// the dust: one small square for each grain in the pool, in the corners of a fixed set of triangles
|
|
471
474
|
let dustMesh;
|
|
472
475
|
let dustMaterial;
|
|
473
|
-
const dustUniforms = { uVP: uniforms.uVP, uRight: { value: new T.Vector3(1, 0, 0) }, uUp: { value: new T.Vector3(0, 1, 0) }, uSize: { value: 0.022 } };
|
|
476
|
+
const dustUniforms = { uVP: uniforms.uVP, uRight: { value: new T.Vector3(1, 0, 0) }, uUp: { value: new T.Vector3(0, 1, 0) }, uSize: { value: 0.022 }, uEyeWorld: { value: new T.Vector3() }, uMinAngle: { value: 0 } };
|
|
474
477
|
const makeDust = (state) => {
|
|
475
478
|
const grains = state.dust;
|
|
476
479
|
if (grains === undefined) {
|
|
@@ -506,8 +509,105 @@ export function createSurfaceItem(options) {
|
|
|
506
509
|
const axes = cameraAxes(state.look);
|
|
507
510
|
dustUniforms.uRight.value.set(axes.right[0], axes.right[1], axes.right[2]);
|
|
508
511
|
dustUniforms.uUp.value.set(axes.up[0], axes.up[1], axes.up[2]);
|
|
512
|
+
dustUniforms.uSize.value = state.lander === undefined ? 0.022 : 0.09;
|
|
513
|
+
dustUniforms.uEyeWorld.value.set(state.eye.east, state.eye.up, -state.eye.north);
|
|
514
|
+
dustUniforms.uMinAngle.value = state.lander === undefined ? 0 : 2.6 * fullPixel; // seen from far off a grain still shows as about two pixels // a blast's grains are thrown wider and bigger than a wheel's
|
|
509
515
|
dustMesh.visible = true;
|
|
510
516
|
};
|
|
517
|
+
// the lunar module coming down: its parts placed at each draw (a few thousand corners), its shadow on the ground far below it, and its plume
|
|
518
|
+
let landerMesh;
|
|
519
|
+
let landerShadow;
|
|
520
|
+
let plumeMesh;
|
|
521
|
+
let plumeMaterial;
|
|
522
|
+
const plumeUniforms = { uVP: uniforms.uVP, uBell: { value: new T.Vector3() }, uLength: { value: 5 }, uRadius: { value: 2 }, uPlume: { value: 1 } };
|
|
523
|
+
const landerLocal = [...landerParts(), ...ascentParts()];
|
|
524
|
+
const landerVertices = landerLocal.reduce((n, part) => n + part.position.length / 3, 0);
|
|
525
|
+
const makeLander = (state) => {
|
|
526
|
+
const l = state.lander;
|
|
527
|
+
const groundOf = options.groundY;
|
|
528
|
+
if (l === undefined || groundOf === undefined) {
|
|
529
|
+
if (landerMesh !== undefined)
|
|
530
|
+
landerMesh.visible = false;
|
|
531
|
+
if (landerShadow !== undefined)
|
|
532
|
+
landerShadow.visible = false;
|
|
533
|
+
if (plumeMesh !== undefined)
|
|
534
|
+
plumeMesh.visible = false;
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const base = groundOf(l.east, l.north);
|
|
538
|
+
const turn = (l.heading * Math.PI) / 180;
|
|
539
|
+
const parts = landerLocal.map((part) => placePart(part, l.east, base + l.altitude, l.north, turn));
|
|
540
|
+
if (landerMesh === undefined) {
|
|
541
|
+
const geometry = new T.BufferGeometry();
|
|
542
|
+
geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(landerVertices * 3), 3));
|
|
543
|
+
geometry.setAttribute("normal", new T.BufferAttribute(new Float32Array(landerVertices * 3), 3));
|
|
544
|
+
const tone = new Float32Array(landerVertices);
|
|
545
|
+
const tint = new Float32Array(landerVertices * 3);
|
|
546
|
+
let at = 0;
|
|
547
|
+
for (const part of parts) {
|
|
548
|
+
for (let i = 0; i < part.position.length / 3; i += 1) {
|
|
549
|
+
tone[at] = part.tone;
|
|
550
|
+
tint.set(part.colour ?? [1, 1, 1], at * 3);
|
|
551
|
+
at += 1;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
geometry.setAttribute("tone", new T.BufferAttribute(tone, 1));
|
|
555
|
+
geometry.setAttribute("tint", new T.BufferAttribute(tint, 3));
|
|
556
|
+
landerMesh = new T.Mesh(geometry, objectMaterial);
|
|
557
|
+
landerMesh.frustumCulled = false;
|
|
558
|
+
landerMesh.renderOrder = 1;
|
|
559
|
+
scene.add(landerMesh);
|
|
560
|
+
// the plume: a fixed cone of 24 by 12 corners, sized and placed by uniforms
|
|
561
|
+
const pos = [];
|
|
562
|
+
const index = [];
|
|
563
|
+
for (let j = 0; j <= 12; j += 1)
|
|
564
|
+
for (let i = 0; i <= 24; i += 1)
|
|
565
|
+
pos.push(i / 24, j / 12, 0);
|
|
566
|
+
for (let j = 0; j < 12; j += 1)
|
|
567
|
+
for (let i = 0; i < 24; i += 1)
|
|
568
|
+
index.push(j * 25 + i, j * 25 + i + 1, (j + 1) * 25 + i, j * 25 + i + 1, (j + 1) * 25 + i + 1, (j + 1) * 25 + i);
|
|
569
|
+
const cone = new T.BufferGeometry();
|
|
570
|
+
cone.setAttribute("position", new T.BufferAttribute(new Float32Array(pos), 3));
|
|
571
|
+
cone.setIndex(new T.BufferAttribute(new Uint16Array(index), 1));
|
|
572
|
+
plumeMaterial = new T.ShaderMaterial({ vertexShader: PLUME_VERTEX, fragmentShader: PLUME_FRAGMENT, uniforms: plumeUniforms, transparent: true, depthWrite: false, side: 2 });
|
|
573
|
+
plumeMesh = new T.Mesh(cone, plumeMaterial);
|
|
574
|
+
plumeMesh.frustumCulled = false;
|
|
575
|
+
plumeMesh.renderOrder = 4;
|
|
576
|
+
scene.add(plumeMesh);
|
|
577
|
+
}
|
|
578
|
+
const position = landerMesh.geometry.getAttribute("position");
|
|
579
|
+
const normal = landerMesh.geometry.getAttribute("normal");
|
|
580
|
+
let at = 0;
|
|
581
|
+
for (const part of parts) {
|
|
582
|
+
position.array.set(part.position, at * 3);
|
|
583
|
+
normal.array.set(part.normal, at * 3);
|
|
584
|
+
at += part.position.length / 3;
|
|
585
|
+
}
|
|
586
|
+
position.needsUpdate = true;
|
|
587
|
+
normal.needsUpdate = true;
|
|
588
|
+
landerMesh.visible = l.inside !== true;
|
|
589
|
+
const shadow = state.shadows === false ? [] : partShadows(parts, base, state.sky.sun.azimuth, state.sky.sun.altitude);
|
|
590
|
+
const shadowGeometry = new T.BufferGeometry();
|
|
591
|
+
shadowGeometry.setAttribute("position", new T.BufferAttribute(new Float32Array(shadow), 3));
|
|
592
|
+
shadowGeometry.setAttribute("uv", new T.BufferAttribute(new Float32Array((shadow.length / 3) * 2).map((_, i) => (i % 2 === 1 ? 0 : 0.5)), 2));
|
|
593
|
+
if (landerShadow === undefined) {
|
|
594
|
+
landerShadow = new T.Mesh(shadowGeometry, shadowMaterial);
|
|
595
|
+
landerShadow.frustumCulled = false;
|
|
596
|
+
landerShadow.renderOrder = 2;
|
|
597
|
+
scene.add(landerShadow);
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
landerShadow.geometry.dispose();
|
|
601
|
+
landerShadow.geometry = shadowGeometry;
|
|
602
|
+
}
|
|
603
|
+
landerShadow.visible = true;
|
|
604
|
+
// the bell's exit is 0.3 m up; the plume reaches farther and wider the harder the engine works
|
|
605
|
+
plumeUniforms.uBell.value.set(l.east, base + l.altitude + 0.3, l.north);
|
|
606
|
+
plumeUniforms.uLength.value = 3 + 9 * l.throttle;
|
|
607
|
+
plumeUniforms.uRadius.value = 1.3 + 2.6 * l.throttle;
|
|
608
|
+
plumeUniforms.uPlume.value = l.throttle;
|
|
609
|
+
plumeMesh.visible = l.throttle > 0.02 && l.inside !== true;
|
|
610
|
+
};
|
|
511
611
|
let measuring = false;
|
|
512
612
|
let drawMs;
|
|
513
613
|
let aspect = context.width / Math.max(1, context.height);
|
|
@@ -522,6 +622,7 @@ export function createSurfaceItem(options) {
|
|
|
522
622
|
makeRocks(state);
|
|
523
623
|
makeObjects(state);
|
|
524
624
|
makeVehicle(state);
|
|
625
|
+
makeLander(state);
|
|
525
626
|
makeTrail(state);
|
|
526
627
|
makeDust(state);
|
|
527
628
|
measuring = state.measure === true;
|
|
@@ -661,6 +762,10 @@ export function createSurfaceItem(options) {
|
|
|
661
762
|
vehicleShadow?.geometry.dispose();
|
|
662
763
|
trailMesh?.geometry.dispose();
|
|
663
764
|
dustMesh?.geometry.dispose();
|
|
765
|
+
landerMesh?.geometry.dispose();
|
|
766
|
+
landerShadow?.geometry.dispose();
|
|
767
|
+
plumeMesh?.geometry.dispose();
|
|
768
|
+
plumeMaterial?.dispose();
|
|
664
769
|
trailMaterialDriven?.dispose();
|
|
665
770
|
dustMaterial?.dispose();
|
|
666
771
|
objectMaterial.dispose();
|
package/dist/surface/shapes.d.ts
CHANGED
|
@@ -60,3 +60,17 @@ export declare function landerParts(): Part[];
|
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
export declare function roverParts(): Part[];
|
|
63
|
+
/**
|
|
64
|
+
* The lunar module's ascent stage in the same frame as `landerParts` (it sits on the descent stage's deck, 3.2 m up): the cabin, its two triangular windows, the hatch section on top with the docking tunnel, the four
|
|
65
|
+
* thruster quads at its corners, the rendezvous radar on its boom and the antenna. Plain shapes from the published sizes (the whole craft stands about 7 m on its legs); no mark or flag is drawn.
|
|
66
|
+
*
|
|
67
|
+
* @returns The parts.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { ascentParts } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
72
|
+
*
|
|
73
|
+
* console.log(ascentParts().length, "parts");
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function ascentParts(): Part[];
|
package/dist/surface/shapes.js
CHANGED
|
@@ -245,3 +245,36 @@ export function roverParts() {
|
|
|
245
245
|
parts.push(box([0, 0.78, -1.15], [0.9, 0.3, 0.5], 0, 1.05, 0, SILVER));
|
|
246
246
|
return parts;
|
|
247
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The lunar module's ascent stage in the same frame as `landerParts` (it sits on the descent stage's deck, 3.2 m up): the cabin, its two triangular windows, the hatch section on top with the docking tunnel, the four
|
|
250
|
+
* thruster quads at its corners, the rendezvous radar on its boom and the antenna. Plain shapes from the published sizes (the whole craft stands about 7 m on its legs); no mark or flag is drawn.
|
|
251
|
+
*
|
|
252
|
+
* @returns The parts.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* import { ascentParts } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
257
|
+
*
|
|
258
|
+
* console.log(ascentParts().length, "parts");
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export function ascentParts() {
|
|
262
|
+
const parts = [];
|
|
263
|
+
const cabin = [0.86, 0.83, 0.76];
|
|
264
|
+
const dark = [0.2, 0.22, 0.26];
|
|
265
|
+
parts.push(box([0, 4.1, 0.1], [3.0, 1.8, 2.6], 0, 1.2, 0, cabin));
|
|
266
|
+
// the front face's two windows, and the hatch section with its tunnel on top
|
|
267
|
+
for (const x of [-0.8, 0.8])
|
|
268
|
+
parts.push(box([x, 4.3, 1.42], [0.5, 0.55, 0.05], 0, 0.6, 0, dark));
|
|
269
|
+
parts.push(box([0, 5.2, 0], [2.2, 0.7, 2.0], 0, 1.1, 0, cabin));
|
|
270
|
+
parts.push(cylinder([0, 5.55, 0], 0.5, 0.45, 12, 1.0, false, [0.7, 0.7, 0.72]));
|
|
271
|
+
// the four thruster quads at the corners of the cabin
|
|
272
|
+
for (const x of [-1, 1])
|
|
273
|
+
for (const z of [-1, 1])
|
|
274
|
+
parts.push(box([x * 1.65, 4.1, z * 1.2], [0.45, 0.45, 0.45], 0, 1.0, 0, [0.78, 0.78, 0.8]));
|
|
275
|
+
// the rendezvous radar on a boom and the antenna
|
|
276
|
+
parts.push(strut([0.6, 5.4, 0.2], [1.1, 6.1, 0.2], 0.06, 1.1, [0.8, 0.8, 0.82]));
|
|
277
|
+
parts.push(dish([1.1, 6.15, 0.2], [0.4, 0.8, 0.4], 0.35, 0.1, 10, 1.4, [0.95, 0.95, 0.97]));
|
|
278
|
+
parts.push(strut([-0.5, 5.4, -0.4], [-0.5, 6.4, -0.4], 0.02, 1.0, [0.5, 0.5, 0.52]));
|
|
279
|
+
return parts;
|
|
280
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.51.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.51.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|