@johnmorrisdotca/chikyu-earth 0.35.0 → 0.37.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 +21 -0
- package/NOTICE.md +27 -1
- package/README.md +20 -2
- package/dist/borders/layer.d.ts +75 -0
- package/dist/borders/layer.js +136 -0
- package/dist/borders/lines.d.ts +138 -0
- package/dist/borders/lines.js +227 -0
- package/dist/catalogue/index.d.ts +1 -0
- package/dist/catalogue/index.js +3 -2
- package/dist/catalogue/pack.js +3 -0
- package/dist/cities/host.d.ts +9 -0
- package/dist/cities/host.js +51 -9
- package/dist/country-names/geometry.d.ts +264 -0
- package/dist/country-names/geometry.js +372 -0
- package/dist/country-names/host.d.ts +82 -0
- package/dist/country-names/host.js +212 -0
- package/dist/grid/layer.d.ts +45 -0
- package/dist/grid/layer.js +66 -0
- package/dist/grid/lines.d.ts +85 -0
- package/dist/grid/lines.js +113 -0
- package/dist/markers/go-to-place.d.ts +27 -0
- package/dist/markers/go-to-place.js +35 -0
- package/dist/markers/index.d.ts +2 -1
- package/dist/markers/index.js +2 -1
- package/dist/markers/layer.d.ts +7 -0
- package/dist/markers/layer.js +7 -0
- package/dist/markers/place-layer.d.ts +58 -7
- package/dist/markers/place-layer.js +326 -64
- package/dist/markers/place-sprites.d.ts +33 -0
- package/dist/markers/place-sprites.js +161 -0
- package/dist/markers/places.d.ts +91 -6
- package/dist/markers/places.js +135 -6
- package/dist/realistic/earth.d.ts +11 -0
- package/dist/realistic/earth.js +55 -1
- package/dist/realistic/element.d.ts +75 -6
- package/dist/realistic/element.js +221 -33
- package/dist/realistic/immersive.d.ts +7 -0
- package/dist/realistic/immersive.js +17 -0
- package/dist/realistic/index.d.ts +6 -0
- package/dist/realistic/index.js +3 -0
- package/dist/realistic/textures.d.ts +5 -0
- package/dist/satellites/index.d.ts +1 -0
- package/dist/satellites/index.js +1 -0
- package/dist/satellites/limits.d.ts +1 -1
- package/dist/satellites/limits.js +1 -1
- package/dist/satellites/owners.d.ts +26 -0
- package/dist/satellites/owners.js +164 -0
- package/dist/satellites/source.js +3 -0
- package/dist/satellites/track.d.ts +5 -0
- package/dist/satellites/track.js +128 -0
- package/dist/satellites/types.d.ts +19 -1
- package/dist/space/element.d.ts +111 -12
- package/dist/space/element.js +360 -26
- package/dist/space/index.d.ts +2 -2
- package/dist/space/index.js +1 -1
- package/dist/space/ride.d.ts +42 -0
- package/dist/space/ride.js +45 -3
- package/dist/space/satellite-layer.d.ts +8 -2
- package/dist/space/satellite-layer.js +138 -19
- package/dist/space/scene.d.ts +56 -6
- package/dist/space/scene.js +97 -15
- package/package.json +3 -3
package/dist/space/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
2
2
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
|
-
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
|
-
export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
3
|
+
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
|
+
export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
5
|
export type { SatelliteScreen } from "./satellite-layer.ts";
|
|
6
6
|
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS } from "./ephemeris.js";
|
|
4
4
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
5
5
|
export { fitDistance, plainPainter } from "./scene.js";
|
|
6
|
-
export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
6
|
+
export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
7
7
|
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
package/dist/space/ride.d.ts
CHANGED
|
@@ -23,6 +23,46 @@ export declare const RIDE_FOV = 60;
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
export type RideLook = "down" | "horizon";
|
|
26
|
+
/**
|
|
27
|
+
* A way to face while riding, as from the windows of a plane or a boat: `ahead` along the way it goes, `behind` the opposite, `left` and `right` across that way as seen facing ahead, `down` straight at the Earth and `up` straight away from it.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { RIDE_FACES, type RideFace } from "@johnmorrisdotca/chikyu-earth/space";
|
|
32
|
+
*
|
|
33
|
+
* const face: RideFace = "ahead";
|
|
34
|
+
* console.log(RIDE_FACES.includes(face));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type RideFace = "ahead" | "behind" | "left" | "right" | "down" | "up";
|
|
38
|
+
/**
|
|
39
|
+
* Every facing, in the order of a row of buttons.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { RIDE_FACES } from "@johnmorrisdotca/chikyu-earth/space";
|
|
44
|
+
*
|
|
45
|
+
* console.log(RIDE_FACES.join(" "));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const RIDE_FACES: readonly RideFace[];
|
|
49
|
+
/**
|
|
50
|
+
* Yaw and tilt, in radians, that put a camera looking at a satellite on a facing. `down` is straight above it, looking down at it and the Earth. `ahead` looks along the way it goes.
|
|
51
|
+
*
|
|
52
|
+
* @param face - The facing.
|
|
53
|
+
* @returns The yaw and tilt to give `aboveAxes`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { faceOffset } from "@johnmorrisdotca/chikyu-earth/space";
|
|
58
|
+
*
|
|
59
|
+
* console.log(faceOffset("down").tilt, faceOffset("ahead").tilt > 1);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function faceOffset(face: RideFace): {
|
|
63
|
+
yaw: number;
|
|
64
|
+
tilt: number;
|
|
65
|
+
};
|
|
26
66
|
/**
|
|
27
67
|
* 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
68
|
*
|
|
@@ -101,6 +141,8 @@ export interface RideInput {
|
|
|
101
141
|
* 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
142
|
*/
|
|
103
143
|
turn?: number;
|
|
144
|
+
/** In the `horizon` look, the facing the yaw and tilt look round from. `ahead` when not given. */
|
|
145
|
+
face?: RideFace;
|
|
104
146
|
}
|
|
105
147
|
/**
|
|
106
148
|
* 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).
|
package/dist/space/ride.js
CHANGED
|
@@ -14,6 +14,45 @@ const MAX_ABOVE_HORIZON = 20;
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export const RIDE_FOV = 60;
|
|
17
|
+
/**
|
|
18
|
+
* Every facing, in the order of a row of buttons.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { RIDE_FACES } from "@johnmorrisdotca/chikyu-earth/space";
|
|
23
|
+
*
|
|
24
|
+
* console.log(RIDE_FACES.join(" "));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const RIDE_FACES = ["ahead", "behind", "left", "right", "down", "up"];
|
|
28
|
+
/** How far each facing turns from the way it goes, in degrees, to the left, in the view from the body. */
|
|
29
|
+
const FACE_TURN = { ahead: 0, behind: 180, left: 90, right: -90, down: 0, up: 0 };
|
|
30
|
+
/**
|
|
31
|
+
* Yaw and tilt, in radians, that put a camera looking at a satellite on a facing. `down` is straight above it, looking down at it and the Earth. `ahead` looks along the way it goes.
|
|
32
|
+
*
|
|
33
|
+
* @param face - The facing.
|
|
34
|
+
* @returns The yaw and tilt to give `aboveAxes`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { faceOffset } from "@johnmorrisdotca/chikyu-earth/space";
|
|
39
|
+
*
|
|
40
|
+
* console.log(faceOffset("down").tilt, faceOffset("ahead").tilt > 1);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function faceOffset(face) {
|
|
44
|
+
if (face === "up")
|
|
45
|
+
return { yaw: 0, tilt: Math.PI };
|
|
46
|
+
if (face === "ahead")
|
|
47
|
+
return { yaw: 0, tilt: Math.PI / 2 };
|
|
48
|
+
if (face === "behind")
|
|
49
|
+
return { yaw: 0, tilt: -Math.PI / 2 };
|
|
50
|
+
if (face === "left")
|
|
51
|
+
return { yaw: Math.PI / 2, tilt: Math.PI / 2 };
|
|
52
|
+
if (face === "right")
|
|
53
|
+
return { yaw: -Math.PI / 2, tilt: Math.PI / 2 };
|
|
54
|
+
return { yaw: 0, tilt: 0 };
|
|
55
|
+
}
|
|
17
56
|
/**
|
|
18
57
|
* 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
58
|
*
|
|
@@ -112,16 +151,19 @@ export function ridePose(input) {
|
|
|
112
151
|
}
|
|
113
152
|
ahead = unit(ahead);
|
|
114
153
|
const earthRadiusDegrees = distance <= 1 ? 90 : Math.asin(1 / distance) / RAD;
|
|
154
|
+
const faced = input.look === "horizon" && input.face ? FACE_TURN[input.face] : 0;
|
|
115
155
|
const base = input.look === "horizon" ? Math.max(0, earthRadiusDegrees - 12) * RAD : 0;
|
|
116
156
|
const fov = rideFov(input.zoom);
|
|
117
|
-
const turn = (input.turn ?? input.yaw * (GRAB * fov / 180)) * RAD;
|
|
157
|
+
const turn = ((input.turn ?? input.yaw * (GRAB * fov / 180)) + faced) * RAD;
|
|
118
158
|
const lift = input.tilt * (GRAB * fov / 60) * RAD;
|
|
159
|
+
const rest = input.face === "down" ? -Math.PI / 2 : input.face === "up" ? Math.PI / 2 : base - Math.PI / 2;
|
|
160
|
+
const cap = Math.max(MAX_ABOVE_HORIZON * RAD, rest);
|
|
119
161
|
if (input.look === "horizon") {
|
|
120
162
|
// 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
|
|
163
|
+
// so the horizon stays level and nothing rolls. A facing (`up`, `down`, `ahead`, ...) is where that drag starts.
|
|
122
164
|
const zenith = scale(nadir, -1);
|
|
123
165
|
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(
|
|
166
|
+
const elevation = Math.max(-Math.PI / 2, Math.min(cap, rest - lift));
|
|
125
167
|
const forward = add(scale(heading, Math.cos(elevation)), scale(zenith, Math.sin(elevation)));
|
|
126
168
|
const up = add(scale(heading, -Math.sin(elevation)), scale(zenith, Math.cos(elevation)));
|
|
127
169
|
return { position: [input.position[0], input.position[1], input.position[2]], forward, up, fov, earthRadiusDegrees };
|
|
@@ -19,9 +19,13 @@ export interface SatelliteState {
|
|
|
19
19
|
/** The groups whose members are ringed and named (`labelSatellites`): the scene tells the page where each is, at every draw. */
|
|
20
20
|
marked: Set<string>;
|
|
21
21
|
/** Written at each draw: satellites placed, whether the clock is too fast for the groups, and the milliseconds the last update took. */
|
|
22
|
+
/** Colour each dot by its orbit class. Off by default: a group keeps the one colour it was given. */
|
|
23
|
+
orbitTint: boolean;
|
|
22
24
|
drawn: {
|
|
23
25
|
placed: number;
|
|
26
|
+
segments: number;
|
|
24
27
|
tooFast: boolean;
|
|
28
|
+
dotScale: number;
|
|
25
29
|
updateMs: number;
|
|
26
30
|
maxUpdateMs: number;
|
|
27
31
|
updates: number;
|
|
@@ -56,8 +60,10 @@ export interface SatelliteLayer {
|
|
|
56
60
|
width: number;
|
|
57
61
|
height: number;
|
|
58
62
|
}): SatelliteScreen | null;
|
|
59
|
-
/** Place every shown group for `model.time` and the chosen satellite exactly. */
|
|
60
|
-
update(time: number, speed: number): void;
|
|
63
|
+
/** Place every shown group for `model.time` and the chosen satellite exactly. `earthPx` is the Earth's radius on the screen, so a dot grows as the view zooms in. */
|
|
64
|
+
update(time: number, speed: number, earthPx?: number): void;
|
|
65
|
+
/** Set the dot size from the Earth's radius on the screen for this frame, after the camera is known. */
|
|
66
|
+
resize(earthPx: number): void;
|
|
61
67
|
/** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
|
|
62
68
|
pick(x: number, y: number, camera: THREE.Camera, size: {
|
|
63
69
|
width: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
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 } });
|
|
2
|
+
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), orbitTint: false, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, 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;
|
|
@@ -8,36 +8,62 @@ const ORBIT_REFRESH_WALL_MS = 1000;
|
|
|
8
8
|
const POINT_VERT = /* glsl */ `
|
|
9
9
|
uniform float size;
|
|
10
10
|
attribute float dim;
|
|
11
|
+
attribute vec3 cls;
|
|
11
12
|
varying float vDim;
|
|
13
|
+
varying vec3 vCls;
|
|
12
14
|
void main() {
|
|
13
15
|
vDim = dim;
|
|
16
|
+
vCls = cls;
|
|
14
17
|
gl_PointSize = size;
|
|
15
18
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
16
19
|
}`;
|
|
17
20
|
const POINT_FRAG = /* glsl */ `
|
|
18
21
|
uniform vec3 tint;
|
|
19
22
|
uniform float ring;
|
|
23
|
+
uniform float byClass;
|
|
20
24
|
varying float vDim;
|
|
25
|
+
varying vec3 vCls;
|
|
21
26
|
void main() {
|
|
22
27
|
float d = length(gl_PointCoord - vec2(0.5));
|
|
23
28
|
if (d > 0.5) discard;
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
vec3 ink = byClass > 0.5 ? vCls : tint;
|
|
30
|
+
if (ring > 0.5) {
|
|
31
|
+
float a = smoothstep(0.30, 0.38, d) * (1.0 - smoothstep(0.44, 0.5, d));
|
|
32
|
+
gl_FragColor = vec4(ink, a * (1.0 - 0.7 * vDim));
|
|
33
|
+
} else {
|
|
34
|
+
float rim = smoothstep(0.28, 0.42, d);
|
|
35
|
+
vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rim);
|
|
36
|
+
float a = smoothstep(0.50, 0.40, d);
|
|
37
|
+
gl_FragColor = vec4(colour, a * (1.0 - 0.7 * vDim));
|
|
38
|
+
}
|
|
26
39
|
}`;
|
|
27
40
|
export function createSatelliteLayer(three, scene, state, ratio) {
|
|
28
41
|
if (!three.Points)
|
|
29
42
|
throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
|
|
30
43
|
const Points = three.Points;
|
|
44
|
+
const LineSegments = three.LineSegments;
|
|
45
|
+
let warned = false;
|
|
46
|
+
/** Without `LineSegments` the streaks cannot be drawn, so above the interpolation limit the dots alone are shown. Said once, in the console, and nothing else is lost. */
|
|
47
|
+
const warnNoStreaks = () => {
|
|
48
|
+
if (warned)
|
|
49
|
+
return;
|
|
50
|
+
warned = true;
|
|
51
|
+
console.warn("chikyu-earth: the three.js parts handed over lack `LineSegments`, so above 60 times real time the satellites are dots without streaks. Add `LineSegments` to the parts the three loader hands over (see setThreeLoader).");
|
|
52
|
+
};
|
|
31
53
|
const drawn = new Map();
|
|
32
54
|
const tmp = new Float64Array(6);
|
|
33
55
|
const projected = new three.Vector3();
|
|
34
56
|
const world = new three.Vector3();
|
|
35
57
|
const view = new three.Vector3();
|
|
36
|
-
const
|
|
58
|
+
const ink = new three.Color();
|
|
59
|
+
let basis = 0;
|
|
60
|
+
let lastGame = 0;
|
|
61
|
+
const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 } }, transparent: true, depthWrite: false });
|
|
37
62
|
const selectedPosition = new Float32Array(3);
|
|
38
63
|
const selectedGeometry = new three.BufferGeometry();
|
|
39
64
|
selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
|
|
40
65
|
selectedGeometry.setAttribute("dim", new three.BufferAttribute(new Float32Array(1), 1));
|
|
66
|
+
selectedGeometry.setAttribute("cls", new three.BufferAttribute(new Float32Array([1, 1, 1]), 3));
|
|
41
67
|
const selectedPoints = new Points(selectedGeometry, selectedMaterial);
|
|
42
68
|
selectedPoints.frustumCulled = false;
|
|
43
69
|
selectedPoints.renderOrder = 6;
|
|
@@ -56,6 +82,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
56
82
|
scene.remove(entry.points);
|
|
57
83
|
entry.geometry.dispose();
|
|
58
84
|
entry.material.dispose();
|
|
85
|
+
if (entry.streak) {
|
|
86
|
+
scene.remove(entry.streak);
|
|
87
|
+
entry.streak.geometry.dispose();
|
|
88
|
+
entry.streak.material.dispose();
|
|
89
|
+
}
|
|
59
90
|
for (const line of entry.lines) {
|
|
60
91
|
scene.remove(line.loop);
|
|
61
92
|
line.geometry.dispose();
|
|
@@ -98,10 +129,17 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
98
129
|
};
|
|
99
130
|
const find = (ref) => state.groups.get(ref.group)?.satellites;
|
|
100
131
|
return {
|
|
101
|
-
update(time, speed) {
|
|
132
|
+
update(time, speed, earthPx = 0) {
|
|
102
133
|
const started = performance.now();
|
|
103
134
|
const tooFast = Math.abs(speed) > MAX_SATELLITE_SPEED;
|
|
104
135
|
const step = Math.min(60_000, Math.max(1000, Math.abs(speed) * 1000));
|
|
136
|
+
if (basis === 0 && earthPx > 0)
|
|
137
|
+
basis = earthPx;
|
|
138
|
+
const dotScale = basis > 0 && earthPx > 0 ? Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis))) : 1;
|
|
139
|
+
const frameMs = speed * (1000 / 30);
|
|
140
|
+
const since = lastGame === 0 ? frameMs : time - lastGame;
|
|
141
|
+
const span = tooFast ? (Math.abs(since) > 0 && Math.abs(since) < Math.abs(frameMs) * 4 ? since : frameMs) : 0;
|
|
142
|
+
lastGame = time;
|
|
105
143
|
for (const [name, entry] of drawn) {
|
|
106
144
|
if (state.groups.get(name)?.satellites !== entry.source) {
|
|
107
145
|
drop(entry);
|
|
@@ -109,45 +147,110 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
109
147
|
}
|
|
110
148
|
}
|
|
111
149
|
let placed = 0;
|
|
150
|
+
let segments = 0;
|
|
112
151
|
for (const [name, group] of state.groups) {
|
|
113
152
|
let entry = drawn.get(name);
|
|
114
153
|
if (!entry) {
|
|
115
|
-
const
|
|
154
|
+
const count = group.satellites.count;
|
|
155
|
+
const positions = new Float32Array(count * 3);
|
|
116
156
|
const geometry = new three.BufferGeometry();
|
|
117
157
|
const attribute = new three.BufferAttribute(positions, 3);
|
|
118
158
|
geometry.setAttribute("position", attribute);
|
|
119
159
|
const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
|
|
120
160
|
geometry.setAttribute("dim", dim);
|
|
121
|
-
|
|
161
|
+
geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
|
|
162
|
+
const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: group.size * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 } }, transparent: true, depthWrite: false });
|
|
122
163
|
const points = new Points(geometry, material);
|
|
123
164
|
points.frustumCulled = false;
|
|
124
165
|
points.renderOrder = 5;
|
|
125
166
|
scene.add(points);
|
|
126
|
-
|
|
167
|
+
const streakPositions = new Float32Array(count * 6);
|
|
168
|
+
const streakColours = new Float32Array(count * 6);
|
|
169
|
+
const streakGeometry = new three.BufferGeometry();
|
|
170
|
+
const streakAttribute = new three.BufferAttribute(streakPositions, 3);
|
|
171
|
+
streakGeometry.setAttribute("position", streakAttribute);
|
|
172
|
+
streakGeometry.setAttribute("color", new three.BufferAttribute(streakColours, 3));
|
|
173
|
+
let streak = null;
|
|
174
|
+
if (LineSegments) {
|
|
175
|
+
streak = new LineSegments(streakGeometry, new three.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.95 }));
|
|
176
|
+
streak.frustumCulled = false;
|
|
177
|
+
streak.renderOrder = 4;
|
|
178
|
+
streak.visible = false;
|
|
179
|
+
scene.add(streak);
|
|
180
|
+
}
|
|
181
|
+
entry = { source: group.satellites, points, geometry, material, positions, attribute, dim, dimVersion: -1, lines: [], linesAt: Number.NaN, linesWall: 0, style: "", streak, streakPositions, streakColours, streakAttribute, pinWall: 0, pinTime: 0 };
|
|
127
182
|
drawn.set(name, entry);
|
|
128
183
|
}
|
|
129
|
-
const style = `${group.color}|${group.size}|${ratio()}`;
|
|
184
|
+
const style = `${group.color}|${group.size}|${ratio()}|${dotScale}|${state.orbitTint ? 1 : 0}`;
|
|
130
185
|
if (style !== entry.style) {
|
|
131
186
|
entry.style = style;
|
|
132
|
-
entry.material.uniforms["size"].value = group.size * ratio();
|
|
187
|
+
entry.material.uniforms["size"].value = group.size * dotScale * ratio();
|
|
133
188
|
entry.material.uniforms["tint"].value.set(group.color);
|
|
189
|
+
entry.material.uniforms["byClass"].value = state.orbitTint ? 1 : 0;
|
|
190
|
+
ink.set(group.color);
|
|
191
|
+
const colours = group.satellites.classColour;
|
|
192
|
+
for (let i = 0; i < group.satellites.count; i += 1) {
|
|
193
|
+
const r = state.orbitTint ? colours[i * 3] : ink.r;
|
|
194
|
+
const g = state.orbitTint ? colours[i * 3 + 1] : ink.g;
|
|
195
|
+
const b = state.orbitTint ? colours[i * 3 + 2] : ink.b;
|
|
196
|
+
for (const end of [0, 1]) {
|
|
197
|
+
const c = i * 6 + end * 3;
|
|
198
|
+
entry.streakColours[c] = r;
|
|
199
|
+
entry.streakColours[c + 1] = g;
|
|
200
|
+
entry.streakColours[c + 2] = b;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (entry.streak)
|
|
204
|
+
entry.streak.geometry.getAttribute("color").needsUpdate = true;
|
|
134
205
|
}
|
|
135
|
-
const show = group.visible
|
|
206
|
+
const show = group.visible;
|
|
136
207
|
entry.points.visible = show;
|
|
137
208
|
if (!show) {
|
|
209
|
+
if (entry.streak)
|
|
210
|
+
entry.streak.visible = false;
|
|
138
211
|
for (const line of entry.lines)
|
|
139
212
|
line.loop.visible = false;
|
|
140
213
|
continue;
|
|
141
214
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
215
|
+
if (tooFast) {
|
|
216
|
+
// pinned again about once a second, and at once when the time jumped (a date typed in, a scrub), so a place is never turned across days
|
|
217
|
+
if (entry.pinWall === 0 || started - entry.pinWall >= 1000 || Math.abs(time - entry.pinTime) > 1500 * Math.abs(speed)) {
|
|
218
|
+
group.satellites.pin(time);
|
|
219
|
+
entry.pinWall = started;
|
|
220
|
+
entry.pinTime = time;
|
|
221
|
+
}
|
|
222
|
+
const n = group.satellites.arc(time, span, entry.positions, entry.streakPositions);
|
|
223
|
+
entry.attribute.needsUpdate = true;
|
|
224
|
+
if (entry.streak) {
|
|
225
|
+
entry.streakAttribute.needsUpdate = true;
|
|
226
|
+
entry.streak.visible = n > 0 && Math.abs(span) > 0;
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
warnNoStreaks();
|
|
230
|
+
if (entry.dimVersion !== group.satellites.dimVersion) {
|
|
231
|
+
entry.dimVersion = group.satellites.dimVersion;
|
|
232
|
+
entry.dim.needsUpdate = true;
|
|
233
|
+
}
|
|
234
|
+
for (const line of entry.lines)
|
|
235
|
+
line.loop.visible = false;
|
|
236
|
+
placed += n;
|
|
237
|
+
if (entry.streak)
|
|
238
|
+
segments += n;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
if (entry.streak)
|
|
242
|
+
entry.streak.visible = false;
|
|
243
|
+
entry.pinWall = 0;
|
|
244
|
+
group.satellites.setStep(step);
|
|
245
|
+
group.satellites.at(time, entry.positions);
|
|
246
|
+
entry.attribute.needsUpdate = true;
|
|
247
|
+
if (entry.dimVersion !== group.satellites.dimVersion) {
|
|
248
|
+
entry.dimVersion = group.satellites.dimVersion;
|
|
249
|
+
entry.dim.needsUpdate = true;
|
|
250
|
+
}
|
|
251
|
+
placed += group.satellites.placed;
|
|
252
|
+
orbitsOf(entry, group, time, started);
|
|
148
253
|
}
|
|
149
|
-
placed += group.satellites.placed;
|
|
150
|
-
orbitsOf(entry, group, time, started);
|
|
151
254
|
}
|
|
152
255
|
const chosen = state.selected;
|
|
153
256
|
const set = chosen ? find(chosen) : undefined;
|
|
@@ -174,6 +277,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
174
277
|
selectedKey = "";
|
|
175
278
|
}
|
|
176
279
|
state.drawn.placed = placed;
|
|
280
|
+
state.drawn.segments = segments;
|
|
281
|
+
state.drawn.dotScale = dotScale;
|
|
177
282
|
state.drawn.tooFast = tooFast;
|
|
178
283
|
state.drawn.updateMs = performance.now() - started;
|
|
179
284
|
if (state.drawn.updateMs > state.drawn.maxUpdateMs)
|
|
@@ -181,6 +286,20 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
181
286
|
state.drawn.updates += 1;
|
|
182
287
|
state.drawn.totalMs += state.drawn.updateMs;
|
|
183
288
|
},
|
|
289
|
+
resize(earthPx) {
|
|
290
|
+
if (!(earthPx > 0))
|
|
291
|
+
return;
|
|
292
|
+
if (basis === 0)
|
|
293
|
+
basis = earthPx;
|
|
294
|
+
const dotScale = Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis)));
|
|
295
|
+
state.drawn.dotScale = dotScale;
|
|
296
|
+
for (const [name, entry] of drawn) {
|
|
297
|
+
const group = state.groups.get(name);
|
|
298
|
+
if (!group)
|
|
299
|
+
continue;
|
|
300
|
+
entry.material.uniforms["size"].value = group.size * dotScale * ratio();
|
|
301
|
+
}
|
|
302
|
+
},
|
|
184
303
|
pick(x, y, camera, size, radius) {
|
|
185
304
|
let best = null;
|
|
186
305
|
let bestD = radius * radius;
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -6,13 +6,17 @@ import type { LightMode } from "../realistic/earth.ts";
|
|
|
6
6
|
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
|
-
import { type RideLook } from "./ride.ts";
|
|
9
|
+
import { type RideFace, type RideLook } from "./ride.ts";
|
|
10
10
|
import type { SkyFrame } from "../sky/frame.ts";
|
|
11
11
|
import type { PlaceView } from "../markers/places.ts";
|
|
12
|
-
import type
|
|
12
|
+
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
13
|
+
import type { CountryFrame } from "../country-names/geometry.ts";
|
|
14
|
+
import type { GeoPoint } from "../types.ts";
|
|
13
15
|
import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
|
|
14
16
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
15
17
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
18
|
+
import { type BorderState } from "../borders/layer.ts";
|
|
19
|
+
import { type GridState } from "../grid/layer.ts";
|
|
16
20
|
type Three = ThreeParts;
|
|
17
21
|
/** How much of the view's shorter side the Earth's disc fills at zoom 1 when the page does not say: 0.9, so the atmosphere's glow (8% beyond the disc) is inside the view and never cut. */
|
|
18
22
|
export declare const DEFAULT_EARTH_SIZE = 0.9;
|
|
@@ -88,6 +92,8 @@ export interface RideState {
|
|
|
88
92
|
/** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. `above` (a satellite): the camera is on the line from the Earth's centre through the satellite, looking straight down. */
|
|
89
93
|
view: "from" | "follow" | "above";
|
|
90
94
|
look: RideLook;
|
|
95
|
+
/** The facing the yaw and tilt look round from, or null. */
|
|
96
|
+
face: RideFace | null;
|
|
91
97
|
/** For `follow` a satellite: how far the camera keeps, in kilometres. */
|
|
92
98
|
distanceKm: number;
|
|
93
99
|
}
|
|
@@ -145,10 +151,13 @@ export interface SpaceModel {
|
|
|
145
151
|
distance: number;
|
|
146
152
|
radiusPx: number;
|
|
147
153
|
} | null;
|
|
148
|
-
/** What the painter has made now: the Sun and planets with a drawing, and the moons shown (set at each draw). */
|
|
154
|
+
/** What the painter has made now: the Sun and planets with a drawing, the moons shown and the moons held (shown, or gone from the view for less than `MOON_KEEP_MS`), whether the Moon is the painter's, and the bodies with finer map tiles on them (set at each draw). */
|
|
149
155
|
painted: {
|
|
150
156
|
bodies: number;
|
|
151
157
|
moons: number;
|
|
158
|
+
held: number;
|
|
159
|
+
moon: boolean;
|
|
160
|
+
tiles: number;
|
|
152
161
|
};
|
|
153
162
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
154
163
|
lookups: number;
|
|
@@ -160,6 +169,10 @@ export interface SpaceModel {
|
|
|
160
169
|
meteors: MeteorState;
|
|
161
170
|
/** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
|
|
162
171
|
bodyLabel: BodyLabelState;
|
|
172
|
+
/** The borders of the countries and of their regions, on the Earth (src/borders/layer.ts): off unless the element switches them on. */
|
|
173
|
+
borders: BorderState;
|
|
174
|
+
/** The meridians and parallels on the Earth (src/grid/layer.ts): off unless the element switches them on. */
|
|
175
|
+
grid: GridState;
|
|
163
176
|
/** The body or satellite the camera rides along with, or null. */
|
|
164
177
|
ride: RideState | null;
|
|
165
178
|
/** Set at each draw: the target of the ride could not be placed (a satellite whose elements are too old, or that is gone), so the ordinary camera was used. */
|
|
@@ -180,6 +193,8 @@ export interface SpaceModel {
|
|
|
180
193
|
tilt: number;
|
|
181
194
|
zoom: number;
|
|
182
195
|
} | null;
|
|
196
|
+
/** The point of the ground the view would look at with yaw and tilt 0, as of the last draw (the middle of the view is this less the yaw and tilt), or null while the camera rides or looks at another body. */
|
|
197
|
+
lookBase: GeoPoint | null;
|
|
183
198
|
heightPx: number;
|
|
184
199
|
pose: Pose;
|
|
185
200
|
/** Pixels a second that riding makes things move on the screen at 1x clock speed (0 when not riding): the draw rate follows it. */
|
|
@@ -223,16 +238,40 @@ export interface BodyDrawing {
|
|
|
223
238
|
object: THREE.Object3D;
|
|
224
239
|
/** Told at each draw the unit direction from the body to the Sun, in scene axes (x to the vernal equinox, y north). */
|
|
225
240
|
light?(toSun: Vec3): void;
|
|
226
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* Told at each draw, after the object is placed and scaled: the direction to the Sun, the moment shown, how many CSS pixels across its radius the body is (a sharper picture is worth fetching only for a big one), and the
|
|
243
|
+
* camera with the size of the view in CSS pixels (`view`), so a body big in the view can lay finer map tiles over the part of it that is seen, and a glow can face the camera.
|
|
244
|
+
*/
|
|
227
245
|
update?(info: {
|
|
228
246
|
toSun: Vec3;
|
|
229
247
|
ms: number;
|
|
230
248
|
radiusPx: number;
|
|
249
|
+
view?: BodyView;
|
|
231
250
|
}): void;
|
|
251
|
+
/** What the window of finer map tiles on the body is doing (`shown` is the level on it now, or `null`), for a drawing that has one. */
|
|
252
|
+
readonly tiles?: {
|
|
253
|
+
shown: number | null;
|
|
254
|
+
} | undefined;
|
|
232
255
|
/** True to have the scene turn the object to face the camera (a disc or a glow). */
|
|
233
256
|
billboard?: boolean;
|
|
234
257
|
dispose(): void;
|
|
235
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* The camera that draws the bodies and the size of its view in CSS pixels, as the space view tells a drawing at each draw. The camera's matrices are current.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts no-run
|
|
264
|
+
* import type { BodyView } from "@johnmorrisdotca/chikyu-earth/space";
|
|
265
|
+
*
|
|
266
|
+
* const across = (view: BodyView): number => view.width;
|
|
267
|
+
* console.log(typeof across);
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export interface BodyView {
|
|
271
|
+
camera: THREE.Camera;
|
|
272
|
+
width: number;
|
|
273
|
+
height: number;
|
|
274
|
+
}
|
|
236
275
|
/**
|
|
237
276
|
* 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
|
|
238
277
|
* (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
|
|
@@ -270,6 +309,8 @@ export interface PaintContext {
|
|
|
270
309
|
ratio: number;
|
|
271
310
|
/** The widest picture, in pixels, the GPU should be given. */
|
|
272
311
|
maxTexture: number;
|
|
312
|
+
/** True to draw every body that has a surface picture from it, in any look but `plain`: the space view asks for this, so a planet or the Moon is never shown shaded where it has a real map. */
|
|
313
|
+
mapped?: boolean;
|
|
273
314
|
}
|
|
274
315
|
/**
|
|
275
316
|
* One moon of a planet at a moment: its name, where it is from the planet's centre and how big it is, both in radii of the planet, in scene axes.
|
|
@@ -306,6 +347,11 @@ export interface BodyPainter {
|
|
|
306
347
|
make(three: ThreeParts, name: string, context?: PaintContext): BodyDrawing | Promise<BodyDrawing>;
|
|
307
348
|
moons?(planet: PlanetName, ms: number): readonly BodyMoon[];
|
|
308
349
|
looks?: readonly string[];
|
|
350
|
+
/** Whose pictures the painter draws, in English and Japanese: the space view writes it under the picture while the painter draws the bodies. */
|
|
351
|
+
credit?: {
|
|
352
|
+
en: string;
|
|
353
|
+
ja: string;
|
|
354
|
+
};
|
|
309
355
|
}
|
|
310
356
|
export interface SpaceDeps {
|
|
311
357
|
assets: AssetCache;
|
|
@@ -322,8 +368,12 @@ export interface SpaceDeps {
|
|
|
322
368
|
onSky?: (frame: SkyFrame) => void;
|
|
323
369
|
/** Where points of the Earth's surface fall on the screen at this draw, for the places drawn on it. Called at each draw. */
|
|
324
370
|
onPlaces?: (view: PlaceView) => void;
|
|
325
|
-
/**
|
|
326
|
-
|
|
371
|
+
/** The rings the places' layer wants drawn in one draw call, read right after `onPlaces`. */
|
|
372
|
+
placeSprites?: () => PlaceSpriteData | null;
|
|
373
|
+
/** Told once, when the rings of the places that are not markers of their own were first wanted: whether the picture can draw them (false when the three.js parts handed over lack `Points`). */
|
|
374
|
+
onPlaceRings?: (drawn: boolean) => void;
|
|
375
|
+
/** Where the Earth is on the screen (its disc) and how to find a place on it, for the names of cities and countries. Called at each draw, with `null` while no Earth is shown. */
|
|
376
|
+
onCities?: (frame: CountryFrame | null) => void;
|
|
327
377
|
/** The name written on the Earth could not be made. */
|
|
328
378
|
onLabelError?: (error: unknown) => void;
|
|
329
379
|
/** 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). */
|