@johnmorrisdotca/chikyu-earth 0.46.6 → 0.48.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 +14 -0
- package/README.md +3 -3
- package/dist/beam/layer.d.ts +1 -1
- package/dist/markers/place-layer.d.ts +4 -0
- package/dist/markers/place-layer.js +20 -6
- package/dist/place/index.d.ts +230 -0
- package/dist/place/index.js +183 -0
- package/dist/place/land.d.ts +30 -0
- package/dist/place/land.js +177 -0
- package/dist/place/water.d.ts +15 -0
- package/dist/place/water.js +63 -0
- package/dist/realistic/earth.d.ts +12 -1
- package/dist/realistic/earth.js +17 -1
- package/dist/realistic/element-base.d.ts +92 -0
- package/dist/realistic/element-base.js +179 -4
- package/dist/sky/claim.d.ts +4 -0
- package/dist/sky/claim.js +8 -0
- package/dist/sky/host.js +5 -0
- package/dist/space/element-base.d.ts +168 -2
- package/dist/space/element-base.js +402 -8
- package/dist/space/ephemeris.d.ts +1 -1
- package/dist/space/ephemeris.js +4 -2
- package/dist/space/follow.d.ts +36 -0
- package/dist/space/follow.js +46 -0
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -0
- package/dist/space/path-controls.d.ts +56 -0
- package/dist/space/path-controls.js +121 -0
- package/dist/space/path-ribbons.d.ts +25 -0
- package/dist/space/path-ribbons.js +165 -0
- package/dist/space/paths.d.ts +119 -0
- package/dist/space/paths.js +163 -0
- package/dist/space/ride.d.ts +3 -2
- package/dist/space/ride.js +6 -4
- package/dist/space/satellite-hover.d.ts +47 -0
- package/dist/space/satellite-hover.js +183 -0
- package/dist/space/satellite-layer.d.ts +83 -2
- package/dist/space/satellite-layer.js +231 -52
- package/dist/space/satellite-model.d.ts +2 -1
- package/dist/space/satellite-model.js +4 -3
- package/dist/space/scene.d.ts +41 -0
- package/dist/space/scene.js +82 -13
- package/package.json +6 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
2
2
|
import { satelliteEmphasis } from "./satellite-focus.js";
|
|
3
|
+
import { BUILT_IN_PATH_STYLES, capPaths, nearestLoop, resolvePathId, styleOf, styleTable } from "./paths.js";
|
|
4
|
+
import { createPathRibbons } from "./path-ribbons.js";
|
|
3
5
|
/**
|
|
4
6
|
* The longest a streak may be along its orbit, in Earth radii: 0.025, about 160 km, which is what a low satellite covers in a frame at 10 minutes a second (150 km). On the screen that is a share of the Earth's drawn radius, so a streak
|
|
5
7
|
* is a few millimetres when the Earth fills the view, half as long when the Earth is half as large, and a dot when the Earth is tiny. A cap of so many pixels alone would leave the same length on a small Earth, where it looks long.
|
|
@@ -54,10 +56,24 @@ export function longestStreak(segments, count, earthPx) {
|
|
|
54
56
|
}
|
|
55
57
|
return longest * earthPx;
|
|
56
58
|
}
|
|
57
|
-
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false } });
|
|
59
|
+
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, pathsDrawn: 0, pathDraws: 0 } });
|
|
58
60
|
/** The most orbits a group may draw all at once, one line each. */
|
|
59
61
|
export const MAX_ORBIT_GROUP = 40;
|
|
60
62
|
const ORBIT_POINTS = 120;
|
|
63
|
+
/** How bright the chosen satellite's orbit is. The orbit under the pointer is about a third of this, so the two are told apart at a glance. */
|
|
64
|
+
export const SELECTED_PATH_OPACITY = BUILT_IN_PATH_STYLES["selected"].opacity;
|
|
65
|
+
/** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
|
|
66
|
+
export const HOVER_PATH_OPACITY = SELECTED_PATH_OPACITY / 3;
|
|
67
|
+
/** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
|
|
68
|
+
export const HOVER_FADE_MS = 180;
|
|
69
|
+
/**
|
|
70
|
+
* How much of the faint orbit is left `elapsedMs` into its fade, from `from` (1 while the pointer rests) down to 0.
|
|
71
|
+
*
|
|
72
|
+
* @param elapsedMs - Milliseconds since the pointer left.
|
|
73
|
+
* @param from - The opacity share when the fade began, 0 to 1.
|
|
74
|
+
* @returns The share still drawn, 0 when the fade is over.
|
|
75
|
+
*/
|
|
76
|
+
export const fadeLeft = (elapsedMs, from) => from * (1 - Math.min(1, Math.max(0, elapsedMs) / HOVER_FADE_MS));
|
|
61
77
|
const ORBIT_REFRESH_GAME_MS = 30 * 60_000;
|
|
62
78
|
const ORBIT_REFRESH_WALL_MS = 1000;
|
|
63
79
|
const POINT_VERT = /* glsl */ `
|
|
@@ -160,6 +176,37 @@ export function edgeBeyondCamera(x, y) {
|
|
|
160
176
|
return x < 0 ? "left" : "right";
|
|
161
177
|
return y >= 0 ? "top" : "bottom";
|
|
162
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Whether the Earth hides a satellite. The Earth is the unit sphere at the origin. True when the line from the camera to the satellite meets that sphere before it arrives. A graze at the limb is not hidden (the line only touches the sphere), and neither is a satellite in front of the Earth. This is not the test for a satellite behind the camera.
|
|
181
|
+
*
|
|
182
|
+
* @param camera - The camera, in the same units as the sphere (Earth radii).
|
|
183
|
+
* @param satellite - The satellite, in those units.
|
|
184
|
+
* @returns True when the globe is in the way.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* import { earthHides } from "@johnmorrisdotca/chikyu-earth/space";
|
|
189
|
+
*
|
|
190
|
+
* const camera = { x: 0, y: 0, z: 4 };
|
|
191
|
+
* console.log(earthHides(camera, { x: 0, y: 0, z: 1.2 }));
|
|
192
|
+
* console.log(earthHides(camera, { x: 0, y: 0, z: -1.2 }));
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export function earthHides(camera, satellite) {
|
|
196
|
+
const px = satellite.x - camera.x;
|
|
197
|
+
const py = satellite.y - camera.y;
|
|
198
|
+
const pz = satellite.z - camera.z;
|
|
199
|
+
const len2 = px * px + py * py + pz * pz;
|
|
200
|
+
if (!(len2 > 0))
|
|
201
|
+
return false;
|
|
202
|
+
const t = Math.max(0, Math.min(1, -(camera.x * px + camera.y * py + camera.z * pz) / len2));
|
|
203
|
+
const nx = camera.x + px * t;
|
|
204
|
+
const ny = camera.y + py * t;
|
|
205
|
+
const nz = camera.z + pz * t;
|
|
206
|
+
return nx * nx + ny * ny + nz * nz < 0.998;
|
|
207
|
+
}
|
|
208
|
+
/** An orthographic view: the satellite is behind the Earth's disc when it is further than the centre and inside the disc. A graze at the limb (just inside radius 1) is not hidden. */
|
|
209
|
+
const earthHidesDisc = (right, up, depth, centreDepth) => depth < centreDepth && right * right + up * up < 0.996;
|
|
163
210
|
export function createSatelliteLayer(three, scene, state, ratio) {
|
|
164
211
|
if (!three.Points)
|
|
165
212
|
throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
|
|
@@ -192,15 +239,25 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
192
239
|
selectedPoints.renderOrder = 6;
|
|
193
240
|
selectedPoints.visible = false;
|
|
194
241
|
scene.add(selectedPoints);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
242
|
+
// One line for the whole life of the layer, rewritten in place: a hover does not make a new buffer. It is about a third as bright as the chosen orbit, so it reads thinner and fainter. WebGL draws a line one pixel wide, and the chosen orbit is left as it is.
|
|
243
|
+
const hoverLine = { positions: new Float32Array(ORBIT_POINTS * 3), geometry: new three.BufferGeometry(), material: new three.LineBasicMaterial({ color: "#ffffff", transparent: true, opacity: HOVER_PATH_OPACITY }) };
|
|
244
|
+
hoverLine.geometry.setAttribute("position", new three.BufferAttribute(hoverLine.positions, 3));
|
|
245
|
+
const hoverLoop = new three.LineLoop(hoverLine.geometry, hoverLine.material);
|
|
246
|
+
hoverLoop.name = "hover-path";
|
|
247
|
+
hoverLoop.frustumCulled = false;
|
|
248
|
+
hoverLoop.visible = false;
|
|
249
|
+
hoverLoop.renderOrder = 4;
|
|
250
|
+
scene.add(hoverLoop);
|
|
251
|
+
let hoverKey = "";
|
|
252
|
+
// The page's paths and the chosen satellite's own orbit: one mesh, one draw call, buffers made once (see path-ribbons.ts).
|
|
253
|
+
const ribbons = createPathRibbons(three, scene);
|
|
254
|
+
let slots = [];
|
|
255
|
+
let slotsSignature = "";
|
|
256
|
+
let resolvedFor = [];
|
|
257
|
+
let resolvedVersion = -1;
|
|
258
|
+
let resolved = [];
|
|
259
|
+
let pathDrawn = false;
|
|
260
|
+
let table = styleTable({});
|
|
204
261
|
const drop = (entry) => {
|
|
205
262
|
scene.remove(entry.points);
|
|
206
263
|
entry.geometry.dispose();
|
|
@@ -251,8 +308,99 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
251
308
|
entry.linesWall = wall;
|
|
252
309
|
};
|
|
253
310
|
const find = (ref) => state.groups.get(ref.group)?.satellites;
|
|
311
|
+
const refKey = (ref) => `${ref.group}:${ref.index}`;
|
|
312
|
+
const cleanRef = (ref) => {
|
|
313
|
+
if (!ref)
|
|
314
|
+
return null;
|
|
315
|
+
const group = state.groups.get(ref.group);
|
|
316
|
+
return group && ref.index >= 0 && ref.index < group.satellites.count && satelliteEmphasis(ref.group, group.visible, state.focus).drawn ? ref : null;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* The paths to draw now: the page's (the last 16 that match a satellite, in order), then the chosen satellite's own orbit and the ridden one's in the `selected` look, last, so they lie over the rest. The orbits are
|
|
320
|
+
* computed once for a satellite and again only when the clock has moved half an hour and a second has passed, as the chosen orbit always was. The buffers are rewritten only when the list, a look or an orbit changed.
|
|
321
|
+
*/
|
|
322
|
+
const syncPaths = (time, wall, chosen) => {
|
|
323
|
+
const pathState = state.paths;
|
|
324
|
+
const sources = [...state.groups.values()].map((group) => group.satellites);
|
|
325
|
+
const same = sources.length === resolvedFor.length && sources.every((source, i) => source === resolvedFor[i]);
|
|
326
|
+
if (!same || resolvedVersion !== pathState.version) {
|
|
327
|
+
resolvedFor = sources;
|
|
328
|
+
resolvedVersion = pathState.version;
|
|
329
|
+
table = styleTable(pathState.overrides);
|
|
330
|
+
resolved = pathState.requests.map((request) => ({ request, ref: resolvePathId(request.id, state.groups) }));
|
|
331
|
+
}
|
|
332
|
+
// a satellite asked for twice is drawn once, in the place and look of the later request
|
|
333
|
+
const byRef = new Map();
|
|
334
|
+
for (const one of resolved) {
|
|
335
|
+
if (!one.ref)
|
|
336
|
+
continue;
|
|
337
|
+
byRef.delete(refKey(one.ref));
|
|
338
|
+
byRef.set(refKey(one.ref), { request: one.request, ref: one.ref });
|
|
339
|
+
}
|
|
340
|
+
const matched = [...byRef.values()];
|
|
341
|
+
const capped = capPaths(matched);
|
|
342
|
+
const wanted = [];
|
|
343
|
+
for (const one of capped.kept) {
|
|
344
|
+
const ref = cleanRef(one.ref);
|
|
345
|
+
if (!ref)
|
|
346
|
+
continue;
|
|
347
|
+
const look = styleOf(one.request, table);
|
|
348
|
+
wanted.push({ id: one.request.id, ref, name: look.name, style: look.style });
|
|
349
|
+
}
|
|
350
|
+
if (pathState.selectedOn) {
|
|
351
|
+
const own = [chosen, state.ridden].map(cleanRef);
|
|
352
|
+
const seen = new Set();
|
|
353
|
+
for (const ref of own) {
|
|
354
|
+
if (!ref || seen.has(refKey(ref)))
|
|
355
|
+
continue;
|
|
356
|
+
seen.add(refKey(ref));
|
|
357
|
+
const norad = find(ref)?.sets[ref.index]?.NORAD_CAT_ID;
|
|
358
|
+
wanted.push({ id: norad ?? refKey(ref), ref, name: "selected", style: table["selected"] });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const signature = wanted.map((w) => `${refKey(w.ref)}|${w.name}|${w.style.color}|${w.style.width}|${w.style.opacity}|${w.style.dash ? w.style.dash.join(",") : "-"}`).join(";");
|
|
362
|
+
let dirty = signature !== slotsSignature;
|
|
363
|
+
const old = new Map(slots.map((slot) => [slot.key, slot]));
|
|
364
|
+
let empty = 0;
|
|
365
|
+
const next = [];
|
|
366
|
+
for (const w of wanted) {
|
|
367
|
+
const key = `${refKey(w.ref)}|${w.name}`;
|
|
368
|
+
let slot = old.get(key);
|
|
369
|
+
const set = find(w.ref);
|
|
370
|
+
if (!slot) {
|
|
371
|
+
slot = { key, info: { id: w.id, ref: w.ref, style: w.name }, style: w.style, positions: new Float32Array(ORBIT_POINTS * 3), screen: new Float32Array(ORBIT_POINTS * 2), seen: new Uint8Array(ORBIT_POINTS), at: Number.NaN, wall: 0, empty: false };
|
|
372
|
+
dirty = true;
|
|
373
|
+
}
|
|
374
|
+
old.delete(key);
|
|
375
|
+
slot.info = { id: w.id, ref: w.ref, style: w.name };
|
|
376
|
+
slot.style = w.style;
|
|
377
|
+
if (Number.isNaN(slot.at) || (Math.abs(time - slot.at) > ORBIT_REFRESH_GAME_MS && wall - slot.wall > ORBIT_REFRESH_WALL_MS)) {
|
|
378
|
+
slot.at = time;
|
|
379
|
+
slot.wall = wall;
|
|
380
|
+
slot.positions.set(set.orbit(w.ref.index, time, ORBIT_POINTS).subarray(0, ORBIT_POINTS * 3));
|
|
381
|
+
slot.empty = slot.positions.every((v) => v === 0);
|
|
382
|
+
dirty = true;
|
|
383
|
+
}
|
|
384
|
+
if (slot.empty)
|
|
385
|
+
empty += 1;
|
|
386
|
+
next.push(slot);
|
|
387
|
+
}
|
|
388
|
+
slots = next;
|
|
389
|
+
if (dirty) {
|
|
390
|
+
slotsSignature = signature;
|
|
391
|
+
ribbons.set(slots.filter((slot) => !slot.empty).map((slot) => ({ positions: slot.positions, style: slot.style })));
|
|
392
|
+
}
|
|
393
|
+
const own = wanted.filter((w) => w.name === "selected" && pathState.selectedOn);
|
|
394
|
+
pathState.info = slots.filter((slot) => !slot.empty).map((slot) => ({ ...slot.info }));
|
|
395
|
+
pathState.dropped = capped.dropped;
|
|
396
|
+
pathState.unresolved = resolved.length - matched.length + empty;
|
|
397
|
+
pathDrawn = ribbons.mesh.visible;
|
|
398
|
+
state.drawn.pathsDrawn = ribbons.count;
|
|
399
|
+
state.drawn.pathDraws = pathDrawn ? 1 : 0;
|
|
400
|
+
state.drawn.selectedOpacity = own.length > 0 ? own[0].style.opacity : 0;
|
|
401
|
+
};
|
|
254
402
|
return {
|
|
255
|
-
update(time, speed, earthPx = 0) {
|
|
403
|
+
update(time, speed, earthPx = 0, size) {
|
|
256
404
|
const started = performance.now();
|
|
257
405
|
const tooFast = Math.abs(speed) > MAX_SATELLITE_SPEED;
|
|
258
406
|
const step = Math.min(60_000, Math.max(1000, Math.abs(speed) * 1000));
|
|
@@ -416,6 +564,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
416
564
|
line.loop.material.opacity = opacity;
|
|
417
565
|
}
|
|
418
566
|
}
|
|
567
|
+
if (size)
|
|
568
|
+
ribbons.frame(size.width, size.height, radius);
|
|
419
569
|
const chosen = state.selected;
|
|
420
570
|
const chosenGroup = chosen ? state.groups.get(chosen.group) : undefined;
|
|
421
571
|
const chosenDrawn = chosen !== null && chosenGroup !== undefined && satelliteEmphasis(chosen.group, chosenGroup.visible, state.focus).drawn;
|
|
@@ -428,23 +578,37 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
428
578
|
const over = state.modelOver !== null && state.modelOver.group === chosen.group && state.modelOver.index === chosen.index;
|
|
429
579
|
selectedPoints.visible = !over;
|
|
430
580
|
state.drawn.selectedRing = !over;
|
|
431
|
-
const key = `${chosen.group}:${chosen.index}`;
|
|
432
|
-
if (key !== selectedKey || (Math.abs(time - selectedAt) > ORBIT_REFRESH_GAME_MS && started - selectedWall > ORBIT_REFRESH_WALL_MS)) {
|
|
433
|
-
selectedKey = key;
|
|
434
|
-
selectedAt = time;
|
|
435
|
-
selectedWall = started;
|
|
436
|
-
selectedLine.positions.set(set.orbit(chosen.index, time, ORBIT_POINTS).subarray(0, ORBIT_POINTS * 3));
|
|
437
|
-
selectedLine.geometry.getAttribute("position").needsUpdate = true;
|
|
438
|
-
}
|
|
439
|
-
selectedLoop.visible = true;
|
|
440
581
|
selectedMaterial.uniforms["size"].value = 14 * ratio();
|
|
441
582
|
}
|
|
442
583
|
else {
|
|
443
584
|
selectedPoints.visible = false;
|
|
444
585
|
state.drawn.selectedRing = false;
|
|
445
|
-
selectedLoop.visible = false;
|
|
446
|
-
selectedKey = "";
|
|
447
586
|
}
|
|
587
|
+
syncPaths(time, started, chosen !== null && set !== undefined && chosenDrawn ? chosen : null);
|
|
588
|
+
// The faint orbit: one path at a time, computed once from the elements already loaded, hidden while it is the chosen satellite's own orbit.
|
|
589
|
+
const hover = state.hover;
|
|
590
|
+
const hoverRef = hover.enabled && hover.fade > 0 ? hover.ref : null;
|
|
591
|
+
const hoverSet = hoverRef ? find(hoverRef) : undefined;
|
|
592
|
+
const sameAsSelected = Boolean(hoverRef && state.selected && hoverRef.group === state.selected.group && hoverRef.index === state.selected.index);
|
|
593
|
+
const hoverOk = Boolean(hoverRef && hoverSet && !sameAsSelected && hoverRef.index >= 0 && hoverRef.index < hoverSet.count && hoverSet.visible(hoverRef.index));
|
|
594
|
+
if (hoverOk && hoverRef && hoverSet) {
|
|
595
|
+
const key = `${hoverRef.group}:${hoverRef.index}`;
|
|
596
|
+
if (key !== hoverKey) {
|
|
597
|
+
hoverKey = key;
|
|
598
|
+
hoverLine.positions.set(hoverSet.orbit(hoverRef.index, time, ORBIT_POINTS).subarray(0, ORBIT_POINTS * 3));
|
|
599
|
+
hoverLine.geometry.getAttribute("position").needsUpdate = true;
|
|
600
|
+
}
|
|
601
|
+
hoverLine.material.color.set(hover.color || "#ffffff");
|
|
602
|
+
hoverLine.material.opacity = hover.opacity * hover.fade;
|
|
603
|
+
hoverLoop.visible = hoverLine.material.opacity > 0;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
hoverLoop.visible = false;
|
|
607
|
+
if (!hoverRef)
|
|
608
|
+
hoverKey = "";
|
|
609
|
+
}
|
|
610
|
+
state.drawn.hoverPath = hoverLoop.visible;
|
|
611
|
+
state.drawn.hoverOpacity = hoverLoop.visible ? hoverLine.material.opacity : 0;
|
|
448
612
|
state.drawn.placed = placed;
|
|
449
613
|
state.drawn.segments = segments;
|
|
450
614
|
state.drawn.longestStreakPx = longest;
|
|
@@ -500,22 +664,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
500
664
|
continue;
|
|
501
665
|
if (ortho) {
|
|
502
666
|
view.copy(world).applyMatrix4(camera.matrixWorldInverse);
|
|
503
|
-
if (view.
|
|
504
|
-
continue;
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
// behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
|
|
508
|
-
const px = world.x - c.x;
|
|
509
|
-
const py = world.y - c.y;
|
|
510
|
-
const pz = world.z - c.z;
|
|
511
|
-
const len2 = px * px + py * py + pz * pz;
|
|
512
|
-
const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
|
|
513
|
-
const nx = c.x + px * t;
|
|
514
|
-
const ny = c.y + py * t;
|
|
515
|
-
const nz = c.z + pz * t;
|
|
516
|
-
if (nx * nx + ny * ny + nz * nz < 0.998)
|
|
667
|
+
if (earthHidesDisc(view.x, view.y, view.z, centreDepth))
|
|
517
668
|
continue;
|
|
518
669
|
}
|
|
670
|
+
else if (earthHides(c, world))
|
|
671
|
+
continue;
|
|
519
672
|
best = { group: name, index: i };
|
|
520
673
|
bestD = d;
|
|
521
674
|
}
|
|
@@ -557,23 +710,48 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
557
710
|
const up = view.y;
|
|
558
711
|
const depth = view.z;
|
|
559
712
|
const centreDepth = world.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z;
|
|
560
|
-
hidden =
|
|
713
|
+
hidden = earthHidesDisc(right, up, depth, centreDepth);
|
|
561
714
|
world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
|
|
562
715
|
}
|
|
563
|
-
else
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
716
|
+
else
|
|
717
|
+
hidden = earthHides(c, world);
|
|
718
|
+
}
|
|
719
|
+
return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind, occluded: hidden };
|
|
720
|
+
},
|
|
721
|
+
pathAt(x, y, camera, size, radius) {
|
|
722
|
+
if (!(radius > 0))
|
|
723
|
+
return null;
|
|
724
|
+
const c = camera.position;
|
|
725
|
+
const ortho = camera.isOrthographicCamera === true;
|
|
726
|
+
const centreDepth = ortho ? view.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z : 0;
|
|
727
|
+
const loops = [];
|
|
728
|
+
const drawn = slots.filter((slot) => !slot.empty);
|
|
729
|
+
// the topmost look is the last drawn, so on a tie the later slot wins: walk them in reverse
|
|
730
|
+
const order = drawn.map((slot, i) => ({ slot, i })).reverse();
|
|
731
|
+
for (const { slot } of order) {
|
|
732
|
+
for (let i = 0; i < ORBIT_POINTS; i += 1) {
|
|
733
|
+
world.set(slot.positions[i * 3], slot.positions[i * 3 + 1], slot.positions[i * 3 + 2]).applyMatrix4(scene.matrixWorld);
|
|
734
|
+
projected.copy(world).project(camera);
|
|
735
|
+
slot.screen[i * 2] = ((projected.x + 1) / 2) * size.width;
|
|
736
|
+
slot.screen[i * 2 + 1] = ((1 - projected.y) / 2) * size.height;
|
|
737
|
+
let seen = projected.z <= 1 && projected.z >= -1 && Number.isFinite(projected.x) && Number.isFinite(projected.y);
|
|
738
|
+
if (seen) {
|
|
739
|
+
if (ortho) {
|
|
740
|
+
view.copy(world).applyMatrix4(camera.matrixWorldInverse);
|
|
741
|
+
seen = !earthHidesDisc(view.x, view.y, view.z, centreDepth);
|
|
742
|
+
}
|
|
743
|
+
else
|
|
744
|
+
seen = !earthHides(c, world);
|
|
745
|
+
}
|
|
746
|
+
slot.seen[i] = seen ? 1 : 0;
|
|
574
747
|
}
|
|
748
|
+
loops.push({ xy: slot.screen, ok: slot.seen, count: ORBIT_POINTS });
|
|
575
749
|
}
|
|
576
|
-
|
|
750
|
+
const best = nearestLoop(x, y, loops, radius);
|
|
751
|
+
if (!best)
|
|
752
|
+
return null;
|
|
753
|
+
const slot = order[best.index].slot;
|
|
754
|
+
return { ...slot.info, ref: { ...slot.info.ref }, x: best.x, y: best.y, distancePx: best.distance };
|
|
577
755
|
},
|
|
578
756
|
place(camera, size) {
|
|
579
757
|
if (!selectedPoints.visible)
|
|
@@ -590,11 +768,12 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
590
768
|
for (const entry of drawn.values())
|
|
591
769
|
drop(entry);
|
|
592
770
|
drawn.clear();
|
|
593
|
-
scene.remove(selectedPoints,
|
|
771
|
+
scene.remove(selectedPoints, hoverLoop);
|
|
772
|
+
ribbons.dispose();
|
|
594
773
|
selectedGeometry.dispose();
|
|
595
774
|
selectedMaterial.dispose();
|
|
596
|
-
|
|
597
|
-
|
|
775
|
+
hoverLine.geometry.dispose();
|
|
776
|
+
hoverLine.material.dispose();
|
|
598
777
|
},
|
|
599
778
|
};
|
|
600
779
|
}
|
|
@@ -154,6 +154,7 @@ export declare const MODEL_HANDOVER_PX = 10;
|
|
|
154
154
|
* Pure, so a test can ask it at any height.
|
|
155
155
|
*
|
|
156
156
|
* @param distanceKm - The camera's distance from the satellite, in kilometres.
|
|
157
|
+
* @param lowest - The share at the lowest height, `ABOVE_MODEL_SHARE` by default (a page sets it with `ride-model-share`).
|
|
157
158
|
* @returns The share, from 0 to 0.17.
|
|
158
159
|
*
|
|
159
160
|
* @example
|
|
@@ -163,4 +164,4 @@ export declare const MODEL_HANDOVER_PX = 10;
|
|
|
163
164
|
* console.log(aboveModelShare(150), aboveModelShare(1000) < aboveModelShare(150), aboveModelShare(6000));
|
|
164
165
|
* ```
|
|
165
166
|
*/
|
|
166
|
-
export declare function aboveModelShare(distanceKm: number): number;
|
|
167
|
+
export declare function aboveModelShare(distanceKm: number, lowest?: number): number;
|
|
@@ -180,6 +180,7 @@ export const MODEL_HANDOVER_PX = 10;
|
|
|
180
180
|
* Pure, so a test can ask it at any height.
|
|
181
181
|
*
|
|
182
182
|
* @param distanceKm - The camera's distance from the satellite, in kilometres.
|
|
183
|
+
* @param lowest - The share at the lowest height, `ABOVE_MODEL_SHARE` by default (a page sets it with `ride-model-share`).
|
|
183
184
|
* @returns The share, from 0 to 0.17.
|
|
184
185
|
*
|
|
185
186
|
* @example
|
|
@@ -189,10 +190,10 @@ export const MODEL_HANDOVER_PX = 10;
|
|
|
189
190
|
* console.log(aboveModelShare(150), aboveModelShare(1000) < aboveModelShare(150), aboveModelShare(6000));
|
|
190
191
|
* ```
|
|
191
192
|
*/
|
|
192
|
-
export function aboveModelShare(distanceKm) {
|
|
193
|
+
export function aboveModelShare(distanceKm, lowest = ABOVE_MODEL_SHARE) {
|
|
193
194
|
if (!(distanceKm > 0))
|
|
194
|
-
return
|
|
195
|
-
const base =
|
|
195
|
+
return lowest;
|
|
196
|
+
const base = lowest * Math.min(1, ABOVE_MODEL_KM / distanceKm);
|
|
196
197
|
const t = Math.min(1, Math.max(0, (distanceKm - MODEL_FADE_FROM_KM) / (MODEL_FADE_TO_KM - MODEL_FADE_FROM_KM)));
|
|
197
198
|
return base * (1 - t * t * (3 - 2 * t));
|
|
198
199
|
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { PlaceView } from "../markers/places.ts";
|
|
|
13
13
|
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
14
14
|
import type { CountryFrame } from "../country-names/geometry.ts";
|
|
15
15
|
import type { GeoPoint } from "../types.ts";
|
|
16
|
+
import type { PathHit } from "./paths.ts";
|
|
16
17
|
import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
|
|
17
18
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
18
19
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
@@ -21,6 +22,14 @@ import { type GridState } from "../grid/layer.ts";
|
|
|
21
22
|
import { type BeamState } from "../beam/layer.ts";
|
|
22
23
|
import { type RouteState } from "../route/layer.ts";
|
|
23
24
|
type Three = ThreeParts;
|
|
25
|
+
/** How big a satellite seen from outside by a ride from itself is drawn: its radius is this share of the height of the view (a model about a fifth of the height across; the satellite is a few metres, so this is not to scale). */
|
|
26
|
+
/** A number easing from one value to another (the model's share, its seat, how much of it is there): `cur` is where it is. */
|
|
27
|
+
export interface FrameEase {
|
|
28
|
+
cur: number;
|
|
29
|
+
from: number;
|
|
30
|
+
to: number;
|
|
31
|
+
start: number;
|
|
32
|
+
}
|
|
24
33
|
/** 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. */
|
|
25
34
|
export declare const DEFAULT_EARTH_SIZE = 0.9;
|
|
26
35
|
/**
|
|
@@ -143,6 +152,8 @@ export interface SpaceModel {
|
|
|
143
152
|
cloudDrift: number;
|
|
144
153
|
/** For the `space` camera: the Earth's turn against the stars (degrees) at the moment the camera was set, so it stays in the stars while the Earth turns beneath; null until the next draw sets it. */
|
|
145
154
|
cameraSpin: number | null;
|
|
155
|
+
/** How much of the Earth's turn the space camera takes: 0 holds the stars, 1 turns with the Earth. */
|
|
156
|
+
follow: number;
|
|
146
157
|
/** The share of the view's shorter side the Earth's disc fills at zoom 1, and where its centre is in the view (0 to 1 across and down; 0.5, 0.5 is the middle). */
|
|
147
158
|
earth: {
|
|
148
159
|
size: number;
|
|
@@ -225,6 +236,26 @@ export interface SpaceModel {
|
|
|
225
236
|
rideTurn: number;
|
|
226
237
|
/** 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. */
|
|
227
238
|
rideDistance: number | null;
|
|
239
|
+
/**
|
|
240
|
+
* The framing of the ridden satellite's model (MODULES-1316): the radius as a share of the picture's height and where its middle sits (a share of the height from the top) as the page set them (`null`: the ride's own), the eased values the last
|
|
241
|
+
* draw used, how long a change takes (0 for reduced motion), and the ground the picture spans below the satellite as of the last draw.
|
|
242
|
+
*/
|
|
243
|
+
rideFrame: {
|
|
244
|
+
share: number | null;
|
|
245
|
+
seat: number | null;
|
|
246
|
+
fresh: boolean;
|
|
247
|
+
ms: number;
|
|
248
|
+
moving: boolean;
|
|
249
|
+
share_: FrameEase;
|
|
250
|
+
seat_: FrameEase;
|
|
251
|
+
weight_: FrameEase;
|
|
252
|
+
groundKm: {
|
|
253
|
+
across: number;
|
|
254
|
+
tall: number;
|
|
255
|
+
} | null;
|
|
256
|
+
};
|
|
257
|
+
/** The page's path under a point of the view (CSS pixels), within a radius (`paths`, and the chosen satellite's own orbit), if a draw has been made and one is there. */
|
|
258
|
+
pathAt: ((x: number, y: number, radius: number) => Omit<PathHit, "pointer"> | null) | null;
|
|
228
259
|
/** The satellite at a point of the view (CSS pixels), within a radius, if a draw has been made and one is there. */
|
|
229
260
|
pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
|
|
230
261
|
/** The followed satellite's model, when there is one drawn: where its middle is on the screen (CSS pixels), as of the last draw. */
|
|
@@ -233,6 +264,9 @@ export interface SpaceModel {
|
|
|
233
264
|
y: number;
|
|
234
265
|
shown: boolean;
|
|
235
266
|
parts: number;
|
|
267
|
+
share: number;
|
|
268
|
+
seat: number;
|
|
269
|
+
weight: number;
|
|
236
270
|
radiusPx: number;
|
|
237
271
|
box: {
|
|
238
272
|
left: number;
|
|
@@ -417,6 +451,12 @@ export interface SpaceDeps {
|
|
|
417
451
|
x: number;
|
|
418
452
|
y: number;
|
|
419
453
|
} | null) => void;
|
|
454
|
+
/** Where the satellite under the pointer is, or null. Called at each draw while one is under the pointer (and once when it is let go). */
|
|
455
|
+
onHover?: (place: {
|
|
456
|
+
x: number;
|
|
457
|
+
y: number;
|
|
458
|
+
visible: boolean;
|
|
459
|
+
} | null) => void;
|
|
420
460
|
/** 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. */
|
|
421
461
|
onSatelliteMarks?: (marks: {
|
|
422
462
|
ref: SatelliteRef;
|
|
@@ -424,6 +464,7 @@ export interface SpaceDeps {
|
|
|
424
464
|
y: number;
|
|
425
465
|
visible: boolean;
|
|
426
466
|
heightKm: number;
|
|
467
|
+
occluded: boolean;
|
|
427
468
|
}[]) => void;
|
|
428
469
|
/** 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). */
|
|
429
470
|
onMoving?: () => void;
|