@johnmorrisdotca/chikyu-earth 0.35.0 → 0.36.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 (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/NOTICE.md +23 -1
  3. package/README.md +20 -2
  4. package/dist/borders/layer.d.ts +75 -0
  5. package/dist/borders/layer.js +136 -0
  6. package/dist/borders/lines.d.ts +138 -0
  7. package/dist/borders/lines.js +227 -0
  8. package/dist/cities/host.d.ts +9 -0
  9. package/dist/cities/host.js +14 -2
  10. package/dist/country-names/geometry.d.ts +264 -0
  11. package/dist/country-names/geometry.js +372 -0
  12. package/dist/country-names/host.d.ts +82 -0
  13. package/dist/country-names/host.js +212 -0
  14. package/dist/grid/layer.d.ts +45 -0
  15. package/dist/grid/layer.js +66 -0
  16. package/dist/grid/lines.d.ts +85 -0
  17. package/dist/grid/lines.js +113 -0
  18. package/dist/markers/go-to-place.d.ts +27 -0
  19. package/dist/markers/go-to-place.js +35 -0
  20. package/dist/markers/index.d.ts +2 -1
  21. package/dist/markers/index.js +2 -1
  22. package/dist/markers/layer.d.ts +7 -0
  23. package/dist/markers/layer.js +7 -0
  24. package/dist/markers/place-layer.d.ts +58 -7
  25. package/dist/markers/place-layer.js +326 -64
  26. package/dist/markers/place-sprites.d.ts +33 -0
  27. package/dist/markers/place-sprites.js +161 -0
  28. package/dist/markers/places.d.ts +91 -6
  29. package/dist/markers/places.js +135 -6
  30. package/dist/realistic/earth.d.ts +11 -0
  31. package/dist/realistic/earth.js +54 -0
  32. package/dist/realistic/element.d.ts +65 -4
  33. package/dist/realistic/element.js +198 -26
  34. package/dist/realistic/immersive.d.ts +7 -0
  35. package/dist/realistic/immersive.js +17 -0
  36. package/dist/realistic/index.d.ts +6 -0
  37. package/dist/realistic/index.js +3 -0
  38. package/dist/realistic/textures.d.ts +3 -0
  39. package/dist/space/element.d.ts +81 -7
  40. package/dist/space/element.js +246 -16
  41. package/dist/space/index.d.ts +1 -1
  42. package/dist/space/scene.d.ts +53 -5
  43. package/dist/space/scene.js +88 -8
  44. package/package.json +3 -3
@@ -6,10 +6,13 @@ 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
8
  import { coverBody, covers } from "../sky/cover.js";
9
+ import { createPlaceSprites } from "../markers/place-sprites.js";
9
10
  import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
10
11
  import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
11
12
  import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
12
13
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
14
+ import { createBorderLayer, newBorderState } from "../borders/layer.js";
15
+ import { createGridLayer, newGridState } from "../grid/layer.js";
13
16
  import { subsolarPoint, unitVector } from "../realistic/sun.js";
14
17
  /** The most satellites ringed and named at once, over all the labelled groups. */
15
18
  const MAX_MARKED = 80;
@@ -74,13 +77,14 @@ export const newSpaceModel = () => ({
74
77
  bodies: "",
75
78
  light: "sun",
76
79
  drawn: null,
77
- painted: { bodies: 0, moons: 0 },
80
+ painted: { bodies: 0, moons: 0, held: 0, moon: false, tiles: 0 },
78
81
  lookups: 0,
79
82
  speed: 1,
80
83
  ride: null,
81
84
  rideLost: false,
82
85
  transition: null,
83
86
  drawnView: null,
87
+ lookBase: null,
84
88
  heightPx: 420,
85
89
  pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
86
90
  rideMotion: 0,
@@ -89,6 +93,8 @@ export const newSpaceModel = () => ({
89
93
  satellites: newSatelliteState(),
90
94
  meteors: newMeteorState(),
91
95
  bodyLabel: newBodyLabelState(),
96
+ borders: newBorderState(),
97
+ grid: newGridState(),
92
98
  pick: null,
93
99
  placeSatellite: null,
94
100
  followModel: null,
@@ -248,7 +254,7 @@ export function createSpaceItem(model, deps) {
248
254
  }
249
255
  };
250
256
  try {
251
- const made = (slot.plain || look === "plain" ? plainPainter : painter).make(three, slot.name, { look, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() });
257
+ const made = (slot.plain || look === "plain" ? plainPainter : painter).make(three, slot.name, { look, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap(), mapped: true });
252
258
  if (typeof made.then === "function")
253
259
  made.then(arrive, fail);
254
260
  else
@@ -259,6 +265,8 @@ export function createSpaceItem(model, deps) {
259
265
  }
260
266
  };
261
267
  const sunSlot = newSlot("Sun");
268
+ // the Moon from the painter when there is one (its picture, and finer tiles where it has them); the view's own Moon until it arrives, and if it cannot be made
269
+ const moonSlot = newSlot("Moon");
262
270
  const planets = new Map();
263
271
  for (const name of PLANETS) {
264
272
  const positions = new Float32Array(96 * 3);
@@ -274,6 +282,10 @@ export function createSpaceItem(model, deps) {
274
282
  let meteors = null;
275
283
  let meteorTimer;
276
284
  let nameOn = null;
285
+ let borders = null;
286
+ let placeSprites = null;
287
+ let placeSpritesTried = false;
288
+ let gridLayer = null;
277
289
  let marksTold = false;
278
290
  // 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
291
  const modelSlot = { key: "", drawing: null, turn: 0, parts: 0 };
@@ -348,6 +360,18 @@ export function createSpaceItem(model, deps) {
348
360
  for (const name of PLANETS)
349
361
  pos[name] = placeAround(mode, sunPos, helioOf(frame.planets[name]));
350
362
  const radiusOf = (name) => (name === "Earth" ? 1 : RADIUS[name][mode]);
363
+ if (deps.painter && lookNow() !== "plain")
364
+ fill(moonSlot, true);
365
+ else if (moonSlot.look !== null) {
366
+ empty(moonSlot);
367
+ moonSlot.look = null;
368
+ }
369
+ const paintedMoon = moonSlot.drawing;
370
+ if (paintedMoon) {
371
+ paintedMoon.object.position.set(moonPos[0], moonPos[1], moonPos[2]);
372
+ paintedMoon.object.scale.setScalar(RADIUS["Moon"][mode]);
373
+ paintedMoon.light?.(moonToSun);
374
+ }
351
375
  // the Sun and the planets, drawn by the painter, and the planets' orbits round the Sun
352
376
  fill(sunSlot);
353
377
  const sunDrawing = sunSlot.drawing;
@@ -400,6 +424,7 @@ export function createSpaceItem(model, deps) {
400
424
  let rideFrom = null;
401
425
  let followed = null;
402
426
  model.rideLost = false;
427
+ model.lookBase = null;
403
428
  model.rideMotion = 0;
404
429
  model.rideDistance = null;
405
430
  const ride = model.ride;
@@ -432,7 +457,9 @@ export function createSpaceItem(model, deps) {
432
457
  model.rideLost = true;
433
458
  }
434
459
  const hidden = rideFrom?.hidden ?? null;
435
- moon.visible = hidden !== "Moon";
460
+ moon.visible = hidden !== "Moon" && !paintedMoon;
461
+ if (paintedMoon)
462
+ paintedMoon.object.visible = hidden !== "Moon";
436
463
  if (sunDrawing)
437
464
  sunDrawing.object.visible = hidden !== "Sun";
438
465
  for (const [name, p] of planets)
@@ -486,6 +513,8 @@ export function createSpaceItem(model, deps) {
486
513
  camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
487
514
  }
488
515
  else {
516
+ if (way === 1 && focus === "Earth")
517
+ model.lookBase = { lon: model.centre.lon + spin - frame.spin, lat: baseLat };
489
518
  distance = Math.max(1.05 * focusRadius, (fit * focusRadius) / Math.max(1e-9, model.view.zoom));
490
519
  target.set(focusPos[0], focusPos[1], focusPos[2]);
491
520
  camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
@@ -558,7 +587,11 @@ export function createSpaceItem(model, deps) {
558
587
  for (const held of moonSlots.values())
559
588
  if (held.slot.drawing?.object.visible)
560
589
  paintedMoons += 1;
561
- model.painted = { bodies: paintedBodies, moons: paintedMoons };
590
+ let tiled = 0;
591
+ for (const drawing of [sunSlot.drawing, moonSlot.drawing, ...[...planets.values()].map((p) => p.slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)])
592
+ if (drawing?.tiles?.shown != null)
593
+ tiled += 1;
594
+ model.painted = { bodies: paintedBodies, moons: paintedMoons, held: 0, moon: paintedMoon !== undefined, tiles: tiled };
562
595
  // 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
563
596
  const satellitePainter = deps.satellitePainter?.();
564
597
  const group = followed ? model.satellites.groups.get(followed.ref.group) : undefined;
@@ -611,10 +644,12 @@ export function createSpaceItem(model, deps) {
611
644
  model.followModel = null;
612
645
  }
613
646
  const sunToSun = unit([-frame.sun[0], -frame.sun[1], -frame.sun[2]]);
614
- sunDrawing?.update?.({ toSun: sunToSun, ms: model.time, radiusPx: px.Sun });
647
+ const bodyView = { camera, width: size.width, height: size.height };
648
+ sunDrawing?.update?.({ toSun: sunToSun, ms: model.time, radiusPx: px.Sun, view: bodyView });
649
+ paintedMoon?.update?.({ toSun: moonToSun, ms: model.time, radiusPx: px.Moon, view: bodyView });
615
650
  for (const name of PLANETS) {
616
651
  const p = planets.get(name);
617
- p.slot.drawing?.update?.({ toSun: p.toSun, ms: model.time, radiusPx: px[name] });
652
+ p.slot.drawing?.update?.({ toSun: p.toSun, ms: model.time, radiusPx: px[name], view: bodyView });
618
653
  }
619
654
  if (painter.moons && lookNow() !== "plain") {
620
655
  const now = performance.now();
@@ -646,7 +681,7 @@ export function createSpaceItem(model, deps) {
646
681
  drawing.object.scale.setScalar(drawn);
647
682
  const moonPx = away <= drawn * 1.001 ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
648
683
  drawing.light?.(p.toSun);
649
- drawing.update?.({ toSun: p.toSun, ms: model.time, radiusPx: moonPx });
684
+ drawing.update?.({ toSun: p.toSun, ms: model.time, radiusPx: moonPx, view: bodyView });
650
685
  }
651
686
  }
652
687
  let soonest = Number.POSITIVE_INFINITY;
@@ -667,9 +702,10 @@ export function createSpaceItem(model, deps) {
667
702
  clearTimeout(releaseTimer);
668
703
  releaseTimer = soonest < Number.POSITIVE_INFINITY ? setTimeout(() => deps.invalidate(), soonest + 50) : undefined;
669
704
  }
705
+ model.painted.held = moonSlots.size;
670
706
  const ratio = model.ratio();
671
707
  const earthPx = Math.min(px.Earth, 1e5) * ratio;
672
- textures.sync({ day: earthPx, night: earthPx, clouds: earthPx, water: earthPx, moon: Math.min(px.Moon, 1e5) * ratio });
708
+ textures.sync({ day: earthPx, night: earthPx, clouds: earthPx, water: earthPx, moon: paintedMoon ? 0 : Math.min(px.Moon, 1e5) * ratio });
673
709
  if (deps.onLabels && model.labels) {
674
710
  const places = {};
675
711
  for (const name of BODY_NAMES) {
@@ -711,6 +747,7 @@ export function createSpaceItem(model, deps) {
711
747
  deps.onPlaces({
712
748
  width: size.width,
713
749
  height: size.height,
750
+ radius: hidden === "Earth" || rideFrom ? 0 : Math.min(px.Earth, 1e5),
714
751
  at(lon, lat, out) {
715
752
  const la = lat * RAD;
716
753
  const lo = lon * RAD;
@@ -737,6 +774,14 @@ export function createSpaceItem(model, deps) {
737
774
  },
738
775
  });
739
776
  }
777
+ const spriteData = deps.placeSprites?.() ?? null;
778
+ if (spriteData && !placeSprites && !placeSpritesTried) {
779
+ placeSprites = createPlaceSprites(three, earth, sunEarth);
780
+ placeSpritesTried = true;
781
+ // told once: without `Points` the page's layer draws these rings itself
782
+ deps.onPlaceRings?.(placeSprites !== null);
783
+ }
784
+ placeSprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
740
785
  // 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
741
786
  if (model.bodyLabel.settings && !nameOn)
742
787
  nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
@@ -786,10 +831,13 @@ export function createSpaceItem(model, deps) {
786
831
  const ground = new three.Vector3();
787
832
  const eye = camera.position;
788
833
  const turned = earth.quaternion;
834
+ ground.set(0, 0, 0).project(camera);
835
+ const disc = { x: ((ground.x + 1) / 2) * size.width, y: ((1 - ground.y) / 2) * size.height, radius: Math.min(px.Earth, 1e5) };
789
836
  deps.onCities({
790
837
  width: size.width,
791
838
  height: size.height,
792
839
  radius: Math.min(px.Earth, 1e5),
840
+ ...(ground.z > -1 && ground.z < 1 ? { disc } : {}),
793
841
  project(lon, lat, out) {
794
842
  const phi = lat * RAD;
795
843
  const lambda = lon * RAD;
@@ -826,6 +874,34 @@ export function createSpaceItem(model, deps) {
826
874
  clearTimeout(meteorTimer);
827
875
  meteorTimer = Number.isFinite(wait) ? setTimeout(() => deps.invalidate(), wait) : undefined;
828
876
  }
877
+ // the borders, on the Earth: made the first time a set is switched on, above the clouds and under the air; the view's middle is the point under the camera, as far round as its horizon
878
+ if ((model.borders.countries || model.borders.regions) && !borders && !model.borders.stats.failed) {
879
+ try {
880
+ borders = createBorderLayer(three, earth, model.borders, () => deps.invalidate(), 3.5);
881
+ }
882
+ catch (error) {
883
+ model.borders.stats.failed = true;
884
+ model.borders.onError?.(error);
885
+ }
886
+ }
887
+ if (borders) {
888
+ const turn = earth.rotation.y;
889
+ const fx = camera.position.x * Math.cos(turn) - camera.position.z * Math.sin(turn);
890
+ const fz = camera.position.x * Math.sin(turn) + camera.position.z * Math.cos(turn);
891
+ const far = Math.hypot(fx, camera.position.y, fz) || 1;
892
+ borders.sync({ points: [{ lon: Math.atan2(fx, fz) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, camera.position.y / far))) / RAD }], angle: Math.acos(Math.min(1, 1 / far)) / RAD, radius: Math.min(px.Earth, 1e5) });
893
+ }
894
+ // the grid, on the Earth: made the first time it is switched on, over the ground and under the clouds
895
+ if (model.grid.on && !gridLayer && !model.grid.stats.failed) {
896
+ try {
897
+ gridLayer = createGridLayer(three, earth, model.grid, sunEarth, 2.5);
898
+ }
899
+ catch (error) {
900
+ model.grid.stats.failed = true;
901
+ model.grid.onError?.(error);
902
+ }
903
+ }
904
+ gridLayer?.sync(Math.min(px.Earth, 1e5));
829
905
  if (model.rideLost)
830
906
  deps.onRideLost?.();
831
907
  if (model.transition)
@@ -842,6 +918,9 @@ export function createSpaceItem(model, deps) {
842
918
  clearTimeout(meteorTimer);
843
919
  meteors?.dispose();
844
920
  nameOn?.dispose();
921
+ borders?.dispose();
922
+ placeSprites?.dispose();
923
+ gridLayer?.dispose();
845
924
  modelSlot.turn += 1;
846
925
  dropModel();
847
926
  layer?.dispose();
@@ -850,6 +929,7 @@ export function createSpaceItem(model, deps) {
850
929
  textures.dispose();
851
930
  ended = true;
852
931
  empty(sunSlot);
932
+ empty(moonSlot);
853
933
  for (const held of moonSlots.values())
854
934
  empty(held.slot);
855
935
  moonSlots.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.35.0",
3
+ "version": "0.36.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",
@@ -195,7 +195,7 @@
195
195
  },
196
196
  "dependencies": {
197
197
  "@johnmorrisdotca/chizu": "^1.6.0",
198
- "@johnmorrisdotca/kazoku-ui": "^0.38.1",
198
+ "@johnmorrisdotca/kazoku-ui": "^0.41.0",
199
199
  "d3-geo": "^3.1.1"
200
200
  },
201
201
  "peerDependencies": {
@@ -235,7 +235,7 @@
235
235
  "@johnmorrisdotca/hata": "^1.8.0",
236
236
  "@johnmorrisdotca/hoshi-stars": "^0.30.0",
237
237
  "@johnmorrisdotca/kuni": "^1.6.1",
238
- "@johnmorrisdotca/wakusei-planets": "^0.5.0",
238
+ "@johnmorrisdotca/wakusei-planets": "^0.37.1",
239
239
  "@playwright/test": "1.64.0",
240
240
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
241
241
  "@types/d3-geo": "^3.1.0",