@johnmorrisdotca/chikyu-earth 0.15.0 → 0.17.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.
@@ -0,0 +1,403 @@
1
+ import { TILE_FRAG, TILE_VERT } from "./shaders.js";
2
+ import { MAX_TEXTURE, TIERS } from "./tiers.js";
3
+ import { coveringTile, parseManifest, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
4
+ /**
5
+ * The most tiles held at once, day and night together, about a megabyte and a third of graphics memory each (a 512 pixel square with its mipmaps).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { TILE_LIMIT } from "@johnmorrisdotca/chikyu-earth/realistic";
10
+ *
11
+ * console.log(TILE_LIMIT);
12
+ * ```
13
+ */
14
+ export const TILE_LIMIT = 48;
15
+ /**
16
+ * Milliseconds a tile that is no longer wanted is kept (the view may come straight back) before it is freed.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { TILE_KEEP_MS } from "@johnmorrisdotca/chikyu-earth/realistic";
21
+ *
22
+ * console.log(TILE_KEEP_MS);
23
+ * ```
24
+ */
25
+ export const TILE_KEEP_MS = 4000;
26
+ const IN_FLIGHT = 6;
27
+ const NEW_PER_DRAW = 8;
28
+ const RETRY_MS = 30_000;
29
+ // the day mix reaches full light at 0.22: a tile whose darkest point is brighter than that never shows the night picture
30
+ const NIGHT_BELOW = 0.25;
31
+ const GRID = 16;
32
+ const keyOf = (layer, id) => `${layer}/${id.level}/${id.col}/${id.row}`;
33
+ /** A 0 to 1 grid, the same for every tile: the vertex shader puts it on the sphere. */
34
+ function patch(three) {
35
+ const positions = new Float32Array((GRID + 1) * (GRID + 1) * 3);
36
+ const uvs = new Float32Array((GRID + 1) * (GRID + 1) * 2);
37
+ let p = 0;
38
+ let q = 0;
39
+ for (let j = 0; j <= GRID; j += 1) {
40
+ for (let i = 0; i <= GRID; i += 1) {
41
+ uvs[q++] = i / GRID;
42
+ uvs[q++] = j / GRID;
43
+ positions[p++] = i / GRID;
44
+ positions[p++] = j / GRID;
45
+ positions[p++] = 0;
46
+ }
47
+ }
48
+ const index = [];
49
+ for (let j = 0; j < GRID; j += 1) {
50
+ for (let i = 0; i < GRID; i += 1) {
51
+ const a = j * (GRID + 1) + i;
52
+ const b = a + GRID + 1;
53
+ index.push(a, b, a + 1, b, b + 1, a + 1);
54
+ }
55
+ }
56
+ const geometry = new three.BufferGeometry();
57
+ geometry.setAttribute("position", new three.BufferAttribute(positions, 3));
58
+ geometry.setAttribute("uv", new three.BufferAttribute(uvs, 2));
59
+ geometry.setIndex(index);
60
+ return geometry;
61
+ }
62
+ /** Make the set that puts tiles on `parent`, a group that turns with the Earth. */
63
+ export function createTileSet(three, parent, shared, deps) {
64
+ const limit = deps.limit ?? TILE_LIMIT;
65
+ const clock = deps.now ?? (() => performance.now());
66
+ const geometry = patch(three);
67
+ const entries = new Map();
68
+ const failed = new Map();
69
+ let queue = [];
70
+ let wantedKeys = new Set();
71
+ let current;
72
+ let manifest;
73
+ let manifestFetch;
74
+ let inFlight = 0;
75
+ let requested = 0;
76
+ let wantedLevel = null;
77
+ let shown = 0;
78
+ let timer;
79
+ let last;
80
+ let disposed = false;
81
+ const baseDay = TIERS.day[TIERS.day.length - 1];
82
+ const baseNight = TIERS.night[TIERS.night.length - 1];
83
+ const take = (layer, id, base) => deps.assets.acquire(`chikyu-earth:tile:${base}${keyOf(layer, id)}`, () => {
84
+ const texture = new three.Texture();
85
+ texture.wrapS = three.ClampToEdgeWrapping;
86
+ texture.wrapT = three.ClampToEdgeWrapping;
87
+ texture.minFilter = three.LinearMipmapLinearFilter;
88
+ texture.magFilter = three.LinearFilter;
89
+ texture.anisotropy = 8;
90
+ const controller = new AbortController();
91
+ const made = { texture, closed: false, ready: Promise.resolve(), release: () => undefined };
92
+ made.ready = fetch(`${base}${keyOf(layer, id)}.webp`, { signal: controller.signal })
93
+ .then((response) => {
94
+ if (!response.ok)
95
+ throw new Error(`${keyOf(layer, id)}: ${response.status}`);
96
+ return response.blob();
97
+ })
98
+ .then((blob) => createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }))
99
+ .then((bitmap) => {
100
+ if (made.closed)
101
+ bitmap.close();
102
+ else {
103
+ texture.image = bitmap;
104
+ texture.needsUpdate = true;
105
+ }
106
+ });
107
+ made.ready.catch(() => undefined);
108
+ made.release = () => {
109
+ made.closed = true;
110
+ controller.abort();
111
+ texture.dispose();
112
+ texture.image?.close?.();
113
+ };
114
+ return made;
115
+ }, (value) => value.release());
116
+ const drop = (entry) => {
117
+ entries.delete(entry.key);
118
+ if (entry.mesh) {
119
+ parent.remove(entry.mesh);
120
+ entry.mesh.material.dispose();
121
+ }
122
+ if (current !== undefined)
123
+ deps.assets.release(`chikyu-earth:tile:${current}${entry.key}`);
124
+ };
125
+ const reset = () => {
126
+ for (const entry of [...entries.values()])
127
+ drop(entry);
128
+ queue = [];
129
+ wantedKeys = new Set();
130
+ failed.clear();
131
+ manifestFetch?.abort();
132
+ manifestFetch = undefined;
133
+ manifest = undefined;
134
+ wantedLevel = null;
135
+ shown = 0;
136
+ };
137
+ const readManifest = (base) => {
138
+ manifest = undefined;
139
+ const controller = new AbortController();
140
+ manifestFetch = controller;
141
+ fetch(`${base}manifest.json`, { signal: controller.signal })
142
+ .then((response) => (response.ok ? response.json() : undefined))
143
+ .then((json) => {
144
+ if (disposed || current !== base || manifestFetch !== controller)
145
+ return;
146
+ const read = parseManifest(json);
147
+ manifest = read ?? null;
148
+ if (read) {
149
+ deps.onManifest?.(Object.fromEntries(Object.entries(read.layers).map(([name, layer]) => [name, layer.levels[layer.levels.length - 1].width])));
150
+ deps.invalidate();
151
+ }
152
+ }, () => {
153
+ if (!disposed && current === base && manifestFetch === controller)
154
+ manifest = null;
155
+ });
156
+ };
157
+ const pump = () => {
158
+ const base = current;
159
+ if (base === undefined)
160
+ return;
161
+ while (inFlight < IN_FLIGHT && queue.length > 0) {
162
+ const next = queue.shift();
163
+ const key = keyOf(next.layer, next.id);
164
+ if (entries.has(key))
165
+ continue;
166
+ const entry = { key, layer: next.layer, id: next.id, asset: take(next.layer, next.id, base), ready: false, integrated: false, lastWanted: clock() };
167
+ entries.set(key, entry);
168
+ inFlight += 1;
169
+ requested += 1;
170
+ const settled = () => {
171
+ inFlight -= 1;
172
+ pump();
173
+ };
174
+ entry.asset.ready.then(() => {
175
+ if (entries.get(key) === entry) {
176
+ entry.ready = true;
177
+ deps.invalidate();
178
+ }
179
+ settled();
180
+ }, () => {
181
+ if (entries.get(key) === entry) {
182
+ failed.set(key, clock());
183
+ drop(entry);
184
+ }
185
+ settled();
186
+ });
187
+ }
188
+ };
189
+ const nightLevels = () => {
190
+ const layer = manifest?.layers["night"];
191
+ const finer = layer?.levels.filter((entry) => entry.width > baseNight);
192
+ return layer && finer && finer.length > 0 ? { tileSize: layer.tileSize, levels: finer } : undefined;
193
+ };
194
+ /** The night tile that goes with a day tile: the same level, or the finest the night picture has. */
195
+ const nightFor = (tile, night) => {
196
+ const level = night.levels.filter((entry) => entry.level <= tile.level).reduce((top, entry) => Math.max(top, entry.level), night.levels[0].level);
197
+ return coveringTile(tile, level);
198
+ };
199
+ const choose = (camera, sun, night, ratio) => {
200
+ const day = manifest?.layers["day"];
201
+ if (!day || deps.cap() < MAX_TEXTURE)
202
+ return { level: null, day: [], night: [] };
203
+ const nightLayer = night ? nightLevels() : undefined;
204
+ let level = tileLevel(camera.radius * ratio, day, baseDay);
205
+ while (level !== undefined) {
206
+ const tiles = tilesInView(level, camera, sun);
207
+ const seen = new Set();
208
+ const dark = [];
209
+ if (nightLayer) {
210
+ for (const tile of tiles) {
211
+ if (tile.ndl >= NIGHT_BELOW)
212
+ continue;
213
+ const id = nightFor(tile, nightLayer);
214
+ const key = keyOf("night", id);
215
+ if (!seen.has(key)) {
216
+ seen.add(key);
217
+ dark.push(id);
218
+ }
219
+ }
220
+ }
221
+ if (tiles.length + dark.length <= limit)
222
+ return { level, day: tiles, night: dark };
223
+ const lower = day.levels.filter((entry) => entry.width > baseDay && entry.level < level).pop();
224
+ level = lower?.level;
225
+ }
226
+ return { level: null, day: [], night: [] };
227
+ };
228
+ const makeMesh = (entry) => {
229
+ const nightRect = { value: [0, 0, 1, 1] };
230
+ const nightMap = { value: shared.night.value };
231
+ const material = new three.ShaderMaterial({
232
+ vertexShader: TILE_VERT,
233
+ fragmentShader: TILE_FRAG,
234
+ uniforms: {
235
+ dayMap: { value: entry.asset.texture },
236
+ nightMap,
237
+ waterMap: shared.water,
238
+ sunDir: shared.sunDir,
239
+ lights: shared.lights,
240
+ boost: shared.boost,
241
+ ortho: shared.ortho,
242
+ nightRect,
243
+ rect: { value: tileRect(entry.id) },
244
+ // a finer level sits a little higher, so two levels at once never fight for the same depth; all sit above the whole-Earth sphere's flat faces
245
+ radius: { value: 1.0004 + 0.0001 * (entry.id.level - 3) },
246
+ },
247
+ polygonOffset: true,
248
+ polygonOffsetFactor: -1,
249
+ polygonOffsetUnits: -1,
250
+ });
251
+ const mesh = new three.Mesh(geometry, material);
252
+ mesh.frustumCulled = false;
253
+ mesh.visible = false;
254
+ parent.add(mesh);
255
+ entry.mesh = mesh;
256
+ entry.nightRect = nightRect;
257
+ entry.nightMap = nightMap;
258
+ };
259
+ /** Each day tile reads the finest night tile it has, else the whole-Earth night picture. */
260
+ const retarget = () => {
261
+ const night = nightLevels();
262
+ for (const entry of entries.values()) {
263
+ if (!entry.mesh || !entry.nightMap || !entry.nightRect)
264
+ continue;
265
+ let texture = null;
266
+ let rect = [0, 0, 1, 1];
267
+ if (night) {
268
+ for (let level = entry.id.level; level >= night.levels[0].level && !texture; level -= 1) {
269
+ if (!night.levels.some((l) => l.level === level))
270
+ continue;
271
+ const id = coveringTile(entry.id, level);
272
+ const held = entries.get(keyOf("night", id));
273
+ if (held?.integrated && held.ready) {
274
+ texture = held.asset.texture;
275
+ rect = [id.col / tileColumns(id.level), id.row / tileRows(id.level), 1 / tileColumns(id.level), 1 / tileRows(id.level)];
276
+ }
277
+ }
278
+ }
279
+ entry.nightMap.value = texture ?? shared.night.value;
280
+ entry.nightRect.value = rect;
281
+ }
282
+ };
283
+ const place = (camera, visible) => {
284
+ shown = 0;
285
+ for (const entry of entries.values()) {
286
+ if (!entry.mesh)
287
+ continue;
288
+ let set = visible.get(entry.id.level);
289
+ if (!set) {
290
+ set = new Set(tilesInView(entry.id.level, camera).map((tile) => tile.row * tileColumns(tile.level) + tile.col));
291
+ visible.set(entry.id.level, set);
292
+ }
293
+ entry.mesh.visible = set.has(entry.id.row * tileColumns(entry.id.level) + entry.id.col);
294
+ if (entry.mesh.visible)
295
+ shown += 1;
296
+ }
297
+ };
298
+ /** Free what is no longer wanted: past its time, or the oldest first when over the limit. True when something on the sphere went. */
299
+ const sweep = () => {
300
+ const now = clock();
301
+ let changed = false;
302
+ const unwanted = [...entries.values()].filter((entry) => !wantedKeys.has(entry.key)).sort((a, b) => a.lastWanted - b.lastWanted);
303
+ for (const entry of unwanted) {
304
+ if (now - entry.lastWanted < TILE_KEEP_MS && entries.size <= limit)
305
+ continue;
306
+ if (entry.mesh?.visible || entry.integrated)
307
+ changed = true;
308
+ drop(entry);
309
+ }
310
+ if (changed)
311
+ retarget();
312
+ return changed;
313
+ };
314
+ const arm = () => {
315
+ if (timer !== undefined || disposed)
316
+ return;
317
+ const unwanted = [...entries.values()].filter((entry) => !wantedKeys.has(entry.key));
318
+ if (unwanted.length === 0)
319
+ return;
320
+ const oldest = Math.min(...unwanted.map((entry) => entry.lastWanted));
321
+ timer = setTimeout(() => {
322
+ timer = undefined;
323
+ if (sweep()) {
324
+ if (last)
325
+ place(last.camera, new Map());
326
+ deps.invalidate();
327
+ }
328
+ arm();
329
+ }, Math.max(50, oldest + TILE_KEEP_MS - clock() + 20));
330
+ };
331
+ return {
332
+ get stats() {
333
+ return {
334
+ ready: manifest != null,
335
+ level: wantedLevel,
336
+ held: entries.size,
337
+ shown,
338
+ loading: [...entries.values()].filter((entry) => !entry.ready).length,
339
+ failed: failed.size,
340
+ requested,
341
+ };
342
+ },
343
+ sync(camera, sun, night, ratio) {
344
+ if (disposed)
345
+ return;
346
+ const base = deps.base();
347
+ if (base !== current) {
348
+ reset();
349
+ current = base;
350
+ if (base !== undefined)
351
+ readManifest(base);
352
+ }
353
+ last = { camera };
354
+ if (current === undefined || !manifest)
355
+ return;
356
+ const now = clock();
357
+ const wanted = choose(camera, sun, night, ratio);
358
+ wantedLevel = wanted.level;
359
+ wantedKeys = new Set([...wanted.day.map((tile) => keyOf("day", tile)), ...wanted.night.map((id) => keyOf("night", id))]);
360
+ for (const [key, when] of failed)
361
+ if (now - when >= RETRY_MS)
362
+ failed.delete(key);
363
+ for (const key of wantedKeys) {
364
+ const entry = entries.get(key);
365
+ if (entry)
366
+ entry.lastWanted = now;
367
+ }
368
+ queue = [...wanted.day.map((tile) => ({ layer: "day", id: { level: tile.level, col: tile.col, row: tile.row } })), ...wanted.night.map((id) => ({ layer: "night", id }))].filter((item) => !failed.has(keyOf(item.layer, item.id)) && !entries.has(keyOf(item.layer, item.id)));
369
+ pump();
370
+ let fresh = 0;
371
+ let waiting = false;
372
+ for (const entry of entries.values()) {
373
+ if (entry.integrated || !entry.ready || !wantedKeys.has(entry.key))
374
+ continue;
375
+ if (fresh >= NEW_PER_DRAW) {
376
+ waiting = true;
377
+ continue;
378
+ }
379
+ fresh += 1;
380
+ entry.integrated = true;
381
+ if (entry.layer === "day")
382
+ makeMesh(entry);
383
+ }
384
+ sweep();
385
+ retarget();
386
+ const visible = new Map();
387
+ if (wanted.level !== null)
388
+ visible.set(wanted.level, new Set(wanted.day.map((tile) => tile.row * tileColumns(tile.level) + tile.col)));
389
+ place(camera, visible);
390
+ if (waiting)
391
+ deps.invalidate();
392
+ arm();
393
+ },
394
+ dispose() {
395
+ disposed = true;
396
+ clearTimeout(timer);
397
+ timer = undefined;
398
+ reset();
399
+ current = undefined;
400
+ geometry.dispose();
401
+ },
402
+ };
403
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * One tile of the map pyramid: a level, a column counted east from longitude -180 and a row counted south from latitude 90.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import type { TileId } from "@johnmorrisdotca/chikyu-earth/realistic";
7
+ *
8
+ * const tile: TileId = { level: 4, col: 17, row: 5 };
9
+ * console.log(tile);
10
+ * ```
11
+ */
12
+ export interface TileId {
13
+ level: number;
14
+ col: number;
15
+ row: number;
16
+ }
17
+ /**
18
+ * What a layer of a tile set holds, from its manifest: the pyramid's levels, each as wide as it is, and the tile size.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import type { TileLayer } from "@johnmorrisdotca/chikyu-earth/realistic";
23
+ *
24
+ * const day: TileLayer = { tileSize: 512, levels: [{ level: 3, width: 8192 }, { level: 4, width: 16384 }] };
25
+ * console.log(day.levels.length);
26
+ * ```
27
+ */
28
+ export interface TileLayer {
29
+ tileSize: number;
30
+ levels: {
31
+ level: number;
32
+ width: number;
33
+ }[];
34
+ }
35
+ /**
36
+ * Where the camera is, as the realistic Earth draws it: the place in the middle of the disc, the box in CSS pixels, the pan, and the disc's radius in CSS pixels.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import type { TileCamera } from "@johnmorrisdotca/chikyu-earth/realistic";
41
+ *
42
+ * const camera: TileCamera = { lon: 10, lat: 20, width: 800, height: 600, panX: 0, panY: 0, radius: 900 };
43
+ * console.log(camera.radius);
44
+ * ```
45
+ */
46
+ export interface TileCamera {
47
+ lon: number;
48
+ lat: number;
49
+ width: number;
50
+ height: number;
51
+ panX: number;
52
+ panY: number;
53
+ radius: number;
54
+ }
55
+ /**
56
+ * A tile that is in view: where, how far its middle is from the middle of the box (CSS pixels, for loading the middle first) and how dark its darkest sampled point is (`ndl`, the
57
+ * cosine of the angle to the Sun, only when a Sun was given).
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import type { VisibleTile } from "@johnmorrisdotca/chikyu-earth/realistic";
62
+ *
63
+ * const tile: VisibleTile = { level: 3, col: 0, row: 0, d: 120, ndl: -0.4 };
64
+ * console.log(tile.d);
65
+ * ```
66
+ */
67
+ export interface VisibleTile extends TileId {
68
+ d: number;
69
+ ndl: number;
70
+ }
71
+ /**
72
+ * How much larger than a device pixel a map texel may be before the next level is wanted: 1.25 is a quarter larger.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { TEXEL_SLACK } from "@johnmorrisdotca/chikyu-earth/realistic";
77
+ *
78
+ * console.log(TEXEL_SLACK);
79
+ * ```
80
+ */
81
+ export declare const TEXEL_SLACK = 1.25;
82
+ /**
83
+ * Columns in a level.
84
+ *
85
+ * @param level - A pyramid level.
86
+ * @returns `2^(level + 1)`.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { tileColumns } from "@johnmorrisdotca/chikyu-earth/realistic";
91
+ *
92
+ * console.log(tileColumns(4));
93
+ * ```
94
+ */
95
+ export declare const tileColumns: (level: number) => number;
96
+ /**
97
+ * Rows in a level.
98
+ *
99
+ * @param level - A pyramid level.
100
+ * @returns `2^level`.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { tileRows } from "@johnmorrisdotca/chikyu-earth/realistic";
105
+ *
106
+ * console.log(tileRows(4));
107
+ * ```
108
+ */
109
+ export declare const tileRows: (level: number) => number;
110
+ /**
111
+ * The first level to load for a disc: the smallest one whose texels are about a device pixel on the screen, else the finest there is, and none when the whole-Earth picture
112
+ * (`baseWidth` across) is already that sharp.
113
+ *
114
+ * @param radiusPx - The disc's radius in device pixels.
115
+ * @param layer - The levels the set has for this layer.
116
+ * @param baseWidth - The width of the picture the tiles are laid over, 4096 for the day map.
117
+ * @returns A level in `layer`, or `undefined` when no tile is worth loading.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * import { tileLevel, type TileLayer } from "@johnmorrisdotca/chikyu-earth/realistic";
122
+ *
123
+ * const day: TileLayer = { tileSize: 512, levels: [{ level: 3, width: 8192 }, { level: 4, width: 16384 }] };
124
+ * console.log(tileLevel(600, day, 4096), tileLevel(1500, day, 4096), tileLevel(9000, day, 4096));
125
+ * ```
126
+ */
127
+ export declare function tileLevel(radiusPx: number, layer: TileLayer, baseWidth: number): number | undefined;
128
+ /**
129
+ * The tile of a coarser or the same level that holds a tile.
130
+ *
131
+ * @param tile - A tile.
132
+ * @param level - A level no finer than the tile's.
133
+ * @returns The tile at `level` that covers it.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { coveringTile } from "@johnmorrisdotca/chikyu-earth/realistic";
138
+ *
139
+ * console.log(coveringTile({ level: 4, col: 17, row: 5 }, 3));
140
+ * ```
141
+ */
142
+ export declare function coveringTile(tile: TileId, level: number): TileId;
143
+ /**
144
+ * Where a tile's edges are, in longitude and latitude in radians: west, north, east and south.
145
+ *
146
+ * @param tile - A tile.
147
+ * @returns `[west, north, east, south]`.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { tileRect } from "@johnmorrisdotca/chikyu-earth/realistic";
152
+ *
153
+ * console.log(tileRect({ level: 3, col: 0, row: 0 }));
154
+ * ```
155
+ */
156
+ export declare function tileRect(tile: TileId): [number, number, number, number];
157
+ /**
158
+ * The longitude and latitude (degrees) under a point of the box, or `undefined` where the box shows the sky.
159
+ *
160
+ * @param camera - The camera.
161
+ * @param x - Across the box, CSS pixels from its left.
162
+ * @param y - Down the box, CSS pixels from its top.
163
+ * @returns The longitude and latitude in degrees under that point, or `undefined` where the box shows the sky.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * import { pointOnEarth } from "@johnmorrisdotca/chikyu-earth/realistic";
168
+ *
169
+ * console.log(pointOnEarth({ lon: 10, lat: 20, width: 800, height: 600, panX: 0, panY: 0, radius: 900 }, 400, 300));
170
+ * ```
171
+ */
172
+ export declare function pointOnEarth(camera: TileCamera, x: number, y: number): {
173
+ lon: number;
174
+ lat: number;
175
+ } | undefined;
176
+ /**
177
+ * The tiles of a level that are in view: those with a sampled point inside the box (a little over, so a tile slides in before its edge does), and those under a grid of points
178
+ * across the box. The antimeridian and the poles need nothing special: a tile is tested where it is on the sphere, and a longitude of 180 is the last column.
179
+ *
180
+ * @param level - A pyramid level.
181
+ * @param camera - The camera.
182
+ * @param sun - The Sun's direction as the camera sees it (+x right, +y up, +z toward the viewer), to read each tile's `ndl`; left out, `ndl` is 1.
183
+ * @returns The tiles in view, the nearest to the middle of the box first.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import { tilesInView } from "@johnmorrisdotca/chikyu-earth/realistic";
188
+ *
189
+ * const tiles = tilesInView(4, { lon: 179.9, lat: 89, width: 800, height: 600, panX: 0, panY: 0, radius: 3000 });
190
+ * console.log(tiles.length, tiles[0]);
191
+ * ```
192
+ */
193
+ export declare function tilesInView(level: number, camera: TileCamera, sun?: readonly [number, number, number]): VisibleTile[];
194
+ /**
195
+ * Read a tile set's manifest (`manifest.json`): the tile size and, for each layer, its levels. A manifest with no usable layer gives `undefined`.
196
+ *
197
+ * @param json - The parsed JSON.
198
+ * @returns A layer name to its levels, and the tile size; or `undefined`.
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * import { parseManifest } from "@johnmorrisdotca/chikyu-earth/realistic";
203
+ *
204
+ * const manifest = parseManifest({ tileSize: 512, layers: { day: { levels: [{ level: 3, width: 8192, height: 4096, columns: 16, rows: 8 }] } } });
205
+ * console.log(manifest?.layers["day"]?.levels);
206
+ * ```
207
+ */
208
+ export declare function parseManifest(json: unknown): {
209
+ tileSize: number;
210
+ layers: Record<string, TileLayer>;
211
+ } | undefined;