@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +307 -3
- 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 +124 -6
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { a as e, i as t } from "./glb-BU81jlYZ.js";
|
|
2
|
+
import { a as n } from "./wgs84-C5btsGGY.js";
|
|
3
|
+
//#region src/formats.ts
|
|
4
|
+
var r = {
|
|
5
|
+
BYTE: 1,
|
|
6
|
+
UNSIGNED_BYTE: 1,
|
|
7
|
+
SHORT: 2,
|
|
8
|
+
UNSIGNED_SHORT: 2,
|
|
9
|
+
INT: 4,
|
|
10
|
+
UNSIGNED_INT: 4,
|
|
11
|
+
FLOAT: 4,
|
|
12
|
+
DOUBLE: 8
|
|
13
|
+
}, i = {
|
|
14
|
+
SCALAR: 1,
|
|
15
|
+
VEC2: 2,
|
|
16
|
+
VEC3: 3,
|
|
17
|
+
VEC4: 4
|
|
18
|
+
};
|
|
19
|
+
function a(e, t, n, i) {
|
|
20
|
+
let a = r[n];
|
|
21
|
+
if (!a) throw TypeError(`Unknown componentType ${n}; use one of ${Object.keys(r).join(", ")}`);
|
|
22
|
+
if (!Number.isInteger(t) || t < 0 || !Number.isInteger(i) || i < 0) throw RangeError("Invalid binary reference; byteOffset and counts must be whole numbers of 0 or more");
|
|
23
|
+
if (t + a * i > e.byteLength) throw RangeError(`Binary body too short: ${i} ${n} at ${t} pass its ${e.byteLength} bytes; the file is truncated or corrupt`);
|
|
24
|
+
let o = new DataView(e.buffer, e.byteOffset + t, a * i);
|
|
25
|
+
switch (n) {
|
|
26
|
+
case "BYTE": return Int8Array.from({ length: i }, (e, t) => o.getInt8(t));
|
|
27
|
+
case "UNSIGNED_BYTE": return Uint8Array.from({ length: i }, (e, t) => o.getUint8(t));
|
|
28
|
+
case "SHORT": return Int16Array.from({ length: i }, (e, t) => o.getInt16(t * 2, !0));
|
|
29
|
+
case "UNSIGNED_SHORT": return Uint16Array.from({ length: i }, (e, t) => o.getUint16(t * 2, !0));
|
|
30
|
+
case "INT": return Int32Array.from({ length: i }, (e, t) => o.getInt32(t * 4, !0));
|
|
31
|
+
case "UNSIGNED_INT": return Uint32Array.from({ length: i }, (e, t) => o.getUint32(t * 4, !0));
|
|
32
|
+
case "FLOAT": return Float32Array.from({ length: i }, (e, t) => o.getFloat32(t * 4, !0));
|
|
33
|
+
default: return Float64Array.from({ length: i }, (e, t) => o.getFloat64(t * 8, !0));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
var o = /* @__PURE__ */ new TextDecoder();
|
|
37
|
+
function s(e, t) {
|
|
38
|
+
if (e.byteLength === 0) return {};
|
|
39
|
+
let n = o.decode(e);
|
|
40
|
+
n = n.replace(/[\0\s]+$/, "");
|
|
41
|
+
let r;
|
|
42
|
+
try {
|
|
43
|
+
r = JSON.parse(n);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
throw TypeError(`Invalid ${t} JSON (${e.message}); the tile content is corrupt`);
|
|
46
|
+
}
|
|
47
|
+
if (!r || typeof r != "object" || Array.isArray(r)) throw TypeError(`Invalid ${t} JSON; it must be an object`);
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
var c = class {
|
|
51
|
+
constructor(e, t) {
|
|
52
|
+
this.json = e, this.binary = t;
|
|
53
|
+
}
|
|
54
|
+
global(e, t, n) {
|
|
55
|
+
let r = this.json[e];
|
|
56
|
+
if (r !== void 0) {
|
|
57
|
+
if (typeof r == "number" || Array.isArray(r)) return r;
|
|
58
|
+
if (r && typeof r == "object" && "byteOffset" in r) return a(this.binary, r.byteOffset, t, n);
|
|
59
|
+
throw TypeError(`Invalid feature table property ${e}; give a number, an array or a {byteOffset} reference`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
property(e, t, n, r) {
|
|
63
|
+
let i = this.json[e];
|
|
64
|
+
if (i !== void 0) {
|
|
65
|
+
if (!i || typeof i != "object" || typeof i.byteOffset != "number") throw TypeError(`Invalid feature table property ${e}; per-feature properties must be {byteOffset} references`);
|
|
66
|
+
return a(this.binary, i.byteOffset, i.componentType ?? r, t * n);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, l = class {
|
|
70
|
+
constructor(e, t, n) {
|
|
71
|
+
this.json = e, this.binary = t, this.length = n, this.cache = /* @__PURE__ */ new Map(), this.names = Object.keys(e).filter((e) => e !== "extensions" && e !== "extras");
|
|
72
|
+
}
|
|
73
|
+
values(e) {
|
|
74
|
+
let t = this.cache.get(e);
|
|
75
|
+
if (t) return t;
|
|
76
|
+
let n = this.json[e];
|
|
77
|
+
if (n === void 0) return;
|
|
78
|
+
let r;
|
|
79
|
+
if (Array.isArray(n)) r = n;
|
|
80
|
+
else if (n && typeof n == "object" && "byteOffset" in n) {
|
|
81
|
+
let t = n, o = i[t.type];
|
|
82
|
+
if (!o) throw TypeError(`Invalid batch table property ${e}; type must be SCALAR, VEC2, VEC3 or VEC4`);
|
|
83
|
+
let s = a(this.binary, t.byteOffset, t.componentType, this.length * o);
|
|
84
|
+
r = o === 1 ? s : Array.from({ length: this.length }, (e, t) => Array.from(s.subarray(t * o, t * o + o)));
|
|
85
|
+
} else throw TypeError(`Invalid batch table property ${e}; give an array or a {byteOffset, componentType, type} reference`);
|
|
86
|
+
return this.cache.set(e, r), r;
|
|
87
|
+
}
|
|
88
|
+
get(e, t) {
|
|
89
|
+
if (!(!Number.isInteger(e) || e < 0 || e >= this.length)) return this.values(t)?.[e];
|
|
90
|
+
}
|
|
91
|
+
feature(e) {
|
|
92
|
+
let t = {};
|
|
93
|
+
for (let n of this.names) t[n] = this.get(e, n);
|
|
94
|
+
return t;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function u(e) {
|
|
98
|
+
if (e.byteLength >= 4) {
|
|
99
|
+
let t = String.fromCharCode(e[0], e[1], e[2], e[3]);
|
|
100
|
+
if (t === "b3dm" || t === "pnts" || t === "i3dm" || t === "cmpt" || t === "glTF" || t === "subt") return t;
|
|
101
|
+
}
|
|
102
|
+
for (let t = 0; t < e.byteLength; t++) {
|
|
103
|
+
let n = e[t];
|
|
104
|
+
if (n !== 32 && n !== 10 && n !== 13 && n !== 9 && n !== 239 && n !== 187 && n !== 191) return n === 123 ? "json" : void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function d(e, t, n) {
|
|
108
|
+
if (e.byteLength < n) throw RangeError(`${t} content too short for its ${n}-byte header; the file is truncated`);
|
|
109
|
+
let r = new DataView(e.buffer, e.byteOffset, e.byteLength), i = r.getUint32(4, !0), a = r.getUint32(8, !0);
|
|
110
|
+
if (i !== 1) throw TypeError(`Unsupported ${t} version ${i}; only version 1 is defined`);
|
|
111
|
+
if (a < n || a > e.byteLength) throw RangeError(`${t} byteLength ${a} does not fit the ${e.byteLength} bytes given; the file is truncated or corrupt`);
|
|
112
|
+
let o = [
|
|
113
|
+
12,
|
|
114
|
+
16,
|
|
115
|
+
20,
|
|
116
|
+
24
|
|
117
|
+
].map((e) => r.getUint32(e, !0)), l = n, u = (n, r) => {
|
|
118
|
+
if (l + n > a) throw RangeError(`${t} ${r} runs past the content (${l + n} > ${a}); the file is truncated or corrupt`);
|
|
119
|
+
let i = e.subarray(l, l + n);
|
|
120
|
+
return l += n, i;
|
|
121
|
+
}, d = s(u(o[0], "feature table JSON"), `${t} feature table`), f = u(o[1], "feature table binary"), p = s(u(o[2], "batch table JSON"), `${t} batch table`), m = u(o[3], "batch table binary");
|
|
122
|
+
return {
|
|
123
|
+
view: r,
|
|
124
|
+
byteLength: a,
|
|
125
|
+
featureTable: new c(d, f),
|
|
126
|
+
batchTableJSON: p,
|
|
127
|
+
batchTableBinary: m,
|
|
128
|
+
body: e.subarray(l, a)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function f(e, t, n) {
|
|
132
|
+
let r = e.json[t];
|
|
133
|
+
if (typeof r != "number" || !Number.isInteger(r) || r < 0) throw TypeError(`${n} feature table needs ${t} as a whole number of 0 or more`);
|
|
134
|
+
return r;
|
|
135
|
+
}
|
|
136
|
+
function p(e, t) {
|
|
137
|
+
if (e !== void 0) {
|
|
138
|
+
if (typeof e == "number" || e.length !== 3 || !Array.from(e).every(Number.isFinite)) throw TypeError(`Invalid ${t}; give three finite numbers`);
|
|
139
|
+
return [
|
|
140
|
+
e[0],
|
|
141
|
+
e[1],
|
|
142
|
+
e[2]
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function m(e, t) {
|
|
147
|
+
return Object.keys(e.batchTableJSON).length ? new l(e.batchTableJSON, e.batchTableBinary, t) : void 0;
|
|
148
|
+
}
|
|
149
|
+
function h(e) {
|
|
150
|
+
let t = d(e, "b3dm", 28), n = t.featureTable, r = f(n, "BATCH_LENGTH", "b3dm");
|
|
151
|
+
return {
|
|
152
|
+
type: "b3dm",
|
|
153
|
+
gltf: g(t.body, "b3dm"),
|
|
154
|
+
rtcCenter: p(n.global("RTC_CENTER", "FLOAT", 3), "RTC_CENTER"),
|
|
155
|
+
featureTable: n,
|
|
156
|
+
batchTable: m(t, r),
|
|
157
|
+
byteLength: t.byteLength
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function g(n, r) {
|
|
161
|
+
if (n.byteLength < 12 || !e(n)) throw TypeError(`${r} glTF body is not a GLB (no glTF magic or too short); the content is corrupt`);
|
|
162
|
+
let i = new DataView(n.buffer, n.byteOffset, 12).getUint32(8, !0);
|
|
163
|
+
if (i > n.byteLength) throw RangeError(`${r} GLB length ${i} passes the ${n.byteLength} bytes given; the file is truncated`);
|
|
164
|
+
let a = n.subarray(0, i);
|
|
165
|
+
return t(a), a;
|
|
166
|
+
}
|
|
167
|
+
function _(e, t) {
|
|
168
|
+
let n = e.featureTable.json.extensions?.["3DTILES_draco_point_compression"];
|
|
169
|
+
if (!n) return;
|
|
170
|
+
let { properties: r, byteOffset: i, byteLength: a } = n, o = e.featureTable.binary;
|
|
171
|
+
if (!r || typeof r != "object" || !Object.values(r).every(Number.isInteger)) throw TypeError("3DTILES_draco_point_compression needs properties: semantic to Draco attribute ID");
|
|
172
|
+
if (!Number.isInteger(i) || !Number.isInteger(a) || i < 0 || a <= 0 || i + a > o.byteLength) throw RangeError(`3DTILES_draco_point_compression byteOffset ${i} and byteLength ${a} pass the ${o.byteLength}-byte feature table binary; the file is truncated or corrupt`);
|
|
173
|
+
let s = e.batchTableJSON.extensions?.["3DTILES_draco_point_compression"];
|
|
174
|
+
return {
|
|
175
|
+
bytes: o.subarray(i, i + a),
|
|
176
|
+
properties: r,
|
|
177
|
+
batchProperties: s?.properties,
|
|
178
|
+
length: t
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function v(e) {
|
|
182
|
+
let t = d(e, "pnts", 28), n = t.featureTable, r = f(n, "POINTS_LENGTH", "pnts"), i = _(t, r), a = (e) => i?.properties[e] !== void 0, o = (e, t, i) => a(e) ? void 0 : n.property(e, r, t, i), s, c = o("POSITION", 3, "FLOAT");
|
|
183
|
+
if (c) s = Float32Array.from(c);
|
|
184
|
+
else if (a("POSITION")) s = /* @__PURE__ */ new Float32Array();
|
|
185
|
+
else {
|
|
186
|
+
let e = n.property("POSITION_QUANTIZED", r, 3, "UNSIGNED_SHORT"), t = p(n.global("QUANTIZED_VOLUME_OFFSET", "FLOAT", 3), "QUANTIZED_VOLUME_OFFSET"), i = p(n.global("QUANTIZED_VOLUME_SCALE", "FLOAT", 3), "QUANTIZED_VOLUME_SCALE");
|
|
187
|
+
if (!e || !t || !i) throw TypeError("pnts needs POSITION, or POSITION_QUANTIZED with QUANTIZED_VOLUME_OFFSET and QUANTIZED_VOLUME_SCALE");
|
|
188
|
+
s = new Float32Array(r * 3);
|
|
189
|
+
for (let n = 0; n < r * 3; n++) s[n] = t[n % 3] + e[n] / 65535 * i[n % 3];
|
|
190
|
+
}
|
|
191
|
+
let l, u = o("RGBA", 4, "UNSIGNED_BYTE"), h = u ? void 0 : o("RGB", 3, "UNSIGNED_BYTE"), g = u || h ? void 0 : o("RGB565", 1, "UNSIGNED_SHORT");
|
|
192
|
+
if (u) l = Uint8Array.from(u);
|
|
193
|
+
else if (h || g) {
|
|
194
|
+
l = new Uint8Array(r * 4);
|
|
195
|
+
for (let e = 0; e < r; e++) {
|
|
196
|
+
if (h) l[e * 4] = h[e * 3], l[e * 4 + 1] = h[e * 3 + 1], l[e * 4 + 2] = h[e * 3 + 2];
|
|
197
|
+
else {
|
|
198
|
+
let t = g[e];
|
|
199
|
+
l[e * 4] = Math.round((t >> 11 & 31) * 255 / 31), l[e * 4 + 1] = Math.round((t >> 5 & 63) * 255 / 63), l[e * 4 + 2] = Math.round((t & 31) * 255 / 31);
|
|
200
|
+
}
|
|
201
|
+
l[e * 4 + 3] = 255;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let v, b = o("NORMAL", 3, "FLOAT");
|
|
205
|
+
if (b) v = Float32Array.from(b);
|
|
206
|
+
else {
|
|
207
|
+
let e = o("NORMAL_OCT16P", 2, "UNSIGNED_BYTE");
|
|
208
|
+
if (e) {
|
|
209
|
+
v = new Float32Array(r * 3);
|
|
210
|
+
for (let t = 0; t < r; t++) y(e[t * 2], e[t * 2 + 1], 255, v, t * 3);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
let x = o("BATCH_ID", 1, n.json.BATCH_ID?.componentType ?? "UNSIGNED_SHORT"), S = n.global("CONSTANT_RGBA", "UNSIGNED_BYTE", 4), C = x || a("BATCH_ID") ? f(n, "BATCH_LENGTH", "pnts") : r;
|
|
214
|
+
return {
|
|
215
|
+
type: "pnts",
|
|
216
|
+
positions: s,
|
|
217
|
+
colors: l,
|
|
218
|
+
normals: v,
|
|
219
|
+
batchIds: x ? Uint32Array.from(x) : void 0,
|
|
220
|
+
constantColor: S !== void 0 && typeof S != "number" && S.length === 4 ? [
|
|
221
|
+
S[0],
|
|
222
|
+
S[1],
|
|
223
|
+
S[2],
|
|
224
|
+
S[3]
|
|
225
|
+
] : void 0,
|
|
226
|
+
rtcCenter: p(n.global("RTC_CENTER", "FLOAT", 3), "RTC_CENTER"),
|
|
227
|
+
featureTable: n,
|
|
228
|
+
batchTable: m(t, C),
|
|
229
|
+
byteLength: t.byteLength,
|
|
230
|
+
draco: i
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function y(e, t, n, r, i) {
|
|
234
|
+
let a = e / n * 2 - 1, o = t / n * 2 - 1, s = 1 - Math.abs(a) - Math.abs(o);
|
|
235
|
+
if (s < 0) {
|
|
236
|
+
let e = a;
|
|
237
|
+
a = (1 - Math.abs(o)) * (e >= 0 ? 1 : -1), o = (1 - Math.abs(e)) * (o >= 0 ? 1 : -1);
|
|
238
|
+
}
|
|
239
|
+
let c = Math.hypot(a, o, s) || 1;
|
|
240
|
+
r[i] = a / c, r[i + 1] = o / c, r[i + 2] = s / c;
|
|
241
|
+
}
|
|
242
|
+
function b(e, t) {
|
|
243
|
+
let n = d(e, "i3dm", 32), r = n.featureTable, i = f(r, "INSTANCES_LENGTH", "i3dm"), a = n.view.getUint32(28, !0);
|
|
244
|
+
if (a > 1) throw TypeError(`Invalid i3dm gltfFormat ${a}; it must be 0 (URI) or 1 (embedded GLB)`);
|
|
245
|
+
let s, c;
|
|
246
|
+
a === 1 ? s = g(n.body, "i3dm") : c = o.decode(n.body).replace(/[\0\s]+$/, "");
|
|
247
|
+
let l = p(r.global("RTC_CENTER", "FLOAT", 3), "RTC_CENTER"), u = r.property("POSITION", i, 3, "FLOAT");
|
|
248
|
+
if (!u) {
|
|
249
|
+
let e = r.property("POSITION_QUANTIZED", i, 3, "UNSIGNED_SHORT"), t = p(r.global("QUANTIZED_VOLUME_OFFSET", "FLOAT", 3), "QUANTIZED_VOLUME_OFFSET"), n = p(r.global("QUANTIZED_VOLUME_SCALE", "FLOAT", 3), "QUANTIZED_VOLUME_SCALE");
|
|
250
|
+
if (!e || !t || !n) throw TypeError("i3dm needs POSITION, or POSITION_QUANTIZED with QUANTIZED_VOLUME_OFFSET and QUANTIZED_VOLUME_SCALE");
|
|
251
|
+
u = Float64Array.from({ length: i * 3 }, (r, i) => t[i % 3] + e[i] / 65535 * n[i % 3]);
|
|
252
|
+
}
|
|
253
|
+
let h = r.property("NORMAL_UP", i, 3, "FLOAT"), _ = r.property("NORMAL_RIGHT", i, 3, "FLOAT");
|
|
254
|
+
if (!h) {
|
|
255
|
+
let e = r.property("NORMAL_UP_OCT32P", i, 2, "UNSIGNED_SHORT"), t = r.property("NORMAL_RIGHT_OCT32P", i, 2, "UNSIGNED_SHORT");
|
|
256
|
+
if (e && t) {
|
|
257
|
+
let n = new Float32Array(i * 3), r = new Float32Array(i * 3);
|
|
258
|
+
for (let a = 0; a < i; a++) y(e[a * 2], e[a * 2 + 1], 65535, n, a * 3), y(t[a * 2], t[a * 2 + 1], 65535, r, a * 3);
|
|
259
|
+
h = n, _ = r;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
let v = r.property("SCALE", i, 1, "FLOAT"), b = r.property("SCALE_NON_UNIFORM", i, 3, "FLOAT"), x = r.json.EAST_NORTH_UP === !0, S = new Float64Array(i * 16);
|
|
263
|
+
for (let e = 0; e < i; e++) {
|
|
264
|
+
let n = [
|
|
265
|
+
u[e * 3],
|
|
266
|
+
u[e * 3 + 1],
|
|
267
|
+
u[e * 3 + 2]
|
|
268
|
+
], r = S.subarray(e * 16, e * 16 + 16), i = [
|
|
269
|
+
1,
|
|
270
|
+
0,
|
|
271
|
+
0
|
|
272
|
+
], a = [
|
|
273
|
+
0,
|
|
274
|
+
1,
|
|
275
|
+
0
|
|
276
|
+
], o = [
|
|
277
|
+
0,
|
|
278
|
+
0,
|
|
279
|
+
1
|
|
280
|
+
];
|
|
281
|
+
if (h && _) i = [
|
|
282
|
+
_[e * 3],
|
|
283
|
+
_[e * 3 + 1],
|
|
284
|
+
_[e * 3 + 2]
|
|
285
|
+
], a = [
|
|
286
|
+
h[e * 3],
|
|
287
|
+
h[e * 3 + 1],
|
|
288
|
+
h[e * 3 + 2]
|
|
289
|
+
];
|
|
290
|
+
else if (x && t) {
|
|
291
|
+
let e = t(l ? [
|
|
292
|
+
n[0] + l[0],
|
|
293
|
+
n[1] + l[1],
|
|
294
|
+
n[2] + l[2]
|
|
295
|
+
] : n);
|
|
296
|
+
i = [
|
|
297
|
+
e[0],
|
|
298
|
+
e[1],
|
|
299
|
+
e[2]
|
|
300
|
+
], a = [
|
|
301
|
+
e[4],
|
|
302
|
+
e[5],
|
|
303
|
+
e[6]
|
|
304
|
+
];
|
|
305
|
+
}
|
|
306
|
+
o = [
|
|
307
|
+
i[1] * a[2] - i[2] * a[1],
|
|
308
|
+
i[2] * a[0] - i[0] * a[2],
|
|
309
|
+
i[0] * a[1] - i[1] * a[0]
|
|
310
|
+
];
|
|
311
|
+
let s = v ? v[e] : 1, c = b ? [
|
|
312
|
+
b[e * 3] * s,
|
|
313
|
+
b[e * 3 + 1] * s,
|
|
314
|
+
b[e * 3 + 2] * s
|
|
315
|
+
] : [
|
|
316
|
+
s,
|
|
317
|
+
s,
|
|
318
|
+
s
|
|
319
|
+
];
|
|
320
|
+
r.set([
|
|
321
|
+
i[0] * c[0],
|
|
322
|
+
i[1] * c[0],
|
|
323
|
+
i[2] * c[0],
|
|
324
|
+
0,
|
|
325
|
+
a[0] * c[1],
|
|
326
|
+
a[1] * c[1],
|
|
327
|
+
a[2] * c[1],
|
|
328
|
+
0,
|
|
329
|
+
o[0] * c[2],
|
|
330
|
+
o[1] * c[2],
|
|
331
|
+
o[2] * c[2],
|
|
332
|
+
0,
|
|
333
|
+
n[0],
|
|
334
|
+
n[1],
|
|
335
|
+
n[2],
|
|
336
|
+
1
|
|
337
|
+
]);
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
type: "i3dm",
|
|
341
|
+
gltf: s,
|
|
342
|
+
gltfUri: c,
|
|
343
|
+
matrices: S,
|
|
344
|
+
length: i,
|
|
345
|
+
rtcCenter: l,
|
|
346
|
+
featureTable: r,
|
|
347
|
+
batchTable: m(n, i),
|
|
348
|
+
byteLength: n.byteLength
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function x(e, t = 8) {
|
|
352
|
+
if (e.byteLength < 16) throw RangeError("cmpt content too short for its 16-byte header; the file is truncated");
|
|
353
|
+
let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getUint32(4, !0), i = n.getUint32(8, !0), a = n.getUint32(12, !0);
|
|
354
|
+
if (r !== 1) throw TypeError(`Unsupported cmpt version ${r}; only version 1 is defined`);
|
|
355
|
+
if (i < 16 || i > e.byteLength) throw RangeError(`cmpt byteLength ${i} does not fit the ${e.byteLength} bytes given; the file is truncated or corrupt`);
|
|
356
|
+
if (t <= 0) throw RangeError("cmpt nested too deeply; flatten the composite to 8 levels or fewer");
|
|
357
|
+
let o = [], s = 16;
|
|
358
|
+
for (let r = 0; r < a; r++) {
|
|
359
|
+
if (s + 12 > i) throw RangeError(`cmpt inner tile ${r} header runs past the content; the file is truncated or corrupt`);
|
|
360
|
+
let a = n.getUint32(s + 8, !0);
|
|
361
|
+
if (a < 12 || s + a > i) throw RangeError(`cmpt inner tile ${r} byteLength ${a} runs past the content; the file is truncated or corrupt`);
|
|
362
|
+
o.push(S(e.subarray(s, s + a), t - 1)), s += a;
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
type: "cmpt",
|
|
366
|
+
tiles: o,
|
|
367
|
+
byteLength: i
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function S(e, t = 8) {
|
|
371
|
+
switch (u(e)) {
|
|
372
|
+
case "b3dm": return h(e);
|
|
373
|
+
case "pnts": return v(e);
|
|
374
|
+
case "i3dm": return b(e, (e) => n(e[0], e[1], e[2]));
|
|
375
|
+
case "cmpt": return x(e, t);
|
|
376
|
+
case "glTF": return {
|
|
377
|
+
type: "glb",
|
|
378
|
+
gltf: g(e, "Tile"),
|
|
379
|
+
byteLength: e.byteLength
|
|
380
|
+
};
|
|
381
|
+
case "json": return {
|
|
382
|
+
type: "gltf",
|
|
383
|
+
gltf: e,
|
|
384
|
+
byteLength: e.byteLength
|
|
385
|
+
};
|
|
386
|
+
default: throw TypeError("Unknown tile content (no b3dm, pnts, i3dm, cmpt or glTF magic); serve glTF, GLB or a 3D Tiles 1.0 format");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
export { x as a, v as c, h as i, a as l, c as n, S as o, u as r, b as s, l as t };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** A component type of feature and batch table binary bodies. */
|
|
2
|
+
export type ComponentType = 'BYTE' | 'UNSIGNED_BYTE' | 'SHORT' | 'UNSIGNED_SHORT' | 'INT' | 'UNSIGNED_INT' | 'FLOAT' | 'DOUBLE';
|
|
3
|
+
/** An element type of feature and batch table binary bodies. */
|
|
4
|
+
export type ElementType = 'SCALAR' | 'VEC2' | 'VEC3' | 'VEC4';
|
|
5
|
+
/** Reads `count` elements of a component type at a byte offset into a new array (no alignment requirement). */
|
|
6
|
+
export declare function readComponents(bytes: Uint8Array, byteOffset: number, componentType: ComponentType, count: number): Float64Array | Float32Array | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array;
|
|
7
|
+
/** A feature table: the JSON header and binary body of b3dm, i3dm and pnts content. */
|
|
8
|
+
export declare class FeatureTable {
|
|
9
|
+
/** The JSON header. */
|
|
10
|
+
readonly json: Record<string, unknown>;
|
|
11
|
+
/** The binary body. */
|
|
12
|
+
readonly binary: Uint8Array;
|
|
13
|
+
constructor(
|
|
14
|
+
/** The JSON header. */
|
|
15
|
+
json: Record<string, unknown>,
|
|
16
|
+
/** The binary body. */
|
|
17
|
+
binary: Uint8Array);
|
|
18
|
+
/** A global (per tile) property: a JSON value, or `count` components read from a `{byteOffset}` reference. */
|
|
19
|
+
global(name: string, componentType: ComponentType, count: number): ArrayLike<number> | number | undefined;
|
|
20
|
+
/** A per-feature property: `length` elements of `size` components from a `{byteOffset, componentType?}` reference. */
|
|
21
|
+
property(name: string, length: number, size: number, componentType: ComponentType): ArrayLike<number> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** A batch table: per-feature properties of b3dm, i3dm and pnts content (the "properties" of each feature). */
|
|
24
|
+
export declare class BatchTable {
|
|
25
|
+
/** The JSON header. */
|
|
26
|
+
readonly json: Record<string, unknown>;
|
|
27
|
+
/** The binary body. */
|
|
28
|
+
readonly binary: Uint8Array;
|
|
29
|
+
/** Number of features (BATCH_LENGTH, INSTANCES_LENGTH or the pnts BATCH_LENGTH). */
|
|
30
|
+
readonly length: number;
|
|
31
|
+
/** Property names, excluding `extensions` and `extras`. */
|
|
32
|
+
readonly names: readonly string[];
|
|
33
|
+
private readonly cache;
|
|
34
|
+
constructor(
|
|
35
|
+
/** The JSON header. */
|
|
36
|
+
json: Record<string, unknown>,
|
|
37
|
+
/** The binary body. */
|
|
38
|
+
binary: Uint8Array,
|
|
39
|
+
/** Number of features (BATCH_LENGTH, INSTANCES_LENGTH or the pnts BATCH_LENGTH). */
|
|
40
|
+
length: number);
|
|
41
|
+
/** All values of one property, one entry per feature (an array of numbers for VEC types). */
|
|
42
|
+
values(name: string): ArrayLike<unknown> | undefined;
|
|
43
|
+
/** One feature's value of a property, or undefined. */
|
|
44
|
+
get(batchId: number, name: string): unknown;
|
|
45
|
+
/** Every property of one feature as an object. */
|
|
46
|
+
feature(batchId: number): Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/** Parsed point cloud (pnts) content: positions relative to `rtcCenter`, colours 0..1, all decoded. */
|
|
49
|
+
export interface PointsContent {
|
|
50
|
+
readonly type: 'pnts';
|
|
51
|
+
/** xyz per point, float32, relative to `rtcCenter` (or to the quantized volume offset, already applied). */
|
|
52
|
+
readonly positions: Float32Array;
|
|
53
|
+
/** RGBA per point, 0..255, or undefined. */
|
|
54
|
+
readonly colors?: Uint8Array;
|
|
55
|
+
/** xyz unit normals, or undefined. */
|
|
56
|
+
readonly normals?: Float32Array;
|
|
57
|
+
/** BATCH_ID per point, or undefined. */
|
|
58
|
+
readonly batchIds?: Uint32Array;
|
|
59
|
+
/** CONSTANT_RGBA when present. */
|
|
60
|
+
readonly constantColor?: readonly [number, number, number, number];
|
|
61
|
+
readonly rtcCenter?: readonly [number, number, number];
|
|
62
|
+
readonly featureTable: FeatureTable;
|
|
63
|
+
readonly batchTable?: BatchTable;
|
|
64
|
+
readonly byteLength: number;
|
|
65
|
+
/**
|
|
66
|
+
* Set for Draco-compressed points (3DTILES_draco_point_compression): the compressed semantics are not decoded yet
|
|
67
|
+
* (`positions` is empty); `dracoPoints` from `@margoengine/tiles/metadata` decodes them.
|
|
68
|
+
*/
|
|
69
|
+
readonly draco?: DracoPointsData;
|
|
70
|
+
}
|
|
71
|
+
/** The compressed part of Draco pnts: the Draco buffer and the attribute ID of each compressed semantic. */
|
|
72
|
+
export interface DracoPointsData {
|
|
73
|
+
readonly bytes: Uint8Array;
|
|
74
|
+
/** Feature table semantic (POSITION, RGBA, RGB, NORMAL, BATCH_ID) to Draco attribute ID. */
|
|
75
|
+
readonly properties: Readonly<Record<string, number>>;
|
|
76
|
+
/** Batch table property to Draco attribute ID. */
|
|
77
|
+
readonly batchProperties?: Readonly<Record<string, number>>;
|
|
78
|
+
/** POINTS_LENGTH. */
|
|
79
|
+
readonly length: number;
|
|
80
|
+
}
|
|
81
|
+
/** glTF content: a GLB (or glTF JSON) to draw, with the b3dm wrapper's RTC_CENTER and batch table when present. */
|
|
82
|
+
export interface ModelContent {
|
|
83
|
+
readonly type: 'glb' | 'gltf' | 'b3dm';
|
|
84
|
+
/** The GLB bytes (or glTF JSON bytes for `type: 'gltf'`). */
|
|
85
|
+
readonly gltf: Uint8Array;
|
|
86
|
+
readonly rtcCenter?: readonly [number, number, number];
|
|
87
|
+
readonly featureTable?: FeatureTable;
|
|
88
|
+
readonly batchTable?: BatchTable;
|
|
89
|
+
readonly byteLength: number;
|
|
90
|
+
}
|
|
91
|
+
/** Instanced 3D Model (i3dm) content: per-instance transforms around one glTF. */
|
|
92
|
+
export interface InstancesContent {
|
|
93
|
+
readonly type: 'i3dm';
|
|
94
|
+
/** The embedded GLB, or the glTF URI (`gltfUri`) when gltfFormat is 0. */
|
|
95
|
+
readonly gltf?: Uint8Array;
|
|
96
|
+
readonly gltfUri?: string;
|
|
97
|
+
/** Column-major float64 4x4 per instance, relative to `rtcCenter`, in tileset (z-up) coordinates. */
|
|
98
|
+
readonly matrices: Float64Array;
|
|
99
|
+
readonly length: number;
|
|
100
|
+
readonly rtcCenter?: readonly [number, number, number];
|
|
101
|
+
readonly featureTable: FeatureTable;
|
|
102
|
+
readonly batchTable?: BatchTable;
|
|
103
|
+
readonly byteLength: number;
|
|
104
|
+
}
|
|
105
|
+
/** Composite (cmpt) content: inner tiles, each with its own format. */
|
|
106
|
+
export interface CompositeContent {
|
|
107
|
+
readonly type: 'cmpt';
|
|
108
|
+
readonly tiles: readonly TileContent[];
|
|
109
|
+
readonly byteLength: number;
|
|
110
|
+
}
|
|
111
|
+
/** Any parsed tile content. */
|
|
112
|
+
export type TileContent = ModelContent | PointsContent | InstancesContent | CompositeContent;
|
|
113
|
+
/** The four-character magic of binary content, or 'json' for JSON (tileset or glTF), or undefined. */
|
|
114
|
+
export declare function contentMagic(bytes: Uint8Array): 'b3dm' | 'pnts' | 'i3dm' | 'cmpt' | 'glTF' | 'subt' | 'json' | undefined;
|
|
115
|
+
/** Parses Batched 3D Model content. */
|
|
116
|
+
export declare function parseB3dm(bytes: Uint8Array): ModelContent;
|
|
117
|
+
/** Parses Point Cloud content: POSITION or POSITION_QUANTIZED, RGBA / RGB / RGB565, NORMAL / NORMAL_OCT16P, BATCH_ID. */
|
|
118
|
+
export declare function parsePnts(bytes: Uint8Array): PointsContent;
|
|
119
|
+
/** Parses Instanced 3D Model content into one matrix per instance (POSITION, NORMAL_UP / RIGHT, SCALE, EAST_NORTH_UP). */
|
|
120
|
+
export declare function parseI3dm(bytes: Uint8Array, eastNorthUp?: (position: readonly number[]) => Float64Array): InstancesContent;
|
|
121
|
+
/** Parses Composite content (and nested composites, at most `depth` levels deep). */
|
|
122
|
+
export declare function parseCmpt(bytes: Uint8Array, depth?: number): CompositeContent;
|
|
123
|
+
/** Parses any binary tile content (b3dm, pnts, i3dm, cmpt, GLB) by its magic. JSON content is handled by the tileset. */
|
|
124
|
+
export declare function parseContent(bytes: Uint8Array, depth?: number): TileContent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { r as e } from "./errors-D5_2oB8I.js";
|
|
2
|
+
//#region ../shared/glb.js
|
|
3
|
+
var t = 1179937895, n = 1313821514, r = 5130562, i = (t) => e(`GLB ${t}; pass a whole glTF 2.0 GLB file`, "failed"), a = (e) => e.length >= 4 && new DataView(e.buffer, e.byteOffset, 4).getUint32(0, !0) === 1179937895;
|
|
4
|
+
function o(e) {
|
|
5
|
+
if (e.length < 20) throw i(`needs at least 20 bytes for its 12-byte file header and 8-byte JSON chunk header; received ${e.length}`);
|
|
6
|
+
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint32(0, !0), r = t.getUint32(4, !0), a = t.getUint32(8, !0);
|
|
7
|
+
if (n !== 1179937895) throw i(`header magic 0x${n.toString(16)} is not glTF (0x46546c67)`);
|
|
8
|
+
if (r !== 2) throw i(`header version ${r} is unsupported; use version 2`);
|
|
9
|
+
if (a !== e.length) throw i(`header total length ${a} bytes differs from the received ${e.length} bytes`);
|
|
10
|
+
let o = [];
|
|
11
|
+
for (let n = 12; n < e.length;) {
|
|
12
|
+
if (n + 8 > e.length) throw i(`ends inside the 8-byte chunk header at byte ${n}`);
|
|
13
|
+
let r = t.getUint32(n, !0), a = t.getUint32(n + 4, !0), s = n + 8 + r;
|
|
14
|
+
if (r % 4) throw i(`chunk length ${r} at byte ${n} must have 4-byte alignment`);
|
|
15
|
+
if (s > e.length) throw i(`chunk length ${r} at byte ${n} extends past the ${e.length}-byte file`);
|
|
16
|
+
if (o.length === 0 != (a === 1313821514) || a === 5130562 && o.length !== 1) throw i("chunks must be JSON first, then at most one BIN second; export the file again");
|
|
17
|
+
o.push({
|
|
18
|
+
type: a,
|
|
19
|
+
data: e.subarray(n + 8, s)
|
|
20
|
+
}), n = s;
|
|
21
|
+
}
|
|
22
|
+
return o;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { a, o as i, n, t as r, r as t };
|
package/dist/height.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
2
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
3
|
+
import { Raycaster } from '@margoengine/bvh';
|
|
4
|
+
import type { TilesRenderer } from './renderer.js';
|
|
5
|
+
/** Options of {@link tilesHeightQuery}. */
|
|
6
|
+
export interface TilesHeightOptions {
|
|
7
|
+
/** Metres above the ellipsoid each query ray starts from; above the highest ground the tileset holds. Default 9000. */
|
|
8
|
+
top?: number;
|
|
9
|
+
/** Metres below the ellipsoid each ray still looks (ocean floors in bathymetry tiles). Default 12000. */
|
|
10
|
+
bottom?: number;
|
|
11
|
+
/** Raycaster to use (layers, side, filter). Default a new one. */
|
|
12
|
+
raycaster?: Raycaster;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A height query over a tileset: `(longitude, latitude)` in RADIANS gives the height above the WGS84 ellipsoid, in
|
|
16
|
+
* metres, of the first surface of the tiles drawn now straight below `top`, or undefined where no drawn tile lies (not
|
|
17
|
+
* loaded yet, or a gap). It reads the renderer's current selection each call, so it follows streaming, and it is what
|
|
18
|
+
* `GeospatialControls` takes as `heightAt` for clearance over tiles.
|
|
19
|
+
*/
|
|
20
|
+
export declare function tilesHeightQuery(engine: EngineKernel, renderer: TilesRenderer, options?: TilesHeightOptions): (longitude: number, latitude: number) => number | undefined;
|
package/dist/height.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { n as e } from "./errors-D5_2oB8I.js";
|
|
2
|
+
import { cartographicToEcef as t } from "@margoengine/math/geo";
|
|
3
|
+
import { Raycaster as n } from "@margoengine/bvh";
|
|
4
|
+
//#region src/height.ts
|
|
5
|
+
function r(r, i, a = {}) {
|
|
6
|
+
let o = a.top ?? 9e3, s = a.bottom ?? 12e3, c = a.raycaster ?? new n();
|
|
7
|
+
if (!Number.isFinite(o) || !(s >= 0) || !Number.isFinite(s) || !(o > -s)) throw e("tilesHeightQuery needs a finite top above -bottom and a finite bottom >= 0; use the defaults", "tiles-height");
|
|
8
|
+
return (e, n) => {
|
|
9
|
+
if (!Number.isFinite(e) || !Number.isFinite(n)) return;
|
|
10
|
+
let a = [];
|
|
11
|
+
for (let e of i.last.selected) {
|
|
12
|
+
let t = e.renderable?.model;
|
|
13
|
+
t && a.push(t);
|
|
14
|
+
}
|
|
15
|
+
if (!a.length) return;
|
|
16
|
+
let l = i.toWorld(t(e, n, o)), u = i.toWorld(t(e, n, o - 1)), d = [
|
|
17
|
+
u[0] - l[0],
|
|
18
|
+
u[1] - l[1],
|
|
19
|
+
u[2] - l[2]
|
|
20
|
+
], f = Math.hypot(...d);
|
|
21
|
+
c.set(l, [
|
|
22
|
+
d[0] / f,
|
|
23
|
+
d[1] / f,
|
|
24
|
+
d[2] / f
|
|
25
|
+
]), c.near = 0, c.far = (o + s) * f, c.firstHitOnly = !0;
|
|
26
|
+
let [p] = c.intersectObjects(r, a);
|
|
27
|
+
return p ? o - p.distance / f : void 0;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { r as tilesHeightQuery };
|
package/dist/i3dm.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TilesInstancesDrawer } from './renderer.js';
|
|
2
|
+
/**
|
|
3
|
+
* Node-space matrices for every instance of one glTF node: the i3dm instance transform `I_i` (tileset z-up, relative
|
|
4
|
+
* to `center`), after the glTF y-up to z-up turn, moved into the node's own space so that
|
|
5
|
+
* `root x N x J_i = root x translate(center) x I_i x Y_UP_TO_Z_UP x N`, where the model root sits at
|
|
6
|
+
* `translate(center)` and `N` is the node's matrix in the model. Returns 16 float64 values per instance.
|
|
7
|
+
*/
|
|
8
|
+
export declare function instanceMatrices(matrices: ArrayLike<number>, node: ArrayLike<number>, center?: ArrayLike<number>): Float64Array;
|
|
9
|
+
/** Mean instance position (float64) of i3dm instance matrices: where the model root is placed, so float32 rows stay small. */
|
|
10
|
+
export declare function instanceCenter(matrices: ArrayLike<number>): [number, number, number];
|
|
11
|
+
/**
|
|
12
|
+
* Draws i3dm content: pass it as `TilesRenderer.load(engine, url, { i3dm })`. Each primitive of the instanced glTF
|
|
13
|
+
* draws all `INSTANCES_LENGTH` instances in one instanced draw (gltf/pbr's `PBRInstances`). An external glTF
|
|
14
|
+
* (`gltfFormat` 0) is fetched with the tileset's own fetch, relative to the tile's content URL.
|
|
15
|
+
*/
|
|
16
|
+
export declare const i3dm: TilesInstancesDrawer;
|