@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
package/dist/space/scene.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
|
7
7
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
8
8
|
import { faceOffset, outsidePose, ridePose } from "./ride.js";
|
|
9
9
|
import { genericSatellite, satelliteKind } from "./generic-satellite.js";
|
|
10
|
+
import { followSpin } from "./follow.js";
|
|
10
11
|
import { coverBody, covers } from "../sky/cover.js";
|
|
11
12
|
import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
|
|
12
13
|
import { ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
@@ -24,10 +25,29 @@ import { subsolarPoint, unitVector } from "../realistic/sun.js";
|
|
|
24
25
|
const MAX_MARKED = 80;
|
|
25
26
|
const RAD = Math.PI / 180;
|
|
26
27
|
const FOV = 35;
|
|
27
|
-
|
|
28
|
+
const newEase = () => ({ cur: Number.NaN, from: Number.NaN, to: Number.NaN, start: 0 });
|
|
29
|
+
/** Moves an ease towards `to`: at once when it is new or `ms` is 0 (reduced motion), else over `ms` milliseconds with a smooth step. True while it is still on its way. */
|
|
30
|
+
function stepEase(e, to, now, ms, fresh) {
|
|
31
|
+
if (fresh || !Number.isFinite(e.cur)) {
|
|
32
|
+
e.cur = e.from = e.to = to;
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (to !== e.to) {
|
|
36
|
+
e.from = e.cur;
|
|
37
|
+
e.to = to;
|
|
38
|
+
e.start = now;
|
|
39
|
+
}
|
|
40
|
+
const k = ms > 0 ? Math.min(1, Math.max(0, (now - e.start) / ms)) : 1;
|
|
41
|
+
e.cur = e.from + (e.to - e.from) * k * k * (3 - 2 * k);
|
|
42
|
+
if (k >= 1)
|
|
43
|
+
e.cur = to;
|
|
44
|
+
return k < 1;
|
|
45
|
+
}
|
|
46
|
+
/** The radius share and the seat the rides have when the page sets none: along the way it goes the model is large and low (0.22, 0.86), looking down it is small and in the middle. */
|
|
47
|
+
const ALONG_SEAT = 0.86;
|
|
28
48
|
const OUTSIDE_RADIUS_SHARE = 0.1;
|
|
29
49
|
/** The share of the view's height an outside ride along (looking along the way it goes) draws the satellite's radius at: it sits at the bottom middle with part of it below the bottom edge, large enough to read and to be drawn sharp (MODULES-1303). */
|
|
30
|
-
const OUTSIDE_ALONG_SHARE = 0.
|
|
50
|
+
const OUTSIDE_ALONG_SHARE = 0.22;
|
|
31
51
|
/** 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. */
|
|
32
52
|
export const DEFAULT_EARTH_SIZE = 0.9;
|
|
33
53
|
/**
|
|
@@ -87,6 +107,7 @@ export const newSpaceModel = () => ({
|
|
|
87
107
|
airThickness: AIR_THICKNESS_DEFAULT,
|
|
88
108
|
cloudDrift: 0,
|
|
89
109
|
cameraSpin: null,
|
|
110
|
+
follow: 0,
|
|
90
111
|
earth: { size: DEFAULT_EARTH_SIZE, x: 0.5, y: 0.5 },
|
|
91
112
|
fit: fitDistance(DEFAULT_EARTH_SIZE, 1),
|
|
92
113
|
orbits: true,
|
|
@@ -117,8 +138,10 @@ export const newSpaceModel = () => ({
|
|
|
117
138
|
beam: newBeamState(),
|
|
118
139
|
route: newRouteState(),
|
|
119
140
|
pick: null,
|
|
141
|
+
pathAt: null,
|
|
120
142
|
placeSatellite: null,
|
|
121
143
|
followModel: null,
|
|
144
|
+
rideFrame: { share: null, seat: null, fresh: true, ms: 400, moving: false, share_: newEase(), seat_: newEase(), weight_: newEase(), groundKm: null },
|
|
122
145
|
tiles: null,
|
|
123
146
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
124
147
|
});
|
|
@@ -387,6 +410,7 @@ export function createSpaceItem(model, deps) {
|
|
|
387
410
|
modelSlot.drawing = null;
|
|
388
411
|
};
|
|
389
412
|
let layer;
|
|
413
|
+
let hoverShown = false;
|
|
390
414
|
const rideState = new Float64Array(6);
|
|
391
415
|
let selectedShown = false;
|
|
392
416
|
const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
|
|
@@ -516,20 +540,44 @@ export function createSpaceItem(model, deps) {
|
|
|
516
540
|
deps.onSatellitesError?.(error);
|
|
517
541
|
}
|
|
518
542
|
}
|
|
543
|
+
// the framing of the ridden satellite's model: its share of the picture, where its middle sits and how much of it there is (a switch to the view from inside fades it out over 0.4 s), each eased towards what the page set or the ride's own
|
|
544
|
+
let frameMoving = false;
|
|
545
|
+
const framing = (() => {
|
|
546
|
+
const riding = model.ride;
|
|
547
|
+
const f = model.rideFrame;
|
|
548
|
+
if (!riding || typeof riding.target === "string") {
|
|
549
|
+
f.fresh = true;
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
const along = riding.view === "from" && riding.look === "horizon";
|
|
553
|
+
const base = riding.view === "above" ? ABOVE_MODEL_SHARE : riding.view === "from" ? (along ? OUTSIDE_ALONG_SHARE : OUTSIDE_RADIUS_SHARE) : MODEL_RADIUS_SHARE;
|
|
554
|
+
const now = performance.now();
|
|
555
|
+
if (stepEase(f.share_, f.share ?? base, now, f.ms, f.fresh))
|
|
556
|
+
frameMoving = true;
|
|
557
|
+
if (stepEase(f.seat_, f.seat ?? (along ? ALONG_SEAT : 0.5), now, f.ms, f.fresh))
|
|
558
|
+
frameMoving = true;
|
|
559
|
+
if (stepEase(f.weight_, riding.viewpoint === "outside" ? 1 : 0, now, f.ms, f.fresh))
|
|
560
|
+
frameMoving = true;
|
|
561
|
+
f.fresh = false;
|
|
562
|
+
return { share: f.share_.cur, seat: f.seat_.cur, weight: f.weight_.cur };
|
|
563
|
+
})();
|
|
564
|
+
model.rideFrame.moving = frameMoving;
|
|
519
565
|
// the ridden satellite is drawn as its model while the model is big enough to read; its ring and name (the page's choice of it, or the marks) are left off exactly then, and come back when the model has shrunk to the size of a ring (MODULES-1303, 1306)
|
|
520
566
|
{
|
|
521
567
|
const riding = model.ride;
|
|
522
568
|
let over = null;
|
|
523
|
-
if (riding && riding.viewpoint === "outside" && typeof riding.target !== "string") {
|
|
569
|
+
if (framing && riding && riding.viewpoint === "outside" && typeof riding.target !== "string") {
|
|
524
570
|
const kmAbove = riding.distanceKm / Math.max(1e-9, model.view.zoom);
|
|
525
|
-
const would = riding.view === "above" ? (riding.modelSize === "fixed" ?
|
|
571
|
+
const would = (riding.view === "above" ? (riding.modelSize === "fixed" ? framing.share : aboveModelShare(kmAbove, framing.share)) : framing.share) * framing.weight;
|
|
526
572
|
if (would * size.height >= MODEL_HANDOVER_PX)
|
|
527
573
|
over = riding.target;
|
|
528
574
|
}
|
|
529
575
|
model.satellites.modelOver = over;
|
|
576
|
+
model.satellites.ridden = riding && typeof riding.target === "object" ? riding.target : null;
|
|
530
577
|
}
|
|
531
|
-
layer?.update(model.time, model.speed, model.drawn?.radiusPx ?? 0);
|
|
578
|
+
layer?.update(model.time, model.speed, model.drawn?.radiusPx ?? 0, size);
|
|
532
579
|
model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
|
|
580
|
+
model.pathAt = layer ? (x, y, radius) => layer.pathAt(x, y, camera, size, radius) : null;
|
|
533
581
|
// 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
|
|
534
582
|
// body and looks at the Earth
|
|
535
583
|
let focus = model.focus;
|
|
@@ -591,7 +639,7 @@ export function createSpaceItem(model, deps) {
|
|
|
591
639
|
// an outside ride: the same look, from a little way back along it, so the satellite is in the picture
|
|
592
640
|
let outsideAway = Infinity;
|
|
593
641
|
if (ridden && ride.viewpoint === "outside") {
|
|
594
|
-
const out = outsidePose(pose, ride.look);
|
|
642
|
+
const out = outsidePose(pose, ride.look, framing ? (framing.seat - 0.5) / 0.5 : undefined);
|
|
595
643
|
pose = out.pose;
|
|
596
644
|
outsideAway = out.distance;
|
|
597
645
|
}
|
|
@@ -614,7 +662,8 @@ export function createSpaceItem(model, deps) {
|
|
|
614
662
|
if (model.camera === "space") {
|
|
615
663
|
if (model.cameraSpin === null)
|
|
616
664
|
model.cameraSpin = frame.spin;
|
|
617
|
-
|
|
665
|
+
// 0 holds the stars (the anchor alone, as before). 1 uses the Earth's turn now. In between, that share of the turn since the anchor.
|
|
666
|
+
spin = followSpin(model.cameraSpin, frame.spin, model.follow);
|
|
618
667
|
}
|
|
619
668
|
else if (model.camera === "sun") {
|
|
620
669
|
spin = Math.atan2(-frame.sun[2], frame.sun[0]) / RAD;
|
|
@@ -669,6 +718,14 @@ export function createSpaceItem(model, deps) {
|
|
|
669
718
|
}
|
|
670
719
|
camera.fov = fovNow;
|
|
671
720
|
camera.aspect = size.width / Math.max(1, size.height);
|
|
721
|
+
// the ground the picture spans straight below a ridden satellite, in kilometres: the height above the ground over the vertical field of view (flat-ground, to compare with a tile level's size)
|
|
722
|
+
if (framing) {
|
|
723
|
+
const heightKm = Math.max(0, (Math.hypot(camera.position.x, camera.position.y, camera.position.z) - 1) * 6371);
|
|
724
|
+
const tall = 2 * heightKm * Math.tan((fovNow / 2) * RAD);
|
|
725
|
+
model.rideFrame.groundKm = { across: tall * camera.aspect, tall };
|
|
726
|
+
}
|
|
727
|
+
else
|
|
728
|
+
model.rideFrame.groundKm = null;
|
|
672
729
|
// the Earth's place in the view: the picture is moved, not the camera (a camera riding from a body, or above a satellite, keeps the middle)
|
|
673
730
|
const centred = rideFrom !== null || (ride?.view === "above" && followed !== null);
|
|
674
731
|
const shiftX = centred ? 0 : (model.earth.x - 0.5) * size.width;
|
|
@@ -790,7 +847,7 @@ export function createSpaceItem(model, deps) {
|
|
|
790
847
|
const satellitePainter = deps.satellitePainter?.();
|
|
791
848
|
// the satellite to draw: the one followed or seen from above, or (an outside ride from the satellite itself) the one ridden
|
|
792
849
|
const candidate = followed ?? ridden;
|
|
793
|
-
const shownSat = followed ?? (ride?.viewpoint === "outside" ? ridden : null);
|
|
850
|
+
const shownSat = followed ?? (ride?.viewpoint === "outside" || (framing !== null && framing.weight > 0.001) ? ridden : null);
|
|
794
851
|
const group = candidate ? model.satellites.groups.get(candidate.ref.group) : undefined;
|
|
795
852
|
const set = candidate && group ? group.satellites.sets[candidate.ref.index] : undefined;
|
|
796
853
|
const norad = set?.NORAD_CAT_ID;
|
|
@@ -839,13 +896,15 @@ export function createSpaceItem(model, deps) {
|
|
|
839
896
|
modelSlot.axes = null;
|
|
840
897
|
const axes = freshAxes ?? (shownSat ? modelSlot.axes : null);
|
|
841
898
|
// a generic drawing is for an outside ride only; a page's model is drawn wherever the camera is not at the satellite
|
|
842
|
-
const drawn = shownSat !== null && (ride?.viewpoint === "outside" || (followed !== null && painted));
|
|
843
|
-
const aboveShare = followed && ride?.view === "above" && ride.modelSize !== "fixed" ? aboveModelShare(Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z) * 6371) : 1;
|
|
899
|
+
const drawn = shownSat !== null && (ride?.viewpoint === "outside" || (framing !== null && framing.weight > 0.001) || (followed !== null && painted));
|
|
900
|
+
const aboveShare = followed && ride?.view === "above" && ride.modelSize !== "fixed" ? aboveModelShare(Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z) * 6371, framing?.share) : 1;
|
|
844
901
|
// from far above the satellite is a point: the model has shrunk to nothing and the ordinary mark is all there is
|
|
845
902
|
if (modelSlot.drawing && shownSat && axes && drawn && aboveShare * size.height >= 0.5) {
|
|
846
903
|
const object = modelSlot.drawing.object;
|
|
847
904
|
const away = Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z);
|
|
848
|
-
const
|
|
905
|
+
const shape = framing?.share ?? MODEL_RADIUS_SHARE;
|
|
906
|
+
const weight = framing ? (followed !== null && ride?.viewpoint !== "outside" && framing.weight <= 0.001 ? 1 : framing.weight) : 1;
|
|
907
|
+
const share = (followed !== null && ride?.view === "above" && ride.modelSize !== "fixed" ? aboveModelShare(away * 6371, shape) : shape) * weight;
|
|
849
908
|
object.matrix.set(...modelMatrix(shownSat.place, axes, modelRadius(away, half, share, 1e-9)));
|
|
850
909
|
object.matrixWorldNeedsUpdate = true;
|
|
851
910
|
object.visible = true;
|
|
@@ -856,7 +915,7 @@ export function createSpaceItem(model, deps) {
|
|
|
856
915
|
const sx = ((projected.x + 1) / 2) * size.width;
|
|
857
916
|
const sy = ((1 - projected.y) / 2) * size.height;
|
|
858
917
|
const radiusPx = size.height * share;
|
|
859
|
-
model.followModel = { x: sx, y: sy, shown: true, parts: modelSlot.parts, radiusPx, box: { left: sx - radiusPx, top: sy - radiusPx, right: sx + radiusPx, bottom: sy + radiusPx }, axes };
|
|
918
|
+
model.followModel = { x: sx, y: sy, shown: true, parts: modelSlot.parts, share, seat: sy / size.height, weight, radiusPx, box: { left: sx - radiusPx, top: sy - radiusPx, right: sx + radiusPx, bottom: sy + radiusPx }, axes };
|
|
860
919
|
}
|
|
861
920
|
else {
|
|
862
921
|
if (modelSlot.drawing)
|
|
@@ -1088,6 +1147,15 @@ export function createSpaceItem(model, deps) {
|
|
|
1088
1147
|
deps.onSelected(at);
|
|
1089
1148
|
selectedShown = at !== null;
|
|
1090
1149
|
}
|
|
1150
|
+
if (layer && deps.onHover) {
|
|
1151
|
+
const hover = model.satellites.hover;
|
|
1152
|
+
const ref = hover.enabled && hover.ref && hover.fade > 0 ? hover.ref : null;
|
|
1153
|
+
const at = ref ? layer.placeOf(ref, camera, size) : null;
|
|
1154
|
+
const place = at ? { x: at.x, y: at.y, visible: at.visible } : null;
|
|
1155
|
+
if (place || hoverShown)
|
|
1156
|
+
deps.onHover(place);
|
|
1157
|
+
hoverShown = place !== null;
|
|
1158
|
+
}
|
|
1091
1159
|
// the meteors, on the Earth: made the first time they are switched on, and asking for their own next draw while a streak is alive or one is due
|
|
1092
1160
|
if (model.meteors.on && !meteors)
|
|
1093
1161
|
meteors = createMeteorLayer(three, earth, model.meteors);
|
|
@@ -1156,7 +1224,7 @@ export function createSpaceItem(model, deps) {
|
|
|
1156
1224
|
routeLayer?.sync();
|
|
1157
1225
|
if (model.rideLost)
|
|
1158
1226
|
deps.onRideLost?.();
|
|
1159
|
-
if (model.transition)
|
|
1227
|
+
if (model.transition || frameMoving)
|
|
1160
1228
|
deps.onMoving?.();
|
|
1161
1229
|
return false;
|
|
1162
1230
|
},
|
|
@@ -1183,6 +1251,7 @@ export function createSpaceItem(model, deps) {
|
|
|
1183
1251
|
dropModel();
|
|
1184
1252
|
layer?.dispose();
|
|
1185
1253
|
model.pick = null;
|
|
1254
|
+
model.pathAt = null;
|
|
1186
1255
|
model.placeSatellite = null;
|
|
1187
1256
|
model.tiles = null;
|
|
1188
1257
|
tiles.dispose();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.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",
|
|
@@ -174,6 +174,11 @@
|
|
|
174
174
|
"import": "./dist/catalogue/index.js",
|
|
175
175
|
"default": "./dist/catalogue/index.js"
|
|
176
176
|
},
|
|
177
|
+
"./place": {
|
|
178
|
+
"types": "./dist/place/index.d.ts",
|
|
179
|
+
"import": "./dist/place/index.js",
|
|
180
|
+
"default": "./dist/place/index.js"
|
|
181
|
+
},
|
|
177
182
|
"./package.json": "./package.json"
|
|
178
183
|
},
|
|
179
184
|
"files": [
|