@margoengine/tiles 0.0.0-stage → 1.0.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +437 -2
- package/dist/bounds-CgKJT3Pg.js +161 -0
- package/dist/bounds.d.ts +66 -0
- package/dist/data-uri-DbGLVHq5.js +132 -0
- package/dist/data-uri.d.ts +2 -0
- package/dist/errors-D5_2oB8I.js +7 -0
- package/dist/fade.d.ts +34 -0
- package/dist/fade.js +129 -0
- package/dist/feature-texture.d.ts +19 -0
- package/dist/features.d.ts +78 -0
- package/dist/features.js +401 -0
- package/dist/formats-NNuOXg-1.js +390 -0
- package/dist/formats.d.ts +124 -0
- package/dist/glb-BU81jlYZ.js +25 -0
- package/dist/height.d.ts +20 -0
- package/dist/height.js +31 -0
- package/dist/i3dm.d.ts +16 -0
- package/dist/i3dm.js +85 -0
- package/dist/imagery.d.ts +108 -0
- package/dist/imagery.js +325 -0
- package/dist/implicit.d.ts +42 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +849 -0
- package/dist/ion.d.ts +106 -0
- package/dist/ion.js +152 -0
- package/dist/json-BQoirgm5.js +4 -0
- package/dist/matrix-DcI5oFrD.js +89 -0
- package/dist/matrix.d.ts +32 -0
- package/dist/memory.d.ts +44 -0
- package/dist/metadata.d.ts +147 -0
- package/dist/metadata.js +285 -0
- package/dist/properties.d.ts +94 -0
- package/dist/properties.js +320 -0
- package/dist/queue.d.ts +37 -0
- package/dist/raw-accessor.d.ts +4 -0
- package/dist/renderer.d.ts +193 -0
- package/dist/s2.d.ts +37 -0
- package/dist/s2.js +181 -0
- package/dist/scene-scope-DufD_3B6.js +42 -0
- package/dist/screen-door-CMv5Jko4.js +11 -0
- package/dist/shared/screen-door.d.ts +9 -0
- package/dist/splats.d.ts +80 -0
- package/dist/splats.js +187 -0
- package/dist/style.d.ts +61 -0
- package/dist/style.js +609 -0
- package/dist/terrain.d.ts +96 -0
- package/dist/terrain.js +434 -0
- package/dist/tileset.d.ts +316 -0
- package/dist/uv-transform.d.ts +11 -0
- package/dist/wgs84-C5btsGGY.js +18 -0
- package/dist/wgs84.d.ts +24 -0
- package/package.json +122 -4
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type TileMatrix } from './matrix.js';
|
|
2
|
+
/** A decoded quantized-mesh-1.0 tile. */
|
|
3
|
+
export interface QuantizedMesh {
|
|
4
|
+
/** Tile centre, ECEF metres (float64). */
|
|
5
|
+
readonly center: readonly [number, number, number];
|
|
6
|
+
readonly minimumHeight: number;
|
|
7
|
+
readonly maximumHeight: number;
|
|
8
|
+
readonly boundingSphere: readonly [number, number, number, number];
|
|
9
|
+
readonly horizonOcclusionPoint: readonly [number, number, number];
|
|
10
|
+
/** 0..32767 west to east, south to north, and 0..32767 from minimumHeight to maximumHeight, per vertex. */
|
|
11
|
+
readonly u: Uint16Array;
|
|
12
|
+
readonly v: Uint16Array;
|
|
13
|
+
readonly height: Uint16Array;
|
|
14
|
+
/** Triangles, counter-clockwise. */
|
|
15
|
+
readonly indices: Uint16Array | Uint32Array;
|
|
16
|
+
readonly west: Uint16Array | Uint32Array;
|
|
17
|
+
readonly south: Uint16Array | Uint32Array;
|
|
18
|
+
readonly east: Uint16Array | Uint32Array;
|
|
19
|
+
readonly north: Uint16Array | Uint32Array;
|
|
20
|
+
/** Oct-encoded normals (extension 1), two bytes per vertex. */
|
|
21
|
+
readonly normals?: Uint8Array;
|
|
22
|
+
/** Water mask (extension 2): one byte, or 256 x 256. */
|
|
23
|
+
readonly waterMask?: Uint8Array;
|
|
24
|
+
/** Metadata JSON (extension 4). */
|
|
25
|
+
readonly metadata?: unknown;
|
|
26
|
+
}
|
|
27
|
+
/** Decodes a quantized-mesh-1.0 tile (not gzipped). Throws RangeError when it is cut short or inconsistent. */
|
|
28
|
+
export declare function parseQuantizedMesh(bytes: Uint8Array): QuantizedMesh;
|
|
29
|
+
/** A geographic rectangle, radians: west, south, east, north. */
|
|
30
|
+
export type Rectangle = readonly [number, number, number, number];
|
|
31
|
+
/** The rectangle of TMS geographic (EPSG:4326) tile (z, x, y): two root tiles, y numbered from the south. */
|
|
32
|
+
export declare function geographicTileRectangle(z: number, x: number, y: number): Rectangle;
|
|
33
|
+
/** Imagery to drape: a URL template of map tiles, and how they are laid out. */
|
|
34
|
+
export interface TerrainImagery {
|
|
35
|
+
/** A URL template with `{z}`, `{x}` and `{y}`, such as an XYZ (slippy map) tile server's. Relative to the page. */
|
|
36
|
+
url: string;
|
|
37
|
+
/** `'EPSG:3857'` (default): Web Mercator, one root tile, as XYZ servers use; `'EPSG:4326'`: geographic, two roots. */
|
|
38
|
+
projection?: 'EPSG:3857' | 'EPSG:4326';
|
|
39
|
+
/** `'xyz'` (default for 3857): y from the north; `'tms'` (default for 4326): y from the south. */
|
|
40
|
+
scheme?: 'xyz' | 'tms';
|
|
41
|
+
/** Deepest level the server has. Default 19. */
|
|
42
|
+
maximumLevel?: number;
|
|
43
|
+
/** Image MIME type of the tiles. Default from the URL's extension, else `image/png`. */
|
|
44
|
+
mimeType?: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
45
|
+
}
|
|
46
|
+
/** Options of `terrain`. */
|
|
47
|
+
export interface TerrainOptions {
|
|
48
|
+
/** Imagery draped over the terrain. Without it the terrain draws lit in grey. */
|
|
49
|
+
imagery?: TerrainImagery;
|
|
50
|
+
/** Fetch for the terrain and imagery requests (auth headers, tests). Default `globalThis.fetch`. */
|
|
51
|
+
fetch?: (input: string, init?: {
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
headers?: Record<string, string>;
|
|
54
|
+
}) => Promise<Response>;
|
|
55
|
+
/** Skirt depth as a share of a tile's geometric error, hiding cracks between levels. Default 2. */
|
|
56
|
+
skirt?: number;
|
|
57
|
+
/** Subtree levels of the implicit tileset. Default 4. */
|
|
58
|
+
subtreeLevels?: number;
|
|
59
|
+
}
|
|
60
|
+
/** Geometric error of a level-0 tile: its width at the equator over the 64 spans of a typical 65-sample tile. */
|
|
61
|
+
export declare const LEVEL_ZERO_ERROR: number;
|
|
62
|
+
/** What `terrain` returns: pass both to `TilesRenderer.load(engine, url, { fetch })`. */
|
|
63
|
+
export interface TerrainSource {
|
|
64
|
+
/** The URL of the generated tileset. */
|
|
65
|
+
readonly url: string;
|
|
66
|
+
/** Serves the generated tileset, subtrees and b3dm tiles, and passes anything else on. */
|
|
67
|
+
readonly fetch: (input: string, init?: {
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}) => Promise<Response>;
|
|
70
|
+
/** The deepest terrain level. */
|
|
71
|
+
readonly maximumLevel: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Reads a quantized-mesh layer (its `layer.json`) and returns a tileset URL and fetch for `TilesRenderer.load`. Only
|
|
75
|
+
* the `EPSG:4326` projection and the `tms` scheme are read, the layout terrain servers use.
|
|
76
|
+
*/
|
|
77
|
+
export declare function terrain(layerUrl: string | URL, options?: TerrainOptions): Promise<TerrainSource>;
|
|
78
|
+
/** The imagery tile covering `rectangle` and how lon/lat map into it. */
|
|
79
|
+
interface Drape {
|
|
80
|
+
bytes: Uint8Array;
|
|
81
|
+
mimeType: string;
|
|
82
|
+
/** Texture coordinates of a longitude and latitude (radians). */
|
|
83
|
+
uv(longitude: number, latitude: number): [number, number];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The terrain tile as b3dm: a glTF mesh in y-up metres relative to its RTC_CENTER (the tile's centre, float64), with
|
|
87
|
+
* skirts `skirt` metres deep along its four edges, normals from the tile or from its triangles, and the imagery as an
|
|
88
|
+
* unlit base colour texture.
|
|
89
|
+
*/
|
|
90
|
+
export declare function meshB3dm(mesh: QuantizedMesh, rectangle: Rectangle, drape: Drape | undefined, skirt: number): Uint8Array;
|
|
91
|
+
/**
|
|
92
|
+
* A `frame` for `TilesRenderer.load` that puts the east-north-up frame at a longitude and latitude (degrees) and height
|
|
93
|
+
* at the world origin, x east, y up, -z north: a whole-globe terrain tileset's own centre is the earth's.
|
|
94
|
+
*/
|
|
95
|
+
export declare function terrainFrame(longitude: number, latitude: number, height?: number): TileMatrix;
|
|
96
|
+
export {};
|
package/dist/terrain.js
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { n as e, r as t, t as n } from "./glb-BU81jlYZ.js";
|
|
2
|
+
import { a as r, i, t as a } from "./wgs84-C5btsGGY.js";
|
|
3
|
+
import { n as o, o as s, s as c } from "./matrix-DcI5oFrD.js";
|
|
4
|
+
import { MargoError as l } from "@margoengine/math/errors";
|
|
5
|
+
//#region src/terrain.ts
|
|
6
|
+
var u = (e) => /* @__PURE__ */ RangeError(`Invalid quantized-mesh tile: ${e}; the file is cut or not quantized-mesh-1.0`);
|
|
7
|
+
function d(e) {
|
|
8
|
+
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = 0, r = (t, r) => {
|
|
9
|
+
if (n + t > e.byteLength) throw u(`${r} runs past the end (${e.byteLength} bytes)`);
|
|
10
|
+
}, i = () => (n += 8, t.getFloat64(n - 8, !0));
|
|
11
|
+
r(88, "the header");
|
|
12
|
+
let a = [
|
|
13
|
+
i(),
|
|
14
|
+
i(),
|
|
15
|
+
i()
|
|
16
|
+
], o = t.getFloat32(n, !0), s = t.getFloat32(n + 4, !0);
|
|
17
|
+
n += 8;
|
|
18
|
+
let c = [
|
|
19
|
+
i(),
|
|
20
|
+
i(),
|
|
21
|
+
i(),
|
|
22
|
+
i()
|
|
23
|
+
], l = [
|
|
24
|
+
i(),
|
|
25
|
+
i(),
|
|
26
|
+
i()
|
|
27
|
+
];
|
|
28
|
+
r(4, "vertexCount");
|
|
29
|
+
let d = t.getUint32(n, !0);
|
|
30
|
+
n += 4, r(d * 6, "the vertex data");
|
|
31
|
+
let f = () => {
|
|
32
|
+
let e = new Uint16Array(d), r = 0;
|
|
33
|
+
for (let i = 0; i < d; i++) {
|
|
34
|
+
let a = t.getUint16(n + i * 2, !0);
|
|
35
|
+
if (r += a >> 1 ^ -(a & 1), r < 0 || r > 32767) throw u(`a vertex coordinate decodes to ${r}, outside 0..32767`);
|
|
36
|
+
e[i] = r;
|
|
37
|
+
}
|
|
38
|
+
return n += d * 2, e;
|
|
39
|
+
}, p = f(), m = f(), h = f(), g = d > 65536, _ = g ? 4 : 2;
|
|
40
|
+
n % _ && (n += _ - n % _);
|
|
41
|
+
let v = (e, i) => {
|
|
42
|
+
r(e * _, i);
|
|
43
|
+
let a = g ? new Uint32Array(e) : new Uint16Array(e);
|
|
44
|
+
for (let r = 0; r < e; r++) a[r] = g ? t.getUint32(n + r * 4, !0) : t.getUint16(n + r * 2, !0);
|
|
45
|
+
return n += e * _, a;
|
|
46
|
+
};
|
|
47
|
+
r(4, "triangleCount");
|
|
48
|
+
let y = t.getUint32(n, !0);
|
|
49
|
+
n += 4;
|
|
50
|
+
let b = v(y * 3, "the triangle indices"), x = 0;
|
|
51
|
+
for (let e = 0; e < b.length; e++) {
|
|
52
|
+
let t = b[e];
|
|
53
|
+
if (b[e] = x - t, x - t < 0 || x - t >= d) throw u(`triangle index ${x - t} is not a vertex`);
|
|
54
|
+
t === 0 && x++;
|
|
55
|
+
}
|
|
56
|
+
let S = (e) => {
|
|
57
|
+
r(4, e);
|
|
58
|
+
let i = t.getUint32(n, !0);
|
|
59
|
+
n += 4;
|
|
60
|
+
let a = v(i, e);
|
|
61
|
+
for (let t of a) if (t >= d) throw u(`${e} index ${t} is not a vertex`);
|
|
62
|
+
return a;
|
|
63
|
+
}, C = S("the west edge"), w = S("the south edge"), T = S("the east edge"), E = S("the north edge"), D, O, k;
|
|
64
|
+
for (; n < e.byteLength;) {
|
|
65
|
+
r(5, "an extension header");
|
|
66
|
+
let i = t.getUint8(n), a = t.getUint32(n + 1, !0);
|
|
67
|
+
n += 5, r(a, `extension ${i}`);
|
|
68
|
+
let o = e.subarray(n, n + a);
|
|
69
|
+
if (i === 1) {
|
|
70
|
+
if (a !== d * 2) throw u(`the normals extension holds ${a} bytes for ${d} vertices`);
|
|
71
|
+
D = o;
|
|
72
|
+
} else if (i === 2) O = o;
|
|
73
|
+
else if (i === 4) {
|
|
74
|
+
let e = new DataView(o.buffer, o.byteOffset, o.byteLength);
|
|
75
|
+
if (a < 4 || e.getUint32(0, !0) + 4 > a) throw u("the metadata extension is cut");
|
|
76
|
+
k = JSON.parse(new TextDecoder().decode(o.subarray(4, 4 + e.getUint32(0, !0))));
|
|
77
|
+
}
|
|
78
|
+
n += a;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
center: a,
|
|
82
|
+
minimumHeight: o,
|
|
83
|
+
maximumHeight: s,
|
|
84
|
+
boundingSphere: c,
|
|
85
|
+
horizonOcclusionPoint: l,
|
|
86
|
+
u: p,
|
|
87
|
+
v: m,
|
|
88
|
+
height: h,
|
|
89
|
+
indices: b,
|
|
90
|
+
west: C,
|
|
91
|
+
south: w,
|
|
92
|
+
east: T,
|
|
93
|
+
north: E,
|
|
94
|
+
normals: D,
|
|
95
|
+
waterMask: O,
|
|
96
|
+
metadata: k
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function f(e, t, n) {
|
|
100
|
+
let r = Math.PI / 2 ** e;
|
|
101
|
+
return [
|
|
102
|
+
-Math.PI + t * r,
|
|
103
|
+
-Math.PI / 2 + n * r,
|
|
104
|
+
-Math.PI + (t + 1) * r,
|
|
105
|
+
-Math.PI / 2 + (n + 1) * r
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
function p(e, t) {
|
|
109
|
+
let n = e / 255 * 2 - 1, r = t / 255 * 2 - 1, i = 1 - Math.abs(n) - Math.abs(r);
|
|
110
|
+
if (i < 0) {
|
|
111
|
+
let e = n;
|
|
112
|
+
n = (1 - Math.abs(r)) * Math.sign(e || 1), r = (1 - Math.abs(e)) * Math.sign(r || 1);
|
|
113
|
+
}
|
|
114
|
+
let a = Math.hypot(n, r, i);
|
|
115
|
+
return [
|
|
116
|
+
n / a,
|
|
117
|
+
r / a,
|
|
118
|
+
i / a
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
var m = Math.PI * a / 64, h = -500, g = 9e3, _ = (e, t) => new l("failed", `Terrain request ${e} answered ${t}; check the layer URL and its access`);
|
|
122
|
+
async function v(e, t = {}) {
|
|
123
|
+
let n = new URL(String(e), globalThis.location?.href).href, r = t.fetch ?? globalThis.fetch.bind(globalThis), i = await r(n);
|
|
124
|
+
if (!i.ok) throw _(n, i.status);
|
|
125
|
+
let a = await i.json();
|
|
126
|
+
if (!Array.isArray(a.tiles) || typeof a.tiles[0] != "string") throw TypeError(`Invalid terrain layer ${n}: tiles is missing; give a URL template in "tiles"`);
|
|
127
|
+
if ((a.projection ?? "EPSG:4326") !== "EPSG:4326" || (a.scheme ?? "tms") !== "tms") throw new l("unsupported", `Terrain layer ${n} is ${a.projection ?? "EPSG:4326"} ${a.scheme ?? "tms"}; only EPSG:4326 tms layers are read`);
|
|
128
|
+
let o = a.available?.length ? a.available.length - 1 : a.maxzoom ?? 19, s = t.subtreeLevels ?? 4, c = (a.extensions ?? []).filter((e) => e === "octvertexnormals" || e === "watermask"), u = `application/vnd.quantized-mesh${c.length ? `;extensions=${c.join("-")}` : ""},application/octet-stream;q=0.9`, p = t.skirt ?? 2, v = (e, t, n) => {
|
|
129
|
+
if (e > o || t < 0 || n < 0 || t >= 2 ** (e + 1) || n >= 2 ** e) return !1;
|
|
130
|
+
let r = a.available?.[e];
|
|
131
|
+
return !a.available || !!r?.some((e) => t >= e.startX && t <= e.endX && n >= e.startY && n <= e.endY);
|
|
132
|
+
}, b = (e, t, r) => new URL(a.tiles[0].replace(/\{z\}/g, String(e)).replace(/\{x\}/g, String(t)).replace(/\{y\}/g, String(r)).replace(/\{version\}/g, a.version ?? "1.0.0"), n).href, x = "margo-terrain:/", w = {
|
|
133
|
+
asset: { version: "1.1" },
|
|
134
|
+
geometricError: m * 2,
|
|
135
|
+
root: {
|
|
136
|
+
boundingVolume: { region: [
|
|
137
|
+
-Math.PI,
|
|
138
|
+
-Math.PI / 2,
|
|
139
|
+
Math.PI,
|
|
140
|
+
Math.PI / 2,
|
|
141
|
+
h,
|
|
142
|
+
g
|
|
143
|
+
] },
|
|
144
|
+
geometricError: m * 2,
|
|
145
|
+
refine: "REPLACE",
|
|
146
|
+
children: [0, 1].map((e) => ({
|
|
147
|
+
boundingVolume: { region: [
|
|
148
|
+
...f(0, e, 0),
|
|
149
|
+
h,
|
|
150
|
+
g
|
|
151
|
+
] },
|
|
152
|
+
geometricError: m,
|
|
153
|
+
refine: "REPLACE",
|
|
154
|
+
content: { uri: `${e}/{level}/{x}/{y}.b3dm` },
|
|
155
|
+
implicitTiling: {
|
|
156
|
+
subdivisionScheme: "QUADTREE",
|
|
157
|
+
subtreeLevels: s,
|
|
158
|
+
availableLevels: o + 1,
|
|
159
|
+
subtrees: { uri: `${e}/{level}/{x}/{y}.subtree` }
|
|
160
|
+
}
|
|
161
|
+
}))
|
|
162
|
+
}
|
|
163
|
+
}, T = new TextEncoder(), E = async (e, n) => {
|
|
164
|
+
if (e === "tileset.json") return T.encode(JSON.stringify(w));
|
|
165
|
+
let i = /^([01])\/(\d+)\/(\d+)\/(\d+)\.(subtree|b3dm)$/.exec(e);
|
|
166
|
+
if (!i) throw TypeError(`Unknown terrain path ${e}; request only the URLs of the tileset terrain() made`);
|
|
167
|
+
let [, a, o, c, l, h] = i, g = Number(o), x = Number(a) * 2 ** g + Number(c), E = Number(l);
|
|
168
|
+
if (h === "subtree") return y(g, x, E, s, v);
|
|
169
|
+
let D = b(g, x, E), O = await r(D, {
|
|
170
|
+
signal: n,
|
|
171
|
+
headers: { Accept: u }
|
|
172
|
+
});
|
|
173
|
+
if (!O.ok) throw _(D, O.status);
|
|
174
|
+
let k = d(new Uint8Array(await O.arrayBuffer())), A = f(g, x, E);
|
|
175
|
+
return C(k, A, t.imagery ? await S(t.imagery, A, g, r, n) : void 0, m / 2 ** g * p);
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
url: `${x}tileset.json`,
|
|
179
|
+
maximumLevel: o,
|
|
180
|
+
fetch: async (e, t) => {
|
|
181
|
+
let n = String(e);
|
|
182
|
+
if (!n.startsWith(x)) return r(n, t);
|
|
183
|
+
let i = await E(n.slice(15), t?.signal);
|
|
184
|
+
return new Response(i, { status: 200 });
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function y(e, t, n, r, i) {
|
|
189
|
+
let a = [];
|
|
190
|
+
for (let o = 0; o < r; o++) for (let r = 0; r < 4 ** o; r++) {
|
|
191
|
+
let s = 0, c = 0;
|
|
192
|
+
for (let e = 0; e < o; e++) s |= (r >> 2 * e & 1) << e, c |= (r >> 2 * e + 1 & 1) << e;
|
|
193
|
+
a.push(i(e + o, t * 2 ** o + s, n * 2 ** o + c));
|
|
194
|
+
}
|
|
195
|
+
let o = [];
|
|
196
|
+
for (let a = 0; a < 4 ** r; a++) {
|
|
197
|
+
let s = 0, c = 0;
|
|
198
|
+
for (let e = 0; e < r; e++) s |= (a >> 2 * e & 1) << e, c |= (a >> 2 * e + 1 & 1) << e;
|
|
199
|
+
o.push(i(e + r, t * 2 ** r + s, n * 2 ** r + c));
|
|
200
|
+
}
|
|
201
|
+
let s = (e) => {
|
|
202
|
+
let t = new Uint8Array(Math.ceil(e.length / 8));
|
|
203
|
+
return e.forEach((e, n) => {
|
|
204
|
+
e && (t[n >> 3] |= 1 << (n & 7));
|
|
205
|
+
}), t;
|
|
206
|
+
}, c = [], l = [], u = 0, d = (e) => {
|
|
207
|
+
if (e.every((e) => e)) return { constant: 1 };
|
|
208
|
+
if (!e.some((e) => e)) return { constant: 0 };
|
|
209
|
+
let t = s(e);
|
|
210
|
+
return c.push({
|
|
211
|
+
buffer: 0,
|
|
212
|
+
byteOffset: u,
|
|
213
|
+
byteLength: t.byteLength
|
|
214
|
+
}), l.push(t), u += Math.ceil(t.byteLength / 8) * 8, { bitstream: c.length - 1 };
|
|
215
|
+
}, f = d(a), p = {
|
|
216
|
+
tileAvailability: f,
|
|
217
|
+
contentAvailability: [f],
|
|
218
|
+
childSubtreeAvailability: d(o)
|
|
219
|
+
};
|
|
220
|
+
u && (p.buffers = [{ byteLength: u }], p.bufferViews = c);
|
|
221
|
+
let m = b(new TextEncoder().encode(JSON.stringify(p)), 32), h = new Uint8Array(u), g = 0;
|
|
222
|
+
for (let e of l) h.set(e, g), g += Math.ceil(e.byteLength / 8) * 8;
|
|
223
|
+
let _ = new Uint8Array(24 + m.byteLength + h.byteLength), v = new DataView(_.buffer);
|
|
224
|
+
return v.setUint32(0, 1952609651, !0), v.setUint32(4, 1, !0), v.setBigUint64(8, BigInt(m.byteLength), !0), v.setBigUint64(16, BigInt(h.byteLength), !0), _.set(m, 24), _.set(h, 24 + m.byteLength), _;
|
|
225
|
+
}
|
|
226
|
+
function b(e, t) {
|
|
227
|
+
let n = new Uint8Array(Math.ceil(e.byteLength / 8) * 8).fill(t);
|
|
228
|
+
return n.set(e), n;
|
|
229
|
+
}
|
|
230
|
+
var x = Math.atan(Math.sinh(Math.PI));
|
|
231
|
+
async function S(e, [t, n, r, i], a, o, s) {
|
|
232
|
+
let c = (e.projection ?? "EPSG:3857") === "EPSG:3857", l = e.scheme ?? (c ? "xyz" : "tms"), u = e.maximumLevel ?? 19, d = (e) => (e + Math.PI) / (2 * Math.PI), f = (e) => {
|
|
233
|
+
if (!c) return (Math.PI / 2 - e) / Math.PI;
|
|
234
|
+
let t = Math.max(-x, Math.min(x, e));
|
|
235
|
+
return (1 - Math.log(Math.tan(Math.PI / 4 + t / 2)) / Math.PI) / 2;
|
|
236
|
+
}, p = (e) => c ? 2 ** e : 2 ** (e + 1), m = (e) => 2 ** e, h = 1e-9, g = Math.min(u, a + 1), v = 0, y = 0;
|
|
237
|
+
for (; g >= 0; g--) {
|
|
238
|
+
let e = Math.floor((d(t) + h) * p(g)), a = Math.floor((d(r) - h) * p(g)), o = Math.floor((f(i) + h) * m(g)), s = Math.floor((f(n) - h) * m(g));
|
|
239
|
+
if (e === a && o === s) {
|
|
240
|
+
v = e, y = o;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
g < 0 && (g = 0);
|
|
245
|
+
let b = l === "xyz" ? y : m(g) - 1 - y, S = e.url.replace(/\{z\}/g, String(g)).replace(/\{x\}/g, String(v)).replace(/\{y\}/g, String(b)), C = await o(S, { signal: s });
|
|
246
|
+
if (!C.ok) throw _(S, C.status);
|
|
247
|
+
let w = e.mimeType ?? (/\.jpe?g(\?|$)/i.test(S) ? "image/jpeg" : /\.webp(\?|$)/i.test(S) ? "image/webp" : "image/png");
|
|
248
|
+
return {
|
|
249
|
+
bytes: new Uint8Array(await C.arrayBuffer()),
|
|
250
|
+
mimeType: w,
|
|
251
|
+
uv: (e, t) => [d(e) * p(g) - v, f(t) * m(g) - y]
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function C(e, t, n, r) {
|
|
255
|
+
let [a, o, s, c] = t, l = e.u.length, u = [
|
|
256
|
+
e.west,
|
|
257
|
+
e.south,
|
|
258
|
+
e.east,
|
|
259
|
+
e.north
|
|
260
|
+
], d = l + u.reduce((e, t) => e + t.length, 0), f = new Float32Array(d * 3), m = new Float32Array(d * 3), h = new Float32Array(d * 2), g = e.center, _ = new Float64Array(l * 2), v = e.maximumHeight - e.minimumHeight, y = (e, t, r, a) => {
|
|
261
|
+
let o = i(t, r, a);
|
|
262
|
+
if (f[e * 3] = o[0] - g[0], f[e * 3 + 1] = o[2] - g[2], f[e * 3 + 2] = -(o[1] - g[1]), n) {
|
|
263
|
+
let [i, a] = n.uv(t, r);
|
|
264
|
+
h[e * 2] = i, h[e * 2 + 1] = a;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
for (let t = 0; t < l; t++) {
|
|
268
|
+
let n = a + e.u[t] / 32767 * (s - a), r = o + e.v[t] / 32767 * (c - o);
|
|
269
|
+
_[t * 2] = n, _[t * 2 + 1] = r, y(t, n, r, e.minimumHeight + e.height[t] / 32767 * v);
|
|
270
|
+
}
|
|
271
|
+
if (e.normals) for (let t = 0; t < l; t++) {
|
|
272
|
+
let [n, r, i] = p(e.normals[t * 2], e.normals[t * 2 + 1]);
|
|
273
|
+
m.set([
|
|
274
|
+
n,
|
|
275
|
+
i,
|
|
276
|
+
-r
|
|
277
|
+
], t * 3);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
let t = e.indices;
|
|
281
|
+
for (let e = 0; e < t.length; e += 3) {
|
|
282
|
+
let n = t[e] * 3, r = t[e + 1] * 3, i = t[e + 2] * 3, a = [
|
|
283
|
+
0,
|
|
284
|
+
1,
|
|
285
|
+
2
|
|
286
|
+
].map((e) => f[r + e] - f[n + e]), o = [
|
|
287
|
+
0,
|
|
288
|
+
1,
|
|
289
|
+
2
|
|
290
|
+
].map((e) => f[i + e] - f[n + e]), s = [
|
|
291
|
+
a[1] * o[2] - a[2] * o[1],
|
|
292
|
+
a[2] * o[0] - a[0] * o[2],
|
|
293
|
+
a[0] * o[1] - a[1] * o[0]
|
|
294
|
+
];
|
|
295
|
+
for (let e of [
|
|
296
|
+
n,
|
|
297
|
+
r,
|
|
298
|
+
i
|
|
299
|
+
]) for (let t = 0; t < 3; t++) m[e + t] += s[t];
|
|
300
|
+
}
|
|
301
|
+
for (let e = 0; e < l; e++) {
|
|
302
|
+
let t = Math.hypot(m[e * 3], m[e * 3 + 1], m[e * 3 + 2]) || 1;
|
|
303
|
+
for (let n = 0; n < 3; n++) m[e * 3 + n] /= t;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
let b = [], x = l;
|
|
307
|
+
u.forEach((t, n) => {
|
|
308
|
+
let i = n % 2 == 0 ? e.v : e.u, a = Array.from(t).sort((e, t) => i[e] - i[t]), o = x;
|
|
309
|
+
for (let t of a) y(x, _[t * 2], _[t * 2 + 1], e.minimumHeight + e.height[t] / 32767 * v - r), m.set(m.subarray(t * 3, t * 3 + 3), x * 3), x++;
|
|
310
|
+
for (let e = 0; e + 1 < a.length; e++) {
|
|
311
|
+
let t = a[e], n = a[e + 1], r = o + e, i = o + e + 1;
|
|
312
|
+
b.push(t, r, n, n, r, i, t, n, r, n, i, r);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
let S = e.indices.length + b.length, C = d > 65535 ? new Uint32Array(S) : new Uint16Array(S);
|
|
316
|
+
return C.set(e.indices), C.set(b, e.indices.length), T(w(f, m, n ? h : void 0, C, n), e.center);
|
|
317
|
+
}
|
|
318
|
+
function w(r, i, a, o, s) {
|
|
319
|
+
let c = [], l = [], u = 0, d = (e, t) => {
|
|
320
|
+
let n = new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
321
|
+
l.push({
|
|
322
|
+
buffer: 0,
|
|
323
|
+
byteOffset: u,
|
|
324
|
+
byteLength: n.byteLength,
|
|
325
|
+
...t ? { target: t } : {}
|
|
326
|
+
}), c.push(n), u += n.byteLength;
|
|
327
|
+
let r = (4 - u % 4) % 4;
|
|
328
|
+
return r && (c.push(new Uint8Array(r)), u += r), l.length - 1;
|
|
329
|
+
}, f = r.length / 3, p = [
|
|
330
|
+
Infinity,
|
|
331
|
+
Infinity,
|
|
332
|
+
Infinity
|
|
333
|
+
], m = [
|
|
334
|
+
-Infinity,
|
|
335
|
+
-Infinity,
|
|
336
|
+
-Infinity
|
|
337
|
+
];
|
|
338
|
+
for (let e = 0; e < f; e++) for (let t = 0; t < 3; t++) p[t] = Math.min(p[t], r[e * 3 + t]), m[t] = Math.max(m[t], r[e * 3 + t]);
|
|
339
|
+
let h = [
|
|
340
|
+
{
|
|
341
|
+
bufferView: d(r, 34962),
|
|
342
|
+
componentType: 5126,
|
|
343
|
+
count: f,
|
|
344
|
+
type: "VEC3",
|
|
345
|
+
min: p,
|
|
346
|
+
max: m
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
bufferView: d(i, 34962),
|
|
350
|
+
componentType: 5126,
|
|
351
|
+
count: f,
|
|
352
|
+
type: "VEC3"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
bufferView: d(o, 34963),
|
|
356
|
+
componentType: o instanceof Uint32Array ? 5125 : 5123,
|
|
357
|
+
count: o.length,
|
|
358
|
+
type: "SCALAR"
|
|
359
|
+
}
|
|
360
|
+
], g = {
|
|
361
|
+
POSITION: 0,
|
|
362
|
+
NORMAL: 1
|
|
363
|
+
}, _ = {
|
|
364
|
+
asset: {
|
|
365
|
+
version: "2.0",
|
|
366
|
+
generator: "margoengine tiles/terrain"
|
|
367
|
+
},
|
|
368
|
+
scene: 0,
|
|
369
|
+
scenes: [{ nodes: [0] }],
|
|
370
|
+
nodes: [{ mesh: 0 }],
|
|
371
|
+
accessors: h,
|
|
372
|
+
bufferViews: l
|
|
373
|
+
}, v = { pbrMetallicRoughness: {
|
|
374
|
+
baseColorFactor: [
|
|
375
|
+
.6,
|
|
376
|
+
.6,
|
|
377
|
+
.58,
|
|
378
|
+
1
|
|
379
|
+
],
|
|
380
|
+
metallicFactor: 0,
|
|
381
|
+
roughnessFactor: 1
|
|
382
|
+
} };
|
|
383
|
+
s && a && (h.push({
|
|
384
|
+
bufferView: d(a, 34962),
|
|
385
|
+
componentType: 5126,
|
|
386
|
+
count: f,
|
|
387
|
+
type: "VEC2"
|
|
388
|
+
}), g.TEXCOORD_0 = 3, _.images = [{
|
|
389
|
+
bufferView: d(s.bytes),
|
|
390
|
+
mimeType: s.mimeType
|
|
391
|
+
}], _.samplers = [{
|
|
392
|
+
magFilter: 9729,
|
|
393
|
+
minFilter: 9987,
|
|
394
|
+
wrapS: 33071,
|
|
395
|
+
wrapT: 33071
|
|
396
|
+
}], _.textures = [{
|
|
397
|
+
source: 0,
|
|
398
|
+
sampler: 0
|
|
399
|
+
}], v = {
|
|
400
|
+
pbrMetallicRoughness: {
|
|
401
|
+
baseColorTexture: { index: 0 },
|
|
402
|
+
metallicFactor: 0,
|
|
403
|
+
roughnessFactor: 1
|
|
404
|
+
},
|
|
405
|
+
extensions: { KHR_materials_unlit: {} }
|
|
406
|
+
}, _.extensionsUsed = ["KHR_materials_unlit"]), _.materials = [v], _.meshes = [{ primitives: [{
|
|
407
|
+
attributes: g,
|
|
408
|
+
indices: 2,
|
|
409
|
+
material: 0
|
|
410
|
+
}] }], _.buffers = [{ byteLength: u }];
|
|
411
|
+
let y = new TextEncoder().encode(JSON.stringify(_)), b = Math.ceil(y.byteLength / 4) * 4, x = new Uint8Array(20 + b + 8 + u), S = new DataView(x.buffer);
|
|
412
|
+
S.setUint32(0, t, !0), S.setUint32(4, 2, !0), S.setUint32(8, x.byteLength, !0), S.setUint32(12, b, !0), S.setUint32(16, e, !0), x.fill(32, 20, 20 + b), x.set(y, 20), S.setUint32(20 + b, u, !0), S.setUint32(24 + b, n, !0);
|
|
413
|
+
let C = 28 + b;
|
|
414
|
+
for (let e of c) x.set(e, C), C += e.byteLength;
|
|
415
|
+
return x;
|
|
416
|
+
}
|
|
417
|
+
function T(e, t) {
|
|
418
|
+
let n = new TextEncoder().encode(JSON.stringify({
|
|
419
|
+
BATCH_LENGTH: 0,
|
|
420
|
+
RTC_CENTER: [...t]
|
|
421
|
+
})), r = Math.ceil((28 + n.byteLength) / 8) * 8 - 28, i = new Uint8Array(28 + r + e.byteLength), a = new DataView(i.buffer);
|
|
422
|
+
return i.set([
|
|
423
|
+
98,
|
|
424
|
+
51,
|
|
425
|
+
100,
|
|
426
|
+
109
|
|
427
|
+
]), a.setUint32(4, 1, !0), a.setUint32(8, i.byteLength, !0), a.setUint32(12, r, !0), i.fill(32, 28, 28 + r), i.set(n, 28), i.set(e, 28 + r), i;
|
|
428
|
+
}
|
|
429
|
+
function E(e, t, n = 0) {
|
|
430
|
+
let a = i(e * Math.PI / 180, t * Math.PI / 180, n);
|
|
431
|
+
return c(o, s(r(a[0], a[1], a[2])));
|
|
432
|
+
}
|
|
433
|
+
//#endregion
|
|
434
|
+
export { m as LEVEL_ZERO_ERROR, f as geographicTileRectangle, C as meshB3dm, d as parseQuantizedMesh, v as terrain, E as terrainFrame };
|