@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/index.js ADDED
@@ -0,0 +1,849 @@
1
+ // @margo/core-built 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./wgs84-C5btsGGY.js";
5
+ import { a as s, c, i as l, l as u, n as d, o as f, r as p, s as m, t as h } from "./formats-NNuOXg-1.js";
6
+ import { a as g, c as _, i as v, l as y, n as b, o as x, r as S, s as C, t as w, u as T } from "./matrix-DcI5oFrD.js";
7
+ import { a as E, i as D, n as ee, r as O, t as k } from "./bounds-CgKJT3Pg.js";
8
+ import { n as te, t as A } from "./scene-scope-DufD_3B6.js";
9
+ import { MargoError as j } from "@margoengine/math/errors";
10
+ //#region src/implicit.ts
11
+ function M(e, t, n) {
12
+ let r = 0, i = 1, a = n === void 0 ? 2 : 3;
13
+ for (let o = 0; o < 26 && (e >> o & 1 && (r += i), i *= 2, t >> o & 1 && (r += i), i *= 2, a === 3 && (n >> o & 1 && (r += i), i *= 2), e >> o !== 0 || t >> o !== 0 || n !== void 0 && n >> o !== 0); o++);
14
+ return r;
15
+ }
16
+ function N(e, t, n, r) {
17
+ let i = r === void 0 ? 4 : 8;
18
+ return (i ** e - 1) / (i - 1) + M(t, n, r);
19
+ }
20
+ function P(e, t) {
21
+ return {
22
+ get: (n) => e && n >= 0 && n < t,
23
+ count: e ? t : 0
24
+ };
25
+ }
26
+ function F(e, t) {
27
+ if (e.byteLength * 8 < t) throw RangeError(`Subtree availability has ${e.byteLength} bytes for ${t} bits; the subtree file is truncated`);
28
+ let n = 0;
29
+ for (let r = 0; r < t; r++) e[r >> 3] >> (r & 7) & 1 && n++;
30
+ return {
31
+ get: (n) => n >= 0 && n < t && (e[n >> 3] >> (n & 7) & 1) == 1,
32
+ count: n
33
+ };
34
+ }
35
+ var ne = /* @__PURE__ */ new TextDecoder();
36
+ async function I(e, t, n, r = () => Promise.reject(/* @__PURE__ */ TypeError("External subtree buffers need a fetch"))) {
37
+ let i, a, o = new DataView(e.buffer, e.byteOffset, e.byteLength);
38
+ if (e.byteLength >= 4 && o.getUint32(0, !0) === 1952609651) {
39
+ if (e.byteLength < 24) throw RangeError("Subtree file too short for its 24-byte header; the file is truncated");
40
+ let t = o.getUint32(4, !0), n = Number(o.getBigUint64(8, !0)), r = Number(o.getBigUint64(16, !0));
41
+ if (t !== 1) throw TypeError(`Unsupported subtree version ${t}; only version 1 is defined`);
42
+ if (24 + n + r > e.byteLength) throw RangeError(`Subtree chunks (${n} + ${r} bytes) run past the file; it is truncated`);
43
+ i = L(e.subarray(24, 24 + n)), a = e.subarray(24 + n, 24 + n + r);
44
+ } else i = L(e);
45
+ let s = [];
46
+ for (let [e, t] of (i.buffers ?? []).entries()) {
47
+ if (!t || typeof t.byteLength != "number") throw TypeError(`Subtree buffer ${e} needs a byteLength`);
48
+ let n = t.uri === void 0 ? a : await r(t.uri);
49
+ if (!n) throw TypeError(`Subtree buffer ${e} has no uri and the file has no binary chunk; the subtree is corrupt`);
50
+ if (n.byteLength < t.byteLength) throw RangeError(`Subtree buffer ${e} is shorter than its byteLength; it is truncated`);
51
+ s.push(n);
52
+ }
53
+ let c = t === "QUADTREE" ? 4 : 8, l = (c ** n - 1) / (c - 1), u = c ** n, d = (e, t, n) => {
54
+ if (!e || typeof e != "object") throw TypeError(`Subtree has no ${n}; the subtree is corrupt`);
55
+ if (e.constant !== void 0) return P(e.constant === 1, t);
56
+ let r = e.bitstream ?? e.bufferView, a = r === void 0 ? void 0 : i.bufferViews?.[r];
57
+ if (!a) throw TypeError(`Subtree ${n} names a missing bufferView; the subtree is corrupt`);
58
+ let o = s[a.buffer];
59
+ if (!o || a.byteOffset < 0 || a.byteOffset + a.byteLength > o.byteLength) throw RangeError(`Subtree ${n} bufferView runs past its buffer; the subtree is truncated or corrupt`);
60
+ return F(o.subarray(a.byteOffset, a.byteOffset + a.byteLength), t);
61
+ }, f = i.contentAvailability === void 0 ? [] : Array.isArray(i.contentAvailability) ? i.contentAvailability : [i.contentAvailability];
62
+ return {
63
+ tiles: d(i.tileAvailability, l, "tileAvailability"),
64
+ contents: f.map((e, t) => d(e, l, `contentAvailability[${t}]`)),
65
+ childSubtrees: d(i.childSubtreeAvailability, u, "childSubtreeAvailability"),
66
+ metadata: i.subtreeMetadata
67
+ };
68
+ }
69
+ function L(e) {
70
+ try {
71
+ let t = JSON.parse(ne.decode(e).replace(/[\0\s]+$/, ""));
72
+ if (t && typeof t == "object") return t;
73
+ } catch {}
74
+ throw TypeError("Invalid subtree JSON; the subtree file is corrupt");
75
+ }
76
+ function R(e, t, n, r, i = 0) {
77
+ return e.replace(/\{(level|x|y|z)\}/g, (e, a) => String(a === "level" ? t : a === "x" ? n : a === "y" ? r : i));
78
+ }
79
+ function z(e, t, n, r, i, a = 0) {
80
+ if (e.split) return e.split(t, n, r, i, a);
81
+ let o = 2 ** n;
82
+ if (e.region) {
83
+ let [n, s, c, l, u, d] = e.region, f = (c - n) / o, p = (l - s) / o, m = t === "OCTREE" ? (d - u) / o : d - u, h = t === "OCTREE" ? u + m * a : u;
84
+ return D([
85
+ n + f * r,
86
+ s + p * i,
87
+ n + f * (r + 1),
88
+ s + p * (i + 1),
89
+ h,
90
+ h + m
91
+ ]);
92
+ }
93
+ let s = e.center, c = e.halfAxes, l = (2 * r + 1) / o - 1, u = (2 * i + 1) / o - 1, d = t === "OCTREE" ? (2 * a + 1) / o - 1 : 0, f = t === "OCTREE" ? 1 / o : 1;
94
+ return new k([
95
+ 0,
96
+ 1,
97
+ 2
98
+ ].map((e) => s[e] + c[e] * l + c[3 + e] * u + c[6 + e] * d), [
99
+ c[0] / o,
100
+ c[1] / o,
101
+ c[2] / o,
102
+ c[3] / o,
103
+ c[4] / o,
104
+ c[5] / o,
105
+ c[6] * f,
106
+ c[7] * f,
107
+ c[8] * f
108
+ ]);
109
+ }
110
+ //#endregion
111
+ //#region src/queue.ts
112
+ var B = class {
113
+ constructor({ maxConcurrent: e = 6, signal: t } = {}) {
114
+ if (this.entries = /* @__PURE__ */ new Map(), this.frame = 0, this.active = 0, !Number.isInteger(e) || e < 1) throw RangeError("Invalid maxConcurrent; pass a whole number of 1 or more");
115
+ this.maxConcurrent = e, this.signal = t;
116
+ }
117
+ get queued() {
118
+ return this.entries.size - this.active;
119
+ }
120
+ get inFlight() {
121
+ return this.active;
122
+ }
123
+ begin() {
124
+ this.frame++;
125
+ }
126
+ want(e, t, n) {
127
+ let r = this.entries.get(e);
128
+ r ? (r.priority = t, r.frame = this.frame) : this.entries.set(e, {
129
+ key: e,
130
+ priority: t,
131
+ frame: this.frame,
132
+ run: n
133
+ });
134
+ }
135
+ has(e) {
136
+ return this.entries.has(e);
137
+ }
138
+ flush() {
139
+ let e = [];
140
+ for (let t of this.entries.values()) t.frame === this.frame ? t.controller || e.push(t) : (this.entries.delete(t.key), t.controller && t.controller.abort(new DOMException("Tile no longer needed", "AbortError")));
141
+ if (!this.signal?.aborted) {
142
+ e.sort((e, t) => e.priority[0] - t.priority[0] || e.priority[1] - t.priority[1]);
143
+ for (let t of e) {
144
+ if (this.active >= this.maxConcurrent) break;
145
+ this.start(t);
146
+ }
147
+ }
148
+ }
149
+ clear() {
150
+ for (let e of this.entries.values()) e.controller?.abort(new DOMException("Queue cleared", "AbortError"));
151
+ this.entries.clear();
152
+ }
153
+ start(e) {
154
+ let t = new AbortController();
155
+ e.controller = t, this.active++;
156
+ let n = this.signal, r = () => t.abort(n?.reason);
157
+ n?.addEventListener("abort", r, { once: !0 });
158
+ let i;
159
+ try {
160
+ i = e.run(t.signal);
161
+ } catch (e) {
162
+ i = Promise.reject(e);
163
+ }
164
+ i.catch(() => void 0).finally(() => {
165
+ n?.removeEventListener("abort", r), this.active--, this.entries.get(e.key) === e && this.entries.delete(e.key);
166
+ });
167
+ }
168
+ }, V = class {
169
+ constructor(e) {
170
+ this.children = [], this.state = "unloaded", this.external = !1, this.contents = [], this.distance = Infinity, this.screenSpaceError = 0, this.lastUsed = -1, this.expanded = !1, this.id = e.id, this.parent = e.parent, this.depth = e.parent ? e.parent.depth + 1 : 0, this.geometricError = e.geometricError, this.refine = e.refine, this.transform = e.transform, this.bounds = e.bounds, this.contentBounds = e.contentBounds, this.viewerRequestVolume = e.viewerRequestVolume, this.contentUrls = e.contentUrls, this.metadata = e.metadata, this.contentMetadata = e.contentMetadata ?? [], this.contentGroups = e.contentGroups ?? [], this.implicit = e.implicit, this.context = e.context;
171
+ }
172
+ get hasContent() {
173
+ return this.contentUrls.length > 0 && !this.external;
174
+ }
175
+ }, re = 536870912;
176
+ function H(e) {
177
+ if (URL.canParse(e)) return e;
178
+ let t = globalThis.location?.href;
179
+ return typeof t == "string" && URL.canParse(e, t) ? new URL(e, t).href : e;
180
+ }
181
+ function U(e, t) {
182
+ try {
183
+ return new URL(e, t).href;
184
+ } catch {
185
+ throw TypeError(`Cannot resolve tile URI ${JSON.stringify(e)} against ${t}; give absolute URLs or a tileset URL`);
186
+ }
187
+ }
188
+ function W(e, t) {
189
+ if (typeof e != "number" || !Number.isFinite(e) || e < 0) throw TypeError(`Invalid ${t}; it must be a finite number of 0 or more`);
190
+ return e;
191
+ }
192
+ var G = class e {
193
+ static async load(t, n = {}) {
194
+ let r = H(String(t)), i = n.fetch ?? globalThis.fetch?.bind(globalThis);
195
+ if (!i) throw new j("unsupported", "No fetch available; pass options.fetch");
196
+ let a = await q(i, r, n.signal), o;
197
+ return a && typeof a == "object" && typeof a.schemaUri == "string" && (o = await q(i, U(a.schemaUri, r), n.signal)), new e(a, r, n, o);
198
+ }
199
+ static from(t, n, r = {}) {
200
+ return new e(t, H(String(n)), r);
201
+ }
202
+ constructor(e, t, n, r) {
203
+ if (this.bytes = 0, this.overBudget = !1, this.disposed = !1, this.controller = new AbortController(), this.listeners = /* @__PURE__ */ new Map(), this.ready = /* @__PURE__ */ new Set(), this.failed = /* @__PURE__ */ new Set(), this.failedSubtrees = /* @__PURE__ */ new Map(), this.frame = 0, this.shown = [], this.pending = 0, this.wasIdle = !1, this.url = t, this.volumes = n.boundingVolumes ?? [], this.json = Y(e, t, this.volumes), this.fetcher = n.fetch ?? globalThis.fetch?.bind(globalThis), !this.fetcher) throw new j("unsupported", "No fetch available; pass options.fetch");
204
+ this.maximumScreenSpaceError = W(n.maximumScreenSpaceError ?? 16, "maximumScreenSpaceError"), this.memoryBudget = W(n.memoryBudget ?? re, "memoryBudget"), this.skipLevelOfDetail = n.skipLevelOfDetail ?? !1, this.skipScreenSpaceErrorFactor = W(n.skipScreenSpaceErrorFactor ?? 16, "skipScreenSpaceErrorFactor"), this.factory = n.content, n.signal && (n.signal.aborted ? this.controller.abort(n.signal.reason) : n.signal.addEventListener("abort", () => this.controller.abort(n.signal.reason), { once: !0 })), this.queue = new B({
205
+ maxConcurrent: n.maxConcurrentRequests ?? 6,
206
+ signal: this.controller.signal
207
+ }), this.schema = r ?? this.json.schema, this.metadata = this.json.metadata, this.groups = this.json.groups ?? [], this.root = this.buildTile(this.json.root, null, g(), t, "root", "REPLACE");
208
+ }
209
+ on(e, t) {
210
+ let n = this.listeners.get(e);
211
+ return n || this.listeners.set(e, n = /* @__PURE__ */ new Set()), n.add(t), () => n.delete(t);
212
+ }
213
+ emit(e, t) {
214
+ for (let n of this.listeners.get(e) ?? []) n(t);
215
+ }
216
+ get progress() {
217
+ return {
218
+ queued: this.queue.queued,
219
+ loading: this.queue.inFlight,
220
+ ready: this.ready.size,
221
+ failed: this.failed.size,
222
+ selected: this.shown.length,
223
+ bytes: this.bytes,
224
+ memoryBudget: this.memoryBudget
225
+ };
226
+ }
227
+ *tiles() {
228
+ let e = [this.root];
229
+ for (; e.length;) {
230
+ let t = e.pop();
231
+ yield t;
232
+ for (let n = t.children.length - 1; n >= 0; n--) e.push(t.children[n]);
233
+ }
234
+ }
235
+ properties(e) {
236
+ if (!e) return {};
237
+ let t = {}, n = this.schema?.classes?.[e.class]?.properties ?? {};
238
+ for (let [e, r] of Object.entries(n)) r.default !== void 0 && (t[e] = r.default);
239
+ return Object.assign(t, e.properties);
240
+ }
241
+ static screenSpaceError(e, t, n) {
242
+ if (n.orthographicHeight !== void 0) return e * n.screenHeight / n.orthographicHeight;
243
+ if (t <= 0) return e > 0 ? Infinity : 0;
244
+ let r = (n.fov ?? 60) * Math.PI / 180;
245
+ return e * n.screenHeight / (2 * t * Math.tan(r / 2));
246
+ }
247
+ update(e) {
248
+ if (this.disposed) throw new j("disposed", "Tileset is disposed; load a new Tileset");
249
+ if (!(e.screenHeight > 0)) throw RangeError("Invalid view.screenHeight; pass the drawing-buffer height in pixels");
250
+ if (e.planes !== void 0 && e.planes.length < 24) throw RangeError("Invalid view.planes; pass 24 numbers (6 planes)");
251
+ this.bytes = [...this.ready].reduce((e, t) => e + (t.renderable?.bytes ?? 0), 0), this.frame++, this.queue.begin(), this.pending = 0;
252
+ let t = [];
253
+ this.visit(this.root, e, t);
254
+ let n = new Set(t);
255
+ for (let e of this.shown) !n.has(e) && e.renderable && (e.renderable.visible = !1);
256
+ for (let e of t) e.renderable && (e.renderable.visible = !0);
257
+ this.shown = t, this.emit("selection", { selected: t }), this.evict(), this.overBudget = this.bytes > this.memoryBudget, this.controller.signal.aborted || this.queue.flush();
258
+ let r = this.progress;
259
+ this.emit("progress", r);
260
+ let i = this.pending === 0 && r.queued === 0 && r.loading === 0;
261
+ return i && !this.wasIdle && this.emit("idle", r), this.wasIdle = i, {
262
+ selected: t,
263
+ pending: this.pending
264
+ };
265
+ }
266
+ retry() {
267
+ for (let e of this.failed) e.state = "unloaded", e.error = void 0;
268
+ this.failed.clear(), this.failedSubtrees.clear();
269
+ }
270
+ dispose() {
271
+ if (!this.disposed) {
272
+ this.disposed = !0, this.controller.abort(new DOMException("Tileset disposed", "AbortError")), this.queue.clear();
273
+ for (let e of [...this.ready]) this.unload(e);
274
+ this.listeners.clear();
275
+ }
276
+ }
277
+ [Symbol.dispose]() {
278
+ this.dispose();
279
+ }
280
+ visit(t, n, r) {
281
+ let i = t.bounds.distanceTo(n.position);
282
+ if (t.distance = i, n.planes && !t.bounds.intersectsFrustum(n.planes) || t.viewerRequestVolume && !t.viewerRequestVolume.contains(n.position)) return !0;
283
+ let a = e.screenSpaceError(t.geometricError, i, n);
284
+ if (t.screenSpaceError = a, t.context && !this.expand(t)) return !1;
285
+ if (t.contentUrls.length && !t.external && t.state !== "ready" && this.mightBeTileset(t)) return this.want(t, [0, t.depth]), !1;
286
+ let o = t.hasContent, s = !o || !t.contentBounds || !n.planes || t.contentBounds.intersectsFrustum(n.planes);
287
+ if (!(t.children.length > 0 && (a > this.maximumScreenSpaceError || !o || t.external))) return !o || !s || (this.want(t, [1, i]), t.state === "ready" && (this.draw(t, r), !0));
288
+ if (t.refine === "ADD") {
289
+ o && s && (this.want(t, [0, t.depth]), t.state === "ready" && this.draw(t, r));
290
+ for (let e of t.children) this.visit(e, n, r);
291
+ return !o || !s || t.state === "ready";
292
+ }
293
+ let c = r.length, l = o && s && (!this.skipLevelOfDetail || a <= this.maximumScreenSpaceError * this.skipScreenSpaceErrorFactor), u = !0;
294
+ for (let e of t.children) u = this.visit(e, n, r) && u;
295
+ return u ? !0 : (l && this.want(t, [0, t.depth]), o && s && t.state === "ready" ? (r.length = c, this.draw(t, r), !0) : !1);
296
+ }
297
+ mightBeTileset(e) {
298
+ return e.contentUrls.length === 1 && /\.json($|[?#])/i.test(e.contentUrls[0]);
299
+ }
300
+ draw(e, t) {
301
+ e.lastUsed = this.frame, t.push(e);
302
+ }
303
+ want(e, t) {
304
+ e.lastUsed = this.frame, e.state !== "ready" && e.state !== "failed" && (this.overBudget && t[0] === 1 || (this.pending++, this.queue.want(e.id, t, (t) => this.loadTile(e, t))));
305
+ }
306
+ fetchBytes(e, t) {
307
+ return K(this.fetcher, e, t);
308
+ }
309
+ async loadTile(e, t) {
310
+ e.state = "loading";
311
+ let n = [];
312
+ try {
313
+ let r = [];
314
+ for (let n of e.contentUrls) {
315
+ let i = await K(this.fetcher, n, t);
316
+ if (p(i) === "json") {
317
+ let t = J(i, n);
318
+ if (t && typeof t == "object" && "root" in t) {
319
+ if (e.contentUrls.length !== 1) throw TypeError("A tile with several contents cannot hold an external tileset; give it one content");
320
+ this.attachExternal(e, t, n);
321
+ return;
322
+ }
323
+ }
324
+ r.push(f(i));
325
+ }
326
+ t.throwIfAborted();
327
+ for (let i of r) this.factory && (n.push(await this.factory(i, e, t)), t.throwIfAborted());
328
+ if (this.disposed) throw new DOMException("Tileset disposed", "AbortError");
329
+ e.contents = r, e.renderable = this.factory ? ie(n) : ae(r), e.renderable.visible = !1, e.state = "ready", this.ready.add(e), this.bytes += e.renderable.bytes, this.emit("tileload", { tile: e });
330
+ } catch (r) {
331
+ for (let e of n) e.dispose();
332
+ if (t.aborted || r?.name === "AbortError") {
333
+ e.state = "unloaded";
334
+ return;
335
+ }
336
+ this.fail(e, r);
337
+ }
338
+ }
339
+ fail(e, t) {
340
+ let n = t instanceof Error ? t.message : String(t), r = t instanceof j && t.code === "unsupported" ? t : new j("failed", `Tile ${e.id} failed to load (${n}); fix the file or the server, then call tileset.retry()`);
341
+ e.state = "failed", e.error = r, this.failed.add(e), this.emit("error", {
342
+ tile: e,
343
+ error: r
344
+ });
345
+ }
346
+ attachExternal(e, t, n) {
347
+ let r = Y(t, n, this.volumes);
348
+ e.children = [this.buildTile(r.root, e, e.transform, n, `${n}#root`, e.refine)], e.external = !0, e.state = "ready";
349
+ }
350
+ unload(e) {
351
+ e.renderable && (this.bytes -= e.renderable.bytes, e.renderable.dispose(), e.renderable = void 0, e.contents = [], e.state = "unloaded", this.ready.delete(e), this.emit("tileunload", { tile: e }));
352
+ }
353
+ evict() {
354
+ if (this.bytes <= this.memoryBudget) return;
355
+ let e = [...this.ready].filter((e) => e.lastUsed !== this.frame && !e.renderable?.visible);
356
+ e.sort((e, t) => e.lastUsed - t.lastUsed || t.depth - e.depth);
357
+ for (let t of e) {
358
+ if (this.bytes <= this.memoryBudget) break;
359
+ this.unload(t);
360
+ }
361
+ }
362
+ buildTile(e, t, n, r, i, a) {
363
+ if (!e || typeof e != "object") throw TypeError(`Invalid tile at ${i}; it must be an object`);
364
+ let o = W(e.geometricError, `${i}.geometricError`);
365
+ if (e.refine !== void 0 && e.refine !== "ADD" && e.refine !== "REPLACE") throw TypeError(`Invalid ${i}.refine ${JSON.stringify(e.refine)}; use "ADD" or "REPLACE"`);
366
+ let s = e.refine ?? a;
367
+ if (e.transform !== void 0 && (!Array.isArray(e.transform) || e.transform.length !== 16 || !e.transform.every(Number.isFinite))) throw TypeError(`Invalid ${i}.transform; give 16 finite numbers (column-major)`);
368
+ let c = e.transform ? C(n, v(e.transform)) : Float64Array.from(n), l = e.contents ?? (e.content ? [e.content] : []), u = l.map((e, t) => {
369
+ let n = e?.uri ?? e?.url;
370
+ if (typeof n != "string") throw TypeError(`Invalid ${i}.content${l.length > 1 ? `s[${t}]` : ""}; give it a uri`);
371
+ return n;
372
+ }), d = O(e.boundingVolume, c, this.volumes);
373
+ if (e.implicitTiling) {
374
+ let n = e.implicitTiling;
375
+ if (n.subdivisionScheme !== "QUADTREE" && n.subdivisionScheme !== "OCTREE") throw TypeError(`Invalid ${i}.implicitTiling.subdivisionScheme; use "QUADTREE" or "OCTREE"`);
376
+ let a = n.availableLevels ?? n.maximumLevel + 1;
377
+ if (!Number.isInteger(n.subtreeLevels) || n.subtreeLevels < 1 || !Number.isInteger(a) || a < 1) throw TypeError(`Invalid ${i}.implicitTiling; subtreeLevels and availableLevels must be whole numbers of 1 or more`);
378
+ if (typeof n.subtrees?.uri != "string") throw TypeError(`Invalid ${i}.implicitTiling.subtrees; give a uri template`);
379
+ let l = {
380
+ scheme: n.subdivisionScheme,
381
+ subtreeLevels: n.subtreeLevels,
382
+ availableLevels: a,
383
+ subtreeTemplate: n.subtrees.uri,
384
+ contentTemplates: u,
385
+ base: r,
386
+ rootBounds: d,
387
+ rootError: o,
388
+ refine: s,
389
+ transform: c,
390
+ subtrees: /* @__PURE__ */ new Map()
391
+ };
392
+ return new V({
393
+ id: `${r}#${i}/0/0/0/0`,
394
+ parent: t,
395
+ geometricError: o,
396
+ refine: s,
397
+ transform: c,
398
+ bounds: d,
399
+ contentUrls: [],
400
+ metadata: e.metadata,
401
+ implicit: {
402
+ level: 0,
403
+ x: 0,
404
+ y: 0,
405
+ z: 0
406
+ },
407
+ context: l
408
+ });
409
+ }
410
+ let f = new V({
411
+ id: u.length ? U(u[0], r) : `${r}#${i}`,
412
+ parent: t,
413
+ geometricError: o,
414
+ refine: s,
415
+ transform: c,
416
+ bounds: d,
417
+ contentBounds: l[0]?.boundingVolume ? O(l[0].boundingVolume, c, this.volumes) : void 0,
418
+ viewerRequestVolume: e.viewerRequestVolume ? O(e.viewerRequestVolume, c, this.volumes) : void 0,
419
+ contentUrls: u.map((e) => U(e, r)),
420
+ metadata: e.metadata,
421
+ contentMetadata: l.map((e) => e.metadata),
422
+ contentGroups: l.map((e) => e.group)
423
+ });
424
+ if (e.children !== void 0 && !Array.isArray(e.children)) throw TypeError(`Invalid ${i}.children; it must be an array`);
425
+ return f.children = (e.children ?? []).map((e, t) => this.buildTile(e, f, c, r, `${i}.children[${t}]`, s)), f;
426
+ }
427
+ expand(e) {
428
+ if (e.expanded) return !0;
429
+ let t = e.context, { level: n, x: r, y: i, z: a } = e.implicit, o = t.scheme === "OCTREE", s = n % t.subtreeLevels, c = n - s, l = r >> s, u = i >> s, d = a >> s, f = `${c}/${l}/${u}/${d}`, p = t.subtrees.get(f);
430
+ if (!p) {
431
+ if (this.failedSubtrees.get(f)) return !1;
432
+ let n = U(R(t.subtreeTemplate, c, l, u, d), t.base);
433
+ return this.pending++, this.queue.want(`subtree:${n}`, [0, e.depth - .5], async (r) => {
434
+ try {
435
+ let e = await K(this.fetcher, n, r);
436
+ t.subtrees.set(f, await I(e, t.scheme, t.subtreeLevels, (e) => K(this.fetcher, U(e, n), r)));
437
+ } catch (t) {
438
+ if (r.aborted || t?.name === "AbortError") return;
439
+ let i = new j("failed", `Subtree ${n} failed to load (${t instanceof Error ? t.message : String(t)}); fix the file or the server, then call tileset.retry()`);
440
+ this.failedSubtrees.set(f, i), this.emit("error", {
441
+ tile: e,
442
+ error: i
443
+ });
444
+ }
445
+ }), !1;
446
+ }
447
+ let m = r - (l << s), h = i - (u << s), g = a - (d << s), _ = N(s, m, h, o ? g : void 0), v = t.contentTemplates.filter((e, t) => p.contents[t]?.get(_)).map((e) => U(R(e, n, r, i, a), t.base));
448
+ e.contentUrls = v, v.length && (e.id = v[0]);
449
+ let y = [];
450
+ if (n + 1 < t.availableLevels) for (let c = 0; c < (o ? 8 : 4); c++) {
451
+ let f = 2 * r + (c & 1), _ = 2 * i + (c >> 1 & 1), v = o ? 2 * a + (c >> 2 & 1) : 0;
452
+ (s + 1 < t.subtreeLevels ? p.tiles.get(N(s + 1, 2 * m + (c & 1), 2 * h + (c >> 1 & 1), o ? 2 * g + (c >> 2 & 1) : void 0)) : p.childSubtrees.get(M(f - (l << s + 1), _ - (u << s + 1), o ? v - (d << s + 1) : void 0))) && y.push(new V({
453
+ id: `${t.base}#implicit/${n + 1}/${f}/${_}/${v}`,
454
+ parent: e,
455
+ geometricError: t.rootError / 2 ** (n + 1),
456
+ refine: t.refine,
457
+ transform: t.transform,
458
+ bounds: z(t.rootBounds, t.scheme, n + 1, f, _, v),
459
+ contentUrls: [],
460
+ implicit: {
461
+ level: n + 1,
462
+ x: f,
463
+ y: _,
464
+ z: v
465
+ },
466
+ context: t
467
+ }));
468
+ }
469
+ return e.children = y, e.expanded = !0, !0;
470
+ }
471
+ };
472
+ function ie(e) {
473
+ if (e.length === 1) return e[0];
474
+ let t = !1;
475
+ return {
476
+ get bytes() {
477
+ return e.reduce((e, t) => e + t.bytes, 0);
478
+ },
479
+ get visible() {
480
+ return t;
481
+ },
482
+ set visible(n) {
483
+ t = n;
484
+ for (let t of e) t.visible = n;
485
+ },
486
+ dispose: () => {
487
+ for (let t of e) t.dispose();
488
+ }
489
+ };
490
+ }
491
+ function ae(e) {
492
+ return {
493
+ bytes: e.reduce((e, t) => e + t.byteLength, 0),
494
+ visible: !1,
495
+ dispose: () => void 0
496
+ };
497
+ }
498
+ async function K(e, t, n) {
499
+ n?.throwIfAborted();
500
+ let r = await e(t, { signal: n });
501
+ if (!r.ok) throw new j("failed", `GET ${t} answered ${r.status}; check the URL and the server`);
502
+ return new Uint8Array(await r.arrayBuffer());
503
+ }
504
+ async function q(e, t, n) {
505
+ return J(await K(e, t, n), t);
506
+ }
507
+ var oe = /* @__PURE__ */ new TextDecoder();
508
+ function J(e, t) {
509
+ try {
510
+ return JSON.parse(oe.decode(e));
511
+ } catch (e) {
512
+ throw TypeError(`Invalid JSON at ${t} (${e.message}); fix the tileset file`);
513
+ }
514
+ }
515
+ function Y(e, t, n) {
516
+ if (!e || typeof e != "object") throw TypeError(`Invalid tileset ${t}; it must be a JSON object`);
517
+ let r = e;
518
+ if (!r.asset || typeof r.asset.version != "string") throw TypeError(`Invalid tileset ${t}: asset.version is missing; add "asset": {"version": "1.1"}`);
519
+ if (!r.root || typeof r.root != "object") throw TypeError(`Invalid tileset ${t}: root is missing; add a root tile`);
520
+ W(r.geometricError, `${t} geometricError`);
521
+ let i = /* @__PURE__ */ new Set([
522
+ "3DTILES_implicit_tiling",
523
+ "3DTILES_metadata",
524
+ "3DTILES_content_gltf",
525
+ "3DTILES_multiple_contents",
526
+ ...n.map((e) => e.name)
527
+ ]);
528
+ for (let e of r.extensionsRequired ?? []) if (!i.has(e)) throw new j("unsupported", e === "3DTILES_bounding_volume_S2" ? `Tileset ${t} requires S2 bounding volumes: import { s2 } from '@margoengine/tiles/s2' and pass { boundingVolumes: [s2] }` : `Tileset ${t} requires extension ${e}, which this loader does not implement; use a tileset without it`);
529
+ return r;
530
+ }
531
+ //#endregion
532
+ //#region src/memory.ts
533
+ function X(e, t, n) {
534
+ let r = n ?? Math.floor(Math.log2(Math.max(e, t, 1))) + 1, i = 0;
535
+ for (let n = 0; n < r; n++) i += Math.max(1, e >> n) * Math.max(1, t >> n) * 4;
536
+ return i;
537
+ }
538
+ function se(e) {
539
+ if (!e || typeof e != "object") return 0;
540
+ let t = "ktx2" in e ? e.ktx2 : "mipmaps" in e ? e : void 0;
541
+ if (t) return t.mipmaps.reduce((e, t) => e + t.byteLength, 0);
542
+ if ("streamed" in e) return 0;
543
+ let { width: n, height: r } = e;
544
+ return typeof n == "number" && typeof r == "number" ? X(n, r) : 0;
545
+ }
546
+ function Z(e) {
547
+ if (!Array.isArray(e.primitives)) return;
548
+ let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
549
+ for (let i of [...e.primitives, ...e.pointsAndLines ?? []]) {
550
+ if (i.buffers) t.add(i.buffers.vertex), t.add(i.buffers.index), i.uvs && n.add(i.uvs);
551
+ else for (let e of [
552
+ i.vertices,
553
+ i.indices,
554
+ i.uvs
555
+ ]) e && n.add(e);
556
+ for (let e of i.material?.maps ?? []) e && r.add(e.index);
557
+ }
558
+ let i = [...t].reduce((e, t) => e + t.size, 0);
559
+ for (let e of n) i += e.byteLength;
560
+ let a = e.asset?.doc?.textures ?? [], o = /* @__PURE__ */ new Set();
561
+ for (let t of r) {
562
+ let n = a[t];
563
+ if (!n) continue;
564
+ let r = [
565
+ "KHR_texture_basisu",
566
+ "EXT_texture_webp",
567
+ "EXT_texture_avif"
568
+ ].map((e) => n.extensions?.[e]?.source).find((t) => t !== void 0 && Q(e, t) !== void 0) ?? n.source;
569
+ r !== void 0 && o.add(r);
570
+ }
571
+ for (let t of o) i += se(Q(e, t));
572
+ return i;
573
+ }
574
+ function Q(e, t) {
575
+ let n = e.images;
576
+ return Array.isArray(n) ? n[t] : e.image?.(t);
577
+ }
578
+ //#endregion
579
+ //#region src/renderer.ts
580
+ function $(e) {
581
+ let t = e.gltf, n = t;
582
+ if (t.byteLength >= 20 && t[0] === 103 && t[1] === 108 && t[2] === 84 && t[3] === 70) {
583
+ let e = new DataView(t.buffer, t.byteOffset + 12, 4).getUint32(0, !0);
584
+ n = t.subarray(20, Math.min(t.byteLength, 20 + e));
585
+ }
586
+ return new TextDecoder().decode(n).includes("\"KHR_gaussian_splatting\"");
587
+ }
588
+ var ce = 0, le = class n {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
589
+ static async load(e, t, r = {}) {
590
+ let i, a = A(e), o = await G.load(t, {
591
+ ...r,
592
+ content: (e, t, n) => i.createContent(e, t, n)
593
+ });
594
+ return i = new n(o, r), a.run(() => e.use(i)), i;
595
+ }
596
+ static attach(e, t, r = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
597
+ return n.load(e, t, r);
598
+ }
599
+ constructor(t, n) {
600
+ if (this.last = {
601
+ selected: [],
602
+ pending: 0
603
+ }, this.enabled = !0, this.disposed = !1, this.listeners = /* @__PURE__ */ new Set(), this.planes = /* @__PURE__ */ new Float64Array(24), this.name = `tiles-${++ce}`, this.tileset = t, this.origin = n.origin, this.pointBudget = n.pointBudget ?? 2e6, this.budget = n.budget ?? "gpu", this.budget !== "gpu" && this.budget !== "content") throw TypeError(`Invalid budget ${JSON.stringify(this.budget)}; use 'gpu' or 'content'`);
604
+ this.i3dm = n.i3dm, this.dracoPoints = n.dracoPoints, this.splats = n.splats, this.decorate = n.decorate, this.loadModel = n.loadModel ?? (async (e, t, n) => {
605
+ let r = A(e), { parseGLTFAsync: i } = await import("@margoengine/gltf/pbr");
606
+ return r.run(() => i(e, t, { signal: n }));
607
+ });
608
+ let r = n.frame ?? "enu";
609
+ if (typeof r == "string" && r !== "enu" && r !== "local") throw TypeError(`Invalid frame ${JSON.stringify(r)}; use 'enu', 'local' or a 4x4 matrix`);
610
+ if (typeof r != "string") {
611
+ if (r.length !== 16) throw TypeError("Invalid frame matrix; give 16 numbers, column-major");
612
+ this.frame = Float64Array.from(r);
613
+ } else {
614
+ let n = t.root.bounds.center;
615
+ this.frame = r === "enu" && Math.hypot(n[0], n[1], n[2]) > 1e5 ? C(b, x(e(n[0], n[1], n[2]))) : Float64Array.from(b);
616
+ }
617
+ this.inverseFrame = x(this.frame);
618
+ }
619
+ setup(e) {
620
+ if (this.engine && this.engine !== e) throw new j("attached", "TilesRenderer is attached to another engine; load one renderer per engine");
621
+ this.engine = e;
622
+ }
623
+ toWorld(e) {
624
+ return y(this.frame, e);
625
+ }
626
+ toTileset(e) {
627
+ return y(this.inverseFrame, e);
628
+ }
629
+ cartographicToWorld(e, n, r = 0) {
630
+ return this.toWorld(t(e * Math.PI / 180, n * Math.PI / 180, r));
631
+ }
632
+ onPreUpdate() {
633
+ this.enabled && this.engine && !this.tileset.disposed && this.update();
634
+ }
635
+ update() {
636
+ let e = this.engine;
637
+ if (!e) throw new j("state", "TilesRenderer is not attached; create it with TilesRenderer.load(engine, url)");
638
+ let t = e.camera, r = this.origin?.origin ?? [
639
+ 0,
640
+ 0,
641
+ 0
642
+ ], i = this.origin?.cameraPosition ?? t.position, a = this.frame, o = this.planes;
643
+ for (let e = 0; e < 6; e++) {
644
+ let n = t.planes[e * 4], i = t.planes[e * 4 + 1], s = t.planes[e * 4 + 2], c = t.planes[e * 4 + 3] - (n * r[0] + i * r[1] + s * r[2]);
645
+ for (let t = 0; t < 3; t++) o[e * 4 + t] = n * a[t * 4] + i * a[t * 4 + 1] + s * a[t * 4 + 2];
646
+ o[e * 4 + 3] = n * a[12] + i * a[13] + s * a[14] + c;
647
+ }
648
+ let s = n.orthographicHeight(t.matrix);
649
+ this.last = this.tileset.update({
650
+ position: this.toTileset(i),
651
+ planes: o,
652
+ screenHeight: e.canvas.height || 1,
653
+ fov: t.fov,
654
+ ...s === void 0 ? {} : { orthographicHeight: s / Math.hypot(a[0], a[1], a[2]) }
655
+ });
656
+ for (let e of this.listeners) e();
657
+ return this.last;
658
+ }
659
+ static orthographicHeight(e) {
660
+ if (!e) return;
661
+ let t = e[15], n = Math.max(Math.abs(e[3]), Math.abs(e[7]), Math.abs(e[11]));
662
+ if (!(Math.abs(t) > 0) || n > 1e-9 * Math.abs(t)) return;
663
+ let r = Math.hypot(e[1], e[5], e[9]);
664
+ return r > 0 ? 2 * Math.abs(t) / r : void 0;
665
+ }
666
+ contentMatrix(e, t, n = !0) {
667
+ let r = C(this.frame, e.transform);
668
+ return t && (r = C(r, T(t[0], t[1], t[2]))), n ? C(r, w) : r;
669
+ }
670
+ place(e, t) {
671
+ let { translation: n, rotation: r, scale: i } = S(t);
672
+ e.setQuaternion(r), e.setScale(i), this.origin ? this.origin.place(e, n) : e.setPosition(n);
673
+ }
674
+ async createContent(e, t, n) {
675
+ let r = this.engine;
676
+ if (!r) throw new j("state", "TilesRenderer is not attached; create it with TilesRenderer.load(engine, url)");
677
+ switch (e.type) {
678
+ case "glb":
679
+ case "gltf":
680
+ case "b3dm": {
681
+ if ($(e)) {
682
+ if (!this.splats) throw new j("unsupported", "Gaussian splat tiles (KHR_gaussian_splatting) need their drawer: import { splats } from '@margoengine/tiles/splats' and pass { splats } to TilesRenderer.load");
683
+ let i = this.splats, a = this.host ??= this.contentHost(r), o = e;
684
+ return this.own(() => i(a, o, t, n));
685
+ }
686
+ let i = e.gltf, a = await this.own(() => this.loadModel(r, i, n));
687
+ n.aborted && (a.dispose(), n.throwIfAborted()), this.place(a.root, this.contentMatrix(t, e.type === "b3dm" ? e.rtcCenter : void 0)), a.root.visible = !1;
688
+ let o;
689
+ try {
690
+ o = await this.decorate?.({
691
+ kind: "model",
692
+ model: a,
693
+ content: e,
694
+ tile: t,
695
+ signal: n,
696
+ fetch: (e, t) => this.tileset.fetchBytes(e, t)
697
+ }), n.throwIfAborted();
698
+ } catch (e) {
699
+ throw o?.dispose(), this.origin?.forget(a.root), a.dispose(), e;
700
+ }
701
+ let s = this;
702
+ return {
703
+ model: a,
704
+ get bytes() {
705
+ return s.measure(a, e.byteLength) + (o?.bytes ?? 0);
706
+ },
707
+ get visible() {
708
+ return a.root.visible;
709
+ },
710
+ set visible(e) {
711
+ a.root.visible = e;
712
+ },
713
+ dispose: () => {
714
+ o?.dispose(), this.origin?.forget(a.root), a.dispose();
715
+ }
716
+ };
717
+ }
718
+ case "pnts": {
719
+ if (e.draco) {
720
+ if (!this.dracoPoints) throw new j("unsupported", "Draco-compressed pnts needs its decoder: import { dracoPoints } from '@margoengine/tiles/metadata' and pass { dracoPoints } to TilesRenderer.load");
721
+ e = await this.dracoPoints(e, n), n.throwIfAborted();
722
+ }
723
+ let { host: i, PointCloud: a } = await (this.points ??= this.loadPoints(r)), o = this.own(() => r.createMesh());
724
+ this.place(o, this.contentMatrix(t, e.rtcCenter, !1));
725
+ let s = e.constantColor, c = e.colors ?? (s ? Uint8Array.from({ length: e.positions.length / 3 * 4 }, (e, t) => s[t % 4]) : void 0), l = i.add(new a({
726
+ positions: e.positions,
727
+ colors: c,
728
+ colorComponents: c ? 4 : void 0,
729
+ material: { size: 2 }
730
+ }));
731
+ l.attach(o), l.visible = !1;
732
+ let u;
733
+ try {
734
+ u = await this.decorate?.({
735
+ kind: "points",
736
+ cloud: l,
737
+ content: e,
738
+ tile: t,
739
+ signal: n,
740
+ fetch: (e, t) => this.tileset.fetchBytes(e, t)
741
+ }), n.throwIfAborted();
742
+ } catch (e) {
743
+ throw u?.dispose(), i.remove(l), this.origin?.forget(o), o.dispose(), e;
744
+ }
745
+ return {
746
+ bytes: (this.budget === "gpu" ? e.positions.length / 3 * (12 + (c ? 4 : 0)) : e.byteLength) + (u?.bytes ?? 0),
747
+ get visible() {
748
+ return l.visible;
749
+ },
750
+ set visible(e) {
751
+ l.visible = e;
752
+ },
753
+ dispose: () => {
754
+ u?.dispose(), i.remove(l), this.origin?.forget(o), o.dispose();
755
+ }
756
+ };
757
+ }
758
+ case "cmpt": {
759
+ let r = [];
760
+ try {
761
+ for (let i of e.tiles) r.push(await this.createContent(i, t, n));
762
+ } catch (e) {
763
+ for (let e of r) e.dispose();
764
+ throw e;
765
+ }
766
+ let i = !1;
767
+ return {
768
+ get bytes() {
769
+ return r.reduce((e, t) => e + t.bytes, 0);
770
+ },
771
+ get visible() {
772
+ return i;
773
+ },
774
+ set visible(e) {
775
+ i = e;
776
+ for (let t of r) t.visible = e;
777
+ },
778
+ dispose: () => {
779
+ for (let e of r) e.dispose();
780
+ }
781
+ };
782
+ }
783
+ case "i3dm":
784
+ if (!this.i3dm) throw new j("unsupported", "i3dm instanced content needs its drawer: import { i3dm } from '@margoengine/tiles/i3dm' and pass { i3dm } to TilesRenderer.load");
785
+ let i = this.i3dm, a = this.host ??= this.contentHost(r), o = e;
786
+ return this.own(() => i(a, o, t, n));
787
+ }
788
+ }
789
+ onUpdate(e) {
790
+ return this.listeners.add(e), () => this.listeners.delete(e);
791
+ }
792
+ measure(e, t) {
793
+ return this.budget === "gpu" ? Z(e) ?? t : t;
794
+ }
795
+ own(e) {
796
+ let t = this.engine;
797
+ return te(t, typeof t?.sceneOf == "function" ? t.sceneOf(this) : void 0).run(e);
798
+ }
799
+ contentHost(e) {
800
+ return {
801
+ decorate: (e) => this.decorate?.(e),
802
+ budget: this.budget,
803
+ measure: (e, t) => this.measure(e, t),
804
+ engine: e,
805
+ url: this.tileset.url,
806
+ loadModel: (t, n) => this.own(() => this.loadModel(e, t, n)),
807
+ place: (e, t) => this.place(e, t),
808
+ forget: (e) => this.origin?.forget(e),
809
+ contentMatrix: (e, t, n) => this.contentMatrix(e, t, n),
810
+ fetch: (e, t) => this.tileset.fetchBytes(e, t),
811
+ onUpdate: (e) => this.onUpdate(e),
812
+ offset: () => {
813
+ let e = this.origin?.origin;
814
+ return e ? [
815
+ e[0],
816
+ e[1],
817
+ e[2]
818
+ ] : [
819
+ 0,
820
+ 0,
821
+ 0
822
+ ];
823
+ }
824
+ };
825
+ }
826
+ async loadPoints(e) {
827
+ let t = await import("@margoengine/points"), n = new t.PointsPlugin({
828
+ name: `${this.name}-points`,
829
+ pointBudget: this.pointBudget
830
+ }), r = e.sceneOf(this);
831
+ return r ? r.use(n) : e.use(n), this.pointsHost = n, {
832
+ host: n,
833
+ PointCloud: t.PointCloud
834
+ };
835
+ }
836
+ dispose() {
837
+ if (this.disposed) return;
838
+ this.disposed = !0, this.tileset.dispose();
839
+ let e = this.engine;
840
+ if (!e) return;
841
+ let t = this.pointsHost;
842
+ this.pointsHost = void 0, t && e.sceneOf(t)?.removePlugin(t.name), e.sceneOf(this)?.removePlugin(this.name), this.engine = void 0;
843
+ }
844
+ [Symbol.dispose]() {
845
+ this.dispose();
846
+ }
847
+ };
848
+ //#endregion
849
+ export { h as BatchTable, d as FeatureTable, B as FetchQueue, k as TileBounds, le as TilesRenderer, G as Tileset, V as TilesetTile, o as WGS84_A, n as WGS84_B, i as WGS84_F, w as Y_UP_TO_Z_UP, b as Z_UP_TO_Y_UP, N as availabilityIndex, ee as boxBounds, t as cartographicToEcef, p as contentMagic, O as createBounds, S as decompose, e as eastNorthUpToEcef, r as ecefToCartographic, R as expandTemplate, v as fromArray, a as geodeticNormal, $ as holdsSplats, g as identity, z as implicitBounds, x as invert, Z as modelGpuBytes, M as mortonIndex, C as multiply, l as parseB3dm, s as parseCmpt, f as parseContent, m as parseI3dm, c as parsePnts, I as parseSubtree, u as readComponents, D as regionBounds, E as sphereBounds, X as textureBytes, _ as transformDirection, y as transformPoint, T as translation };