@johnmorrisdotca/chikyu-earth 0.33.1 → 0.34.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 +19 -0
- package/README.md +23 -5
- package/dist/cities/geometry.d.ts +233 -0
- package/dist/cities/geometry.js +174 -0
- package/dist/cities/host.d.ts +73 -0
- package/dist/cities/host.js +240 -0
- package/dist/element.d.ts +1 -1
- package/dist/element.js +2 -13
- package/dist/markers/index.d.ts +1 -0
- package/dist/markers/index.js +1 -0
- package/dist/markers/labels.d.ts +7 -1
- package/dist/markers/labels.js +12 -1
- package/dist/markers/place-layer.d.ts +43 -0
- package/dist/markers/place-layer.js +238 -0
- package/dist/markers/places.d.ts +279 -0
- package/dist/markers/places.js +213 -0
- package/dist/passes/element.js +2 -5
- package/dist/realistic/body-label.js +19 -11
- package/dist/realistic/earth.d.ts +1 -1
- package/dist/realistic/element.d.ts +45 -5
- package/dist/realistic/element.js +96 -13
- package/dist/realistic/index.d.ts +3 -0
- package/dist/realistic/index.js +2 -0
- package/dist/satellites/index.d.ts +1 -0
- package/dist/satellites/index.js +1 -0
- package/dist/satellites/names.d.ts +14 -0
- package/dist/satellites/names.js +16 -0
- package/dist/sky/cover.d.ts +27 -0
- package/dist/sky/cover.js +32 -0
- package/dist/sky/frame.d.ts +21 -0
- package/dist/sky/frame.js +2 -0
- package/dist/sky/host.d.ts +10 -15
- package/dist/sky/host.js +37 -3
- package/dist/sky/style.d.ts +50 -0
- package/dist/sky/style.js +2 -0
- package/dist/space/element.d.ts +116 -8
- package/dist/space/element.js +253 -8
- package/dist/space/index.d.ts +4 -2
- package/dist/space/index.js +2 -1
- package/dist/space/ride.d.ts +60 -4
- package/dist/space/ride.js +78 -6
- package/dist/space/satellite-layer.d.ts +26 -0
- package/dist/space/satellite-layer.js +37 -1
- package/dist/space/satellite-model.d.ts +72 -0
- package/dist/space/satellite-model.js +82 -0
- package/dist/space/scene.d.ts +47 -2
- package/dist/space/scene.js +169 -1
- package/package.json +8 -4
package/dist/space/ride.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { Vec3 } from "./ephemeris.ts";
|
|
|
12
12
|
export declare const RIDE_FOV = 60;
|
|
13
13
|
/**
|
|
14
14
|
* Where a riding camera looks: `down` straight at the Earth's centre (the ground goes by under the camera), or `horizon` tipped forward along the way it is going until the horizon
|
|
15
|
-
* is a little above the middle of the view.
|
|
15
|
+
* is a little above the middle of the view. A drag looks round from there on the spot with the horizon kept level: sideways turns about the local vertical, all the way round, and up and down only tips the view, from straight down to 20 degrees above the horizon.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
@@ -23,6 +23,57 @@ export declare const RIDE_FOV = 60;
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
export type RideLook = "down" | "horizon";
|
|
26
|
+
/**
|
|
27
|
+
* The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
|
|
28
|
+
*
|
|
29
|
+
* @param zoom - The shared controls' zoom.
|
|
30
|
+
* @returns The field of view in degrees.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { rideFov } from "@johnmorrisdotca/chikyu-earth/space";
|
|
35
|
+
*
|
|
36
|
+
* console.log(rideFov(1), rideFov(6), rideFov(100));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function rideFov(zoom: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* How many degrees the camera turns for a change of the controls' yaw at a zoom. The controls wrap their yaw into -180 to 180, so a page adds up the turns itself, change by change (`wrapYaw` of the change, scaled by this at the zoom of the moment), and hands
|
|
42
|
+
* the total to `ridePose` as `turn`: a drag the whole way round is then a turn the whole way round, and the pace follows the field of view at any zoom.
|
|
43
|
+
*
|
|
44
|
+
* @param change - The change of yaw, in degrees, between two views of the controls (already brought into -180 to 180).
|
|
45
|
+
* @param zoom - The shared controls' zoom at the moment.
|
|
46
|
+
* @returns The turn, in degrees.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { rideTurnDegrees } from "@johnmorrisdotca/chikyu-earth/space";
|
|
51
|
+
*
|
|
52
|
+
* console.log(rideTurnDegrees(180, 1), rideTurnDegrees(180, 6));
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function rideTurnDegrees(change: number, zoom: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* The range of the controls' tilt that does something in the `horizon` look: from straight down to a little above the horizon. A tilt beyond it moves nothing, so a page holds the tilt to it, and a drag back starts moving at once instead of after the
|
|
58
|
+
* excess is dragged back. It depends on the height (the horizon is further from straight down the higher the camera is) and the zoom. The `down` look has no such range.
|
|
59
|
+
*
|
|
60
|
+
* @param distance - The camera's distance from the Earth's centre, in Earth radii.
|
|
61
|
+
* @param look - The look.
|
|
62
|
+
* @param zoom - The shared controls' zoom.
|
|
63
|
+
* @returns The lowest and highest tilt, or `null` for the `down` look.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { rideTiltLimits } from "@johnmorrisdotca/chikyu-earth/space";
|
|
68
|
+
*
|
|
69
|
+
* const range = rideTiltLimits(1.066, "horizon", 1);
|
|
70
|
+
* console.log(range && `${range.min.toFixed(0)} to ${range.max.toFixed(0)}`, rideTiltLimits(1.066, "down", 1));
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function rideTiltLimits(distance: number, look: RideLook, zoom: number): {
|
|
74
|
+
min: number;
|
|
75
|
+
max: number;
|
|
76
|
+
} | null;
|
|
26
77
|
/**
|
|
27
78
|
* What `ridePose` is asked: the camera's place and its way of travel (any length), where it looks, and the shared controls' yaw, tilt and zoom.
|
|
28
79
|
*
|
|
@@ -46,6 +97,10 @@ export interface RideInput {
|
|
|
46
97
|
tilt: number;
|
|
47
98
|
/** 1 is the natural view; more narrows the field of view. */
|
|
48
99
|
zoom: number;
|
|
100
|
+
/**
|
|
101
|
+
* The heading in degrees, accumulated by the caller (see `rideTurnDegrees`): used in place of `yaw` when given, so a turn of more than half a way round is not undone by the controls wrapping their yaw, and a change of zoom does not swing it.
|
|
102
|
+
*/
|
|
103
|
+
turn?: number;
|
|
49
104
|
}
|
|
50
105
|
/**
|
|
51
106
|
* The camera `ridePose` works out: where it is, which way it looks, which way is up in the picture, its field of view in degrees, and how big the Earth looks from there (its angular radius in degrees).
|
|
@@ -66,9 +121,10 @@ export interface RidePose {
|
|
|
66
121
|
earthRadiusDegrees: number;
|
|
67
122
|
}
|
|
68
123
|
/**
|
|
69
|
-
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the
|
|
70
|
-
*
|
|
71
|
-
*
|
|
124
|
+
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there on the spot:
|
|
125
|
+
* `yaw` turns the camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the field of view's, so the pace is the same at any zoom.
|
|
126
|
+
* In the `horizon` look a sideways drag turns about the local vertical (the line from the Earth's centre through the camera), all the way round, and up and down only tips the view, from straight down to 20 degrees above the horizon, so the horizon stays level and
|
|
127
|
+
* nothing rolls; in the `down` look the camera turns about its own up. `zoom` narrows the field of view.
|
|
72
128
|
*
|
|
73
129
|
* @param input - The camera's place, its way of travel, the look, and the shared controls' yaw, tilt and zoom.
|
|
74
130
|
* @returns The camera's place, forward and up directions (unit vectors), its field of view, and the Earth's angular radius from there.
|
package/dist/space/ride.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const RAD = Math.PI / 180;
|
|
2
2
|
/** How far the ground moves in the picture for each pixel of a drag at the middle of it: the same pace as the line globe and the Earth from space (about one and a half). */
|
|
3
3
|
const GRAB = 1.5;
|
|
4
|
+
/** How far above the horizon a drag may tip the horizon look, in degrees. */
|
|
5
|
+
const MAX_ABOVE_HORIZON = 20;
|
|
4
6
|
/**
|
|
5
7
|
* The field of view, in degrees, of a camera riding along at zoom 1 (the Earth's view from outside is 35).
|
|
6
8
|
*
|
|
@@ -12,6 +14,65 @@ const GRAB = 1.5;
|
|
|
12
14
|
* ```
|
|
13
15
|
*/
|
|
14
16
|
export const RIDE_FOV = 60;
|
|
17
|
+
/**
|
|
18
|
+
* The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
|
|
19
|
+
*
|
|
20
|
+
* @param zoom - The shared controls' zoom.
|
|
21
|
+
* @returns The field of view in degrees.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { rideFov } from "@johnmorrisdotca/chikyu-earth/space";
|
|
26
|
+
*
|
|
27
|
+
* console.log(rideFov(1), rideFov(6), rideFov(100));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function rideFov(zoom) {
|
|
31
|
+
return Math.min(100, Math.max(5, RIDE_FOV / Math.max(0.05, zoom)));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* How many degrees the camera turns for a change of the controls' yaw at a zoom. The controls wrap their yaw into -180 to 180, so a page adds up the turns itself, change by change (`wrapYaw` of the change, scaled by this at the zoom of the moment), and hands
|
|
35
|
+
* the total to `ridePose` as `turn`: a drag the whole way round is then a turn the whole way round, and the pace follows the field of view at any zoom.
|
|
36
|
+
*
|
|
37
|
+
* @param change - The change of yaw, in degrees, between two views of the controls (already brought into -180 to 180).
|
|
38
|
+
* @param zoom - The shared controls' zoom at the moment.
|
|
39
|
+
* @returns The turn, in degrees.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { rideTurnDegrees } from "@johnmorrisdotca/chikyu-earth/space";
|
|
44
|
+
*
|
|
45
|
+
* console.log(rideTurnDegrees(180, 1), rideTurnDegrees(180, 6));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function rideTurnDegrees(change, zoom) {
|
|
49
|
+
return change * (GRAB * rideFov(zoom)) / 180;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The range of the controls' tilt that does something in the `horizon` look: from straight down to a little above the horizon. A tilt beyond it moves nothing, so a page holds the tilt to it, and a drag back starts moving at once instead of after the
|
|
53
|
+
* excess is dragged back. It depends on the height (the horizon is further from straight down the higher the camera is) and the zoom. The `down` look has no such range.
|
|
54
|
+
*
|
|
55
|
+
* @param distance - The camera's distance from the Earth's centre, in Earth radii.
|
|
56
|
+
* @param look - The look.
|
|
57
|
+
* @param zoom - The shared controls' zoom.
|
|
58
|
+
* @returns The lowest and highest tilt, or `null` for the `down` look.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { rideTiltLimits } from "@johnmorrisdotca/chikyu-earth/space";
|
|
63
|
+
*
|
|
64
|
+
* const range = rideTiltLimits(1.066, "horizon", 1);
|
|
65
|
+
* console.log(range && `${range.min.toFixed(0)} to ${range.max.toFixed(0)}`, rideTiltLimits(1.066, "down", 1));
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function rideTiltLimits(distance, look, zoom) {
|
|
69
|
+
if (look !== "horizon")
|
|
70
|
+
return null;
|
|
71
|
+
const radius = distance <= 1 ? 90 : Math.asin(1 / distance) / RAD;
|
|
72
|
+
const start = Math.max(0, radius - 12) * RAD - Math.PI / 2;
|
|
73
|
+
const perDegree = (GRAB * rideFov(zoom)) / 60;
|
|
74
|
+
return { min: (start - (MAX_ABOVE_HORIZON * RAD)) / RAD / perDegree, max: (start + Math.PI / 2) / RAD / perDegree };
|
|
75
|
+
}
|
|
15
76
|
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
16
77
|
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]];
|
|
17
78
|
const scale = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
@@ -22,9 +83,10 @@ const unit = (a) => {
|
|
|
22
83
|
return n === 0 ? [0, 0, 0] : [a[0] / n, a[1] / n, a[2] / n];
|
|
23
84
|
};
|
|
24
85
|
/**
|
|
25
|
-
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the
|
|
26
|
-
*
|
|
27
|
-
*
|
|
86
|
+
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there on the spot:
|
|
87
|
+
* `yaw` turns the camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the field of view's, so the pace is the same at any zoom.
|
|
88
|
+
* In the `horizon` look a sideways drag turns about the local vertical (the line from the Earth's centre through the camera), all the way round, and up and down only tips the view, from straight down to 20 degrees above the horizon, so the horizon stays level and
|
|
89
|
+
* nothing rolls; in the `down` look the camera turns about its own up. `zoom` narrows the field of view.
|
|
28
90
|
*
|
|
29
91
|
* @param input - The camera's place, its way of travel, the look, and the shared controls' yaw, tilt and zoom.
|
|
30
92
|
* @returns The camera's place, forward and up directions (unit vectors), its field of view, and the Earth's angular radius from there.
|
|
@@ -51,11 +113,21 @@ export function ridePose(input) {
|
|
|
51
113
|
ahead = unit(ahead);
|
|
52
114
|
const earthRadiusDegrees = distance <= 1 ? 90 : Math.asin(1 / distance) / RAD;
|
|
53
115
|
const base = input.look === "horizon" ? Math.max(0, earthRadiusDegrees - 12) * RAD : 0;
|
|
116
|
+
const fov = rideFov(input.zoom);
|
|
117
|
+
const turn = (input.turn ?? input.yaw * (GRAB * fov / 180)) * RAD;
|
|
118
|
+
const lift = input.tilt * (GRAB * fov / 60) * RAD;
|
|
119
|
+
if (input.look === "horizon") {
|
|
120
|
+
// looking round on the spot: a drag sideways turns the camera about the local vertical, all the way round, and a drag up or down tips it up or down in the vertical plane it faces, from straight down to a little above the horizon,
|
|
121
|
+
// so the horizon stays level and nothing rolls
|
|
122
|
+
const zenith = scale(nadir, -1);
|
|
123
|
+
const heading = add(scale(ahead, Math.cos(turn)), scale(cross(zenith, ahead), Math.sin(turn)));
|
|
124
|
+
const elevation = Math.max(-Math.PI / 2, Math.min(MAX_ABOVE_HORIZON * RAD, base - Math.PI / 2 - lift));
|
|
125
|
+
const forward = add(scale(heading, Math.cos(elevation)), scale(zenith, Math.sin(elevation)));
|
|
126
|
+
const up = add(scale(heading, -Math.sin(elevation)), scale(zenith, Math.cos(elevation)));
|
|
127
|
+
return { position: [input.position[0], input.position[1], input.position[2]], forward, up, fov, earthRadiusDegrees };
|
|
128
|
+
}
|
|
54
129
|
const forward0 = add(scale(nadir, Math.cos(base)), scale(ahead, Math.sin(base)));
|
|
55
130
|
const up0 = add(scale(ahead, Math.cos(base)), scale(nadir, -Math.sin(base)));
|
|
56
|
-
const fov = Math.min(100, Math.max(5, RIDE_FOV / Math.max(0.05, input.zoom)));
|
|
57
|
-
const turn = input.yaw * (GRAB * fov / 180) * RAD;
|
|
58
|
-
const lift = input.tilt * (GRAB * fov / 60) * RAD;
|
|
59
131
|
const turned = add(scale(forward0, Math.cos(turn)), scale(cross(up0, forward0), Math.sin(turn)));
|
|
60
132
|
const forward = add(scale(turned, Math.cos(lift)), scale(up0, -Math.sin(lift)));
|
|
61
133
|
const up = add(scale(up0, Math.cos(lift)), scale(turned, Math.sin(lift)));
|
|
@@ -16,6 +16,8 @@ export interface SatelliteGroupState extends SatelliteStyle {
|
|
|
16
16
|
export interface SatelliteState {
|
|
17
17
|
groups: Map<string, SatelliteGroupState>;
|
|
18
18
|
selected: SatelliteRef | null;
|
|
19
|
+
/** The groups whose members are ringed and named (`labelSatellites`): the scene tells the page where each is, at every draw. */
|
|
20
|
+
marked: Set<string>;
|
|
19
21
|
/** Written at each draw: satellites placed, whether the clock is too fast for the groups, and the milliseconds the last update took. */
|
|
20
22
|
drawn: {
|
|
21
23
|
placed: number;
|
|
@@ -29,7 +31,31 @@ export interface SatelliteState {
|
|
|
29
31
|
export declare const newSatelliteState: () => SatelliteState;
|
|
30
32
|
/** The most orbits a group may draw all at once, one line each. */
|
|
31
33
|
export declare const MAX_ORBIT_GROUP = 40;
|
|
34
|
+
/**
|
|
35
|
+
* Where a satellite is on the screen now: in CSS pixels in the view's box, whether it can be seen (inside the box and not behind the Earth) and how high it is.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import type { SatelliteScreen } from "@johnmorrisdotca/chikyu-earth/space";
|
|
40
|
+
*
|
|
41
|
+
* const seen = (place: SatelliteScreen | null): boolean => place !== null && place.visible;
|
|
42
|
+
* console.log(typeof seen);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface SatelliteScreen {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
/** Inside the box and in front of the Earth (not hidden by it). */
|
|
49
|
+
visible: boolean;
|
|
50
|
+
/** Height above the mean Earth radius, in kilometres, at the moment drawn. */
|
|
51
|
+
heightKm: number;
|
|
52
|
+
}
|
|
32
53
|
export interface SatelliteLayer {
|
|
54
|
+
/** Where one satellite of a shown group is on the screen as of the last update, or `null` when its group is not shown, it is not placed (its elements are too old) or it is behind the camera. */
|
|
55
|
+
placeOf(ref: SatelliteRef, camera: THREE.Camera, size: {
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
}): SatelliteScreen | null;
|
|
33
59
|
/** Place every shown group for `model.time` and the chosen satellite exactly. */
|
|
34
60
|
update(time: number, speed: number): void;
|
|
35
61
|
/** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
2
|
-
export const newSatelliteState = () => ({ groups: new Map(), selected: null, drawn: { placed: 0, tooFast: false, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
|
|
2
|
+
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), drawn: { placed: 0, tooFast: false, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
|
|
3
3
|
/** The most orbits a group may draw all at once, one line each. */
|
|
4
4
|
export const MAX_ORBIT_GROUP = 40;
|
|
5
5
|
const ORBIT_POINTS = 120;
|
|
@@ -229,6 +229,42 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
229
229
|
}
|
|
230
230
|
return best;
|
|
231
231
|
},
|
|
232
|
+
placeOf(ref, camera, size) {
|
|
233
|
+
const entry = drawn.get(ref.group);
|
|
234
|
+
const group = state.groups.get(ref.group);
|
|
235
|
+
if (!entry || !group || !entry.points.visible || !Number.isInteger(ref.index) || ref.index < 0 || ref.index >= group.satellites.count || !group.satellites.visible(ref.index))
|
|
236
|
+
return null;
|
|
237
|
+
const p = entry.positions;
|
|
238
|
+
const i = ref.index * 3;
|
|
239
|
+
world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
|
|
240
|
+
const heightKm = (Math.hypot(p[i], p[i + 1], p[i + 2]) - 1) * 6371;
|
|
241
|
+
projected.copy(world).project(camera);
|
|
242
|
+
if (projected.z > 1 || projected.z < -1)
|
|
243
|
+
return null;
|
|
244
|
+
const x = ((projected.x + 1) / 2) * size.width;
|
|
245
|
+
const y = ((1 - projected.y) / 2) * size.height;
|
|
246
|
+
const ortho = camera.isOrthographicCamera === true;
|
|
247
|
+
const c = camera.position;
|
|
248
|
+
let hidden;
|
|
249
|
+
if (ortho) {
|
|
250
|
+
const centreDepth = view.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z;
|
|
251
|
+
view.copy(world).applyMatrix4(camera.matrixWorldInverse);
|
|
252
|
+
hidden = view.z < centreDepth && view.x * view.x + view.y * view.y < 0.996;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
|
|
256
|
+
const px = world.x - c.x;
|
|
257
|
+
const py = world.y - c.y;
|
|
258
|
+
const pz = world.z - c.z;
|
|
259
|
+
const len2 = px * px + py * py + pz * pz;
|
|
260
|
+
const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
|
|
261
|
+
const nx = c.x + px * t;
|
|
262
|
+
const ny = c.y + py * t;
|
|
263
|
+
const nz = c.z + pz * t;
|
|
264
|
+
hidden = nx * nx + ny * ny + nz * nz < 0.998;
|
|
265
|
+
}
|
|
266
|
+
return { x, y, visible: !hidden && x >= 0 && x <= size.width && y >= 0 && y <= size.height, heightKm };
|
|
267
|
+
},
|
|
232
268
|
place(camera, size) {
|
|
233
269
|
if (!selectedPoints.visible)
|
|
234
270
|
return null;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Vec3 } from "./ephemeris.ts";
|
|
2
|
+
/**
|
|
3
|
+
* How big a followed satellite's model is drawn: its radius is this share of the height of the view (0.17), so it reads at any distance the camera keeps.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { MODEL_RADIUS_SHARE } from "@johnmorrisdotca/chikyu-earth/space";
|
|
8
|
+
*
|
|
9
|
+
* console.log(MODEL_RADIUS_SHARE);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const MODEL_RADIUS_SHARE = 0.17;
|
|
13
|
+
/**
|
|
14
|
+
* The axes of a satellite flying: `x` along the way it goes (its velocity, taken level with the ground below it), `z` straight away from the Earth's centre, and `y` to complete them (`z` cross `x`, so it points to the left of the way it goes).
|
|
15
|
+
* The family's convention for a model: its nose or long axis along +x, its top (the side that faces space) along +z.
|
|
16
|
+
*
|
|
17
|
+
* @param position - Where the satellite is, from the Earth's centre, in any unit.
|
|
18
|
+
* @param velocity - The way it is going, in any unit.
|
|
19
|
+
* @returns Three unit vectors, `x`, `y` and `z`, in the scene's axes; `null` when the position is the centre or the satellite does not move.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
|
|
24
|
+
*
|
|
25
|
+
* const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66]);
|
|
26
|
+
* console.log(axes?.x, axes?.z);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function satelliteAxes(position: Vec3, velocity: Vec3): {
|
|
30
|
+
x: Vec3;
|
|
31
|
+
y: Vec3;
|
|
32
|
+
z: Vec3;
|
|
33
|
+
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
|
|
36
|
+
*
|
|
37
|
+
* @param place - Where the model's middle goes, in the scene's units.
|
|
38
|
+
* @param axes - The satellite's axes (`satelliteAxes`).
|
|
39
|
+
* @param scale - The model's radius in the scene's units.
|
|
40
|
+
* @returns Sixteen numbers, row by row.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { modelMatrix, satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
|
|
45
|
+
*
|
|
46
|
+
* const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66])!;
|
|
47
|
+
* console.log(modelMatrix([1.066, 0, 0], axes, 0.01));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function modelMatrix(place: Vec3, axes: {
|
|
51
|
+
x: Vec3;
|
|
52
|
+
y: Vec3;
|
|
53
|
+
z: Vec3;
|
|
54
|
+
}, scale: number): number[];
|
|
55
|
+
/**
|
|
56
|
+
* The radius to draw a model at so that it is `share` of the height of the view across its radius, seen from `away` with the half field of view `half` (the tangent of half the field, as the view uses it): the model grows with the distance, so it reads
|
|
57
|
+
* at any distance the camera keeps. Never under `real`, its true size, so a camera that comes in close still sees it as big as it is.
|
|
58
|
+
*
|
|
59
|
+
* @param away - The camera's distance from the satellite, in the scene's units.
|
|
60
|
+
* @param half - The tangent of half the field of view.
|
|
61
|
+
* @param share - The share of the view's height that the radius should take (`MODEL_RADIUS_SHARE`).
|
|
62
|
+
* @param real - The model's true radius, in the same units.
|
|
63
|
+
* @returns The radius to draw it at.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { MODEL_RADIUS_SHARE, modelRadius } from "@johnmorrisdotca/chikyu-earth/space";
|
|
68
|
+
*
|
|
69
|
+
* console.log(modelRadius(0.5, Math.tan((35 / 2) * (Math.PI / 180)), MODEL_RADIUS_SHARE, 1e-8));
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function modelRadius(away: number, half: number, share: number, real: number): number;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How big a followed satellite's model is drawn: its radius is this share of the height of the view (0.17), so it reads at any distance the camera keeps.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { MODEL_RADIUS_SHARE } from "@johnmorrisdotca/chikyu-earth/space";
|
|
7
|
+
*
|
|
8
|
+
* console.log(MODEL_RADIUS_SHARE);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const MODEL_RADIUS_SHARE = 0.17;
|
|
12
|
+
/**
|
|
13
|
+
* The axes of a satellite flying: `x` along the way it goes (its velocity, taken level with the ground below it), `z` straight away from the Earth's centre, and `y` to complete them (`z` cross `x`, so it points to the left of the way it goes).
|
|
14
|
+
* The family's convention for a model: its nose or long axis along +x, its top (the side that faces space) along +z.
|
|
15
|
+
*
|
|
16
|
+
* @param position - Where the satellite is, from the Earth's centre, in any unit.
|
|
17
|
+
* @param velocity - The way it is going, in any unit.
|
|
18
|
+
* @returns Three unit vectors, `x`, `y` and `z`, in the scene's axes; `null` when the position is the centre or the satellite does not move.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
|
|
23
|
+
*
|
|
24
|
+
* const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66]);
|
|
25
|
+
* console.log(axes?.x, axes?.z);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function satelliteAxes(position, velocity) {
|
|
29
|
+
const length = Math.hypot(position[0], position[1], position[2]);
|
|
30
|
+
if (!(length > 0))
|
|
31
|
+
return null;
|
|
32
|
+
const z = [position[0] / length, position[1] / length, position[2] / length];
|
|
33
|
+
// the velocity without the part that points up or down
|
|
34
|
+
const along = velocity[0] * z[0] + velocity[1] * z[1] + velocity[2] * z[2];
|
|
35
|
+
const level = [velocity[0] - along * z[0], velocity[1] - along * z[1], velocity[2] - along * z[2]];
|
|
36
|
+
const speed = Math.hypot(level[0], level[1], level[2]);
|
|
37
|
+
if (!(speed > 1e-12))
|
|
38
|
+
return null;
|
|
39
|
+
const x = [level[0] / speed, level[1] / speed, level[2] / speed];
|
|
40
|
+
const y = [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]];
|
|
41
|
+
return { x, y, z };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
|
|
45
|
+
*
|
|
46
|
+
* @param place - Where the model's middle goes, in the scene's units.
|
|
47
|
+
* @param axes - The satellite's axes (`satelliteAxes`).
|
|
48
|
+
* @param scale - The model's radius in the scene's units.
|
|
49
|
+
* @returns Sixteen numbers, row by row.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { modelMatrix, satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
|
|
54
|
+
*
|
|
55
|
+
* const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66])!;
|
|
56
|
+
* console.log(modelMatrix([1.066, 0, 0], axes, 0.01));
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function modelMatrix(place, axes, scale) {
|
|
60
|
+
const { x, y, z } = axes;
|
|
61
|
+
return [x[0] * scale, y[0] * scale, z[0] * scale, place[0], x[1] * scale, y[1] * scale, z[1] * scale, place[1], x[2] * scale, y[2] * scale, z[2] * scale, place[2], 0, 0, 0, 1];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The radius to draw a model at so that it is `share` of the height of the view across its radius, seen from `away` with the half field of view `half` (the tangent of half the field, as the view uses it): the model grows with the distance, so it reads
|
|
65
|
+
* at any distance the camera keeps. Never under `real`, its true size, so a camera that comes in close still sees it as big as it is.
|
|
66
|
+
*
|
|
67
|
+
* @param away - The camera's distance from the satellite, in the scene's units.
|
|
68
|
+
* @param half - The tangent of half the field of view.
|
|
69
|
+
* @param share - The share of the view's height that the radius should take (`MODEL_RADIUS_SHARE`).
|
|
70
|
+
* @param real - The model's true radius, in the same units.
|
|
71
|
+
* @returns The radius to draw it at.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { MODEL_RADIUS_SHARE, modelRadius } from "@johnmorrisdotca/chikyu-earth/space";
|
|
76
|
+
*
|
|
77
|
+
* console.log(modelRadius(0.5, Math.tan((35 / 2) * (Math.PI / 180)), MODEL_RADIUS_SHARE, 1e-8));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function modelRadius(away, half, share, real) {
|
|
81
|
+
return Math.max(real, away * half * share * 2);
|
|
82
|
+
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -7,8 +7,10 @@ import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
|
7
7
|
import { type ScaleMode } from "./scale.ts";
|
|
8
8
|
import type { SatelliteRef } from "../satellites/types.ts";
|
|
9
9
|
import { type RideLook } from "./ride.ts";
|
|
10
|
-
import type { SkyFrame } from "../sky/
|
|
11
|
-
import {
|
|
10
|
+
import type { SkyFrame } from "../sky/frame.ts";
|
|
11
|
+
import type { PlaceView } from "../markers/places.ts";
|
|
12
|
+
import type { CityFrame } from "../cities/geometry.ts";
|
|
13
|
+
import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
|
|
12
14
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
13
15
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
14
16
|
type Three = ThreeParts;
|
|
@@ -180,8 +182,20 @@ export interface SpaceModel {
|
|
|
180
182
|
pose: Pose;
|
|
181
183
|
/** Pixels a second that riding makes things move on the screen at 1x clock speed (0 when not riding): the draw rate follows it. */
|
|
182
184
|
rideMotion: number;
|
|
185
|
+
/** The heading of a riding camera in degrees, added up change by change from the controls' wrapped yaw (`rideTurnDegrees`): a drag the whole way round is a turn the whole way round, and a change of zoom swings nothing. */
|
|
186
|
+
rideTurn: number;
|
|
187
|
+
/** How far the riding camera is from the Earth's centre in Earth radii as of the last draw, or null when none rides: the range of tilt that does something follows it. */
|
|
188
|
+
rideDistance: number | null;
|
|
183
189
|
/** The satellite at a point of the view (CSS pixels), within a radius, if a draw has been made and one is there. */
|
|
184
190
|
pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
|
|
191
|
+
/** The followed satellite's model, when there is one drawn: where its middle is on the screen (CSS pixels), as of the last draw. */
|
|
192
|
+
followModel: {
|
|
193
|
+
x: number;
|
|
194
|
+
y: number;
|
|
195
|
+
shown: boolean;
|
|
196
|
+
} | null;
|
|
197
|
+
/** Where a satellite of a shown group is on the screen as of the last draw (`placeSatellite`), or `null`. */
|
|
198
|
+
placeSatellite: ((ref: SatelliteRef) => SatelliteScreen | null) | null;
|
|
185
199
|
ratio(): number;
|
|
186
200
|
}
|
|
187
201
|
export declare const newSpaceModel: () => SpaceModel;
|
|
@@ -216,6 +230,23 @@ export interface BodyDrawing {
|
|
|
216
230
|
billboard?: boolean;
|
|
217
231
|
dispose(): void;
|
|
218
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* The seam for drawing a followed satellite as a 3D model: the package ships no model, the page supplies them. `has` says whether there is a model for a satellite (by NORAD number: `25544` is the ISS); `make` makes it as a drawing of radius 1
|
|
235
|
+
* (its middle at the origin, its long axis along +x, its top, the side that faces space, along +z, and its left along +y), at once or later (a promise); the view places it where the satellite is, points it the way it flies, sizes it to read and
|
|
236
|
+
* gives it the Sun's direction (`light`, `update`). `null` from `make` is no model: the satellite stays a dot.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts no-run
|
|
240
|
+
* import type { SatellitePainter } from "@johnmorrisdotca/chikyu-earth/space";
|
|
241
|
+
*
|
|
242
|
+
* const painter: SatellitePainter = { has: (norad) => norad === 25544, make: async () => null };
|
|
243
|
+
* console.log(painter.has(25544));
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export interface SatellitePainter {
|
|
247
|
+
has(noradId: number): boolean;
|
|
248
|
+
make(three: Three, noradId: number, context: PaintContext): BodyDrawing | null | Promise<BodyDrawing | null>;
|
|
249
|
+
}
|
|
219
250
|
/**
|
|
220
251
|
* What the scene tells a painter when it makes a body.
|
|
221
252
|
*
|
|
@@ -286,6 +317,10 @@ export interface SpaceDeps {
|
|
|
286
317
|
onLabels?: (places: Record<BodyName, BodyPlace | null>) => void;
|
|
287
318
|
/** Where the sky falls on the screen at this draw, and the bodies that cover it (the names of the stars and the constellation lines are laid over it). Called at each draw. */
|
|
288
319
|
onSky?: (frame: SkyFrame) => void;
|
|
320
|
+
/** Where points of the Earth's surface fall on the screen at this draw, for the places drawn on it. Called at each draw. */
|
|
321
|
+
onPlaces?: (view: PlaceView) => void;
|
|
322
|
+
/** Where the Earth is on the screen and how to find a place on it, for the names of cities. Called at each draw, with `null` while no Earth is shown. */
|
|
323
|
+
onCities?: (frame: CityFrame | null) => void;
|
|
289
324
|
/** The name written on the Earth could not be made. */
|
|
290
325
|
onLabelError?: (error: unknown) => void;
|
|
291
326
|
/** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
|
|
@@ -293,6 +328,14 @@ export interface SpaceDeps {
|
|
|
293
328
|
x: number;
|
|
294
329
|
y: number;
|
|
295
330
|
} | null) => void;
|
|
331
|
+
/** Where each member of a labelled group is on the screen at this draw (the groups of `model.satellites.marked`); an empty list once when the last group is let go. */
|
|
332
|
+
onSatelliteMarks?: (marks: {
|
|
333
|
+
ref: SatelliteRef;
|
|
334
|
+
x: number;
|
|
335
|
+
y: number;
|
|
336
|
+
visible: boolean;
|
|
337
|
+
heightKm: number;
|
|
338
|
+
}[]) => void;
|
|
296
339
|
/** Called at the end of a draw while the camera is moving from one ride to another, so the next frame is asked for (at the page's frame cap). */
|
|
297
340
|
onMoving?: () => void;
|
|
298
341
|
/** The target of the ride could not be placed at this draw. */
|
|
@@ -301,6 +344,8 @@ export interface SpaceDeps {
|
|
|
301
344
|
onSatellitesError?: (error: unknown) => void;
|
|
302
345
|
/** How the Sun, the planets and their moons are drawn; left out, plain spheres in the right colours (see `BodyPainter`). */
|
|
303
346
|
painter?: BodyPainter;
|
|
347
|
+
/** The models of large satellites, for a followed satellite (see `SatellitePainter`); none, and a satellite is a dot. */
|
|
348
|
+
satellitePainter?: () => SatellitePainter | undefined;
|
|
304
349
|
/** The painter could not make a body (the three.js parts handed over lack something it needs); the body is drawn plain instead. */
|
|
305
350
|
onPainterError?: (error: unknown) => void;
|
|
306
351
|
}
|