@johnmorrisdotca/chikyu-earth 0.38.0 → 0.40.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 (39) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -1
  3. package/dist/cities/geometry.d.ts +7 -0
  4. package/dist/cities/geometry.js +1 -1
  5. package/dist/cities/host.d.ts +10 -2
  6. package/dist/cities/host.js +4 -2
  7. package/dist/markers/layer.d.ts +16 -1
  8. package/dist/markers/layer.js +3 -2
  9. package/dist/markers/place-layer.js +3 -0
  10. package/dist/paint/buffer.d.ts +6 -1
  11. package/dist/paint/buffer.js +151 -68
  12. package/dist/paint/texture.d.ts +16 -6
  13. package/dist/paint/texture.js +46 -27
  14. package/dist/realistic/earth.d.ts +1 -1
  15. package/dist/realistic/earth.js +5 -4
  16. package/dist/realistic/element-base.d.ts +437 -0
  17. package/dist/realistic/element-base.js +1249 -0
  18. package/dist/realistic/element.d.ts +2 -431
  19. package/dist/realistic/element.js +3 -1203
  20. package/dist/realistic/index.d.ts +1 -1
  21. package/dist/realistic/no-cultures.d.ts +1 -0
  22. package/dist/realistic/no-cultures.js +2 -0
  23. package/dist/realistic/tiles.d.ts +24 -0
  24. package/dist/realistic/tiles.js +30 -12
  25. package/dist/sky/culture-source.d.ts +15 -0
  26. package/dist/sky/culture-source.js +15 -0
  27. package/dist/sky/cultures.d.ts +1 -0
  28. package/dist/sky/cultures.js +8 -0
  29. package/dist/sky/host.d.ts +12 -0
  30. package/dist/sky/host.js +174 -22
  31. package/dist/space/element-base.d.ts +624 -0
  32. package/dist/space/element-base.js +1656 -0
  33. package/dist/space/element.d.ts +2 -612
  34. package/dist/space/element.js +3 -1597
  35. package/dist/space/no-cultures.d.ts +1 -0
  36. package/dist/space/no-cultures.js +2 -0
  37. package/dist/space/scene.d.ts +8 -1
  38. package/dist/space/scene.js +73 -34
  39. package/package.json +23 -3
@@ -0,0 +1 @@
1
+ export * from "./element-base.ts";
@@ -0,0 +1,2 @@
1
+ // `<chikyu-space>` with no sky culture but the IAU's: nothing under `hoshi-stars/cultures` is in the build, and `constellation-culture` is `iau` whatever a page sets (with one warning). Everything else is as `space/element`.
2
+ export * from "./element-base.js";
@@ -1,6 +1,7 @@
1
1
  import type * as THREE from "three";
2
2
  import type { AssetCache, Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
3
3
  import { type ThreeParts } from "../realistic/textures.ts";
4
+ import { type TileSet, type TileSources } from "../realistic/tile-set.ts";
4
5
  import type { Layer } from "../realistic/tiers.ts";
5
6
  import type { LightMode } from "../realistic/earth.ts";
6
7
  import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
@@ -212,6 +213,8 @@ export interface SpaceModel {
212
213
  shown: boolean;
213
214
  parts: number;
214
215
  } | null;
216
+ /** The map tiles laid over the Earth while the scene is built: what they are doing, for a page or a test. */
217
+ tiles: TileSet | null;
215
218
  /** Where a satellite of a shown group is on the screen as of the last draw (`placeSatellite`), or `null`. */
216
219
  placeSatellite: ((ref: SatelliteRef) => SatelliteScreen | null) | null;
217
220
  ratio(): number;
@@ -397,7 +400,7 @@ export interface SpaceDeps {
397
400
  onSatellitesError?: (error: unknown) => void;
398
401
  /** The painted satellite trail. Read at every draw; nothing is uploaded while `step` returns false. */
399
402
  paint?: {
400
- data: Uint8Array;
403
+ data(): Uint8Array;
401
404
  width: number;
402
405
  height: number;
403
406
  step(ms: number): boolean;
@@ -410,6 +413,10 @@ export interface SpaceDeps {
410
413
  satellitePainter?: () => SatellitePainter | undefined;
411
414
  /** The painter could not make a body (the three.js parts handed over lack something it needs); the body is drawn plain instead. */
412
415
  onPainterError?: (error: unknown) => void;
416
+ /** The map source of each layer now (the folder of the `tiles` attribute), or none: the Earth then keeps the package's own pictures. Read at every draw. */
417
+ sources?: () => TileSources;
418
+ /** Told once when the tile set has been read: the width in pixels of the finest level of each of its layers. */
419
+ onTiles?: (layers: Record<string, number>) => void;
413
420
  }
414
421
  /**
415
422
  * The default look: a sphere in the planet's colour, lit by the Sun, and for the Sun a glowing disc.
@@ -2,6 +2,7 @@ import { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_VERT, airFrag, airTop } from ".
2
2
  import { sphere } from "../realistic/earth.js";
3
3
  import { BODY_FRAG, CLOUD_FRAG, GLOW_FRAG, GLOW_VERT, SURFACE_FRAG, SURFACE_VERT } from "../realistic/shaders.js";
4
4
  import { createTextureSet } from "../realistic/textures.js";
5
+ import { createTileSet } from "../realistic/tile-set.js";
5
6
  import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
6
7
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
7
8
  import { faceOffset, ridePose } from "./ride.js";
@@ -100,6 +101,7 @@ export const newSpaceModel = () => ({
100
101
  pick: null,
101
102
  placeSatellite: null,
102
103
  followModel: null,
104
+ tiles: null,
103
105
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
104
106
  });
105
107
  /** An inertial direction from the Earth's centre, in scene axes, for right ascension and declination in degrees. */
@@ -188,7 +190,7 @@ export function createSpaceItem(model, deps) {
188
190
  fragmentShader: SURFACE_FRAG,
189
191
  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 } },
190
192
  });
191
- const paint = createPaintTexture(three, deps.paint?.data ?? new Uint8Array(4), deps.paint?.width ?? 1, deps.paint?.height ?? 1);
193
+ const paint = createPaintTexture(three, { data: () => deps.paint?.data() ?? new Uint8Array(4), width: deps.paint?.width ?? 1, height: deps.paint?.height ?? 1 });
192
194
  Object.assign(earthMaterial.uniforms, paint.uniforms);
193
195
  const cloudMaterial = new three.ShaderMaterial({
194
196
  vertexShader: SURFACE_VERT,
@@ -207,6 +209,9 @@ export function createSpaceItem(model, deps) {
207
209
  depthWrite: false,
208
210
  });
209
211
  const earth = new three.Mesh(grid, earthMaterial);
212
+ // the finer map tiles, laid over the Earth's own picture where the camera is near enough to need them (they turn with the Earth: they are its children)
213
+ const tiles = createTileSet(three, earth, { sunDir: sunEarth, lights: earthMaterial.uniforms["lights"], boost: earthMaterial.uniforms["boost"], ortho: earthMaterial.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
214
+ model.tiles = tiles;
210
215
  const clouds = new three.Mesh(grid, cloudMaterial);
211
216
  clouds.scale.setScalar(1.006);
212
217
  clouds.renderOrder = 3;
@@ -307,6 +312,9 @@ export function createSpaceItem(model, deps) {
307
312
  const desiredQ = camera.quaternion.clone();
308
313
  const fromQ = camera.quaternion.clone();
309
314
  const projected = new three.Vector3();
315
+ const upAxis = new three.Vector3(0, 1, 0);
316
+ const eye = new three.Vector3();
317
+ const ray = new three.Vector3();
310
318
  const placeAll = (at) => {
311
319
  const sunAt = placeSun(model.mode, at.sun);
312
320
  const all = { Earth: [0, 0, 0], Moon: placeMoon(model.mode, at.moon), Sun: sunAt };
@@ -352,8 +360,8 @@ export function createSpaceItem(model, deps) {
352
360
  earthMaterial.uniforms["lights"].value = model.light === "lit" ? 0 : 1;
353
361
  earthMaterial.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
354
362
  if (deps.paint) {
355
- if (deps.paint.step(model.time))
356
- paint.upload();
363
+ const changed = deps.paint.step(model.time);
364
+ paint.sync(deps.paint.on(), changed);
357
365
  paint.uniforms.paintNow.value = paintMinute(model.time);
358
366
  paint.uniforms.paintSpan.value = deps.paint.span();
359
367
  paint.uniforms.paintOn.value = deps.paint.on() ? 1 : 0;
@@ -591,6 +599,34 @@ export function createSpaceItem(model, deps) {
591
599
  px[name] = radiusPxOf(name);
592
600
  model.drawn = { frame, distance, radiusPx: px.Earth };
593
601
  layer?.resize(px.Earth);
602
+ // the finer map tiles: the camera as the Earth's own axes have it, so a camera a few kilometres up asks for the tiles under it at the level its height needs
603
+ {
604
+ // the Earth is turned about the y axis and sits at the origin, so its own axes are the world's turned back by that angle
605
+ const turn = earth.rotation.y;
606
+ eye.copy(camera.position).applyAxisAngle(upAxis, -turn);
607
+ const away = Math.max(1e-4, eye.length() - 1);
608
+ const focal = size.height / 2 / half;
609
+ const look = {
610
+ eye: [eye.x, eye.y, eye.z],
611
+ project: (point) => {
612
+ projected.set(point[0], point[1], point[2]).applyAxisAngle(upAxis, turn).project(camera);
613
+ if (projected.z > 1 || projected.z < -1)
614
+ return null;
615
+ return { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height };
616
+ },
617
+ ground: (x, y) => {
618
+ ray.set((x / size.width) * 2 - 1, 1 - (y / size.height) * 2, 0.5).unproject(camera).sub(camera.position).normalize().applyAxisAngle(upAxis, -turn);
619
+ // the nearer point where the line from the camera meets the unit sphere, if it does
620
+ const b = eye.dot(ray);
621
+ const rest = b * b - (eye.lengthSq() - 1);
622
+ if (rest < 0)
623
+ return null;
624
+ const t = -b - Math.sqrt(rest);
625
+ return t < 0 ? null : [eye.x + t * ray.x, eye.y + t * ray.y, eye.z + t * ray.z];
626
+ },
627
+ };
628
+ tiles.sync({ lon: 0, lat: 0, width: size.width, height: size.height, panX: 0, panY: 0, radius: focal / away, perspective: look }, [sunLocal.value.x, sunLocal.value.y, sunLocal.value.z], true, model.ratio());
629
+ }
594
630
  let paintedBodies = sunSlot.drawing ? 1 : 0;
595
631
  for (const p of planets.values())
596
632
  if (p.slot.drawing)
@@ -796,6 +832,38 @@ export function createSpaceItem(model, deps) {
796
832
  if (model.bodyLabel.settings && !nameOn)
797
833
  nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
798
834
  nameOn?.sync(camera, rideFrom ? 0 : Math.min(px.Earth, 1e5));
835
+ if (deps.onCities) {
836
+ if (hidden === "Earth")
837
+ deps.onCities(null);
838
+ else {
839
+ // 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
840
+ const ground = new three.Vector3();
841
+ const eye = camera.position;
842
+ const turned = earth.quaternion;
843
+ ground.set(0, 0, 0).project(camera);
844
+ const disc = { x: ((ground.x + 1) / 2) * size.width, y: ((1 - ground.y) / 2) * size.height, radius: Math.min(px.Earth, 1e5) };
845
+ deps.onCities({
846
+ width: size.width,
847
+ height: size.height,
848
+ radius: Math.min(px.Earth, 1e5),
849
+ ...(ground.z > -1 && ground.z < 1 ? { disc } : {}),
850
+ project(lon, lat, out) {
851
+ const phi = lat * RAD;
852
+ const lambda = lon * RAD;
853
+ ground.set(Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)).applyQuaternion(turned);
854
+ const dx = eye.x - ground.x;
855
+ const dy = eye.y - ground.y;
856
+ const dz = eye.z - ground.z;
857
+ const facing = (ground.x * dx + ground.y * dy + ground.z * dz) / (Math.hypot(dx, dy, dz) || 1);
858
+ ground.project(camera);
859
+ out.x = ((ground.x + 1) / 2) * size.width;
860
+ out.y = ((1 - ground.y) / 2) * size.height;
861
+ return ground.z > 1 || ground.z < -1 ? -1 : facing;
862
+ },
863
+ });
864
+ }
865
+ }
866
+ // the sky after the places and the city names, so its names keep clear of what they take as it is laid out
799
867
  if (deps.onSky) {
800
868
  const sky = new three.Vector3();
801
869
  // stars are directions: a point far along the direction from the camera, in the scene's axes (x to the vernal equinox, y north, z completing the hand), seen through the camera
@@ -833,37 +901,6 @@ export function createSpaceItem(model, deps) {
833
901
  },
834
902
  });
835
903
  }
836
- if (deps.onCities) {
837
- if (hidden === "Earth")
838
- deps.onCities(null);
839
- else {
840
- // 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
841
- const ground = new three.Vector3();
842
- const eye = camera.position;
843
- const turned = earth.quaternion;
844
- ground.set(0, 0, 0).project(camera);
845
- const disc = { x: ((ground.x + 1) / 2) * size.width, y: ((1 - ground.y) / 2) * size.height, radius: Math.min(px.Earth, 1e5) };
846
- deps.onCities({
847
- width: size.width,
848
- height: size.height,
849
- radius: Math.min(px.Earth, 1e5),
850
- ...(ground.z > -1 && ground.z < 1 ? { disc } : {}),
851
- project(lon, lat, out) {
852
- const phi = lat * RAD;
853
- const lambda = lon * RAD;
854
- ground.set(Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)).applyQuaternion(turned);
855
- const dx = eye.x - ground.x;
856
- const dy = eye.y - ground.y;
857
- const dz = eye.z - ground.z;
858
- const facing = (ground.x * dx + ground.y * dy + ground.z * dz) / (Math.hypot(dx, dy, dz) || 1);
859
- ground.project(camera);
860
- out.x = ((ground.x + 1) / 2) * size.width;
861
- out.y = ((1 - ground.y) / 2) * size.height;
862
- return ground.z > 1 || ground.z < -1 ? -1 : facing;
863
- },
864
- });
865
- }
866
- }
867
904
  if (layer && deps.onSelected) {
868
905
  const at = model.satellites.selected ? layer.place(camera, size) : null;
869
906
  if (at || selectedShown)
@@ -936,6 +973,8 @@ export function createSpaceItem(model, deps) {
936
973
  layer?.dispose();
937
974
  model.pick = null;
938
975
  model.placeSatellite = null;
976
+ model.tiles = null;
977
+ tiles.dispose();
939
978
  textures.dispose();
940
979
  ended = true;
941
980
  empty(sunSlot);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.38.0",
3
+ "version": "0.40.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",
@@ -77,8 +77,18 @@
77
77
  "./src/passes/element.ts",
78
78
  "./dist/realistic/element.js",
79
79
  "./src/realistic/element.ts",
80
+ "./dist/realistic/element-base.js",
81
+ "./src/realistic/element-base.ts",
82
+ "./dist/realistic/no-cultures.js",
83
+ "./src/realistic/no-cultures.ts",
80
84
  "./dist/space/element.js",
81
- "./src/space/element.ts"
85
+ "./src/space/element.ts",
86
+ "./dist/space/element-base.js",
87
+ "./src/space/element-base.ts",
88
+ "./dist/space/no-cultures.js",
89
+ "./src/space/no-cultures.ts",
90
+ "./dist/sky/cultures.js",
91
+ "./src/sky/cultures.ts"
82
92
  ],
83
93
  "main": "./dist/index.js",
84
94
  "module": "./dist/index.js",
@@ -104,6 +114,11 @@
104
114
  "import": "./dist/realistic/element.js",
105
115
  "default": "./dist/realistic/element.js"
106
116
  },
117
+ "./realistic/no-cultures": {
118
+ "types": "./dist/realistic/no-cultures.d.ts",
119
+ "import": "./dist/realistic/no-cultures.js",
120
+ "default": "./dist/realistic/no-cultures.js"
121
+ },
107
122
  "./markers": {
108
123
  "types": "./dist/markers/index.d.ts",
109
124
  "import": "./dist/markers/index.js",
@@ -119,6 +134,11 @@
119
134
  "import": "./dist/space/element.js",
120
135
  "default": "./dist/space/element.js"
121
136
  },
137
+ "./space/no-cultures": {
138
+ "types": "./dist/space/no-cultures.d.ts",
139
+ "import": "./dist/space/no-cultures.js",
140
+ "default": "./dist/space/no-cultures.js"
141
+ },
122
142
  "./door": {
123
143
  "types": "./dist/door/index.d.ts",
124
144
  "import": "./dist/door/index.js",
@@ -235,7 +255,7 @@
235
255
  "@johnmorrisdotca/hata": "^1.8.0",
236
256
  "@johnmorrisdotca/hoshi-stars": "^0.30.0",
237
257
  "@johnmorrisdotca/kuni": "^1.6.1",
238
- "@johnmorrisdotca/wakusei-planets": "^0.37.1",
258
+ "@johnmorrisdotca/wakusei-planets": "^0.38.0",
239
259
  "@playwright/test": "1.64.0",
240
260
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
241
261
  "@types/d3-geo": "^3.1.0",