@johnmorrisdotca/wakusei-planets 0.45.1 → 0.47.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/NOTICE.md +12 -0
- package/README.md +4 -3
- package/dist/scene/body.d.ts +1 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +7 -0
- package/dist/space/element.js +12 -0
- package/dist/surface/detail.d.ts +186 -0
- package/dist/surface/detail.js +316 -0
- package/dist/surface/element.d.ts +103 -0
- package/dist/surface/element.js +685 -0
- package/dist/surface/glsl.d.ts +26 -0
- package/dist/surface/glsl.js +457 -0
- package/dist/surface/height.d.ts +257 -0
- package/dist/surface/height.js +232 -0
- package/dist/surface/index.d.ts +10 -0
- package/dist/surface/index.js +10 -0
- package/dist/surface/land.d.ts +111 -0
- package/dist/surface/land.js +261 -0
- package/dist/surface/load.d.ts +133 -0
- package/dist/surface/load.js +183 -0
- package/dist/surface/objects-apollo-17.d.ts +4 -0
- package/dist/surface/objects-apollo-17.js +19 -0
- package/dist/surface/objects.d.ts +127 -0
- package/dist/surface/objects.js +179 -0
- package/dist/surface/rocks.d.ts +45 -0
- package/dist/surface/rocks.js +166 -0
- package/dist/surface/scene.d.ts +72 -0
- package/dist/surface/scene.js +488 -0
- package/dist/surface/shapes.d.ts +62 -0
- package/dist/surface/shapes.js +247 -0
- package/dist/surface/site.d.ts +58 -0
- package/dist/surface/site.js +38 -0
- package/dist/surface/sky.d.ts +81 -0
- package/dist/surface/sky.js +60 -0
- package/dist/surface/view.d.ts +129 -0
- package/dist/surface/view.js +139 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +23 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// The plain shapes the things at a site are drawn with: boxes, cylinders, cones, struts and dishes as triangles (x east or right, y up, z north or forward), each piece with a brightness and a flat colour. Pure: no
|
|
2
|
+
// DOM. Everything here is this package's drawing from published sizes; none of it is a scan or a model of the real thing.
|
|
3
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
4
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
5
|
+
const norm = (a) => {
|
|
6
|
+
const l = Math.hypot(a[0], a[1], a[2]) || 1;
|
|
7
|
+
return [a[0] / l, a[1] / l, a[2] / l];
|
|
8
|
+
};
|
|
9
|
+
const make = (tone, colour) => (colour === undefined ? { position: [], normal: [], tone } : { position: [], normal: [], tone, colour });
|
|
10
|
+
const tri = (part, a, b, c, n) => {
|
|
11
|
+
const flat = norm(cross(sub(b, a), sub(c, a)));
|
|
12
|
+
const ns = n ?? [flat, flat, flat];
|
|
13
|
+
for (const [p, q] of [[a, ns[0]], [b, ns[1]], [c, ns[2]]]) {
|
|
14
|
+
part.position.push(p[0], p[1], p[2]);
|
|
15
|
+
part.normal.push(q[0], q[1], q[2]);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const quad = (part, a, b, c, d) => {
|
|
19
|
+
tri(part, a, b, c);
|
|
20
|
+
tri(part, a, c, d);
|
|
21
|
+
};
|
|
22
|
+
/** A box with its centre, its three sizes, a turn about the up axis (radians) and a tilt about its own x axis. */
|
|
23
|
+
export function box(centre, size, turn = 0, tone = 1, tilt = 0, colour) {
|
|
24
|
+
const part = make(tone, colour);
|
|
25
|
+
const [hx, hy, hz] = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
26
|
+
const [c, s, ct, st] = [Math.cos(turn), Math.sin(turn), Math.cos(tilt), Math.sin(tilt)];
|
|
27
|
+
const at = (x, y, z) => {
|
|
28
|
+
const y2 = y * ct - z * st;
|
|
29
|
+
const z2 = y * st + z * ct;
|
|
30
|
+
return [centre[0] + x * c + z2 * s, centre[1] + y2, centre[2] - x * s + z2 * c];
|
|
31
|
+
};
|
|
32
|
+
const p = [at(-hx, -hy, -hz), at(hx, -hy, -hz), at(hx, hy, -hz), at(-hx, hy, -hz), at(-hx, -hy, hz), at(hx, -hy, hz), at(hx, hy, hz), at(-hx, hy, hz)];
|
|
33
|
+
quad(part, p[4], p[5], p[6], p[7]);
|
|
34
|
+
quad(part, p[1], p[0], p[3], p[2]);
|
|
35
|
+
quad(part, p[5], p[1], p[2], p[6]);
|
|
36
|
+
quad(part, p[0], p[4], p[7], p[3]);
|
|
37
|
+
quad(part, p[7], p[6], p[2], p[3]);
|
|
38
|
+
quad(part, p[0], p[1], p[5], p[4]);
|
|
39
|
+
return part;
|
|
40
|
+
}
|
|
41
|
+
/** A cone or a cylinder standing on its base (axis up) or lying along x (a wheel): radius at the base and at the top, smooth sides, ends closed. */
|
|
42
|
+
export function frustum(base, r0, r1, height, sides = 14, tone = 1, lying = false, colour) {
|
|
43
|
+
const part = make(tone, colour);
|
|
44
|
+
const at = (angle, h, r) => (lying ? [base[0] + h, base[1] + Math.cos(angle) * r, base[2] + Math.sin(angle) * r] : [base[0] + Math.cos(angle) * r, base[1] + h, base[2] + Math.sin(angle) * r]);
|
|
45
|
+
const side = (angle) => {
|
|
46
|
+
const radial = lying ? [0, Math.cos(angle), Math.sin(angle)] : [Math.cos(angle), 0, Math.sin(angle)];
|
|
47
|
+
const axis = lying ? [1, 0, 0] : [0, 1, 0];
|
|
48
|
+
const lean = (r0 - r1) / Math.max(height, 1e-6);
|
|
49
|
+
return norm([radial[0] + axis[0] * lean, radial[1] + axis[1] * lean, radial[2] + axis[2] * lean]);
|
|
50
|
+
};
|
|
51
|
+
const axis = lying ? [1, 0, 0] : [0, 1, 0];
|
|
52
|
+
const back = [-axis[0], -axis[1], -axis[2]];
|
|
53
|
+
for (let i = 0; i < sides; i += 1) {
|
|
54
|
+
const a0 = (i / sides) * Math.PI * 2;
|
|
55
|
+
const a1 = ((i + 1) / sides) * Math.PI * 2;
|
|
56
|
+
const [p0, p1, p2, p3] = [at(a0, 0, r0), at(a1, 0, r0), at(a1, height, r1), at(a0, height, r1)];
|
|
57
|
+
tri(part, p0, p1, p2, [side(a0), side(a1), side(a1)]);
|
|
58
|
+
tri(part, p0, p2, p3, [side(a0), side(a1), side(a0)]);
|
|
59
|
+
tri(part, at(0, height, 0), p3, p2, [axis, axis, axis]);
|
|
60
|
+
tri(part, at(0, 0, 0), p1, p0, [back, back, back]);
|
|
61
|
+
}
|
|
62
|
+
return part;
|
|
63
|
+
}
|
|
64
|
+
/** A cylinder: a frustum with one radius. */
|
|
65
|
+
export const cylinder = (base, radius, height, sides = 14, tone = 1, lying = false, colour) => frustum(base, radius, radius, height, sides, tone, lying, colour);
|
|
66
|
+
/** A strut: a thin box from one point to another. */
|
|
67
|
+
export function strut(a, b, thickness, tone = 1, colour) {
|
|
68
|
+
const part = make(tone, colour);
|
|
69
|
+
const along = norm(sub(b, a));
|
|
70
|
+
const side = norm(cross(along, Math.abs(along[1]) > 0.95 ? [1, 0, 0] : [0, 1, 0]));
|
|
71
|
+
const up = norm(cross(side, along));
|
|
72
|
+
const h = thickness / 2;
|
|
73
|
+
const corner = (p, s, u) => [p[0] + side[0] * s * h + up[0] * u * h, p[1] + side[1] * s * h + up[1] * u * h, p[2] + side[2] * s * h + up[2] * u * h];
|
|
74
|
+
const ring = (p) => [corner(p, -1, -1), corner(p, 1, -1), corner(p, 1, 1), corner(p, -1, 1)];
|
|
75
|
+
const [r0, r1] = [ring(a), ring(b)];
|
|
76
|
+
for (let i = 0; i < 4; i += 1) {
|
|
77
|
+
const j = (i + 1) % 4;
|
|
78
|
+
quad(part, r0[i], r0[j], r1[j], r1[i]);
|
|
79
|
+
}
|
|
80
|
+
return part;
|
|
81
|
+
}
|
|
82
|
+
/** A shallow dish: a cone with its rim a radius out and its middle `depth` back, facing along `facing`. Both sides drawn. */
|
|
83
|
+
export function dish(centre, facing, radius, depth, sides = 14, tone = 1, colour) {
|
|
84
|
+
const part = make(tone, colour);
|
|
85
|
+
const f = norm(facing);
|
|
86
|
+
const right = norm(cross(f, Math.abs(f[1]) > 0.95 ? [1, 0, 0] : [0, 1, 0]));
|
|
87
|
+
const up = norm(cross(right, f));
|
|
88
|
+
const rim = (angle) => [centre[0] + (right[0] * Math.cos(angle) + up[0] * Math.sin(angle)) * radius, centre[1] + (right[1] * Math.cos(angle) + up[1] * Math.sin(angle)) * radius, centre[2] + (right[2] * Math.cos(angle) + up[2] * Math.sin(angle)) * radius];
|
|
89
|
+
const middle = [centre[0] - f[0] * depth, centre[1] - f[1] * depth, centre[2] - f[2] * depth];
|
|
90
|
+
for (let i = 0; i < sides; i += 1) {
|
|
91
|
+
const a0 = (i / sides) * Math.PI * 2;
|
|
92
|
+
const a1 = ((i + 1) / sides) * Math.PI * 2;
|
|
93
|
+
tri(part, middle, rim(a1), rim(a0));
|
|
94
|
+
tri(part, middle, rim(a0), rim(a1));
|
|
95
|
+
}
|
|
96
|
+
return part;
|
|
97
|
+
}
|
|
98
|
+
/** Turn and move a part about the up axis (radians, clockwise from north as heading is) and put it at a place: `x, z` of the part's own frame are right and forward. */
|
|
99
|
+
export function placePart(part, east, base, north, turn) {
|
|
100
|
+
const [c, s] = [Math.cos(turn), Math.sin(turn)];
|
|
101
|
+
const out = { ...part, position: [], normal: [] };
|
|
102
|
+
for (let i = 0; i < part.position.length; i += 3) {
|
|
103
|
+
const [x, y, z] = [part.position[i], part.position[i + 1], part.position[i + 2]];
|
|
104
|
+
out.position.push(east + x * c + z * s, base + y, north - x * s + z * c);
|
|
105
|
+
const [nx, ny, nz] = [part.normal[i], part.normal[i + 1], part.normal[i + 2]];
|
|
106
|
+
out.normal.push(nx * c + nz * s, ny, -nx * s + nz * c);
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
const GOLD = [1, 0.74, 0.3];
|
|
111
|
+
const SILVER = [0.86, 0.87, 0.9];
|
|
112
|
+
const DARK = [0.32, 0.33, 0.36];
|
|
113
|
+
/**
|
|
114
|
+
* The lunar module's descent stage in its own frame (x right, z forward, the middle of its footprint on the ground at the origin): an octagonal body in a flat gold, a dark deck, the engine's bell under it, four splayed
|
|
115
|
+
* legs each with two braces and a footpad, and the ladder down the forward leg to a porch. Sizes from the published ones (about 4.2 m across the body, the deck 3.2 m up, 4.7 m from the middle to a footpad).
|
|
116
|
+
*
|
|
117
|
+
* @returns The parts.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { landerParts } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
122
|
+
*
|
|
123
|
+
* console.log(landerParts().length, "parts");
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function landerParts() {
|
|
127
|
+
const parts = [];
|
|
128
|
+
const R = 2.3;
|
|
129
|
+
const [bottom, top] = [0.95, 3.2];
|
|
130
|
+
const ring = (y, r = R) => Array.from({ length: 8 }, (_, i) => [Math.cos(Math.PI / 8 + (i * Math.PI) / 4) * r, y, Math.sin(Math.PI / 8 + (i * Math.PI) / 4) * r]);
|
|
131
|
+
const [a, b] = [ring(bottom), ring(top)];
|
|
132
|
+
const body = make(1.25, GOLD);
|
|
133
|
+
for (let i = 0; i < 8; i += 1) {
|
|
134
|
+
const j = (i + 1) % 8;
|
|
135
|
+
quad(body, a[i], a[j], b[j], b[i]);
|
|
136
|
+
tri(body, [0, bottom, 0], a[i], a[j], [[0, -1, 0], [0, -1, 0], [0, -1, 0]]);
|
|
137
|
+
}
|
|
138
|
+
parts.push(body);
|
|
139
|
+
const deck = make(0.7, DARK);
|
|
140
|
+
const d = ring(top + 0.06, R - 0.12);
|
|
141
|
+
for (let i = 0; i < 8; i += 1) {
|
|
142
|
+
const j = (i + 1) % 8;
|
|
143
|
+
tri(deck, [0, top + 0.06, 0], d[j], d[i], [[0, 1, 0], [0, 1, 0], [0, 1, 0]]);
|
|
144
|
+
}
|
|
145
|
+
parts.push(deck);
|
|
146
|
+
// the equipment bay's door on one flat, and the engine's bell under the body
|
|
147
|
+
parts.push(box([R * Math.cos(Math.PI / 8) + 0.04, 1.9, 0], [0.08, 1.1, 1.3], 0, 0.6, 0, DARK));
|
|
148
|
+
parts.push(frustum([0, 0.28, 0], 0.8, 0.36, 0.7, 14, 0.7, false, DARK));
|
|
149
|
+
for (let k = 0; k < 4; k += 1) {
|
|
150
|
+
const angle = (k * Math.PI) / 2 + Math.PI / 4;
|
|
151
|
+
const [cx, cz] = [Math.cos(angle), Math.sin(angle)];
|
|
152
|
+
const [px, pz] = [-cz, cx];
|
|
153
|
+
const pad = [cx * 4.7, 0.12, cz * 4.7];
|
|
154
|
+
// the leg and its two braces, which join it a third of the way down from the body's corner
|
|
155
|
+
parts.push(strut([cx * 1.95, 2.5, cz * 1.95], pad, 0.16, 1.2, SILVER));
|
|
156
|
+
for (const side of [-1, 1])
|
|
157
|
+
parts.push(strut([cx * 2.1 + px * side * 1.05, 1.3, cz * 2.1 + pz * side * 1.05], [cx * 3.4, 1.35, cz * 3.4], 0.09, 1.1, SILVER));
|
|
158
|
+
parts.push(cylinder([pad[0], 0, pad[2]], 0.46, 0.09, 14, 1.2, false, SILVER));
|
|
159
|
+
if (k === 0) {
|
|
160
|
+
// the forward leg: a porch on the body and a ladder of two rails and rungs from it to the ground
|
|
161
|
+
parts.push(box([cx * 2.75, 1.85, cz * 2.75], [0.95, 0.06, 0.8], Math.atan2(cx, cz), 1.1, 0, SILVER));
|
|
162
|
+
for (const side of [-1, 1])
|
|
163
|
+
parts.push(strut([cx * 2.75 + px * side * 0.26, 1.85, cz * 2.75 + pz * side * 0.26], [cx * 4.3 + px * side * 0.26, 0.05, cz * 4.3 + pz * side * 0.26], 0.05, 1.2, SILVER));
|
|
164
|
+
for (let r = 1; r <= 5; r += 1) {
|
|
165
|
+
const t = r / 6;
|
|
166
|
+
parts.push(box([cx * (2.75 + 1.55 * t), 1.85 * (1 - t) + 0.05 * t, cz * (2.75 + 1.55 * t)], [0.54, 0.035, 0.05], Math.atan2(cx, cz) + Math.PI / 2, 1.1, 0, SILVER));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return parts;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The lunar rover in its own frame (x right, z forward, the middle of its wheelbase on the ground at the origin): a frame and floor, four wheels (parts 0 to 3: front left, front right, rear left, rear right) with a
|
|
174
|
+
* fender over each, two seats, the console with its handle, the dish on its mast, the television camera on its own mast, a whip antenna and the boxes at both ends. Sizes from the published ones (3.1 m long, 2.3 m
|
|
175
|
+
* wide, wheels 0.82 m across, the wheelbase 2.3 m).
|
|
176
|
+
*
|
|
177
|
+
* @returns The parts.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { roverParts } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
182
|
+
*
|
|
183
|
+
* console.log(roverParts().filter((part) => part.wheel !== undefined).length, "wheels");
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export function roverParts() {
|
|
187
|
+
const parts = [];
|
|
188
|
+
const grey = [0.84, 0.85, 0.88];
|
|
189
|
+
const tan = [0.82, 0.78, 0.68];
|
|
190
|
+
const seatColour = [0.74, 0.76, 0.84];
|
|
191
|
+
// the frame: two rails with three cross pieces, the floor between them, the decks at both ends
|
|
192
|
+
for (const x of [-0.55, 0.55])
|
|
193
|
+
parts.push(box([x, 0.55, 0], [0.09, 0.09, 3.0], 0, 1.1, 0, grey));
|
|
194
|
+
for (const z of [-1.4, -0.2, 1.3])
|
|
195
|
+
parts.push(box([0, 0.55, z], [1.2, 0.07, 0.09], 0, 1.1, 0, grey));
|
|
196
|
+
parts.push(box([0, 0.57, -0.2], [1.1, 0.03, 1.1], 0, 1.0, 0, grey));
|
|
197
|
+
parts.push(box([0, 0.57, 1.0], [1.15, 0.03, 0.7], 0, 1.0, 0, grey));
|
|
198
|
+
parts.push(box([0, 0.57, -1.1], [1.15, 0.03, 0.6], 0, 1.0, 0, grey));
|
|
199
|
+
const wheels = [[-1, 1], [1, 1], [-1, -1], [1, -1]];
|
|
200
|
+
wheels.forEach(([sx, sz], index) => {
|
|
201
|
+
const centre = [sx * 1.03, 0.41, sz * 1.15];
|
|
202
|
+
// a wheel of wire mesh (dark, with a lighter hub), its strut to the frame and its fender over the top
|
|
203
|
+
const wheel = cylinder([-0.115, 0, 0], 0.41, 0.23, 16, 0.55, true, DARK);
|
|
204
|
+
const hub = cylinder([-0.12, 0, 0], 0.16, 0.24, 10, 1.0, true, [0.7, 0.72, 0.76]);
|
|
205
|
+
for (const part of [wheel, hub]) {
|
|
206
|
+
part.wheel = index;
|
|
207
|
+
for (let i = 0; i < part.position.length; i += 3) {
|
|
208
|
+
part.position[i] = part.position[i] + centre[0];
|
|
209
|
+
part.position[i + 1] = part.position[i + 1] + centre[1];
|
|
210
|
+
part.position[i + 2] = part.position[i + 2] + centre[2];
|
|
211
|
+
}
|
|
212
|
+
parts.push(part);
|
|
213
|
+
}
|
|
214
|
+
parts.push(strut([sx * 0.55, 0.55, sz * 1.15], [sx * 0.95, 0.45, sz * 1.15], 0.07, 1.1, grey));
|
|
215
|
+
// the fender: five narrow boards along an arc a hand above the tyre
|
|
216
|
+
for (let s = 0; s < 5; s += 1) {
|
|
217
|
+
const a0 = ((-65 + s * 26) * Math.PI) / 180;
|
|
218
|
+
const a1 = ((-65 + (s + 1) * 26) * Math.PI) / 180;
|
|
219
|
+
const r = 0.52;
|
|
220
|
+
const p0 = [centre[0], centre[1] + Math.cos(a0) * r, centre[2] + Math.sin(a0) * r];
|
|
221
|
+
const p1 = [centre[0], centre[1] + Math.cos(a1) * r, centre[2] + Math.sin(a1) * r];
|
|
222
|
+
parts.push(strut(p0, p1, 0.02, 1.15, tan));
|
|
223
|
+
const wide = box([(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2, (p0[2] + p1[2]) / 2], [0.34, 0.02, Math.hypot(p1[2] - p0[2], p1[1] - p0[1])], 0, 1.15, -Math.atan2(p1[1] - p0[1], p1[2] - p0[2]), tan);
|
|
224
|
+
parts.push(wide);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
for (const x of [-0.42, 0.42]) {
|
|
228
|
+
parts.push(box([x, 0.82, -0.3], [0.44, 0.06, 0.46], 0, 1.15, 0, seatColour));
|
|
229
|
+
parts.push(box([x, 1.1, -0.55], [0.44, 0.5, 0.05], 0, 1.15, 0.12, seatColour));
|
|
230
|
+
parts.push(strut([x, 0.58, -0.1], [x, 0.8, -0.1], 0.04, 1.0, grey));
|
|
231
|
+
}
|
|
232
|
+
// the console with its hand controller, between and in front of the seats
|
|
233
|
+
parts.push(box([0, 0.95, 0.45], [0.46, 0.3, 0.25], 0, 0.9, 0, DARK));
|
|
234
|
+
parts.push(strut([0, 1.1, 0.35], [0, 1.4, 0.3], 0.03, 1.0, DARK));
|
|
235
|
+
parts.push(box([0, 1.42, 0.3], [0.2, 0.04, 0.05], 0, 1.0, 0, DARK));
|
|
236
|
+
// the dish on its mast at the front, turned up and back toward the Earth, and the camera's own mast beside it
|
|
237
|
+
parts.push(strut([0, 0.6, 1.2], [0, 1.65, 1.2], 0.05, 1.2, grey));
|
|
238
|
+
parts.push(dish([0, 1.75, 1.2], [0, 0.55, -0.55], 0.46, 0.14, 14, 1.4, [0.95, 0.95, 0.97]));
|
|
239
|
+
parts.push(strut([-0.38, 0.6, 1.3], [-0.38, 1.4, 1.3], 0.04, 1.2, grey));
|
|
240
|
+
parts.push(box([-0.38, 1.5, 1.3], [0.26, 0.16, 0.18], 0, 1.0, 0, [0.5, 0.52, 0.56]));
|
|
241
|
+
parts.push(strut([0.4, 0.6, 1.05], [0.4, 1.8, 1.05], 0.012, 1.0, DARK));
|
|
242
|
+
// the boxes: the batteries at the front, the tools at the back
|
|
243
|
+
for (const x of [-0.4, 0.4])
|
|
244
|
+
parts.push(box([x, 0.76, 0.85], [0.36, 0.26, 0.38], 0, 1.0, 0, SILVER));
|
|
245
|
+
parts.push(box([0, 0.78, -1.15], [0.9, 0.3, 0.5], 0, 1.05, 0, SILVER));
|
|
246
|
+
return parts;
|
|
247
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Look } from "./view.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A site's record.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { siteById, type SurfaceSite } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* const site: SurfaceSite | undefined = siteById("apollo-17");
|
|
10
|
+
* console.log(site?.name.en, site?.lat, site?.lon);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface SurfaceSite {
|
|
14
|
+
/** The name in the `site` attribute. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** The body it is on. */
|
|
17
|
+
body: "moon";
|
|
18
|
+
name: {
|
|
19
|
+
en: string;
|
|
20
|
+
ja: string;
|
|
21
|
+
};
|
|
22
|
+
/** Planetocentric degrees. */
|
|
23
|
+
lat: number;
|
|
24
|
+
lon: number;
|
|
25
|
+
/** The site's place in the Moon's list of places (`/places`), which the orbit view turns to when it lands here. */
|
|
26
|
+
place: string;
|
|
27
|
+
/** A moment with a low Sun and long shadows, milliseconds since 1970: the landing itself. */
|
|
28
|
+
time: number;
|
|
29
|
+
/** Where to look first: toward the biggest mountain near. */
|
|
30
|
+
look: Look;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The sites with heights. The Apollo 17 landing site stands in Taurus-Littrow, a valley a few kilometres wide between mountains 2 kilometres high; it is first looked at toward the South Massif,
|
|
34
|
+
* at the moment of the landing, with the Sun 13 degrees up and the Earth above the mountain.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { SURFACE_SITES } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
39
|
+
*
|
|
40
|
+
* console.log(SURFACE_SITES.map((site) => site.id).join(", "));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const SURFACE_SITES: readonly SurfaceSite[];
|
|
44
|
+
/**
|
|
45
|
+
* A site by name, or `undefined`.
|
|
46
|
+
*
|
|
47
|
+
* @param id - The site's name, as in the `site` attribute.
|
|
48
|
+
* @returns The site's record, or `undefined` when there is no such site.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { siteById } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
53
|
+
*
|
|
54
|
+
* const site = siteById("apollo-17");
|
|
55
|
+
* console.log(site?.name.en, siteById("nowhere"));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const siteById: (id: string) => SurfaceSite | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sites with heights. The Apollo 17 landing site stands in Taurus-Littrow, a valley a few kilometres wide between mountains 2 kilometres high; it is first looked at toward the South Massif,
|
|
3
|
+
* at the moment of the landing, with the Sun 13 degrees up and the Earth above the mountain.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { SURFACE_SITES } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* console.log(SURFACE_SITES.map((site) => site.id).join(", "));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const SURFACE_SITES = [
|
|
13
|
+
{
|
|
14
|
+
id: "apollo-17",
|
|
15
|
+
body: "moon",
|
|
16
|
+
name: { en: "Apollo 17, Taurus-Littrow", ja: "アポロ17号、タウルス・リットロー" },
|
|
17
|
+
lat: 20.1911,
|
|
18
|
+
lon: 30.7723,
|
|
19
|
+
place: "moon/apollo-17-lunar-module",
|
|
20
|
+
time: Date.UTC(1972, 11, 11, 19, 54),
|
|
21
|
+
look: { azimuth: 232, pitch: 13, fov: 74 },
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* A site by name, or `undefined`.
|
|
26
|
+
*
|
|
27
|
+
* @param id - The site's name, as in the `site` attribute.
|
|
28
|
+
* @returns The site's record, or `undefined` when there is no such site.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { siteById } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
33
|
+
*
|
|
34
|
+
* const site = siteById("apollo-17");
|
|
35
|
+
* console.log(site?.name.en, siteById("nowhere"));
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const siteById = (id) => SURFACE_SITES.find((site) => site.id === id);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Vec3 } from "../vec.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A direction in the viewer's own sky: a unit vector east, north and up (`enu`), and the same as an azimuth (degrees clockwise from north) and an altitude (degrees above the horizon).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { moonSky, type SkyDirection } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* const sun: SkyDirection = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54)).sun;
|
|
10
|
+
* console.log(`${sun.azimuth.toFixed(0)} degrees clockwise from north, ${sun.altitude.toFixed(0)} degrees up`);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface SkyDirection {
|
|
14
|
+
enu: Vec3;
|
|
15
|
+
azimuth: number;
|
|
16
|
+
altitude: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What the sky holds at one place and moment.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { moonSky, type MoonSky } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
24
|
+
*
|
|
25
|
+
* const sky: MoonSky = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
26
|
+
* console.log(`the Earth is ${(sky.earthIllumination * 100).toFixed(0)}% lit and ${sky.earthDiameter.toFixed(1)} degrees across`);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface MoonSky {
|
|
30
|
+
/** The Sun's centre. */
|
|
31
|
+
sun: SkyDirection;
|
|
32
|
+
/** The Sun's angular diameter in degrees (about 0.53 from the Moon). */
|
|
33
|
+
sunDiameter: number;
|
|
34
|
+
/** The Earth's centre. */
|
|
35
|
+
earth: SkyDirection;
|
|
36
|
+
/** The Earth's angular diameter in degrees (about 1.9). */
|
|
37
|
+
earthDiameter: number;
|
|
38
|
+
/** The share of the Earth's disc that is lit, 0 (new) to 1 (full). It is the opposite of the Moon's phase from the Earth: a full Moon is a new Earth. */
|
|
39
|
+
earthIllumination: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The local frame of a point on the Moon at a moment: its east, north and up as unit vectors in the frame of `apparent`, in which `[0, 0, 1]` is toward the Earth.
|
|
43
|
+
*
|
|
44
|
+
* @param lat - Latitude in degrees, positive north.
|
|
45
|
+
* @param lon - Longitude in degrees, positive east.
|
|
46
|
+
* @param time - Milliseconds since 1970.
|
|
47
|
+
* @returns The axes, and `toLocal`, which turns a vector of that frame into east, north and up.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { localFrame } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
52
|
+
*
|
|
53
|
+
* const frame = localFrame(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
54
|
+
* console.log(frame.toLocal([0, 0, 1]).map((n) => n.toFixed(2)).join(", "));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function localFrame(lat: number, lon: number, time: number): {
|
|
58
|
+
east: Vec3;
|
|
59
|
+
north: Vec3;
|
|
60
|
+
up: Vec3;
|
|
61
|
+
toLocal(v: Vec3): Vec3;
|
|
62
|
+
light: Vec3;
|
|
63
|
+
distanceKm: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The Sun and the Earth in the sky of a point on the Moon at a moment, from the package's own ephemeris: the Moon's real turn and libration, the Sun's real place.
|
|
67
|
+
*
|
|
68
|
+
* @param lat - Latitude in degrees, positive north.
|
|
69
|
+
* @param lon - Longitude in degrees, positive east.
|
|
70
|
+
* @param time - Milliseconds since 1970.
|
|
71
|
+
* @returns The two directions, their sizes and the Earth's lit share.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { moonSky } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
76
|
+
*
|
|
77
|
+
* const sky = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
78
|
+
* console.log(`the Sun is ${sky.sun.altitude.toFixed(0)} degrees up, the Earth ${sky.earth.altitude.toFixed(0)}`);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function moonSky(lat: number, lon: number, time: number): MoonSky;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The sky as a person standing on the Moon sees it: where the Sun and the Earth are, and how much of the Earth is lit. Pure: no DOM, no clock; the date is an argument.
|
|
2
|
+
import { apparent } from "../ephemeris.js";
|
|
3
|
+
import { surfacePoint } from "../pose.js";
|
|
4
|
+
import { cross, dot, unit, DEG } from "../vec.js";
|
|
5
|
+
const direction = (enu) => ({
|
|
6
|
+
enu,
|
|
7
|
+
azimuth: (Math.atan2(enu[0], enu[1]) * DEG + 360) % 360,
|
|
8
|
+
altitude: Math.asin(Math.max(-1, Math.min(1, enu[2]))) * DEG,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* The local frame of a point on the Moon at a moment: its east, north and up as unit vectors in the frame of `apparent`, in which `[0, 0, 1]` is toward the Earth.
|
|
12
|
+
*
|
|
13
|
+
* @param lat - Latitude in degrees, positive north.
|
|
14
|
+
* @param lon - Longitude in degrees, positive east.
|
|
15
|
+
* @param time - Milliseconds since 1970.
|
|
16
|
+
* @returns The axes, and `toLocal`, which turns a vector of that frame into east, north and up.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { localFrame } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
21
|
+
*
|
|
22
|
+
* const frame = localFrame(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
23
|
+
* console.log(frame.toLocal([0, 0, 1]).map((n) => n.toFixed(2)).join(", "));
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function localFrame(lat, lon, time) {
|
|
27
|
+
const moon = apparent("moon", time);
|
|
28
|
+
const up = surfacePoint(moon, lon, lat);
|
|
29
|
+
const east = unit(cross(moon.pole, up));
|
|
30
|
+
const north = cross(up, east);
|
|
31
|
+
return { east, north, up, toLocal: (v) => [dot(v, east), dot(v, north), dot(v, up)], light: moon.light, distanceKm: moon.distanceKm };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The Sun and the Earth in the sky of a point on the Moon at a moment, from the package's own ephemeris: the Moon's real turn and libration, the Sun's real place.
|
|
35
|
+
*
|
|
36
|
+
* @param lat - Latitude in degrees, positive north.
|
|
37
|
+
* @param lon - Longitude in degrees, positive east.
|
|
38
|
+
* @param time - Milliseconds since 1970.
|
|
39
|
+
* @returns The two directions, their sizes and the Earth's lit share.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { moonSky } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
44
|
+
*
|
|
45
|
+
* const sky = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
46
|
+
* console.log(`the Sun is ${sky.sun.altitude.toFixed(0)} degrees up, the Earth ${sky.earth.altitude.toFixed(0)}`);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function moonSky(lat, lon, time) {
|
|
50
|
+
const frame = localFrame(lat, lon, time);
|
|
51
|
+
const sun = frame.toLocal(unit(frame.light));
|
|
52
|
+
const earth = frame.toLocal([0, 0, 1]);
|
|
53
|
+
return {
|
|
54
|
+
sun: direction(sun),
|
|
55
|
+
sunDiameter: 0.533,
|
|
56
|
+
earth: direction(earth),
|
|
57
|
+
earthDiameter: (2 * Math.asin(6371 / frame.distanceKm)) * DEG,
|
|
58
|
+
earthIllumination: (1 - dot(sun, earth)) / 2,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Vec3 } from "../vec.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Eye height of a standing person in metres.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { EYE_HEIGHT } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* console.log(`eyes ${EYE_HEIGHT} m above the ground`);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const EYE_HEIGHT = 1.7;
|
|
13
|
+
/**
|
|
14
|
+
* The widest and the narrowest view, in degrees from the top of the picture to its bottom: zoom is the field of view.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { FOV_LIMITS } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
19
|
+
*
|
|
20
|
+
* console.log(`zoom runs from ${FOV_LIMITS.min} to ${FOV_LIMITS.max} degrees`);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const FOV_LIMITS: {
|
|
24
|
+
readonly min: 8;
|
|
25
|
+
readonly max: 100;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A person's walking pace, metres a second.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { WALK_SPEED } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
33
|
+
*
|
|
34
|
+
* console.log(`${(WALK_SPEED * 10).toFixed(0)} m in ten seconds`);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const WALK_SPEED = 1.4;
|
|
38
|
+
/**
|
|
39
|
+
* Where the eyes look: an azimuth (degrees clockwise from north), a pitch (degrees above the horizon) and a field of view (degrees, top to bottom).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { siteById, type Look } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
44
|
+
*
|
|
45
|
+
* const look: Look = siteById("apollo-17")!.look;
|
|
46
|
+
* console.log(`toward ${look.azimuth} degrees, ${look.pitch} up, ${look.fov} wide`);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export interface Look {
|
|
50
|
+
azimuth: number;
|
|
51
|
+
pitch: number;
|
|
52
|
+
fov: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A look held within what makes sense: the azimuth round the compass, the pitch short of straight up and down, the field of view within `FOV_LIMITS`.
|
|
56
|
+
*
|
|
57
|
+
* @param look - Any look, however far out of range.
|
|
58
|
+
* @returns A new look: the azimuth from 0 up to but not including 360, the pitch from -85 to 85 and the field of view within `FOV_LIMITS`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { clampLook } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
63
|
+
*
|
|
64
|
+
* console.log(clampLook({ azimuth: -90, pitch: 120, fov: 200 }));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function clampLook(look: Look): Look;
|
|
68
|
+
/**
|
|
69
|
+
* The direction a look points, in the scene's frame: x to the east, y up and z to the south (so north is -z and a camera looking north has the east on its right).
|
|
70
|
+
*
|
|
71
|
+
* @param look - The look.
|
|
72
|
+
* @returns A unit vector.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { forward } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
77
|
+
*
|
|
78
|
+
* console.log(forward({ azimuth: 90, pitch: 0, fov: 60 }).map((n) => n.toFixed(2)).join(", "));
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function forward(look: Look): Vec3;
|
|
82
|
+
/** The camera's right, up and forward axes in the scene's frame for a look: what a flat thing that faces the viewer is drawn along. */
|
|
83
|
+
export declare function cameraAxes(look: Look): {
|
|
84
|
+
right: Vec3;
|
|
85
|
+
up: Vec3;
|
|
86
|
+
forward: Vec3;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The view and projection together, as a column-major 4 x 4 matrix (a float array of sixteen numbers) for a vertex shader: eyes at `eye` in the scene's frame, looking along `look`.
|
|
90
|
+
*
|
|
91
|
+
* @param eye - Where the eyes are, in the scene's frame (east, up, south), in metres.
|
|
92
|
+
* @param look - Which way they look and how wide.
|
|
93
|
+
* @param aspect - The picture's width over its height.
|
|
94
|
+
* @param near - The nearest distance drawn, in metres.
|
|
95
|
+
* @param far - The farthest distance drawn, in metres.
|
|
96
|
+
* @returns The sixteen numbers of the matrix, column by column.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { viewProjection } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
101
|
+
*
|
|
102
|
+
* const matrix = viewProjection([0, 1.7, 0], { azimuth: 0, pitch: 0, fov: 60 }, 16 / 9);
|
|
103
|
+
* console.log(matrix.length);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function viewProjection(eye: Vec3, look: Look, aspect: number, near?: number, far?: number): Float32Array;
|
|
107
|
+
/**
|
|
108
|
+
* A position moved over the ground by a walk: `ahead` metres along the look's heading (negative backs up) and `aside` to its right, in the site's plane (east, north).
|
|
109
|
+
*
|
|
110
|
+
* @param position - Where the walker is, in metres east and north of the site.
|
|
111
|
+
* @param azimuth - The heading, in degrees clockwise from north.
|
|
112
|
+
* @param ahead - Metres along the heading; negative backs up.
|
|
113
|
+
* @param aside - Metres to the right of the heading; negative goes left.
|
|
114
|
+
* @returns The new position, in metres east and north of the site.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { stepOver } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
119
|
+
*
|
|
120
|
+
* console.log(stepOver({ east: 0, north: 0 }, 0, 10, 0));
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function stepOver(position: {
|
|
124
|
+
east: number;
|
|
125
|
+
north: number;
|
|
126
|
+
}, azimuth: number, ahead: number, aside: number): {
|
|
127
|
+
east: number;
|
|
128
|
+
north: number;
|
|
129
|
+
};
|