@johnmorrisdotca/chikyu-earth 0.38.0 → 0.39.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 +8 -0
- package/README.md +2 -1
- package/dist/paint/buffer.d.ts +6 -1
- package/dist/paint/buffer.js +151 -68
- package/dist/paint/texture.d.ts +16 -6
- package/dist/paint/texture.js +46 -27
- package/dist/realistic/earth.d.ts +1 -1
- package/dist/realistic/earth.js +3 -3
- package/dist/realistic/element-base.d.ts +437 -0
- package/dist/realistic/element-base.js +1209 -0
- package/dist/realistic/element.d.ts +2 -431
- package/dist/realistic/element.js +3 -1203
- package/dist/realistic/index.d.ts +1 -1
- package/dist/realistic/no-cultures.d.ts +1 -0
- package/dist/realistic/no-cultures.js +2 -0
- package/dist/realistic/tiles.d.ts +24 -0
- package/dist/realistic/tiles.js +30 -12
- package/dist/sky/culture-source.d.ts +15 -0
- package/dist/sky/culture-source.js +15 -0
- package/dist/sky/cultures.d.ts +1 -0
- package/dist/sky/cultures.js +8 -0
- package/dist/sky/host.js +144 -18
- package/dist/space/element-base.d.ts +624 -0
- package/dist/space/element-base.js +1627 -0
- package/dist/space/element.d.ts +2 -612
- package/dist/space/element.js +3 -1597
- package/dist/space/no-cultures.d.ts +1 -0
- package/dist/space/no-cultures.js +2 -0
- package/dist/space/scene.d.ts +8 -1
- package/dist/space/scene.js +41 -3
- package/package.json +23 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./element-base.ts";
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -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.
|
package/dist/space/scene.js
CHANGED
|
@@ -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
|
-
|
|
356
|
-
|
|
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)
|
|
@@ -936,6 +972,8 @@ export function createSpaceItem(model, deps) {
|
|
|
936
972
|
layer?.dispose();
|
|
937
973
|
model.pick = null;
|
|
938
974
|
model.placeSatellite = null;
|
|
975
|
+
model.tiles = null;
|
|
976
|
+
tiles.dispose();
|
|
939
977
|
textures.dispose();
|
|
940
978
|
ended = true;
|
|
941
979
|
empty(sunSlot);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.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.
|
|
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",
|