@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,127 @@
|
|
|
1
|
+
import { type Part } from "./shapes.ts";
|
|
2
|
+
/**
|
|
3
|
+
* One thing at a site: where it stands (metres east and north of the site point), what it is, and for the rover the way it points.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* const lander = objectsOf("apollo-17").find((object) => object.kind === "lander");
|
|
10
|
+
* console.log(lander?.name.en, lander?.east, lander?.north);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface SiteObject {
|
|
14
|
+
id: string;
|
|
15
|
+
kind: "lander" | "rover" | "flag" | "station" | "instrument";
|
|
16
|
+
name: {
|
|
17
|
+
en: string;
|
|
18
|
+
ja: string;
|
|
19
|
+
};
|
|
20
|
+
east: number;
|
|
21
|
+
north: number;
|
|
22
|
+
/** The way a vehicle points, degrees clockwise from north (the rover's, read from the end of its path by this package). */
|
|
23
|
+
heading?: number;
|
|
24
|
+
/** Where the published position is, planetocentric degrees (the rover's is a reading of a line, so it has none). */
|
|
25
|
+
lat?: number;
|
|
26
|
+
lon?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The things at a site, at their published places; none for a site that has none.
|
|
30
|
+
*
|
|
31
|
+
* @param site - A site's name from `SURFACE_SITES`.
|
|
32
|
+
* @returns The objects.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
37
|
+
*
|
|
38
|
+
* console.log(objectsOf("apollo-17").map((object) => object.id).join(", "), objectsOf("nowhere").length);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function objectsOf(site: string): readonly SiteObject[];
|
|
42
|
+
/**
|
|
43
|
+
* The rover's traverses at a site as lines, each east, north, east, north, ... in metres from the site point (the published path, digitised from the orbiter's images).
|
|
44
|
+
*
|
|
45
|
+
* @param site - A site's name from `SURFACE_SITES`.
|
|
46
|
+
* @returns The lines, or none.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { traverseOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
51
|
+
*
|
|
52
|
+
* const lines = traverseOf("apollo-17");
|
|
53
|
+
* console.log(lines.length, "traverses,", lines.reduce((n, line) => n + line.length / 2, 0), "points");
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function traverseOf(site: string): readonly (readonly number[])[];
|
|
57
|
+
/**
|
|
58
|
+
* How far round an object the made craters and rocks keep away: nothing is made inside `inner` metres of its place, and the ground is all its own again from `outer` metres.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { KEEP_OUT } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
63
|
+
*
|
|
64
|
+
* console.log(KEEP_OUT.lander.inner, KEEP_OUT.lander.outer);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare const KEEP_OUT: Record<SiteObject["kind"], {
|
|
68
|
+
inner: number;
|
|
69
|
+
outer: number;
|
|
70
|
+
}>;
|
|
71
|
+
export type { Part } from "./shapes.ts";
|
|
72
|
+
/**
|
|
73
|
+
* The shape of one object as plain parts placed at its site: the lunar module's descent stage (an octagonal gold body on four splayed legs with braces and footpads, a ladder, a bell under it), the rover (a frame
|
|
74
|
+
* on four wheels with fenders, two seats, a console, the dish and the camera on their masts), the flag, the ALSEP station and the transmitter. `base` is the height of the ground at the object's place in metres over
|
|
75
|
+
* the site's ground; the shapes stand on it. All of it is this package's drawing from published sizes: it is no model of the real thing.
|
|
76
|
+
*
|
|
77
|
+
* @param object - The object.
|
|
78
|
+
* @param base - The ground's height at its place.
|
|
79
|
+
* @returns The parts, in the site's plane (x east, y up, z north).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { objectParts, objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
84
|
+
*
|
|
85
|
+
* const lander = objectsOf("apollo-17").find((object) => object.kind === "lander")!;
|
|
86
|
+
* const parts = objectParts(lander, 0);
|
|
87
|
+
* console.log(parts.length, "parts,", parts.reduce((n, part) => n + part.position.length / 9, 0), "triangles");
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function objectParts(object: SiteObject, base: number): Part[];
|
|
91
|
+
/**
|
|
92
|
+
* The shadows of an object's parts on the ground for a Sun at an azimuth and an altitude: for each part the convex hull of where its corners fall on the plane of its base, as triangles (x east, y up, z north) lifted a
|
|
93
|
+
* hair off the ground. Flat and hard-edged: the Moon has no air.
|
|
94
|
+
*
|
|
95
|
+
* @param parts - The object's parts, as `objectParts` makes them.
|
|
96
|
+
* @param base - The ground's height under it.
|
|
97
|
+
* @param azimuth - The Sun's azimuth, degrees clockwise from north.
|
|
98
|
+
* @param altitude - The Sun's altitude in degrees.
|
|
99
|
+
* @returns The triangles' corners, three numbers each.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { objectParts, objectsOf, partShadows } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
104
|
+
*
|
|
105
|
+
* const flag = objectsOf("apollo-17").find((object) => object.kind === "flag")!;
|
|
106
|
+
* const shadow = partShadows(objectParts(flag, 0), 0, 95, 13);
|
|
107
|
+
* console.log(shadow.length / 9, "triangles of shadow");
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function partShadows(parts: readonly Part[], base: number, azimuth: number, altitude: number): number[];
|
|
111
|
+
/**
|
|
112
|
+
* How much of the made ground (its craters and rocks) is kept at a point: 0 at an object's place, up to 1 where it is the ground's own again, so that no made crater cuts the lunar module's legs. The smallest over the objects.
|
|
113
|
+
*
|
|
114
|
+
* @param x - Metres east of the site point.
|
|
115
|
+
* @param y - Metres north of the site point.
|
|
116
|
+
* @param objects - The objects of the site.
|
|
117
|
+
* @returns A share from 0 to 1.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { keepAway, objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
122
|
+
*
|
|
123
|
+
* const objects = objectsOf("apollo-17");
|
|
124
|
+
* console.log(keepAway(objects[0]!.east, objects[0]!.north, objects), keepAway(500, 500, objects));
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function keepAway(x: number, y: number, objects: readonly SiteObject[]): number;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// Things at a site, drawn by this package at their published places: the lunar module's descent stage, the rover, the flag, the ALSEP station and the electrical-properties transmitter at Apollo 17, in plain shapes
|
|
2
|
+
// (boxes, cylinders, struts), with the rover's traverse as a faint line. The positions come from published coordinates (`objects-apollo-17.ts`, made by `scripts/make-apollo17-objects.py`); the shapes, the
|
|
3
|
+
// rover's heading and what the line looks like are made here, and the page says so. Pure: no DOM.
|
|
4
|
+
import { APOLLO_17_OBJECTS, APOLLO_17_TRAVERSE } from "./objects-apollo-17.js";
|
|
5
|
+
import { box, cylinder, landerParts, placePart, roverParts, strut } from "./shapes.js";
|
|
6
|
+
/**
|
|
7
|
+
* The things at a site, at their published places; none for a site that has none.
|
|
8
|
+
*
|
|
9
|
+
* @param site - A site's name from `SURFACE_SITES`.
|
|
10
|
+
* @returns The objects.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
15
|
+
*
|
|
16
|
+
* console.log(objectsOf("apollo-17").map((object) => object.id).join(", "), objectsOf("nowhere").length);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function objectsOf(site) {
|
|
20
|
+
return site === "apollo-17" ? APOLLO_17_OBJECTS : [];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The rover's traverses at a site as lines, each east, north, east, north, ... in metres from the site point (the published path, digitised from the orbiter's images).
|
|
24
|
+
*
|
|
25
|
+
* @param site - A site's name from `SURFACE_SITES`.
|
|
26
|
+
* @returns The lines, or none.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { traverseOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
31
|
+
*
|
|
32
|
+
* const lines = traverseOf("apollo-17");
|
|
33
|
+
* console.log(lines.length, "traverses,", lines.reduce((n, line) => n + line.length / 2, 0), "points");
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function traverseOf(site) {
|
|
37
|
+
return site === "apollo-17" ? APOLLO_17_TRAVERSE : [];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* How far round an object the made craters and rocks keep away: nothing is made inside `inner` metres of its place, and the ground is all its own again from `outer` metres.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { KEEP_OUT } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
45
|
+
*
|
|
46
|
+
* console.log(KEEP_OUT.lander.inner, KEEP_OUT.lander.outer);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const KEEP_OUT = {
|
|
50
|
+
lander: { inner: 9, outer: 15 },
|
|
51
|
+
rover: { inner: 4, outer: 8 },
|
|
52
|
+
flag: { inner: 2, outer: 5 },
|
|
53
|
+
station: { inner: 4, outer: 8 },
|
|
54
|
+
instrument: { inner: 2, outer: 5 },
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The shape of one object as plain parts placed at its site: the lunar module's descent stage (an octagonal gold body on four splayed legs with braces and footpads, a ladder, a bell under it), the rover (a frame
|
|
58
|
+
* on four wheels with fenders, two seats, a console, the dish and the camera on their masts), the flag, the ALSEP station and the transmitter. `base` is the height of the ground at the object's place in metres over
|
|
59
|
+
* the site's ground; the shapes stand on it. All of it is this package's drawing from published sizes: it is no model of the real thing.
|
|
60
|
+
*
|
|
61
|
+
* @param object - The object.
|
|
62
|
+
* @param base - The ground's height at its place.
|
|
63
|
+
* @returns The parts, in the site's plane (x east, y up, z north).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { objectParts, objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
68
|
+
*
|
|
69
|
+
* const lander = objectsOf("apollo-17").find((object) => object.kind === "lander")!;
|
|
70
|
+
* const parts = objectParts(lander, 0);
|
|
71
|
+
* console.log(parts.length, "parts,", parts.reduce((n, part) => n + part.position.length / 9, 0), "triangles");
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function objectParts(object, base) {
|
|
75
|
+
const { east: e, north: n } = object;
|
|
76
|
+
const at = (x, y, z) => [e + x, base + y, n + z];
|
|
77
|
+
switch (object.kind) {
|
|
78
|
+
case "lander":
|
|
79
|
+
return landerParts().map((part) => placePart(part, e, base, n, 0));
|
|
80
|
+
case "rover":
|
|
81
|
+
return roverParts().map((part) => placePart(part, e, base, n, ((object.heading ?? 0) * Math.PI) / 180));
|
|
82
|
+
case "flag":
|
|
83
|
+
return [cylinder(at(0, 0, 0), 0.015, 2.4, 6, 1.3, false, [0.85, 0.85, 0.88]), box(at(0.55, 2.0, 0), [1.1, 0.7, 0.012], 0, 1.7, 0, [0.9, 0.9, 0.95])];
|
|
84
|
+
case "station":
|
|
85
|
+
return [box(at(0, 0.25, 0), [0.7, 0.5, 0.5], 0.4, 1.4, 0, [0.9, 0.78, 0.45]), cylinder(at(1.0, 0, 0.3), 0.18, 0.55, 10, 0.9, false, DARKER), strut(at(-0.1, 0.5, 0), at(-0.1, 1.5, 0), 0.03, 1.3, [0.85, 0.85, 0.88])];
|
|
86
|
+
case "instrument":
|
|
87
|
+
return [box(at(0, 0.15, 0), [0.45, 0.3, 0.35], 0.5, 1.4, 0, [0.85, 0.85, 0.88])];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const DARKER = [0.35, 0.35, 0.38];
|
|
91
|
+
/**
|
|
92
|
+
* The shadows of an object's parts on the ground for a Sun at an azimuth and an altitude: for each part the convex hull of where its corners fall on the plane of its base, as triangles (x east, y up, z north) lifted a
|
|
93
|
+
* hair off the ground. Flat and hard-edged: the Moon has no air.
|
|
94
|
+
*
|
|
95
|
+
* @param parts - The object's parts, as `objectParts` makes them.
|
|
96
|
+
* @param base - The ground's height under it.
|
|
97
|
+
* @param azimuth - The Sun's azimuth, degrees clockwise from north.
|
|
98
|
+
* @param altitude - The Sun's altitude in degrees.
|
|
99
|
+
* @returns The triangles' corners, three numbers each.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { objectParts, objectsOf, partShadows } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
104
|
+
*
|
|
105
|
+
* const flag = objectsOf("apollo-17").find((object) => object.kind === "flag")!;
|
|
106
|
+
* const shadow = partShadows(objectParts(flag, 0), 0, 95, 13);
|
|
107
|
+
* console.log(shadow.length / 9, "triangles of shadow");
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function partShadows(parts, base, azimuth, altitude) {
|
|
111
|
+
const out = [];
|
|
112
|
+
if (altitude < 0.5)
|
|
113
|
+
return out;
|
|
114
|
+
const reach = 1 / Math.tan((Math.min(altitude, 89) * Math.PI) / 180);
|
|
115
|
+
const away = [-Math.sin((azimuth * Math.PI) / 180), -Math.cos((azimuth * Math.PI) / 180)];
|
|
116
|
+
for (const part of parts) {
|
|
117
|
+
const pts = [];
|
|
118
|
+
for (let i = 0; i < part.position.length; i += 3) {
|
|
119
|
+
const h = Math.max(0, part.position[i + 1] - base);
|
|
120
|
+
const clamp = Math.min(h * reach, 80);
|
|
121
|
+
pts.push([part.position[i] + away[0] * clamp, part.position[i + 2] + away[1] * clamp]);
|
|
122
|
+
pts.push([part.position[i], part.position[i + 2]]);
|
|
123
|
+
}
|
|
124
|
+
const hull = convexHull(pts);
|
|
125
|
+
for (let i = 1; i + 1 < hull.length; i += 1) {
|
|
126
|
+
for (const p of [hull[0], hull[i], hull[i + 1]])
|
|
127
|
+
out.push(p[0], base + 0.02, p[1]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
/** The convex hull of points on the plane, counter-clockwise (Andrew's monotone chain). */
|
|
133
|
+
function convexHull(points) {
|
|
134
|
+
const p = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
135
|
+
if (p.length < 3)
|
|
136
|
+
return p;
|
|
137
|
+
const cross2 = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
138
|
+
const lower = [];
|
|
139
|
+
for (const q of p) {
|
|
140
|
+
while (lower.length >= 2 && cross2(lower[lower.length - 2], lower[lower.length - 1], q) <= 0)
|
|
141
|
+
lower.pop();
|
|
142
|
+
lower.push(q);
|
|
143
|
+
}
|
|
144
|
+
const upper = [];
|
|
145
|
+
for (const q of [...p].reverse()) {
|
|
146
|
+
while (upper.length >= 2 && cross2(upper[upper.length - 2], upper[upper.length - 1], q) <= 0)
|
|
147
|
+
upper.pop();
|
|
148
|
+
upper.push(q);
|
|
149
|
+
}
|
|
150
|
+
lower.pop();
|
|
151
|
+
upper.pop();
|
|
152
|
+
return [...lower, ...upper];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* How much of the made ground (its craters and rocks) is kept at a point: 0 at an object's place, up to 1 where it is the ground's own again, so that no made crater cuts the lunar module's legs. The smallest over the objects.
|
|
156
|
+
*
|
|
157
|
+
* @param x - Metres east of the site point.
|
|
158
|
+
* @param y - Metres north of the site point.
|
|
159
|
+
* @param objects - The objects of the site.
|
|
160
|
+
* @returns A share from 0 to 1.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { keepAway, objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
165
|
+
*
|
|
166
|
+
* const objects = objectsOf("apollo-17");
|
|
167
|
+
* console.log(keepAway(objects[0]!.east, objects[0]!.north, objects), keepAway(500, 500, objects));
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export function keepAway(x, y, objects) {
|
|
171
|
+
let keep = 1;
|
|
172
|
+
for (const o of objects) {
|
|
173
|
+
const { inner, outer } = KEEP_OUT[o.kind];
|
|
174
|
+
const d = Math.hypot(x - o.east, y - o.north);
|
|
175
|
+
const t = Math.min(1, Math.max(0, (d - inner) / (outer - inner)));
|
|
176
|
+
keep = Math.min(keep, t * t * (3 - 2 * t));
|
|
177
|
+
}
|
|
178
|
+
return keep;
|
|
179
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Rock } from "./detail.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The arrays of the rocks' mesh, in the site's plane (east, up, north): `ROCK_VERTICES` (240) a rock, and 10 for its shadow.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { rockMesh, type RockMesh } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* const mesh: RockMesh = rockMesh([{ x: 2, y: 3, size: 0.5, shape: 0, turn: 0, tone: 1, flat: 0.6 }], () => 0, { azimuth: 95, altitude: 13 });
|
|
10
|
+
* console.log(mesh.count, mesh.position.length / 3, mesh.shadowIndex.length);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface RockMesh {
|
|
14
|
+
position: Float32Array;
|
|
15
|
+
normal: Float32Array;
|
|
16
|
+
tone: Float32Array;
|
|
17
|
+
count: number;
|
|
18
|
+
shadowPosition: Float32Array;
|
|
19
|
+
shadowUv: Float32Array;
|
|
20
|
+
shadowIndex: Uint32Array;
|
|
21
|
+
}
|
|
22
|
+
/** Vertices a rock's mesh has: 80 faces of 3. */
|
|
23
|
+
export declare const ROCK_VERTICES: number;
|
|
24
|
+
/** The three shapes: the cut icosahedron with each corner pulled in or out by a seeded share, in lumps (a corner takes the share of its neighbours too), so each shape is its own and none is a ball. */
|
|
25
|
+
export declare const SHAPES: readonly (readonly (readonly [number, number, number])[])[];
|
|
26
|
+
/**
|
|
27
|
+
* The mesh of a list of rocks standing on the ground, and a shadow for each.
|
|
28
|
+
*
|
|
29
|
+
* @param rocks - The rocks, from `rocksAround`.
|
|
30
|
+
* @param ground - The ground's height at a point (metres east and north of the site), the made craters on it and the Moon's curve taken off.
|
|
31
|
+
* @param sun - The Sun's azimuth (degrees clockwise from north) and altitude (degrees).
|
|
32
|
+
* @returns The arrays.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { rockMesh, rocksAround } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
37
|
+
*
|
|
38
|
+
* const mesh = rockMesh(rocksAround(0, 0, 20, 0.0024), () => 0, { azimuth: 95, altitude: 13 });
|
|
39
|
+
* console.log(mesh.count, "rocks");
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function rockMesh(rocks: readonly Rock[], ground: (x: number, y: number) => number, sun: {
|
|
43
|
+
azimuth: number;
|
|
44
|
+
altitude: number;
|
|
45
|
+
}): RockMesh;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// The rocks and their shadows as geometry: each rock a small faceted stone of one of three shapes, set on the ground, and a quad of shadow laid on the ground away from the Sun. Pure: the
|
|
2
|
+
// ground's height is a function handed in. All made, none measured.
|
|
3
|
+
import { pcg2d, unit24 } from "./detail.js";
|
|
4
|
+
const PHI = (1 + Math.sqrt(5)) / 2;
|
|
5
|
+
const ICOSAHEDRON = [
|
|
6
|
+
[-1, PHI, 0], [1, PHI, 0], [-1, -PHI, 0], [1, -PHI, 0],
|
|
7
|
+
[0, -1, PHI], [0, 1, PHI], [0, -1, -PHI], [0, 1, -PHI],
|
|
8
|
+
[PHI, 0, -1], [PHI, 0, 1], [-PHI, 0, -1], [-PHI, 0, 1],
|
|
9
|
+
].map((v) => {
|
|
10
|
+
const l = Math.hypot(v[0], v[1], v[2]);
|
|
11
|
+
return [v[0] / l, v[1] / l, v[2] / l];
|
|
12
|
+
});
|
|
13
|
+
const FACES = [
|
|
14
|
+
[0, 11, 5], [0, 5, 1], [0, 1, 7], [0, 7, 10], [0, 10, 11], [1, 5, 9], [5, 11, 4], [11, 10, 2], [10, 7, 6], [7, 1, 8],
|
|
15
|
+
[3, 9, 4], [3, 4, 2], [3, 2, 6], [3, 6, 8], [3, 8, 9], [4, 9, 5], [2, 4, 11], [6, 2, 10], [8, 6, 7], [9, 8, 1],
|
|
16
|
+
];
|
|
17
|
+
/** The icosahedron cut once: each edge's middle pushed out to the sphere, so 42 corners and 80 faces, round enough that a rock seen close is not a die. */
|
|
18
|
+
const subdivided = (() => {
|
|
19
|
+
const vertices = [...ICOSAHEDRON];
|
|
20
|
+
const middle = new Map();
|
|
21
|
+
const mid = (a, b) => {
|
|
22
|
+
const key = a < b ? `${a}:${b}` : `${b}:${a}`;
|
|
23
|
+
let at = middle.get(key);
|
|
24
|
+
if (at === undefined) {
|
|
25
|
+
const p = vertices[a];
|
|
26
|
+
const q = vertices[b];
|
|
27
|
+
const m = [(p[0] + q[0]) / 2, (p[1] + q[1]) / 2, (p[2] + q[2]) / 2];
|
|
28
|
+
const l = Math.hypot(m[0], m[1], m[2]);
|
|
29
|
+
at = vertices.push([m[0] / l, m[1] / l, m[2] / l]) - 1;
|
|
30
|
+
middle.set(key, at);
|
|
31
|
+
}
|
|
32
|
+
return at;
|
|
33
|
+
};
|
|
34
|
+
const faces = [];
|
|
35
|
+
for (const [a, b, c] of FACES) {
|
|
36
|
+
const ab = mid(a, b);
|
|
37
|
+
const bc = mid(b, c);
|
|
38
|
+
const ca = mid(c, a);
|
|
39
|
+
faces.push([a, ab, ca], [b, bc, ab], [c, ca, bc], [ab, bc, ca]);
|
|
40
|
+
}
|
|
41
|
+
return { vertices, faces };
|
|
42
|
+
})();
|
|
43
|
+
/** Vertices a rock's mesh has: 80 faces of 3. */
|
|
44
|
+
export const ROCK_VERTICES = subdivided.faces.length * 3;
|
|
45
|
+
/** The three shapes: the cut icosahedron with each corner pulled in or out by a seeded share, in lumps (a corner takes the share of its neighbours too), so each shape is its own and none is a ball. */
|
|
46
|
+
export const SHAPES = [0, 1, 2].map((shape) => {
|
|
47
|
+
const raw = subdivided.vertices.map((_, i) => 0.78 + 0.42 * unit24(pcg2d(shape * 101 + 5, i * 13 + 9)[0]));
|
|
48
|
+
return subdivided.vertices.map((v, i) => {
|
|
49
|
+
// smoothed over the corner's own face neighbours, so the lumps are broad
|
|
50
|
+
let sum = raw[i];
|
|
51
|
+
let n = 1;
|
|
52
|
+
for (const f of subdivided.faces) {
|
|
53
|
+
if (f[0] === i || f[1] === i || f[2] === i) {
|
|
54
|
+
for (const j of f) {
|
|
55
|
+
if (j !== i) {
|
|
56
|
+
sum += raw[j];
|
|
57
|
+
n += 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const k = (raw[i] + sum / n) / 2;
|
|
63
|
+
return [v[0] * k, v[1] * k, v[2] * k];
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
/** How many segments a shadow is cut into along its length, so it follows the ground it lies on. */
|
|
67
|
+
const SEGMENTS = 4;
|
|
68
|
+
/**
|
|
69
|
+
* The mesh of a list of rocks standing on the ground, and a shadow for each.
|
|
70
|
+
*
|
|
71
|
+
* @param rocks - The rocks, from `rocksAround`.
|
|
72
|
+
* @param ground - The ground's height at a point (metres east and north of the site), the made craters on it and the Moon's curve taken off.
|
|
73
|
+
* @param sun - The Sun's azimuth (degrees clockwise from north) and altitude (degrees).
|
|
74
|
+
* @returns The arrays.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { rockMesh, rocksAround } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
79
|
+
*
|
|
80
|
+
* const mesh = rockMesh(rocksAround(0, 0, 20, 0.0024), () => 0, { azimuth: 95, altitude: 13 });
|
|
81
|
+
* console.log(mesh.count, "rocks");
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function rockMesh(rocks, ground, sun) {
|
|
85
|
+
const n = rocks.length;
|
|
86
|
+
const per = ROCK_VERTICES;
|
|
87
|
+
const position = new Float32Array(n * per * 3);
|
|
88
|
+
const normal = new Float32Array(n * per * 3);
|
|
89
|
+
const tone = new Float32Array(n * per);
|
|
90
|
+
const shadowPosition = new Float32Array(n * (SEGMENTS + 1) * 2 * 3);
|
|
91
|
+
const shadowUv = new Float32Array(n * (SEGMENTS + 1) * 2 * 2);
|
|
92
|
+
const shadowIndex = new Uint32Array(n * SEGMENTS * 6);
|
|
93
|
+
const away = ((sun.azimuth + 180) * Math.PI) / 180;
|
|
94
|
+
const ax = Math.sin(away);
|
|
95
|
+
const ay = Math.cos(away);
|
|
96
|
+
const tan = Math.tan((Math.max(sun.altitude, 0.8) * Math.PI) / 180);
|
|
97
|
+
let p = 0;
|
|
98
|
+
let q = 0;
|
|
99
|
+
let sp = 0;
|
|
100
|
+
let su = 0;
|
|
101
|
+
let si = 0;
|
|
102
|
+
rocks.forEach((rock) => {
|
|
103
|
+
const base = SHAPES[rock.shape];
|
|
104
|
+
const half = rock.size / 2;
|
|
105
|
+
const sx = half;
|
|
106
|
+
const sz = half * (0.55 + 0.45 * ((rock.tone * 7) % 1));
|
|
107
|
+
const sy = half * rock.flat;
|
|
108
|
+
const c = Math.cos(rock.turn);
|
|
109
|
+
const s = Math.sin(rock.turn);
|
|
110
|
+
// half buried: the middle is only a quarter of its height over the ground
|
|
111
|
+
const lift = sy * 0.25;
|
|
112
|
+
const ground0 = ground(rock.x, rock.y);
|
|
113
|
+
const corner = base.map(([vx, vy, vz]) => {
|
|
114
|
+
const lx = vx * sx;
|
|
115
|
+
const lz = vz * sz;
|
|
116
|
+
const ly = vy * sy;
|
|
117
|
+
// the smooth normal of the ellipsoid it is cut from, turned with the rock: a stone with lumps, not a die
|
|
118
|
+
const ex = vx / sx;
|
|
119
|
+
const ey = vy / sy;
|
|
120
|
+
const ez = vz / sz;
|
|
121
|
+
const l = Math.hypot(ex, ey, ez) || 1;
|
|
122
|
+
const nx0 = ex / l;
|
|
123
|
+
const nz0 = ez / l;
|
|
124
|
+
return { pos: [rock.x + lx * c - lz * s, ground0 + lift + ly, rock.y + lx * s + lz * c], normal: [nx0 * c - nz0 * s, ey / l, nx0 * s + nz0 * c] };
|
|
125
|
+
});
|
|
126
|
+
for (const [a, b, d] of subdivided.faces) {
|
|
127
|
+
for (const k of [a, b, d]) {
|
|
128
|
+
const v = corner[k];
|
|
129
|
+
position[p++] = v.pos[0];
|
|
130
|
+
position[p++] = v.pos[1];
|
|
131
|
+
position[p++] = v.pos[2];
|
|
132
|
+
normal[q++] = v.normal[0];
|
|
133
|
+
normal[q++] = v.normal[1];
|
|
134
|
+
normal[q++] = v.normal[2];
|
|
135
|
+
tone[(p - 3) / 3] = rock.tone;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// its shadow: along the way the light goes, as long as the rock is high over tan(the Sun's altitude), as wide as the rock
|
|
139
|
+
const length = Math.min(14, (sy * 2 + lift) / tan);
|
|
140
|
+
const width = Math.max(sx, sz) * 0.85;
|
|
141
|
+
const firstVertex = sp / 3;
|
|
142
|
+
for (let k = 0; k <= SEGMENTS; k += 1) {
|
|
143
|
+
const u = k / SEGMENTS;
|
|
144
|
+
const w = width * (1 - 0.45 * u);
|
|
145
|
+
for (const side of [-1, 1]) {
|
|
146
|
+
const x = rock.x + ax * length * u - ay * w * side;
|
|
147
|
+
const y = rock.y + ay * length * u + ax * w * side;
|
|
148
|
+
shadowPosition[sp++] = x;
|
|
149
|
+
shadowPosition[sp++] = ground(x, y) + 0.03;
|
|
150
|
+
shadowPosition[sp++] = y;
|
|
151
|
+
shadowUv[su++] = u;
|
|
152
|
+
shadowUv[su++] = side;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (let k = 0; k < SEGMENTS; k += 1) {
|
|
156
|
+
const a = firstVertex + k * 2;
|
|
157
|
+
shadowIndex[si++] = a;
|
|
158
|
+
shadowIndex[si++] = a + 1;
|
|
159
|
+
shadowIndex[si++] = a + 2;
|
|
160
|
+
shadowIndex[si++] = a + 1;
|
|
161
|
+
shadowIndex[si++] = a + 3;
|
|
162
|
+
shadowIndex[si++] = a + 2;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return { position, normal, tone, count: n, shadowPosition, shadowUv, shadowIndex };
|
|
166
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Item3D, Scene3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
2
|
+
import type { ThreeParts } from "../scene/body.ts";
|
|
3
|
+
import { type SiteObject } from "./objects.ts";
|
|
4
|
+
import type { HeightLevel, TerrainManifest } from "./height.ts";
|
|
5
|
+
import type { MoonSky } from "./sky.ts";
|
|
6
|
+
import { type Look } from "./view.ts";
|
|
7
|
+
/** Everything that changes how the view looks. The element fills one in and hands it over; the scene holds no clock of its own. */
|
|
8
|
+
export interface SurfaceState {
|
|
9
|
+
/** The eyes: metres east and north of the site, and metres over the site's ground (the site's own height is the origin). */
|
|
10
|
+
eye: {
|
|
11
|
+
east: number;
|
|
12
|
+
north: number;
|
|
13
|
+
up: number;
|
|
14
|
+
};
|
|
15
|
+
look: Look;
|
|
16
|
+
sky: MoonSky;
|
|
17
|
+
/** Brightness: the sunlit ground of an albedo of 0.14 comes out as this share of white times the Sun's height factor (default 4.5). */
|
|
18
|
+
exposure?: number;
|
|
19
|
+
/** The ground's own brightness, 0 to 1 (default 0.14, a grey a little lighter than the Moon's mean). */
|
|
20
|
+
albedo?: number;
|
|
21
|
+
/** Whether the ground shadows itself (default true; false is a try-out, a lit slope with no shadow). */
|
|
22
|
+
shadows?: boolean;
|
|
23
|
+
/** Whether the made detail (craters, roughness) is there (default true). */
|
|
24
|
+
detail?: boolean;
|
|
25
|
+
/** How much the draw spends on shadows: `full` (the default), `medium` or `fast` (the near march shortened, the made craters left out of it): a draw while the view moves is `fast`. */
|
|
26
|
+
quality?: "full" | "medium" | "fast";
|
|
27
|
+
/** The share of the canvas's width and height the ground is drawn at, 1 (the default) to 0.25: below 1 it is drawn to a smaller target and stretched, which is what a draw while the view moves does on a machine that is slow. It needs `WebGLRenderTarget` in the three.js module (a page's own cut-down module may not have it; the draw is then at full size). */
|
|
28
|
+
scale?: number;
|
|
29
|
+
/** 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). */
|
|
30
|
+
objects?: boolean;
|
|
31
|
+
/** Time the next draw to the end of the graphics queue (it waits for the card, so it is for a few draws, not every one). */
|
|
32
|
+
measure?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The scene the shared renderer draws, with the one call that moves it. */
|
|
35
|
+
export interface SurfaceScene extends Scene3D {
|
|
36
|
+
apply(state: SurfaceState): void;
|
|
37
|
+
/** Send what changed to the card: the names of the levels (`h5`), picture levels (`a5`) and horizon maps (`horizon:h5`) whose bytes have changed since. The rocks are made again on the next `apply`. */
|
|
38
|
+
refresh(ids: Iterable<string>): void;
|
|
39
|
+
/** The rocks made round the eyes now. */
|
|
40
|
+
readonly rocks: number;
|
|
41
|
+
/** How long the last measured draw took, in milliseconds, the card finished (asked for with `measure` in the state: a pixel is read back to wait for the card), or `undefined` before one. */
|
|
42
|
+
readonly drawMs: number | undefined;
|
|
43
|
+
/** The mesh's size, for a test or a status line. */
|
|
44
|
+
readonly mesh: {
|
|
45
|
+
rings: number;
|
|
46
|
+
rays: number;
|
|
47
|
+
triangles: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface SurfaceItemOptions {
|
|
51
|
+
/** The pyramid's levels, finest first, filled with their heights. */
|
|
52
|
+
levels: readonly HeightLevel[];
|
|
53
|
+
/** The ground picture's levels, where the site has them. */
|
|
54
|
+
pictures?: readonly HeightLevel[];
|
|
55
|
+
/** The baked horizons (see the manifest's `horizon`), where the site has them. */
|
|
56
|
+
horizons?: readonly {
|
|
57
|
+
id: string;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
data: Uint8Array;
|
|
61
|
+
}[];
|
|
62
|
+
/** The ground's height at a point, metres east and north of the site, for the rocks to stand on: the measured heights, the made craters, the Moon's curve taken off. */
|
|
63
|
+
groundY?(east: number, north: number): number;
|
|
64
|
+
manifest: TerrainManifest;
|
|
65
|
+
/** The things at the site, at their published places, and the rover's traverses as lines (east, north, east, north, ...). */
|
|
66
|
+
objects?: readonly SiteObject[];
|
|
67
|
+
traverse?: readonly (readonly number[])[];
|
|
68
|
+
/** A key that changes whenever the picture would: the renderer keeps one still for each key. */
|
|
69
|
+
key: string;
|
|
70
|
+
}
|
|
71
|
+
/** The Moon's standing view for one site as an item of the shared renderer. */
|
|
72
|
+
export declare function createSurfaceItem(options: SurfaceItemOptions): Item3D<ThreeParts>;
|