@johnmorrisdotca/chikyu-earth 0.33.1 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +23 -5
  3. package/dist/cities/geometry.d.ts +233 -0
  4. package/dist/cities/geometry.js +174 -0
  5. package/dist/cities/host.d.ts +73 -0
  6. package/dist/cities/host.js +240 -0
  7. package/dist/element.d.ts +1 -1
  8. package/dist/element.js +2 -13
  9. package/dist/markers/index.d.ts +1 -0
  10. package/dist/markers/index.js +1 -0
  11. package/dist/markers/labels.d.ts +7 -1
  12. package/dist/markers/labels.js +12 -1
  13. package/dist/markers/place-layer.d.ts +43 -0
  14. package/dist/markers/place-layer.js +238 -0
  15. package/dist/markers/places.d.ts +279 -0
  16. package/dist/markers/places.js +213 -0
  17. package/dist/passes/element.js +2 -5
  18. package/dist/realistic/body-label.js +19 -11
  19. package/dist/realistic/earth.d.ts +1 -1
  20. package/dist/realistic/element.d.ts +45 -5
  21. package/dist/realistic/element.js +96 -13
  22. package/dist/realistic/index.d.ts +3 -0
  23. package/dist/realistic/index.js +2 -0
  24. package/dist/satellites/index.d.ts +1 -0
  25. package/dist/satellites/index.js +1 -0
  26. package/dist/satellites/names.d.ts +14 -0
  27. package/dist/satellites/names.js +16 -0
  28. package/dist/sky/cover.d.ts +27 -0
  29. package/dist/sky/cover.js +32 -0
  30. package/dist/sky/frame.d.ts +21 -0
  31. package/dist/sky/frame.js +2 -0
  32. package/dist/sky/host.d.ts +10 -15
  33. package/dist/sky/host.js +37 -3
  34. package/dist/sky/style.d.ts +50 -0
  35. package/dist/sky/style.js +2 -0
  36. package/dist/space/element.d.ts +116 -8
  37. package/dist/space/element.js +253 -8
  38. package/dist/space/index.d.ts +4 -2
  39. package/dist/space/index.js +2 -1
  40. package/dist/space/ride.d.ts +60 -4
  41. package/dist/space/ride.js +78 -6
  42. package/dist/space/satellite-layer.d.ts +26 -0
  43. package/dist/space/satellite-layer.js +37 -1
  44. package/dist/space/satellite-model.d.ts +72 -0
  45. package/dist/space/satellite-model.js +82 -0
  46. package/dist/space/scene.d.ts +47 -2
  47. package/dist/space/scene.js +169 -1
  48. package/package.json +8 -4
@@ -5,10 +5,14 @@ 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
7
  import { ridePose } from "./ride.js";
8
+ import { coverBody, covers } from "../sky/cover.js";
9
+ import { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
8
10
  import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
9
11
  import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
10
12
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
11
13
  import { subsolarPoint, unitVector } from "../realistic/sun.js";
14
+ /** The most satellites ringed and named at once, over all the labelled groups. */
15
+ const MAX_MARKED = 80;
12
16
  const RAD = Math.PI / 180;
13
17
  const FOV = 35;
14
18
  /** 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. */
@@ -80,10 +84,14 @@ export const newSpaceModel = () => ({
80
84
  heightPx: 420,
81
85
  pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
82
86
  rideMotion: 0,
87
+ rideTurn: 0,
88
+ rideDistance: null,
83
89
  satellites: newSatelliteState(),
84
90
  meteors: newMeteorState(),
85
91
  bodyLabel: newBodyLabelState(),
86
92
  pick: null,
93
+ placeSatellite: null,
94
+ followModel: null,
87
95
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
88
96
  });
89
97
  /** An inertial direction from the Earth's centre, in scene axes, for right ascension and declination in degrees. */
@@ -266,6 +274,16 @@ export function createSpaceItem(model, deps) {
266
274
  let meteors = null;
267
275
  let meteorTimer;
268
276
  let nameOn = null;
277
+ let marksTold = false;
278
+ // 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
279
+ const modelSlot = { key: "", drawing: null, turn: 0 };
280
+ const dropModel = () => {
281
+ if (!modelSlot.drawing)
282
+ return;
283
+ scene.remove(modelSlot.drawing.object);
284
+ modelSlot.drawing.dispose();
285
+ modelSlot.drawing = null;
286
+ };
269
287
  let layer;
270
288
  const rideState = new Float64Array(6);
271
289
  let selectedShown = false;
@@ -380,8 +398,10 @@ export function createSpaceItem(model, deps) {
380
398
  let focusPos = pos[focus];
381
399
  let focusRadius = radiusOf(focus);
382
400
  let rideFrom = null;
401
+ let followed = null;
383
402
  model.rideLost = false;
384
403
  model.rideMotion = 0;
404
+ model.rideDistance = null;
385
405
  const ride = model.ride;
386
406
  if (ride) {
387
407
  if (typeof ride.target === "string") {
@@ -403,6 +423,7 @@ export function createSpaceItem(model, deps) {
403
423
  if (ride.view === "follow") {
404
424
  focusPos = place;
405
425
  focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / fit);
426
+ followed = { place, velocity: [rideState[3], rideState[4], rideState[5]], ref: ride.target };
406
427
  }
407
428
  else
408
429
  rideFrom = { position: place, velocity: [rideState[3], rideState[4], rideState[5]], hidden: null, gameSeconds: 0 };
@@ -420,7 +441,8 @@ export function createSpaceItem(model, deps) {
420
441
  let fovNow = FOV;
421
442
  let distance = 0;
422
443
  if (rideFrom) {
423
- const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom });
444
+ 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 });
445
+ model.rideDistance = Math.hypot(...rideFrom.position);
424
446
  camera.position.set(pose.position[0], pose.position[1], pose.position[2]);
425
447
  camera.up.set(pose.up[0], pose.up[1], pose.up[2]);
426
448
  camera.lookAt(pose.position[0] + pose.forward[0], pose.position[1] + pose.forward[1], pose.position[2] + pose.forward[2]);
@@ -522,6 +544,51 @@ export function createSpaceItem(model, deps) {
522
544
  if (held.slot.drawing?.object.visible)
523
545
  paintedMoons += 1;
524
546
  model.painted = { bodies: paintedBodies, moons: paintedMoons };
547
+ // the followed satellite as a model, when the page has one for it: made once, placed where the satellite is, pointed the way it flies, sized to read and lit by the Sun
548
+ const satellitePainter = deps.satellitePainter?.();
549
+ const group = followed ? model.satellites.groups.get(followed.ref.group) : undefined;
550
+ const norad = followed && group ? group.satellites.sets[followed.ref.index]?.NORAD_CAT_ID : undefined;
551
+ const modelKey = norad !== undefined && satellitePainter?.has(norad) ? String(norad) : "";
552
+ if (modelKey !== modelSlot.key) {
553
+ dropModel();
554
+ modelSlot.key = modelKey;
555
+ const turn = (modelSlot.turn += 1);
556
+ if (modelKey && satellitePainter && norad !== undefined) {
557
+ void Promise.resolve(satellitePainter.make(three, norad, { look: "", invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() }))
558
+ .then((made) => {
559
+ if (!made)
560
+ return;
561
+ if (ended || modelSlot.turn !== turn) {
562
+ made.dispose();
563
+ return;
564
+ }
565
+ made.object.matrixAutoUpdate = false;
566
+ made.object.visible = false;
567
+ scene.add(made.object);
568
+ modelSlot.drawing = made;
569
+ deps.invalidate();
570
+ })
571
+ .catch((error) => deps.onPainterError?.(error));
572
+ }
573
+ }
574
+ const axes = followed ? satelliteAxes(followed.place, followed.velocity) : null;
575
+ if (modelSlot.drawing && followed && axes) {
576
+ const object = modelSlot.drawing.object;
577
+ const away = Math.hypot(followed.place[0] - camera.position.x, followed.place[1] - camera.position.y, followed.place[2] - camera.position.z);
578
+ object.matrix.set(...modelMatrix(followed.place, axes, modelRadius(away, half, MODEL_RADIUS_SHARE, 1e-9)));
579
+ object.matrixWorldNeedsUpdate = true;
580
+ object.visible = true;
581
+ const toSunNow = unit(frame.sun);
582
+ modelSlot.drawing.light?.(toSunNow);
583
+ modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * MODEL_RADIUS_SHARE });
584
+ projected.set(followed.place[0], followed.place[1], followed.place[2]).project(camera);
585
+ model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true };
586
+ }
587
+ else {
588
+ if (modelSlot.drawing)
589
+ modelSlot.drawing.object.visible = false;
590
+ model.followModel = null;
591
+ }
525
592
  const sunToSun = unit([-frame.sun[0], -frame.sun[1], -frame.sun[2]]);
526
593
  sunDrawing?.update?.({ toSun: sunToSun, ms: model.time, radiusPx: px.Sun });
527
594
  for (const name of PLANETS) {
@@ -590,6 +657,65 @@ export function createSpaceItem(model, deps) {
590
657
  }
591
658
  deps.onLabels(places);
592
659
  }
660
+ // the ringed satellites first, so their names are laid out with the places' in this same draw
661
+ model.placeSatellite = layer ? (ref) => layer.placeOf(ref, camera, size) : null;
662
+ if (deps.onSatelliteMarks) {
663
+ if (layer && model.satellites.marked.size > 0) {
664
+ const marks = [];
665
+ for (const name of model.satellites.marked) {
666
+ const group = model.satellites.groups.get(name);
667
+ if (!group)
668
+ continue;
669
+ for (let index = 0; index < group.satellites.count && marks.length < MAX_MARKED; index += 1) {
670
+ const ref = { group: name, index };
671
+ const at = layer.placeOf(ref, camera, size);
672
+ if (at)
673
+ marks.push({ ref, ...at });
674
+ }
675
+ }
676
+ marksTold = true;
677
+ deps.onSatelliteMarks(marks);
678
+ }
679
+ else if (marksTold) {
680
+ marksTold = false;
681
+ deps.onSatelliteMarks([]);
682
+ }
683
+ }
684
+ if (deps.onPlaces) {
685
+ // a place on the ground, turned with the Earth into the scene's axes, seen through the camera: where it falls, which way its upright points on the screen, and whether it faces the camera
686
+ const turn = earth.rotation.y;
687
+ const cos = Math.cos(turn);
688
+ const sin = Math.sin(turn);
689
+ const eye = camera.position;
690
+ deps.onPlaces({
691
+ width: size.width,
692
+ height: size.height,
693
+ at(lon, lat, out) {
694
+ const la = lat * RAD;
695
+ const lo = lon * RAD;
696
+ const lx = Math.cos(la) * Math.sin(lo);
697
+ const lz = Math.cos(la) * Math.cos(lo);
698
+ const wx = lx * cos + lz * sin;
699
+ const wy = Math.sin(la);
700
+ const wz = -lx * sin + lz * cos;
701
+ const away = Math.hypot(eye.x - wx, eye.y - wy, eye.z - wz) || 1;
702
+ out.facing = (wx * (eye.x - wx) + wy * (eye.y - wy) + wz * (eye.z - wz)) / away;
703
+ projected.set(wx, wy, wz).project(camera);
704
+ if (projected.z > 1 || projected.z < -1)
705
+ return false;
706
+ out.x = ((projected.x + 1) / 2) * size.width;
707
+ out.y = ((1 - projected.y) / 2) * size.height;
708
+ projected.set(wx * 1.001, wy * 1.001, wz * 1.001).project(camera);
709
+ const dx = ((projected.x + 1) / 2) * size.width - out.x;
710
+ const dy = ((1 - projected.y) / 2) * size.height - out.y;
711
+ const seen = Math.hypot(dx, dy);
712
+ const side = Math.sqrt(Math.max(0, 1 - out.facing * out.facing));
713
+ out.upX = seen > 0 ? (dx / seen) * side : 0;
714
+ out.upY = seen > 0 ? (dy / seen) * side : 0;
715
+ return true;
716
+ },
717
+ });
718
+ }
593
719
  // 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
594
720
  if (model.bodyLabel.settings && !nameOn)
595
721
  nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
@@ -606,10 +732,21 @@ export function createSpaceItem(model, deps) {
606
732
  continue;
607
733
  discs.push({ x: ((sky.x + 1) / 2) * size.width, y: ((1 - sky.y) / 2) * size.height, radius: Math.min(px[name], 1e5) });
608
734
  }
735
+ // a body covers the sky where the ray through a pixel passes within the body's angular radius of its centre: exact for any field of view, where a circle on the screen is right only on the axis
736
+ const ray = new three.Vector3();
737
+ const bodies = ["Earth", "Moon", "Sun"].map((name) => coverBody(pos[name], [camera.position.x, camera.position.y, camera.position.z], radiusOf(name)));
609
738
  deps.onSky({
610
739
  width: size.width,
611
740
  height: size.height,
612
741
  discs,
742
+ covered(x, y) {
743
+ ray.set((x / size.width) * 2 - 1, 1 - (y / size.height) * 2, 0.5).unproject(camera).sub(camera.position);
744
+ const length = ray.length() || 1;
745
+ const rx = ray.x / length;
746
+ const ry = ray.y / length;
747
+ const rz = ray.z / length;
748
+ return covers(bodies, rx, ry, rz);
749
+ },
613
750
  project(rightAscension, declination, out) {
614
751
  const r = rightAscension * RAD;
615
752
  const d = declination * RAD;
@@ -620,6 +757,34 @@ export function createSpaceItem(model, deps) {
620
757
  },
621
758
  });
622
759
  }
760
+ if (deps.onCities) {
761
+ if (hidden === "Earth")
762
+ deps.onCities(null);
763
+ else {
764
+ // a place on the ground, turned with the Earth (the Earth is at the middle, one unit in radius): in sight when the viewer is above its horizon, found through the camera
765
+ const ground = new three.Vector3();
766
+ const eye = camera.position;
767
+ const turned = earth.quaternion;
768
+ deps.onCities({
769
+ width: size.width,
770
+ height: size.height,
771
+ radius: Math.min(px.Earth, 1e5),
772
+ project(lon, lat, out) {
773
+ const phi = lat * RAD;
774
+ const lambda = lon * RAD;
775
+ ground.set(Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)).applyQuaternion(turned);
776
+ const dx = eye.x - ground.x;
777
+ const dy = eye.y - ground.y;
778
+ const dz = eye.z - ground.z;
779
+ const facing = (ground.x * dx + ground.y * dy + ground.z * dz) / (Math.hypot(dx, dy, dz) || 1);
780
+ ground.project(camera);
781
+ out.x = ((ground.x + 1) / 2) * size.width;
782
+ out.y = ((1 - ground.y) / 2) * size.height;
783
+ return ground.z > 1 || ground.z < -1 ? -1 : facing;
784
+ },
785
+ });
786
+ }
787
+ }
623
788
  if (layer && deps.onSelected) {
624
789
  const at = model.satellites.selected ? layer.place(camera, size) : null;
625
790
  if (at || selectedShown)
@@ -656,8 +821,11 @@ export function createSpaceItem(model, deps) {
656
821
  clearTimeout(meteorTimer);
657
822
  meteors?.dispose();
658
823
  nameOn?.dispose();
824
+ modelSlot.turn += 1;
825
+ dropModel();
659
826
  layer?.dispose();
660
827
  model.pick = null;
828
+ model.placeSatellite = null;
661
829
  textures.dispose();
662
830
  ended = true;
663
831
  empty(sunSlot);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.33.1",
4
- "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on where you are, 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.",
3
+ "version": "0.34.0",
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",
7
7
  "globe",
@@ -195,11 +195,12 @@
195
195
  },
196
196
  "dependencies": {
197
197
  "@johnmorrisdotca/chizu": "^1.6.0",
198
- "@johnmorrisdotca/kazoku-ui": "^0.36.0",
198
+ "@johnmorrisdotca/kazoku-ui": "^0.38.1",
199
199
  "d3-geo": "^3.1.1"
200
200
  },
201
201
  "peerDependencies": {
202
202
  "@johnmorrisdotca/hoshi-stars": ">=0.30.0",
203
+ "@johnmorrisdotca/kuni": ">=1.6.1",
203
204
  "@johnmorrisdotca/wakusei-planets": ">=0.5.0",
204
205
  "astronomy-engine": ">=2.1.0",
205
206
  "satellite.js": ">=6.0.0",
@@ -220,6 +221,9 @@
220
221
  },
221
222
  "@johnmorrisdotca/hoshi-stars": {
222
223
  "optional": true
224
+ },
225
+ "@johnmorrisdotca/kuni": {
226
+ "optional": true
223
227
  }
224
228
  },
225
229
  "devDependencies": {
@@ -230,7 +234,7 @@
230
234
  "@eslint/js": "^9.0.0",
231
235
  "@johnmorrisdotca/hata": "^1.8.0",
232
236
  "@johnmorrisdotca/hoshi-stars": "^0.30.0",
233
- "@johnmorrisdotca/kuni": "^1.5.0",
237
+ "@johnmorrisdotca/kuni": "^1.6.1",
234
238
  "@johnmorrisdotca/wakusei-planets": "^0.5.0",
235
239
  "@playwright/test": "1.64.0",
236
240
  "@sveltejs/vite-plugin-svelte": "^7.3.1",