@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,320 @@
|
|
|
1
|
+
import { a as e, n as t, o as n, r, t as i } from "./data-uri-DbGLVHq5.js";
|
|
2
|
+
import { t as a } from "./json-BQoirgm5.js";
|
|
3
|
+
import { t as o } from "./errors-D5_2oB8I.js";
|
|
4
|
+
import { PropertyTable as s } from "./metadata.js";
|
|
5
|
+
import { MargoError as c } from "@margoengine/math/errors";
|
|
6
|
+
//#region ../shared/cleanup.js
|
|
7
|
+
var l = class {
|
|
8
|
+
constructor(...e) {
|
|
9
|
+
this.failed = e.length > 0, this.error = e[0];
|
|
10
|
+
}
|
|
11
|
+
run(e) {
|
|
12
|
+
try {
|
|
13
|
+
e();
|
|
14
|
+
} catch (e) {
|
|
15
|
+
this.failed || (this.error = e), this.failed = !0;
|
|
16
|
+
}
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
finish() {
|
|
20
|
+
if (this.failed) throw this.error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region ../shared/loading.js
|
|
25
|
+
async function u(e, { maxBytes: t, signal: n, label: r = "Asset", output: i = null, expected: a = 0 }) {
|
|
26
|
+
if (!Number.isSafeInteger(t) || t < 0 || i !== null && (!(i instanceof Uint8Array) || i.length !== t)) throw RangeError("Invalid asset byte budget; pass maxBytes as an integer");
|
|
27
|
+
if (n?.throwIfAborted(), !e) throw TypeError(`Empty ${r} response; check the URL`);
|
|
28
|
+
let o = e.getReader(), s = [], c = 0, u = i, d = new l(), f = (e) => {
|
|
29
|
+
try {
|
|
30
|
+
Promise.resolve(o.cancel(e)).catch(() => {});
|
|
31
|
+
} catch {}
|
|
32
|
+
}, p = () => f(n.reason);
|
|
33
|
+
n?.addEventListener("abort", p, { once: !0 });
|
|
34
|
+
try {
|
|
35
|
+
for (!i && Number.isSafeInteger(a) && a > 0 && a <= t && (u = new Uint8Array(a));;) {
|
|
36
|
+
n?.throwIfAborted();
|
|
37
|
+
let { done: e, value: i } = await o.read();
|
|
38
|
+
if (n?.throwIfAborted(), e) break;
|
|
39
|
+
if (!(i instanceof Uint8Array)) throw TypeError(`${r} stream requires byte chunks`);
|
|
40
|
+
if (i.byteLength > t - c) throw RangeError(`${r} byte budget exceeded; raise maxBytes`);
|
|
41
|
+
u && i.length <= u.length - c ? u.set(i, c) : (u && s.push(u.subarray(0, c)), u = null, s.push(i.length < i.buffer.byteLength || !(i.buffer instanceof ArrayBuffer) ? i.slice() : i)), c += i.byteLength;
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
f(e), d = new l(e);
|
|
45
|
+
}
|
|
46
|
+
if (d.run(() => n?.removeEventListener("abort", p)).run(() => o.releaseLock()).finish(), i) return i.subarray(0, c);
|
|
47
|
+
if (u) return c < u.length ? u.slice(0, c) : u;
|
|
48
|
+
let m = new Uint8Array(c), h = 0;
|
|
49
|
+
for (let e of s) m.set(e, h), h += e.length;
|
|
50
|
+
return m;
|
|
51
|
+
}
|
|
52
|
+
async function d(e, t) {
|
|
53
|
+
try {
|
|
54
|
+
if (t.signal?.throwIfAborted(), !e.ok) throw o("failed", `${t.label ?? "Asset"} request failed: HTTP ${e.status}; check the URL and that the server serves it`);
|
|
55
|
+
let n = Number(e.headers.get("content-length"));
|
|
56
|
+
if (Number.isFinite(n) && n > t.maxBytes) throw RangeError(`${t.label ?? "Asset"} byte budget exceeded; raise maxBytes`);
|
|
57
|
+
let r = e.headers.get("content-encoding");
|
|
58
|
+
(!r || r === "identity") && (t = {
|
|
59
|
+
...t,
|
|
60
|
+
expected: n
|
|
61
|
+
});
|
|
62
|
+
} catch (t) {
|
|
63
|
+
try {
|
|
64
|
+
Promise.resolve(e.body?.cancel(t)).catch(() => {});
|
|
65
|
+
} catch {}
|
|
66
|
+
throw t;
|
|
67
|
+
}
|
|
68
|
+
return u(e.body, t);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/properties.ts
|
|
72
|
+
var f = {
|
|
73
|
+
INT8: 1,
|
|
74
|
+
UINT8: 1,
|
|
75
|
+
INT16: 2,
|
|
76
|
+
UINT16: 2,
|
|
77
|
+
INT32: 4,
|
|
78
|
+
UINT32: 4,
|
|
79
|
+
INT64: 8,
|
|
80
|
+
UINT64: 8,
|
|
81
|
+
FLOAT32: 4,
|
|
82
|
+
FLOAT64: 8
|
|
83
|
+
}, p = {
|
|
84
|
+
SCALAR: 1,
|
|
85
|
+
VEC2: 2,
|
|
86
|
+
VEC3: 3,
|
|
87
|
+
VEC4: 4,
|
|
88
|
+
MAT2: 4,
|
|
89
|
+
MAT3: 9,
|
|
90
|
+
MAT4: 16,
|
|
91
|
+
ENUM: 1,
|
|
92
|
+
BOOLEAN: 1
|
|
93
|
+
}, m = {
|
|
94
|
+
5120: "INT8",
|
|
95
|
+
5121: "UINT8",
|
|
96
|
+
5122: "INT16",
|
|
97
|
+
5123: "UINT16",
|
|
98
|
+
5125: "UINT32",
|
|
99
|
+
5126: "FLOAT32"
|
|
100
|
+
};
|
|
101
|
+
function h(e) {
|
|
102
|
+
if (typeof e == "number" && !Number.isFinite(e)) throw RangeError("Metadata contains a non-finite value; re-export finite property values");
|
|
103
|
+
return Array.isArray(e) && e.forEach(h), e;
|
|
104
|
+
}
|
|
105
|
+
function g(e, t) {
|
|
106
|
+
let n = Object.hasOwn(e.classes ?? {}, t) ? e.classes[t] : void 0;
|
|
107
|
+
if (!n) throw TypeError(`Metadata class ${t} is missing; include it in the schema`);
|
|
108
|
+
return n.properties ?? {};
|
|
109
|
+
}
|
|
110
|
+
function _(e, t) {
|
|
111
|
+
let n = e.type === "ENUM" ? t.enums?.[e.enumType ?? ""]?.valueType ?? "UINT16" : e.type === "BOOLEAN" ? "UINT8" : e.componentType, r = (p[e.type] ?? 0) * (e.array ? e.count ?? 0 : 1);
|
|
112
|
+
if (!r || !f[n] || e.array && (!Number.isInteger(e.count) || e.count < 1)) throw TypeError("Property attributes/textures need fixed-size numeric, enum or boolean values; use a property table for strings or variable arrays");
|
|
113
|
+
return {
|
|
114
|
+
type: n,
|
|
115
|
+
count: r,
|
|
116
|
+
bytes: e.type === "BOOLEAN" ? Math.ceil(r / 8) : r * f[n]
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function v(e, t) {
|
|
120
|
+
for (let [n, r] of Object.entries(g(e, t.class))) if (r.required && !Object.hasOwn(t.properties ?? {}, n)) throw TypeError(`Required property ${n} is missing; add its attribute or texture binding`);
|
|
121
|
+
for (let n of Object.keys(t.properties ?? {})) if (!Object.hasOwn(g(e, t.class), n)) throw TypeError(`Property ${n} is not in class ${t.class}; correct the binding or schema`);
|
|
122
|
+
}
|
|
123
|
+
var y = class {
|
|
124
|
+
constructor(e) {
|
|
125
|
+
this.table = e, this.names = e.names;
|
|
126
|
+
}
|
|
127
|
+
get count() {
|
|
128
|
+
return this.table.count;
|
|
129
|
+
}
|
|
130
|
+
get class() {
|
|
131
|
+
return this.table.class;
|
|
132
|
+
}
|
|
133
|
+
get(e, t) {
|
|
134
|
+
return h(this.table.get(e, t));
|
|
135
|
+
}
|
|
136
|
+
row(e) {
|
|
137
|
+
return Object.fromEntries(this.names.map((t) => [t, this.get(e, t)]));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function b(e, t) {
|
|
141
|
+
if (t === 33071) return Math.max(0, Math.min(1, e));
|
|
142
|
+
let n = Math.floor(e), r = e - n;
|
|
143
|
+
return t === 33648 && Math.abs(n % 2) === 1 ? 1 - r : r;
|
|
144
|
+
}
|
|
145
|
+
function x(e, t, n, r) {
|
|
146
|
+
if (t.length !== 2 || !t.every(Number.isFinite)) throw TypeError("Metadata UV needs two finite coordinates; pass the requested texture coordinate set");
|
|
147
|
+
let i = Math.min(e.width - 1, Math.floor(b(t[0], n) * e.width)), a = Math.min(e.height - 1, Math.floor(b(t[1], r) * e.height));
|
|
148
|
+
return Uint8Array.from(e.data.subarray((a * e.width + i) * 4, (a * e.width + i) * 4 + 4));
|
|
149
|
+
}
|
|
150
|
+
var S = class {
|
|
151
|
+
constructor(e, t, n, r) {
|
|
152
|
+
this.json = e, this.schema = t, this.asset = n, this.decoders = /* @__PURE__ */ new Map(), v(t, e);
|
|
153
|
+
let i = g(t, e.class);
|
|
154
|
+
this.names = Object.keys(i);
|
|
155
|
+
for (let [n, a] of Object.entries(e.properties ?? {})) {
|
|
156
|
+
let o = i[n], l = _(o, t), u = a.channels ?? [0], d = r.image?.(a.index);
|
|
157
|
+
if (!d) throw new c("state", "Property texture image is missing; pass decoded images or use loadPropertyMetadata");
|
|
158
|
+
if (!(d.data instanceof Uint8Array || d.data instanceof Uint8ClampedArray)) throw TypeError("Metadata image samples must be RGBA8 bytes; provide Uint8Array or Uint8ClampedArray data");
|
|
159
|
+
if (!Number.isInteger(d.width) || d.width < 1 || !Number.isInteger(d.height) || d.height < 1 || d.data.length !== d.width * d.height * 4) throw RangeError("Metadata image needs width*height*4 RGBA8 bytes; provide the complete decoded image");
|
|
160
|
+
if (u.length !== l.bytes || u.length > 4 || new Set(u).size !== u.length || u.some((e) => !Number.isInteger(e) || e < 0 || e > 3)) throw RangeError(`Property ${n} needs ${l.bytes} distinct RGBA8 channels; correct the texture channel mapping`);
|
|
161
|
+
let f = new Uint8Array(l.bytes), p = new s({
|
|
162
|
+
class: e.class,
|
|
163
|
+
count: 1,
|
|
164
|
+
properties: { [n]: {
|
|
165
|
+
values: 0,
|
|
166
|
+
...a
|
|
167
|
+
} }
|
|
168
|
+
}, t, () => f);
|
|
169
|
+
this.decoders.set(n, {
|
|
170
|
+
table: p,
|
|
171
|
+
bytes: f,
|
|
172
|
+
binding: a,
|
|
173
|
+
image: d
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
get class() {
|
|
178
|
+
return this.json.class;
|
|
179
|
+
}
|
|
180
|
+
get(e, n) {
|
|
181
|
+
let i = this.decoders.get(n);
|
|
182
|
+
if (!i) return g(this.schema, this.class)[n]?.default;
|
|
183
|
+
let { binding: a, image: o, table: s, bytes: c } = i, l = a.extensions?.KHR_texture_transform, u = l?.texCoord ?? a.texCoord ?? 0, d = typeof e == "function" ? e(u) : e;
|
|
184
|
+
if (d.length !== 2 || !d.every(Number.isFinite) || !Number.isInteger(u) || u < 0) throw TypeError("Metadata UV needs two finite coordinates and a non-negative set index; correct its texture coordinates");
|
|
185
|
+
let f = l?.scale ?? [1, 1], p = l?.offset ?? [0, 0], m = l?.rotation ?? 0;
|
|
186
|
+
if (f.length !== 2 || p.length !== 2 || ![
|
|
187
|
+
...f,
|
|
188
|
+
...p,
|
|
189
|
+
m
|
|
190
|
+
].every(Number.isFinite)) throw TypeError("Metadata texture transform needs finite scale/offset/rotation; correct KHR_texture_transform");
|
|
191
|
+
let _ = t(r(f, p, m), d[0], d[1]), v = this.asset.doc.textures?.[a.index];
|
|
192
|
+
if (!v) throw TypeError("Property texture index is missing; add the referenced glTF texture");
|
|
193
|
+
let y = this.asset.doc.samplers?.[v.sampler ?? -1], b = x(o, _, y?.wrapS, y?.wrapT);
|
|
194
|
+
return (a.channels ?? [0]).forEach((e, t) => c[t] = b[e]), h(s.get(0, n));
|
|
195
|
+
}
|
|
196
|
+
row(e) {
|
|
197
|
+
return Object.fromEntries(this.names.map((t) => [t, this.get(e, t)]));
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
function C(t, r = {}) {
|
|
201
|
+
let i = t.doc.extensions?.EXT_structural_metadata, a = r.schema ?? i?.schema;
|
|
202
|
+
if (!a) throw TypeError("Structural metadata schema is missing; provide the external schema or use loadPropertyMetadata");
|
|
203
|
+
let o = (i?.propertyTextures ?? []).map((e) => new S(e, a, t, r)), c = /* @__PURE__ */ new Map(), l = r.maximumDecodedBytes ?? t.maxBytes * 4;
|
|
204
|
+
if (!Number.isSafeInteger(l) || l < 0) throw RangeError("Metadata maximumDecodedBytes must be a non-negative integer; choose a decoded byte limit");
|
|
205
|
+
let u = 0, d = (t.doc.meshes ?? []).map((d) => d.primitives.map((d) => {
|
|
206
|
+
let f = d.extensions?.EXT_structural_metadata;
|
|
207
|
+
return {
|
|
208
|
+
attributes: (f?.propertyAttributes ?? []).map((o) => {
|
|
209
|
+
let f = i?.propertyAttributes?.[o];
|
|
210
|
+
if (!f) throw TypeError("Property attribute set is missing; correct the primitive metadata index");
|
|
211
|
+
v(a, f);
|
|
212
|
+
let p = g(a, f.class), h = [], b = {}, x = d.attributes?.POSITION, S = t.doc.accessors?.[x ?? -1]?.count ?? 0;
|
|
213
|
+
for (let [i, o] of Object.entries(f.properties ?? {})) {
|
|
214
|
+
let s = d.attributes?.[o.attribute], f = p[i], g = _(f, a), v = t.doc.accessors?.[s ?? -1];
|
|
215
|
+
if (s === void 0 || !v || v.count !== S || n[v.type] !== g.count || m[v.componentType] !== g.type) throw TypeError(`Property ${i} accessor must match its class type and vertex count; correct the attribute binding`);
|
|
216
|
+
let y = c.get(s);
|
|
217
|
+
if (y || (y = e(t, s, {
|
|
218
|
+
...r,
|
|
219
|
+
maximumDecodedBytes: l - u
|
|
220
|
+
}), c.set(s, y), u += y.byteLength), f.type === "BOOLEAN") {
|
|
221
|
+
let e = Math.ceil(S * g.count / 8);
|
|
222
|
+
if (e > l - u) throw RangeError("Boolean property attributes exceed the decoded byte limit; raise maximumDecodedBytes");
|
|
223
|
+
let t = new Uint8Array(e);
|
|
224
|
+
u += e, y.forEach((e, n) => {
|
|
225
|
+
if (e !== 0 && e !== 1) throw RangeError("Boolean property attributes must encode 0 or 1; correct the attribute values");
|
|
226
|
+
e && (t[n >> 3] |= 1 << (n & 7));
|
|
227
|
+
}), y = t;
|
|
228
|
+
}
|
|
229
|
+
b[i] = {
|
|
230
|
+
values: h.length,
|
|
231
|
+
offset: o.offset,
|
|
232
|
+
scale: o.scale
|
|
233
|
+
}, h.push(y);
|
|
234
|
+
}
|
|
235
|
+
return new y(new s({
|
|
236
|
+
class: f.class,
|
|
237
|
+
count: S,
|
|
238
|
+
properties: b
|
|
239
|
+
}, a, (e) => h[e]));
|
|
240
|
+
}),
|
|
241
|
+
textures: (f?.propertyTextures ?? []).map((e) => {
|
|
242
|
+
if (!o[e]) throw TypeError("Property texture set is missing; correct the primitive metadata index");
|
|
243
|
+
return o[e];
|
|
244
|
+
})
|
|
245
|
+
};
|
|
246
|
+
}));
|
|
247
|
+
return {
|
|
248
|
+
schema: a,
|
|
249
|
+
propertyTextures: o,
|
|
250
|
+
primitives: d,
|
|
251
|
+
sample(e, n, r, i) {
|
|
252
|
+
let a = i.reduce((e, t) => e + t, 0);
|
|
253
|
+
if (i.length !== 3 || !i.every(Number.isFinite) || i.some((e) => e < 0) || Math.abs(a - 1) > 3 * 2 ** -24) throw RangeError("Metadata hit needs three non-negative barycentric weights summing to one within float32 rounding; use a triangle ray hit");
|
|
254
|
+
let o = t.doc.meshes?.[e]?.primitives[n], s = d[e]?.[n];
|
|
255
|
+
if (!o || !s) return [];
|
|
256
|
+
let c = o.mode ?? 4, l = o.indices === void 0 ? void 0 : t.accessor(o.indices, "SCALAR"), u = l?.length ?? t.doc.accessors?.[o.attributes?.POSITION ?? -1]?.count ?? 0;
|
|
257
|
+
if (![
|
|
258
|
+
4,
|
|
259
|
+
5,
|
|
260
|
+
6
|
|
261
|
+
].includes(c)) throw TypeError("Metadata triangle sampling needs triangle list/strip/fan geometry; query point or line UVs with get");
|
|
262
|
+
let f = c === 4 ? Math.floor(u / 3) : Math.max(0, u - 2);
|
|
263
|
+
if (!Number.isInteger(r) || r < 0 || r >= f) throw RangeError("Metadata triangle index is outside the primitive; use a source triangle index");
|
|
264
|
+
let p = (c === 4 ? [
|
|
265
|
+
r * 3,
|
|
266
|
+
r * 3 + 1,
|
|
267
|
+
r * 3 + 2
|
|
268
|
+
] : c === 5 ? [
|
|
269
|
+
r,
|
|
270
|
+
r + 1 + r % 2,
|
|
271
|
+
r + 2 - r % 2
|
|
272
|
+
] : [
|
|
273
|
+
r + 1,
|
|
274
|
+
r + 2,
|
|
275
|
+
0
|
|
276
|
+
]).map((e) => l ? l[e] : e);
|
|
277
|
+
return s.textures.map((e) => e.row((e) => {
|
|
278
|
+
let n = o.attributes?.[`TEXCOORD_${e}`];
|
|
279
|
+
if (n === void 0) throw TypeError(`Property texture needs TEXCOORD_${e}; add the referenced coordinate attribute`);
|
|
280
|
+
let r = t.accessor(n, "VEC2");
|
|
281
|
+
return [0, 1].map((e) => p.reduce((t, n, o) => t + r[n * 2 + e] * i[o] / a, 0));
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
async function w(e, t = {}) {
|
|
287
|
+
t.signal?.throwIfAborted();
|
|
288
|
+
let n = e.doc.extensions?.EXT_structural_metadata, r = t.baseURL ?? e.baseURL ?? globalThis.location?.href, o = t.fetch ?? globalThis.fetch.bind(globalThis), s = t.maximumBytes ?? 67108864;
|
|
289
|
+
if (!Number.isSafeInteger(s) || s < 1) throw RangeError("Metadata maximumBytes must be a positive integer; choose a resource byte limit");
|
|
290
|
+
let l = async (e) => {
|
|
291
|
+
let n = i(e, s);
|
|
292
|
+
if (n) return n;
|
|
293
|
+
let a = await o(new URL(e, r).href, { signal: t.signal });
|
|
294
|
+
if (!a.ok) throw new c("failed", `Metadata resource answered ${a.status}; check its URL and access`);
|
|
295
|
+
return d(a, {
|
|
296
|
+
signal: t.signal,
|
|
297
|
+
maxBytes: s,
|
|
298
|
+
label: "Structural metadata resource"
|
|
299
|
+
});
|
|
300
|
+
}, u = t.schema ?? n?.schema ?? (n?.schemaUri ? a(new TextDecoder().decode(await l(n.schemaUri))) : void 0), f = /* @__PURE__ */ new Map();
|
|
301
|
+
for (let r of n?.propertyTextures ?? []) for (let n of Object.values(r.properties ?? {})) if (!f.has(n.index)) {
|
|
302
|
+
let r = t.image?.(n.index);
|
|
303
|
+
if (!r) {
|
|
304
|
+
let i = e.doc.textures?.[n.index], a = i?.extensions?.KHR_texture_basisu?.source ?? i?.source, o = e.doc.images?.[a ?? -1];
|
|
305
|
+
if (!o) throw TypeError("Property texture image is missing; correct the glTF image reference");
|
|
306
|
+
let c = o.bufferView === void 0 ? await l(o.uri) : e.view(o.bufferView);
|
|
307
|
+
if (c.byteLength > s) throw RangeError("Metadata image exceeds maximumBytes; reduce the embedded image or raise its byte limit");
|
|
308
|
+
let { decodeImage: u } = await import("@margoengine/decoders/image");
|
|
309
|
+
r = await u(c, { signal: t.signal });
|
|
310
|
+
}
|
|
311
|
+
f.set(n.index, r);
|
|
312
|
+
}
|
|
313
|
+
return t.signal?.throwIfAborted(), C(e, {
|
|
314
|
+
...t,
|
|
315
|
+
schema: u,
|
|
316
|
+
image: (e) => f.get(e)
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
export { y as PropertyAttributes, S as PropertyTextures, w as loadPropertyMetadata, C as readPropertyMetadata };
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Lower sorts first: a group (0 = needed to avoid holes, 1 = refinement), then a distance-like key. */
|
|
2
|
+
export type Priority = readonly [group: number, key: number];
|
|
3
|
+
/** Options of `FetchQueue`. */
|
|
4
|
+
export interface FetchQueueOptions {
|
|
5
|
+
/** Most requests in flight at once. Default 6. */
|
|
6
|
+
maxConcurrent?: number;
|
|
7
|
+
/** Aborts everything when it aborts. */
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Priority fetch queue. `want(key, priority, run)` each frame for every request still needed, then `flush()`: queued
|
|
12
|
+
* requests not wanted this frame are dropped, in-flight ones are aborted, and the best-priority queued ones start up
|
|
13
|
+
* to `maxConcurrent`. `run` receives an AbortSignal and must settle when it aborts.
|
|
14
|
+
*/
|
|
15
|
+
export declare class FetchQueue {
|
|
16
|
+
readonly maxConcurrent: number;
|
|
17
|
+
private readonly entries;
|
|
18
|
+
private frame;
|
|
19
|
+
private active;
|
|
20
|
+
private readonly signal?;
|
|
21
|
+
constructor({ maxConcurrent, signal }?: FetchQueueOptions);
|
|
22
|
+
/** Requests queued and not started. */
|
|
23
|
+
get queued(): number;
|
|
24
|
+
/** Requests in flight. */
|
|
25
|
+
get inFlight(): number;
|
|
26
|
+
/** Starts a new frame of wants. */
|
|
27
|
+
begin(): void;
|
|
28
|
+
/** Marks a request wanted this frame (queues it the first time). */
|
|
29
|
+
want(key: string, priority: Priority, run: (signal: AbortSignal) => Promise<void>): void;
|
|
30
|
+
/** True while a request is queued or in flight. */
|
|
31
|
+
has(key: string): boolean;
|
|
32
|
+
/** Drops or aborts requests not wanted this frame and starts the best queued ones. */
|
|
33
|
+
flush(): void;
|
|
34
|
+
/** Aborts and forgets everything. */
|
|
35
|
+
clear(): void;
|
|
36
|
+
private start;
|
|
37
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
2
|
+
import type { GLTFAsset } from '@margoengine/gltf/pbr';
|
|
3
|
+
import type { PropertyReadOptions } from './properties.js';
|
|
4
|
+
export declare function rawAccessor(asset: GLTFAsset, index: number, options: PropertyReadOptions): Uint8Array;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, EnginePlugin, Mesh, Vec3 } from '@margoengine/core';
|
|
3
|
+
import type { InstancesContent, ModelContent, PointsContent, TileContent } from './formats.js';
|
|
4
|
+
import { type TileMatrix } from './matrix.js';
|
|
5
|
+
import { type TilesetTile, type TileRenderable, Tileset, type TilesetOptions, type TilesFrame } from './tileset.js';
|
|
6
|
+
/** Optional content decoration owned and disposed with its tile. Bytes are added to the tile budget. */
|
|
7
|
+
export interface TilesContentDecoration {
|
|
8
|
+
readonly bytes: number;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
/** A loaded content item exposed to an optional decorator, before the tile becomes visible. */
|
|
12
|
+
export type TilesDecorationContext = {
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
fetch?: (url: string, signal: AbortSignal) => Promise<Uint8Array>;
|
|
15
|
+
} & ({
|
|
16
|
+
kind: 'model';
|
|
17
|
+
model: TilesModel;
|
|
18
|
+
content: ModelContent;
|
|
19
|
+
tile: TilesetTile;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'points';
|
|
22
|
+
cloud: unknown;
|
|
23
|
+
content: PointsContent;
|
|
24
|
+
tile: TilesetTile;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'instances';
|
|
27
|
+
model: TilesModel;
|
|
28
|
+
content: InstancesContent;
|
|
29
|
+
tile: TilesetTile;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'splats';
|
|
32
|
+
model: TilesModel;
|
|
33
|
+
content: ModelContent;
|
|
34
|
+
tile: TilesetTile;
|
|
35
|
+
fade: (lower: number, upper: number) => void;
|
|
36
|
+
});
|
|
37
|
+
/** Optional entry hook for feature styling and selection. No optional implementation is imported by tiles root. */
|
|
38
|
+
export type TilesContentDecorator = (context: TilesDecorationContext) => TilesContentDecoration | Promise<TilesContentDecoration>;
|
|
39
|
+
/** A floating origin (such as `FloatingOrigin` from `@margoengine/cameras/origin`): float64 placement around the camera. */
|
|
40
|
+
export interface TilesOrigin {
|
|
41
|
+
/** Places a root mesh at a float64 world position and keeps it there across rebases. */
|
|
42
|
+
place(mesh: Mesh, world: ArrayLike<number>): void;
|
|
43
|
+
/** Stops tracking a mesh. */
|
|
44
|
+
forget(mesh: Mesh): void;
|
|
45
|
+
/** Float64 world position of local [0, 0, 0]. */
|
|
46
|
+
readonly origin: Vec3;
|
|
47
|
+
/** Float64 world position of the camera. */
|
|
48
|
+
readonly cameraPosition: Vec3;
|
|
49
|
+
}
|
|
50
|
+
/** The part of a gltf/pbr model the renderer uses. */
|
|
51
|
+
export interface TilesModel {
|
|
52
|
+
readonly root: Mesh;
|
|
53
|
+
dispose(): void;
|
|
54
|
+
}
|
|
55
|
+
/** What a content drawer (such as `i3dm` from `@margoengine/tiles/i3dm`) gets from the renderer. */
|
|
56
|
+
export interface TilesContentHost {
|
|
57
|
+
/** Decorates content using the renderer option, if provided. */
|
|
58
|
+
decorate(context: TilesDecorationContext): TilesContentDecoration | Promise<TilesContentDecoration> | undefined;
|
|
59
|
+
readonly engine: EngineKernel;
|
|
60
|
+
/** The tileset JSON's URL. */
|
|
61
|
+
readonly url: string;
|
|
62
|
+
/** Loads a glTF / GLB with the renderer's `loadModel`. */
|
|
63
|
+
loadModel(gltf: Uint8Array, signal: AbortSignal): Promise<TilesModel>;
|
|
64
|
+
/** Places a root mesh at a float64 world matrix (through the floating origin when there is one). */
|
|
65
|
+
place(mesh: Mesh, matrix: TileMatrix): void;
|
|
66
|
+
/** Stops a floating origin tracking a mesh placed with `place`. */
|
|
67
|
+
forget(mesh: Mesh): void;
|
|
68
|
+
/** frame x tile transform x RTC (x y-up to z-up when `gltf`), float64. */
|
|
69
|
+
contentMatrix(tile: TilesetTile, rtc?: readonly number[], gltf?: boolean): TileMatrix;
|
|
70
|
+
/** Fetches bytes with the tileset's own fetch and signal. */
|
|
71
|
+
fetch(url: string, signal: AbortSignal): Promise<Uint8Array>;
|
|
72
|
+
/** What the memory budget counts (the renderer's `budget` option). */
|
|
73
|
+
readonly budget: 'gpu' | 'content';
|
|
74
|
+
/** Bytes a tile's model counts against the memory budget: its GPU bytes (`budget: 'gpu'`) or `fileBytes`. */
|
|
75
|
+
measure(model: TilesModel, fileBytes: number): number;
|
|
76
|
+
/** Calls `listener` at the end of every selection update (after tile visibility is set); returns the unsubscribe. */
|
|
77
|
+
onUpdate(listener: () => void): () => void;
|
|
78
|
+
/** Float64 world position of engine-local [0, 0, 0]: the floating origin's, or [0, 0, 0] without one. */
|
|
79
|
+
offset(): Vec3;
|
|
80
|
+
}
|
|
81
|
+
/** Draws glTF content of a kind the default model path does not, such as `splats` from `@margoengine/tiles/splats`. */
|
|
82
|
+
export type TilesModelDrawer = (host: TilesContentHost, content: ModelContent, tile: TilesetTile, signal: AbortSignal) => Promise<TileRenderable>;
|
|
83
|
+
/** True when glTF / GLB / b3dm content holds Gaussian splats (KHR_gaussian_splatting in its glTF JSON). */
|
|
84
|
+
export declare function holdsSplats(content: ModelContent): boolean;
|
|
85
|
+
/** Draws Instanced 3D Model (i3dm) content; `i3dm` from `@margoengine/tiles/i3dm` is one. */
|
|
86
|
+
export type TilesInstancesDrawer = (host: TilesContentHost, content: InstancesContent, tile: TilesetTile, signal: AbortSignal) => Promise<TileRenderable>;
|
|
87
|
+
/** Options of `TilesRenderer.load`. */
|
|
88
|
+
export interface TilesRendererOptions extends Omit<TilesetOptions, 'content'> {
|
|
89
|
+
/** Optional content decoration, for example `style.decorate` from tiles/style. Default: none. */
|
|
90
|
+
decorate?: TilesContentDecorator;
|
|
91
|
+
/**
|
|
92
|
+
* Tileset to world: `'enu'` (default) puts the east-north-up frame at the root volume's centre at the world origin
|
|
93
|
+
* (x east, y up, -z north), so city-scale data stays within a few kilometres of 0; `'local'` only turns z-up into
|
|
94
|
+
* y-up (for tilesets in local metres); or a column-major 4x4 matrix of your own. ENU falls back to `'local'` when
|
|
95
|
+
* the root is within 100 km of the earth's centre (the tileset is not geo-referenced).
|
|
96
|
+
*/
|
|
97
|
+
frame?: 'enu' | 'local' | ArrayLike<number>;
|
|
98
|
+
/** A floating origin; placed meshes follow it, and selection reads the camera from it. */
|
|
99
|
+
origin?: TilesOrigin;
|
|
100
|
+
/** Loads one glTF / GLB into the engine. Default: gltf/pbr's `parseGLTFAsync`. */
|
|
101
|
+
loadModel?: (engine: EngineKernel, gltf: Uint8Array, signal: AbortSignal) => Promise<TilesModel>;
|
|
102
|
+
/**
|
|
103
|
+
* What `memoryBudget` counts: `'gpu'` (default) the GPU memory each tile's model takes (vertex, index and uv buffers,
|
|
104
|
+
* textures with their mip chains, point and splat buffers), so the cache limit matches what the device holds;
|
|
105
|
+
* `'content'` the bytes of each tile's file, as `Tileset` alone does.
|
|
106
|
+
*/
|
|
107
|
+
budget?: 'gpu' | 'content';
|
|
108
|
+
/** Point budget of the points plugin made for pnts tiles. Default 2,000,000. */
|
|
109
|
+
pointBudget?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Draws i3dm (instanced) content: pass `i3dm` from `@margoengine/tiles/i3dm`. Without it an i3dm tile fails with
|
|
112
|
+
* code `unsupported` and the rest of the tileset still draws.
|
|
113
|
+
*/
|
|
114
|
+
i3dm?: TilesInstancesDrawer;
|
|
115
|
+
/**
|
|
116
|
+
* Decodes Draco-compressed pnts (3DTILES_draco_point_compression): pass `dracoPoints` from
|
|
117
|
+
* `@margoengine/tiles/metadata`. Without it such a tile fails with code `unsupported`.
|
|
118
|
+
*/
|
|
119
|
+
dracoPoints?: (content: PointsContent, signal: AbortSignal) => Promise<PointsContent>;
|
|
120
|
+
/**
|
|
121
|
+
* Draws glTF content that holds Gaussian splats (KHR_gaussian_splatting): pass `splats` from
|
|
122
|
+
* `@margoengine/tiles/splats`. Without it such a tile fails with code `unsupported`.
|
|
123
|
+
*/
|
|
124
|
+
splats?: TilesModelDrawer;
|
|
125
|
+
}
|
|
126
|
+
/** Engine plugin that streams and draws a 3D Tiles tileset each frame. */
|
|
127
|
+
export declare class TilesRenderer implements EnginePlugin {
|
|
128
|
+
readonly name: string;
|
|
129
|
+
readonly tileset: Tileset;
|
|
130
|
+
/** Tileset to world (float64, column-major). */
|
|
131
|
+
readonly frame: TileMatrix;
|
|
132
|
+
/** World to tileset. */
|
|
133
|
+
readonly inverseFrame: TileMatrix;
|
|
134
|
+
/** The last update's selection. */
|
|
135
|
+
last: TilesFrame;
|
|
136
|
+
/** Set false to freeze the selection (tiles stay as they are while the camera moves). */
|
|
137
|
+
enabled: boolean;
|
|
138
|
+
disposed: boolean;
|
|
139
|
+
private engine?;
|
|
140
|
+
private pointsHost?;
|
|
141
|
+
private readonly origin?;
|
|
142
|
+
private readonly loadModel;
|
|
143
|
+
private readonly pointBudget;
|
|
144
|
+
private readonly budget;
|
|
145
|
+
private readonly i3dm?;
|
|
146
|
+
private readonly dracoPoints?;
|
|
147
|
+
private readonly splats?;
|
|
148
|
+
private readonly decorate?;
|
|
149
|
+
private readonly listeners;
|
|
150
|
+
private host?;
|
|
151
|
+
private points?;
|
|
152
|
+
private readonly planes;
|
|
153
|
+
/** Fetches the tileset JSON, attaches the renderer to the engine and returns it. Aborts with `options.signal`. */
|
|
154
|
+
static load(engine: EngineKernel, url: string | URL, options?: TilesRendererOptions): Promise<TilesRenderer>;
|
|
155
|
+
/** The same as `load`, under the name every engine feature has: fetches the tileset and attaches the renderer. */
|
|
156
|
+
static attach(engine: EngineKernel, url: string | URL, options?: TilesRendererOptions): Promise<TilesRenderer>;
|
|
157
|
+
private constructor();
|
|
158
|
+
setup(engine: EngineKernel): void;
|
|
159
|
+
/** World position (engine coordinates, float64) of an ECEF point. */
|
|
160
|
+
toWorld(ecef: ArrayLike<number>): Vec3;
|
|
161
|
+
/** ECEF of a world position. */
|
|
162
|
+
toTileset(world: ArrayLike<number>): Vec3;
|
|
163
|
+
/** World position of a longitude, latitude (degrees) and height (metres above WGS84). */
|
|
164
|
+
cartographicToWorld(longitude: number, latitude: number, height?: number): Vec3;
|
|
165
|
+
onPreUpdate(): void;
|
|
166
|
+
/** Runs selection for the engine's camera now (the engine also does this every frame). */
|
|
167
|
+
update(): TilesFrame;
|
|
168
|
+
/**
|
|
169
|
+
* The world height an orthographic view-projection `matrix` (column-major) shows, or undefined for a perspective one
|
|
170
|
+
* (or for no matrix, or core's all-zero matrix before the first frame).
|
|
171
|
+
* Orthographic means the clip w row is (0, 0, 0, w): then NDC y spans 2 over a world height of 2 w / |row y|.
|
|
172
|
+
*/
|
|
173
|
+
static orthographicHeight(matrix: ArrayLike<number> | undefined): number | undefined;
|
|
174
|
+
/** World matrix (float64) of a tile's glTF content: frame x tile transform x RTC x y-up to z-up. */
|
|
175
|
+
contentMatrix(tile: TilesetTile, rtc?: readonly number[], gltf?: boolean): TileMatrix;
|
|
176
|
+
private place;
|
|
177
|
+
/** @internal The content factory: models for glTF and b3dm, clouds for pnts, groups for cmpt. */
|
|
178
|
+
createContent(content: TileContent, tile: TilesetTile, signal: AbortSignal): Promise<TileRenderable>;
|
|
179
|
+
/** Calls `listener` after every selection update (tile visibility set, `last` current); returns the unsubscribe. */
|
|
180
|
+
onUpdate(listener: () => void): () => void;
|
|
181
|
+
/** Bytes a model counts against the budget (see `budget`). */
|
|
182
|
+
measure(model: TilesModel, fileBytes: number): number;
|
|
183
|
+
/**
|
|
184
|
+
* Runs `work` in this renderer's own scene. Tile content is made after fetches and imports, when the active scene is the
|
|
185
|
+
* default one again, wherever the renderer went: its meshes, models and plugins belong with it.
|
|
186
|
+
*/
|
|
187
|
+
private own;
|
|
188
|
+
private contentHost;
|
|
189
|
+
private loadPoints;
|
|
190
|
+
/** Frees every tile, the points plugin it made and detaches from the engine. */
|
|
191
|
+
dispose(): void;
|
|
192
|
+
[Symbol.dispose](): void;
|
|
193
|
+
}
|
package/dist/s2.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TileBounds, type BoundingVolumeExtension, type SplitBounds } from './bounds.js';
|
|
2
|
+
/** An S2 cell: cube face 0 to 5, level 0 to 30, and its (i, j) position on the face's 2^level x 2^level grid. */
|
|
3
|
+
export interface S2Cell {
|
|
4
|
+
readonly face: number;
|
|
5
|
+
readonly level: number;
|
|
6
|
+
readonly i: number;
|
|
7
|
+
readonly j: number;
|
|
8
|
+
}
|
|
9
|
+
/** The extension's JSON: `token`, and heights in metres above the WGS84 ellipsoid. */
|
|
10
|
+
export interface S2VolumeJSON {
|
|
11
|
+
token: string;
|
|
12
|
+
minimumHeight: number;
|
|
13
|
+
maximumHeight: number;
|
|
14
|
+
}
|
|
15
|
+
/** Reads an S2 cell token (the cell ID in hex, trailing zeros dropped). Throws TypeError naming what is wrong. */
|
|
16
|
+
export declare function parseS2Token(token: string): S2Cell;
|
|
17
|
+
/** The token of a cell. Throws RangeError for a cell off its face's grid. */
|
|
18
|
+
export declare function s2Token({ face, level, i, j }: S2Cell): string;
|
|
19
|
+
/**
|
|
20
|
+
* Longitude and latitude (radians) of a point of `cell` at fractions `s` and `t` (0 to 1) across it: the cube point's
|
|
21
|
+
* direction, read as geodetic longitude and latitude on WGS84 as the extension does.
|
|
22
|
+
*/
|
|
23
|
+
export declare function s2LonLat(cell: S2Cell, s?: number, t?: number): [number, number];
|
|
24
|
+
/**
|
|
25
|
+
* An oriented box around `cell` extruded from `minimumHeight` to `maximumHeight` along the ellipsoid normals, in ECEF:
|
|
26
|
+
* axes east, north and up at the cell's centre, sized by a grid of points on its bottom and top surfaces, then grown
|
|
27
|
+
* by the largest gap between those points and the surface (the sagitta at the ellipsoid's largest curvature radius).
|
|
28
|
+
*/
|
|
29
|
+
export declare function s2CellBounds(cell: S2Cell, minimumHeight: number, maximumHeight: number, split?: SplitBounds): TileBounds;
|
|
30
|
+
/**
|
|
31
|
+
* The bounds of an S2 volume JSON, with implicit subdivision: a quadtree tile (level, x, y) below it is the cell
|
|
32
|
+
* (face, level + L, i * 2^level + x, j * 2^level + y) over the same heights; an octree tile also takes the z-th of
|
|
33
|
+
* 2^level equal height slabs.
|
|
34
|
+
*/
|
|
35
|
+
export declare function s2Bounds(volume: S2VolumeJSON): TileBounds;
|
|
36
|
+
/** The 3DTILES_bounding_volume_S2 reader: pass it as `boundingVolumes: [s2]` to `Tileset.load` or `TilesRenderer.load`. */
|
|
37
|
+
export declare const s2: BoundingVolumeExtension;
|