@margoengine/tiles 0.0.0-stage → 0.1.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 (54) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +307 -3
  4. package/dist/bounds-CgKJT3Pg.js +161 -0
  5. package/dist/bounds.d.ts +66 -0
  6. package/dist/data-uri-DbGLVHq5.js +132 -0
  7. package/dist/data-uri.d.ts +2 -0
  8. package/dist/errors-D5_2oB8I.js +7 -0
  9. package/dist/fade.d.ts +34 -0
  10. package/dist/fade.js +129 -0
  11. package/dist/feature-texture.d.ts +19 -0
  12. package/dist/features.d.ts +78 -0
  13. package/dist/features.js +401 -0
  14. package/dist/formats-NNuOXg-1.js +390 -0
  15. package/dist/formats.d.ts +124 -0
  16. package/dist/glb-BU81jlYZ.js +25 -0
  17. package/dist/height.d.ts +20 -0
  18. package/dist/height.js +31 -0
  19. package/dist/i3dm.d.ts +16 -0
  20. package/dist/i3dm.js +85 -0
  21. package/dist/imagery.d.ts +108 -0
  22. package/dist/imagery.js +325 -0
  23. package/dist/implicit.d.ts +42 -0
  24. package/dist/index.d.ts +9 -0
  25. package/dist/index.js +849 -0
  26. package/dist/ion.d.ts +106 -0
  27. package/dist/ion.js +152 -0
  28. package/dist/json-BQoirgm5.js +4 -0
  29. package/dist/matrix-DcI5oFrD.js +89 -0
  30. package/dist/matrix.d.ts +32 -0
  31. package/dist/memory.d.ts +44 -0
  32. package/dist/metadata.d.ts +147 -0
  33. package/dist/metadata.js +285 -0
  34. package/dist/properties.d.ts +94 -0
  35. package/dist/properties.js +320 -0
  36. package/dist/queue.d.ts +37 -0
  37. package/dist/raw-accessor.d.ts +4 -0
  38. package/dist/renderer.d.ts +193 -0
  39. package/dist/s2.d.ts +37 -0
  40. package/dist/s2.js +181 -0
  41. package/dist/scene-scope-DufD_3B6.js +42 -0
  42. package/dist/screen-door-CMv5Jko4.js +11 -0
  43. package/dist/shared/screen-door.d.ts +9 -0
  44. package/dist/splats.d.ts +80 -0
  45. package/dist/splats.js +187 -0
  46. package/dist/style.d.ts +61 -0
  47. package/dist/style.js +609 -0
  48. package/dist/terrain.d.ts +96 -0
  49. package/dist/terrain.js +434 -0
  50. package/dist/tileset.d.ts +316 -0
  51. package/dist/uv-transform.d.ts +11 -0
  52. package/dist/wgs84-C5btsGGY.js +18 -0
  53. package/dist/wgs84.d.ts +24 -0
  54. package/package.json +124 -6
package/dist/ion.d.ts ADDED
@@ -0,0 +1,106 @@
1
+ import type { TileContent } from './formats.js';
2
+ import type { TilesetTile } from './tileset.js';
3
+ /** The fetch a tileset, the renderer and `terrain` take. */
4
+ export type TilesFetch = (input: string, init?: {
5
+ signal?: AbortSignal;
6
+ headers?: Record<string, string>;
7
+ }) => Promise<Response>;
8
+ /** A credit to show with the view. */
9
+ export interface Credit {
10
+ /** Plain text (tags of `html` removed). */
11
+ readonly text: string;
12
+ /** The service's own HTML for it (ion attributions, with links and logos), else undefined. */
13
+ readonly html?: string;
14
+ /** False: it must be on screen. True: it may sit behind a "credits" control (ion's `collapsible`). */
15
+ readonly collapsible: boolean;
16
+ /** Drawn tiles naming it this update; 0 for a service credit. */
17
+ readonly count: number;
18
+ }
19
+ /** A signed tileset or terrain layer, ready for `TilesRenderer.load(engine, url, { fetch })` or `terrain(url, { fetch })`. */
20
+ export interface HostedTileset {
21
+ /** The tileset (or terrain layer) URL. */
22
+ readonly url: string;
23
+ /** Signs every request to the service's host; other hosts get the request as it was. */
24
+ readonly fetch: TilesFetch;
25
+ /** The service's attributions, to pass to `TileCredits`. */
26
+ readonly credits: readonly Credit[];
27
+ /** ion's asset type ('3DTILES', 'TERRAIN', ...); '3DTILES' for `hostedTileset`. */
28
+ readonly type: string;
29
+ }
30
+ /** Options of `hostedTileset`. */
31
+ export interface HostedTilesetOptions {
32
+ /** Headers added to each request to the tileset's host (such as an API key header). */
33
+ headers?: Record<string, string>;
34
+ /** Query parameters added to each request to the tileset's host that lacks them (such as `key`). */
35
+ query?: Record<string, string>;
36
+ /**
37
+ * Query parameters the service puts in tile URLs and wants on every later request (default `['session']`): the
38
+ * last value seen on a request is added to requests without one, as relative tile URIs drop the query.
39
+ */
40
+ carry?: readonly string[];
41
+ /** Credits the service asks for on top of the tiles' own copyright. */
42
+ credits?: readonly Credit[];
43
+ /** The fetch under the signing (tests, caches). Default `globalThis.fetch`. */
44
+ fetch?: TilesFetch;
45
+ }
46
+ /** Options of `ionAsset`. */
47
+ export interface IonOptions {
48
+ /** Your ion access token (sent as a bearer header, never in a URL). */
49
+ accessToken: string;
50
+ /** The ion API server. Default `'https://api.cesium.com/'`. */
51
+ server?: string;
52
+ /** The fetch under the signing (tests, caches). Default `globalThis.fetch`. */
53
+ fetch?: TilesFetch;
54
+ }
55
+ /**
56
+ * A tileset on a token-based service: each request to its host gets `headers` and missing `query` parameters, and
57
+ * `carry` parameters (a session) seen on one request go on to the next. No request is made until the tileset loads.
58
+ */
59
+ export declare function hostedTileset(url: string | URL, options?: HostedTilesetOptions): HostedTileset;
60
+ /**
61
+ * Signs in to a Cesium ion asset: asks `server` for its endpoint with `accessToken`, and returns its URL, a fetch
62
+ * that sends the asset's own token to the asset's host (asking for a new one once when it answers 401), and its
63
+ * attributions as credits. Assets ion only points at (`externalType`, such as Bing imagery) throw `unsupported`.
64
+ */
65
+ export declare function ionAsset(assetId: number, options: IonOptions): Promise<HostedTileset>;
66
+ /** The text of an HTML fragment: tags removed, entities decoded, white space collapsed. Only for text output. */
67
+ export declare function htmlText(html: string): string;
68
+ /** The copyright credits a tile content names (cached per content). */
69
+ export declare function contentCopyright(content: TileContent): readonly string[];
70
+ /** What `TileCredits.follow` watches: a `TilesRenderer`. */
71
+ export interface CreditsSource {
72
+ readonly last: {
73
+ readonly selected: readonly TilesetTile[];
74
+ };
75
+ onUpdate(listener: () => void): () => void;
76
+ }
77
+ /**
78
+ * The credits to show with the view: the service's first (in their order), then each copyright of the drawn tiles'
79
+ * glTF `asset.copyright` (split on semicolons), by how many drawn tiles name it, most first, ties by text.
80
+ */
81
+ export declare class TileCredits {
82
+ /** Service credits first, then the drawn tiles' copyrights. */
83
+ list: readonly Credit[];
84
+ private readonly service;
85
+ private key;
86
+ private stop?;
87
+ private element?;
88
+ constructor(service?: readonly Credit[]);
89
+ /** Follows a renderer: recounts after each selection update and writes `text()` to `element` when it changes. */
90
+ static follow(tiles: CreditsSource, options?: {
91
+ credits?: readonly Credit[];
92
+ element?: {
93
+ textContent: string | null;
94
+ };
95
+ }): TileCredits;
96
+ /** Recounts from the tiles drawn this update; true when the list changed. */
97
+ update(selected: readonly TilesetTile[]): boolean;
98
+ /** The credits as plain text, joined by `separator`; `collapsible: false` only when `required` is true. */
99
+ text(separator?: string, required?: boolean): string;
100
+ /** The credits as HTML: the service's own HTML as it gave it, the tiles' copyright escaped. */
101
+ html(separator?: string): string;
102
+ /** Stops following the renderer. */
103
+ dispose(): void;
104
+ /** Same as `dispose()`, for `using credits = TileCredits.follow(...)`. */
105
+ [Symbol.dispose](): void;
106
+ }
package/dist/ion.js ADDED
@@ -0,0 +1,152 @@
1
+ import { t as e } from "./json-BQoirgm5.js";
2
+ import { a as t, i as n } from "./glb-BU81jlYZ.js";
3
+ import { MargoError as r } from "@margoengine/math/errors";
4
+ //#region src/ion.ts
5
+ function i(e) {
6
+ let t = e ?? globalThis.fetch?.bind(globalThis);
7
+ if (!t) throw new r("unsupported", "No fetch available; pass options.fetch");
8
+ return t;
9
+ }
10
+ function a(e, t, n, r, i) {
11
+ let a = new URL(e).origin, o = /* @__PURE__ */ new Map(), s, c = (e, n) => i(e.href, {
12
+ ...n,
13
+ headers: {
14
+ ...n?.headers,
15
+ ...t.headers
16
+ }
17
+ });
18
+ return async (l, u) => {
19
+ let d = new URL(l, e);
20
+ if (d.origin !== a) return i(l, u);
21
+ for (let e of r) {
22
+ let t = d.searchParams.get(e);
23
+ t === null ? o.has(e) && d.searchParams.set(e, o.get(e)) : o.set(e, t);
24
+ }
25
+ for (let [e, t] of Object.entries(n)) d.searchParams.has(e) || d.searchParams.set(e, t);
26
+ let f = t.headers, p = await c(d, u);
27
+ return p.status !== 401 || !t.refresh ? p : (t.headers === f && (s ??= t.refresh().then((e) => (t.headers = e, s = void 0, e), (e) => {
28
+ throw s = void 0, e;
29
+ })), s && await s, c(d, u));
30
+ };
31
+ }
32
+ function o(e, t = {}) {
33
+ let n = String(e);
34
+ if (!URL.canParse(n)) throw TypeError(`Invalid hosted tileset URL ${JSON.stringify(n)}; give an absolute URL`);
35
+ return {
36
+ url: n,
37
+ fetch: a(n, { headers: { ...t.headers } }, { ...t.query }, t.carry ?? ["session"], i(t.fetch)),
38
+ credits: [...t.credits ?? []],
39
+ type: "3DTILES"
40
+ };
41
+ }
42
+ async function s(t, n, i) {
43
+ let a = await i(t, { headers: { Authorization: `Bearer ${n}` } });
44
+ if (!a.ok) {
45
+ let n = "";
46
+ try {
47
+ n = String(e(await a.text()).message ?? "");
48
+ } catch {}
49
+ let i = a.status === 401 ? "check the access token" : a.status === 404 ? "check the asset ID and that the token may read it" : "try again later";
50
+ throw new r("failed", `ion endpoint ${t} answered ${a.status}${n ? ` (${n})` : ""}; ${i}`);
51
+ }
52
+ return e(await a.text());
53
+ }
54
+ async function c(e, t) {
55
+ if (!Number.isInteger(e) || e < 0) throw RangeError(`Invalid ion asset ID ${e}; pass a whole number, as ion lists it`);
56
+ if (typeof t?.accessToken != "string" || !t.accessToken) throw TypeError("ionAsset needs { accessToken }: an ion access token");
57
+ let n = i(t.fetch), o = new URL(`v1/assets/${e}/endpoint`, t.server ?? "https://api.cesium.com/").href, c = await s(o, t.accessToken, n);
58
+ if (typeof c.url != "string" || !URL.canParse(c.url)) throw new r("unsupported", `ion asset ${e} (${c.type ?? "no type"}${c.externalType ? `, external ${c.externalType}` : ""}) has no URL to stream; use a 3D Tiles or terrain asset`);
59
+ let l = (e) => e ? { Authorization: `Bearer ${e}` } : {}, d = {
60
+ headers: l(c.accessToken),
61
+ refresh: async () => l((await s(o, t.accessToken, n)).accessToken)
62
+ }, f = (c.attributions ?? []).filter((e) => typeof e?.html == "string").map((e) => ({
63
+ text: u(e.html),
64
+ html: e.html,
65
+ collapsible: e.collapsible !== !1,
66
+ count: 0
67
+ }));
68
+ return {
69
+ url: c.url,
70
+ fetch: a(c.url, d, {}, [], n),
71
+ credits: f,
72
+ type: c.type ?? "3DTILES"
73
+ };
74
+ }
75
+ var l = {
76
+ amp: "&",
77
+ lt: "<",
78
+ gt: ">",
79
+ quot: "\"",
80
+ apos: "'",
81
+ nbsp: "\xA0",
82
+ copy: "©",
83
+ reg: "®"
84
+ };
85
+ function u(e) {
86
+ return e.replace(/<[^>]*>/g, " ").replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (e, t) => {
87
+ if (t[0] !== "#") return l[t.toLowerCase()] ?? e;
88
+ let n = t[1] === "x" || t[1] === "X", r = Number.parseInt(t.slice(n ? 2 : 1), n ? 16 : 10);
89
+ return r <= 1114111 ? String.fromCodePoint(r) : e;
90
+ }).replace(/\s+/g, " ").trim();
91
+ }
92
+ var d = {
93
+ "&": "&amp;",
94
+ "<": "&lt;",
95
+ ">": "&gt;",
96
+ "\"": "&quot;",
97
+ "'": "&#39;"
98
+ };
99
+ function f(e) {
100
+ return e.replace(/[&<>"']/g, (e) => d[e]);
101
+ }
102
+ var p = new TextDecoder();
103
+ function m(r) {
104
+ try {
105
+ let i = t(r) ? n(r)[0].data : r, a = e(p.decode(i)).asset?.copyright;
106
+ return typeof a == "string" ? a.split(";").map((e) => e.trim()).filter(Boolean) : [];
107
+ } catch {
108
+ return [];
109
+ }
110
+ }
111
+ var h = /* @__PURE__ */ new WeakMap();
112
+ function g(e) {
113
+ let t = h.get(e);
114
+ return t || (t = e.type === "cmpt" ? [...new Set(e.tiles.flatMap((e) => g(e)))] : e.type === "pnts" || !e.gltf ? [] : [...new Set(m(e.gltf))], h.set(e, t)), t;
115
+ }
116
+ var _ = class e {
117
+ constructor(e = []) {
118
+ this.list = [], this.key = "", this.service = e, this.list = [...e];
119
+ }
120
+ static follow(t, n = {}) {
121
+ let r = new e(n.credits);
122
+ return r.element = n.element, r.element && (r.element.textContent = r.text()), r.stop = t.onUpdate(() => r.update(t.last.selected)), r.update(t.last.selected), r;
123
+ }
124
+ update(e) {
125
+ let t = /* @__PURE__ */ new Map();
126
+ for (let n of e) {
127
+ let e = /* @__PURE__ */ new Set();
128
+ for (let t of n.contents) for (let n of g(t)) e.add(n);
129
+ for (let n of e) t.set(n, (t.get(n) ?? 0) + 1);
130
+ }
131
+ let n = [...t].sort((e, t) => t[1] - e[1] || (e[0] < t[0] ? -1 : +(e[0] > t[0]))).map(([e, t]) => ({
132
+ text: e,
133
+ collapsible: !1,
134
+ count: t
135
+ })), r = JSON.stringify(n.map((e) => [e.text, e.count]));
136
+ return r !== this.key && (this.key = r, this.list = [...this.service, ...n], this.element && (this.element.textContent = this.text()), !0);
137
+ }
138
+ text(e = " | ", t = !1) {
139
+ return this.list.filter((e) => !t || !e.collapsible).map((e) => e.text).join(e);
140
+ }
141
+ html(e = " | ") {
142
+ return this.list.map((e) => e.html ?? f(e.text)).join(e);
143
+ }
144
+ dispose() {
145
+ this.stop?.(), this.stop = void 0;
146
+ }
147
+ [Symbol.dispose]() {
148
+ this.dispose();
149
+ }
150
+ };
151
+ //#endregion
152
+ export { _ as TileCredits, g as contentCopyright, o as hostedTileset, u as htmlText, c as ionAsset };
@@ -0,0 +1,4 @@
1
+ //#region ../shared/json.js
2
+ var e = /"(?:__proto__|constructor|prototype)"|\\u/, t = (e, t) => e === "__proto__" || e === "constructor" || e === "prototype" ? void 0 : t, n = (n) => e.test(n) ? JSON.parse(n, t) : JSON.parse(n);
3
+ //#endregion
4
+ export { n as t };
@@ -0,0 +1,89 @@
1
+ //#region src/matrix.ts
2
+ function e() {
3
+ let e = /* @__PURE__ */ new Float64Array(16);
4
+ return e[0] = e[5] = e[10] = e[15] = 1, e;
5
+ }
6
+ function t(e) {
7
+ return Float64Array.from({ length: 16 }, (t, n) => e[n]);
8
+ }
9
+ function n(e, t, n = /* @__PURE__ */ new Float64Array(16)) {
10
+ let r = /* @__PURE__ */ new Float64Array(16);
11
+ for (let n = 0; n < 4; n++) for (let i = 0; i < 4; i++) r[n * 4 + i] = e[i] * t[n * 4] + e[4 + i] * t[n * 4 + 1] + e[8 + i] * t[n * 4 + 2] + e[12 + i] * t[n * 4 + 3];
12
+ return n.set(r), n;
13
+ }
14
+ function r(e, t = /* @__PURE__ */ new Float64Array(16)) {
15
+ let [n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _] = Array.from(e), v = n * s - r * o, y = n * c - i * o, b = n * l - a * o, x = r * c - i * s, S = r * l - a * s, C = i * l - a * c, w = u * h - d * m, T = u * g - f * m, E = u * _ - p * m, D = d * g - f * h, O = d * _ - p * h, k = f * _ - p * g, A = v * k - y * O + b * D + x * E - S * T + C * w;
16
+ if (!A || !Number.isFinite(A)) throw RangeError("Singular transform; give every tile an invertible transform");
17
+ let j = 1 / A;
18
+ return t[0] = (s * k - c * O + l * D) * j, t[1] = (i * O - r * k - a * D) * j, t[2] = (h * C - g * S + _ * x) * j, t[3] = (f * S - d * C - p * x) * j, t[4] = (c * E - o * k - l * T) * j, t[5] = (n * k - i * E + a * T) * j, t[6] = (g * b - m * C - _ * y) * j, t[7] = (u * C - f * b + p * y) * j, t[8] = (o * O - s * E + l * w) * j, t[9] = (r * E - n * O - a * w) * j, t[10] = (m * S - h * b + _ * v) * j, t[11] = (d * b - u * S - p * v) * j, t[12] = (s * T - o * D - c * w) * j, t[13] = (n * D - r * T + i * w) * j, t[14] = (h * y - m * x - g * v) * j, t[15] = (u * x - d * y + f * v) * j, t;
19
+ }
20
+ function i(e, t) {
21
+ let n = t[0], r = t[1], i = t[2];
22
+ return [
23
+ e[0] * n + e[4] * r + e[8] * i + e[12],
24
+ e[1] * n + e[5] * r + e[9] * i + e[13],
25
+ e[2] * n + e[6] * r + e[10] * i + e[14]
26
+ ];
27
+ }
28
+ function a(e, t) {
29
+ let n = t[0], r = t[1], i = t[2];
30
+ return [
31
+ e[0] * n + e[4] * r + e[8] * i,
32
+ e[1] * n + e[5] * r + e[9] * i,
33
+ e[2] * n + e[6] * r + e[10] * i
34
+ ];
35
+ }
36
+ function o(t, n, r) {
37
+ let i = e();
38
+ return i[12] = t, i[13] = n, i[14] = r, i;
39
+ }
40
+ var s = /* @__PURE__ */ Float64Array.of(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1), c = /* @__PURE__ */ Float64Array.of(1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1);
41
+ function l(e) {
42
+ let t = Math.hypot(e[0], e[1], e[2]), n = Math.hypot(e[4], e[5], e[6]), r = Math.hypot(e[8], e[9], e[10]);
43
+ e[0] * (e[5] * e[10] - e[6] * e[9]) - e[4] * (e[1] * e[10] - e[2] * e[9]) + e[8] * (e[1] * e[6] - e[2] * e[5]) < 0 && (t = -t);
44
+ let i = [
45
+ e[0] / t,
46
+ e[1] / t,
47
+ e[2] / t,
48
+ e[4] / n,
49
+ e[5] / n,
50
+ e[6] / n,
51
+ e[8] / r,
52
+ e[9] / r,
53
+ e[10] / r
54
+ ], a = i[0], o = i[4], s = i[8], c = a + o + s, l, u, d, f;
55
+ if (c > 0) {
56
+ let e = Math.sqrt(c + 1) * 2;
57
+ f = e / 4, l = (i[5] - i[7]) / e, u = (i[6] - i[2]) / e, d = (i[1] - i[3]) / e;
58
+ } else if (a > o && a > s) {
59
+ let e = Math.sqrt(1 + a - o - s) * 2;
60
+ f = (i[5] - i[7]) / e, l = e / 4, u = (i[3] + i[1]) / e, d = (i[6] + i[2]) / e;
61
+ } else if (o > s) {
62
+ let e = Math.sqrt(1 + o - a - s) * 2;
63
+ f = (i[6] - i[2]) / e, l = (i[3] + i[1]) / e, u = e / 4, d = (i[7] + i[5]) / e;
64
+ } else {
65
+ let e = Math.sqrt(1 + s - a - o) * 2;
66
+ f = (i[1] - i[3]) / e, l = (i[6] + i[2]) / e, u = (i[7] + i[5]) / e, d = e / 4;
67
+ }
68
+ let p = Math.hypot(l, u, d, f) || 1;
69
+ return {
70
+ translation: [
71
+ e[12],
72
+ e[13],
73
+ e[14]
74
+ ],
75
+ rotation: [
76
+ l / p,
77
+ u / p,
78
+ d / p,
79
+ f / p
80
+ ],
81
+ scale: [
82
+ t,
83
+ n,
84
+ r
85
+ ]
86
+ };
87
+ }
88
+ //#endregion
89
+ export { e as a, a as c, t as i, i as l, c as n, r as o, l as r, n as s, s as t, o as u };
@@ -0,0 +1,32 @@
1
+ /** A column-major 4x4 matrix in float64 (16 numbers, translation in elements 12 to 14). */
2
+ export type TileMatrix = Float64Array;
3
+ /** A new identity matrix. */
4
+ export declare function identity(): TileMatrix;
5
+ /** Copies 16 numbers (a tileset `transform` array) into a new float64 matrix. */
6
+ export declare function fromArray(values: ArrayLike<number>): TileMatrix;
7
+ /** out = a * b (column-major), safe when out aliases a or b. */
8
+ export declare function multiply(a: ArrayLike<number>, b: ArrayLike<number>, out?: TileMatrix): TileMatrix;
9
+ /** Inverse of a general 4x4 matrix; throws RangeError when it is singular. */
10
+ export declare function invert(m: ArrayLike<number>, out?: TileMatrix): TileMatrix;
11
+ /** Transforms the point (x, y, z, 1). */
12
+ export declare function transformPoint(m: ArrayLike<number>, p: ArrayLike<number>): [number, number, number];
13
+ /** Transforms the direction (x, y, z, 0). */
14
+ export declare function transformDirection(m: ArrayLike<number>, p: ArrayLike<number>): [number, number, number];
15
+ /** A translation matrix. */
16
+ export declare function translation(x: number, y: number, z: number): TileMatrix;
17
+ /**
18
+ * glTF is y-up and 3D Tiles is z-up: tile content in glTF is rotated +90 degrees about x before the tile transform
19
+ * (3D Tiles 1.1, "glTF transforms"). Maps (x, y, z) to (x, -z, y).
20
+ */
21
+ export declare const Y_UP_TO_Z_UP: TileMatrix;
22
+ /** The inverse of `Y_UP_TO_Z_UP`: z-up tileset coordinates to the engine's y-up world. Maps (x, y, z) to (x, z, -y). */
23
+ export declare const Z_UP_TO_Y_UP: TileMatrix;
24
+ /**
25
+ * Splits an affine matrix without shear into translation, rotation quaternion [x, y, z, w] and scale. A mirrored
26
+ * matrix (negative determinant) puts the reflection in the x scale.
27
+ */
28
+ export declare function decompose(m: ArrayLike<number>): {
29
+ translation: [number, number, number];
30
+ rotation: [number, number, number, number];
31
+ scale: [number, number, number];
32
+ };
@@ -0,0 +1,44 @@
1
+ /** The parts of a gltf/pbr model (`PBRModel`) the count reads; all optional, so any model fits. */
2
+ export interface MeasurableModel {
3
+ readonly primitives?: readonly MeasurablePrimitive[];
4
+ readonly pointsAndLines?: readonly MeasurablePrimitive[];
5
+ readonly asset?: {
6
+ readonly doc?: {
7
+ readonly textures?: readonly (TextureJSON | undefined)[];
8
+ };
9
+ };
10
+ image?(index: number): unknown;
11
+ }
12
+ interface MeasurablePrimitive {
13
+ readonly buffers?: {
14
+ readonly vertex: {
15
+ readonly size: number;
16
+ };
17
+ readonly index: {
18
+ readonly size: number;
19
+ };
20
+ };
21
+ readonly vertices?: ArrayBufferView;
22
+ readonly indices?: ArrayBufferView;
23
+ readonly uvs?: ArrayBufferView;
24
+ readonly material?: {
25
+ readonly maps?: readonly ({
26
+ readonly index: number;
27
+ } | null | undefined)[];
28
+ };
29
+ }
30
+ interface TextureJSON {
31
+ source?: number;
32
+ extensions?: Record<string, {
33
+ source?: number;
34
+ } | undefined>;
35
+ }
36
+ /** Bytes of an rgba8 texture of `width` x `height` with `levels` mip levels (all of them when omitted). */
37
+ export declare function textureBytes(width: number, height: number, levels?: number): number;
38
+ /**
39
+ * GPU bytes a gltf/pbr model of a tile takes: its unique vertex, index and uv arrays plus each texture its materials
40
+ * bind once. A model with no `primitives` (a custom `loadModel`) returns `undefined`, and the renderer counts it by
41
+ * its file size.
42
+ */
43
+ export declare function modelGpuBytes(model: MeasurableModel): number | undefined;
44
+ export {};
@@ -0,0 +1,147 @@
1
+ import { type PointsContent } from './formats.js';
2
+ /** A metadata component type. */
3
+ export type MetadataComponentType = 'INT8' | 'UINT8' | 'INT16' | 'UINT16' | 'INT32' | 'UINT32' | 'INT64' | 'UINT64' | 'FLOAT32' | 'FLOAT64';
4
+ /** A metadata property type. */
5
+ export type MetadataType = 'SCALAR' | 'VEC2' | 'VEC3' | 'VEC4' | 'MAT2' | 'MAT3' | 'MAT4' | 'STRING' | 'BOOLEAN' | 'ENUM';
6
+ /** A class property of a metadata schema. */
7
+ export interface ClassPropertyJSON {
8
+ type: MetadataType;
9
+ componentType?: MetadataComponentType;
10
+ enumType?: string;
11
+ array?: boolean;
12
+ count?: number;
13
+ normalized?: boolean;
14
+ offset?: unknown;
15
+ scale?: unknown;
16
+ noData?: unknown;
17
+ default?: unknown;
18
+ required?: boolean;
19
+ semantic?: string;
20
+ name?: string;
21
+ description?: string;
22
+ }
23
+ /** A metadata schema (`EXT_structural_metadata.schema`). */
24
+ export interface StructuralSchemaJSON {
25
+ id?: string;
26
+ classes?: Record<string, {
27
+ name?: string;
28
+ properties?: Record<string, ClassPropertyJSON>;
29
+ }>;
30
+ enums?: Record<string, {
31
+ valueType?: MetadataComponentType;
32
+ values: {
33
+ name: string;
34
+ value: number;
35
+ }[];
36
+ }>;
37
+ }
38
+ /** A property table as stored in glTF. */
39
+ export interface PropertyTableJSON {
40
+ name?: string;
41
+ class: string;
42
+ count: number;
43
+ properties?: Record<string, {
44
+ values: number;
45
+ arrayOffsets?: number;
46
+ stringOffsets?: number;
47
+ arrayOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64';
48
+ stringOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64';
49
+ offset?: unknown;
50
+ scale?: unknown;
51
+ }>;
52
+ }
53
+ /** A buffer view's bytes, checked against the buffer. */
54
+ type Views = (index: number, what: string) => Uint8Array;
55
+ /** One EXT_structural_metadata property table: `count` rows of a schema class. */
56
+ export declare class PropertyTable {
57
+ readonly json: PropertyTableJSON;
58
+ readonly schema: StructuralSchemaJSON;
59
+ /** Property names of the class, in schema order (those without a column read as their `default`). */
60
+ readonly names: readonly string[];
61
+ private readonly columns;
62
+ constructor(json: PropertyTableJSON, schema: StructuralSchemaJSON, views: Views);
63
+ get name(): string | undefined;
64
+ get class(): string;
65
+ /** Number of rows (features). */
66
+ get count(): number;
67
+ /** One feature's value of a property: undefined for a row out of range or a property the class lacks. */
68
+ get(row: number, name: string): unknown;
69
+ /** Every property of one feature as an object. */
70
+ row(row: number): Record<string, unknown>;
71
+ }
72
+ /** One feature ID set of a primitive (`EXT_mesh_features.featureIds[i]`). */
73
+ export interface FeatureIdSet {
74
+ readonly featureCount: number;
75
+ readonly nullFeatureId?: number;
76
+ readonly label?: string;
77
+ /** The `_FEATURE_ID_n` vertex attribute, when the IDs are per vertex. */
78
+ readonly attribute?: number;
79
+ /** The feature ID texture, when the IDs are in a texture (read the texture yourself; see the README). */
80
+ readonly texture?: {
81
+ index: number;
82
+ texCoord?: number;
83
+ channels?: number[];
84
+ extensions?: {
85
+ KHR_texture_transform?: {
86
+ offset?: number[];
87
+ scale?: number[];
88
+ rotation?: number;
89
+ texCoord?: number;
90
+ };
91
+ };
92
+ };
93
+ /** The property table these IDs index. */
94
+ readonly propertyTable?: PropertyTable;
95
+ /** One ID per vertex (attribute or implicit sets; undefined for a texture set). */
96
+ readonly ids?: Uint32Array;
97
+ }
98
+ /** Metadata of one glTF: its schema, property tables and the feature ID sets of each mesh primitive. */
99
+ export interface StructuralMetadata {
100
+ readonly schema?: StructuralSchemaJSON;
101
+ readonly propertyTables: readonly PropertyTable[];
102
+ /** `primitives[mesh][primitive]` lists that primitive's feature ID sets (empty when it has none). */
103
+ readonly primitives: readonly (readonly (readonly FeatureIdSet[])[])[];
104
+ /**
105
+ * The feature a vertex belongs to and its properties: the `set`-th feature ID set of the primitive, or undefined
106
+ * when the vertex has the null feature ID, no ID or the set has no property table.
107
+ */
108
+ feature(mesh: number, primitive: number, vertex: number, set?: number): {
109
+ id: number;
110
+ table?: PropertyTable;
111
+ properties?: Record<string, unknown>;
112
+ } | undefined;
113
+ }
114
+ /** Options of {@link readStructuralMetadata}. */
115
+ export interface StructuralMetadataOptions {
116
+ /** Original packed scalar attribute bytes, including decoded or sparse accessors. */
117
+ accessor?: (index: number) => Uint8Array;
118
+ /** Bytes of an external buffer (`buffers[i].uri` that is not a data URI). Default: such buffers are missing. */
119
+ buffer?: (index: number, uri: string) => Uint8Array | undefined;
120
+ }
121
+ /**
122
+ * Reads the EXT_structural_metadata property tables and EXT_mesh_features feature IDs of a glTF: a GLB, glTF JSON
123
+ * bytes (data URIs and `options.buffer` for buffers) or a tile's glTF / b3dm content bytes (`content.gltf`).
124
+ * Throws a TypeError or RangeError naming the problem for a malformed table; never reads out of bounds.
125
+ */
126
+ export declare function readStructuralMetadata(gltf: Uint8Array, options?: StructuralMetadataOptions): StructuralMetadata;
127
+ /** A Draco point cloud decoder: `DracoPointsDecoder` from `@margoengine/decoders/draco-points` is one. */
128
+ export interface DracoPointsSource {
129
+ decode(data: Uint8Array, options?: {
130
+ signal?: AbortSignal;
131
+ }): Promise<{
132
+ pointCount: number;
133
+ attributes: {
134
+ uniqueId: number;
135
+ array: ArrayLike<number>;
136
+ itemSize: number;
137
+ normalized: boolean;
138
+ }[];
139
+ }>;
140
+ }
141
+ /**
142
+ * Decodes Draco-compressed pnts content (3DTILES_draco_point_compression) into ordinary point content: POSITION, RGBA
143
+ * or RGB, NORMAL and BATCH_ID from the Draco buffer, and the batch table properties the extension names. Content that
144
+ * is not compressed comes back as it is. Pass it to the renderer as `TilesRenderer.load(engine, url, { dracoPoints })`.
145
+ */
146
+ export declare function dracoPoints(content: PointsContent, signal?: AbortSignal, decoder?: DracoPointsSource): Promise<PointsContent>;
147
+ export {};