@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/NOTICE.md +12 -0
  3. package/README.md +4 -3
  4. package/dist/scene/body.d.ts +1 -1
  5. package/dist/scene/textures.d.ts +2 -2
  6. package/dist/space/element.d.ts +7 -0
  7. package/dist/space/element.js +12 -0
  8. package/dist/surface/detail.d.ts +186 -0
  9. package/dist/surface/detail.js +316 -0
  10. package/dist/surface/element.d.ts +103 -0
  11. package/dist/surface/element.js +685 -0
  12. package/dist/surface/glsl.d.ts +26 -0
  13. package/dist/surface/glsl.js +457 -0
  14. package/dist/surface/height.d.ts +257 -0
  15. package/dist/surface/height.js +232 -0
  16. package/dist/surface/index.d.ts +10 -0
  17. package/dist/surface/index.js +10 -0
  18. package/dist/surface/land.d.ts +111 -0
  19. package/dist/surface/land.js +261 -0
  20. package/dist/surface/load.d.ts +133 -0
  21. package/dist/surface/load.js +183 -0
  22. package/dist/surface/objects-apollo-17.d.ts +4 -0
  23. package/dist/surface/objects-apollo-17.js +19 -0
  24. package/dist/surface/objects.d.ts +127 -0
  25. package/dist/surface/objects.js +179 -0
  26. package/dist/surface/rocks.d.ts +45 -0
  27. package/dist/surface/rocks.js +166 -0
  28. package/dist/surface/scene.d.ts +72 -0
  29. package/dist/surface/scene.js +488 -0
  30. package/dist/surface/shapes.d.ts +62 -0
  31. package/dist/surface/shapes.js +247 -0
  32. package/dist/surface/site.d.ts +58 -0
  33. package/dist/surface/site.js +38 -0
  34. package/dist/surface/sky.d.ts +81 -0
  35. package/dist/surface/sky.js +60 -0
  36. package/dist/surface/view.d.ts +129 -0
  37. package/dist/surface/view.js +139 -0
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +23 -1
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Eye height of a standing person in metres.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { EYE_HEIGHT } from "@johnmorrisdotca/wakusei-planets/surface";
7
+ *
8
+ * console.log(`eyes ${EYE_HEIGHT} m above the ground`);
9
+ * ```
10
+ */
11
+ export const EYE_HEIGHT = 1.7;
12
+ /**
13
+ * The widest and the narrowest view, in degrees from the top of the picture to its bottom: zoom is the field of view.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { FOV_LIMITS } from "@johnmorrisdotca/wakusei-planets/surface";
18
+ *
19
+ * console.log(`zoom runs from ${FOV_LIMITS.min} to ${FOV_LIMITS.max} degrees`);
20
+ * ```
21
+ */
22
+ export const FOV_LIMITS = { min: 8, max: 100 };
23
+ /**
24
+ * A person's walking pace, metres a second.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { WALK_SPEED } from "@johnmorrisdotca/wakusei-planets/surface";
29
+ *
30
+ * console.log(`${(WALK_SPEED * 10).toFixed(0)} m in ten seconds`);
31
+ * ```
32
+ */
33
+ export const WALK_SPEED = 1.4;
34
+ /**
35
+ * 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`.
36
+ *
37
+ * @param look - Any look, however far out of range.
38
+ * @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`.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { clampLook } from "@johnmorrisdotca/wakusei-planets/surface";
43
+ *
44
+ * console.log(clampLook({ azimuth: -90, pitch: 120, fov: 200 }));
45
+ * ```
46
+ */
47
+ export function clampLook(look) {
48
+ return {
49
+ azimuth: ((look.azimuth % 360) + 360) % 360,
50
+ pitch: Math.max(-85, Math.min(85, look.pitch)),
51
+ fov: Math.max(FOV_LIMITS.min, Math.min(FOV_LIMITS.max, look.fov)),
52
+ };
53
+ }
54
+ /**
55
+ * 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).
56
+ *
57
+ * @param look - The look.
58
+ * @returns A unit vector.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { forward } from "@johnmorrisdotca/wakusei-planets/surface";
63
+ *
64
+ * console.log(forward({ azimuth: 90, pitch: 0, fov: 60 }).map((n) => n.toFixed(2)).join(", "));
65
+ * ```
66
+ */
67
+ export function forward(look) {
68
+ const az = (look.azimuth * Math.PI) / 180;
69
+ const p = (look.pitch * Math.PI) / 180;
70
+ return [Math.sin(az) * Math.cos(p), Math.sin(p), -Math.cos(az) * Math.cos(p)];
71
+ }
72
+ /** 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. */
73
+ export function cameraAxes(look) {
74
+ const f = forward(look);
75
+ // right = forward x (0, 1, 0), up = right x forward
76
+ let rx = -f[2];
77
+ let rz = f[0];
78
+ const rl = Math.hypot(rx, rz) || 1;
79
+ rx /= rl;
80
+ rz /= rl;
81
+ return { right: [rx, 0, rz], up: [-rz * f[1], rz * f[0] - rx * f[2], rx * f[1]], forward: f };
82
+ }
83
+ /**
84
+ * 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`.
85
+ *
86
+ * @param eye - Where the eyes are, in the scene's frame (east, up, south), in metres.
87
+ * @param look - Which way they look and how wide.
88
+ * @param aspect - The picture's width over its height.
89
+ * @param near - The nearest distance drawn, in metres.
90
+ * @param far - The farthest distance drawn, in metres.
91
+ * @returns The sixteen numbers of the matrix, column by column.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { viewProjection } from "@johnmorrisdotca/wakusei-planets/surface";
96
+ *
97
+ * const matrix = viewProjection([0, 1.7, 0], { azimuth: 0, pitch: 0, fov: 60 }, 16 / 9);
98
+ * console.log(matrix.length);
99
+ * ```
100
+ */
101
+ export function viewProjection(eye, look, aspect, near = 0.3, far = 600_000) {
102
+ const { right: r, up: u, forward: f } = cameraAxes(look);
103
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
104
+ const view = [r[0], u[0], -f[0], 0, r[1], u[1], -f[1], 0, r[2], u[2], -f[2], 0, -dot(r, eye), -dot(u, eye), dot(f, eye), 1];
105
+ const t = 1 / Math.tan((look.fov * Math.PI) / 360);
106
+ const proj = [t / aspect, 0, 0, 0, 0, t, 0, 0, 0, 0, (far + near) / (near - far), -1, 0, 0, (2 * far * near) / (near - far), 0];
107
+ const out = new Float32Array(16);
108
+ for (let c = 0; c < 4; c += 1) {
109
+ for (let row = 0; row < 4; row += 1) {
110
+ let sum = 0;
111
+ for (let k = 0; k < 4; k += 1)
112
+ sum += proj[k * 4 + row] * view[c * 4 + k];
113
+ out[c * 4 + row] = sum;
114
+ }
115
+ }
116
+ return out;
117
+ }
118
+ /**
119
+ * 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).
120
+ *
121
+ * @param position - Where the walker is, in metres east and north of the site.
122
+ * @param azimuth - The heading, in degrees clockwise from north.
123
+ * @param ahead - Metres along the heading; negative backs up.
124
+ * @param aside - Metres to the right of the heading; negative goes left.
125
+ * @returns The new position, in metres east and north of the site.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * import { stepOver } from "@johnmorrisdotca/wakusei-planets/surface";
130
+ *
131
+ * console.log(stepOver({ east: 0, north: 0 }, 0, 10, 0));
132
+ * ```
133
+ */
134
+ export function stepOver(position, azimuth, ahead, aside) {
135
+ const az = (azimuth * Math.PI) / 180;
136
+ const sin = Math.sin(az);
137
+ const cos = Math.cos(az);
138
+ return { east: position.east + ahead * sin + aside * cos, north: position.north + ahead * cos - aside * sin };
139
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.45.1";
1
+ export declare const VERSION = "0.47.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.45.1";
1
+ export const VERSION = "0.47.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.45.1",
3
+ "version": "0.47.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",
@@ -92,6 +92,8 @@
92
92
  "./dist/lineup/element.js",
93
93
  "./dist/space/element.js",
94
94
  "./dist/plan/element.js",
95
+ "./dist/surface/element.js",
96
+ "./dist/surface/land.js",
95
97
  "./dist/earth-places.js",
96
98
  "./dist/bodies/*.js",
97
99
  "./dist/tables/*.js",
@@ -101,6 +103,8 @@
101
103
  "./src/lineup/element.ts",
102
104
  "./src/space/element.ts",
103
105
  "./src/plan/element.ts",
106
+ "./src/surface/element.ts",
107
+ "./src/surface/land.ts",
104
108
  "./src/earth-places.ts",
105
109
  "./src/bodies/*.ts",
106
110
  "./src/tables/*.ts",
@@ -150,6 +154,21 @@
150
154
  "import": "./dist/plan/element.js",
151
155
  "default": "./dist/plan/element.js"
152
156
  },
157
+ "./surface": {
158
+ "types": "./dist/surface/index.d.ts",
159
+ "import": "./dist/surface/index.js",
160
+ "default": "./dist/surface/index.js"
161
+ },
162
+ "./surface/element": {
163
+ "types": "./dist/surface/element.d.ts",
164
+ "import": "./dist/surface/element.js",
165
+ "default": "./dist/surface/element.js"
166
+ },
167
+ "./surface/land": {
168
+ "types": "./dist/surface/land.d.ts",
169
+ "import": "./dist/surface/land.js",
170
+ "default": "./dist/surface/land.js"
171
+ },
153
172
  "./time": {
154
173
  "types": "./dist/time.d.ts",
155
174
  "import": "./dist/time.js",
@@ -586,6 +605,9 @@
586
605
  "tiles:moon": ".cache/venv/bin/python -I scripts/make-body-tiles.py sharp --bodies moon",
587
606
  "tiles:mars": ".cache/venv/bin/python -I scripts/make-body-tiles.py sharp --bodies mars",
588
607
  "test:tiles": ".cache/venv/bin/python -I scripts/make-body-tiles.py selftest",
608
+ "terrain": ".cache/venv/bin/python -I scripts/make-moon-terrain.py build",
609
+ "terrain:fetch": ".cache/venv/bin/python -I scripts/make-moon-terrain.py fetch",
610
+ "test:terrain": ".cache/venv/bin/python -I scripts/make-moon-terrain.py selftest",
589
611
  "orbiters:refresh": "python3 -I scripts/make-orbiter-data.py --brief --cache \"$HOME/.cache/wakusei-planets/horizons-orbiters\"",
590
612
  "family:readme": "node scripts/family-readme.mjs",
591
613
  "readme:images": "node scripts/readme-images.mjs",