@johnmorrisdotca/chikyu-earth 0.36.0 → 0.38.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 +15 -0
- package/NOTICE.md +6 -1
- package/README.md +1 -1
- 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.js +38 -8
- package/dist/markers/place-layer.d.ts +12 -1
- package/dist/markers/place-layer.js +88 -18
- package/dist/markers/place-sprites.d.ts +5 -0
- package/dist/markers/place-sprites.js +8 -0
- package/dist/paint/buffer.d.ts +53 -0
- package/dist/paint/buffer.js +238 -0
- package/dist/paint/math.d.ts +24 -0
- package/dist/paint/math.js +94 -0
- package/dist/paint/texture.d.ts +24 -0
- package/dist/paint/texture.js +33 -0
- package/dist/realistic/earth.d.ts +9 -0
- package/dist/realistic/earth.js +20 -11
- package/dist/realistic/element.d.ts +36 -3
- package/dist/realistic/element.js +82 -14
- package/dist/realistic/shaders.js +13 -0
- package/dist/realistic/textures.d.ts +2 -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 +146 -3
- package/dist/satellites/types.d.ts +22 -1
- package/dist/space/element.d.ts +56 -6
- package/dist/space/element.js +171 -16
- package/dist/space/index.d.ts +1 -1
- 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 +32 -2
- package/dist/space/satellite-layer.js +178 -19
- package/dist/space/scene.d.ts +12 -1
- package/dist/space/scene.js +27 -16
- package/package.json +1 -1
|
@@ -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,93 @@ 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
|
}`;
|
|
40
|
+
/** How long, in milliseconds of wall time, a satellite's place is kept before SGP4 places it again when the clock is too fast to interpolate: about once a second. */
|
|
41
|
+
export const PIN_PERIOD_MS = 1000;
|
|
42
|
+
/**
|
|
43
|
+
* How many satellites of a group to pin in a frame that comes `elapsedMs` after the last one, so that each is pinned again about once every {@link PIN_PERIOD_MS} and no frame that comes at a lively pace pins them all: a share of the group in
|
|
44
|
+
* proportion to the time since the last frame (a 60 Hz frame pins about a sixtieth, a 30 Hz one a thirtieth), at least one. A frame that comes a second or more after the last one pins the whole group, as one always did: a picture that
|
|
45
|
+
* is drawn that seldom has no frames for a single batch to hitch.
|
|
46
|
+
*
|
|
47
|
+
* @param count - How many satellites the group has.
|
|
48
|
+
* @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
|
|
49
|
+
* @returns How many to pin now, from 0 (an empty group) to `count`. Internal: not exported from the package.
|
|
50
|
+
*/
|
|
51
|
+
export const pinSliceSize = (count, elapsedMs) => (count <= 0 ? 0 : Math.min(count, Math.max(1, Math.ceil((count * Math.min(PIN_PERIOD_MS, Math.max(0, elapsedMs))) / PIN_PERIOD_MS))));
|
|
52
|
+
/**
|
|
53
|
+
* The slice of a group to pin in this frame: up to two runs of satellites as `[first, count]` (the second when the slice reaches the end and goes on from the start), and where the next slice begins.
|
|
54
|
+
*
|
|
55
|
+
* @param count - How many satellites the group has.
|
|
56
|
+
* @param next - Where the last slice ended (the first satellite of this one).
|
|
57
|
+
* @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
|
|
58
|
+
* @returns The runs to pin and the start of the next slice. Internal: not exported from the package.
|
|
59
|
+
*/
|
|
60
|
+
export function pinPlan(count, next, elapsedMs) {
|
|
61
|
+
const slice = pinSliceSize(count, elapsedMs);
|
|
62
|
+
if (slice === 0)
|
|
63
|
+
return { runs: [], next: 0 };
|
|
64
|
+
const first = next >= 0 && next < count ? Math.floor(next) : 0;
|
|
65
|
+
const part = Math.min(slice, count - first);
|
|
66
|
+
const runs = [[first, part]];
|
|
67
|
+
if (part < slice)
|
|
68
|
+
runs.push([0, slice - part]);
|
|
69
|
+
return { runs, next: (first + slice) % count };
|
|
70
|
+
}
|
|
27
71
|
export function createSatelliteLayer(three, scene, state, ratio) {
|
|
28
72
|
if (!three.Points)
|
|
29
73
|
throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
|
|
30
74
|
const Points = three.Points;
|
|
75
|
+
const LineSegments = three.LineSegments;
|
|
76
|
+
let warned = false;
|
|
77
|
+
/** 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. */
|
|
78
|
+
const warnNoStreaks = () => {
|
|
79
|
+
if (warned)
|
|
80
|
+
return;
|
|
81
|
+
warned = true;
|
|
82
|
+
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).");
|
|
83
|
+
};
|
|
31
84
|
const drawn = new Map();
|
|
32
85
|
const tmp = new Float64Array(6);
|
|
33
86
|
const projected = new three.Vector3();
|
|
34
87
|
const world = new three.Vector3();
|
|
35
88
|
const view = new three.Vector3();
|
|
36
|
-
const
|
|
89
|
+
const ink = new three.Color();
|
|
90
|
+
let basis = 0;
|
|
91
|
+
let lastGame = 0;
|
|
92
|
+
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
93
|
const selectedPosition = new Float32Array(3);
|
|
38
94
|
const selectedGeometry = new three.BufferGeometry();
|
|
39
95
|
selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
|
|
40
96
|
selectedGeometry.setAttribute("dim", new three.BufferAttribute(new Float32Array(1), 1));
|
|
97
|
+
selectedGeometry.setAttribute("cls", new three.BufferAttribute(new Float32Array([1, 1, 1]), 3));
|
|
41
98
|
const selectedPoints = new Points(selectedGeometry, selectedMaterial);
|
|
42
99
|
selectedPoints.frustumCulled = false;
|
|
43
100
|
selectedPoints.renderOrder = 6;
|
|
@@ -56,6 +113,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
56
113
|
scene.remove(entry.points);
|
|
57
114
|
entry.geometry.dispose();
|
|
58
115
|
entry.material.dispose();
|
|
116
|
+
if (entry.streak) {
|
|
117
|
+
scene.remove(entry.streak);
|
|
118
|
+
entry.streak.geometry.dispose();
|
|
119
|
+
entry.streak.material.dispose();
|
|
120
|
+
}
|
|
59
121
|
for (const line of entry.lines) {
|
|
60
122
|
scene.remove(line.loop);
|
|
61
123
|
line.geometry.dispose();
|
|
@@ -98,10 +160,17 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
98
160
|
};
|
|
99
161
|
const find = (ref) => state.groups.get(ref.group)?.satellites;
|
|
100
162
|
return {
|
|
101
|
-
update(time, speed) {
|
|
163
|
+
update(time, speed, earthPx = 0) {
|
|
102
164
|
const started = performance.now();
|
|
103
165
|
const tooFast = Math.abs(speed) > MAX_SATELLITE_SPEED;
|
|
104
166
|
const step = Math.min(60_000, Math.max(1000, Math.abs(speed) * 1000));
|
|
167
|
+
if (basis === 0 && earthPx > 0)
|
|
168
|
+
basis = earthPx;
|
|
169
|
+
const dotScale = basis > 0 && earthPx > 0 ? Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis))) : 1;
|
|
170
|
+
const frameMs = speed * (1000 / 30);
|
|
171
|
+
const since = lastGame === 0 ? frameMs : time - lastGame;
|
|
172
|
+
const span = tooFast ? (Math.abs(since) > 0 && Math.abs(since) < Math.abs(frameMs) * 4 ? since : frameMs) : 0;
|
|
173
|
+
lastGame = time;
|
|
105
174
|
for (const [name, entry] of drawn) {
|
|
106
175
|
if (state.groups.get(name)?.satellites !== entry.source) {
|
|
107
176
|
drop(entry);
|
|
@@ -109,45 +178,119 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
109
178
|
}
|
|
110
179
|
}
|
|
111
180
|
let placed = 0;
|
|
181
|
+
let segments = 0;
|
|
112
182
|
for (const [name, group] of state.groups) {
|
|
113
183
|
let entry = drawn.get(name);
|
|
114
184
|
if (!entry) {
|
|
115
|
-
const
|
|
185
|
+
const count = group.satellites.count;
|
|
186
|
+
const positions = new Float32Array(count * 3);
|
|
116
187
|
const geometry = new three.BufferGeometry();
|
|
117
188
|
const attribute = new three.BufferAttribute(positions, 3);
|
|
118
189
|
geometry.setAttribute("position", attribute);
|
|
119
190
|
const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
|
|
120
191
|
geometry.setAttribute("dim", dim);
|
|
121
|
-
|
|
192
|
+
geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
|
|
193
|
+
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
194
|
const points = new Points(geometry, material);
|
|
123
195
|
points.frustumCulled = false;
|
|
124
196
|
points.renderOrder = 5;
|
|
125
197
|
scene.add(points);
|
|
126
|
-
|
|
198
|
+
const streakPositions = new Float32Array(count * 6);
|
|
199
|
+
const streakColours = new Float32Array(count * 6);
|
|
200
|
+
const streakGeometry = new three.BufferGeometry();
|
|
201
|
+
const streakAttribute = new three.BufferAttribute(streakPositions, 3);
|
|
202
|
+
streakGeometry.setAttribute("position", streakAttribute);
|
|
203
|
+
streakGeometry.setAttribute("color", new three.BufferAttribute(streakColours, 3));
|
|
204
|
+
let streak = null;
|
|
205
|
+
if (LineSegments) {
|
|
206
|
+
streak = new LineSegments(streakGeometry, new three.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.95 }));
|
|
207
|
+
streak.frustumCulled = false;
|
|
208
|
+
streak.renderOrder = 4;
|
|
209
|
+
streak.visible = false;
|
|
210
|
+
scene.add(streak);
|
|
211
|
+
}
|
|
212
|
+
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, pinNext: 0 };
|
|
127
213
|
drawn.set(name, entry);
|
|
128
214
|
}
|
|
129
|
-
const style = `${group.color}|${group.size}|${ratio()}`;
|
|
215
|
+
const style = `${group.color}|${group.size}|${ratio()}|${dotScale}|${state.orbitTint ? 1 : 0}`;
|
|
130
216
|
if (style !== entry.style) {
|
|
131
217
|
entry.style = style;
|
|
132
|
-
entry.material.uniforms["size"].value = group.size * ratio();
|
|
218
|
+
entry.material.uniforms["size"].value = group.size * dotScale * ratio();
|
|
133
219
|
entry.material.uniforms["tint"].value.set(group.color);
|
|
220
|
+
entry.material.uniforms["byClass"].value = state.orbitTint ? 1 : 0;
|
|
221
|
+
ink.set(group.color);
|
|
222
|
+
const colours = group.satellites.classColour;
|
|
223
|
+
for (let i = 0; i < group.satellites.count; i += 1) {
|
|
224
|
+
const r = state.orbitTint ? colours[i * 3] : ink.r;
|
|
225
|
+
const g = state.orbitTint ? colours[i * 3 + 1] : ink.g;
|
|
226
|
+
const b = state.orbitTint ? colours[i * 3 + 2] : ink.b;
|
|
227
|
+
for (const end of [0, 1]) {
|
|
228
|
+
const c = i * 6 + end * 3;
|
|
229
|
+
entry.streakColours[c] = r;
|
|
230
|
+
entry.streakColours[c + 1] = g;
|
|
231
|
+
entry.streakColours[c + 2] = b;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (entry.streak)
|
|
235
|
+
entry.streak.geometry.getAttribute("color").needsUpdate = true;
|
|
134
236
|
}
|
|
135
|
-
const show = group.visible
|
|
237
|
+
const show = group.visible;
|
|
136
238
|
entry.points.visible = show;
|
|
137
239
|
if (!show) {
|
|
240
|
+
if (entry.streak)
|
|
241
|
+
entry.streak.visible = false;
|
|
138
242
|
for (const line of entry.lines)
|
|
139
243
|
line.loop.visible = false;
|
|
140
244
|
continue;
|
|
141
245
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
entry.
|
|
147
|
-
|
|
246
|
+
if (tooFast) {
|
|
247
|
+
// pinned whole at the first frame and when the time jumped (a date typed in, a scrub), so a place is never turned across days; after that a slice a frame, each satellite again about once a second,
|
|
248
|
+
// so SGP4 never runs for the whole group (17,000 satellites take about 12 ms) in one frame
|
|
249
|
+
const total = group.satellites.count;
|
|
250
|
+
if (entry.pinWall === 0 || Math.abs(time - entry.pinTime) > 1500 * Math.abs(speed)) {
|
|
251
|
+
group.satellites.pin(time);
|
|
252
|
+
entry.pinNext = 0;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const plan = pinPlan(total, entry.pinNext, started - entry.pinWall);
|
|
256
|
+
for (const [first, part] of plan.runs)
|
|
257
|
+
group.satellites.pin(time, first, part);
|
|
258
|
+
entry.pinNext = plan.next;
|
|
259
|
+
}
|
|
260
|
+
entry.pinWall = started;
|
|
261
|
+
entry.pinTime = time;
|
|
262
|
+
const n = group.satellites.arc(time, span, entry.positions, entry.streakPositions);
|
|
263
|
+
entry.attribute.needsUpdate = true;
|
|
264
|
+
if (entry.streak) {
|
|
265
|
+
entry.streakAttribute.needsUpdate = true;
|
|
266
|
+
entry.streak.visible = n > 0 && Math.abs(span) > 0;
|
|
267
|
+
}
|
|
268
|
+
else
|
|
269
|
+
warnNoStreaks();
|
|
270
|
+
if (entry.dimVersion !== group.satellites.dimVersion) {
|
|
271
|
+
entry.dimVersion = group.satellites.dimVersion;
|
|
272
|
+
entry.dim.needsUpdate = true;
|
|
273
|
+
}
|
|
274
|
+
for (const line of entry.lines)
|
|
275
|
+
line.loop.visible = false;
|
|
276
|
+
placed += n;
|
|
277
|
+
if (entry.streak)
|
|
278
|
+
segments += n;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
if (entry.streak)
|
|
282
|
+
entry.streak.visible = false;
|
|
283
|
+
entry.pinWall = 0;
|
|
284
|
+
group.satellites.setStep(step);
|
|
285
|
+
group.satellites.at(time, entry.positions);
|
|
286
|
+
entry.attribute.needsUpdate = true;
|
|
287
|
+
if (entry.dimVersion !== group.satellites.dimVersion) {
|
|
288
|
+
entry.dimVersion = group.satellites.dimVersion;
|
|
289
|
+
entry.dim.needsUpdate = true;
|
|
290
|
+
}
|
|
291
|
+
placed += group.satellites.placed;
|
|
292
|
+
orbitsOf(entry, group, time, started);
|
|
148
293
|
}
|
|
149
|
-
placed += group.satellites.placed;
|
|
150
|
-
orbitsOf(entry, group, time, started);
|
|
151
294
|
}
|
|
152
295
|
const chosen = state.selected;
|
|
153
296
|
const set = chosen ? find(chosen) : undefined;
|
|
@@ -174,6 +317,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
174
317
|
selectedKey = "";
|
|
175
318
|
}
|
|
176
319
|
state.drawn.placed = placed;
|
|
320
|
+
state.drawn.segments = segments;
|
|
321
|
+
state.drawn.dotScale = dotScale;
|
|
177
322
|
state.drawn.tooFast = tooFast;
|
|
178
323
|
state.drawn.updateMs = performance.now() - started;
|
|
179
324
|
if (state.drawn.updateMs > state.drawn.maxUpdateMs)
|
|
@@ -181,6 +326,20 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
181
326
|
state.drawn.updates += 1;
|
|
182
327
|
state.drawn.totalMs += state.drawn.updateMs;
|
|
183
328
|
},
|
|
329
|
+
resize(earthPx) {
|
|
330
|
+
if (!(earthPx > 0))
|
|
331
|
+
return;
|
|
332
|
+
if (basis === 0)
|
|
333
|
+
basis = earthPx;
|
|
334
|
+
const dotScale = Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis)));
|
|
335
|
+
state.drawn.dotScale = dotScale;
|
|
336
|
+
for (const [name, entry] of drawn) {
|
|
337
|
+
const group = state.groups.get(name);
|
|
338
|
+
if (!group)
|
|
339
|
+
continue;
|
|
340
|
+
entry.material.uniforms["size"].value = group.size * dotScale * ratio();
|
|
341
|
+
}
|
|
342
|
+
},
|
|
184
343
|
pick(x, y, camera, size, radius) {
|
|
185
344
|
let best = null;
|
|
186
345
|
let bestD = radius * radius;
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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
12
|
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
@@ -92,6 +92,8 @@ export interface RideState {
|
|
|
92
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. */
|
|
93
93
|
view: "from" | "follow" | "above";
|
|
94
94
|
look: RideLook;
|
|
95
|
+
/** The facing the yaw and tilt look round from, or null. */
|
|
96
|
+
face: RideFace | null;
|
|
95
97
|
/** For `follow` a satellite: how far the camera keeps, in kilometres. */
|
|
96
98
|
distanceKm: number;
|
|
97
99
|
}
|
|
@@ -393,6 +395,15 @@ export interface SpaceDeps {
|
|
|
393
395
|
onRideLost?: () => void;
|
|
394
396
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
395
397
|
onSatellitesError?: (error: unknown) => void;
|
|
398
|
+
/** The painted satellite trail. Read at every draw; nothing is uploaded while `step` returns false. */
|
|
399
|
+
paint?: {
|
|
400
|
+
data: Uint8Array;
|
|
401
|
+
width: number;
|
|
402
|
+
height: number;
|
|
403
|
+
step(ms: number): boolean;
|
|
404
|
+
span(): number;
|
|
405
|
+
on(): boolean;
|
|
406
|
+
};
|
|
396
407
|
/** How the Sun, the planets and their moons are drawn; left out, plain spheres in the right colours (see `BodyPainter`). */
|
|
397
408
|
painter?: BodyPainter;
|
|
398
409
|
/** The models of large satellites, for a followed satellite (see `SatellitePainter`); none, and a satellite is a dot. */
|
package/dist/space/scene.js
CHANGED
|
@@ -4,11 +4,13 @@ import { BODY_FRAG, CLOUD_FRAG, GLOW_FRAG, GLOW_VERT, SURFACE_FRAG, SURFACE_VERT
|
|
|
4
4
|
import { createTextureSet } from "../realistic/textures.js";
|
|
5
5
|
import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
6
6
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
7
|
-
import { ridePose } from "./ride.js";
|
|
7
|
+
import { faceOffset, ridePose } from "./ride.js";
|
|
8
8
|
import { coverBody, covers } from "../sky/cover.js";
|
|
9
|
-
import { createPlaceSprites } from "../markers/place-sprites.js";
|
|
9
|
+
import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
|
|
10
10
|
import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
11
11
|
import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
|
|
12
|
+
import { paintMinute } from "../paint/buffer.js";
|
|
13
|
+
import { createPaintTexture } from "../paint/texture.js";
|
|
12
14
|
import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
|
|
13
15
|
import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
|
|
14
16
|
import { createBorderLayer, newBorderState } from "../borders/layer.js";
|
|
@@ -186,6 +188,8 @@ export function createSpaceItem(model, deps) {
|
|
|
186
188
|
fragmentShader: SURFACE_FRAG,
|
|
187
189
|
uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, cloudMap: uniform.clouds, sunDir: sunEarth, sunLocal, cloudShift, lights: { value: 1 }, boost: { value: 0 }, ortho: { value: 0 } },
|
|
188
190
|
});
|
|
191
|
+
const paint = createPaintTexture(three, deps.paint?.data ?? new Uint8Array(4), deps.paint?.width ?? 1, deps.paint?.height ?? 1);
|
|
192
|
+
Object.assign(earthMaterial.uniforms, paint.uniforms);
|
|
189
193
|
const cloudMaterial = new three.ShaderMaterial({
|
|
190
194
|
vertexShader: SURFACE_VERT,
|
|
191
195
|
fragmentShader: CLOUD_FRAG,
|
|
@@ -283,8 +287,7 @@ export function createSpaceItem(model, deps) {
|
|
|
283
287
|
let meteorTimer;
|
|
284
288
|
let nameOn = null;
|
|
285
289
|
let borders = null;
|
|
286
|
-
|
|
287
|
-
let placeSpritesTried = false;
|
|
290
|
+
const placeRings = { sprites: null, tried: false };
|
|
288
291
|
let gridLayer = null;
|
|
289
292
|
let marksTold = false;
|
|
290
293
|
// the followed satellite's model: which satellite it is for, the drawing once it is made, and a count so that a model made for a satellite no longer followed is let go
|
|
@@ -348,6 +351,13 @@ export function createSpaceItem(model, deps) {
|
|
|
348
351
|
glow.scale.setScalar(airTop(model.airThickness));
|
|
349
352
|
earthMaterial.uniforms["lights"].value = model.light === "lit" ? 0 : 1;
|
|
350
353
|
earthMaterial.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
|
|
354
|
+
if (deps.paint) {
|
|
355
|
+
if (deps.paint.step(model.time))
|
|
356
|
+
paint.upload();
|
|
357
|
+
paint.uniforms.paintNow.value = paintMinute(model.time);
|
|
358
|
+
paint.uniforms.paintSpan.value = deps.paint.span();
|
|
359
|
+
paint.uniforms.paintOn.value = deps.paint.on() ? 1 : 0;
|
|
360
|
+
}
|
|
351
361
|
// the Moon, with its near side to the Earth
|
|
352
362
|
moon.position.set(moonPos[0], moonPos[1], moonPos[2]);
|
|
353
363
|
moon.scale.setScalar(RADIUS["Moon"][mode]);
|
|
@@ -414,7 +424,7 @@ export function createSpaceItem(model, deps) {
|
|
|
414
424
|
deps.onSatellitesError?.(error);
|
|
415
425
|
}
|
|
416
426
|
}
|
|
417
|
-
layer?.update(model.time, model.speed);
|
|
427
|
+
layer?.update(model.time, model.speed, model.drawn?.radiusPx ?? 0);
|
|
418
428
|
model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
|
|
419
429
|
// the camera: looks at the focus body from the direction the sky was in when it was last moved, turned by yaw and tilt, as far as the zoom says; or, riding along, sits at the
|
|
420
430
|
// body and looks at the Earth
|
|
@@ -468,7 +478,7 @@ export function createSpaceItem(model, deps) {
|
|
|
468
478
|
let fovNow = FOV;
|
|
469
479
|
let distance = 0;
|
|
470
480
|
if (rideFrom) {
|
|
471
|
-
const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn });
|
|
481
|
+
const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn, ...(ride.face ? { face: ride.face } : {}) });
|
|
472
482
|
model.rideDistance = Math.hypot(...rideFrom.position);
|
|
473
483
|
camera.position.set(pose.position[0], pose.position[1], pose.position[2]);
|
|
474
484
|
camera.up.set(pose.up[0], pose.up[1], pose.up[2]);
|
|
@@ -500,11 +510,12 @@ export function createSpaceItem(model, deps) {
|
|
|
500
510
|
const lon = model.centre.lon - way * model.view.yaw;
|
|
501
511
|
const lat = Math.max(-90, Math.min(90, baseLat - way * model.view.tilt));
|
|
502
512
|
const aim = direction(spin + lon, lat);
|
|
503
|
-
if (followed && ride && ride.view === "above") {
|
|
504
|
-
// above the satellite: on
|
|
505
|
-
// A
|
|
513
|
+
if (followed && ride && (ride.view === "above" || (ride.view === "follow" && ride.face))) {
|
|
514
|
+
// above the satellite, or a follow that was asked to face a way: on a line from the satellite, looking at it. With no facing, straight above, the way it is going at the top of the picture.
|
|
515
|
+
// A facing puts the camera ahead, behind, left, right, down or up; a drag turns and tips from there.
|
|
506
516
|
distance = Math.max(1e-4, ride.distanceKm / 6371 / Math.max(1e-9, model.view.zoom));
|
|
507
|
-
const
|
|
517
|
+
const base = ride.face ? faceOffset(ride.face) : { yaw: 0, tilt: 0 };
|
|
518
|
+
const up = aboveAxes(followed.place, followed.velocity, base.yaw + model.view.yaw * RAD, base.tilt + Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
|
|
508
519
|
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
509
520
|
camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
|
|
510
521
|
camera.up.set(up.up[0], up.up[1], up.up[2]);
|
|
@@ -579,6 +590,7 @@ export function createSpaceItem(model, deps) {
|
|
|
579
590
|
for (const name of BODY_NAMES)
|
|
580
591
|
px[name] = radiusPxOf(name);
|
|
581
592
|
model.drawn = { frame, distance, radiusPx: px.Earth };
|
|
593
|
+
layer?.resize(px.Earth);
|
|
582
594
|
let paintedBodies = sunSlot.drawing ? 1 : 0;
|
|
583
595
|
for (const p of planets.values())
|
|
584
596
|
if (p.slot.drawing)
|
|
@@ -775,13 +787,11 @@ export function createSpaceItem(model, deps) {
|
|
|
775
787
|
});
|
|
776
788
|
}
|
|
777
789
|
const spriteData = deps.placeSprites?.() ?? null;
|
|
778
|
-
if (spriteData
|
|
779
|
-
placeSprites = createPlaceSprites(three, earth, sunEarth);
|
|
780
|
-
placeSpritesTried = true;
|
|
790
|
+
if (beginPlaceSprites(placeRings, spriteData, () => createPlaceSprites(three, earth, sunEarth))) {
|
|
781
791
|
// told once: without `Points` the page's layer draws these rings itself
|
|
782
|
-
deps.onPlaceRings?.(
|
|
792
|
+
deps.onPlaceRings?.(placeRings.sprites !== null);
|
|
783
793
|
}
|
|
784
|
-
|
|
794
|
+
placeRings.sprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
|
|
785
795
|
// the name written on the Earth: made the first time the settings ask for it; none while a ride along a body hides the Earth
|
|
786
796
|
if (model.bodyLabel.settings && !nameOn)
|
|
787
797
|
nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
|
|
@@ -919,7 +929,7 @@ export function createSpaceItem(model, deps) {
|
|
|
919
929
|
meteors?.dispose();
|
|
920
930
|
nameOn?.dispose();
|
|
921
931
|
borders?.dispose();
|
|
922
|
-
|
|
932
|
+
placeRings.sprites?.dispose();
|
|
923
933
|
gridLayer?.dispose();
|
|
924
934
|
modelSlot.turn += 1;
|
|
925
935
|
dropModel();
|
|
@@ -940,6 +950,7 @@ export function createSpaceItem(model, deps) {
|
|
|
940
950
|
}
|
|
941
951
|
grid.dispose();
|
|
942
952
|
solid.dispose();
|
|
953
|
+
paint.dispose();
|
|
943
954
|
earthMaterial.dispose();
|
|
944
955
|
cloudMaterial.dispose();
|
|
945
956
|
atmosphereMaterial.dispose();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|