@margoengine/points 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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +794 -3
  4. package/dist/attributes-DNc-1pdr.js +256 -0
  5. package/dist/attributes.d.ts +48 -0
  6. package/dist/clip.d.ts +55 -0
  7. package/dist/clip.js +122 -0
  8. package/dist/cloud-B4O_G-Df.js +545 -0
  9. package/dist/cloud.d.ts +155 -0
  10. package/dist/color.d.ts +1 -0
  11. package/dist/copc.d.ts +55 -0
  12. package/dist/copc.js +130 -0
  13. package/dist/depth-video.d.ts +98 -0
  14. package/dist/depth-video.js +164 -0
  15. package/dist/e57.d.ts +163 -0
  16. package/dist/e57.js +624 -0
  17. package/dist/frame.d.ts +9 -0
  18. package/dist/index.d.ts +16 -0
  19. package/dist/index.js +1246 -0
  20. package/dist/las.d.ts +213 -0
  21. package/dist/las.js +500 -0
  22. package/dist/laz.d.ts +50 -0
  23. package/dist/laz.js +1025 -0
  24. package/dist/material.d.ts +167 -0
  25. package/dist/math.d.ts +103 -0
  26. package/dist/octree.d.ts +182 -0
  27. package/dist/octree.js +360 -0
  28. package/dist/pick.d.ts +76 -0
  29. package/dist/pick.js +192 -0
  30. package/dist/plugin.d.ts +235 -0
  31. package/dist/potree.d.ts +70 -0
  32. package/dist/potree.js +451 -0
  33. package/dist/range-BQuJAjUM.js +23 -0
  34. package/dist/range.d.ts +4 -0
  35. package/dist/screen-door-CALlYs39.js +7 -0
  36. package/dist/shaders-Deu8H36P.js +278 -0
  37. package/dist/shaders.d.ts +52 -0
  38. package/dist/shared/fog.d.ts +33 -0
  39. package/dist/shared/pass.d.ts +53 -0
  40. package/dist/shared/selection-mask.d.ts +52 -0
  41. package/dist/shared/style-expression.d.ts +18 -0
  42. package/dist/sprites.d.ts +78 -0
  43. package/dist/storage-limit.d.ts +6 -0
  44. package/dist/style.d.ts +124 -0
  45. package/dist/style.js +708 -0
  46. package/dist/surfels.d.ts +95 -0
  47. package/dist/surfels.js +538 -0
  48. package/dist/survey-DToZwkJv.js +46 -0
  49. package/dist/survey.d.ts +10 -0
  50. package/dist/tier-BcFbLPVT.js +91 -0
  51. package/dist/tier.d.ts +6 -0
  52. package/package.json +96 -6
package/dist/e57.js ADDED
@@ -0,0 +1,624 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ //#region src/e57.ts
3
+ var t = 1024, n = 1020, r = /* @__PURE__ */ (() => {
4
+ let e = /* @__PURE__ */ new Uint32Array(256);
5
+ for (let t = 0; t < 256; t++) {
6
+ let n = t;
7
+ for (let e = 0; e < 8; e++) n = n & 1 ? 2197175160 ^ n >>> 1 : n >>> 1;
8
+ e[t] = n >>> 0;
9
+ }
10
+ return e;
11
+ })();
12
+ function i(e) {
13
+ let t = 4294967295;
14
+ for (let n = 0; n < e.length; n++) t = r[(t ^ e[n]) & 255] ^ t >>> 8;
15
+ return (t ^ 4294967295) >>> 0;
16
+ }
17
+ var a = {
18
+ lt: "<",
19
+ gt: ">",
20
+ amp: "&",
21
+ quot: "\"",
22
+ apos: "'"
23
+ }, o = (e) => e.replace(/&(#x[0-9a-f]+|#\d+|lt|gt|amp|quot|apos);/gi, (e, t) => t[0] === "#" ? String.fromCodePoint(t[1] === "x" || t[1] === "X" ? Number.parseInt(t.slice(2), 16) : Number(t.slice(1))) : a[t]);
24
+ function s(e) {
25
+ let t = 0, n = (e) => {
26
+ throw TypeError(`Invalid E57 XML: ${e} at character ${t}; the file is corrupt`);
27
+ }, r = () => {
28
+ for (;;) {
29
+ for (; t < e.length && /\s/.test(e[t]);) t++;
30
+ let r;
31
+ if (e.startsWith("<?", t)) r = (e.indexOf("?>", t) + 1 || n("unclosed declaration")) + 1;
32
+ else if (e.startsWith("<!--", t)) r = (e.indexOf("-->", t) + 1 || n("unclosed comment")) + 2;
33
+ else return;
34
+ t = r;
35
+ }
36
+ }, i = (r) => {
37
+ r > 64 && n("nesting deeper than 64 levels"), e[t] !== "<" && n("expected an element");
38
+ let a = /^<([A-Za-z_][\w.:-]*)/.exec(e.slice(t, t + 256)) ?? n("bad element name"), s = a[1];
39
+ t += a[0].length;
40
+ let c = {};
41
+ for (;;) {
42
+ for (; /\s/.test(e[t] ?? "");) t++;
43
+ if (e[t] === "/" && e[t + 1] === ">") return t += 2, {
44
+ name: s,
45
+ attributes: c,
46
+ children: [],
47
+ text: ""
48
+ };
49
+ if (e[t] === ">") {
50
+ t++;
51
+ break;
52
+ }
53
+ let r = /^([A-Za-z_][\w.:-]*)\s*=\s*("([^"]*)"|'([^']*)')/.exec(e.slice(t, t + 4096)) ?? n("bad attribute");
54
+ c[r[1]] = o(r[3] ?? r[4]), t += r[0].length;
55
+ }
56
+ let l = [], u = "";
57
+ for (;;) {
58
+ if (t >= e.length && n(`unclosed <${s}>`), e.startsWith("</", t)) {
59
+ let r = e.indexOf(">", t);
60
+ return (r < 0 || e.slice(t + 2, r).trim() !== s) && n(`mismatched </${s}>`), t = r + 1, {
61
+ name: s,
62
+ attributes: c,
63
+ children: l,
64
+ text: o(u).trim()
65
+ };
66
+ }
67
+ if (e.startsWith("<![CDATA[", t)) {
68
+ let r = e.indexOf("]]>", t);
69
+ r < 0 && n("unclosed CDATA"), u += e.slice(t + 9, r), t = r + 3;
70
+ } else if (e.startsWith("<!--", t)) {
71
+ let r = e.indexOf("-->", t);
72
+ r < 0 && n("unclosed comment"), t = r + 3;
73
+ } else if (e[t] === "<") l.push(i(r + 1));
74
+ else {
75
+ let r = e.indexOf("<", t);
76
+ r < 0 && n(`unclosed <${s}>`), u += e.slice(t, r), t = r;
77
+ }
78
+ }
79
+ };
80
+ return r(), i(0);
81
+ }
82
+ function c(e) {
83
+ if (e.byteLength < 48) throw RangeError("E57 file shorter than its 48-byte header; the file is truncated");
84
+ if (String.fromCharCode(...e.subarray(0, 8)) !== "ASTM-E57") throw TypeError("Not an E57 file (no ASTM-E57 signature); pass a .e57 file");
85
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = (e) => Number(n.getBigUint64(e, !0)), i = {
86
+ versionMajor: n.getUint32(8, !0),
87
+ versionMinor: n.getUint32(12, !0),
88
+ physicalLength: r(16),
89
+ xmlOffset: r(24),
90
+ xmlLength: r(32),
91
+ pageSize: r(40)
92
+ };
93
+ if (i.versionMajor !== 1) throw TypeError(`Unsupported E57 version ${i.versionMajor}.${i.versionMinor}; read version 1`);
94
+ if (i.pageSize !== t) throw TypeError(`Unsupported E57 page size ${i.pageSize}; the standard fixes it at 1024`);
95
+ if (i.physicalLength > e.byteLength) throw RangeError(`E57 file is ${e.byteLength} bytes, its header says ${i.physicalLength}; the file is truncated`);
96
+ return i;
97
+ }
98
+ var l = (e) => Math.floor(e / t) * n + e % t, u = class {
99
+ constructor(e, r, a) {
100
+ this.bytes = e, this.physicalLength = r;
101
+ let o = Math.floor(r / t);
102
+ if (r % t) throw RangeError("E57 file length is not a whole number of 1024-byte pages; the file is truncated");
103
+ if (this.length = o * n, a) for (let r = 0; r < o; r++) {
104
+ let a = r * t, o = new DataView(e.buffer, e.byteOffset + a + n, 4).getUint32(0, !1);
105
+ if (i(e.subarray(a, a + n)) !== o) throw RangeError(`E57 page ${r} fails its CRC-32C checksum; the file is corrupt (pass verifyChecksums: false to read it anyway)`);
106
+ }
107
+ }
108
+ read(e, r) {
109
+ if (!Number.isFinite(e) || e < 0 || r < 0 || e + r > this.length) throw RangeError(`E57 read of ${r} bytes at logical ${e} passes the file; it is truncated or corrupt`);
110
+ let i = new Uint8Array(r), a = 0;
111
+ for (; a < r;) {
112
+ let o = e + a, s = Math.floor(o / n), c = o % n, l = Math.min(n - c, r - a);
113
+ i.set(this.bytes.subarray(s * t + c, s * t + c + l), a), a += l;
114
+ }
115
+ return i;
116
+ }
117
+ };
118
+ function d(e, t) {
119
+ return e.children.find((e) => e.name === t);
120
+ }
121
+ function f(e, t = 0) {
122
+ if (!e) return t;
123
+ let n = Number(e.text);
124
+ return Number.isFinite(n) ? n : t;
125
+ }
126
+ function p(e) {
127
+ let t = e.attributes.type, n = e.attributes;
128
+ if (t === "Float") {
129
+ let r = n.precision === "single" ? 32 : 64;
130
+ return {
131
+ name: e.name,
132
+ type: t,
133
+ bits: r,
134
+ minimum: Number(n.minimum ?? -Infinity),
135
+ maximum: Number(n.maximum ?? Infinity),
136
+ scale: 1,
137
+ offset: 0
138
+ };
139
+ }
140
+ if (t === "ScaledInteger" || t === "Integer") {
141
+ let r = Number(n.minimum ?? -(2 ** 63)), i = Number(n.maximum ?? 2 ** 63 - 1);
142
+ if (!Number.isFinite(r) || !Number.isFinite(i) || i < r) throw TypeError(`E57 field ${e.name} has an invalid range; the file is corrupt`);
143
+ let a = i - r, o = a <= 0 ? 0 : Math.ceil(Math.log2(a + 1));
144
+ if (o > 52) throw TypeError(`E57 field ${e.name} needs ${o} bits; integers above 52 bits are not supported`);
145
+ return {
146
+ name: e.name,
147
+ type: t,
148
+ bits: o,
149
+ minimum: r,
150
+ maximum: i,
151
+ scale: t === "ScaledInteger" ? Number(n.scale ?? 1) : 1,
152
+ offset: t === "ScaledInteger" ? Number(n.offset ?? 0) : 0
153
+ };
154
+ }
155
+ }
156
+ function m(e, t, n, r, i) {
157
+ let a = e.read(l(t), 32), o = new DataView(a.buffer);
158
+ if (o.getUint8(0) !== 1) throw TypeError("E57 compressed vector section has the wrong section id; the file is corrupt");
159
+ let s = Number(o.getBigUint64(8, !0)), c = Number(o.getBigUint64(16, !0)), u = r.map(() => new Float64Array(n)), d = r.map(() => 0), f = r.map(() => ({
160
+ value: 0n,
161
+ bits: 0
162
+ })), p = l(c), m = l(t) + s, g = 0;
163
+ for (; d.some((e, t) => e < n && r[t].bits > 0) && p < m;) {
164
+ ++g % 64 == 0 && i?.throwIfAborted();
165
+ let t = e.read(p, 6), a = new DataView(t.buffer), o = a.getUint8(0), s = a.getUint16(2, !0) + 1;
166
+ if (o !== 1) {
167
+ if (p += s, s < 4) throw RangeError("E57 packet length is invalid; the file is corrupt");
168
+ continue;
169
+ }
170
+ let c = e.read(p, s), l = new DataView(c.buffer), m = l.getUint16(4, !0);
171
+ if (m !== r.length) throw TypeError(`E57 data packet has ${m} bytestreams for ${r.length} fields; the file is corrupt`);
172
+ let _ = 6 + m * 2;
173
+ for (let e = 0; e < m; e++) {
174
+ let t = l.getUint16(6 + e * 2, !0);
175
+ if (_ + t > s) throw RangeError("E57 bytestream runs past its packet; the file is corrupt");
176
+ h(c.subarray(_, _ + t), r[e], u[e], d, e, f[e], n), _ += t;
177
+ }
178
+ p += s;
179
+ }
180
+ for (let e = 0; e < r.length; e++) if (r[e].bits === 0) u[e].fill(r[e].minimum * r[e].scale + r[e].offset);
181
+ else if (d[e] < n) throw RangeError(`E57 field ${r[e].name} holds ${d[e]} of ${n} values; the file is truncated`);
182
+ return u;
183
+ }
184
+ function h(e, t, n, r, i, a, o) {
185
+ if (t.type === "Float") {
186
+ let s = t.bits / 8, c = new DataView(e.buffer, e.byteOffset, e.byteLength), l = 0;
187
+ if (a.bits) {
188
+ let t = s - a.bits / 8, c = new Uint8Array(s);
189
+ for (let e = 0; e < a.bits / 8; e++) c[e] = Number(a.value >> BigInt(e * 8) & 255n);
190
+ c.set(e.subarray(0, t), a.bits / 8);
191
+ let u = new DataView(c.buffer);
192
+ r[i] < o && (n[r[i]++] = s === 4 ? u.getFloat32(0, !0) : u.getFloat64(0, !0)), l = t, a.value = 0n, a.bits = 0;
193
+ }
194
+ for (; l + s <= e.length && r[i] < o; l += s) n[r[i]++] = s === 4 ? c.getFloat32(l, !0) : c.getFloat64(l, !0);
195
+ for (let t = 0; l + t < e.length; t++) a.value |= BigInt(e[l + t]) << BigInt(a.bits), a.bits += 8;
196
+ return;
197
+ }
198
+ let s = t.bits, c = (1n << BigInt(s)) - 1n, l = a.value, u = a.bits;
199
+ for (let a = 0; a < e.length; a++) for (l |= BigInt(e[a]) << BigInt(u), u += 8; u >= s && r[i] < o;) {
200
+ let e = Number(l & c);
201
+ l >>= BigInt(s), u -= s, n[r[i]++] = (e + t.minimum) * t.scale + t.offset;
202
+ }
203
+ a.value = l, a.bits = u;
204
+ }
205
+ function g(e) {
206
+ let t = d(e, "pose"), n = t && d(t, "rotation"), r = t && d(t, "translation"), [i, a, o, s] = n ? [
207
+ f(d(n, "w"), 1),
208
+ f(d(n, "x")),
209
+ f(d(n, "y")),
210
+ f(d(n, "z"))
211
+ ] : [
212
+ 1,
213
+ 0,
214
+ 0,
215
+ 0
216
+ ], c = Math.hypot(i, a, o, s) || 1;
217
+ return [i, a, o, s] = [
218
+ i / c,
219
+ a / c,
220
+ o / c,
221
+ s / c
222
+ ], {
223
+ rotation: [
224
+ i,
225
+ a,
226
+ o,
227
+ s
228
+ ],
229
+ translation: r ? [
230
+ f(d(r, "x")),
231
+ f(d(r, "y")),
232
+ f(d(r, "z"))
233
+ ] : [
234
+ 0,
235
+ 0,
236
+ 0
237
+ ]
238
+ };
239
+ }
240
+ function _(e, t, n) {
241
+ let r = Number(t.attributes.fileOffset), i = Number(t.attributes.length);
242
+ if (!Number.isFinite(r) || !Number.isInteger(i) || i < 0) throw TypeError(`E57 ${n} has an invalid Blob offset or length; the file is corrupt`);
243
+ let a = l(r);
244
+ if (e.read(a, 1)[0] !== 0) throw TypeError(`E57 ${n} Blob section has the wrong section id; the file is corrupt`);
245
+ return e.read(a + 16, i);
246
+ }
247
+ var v = [
248
+ "pinholeRepresentation",
249
+ "sphericalRepresentation",
250
+ "cylindricalRepresentation",
251
+ "visualReferenceRepresentation"
252
+ ];
253
+ function y(e, t, n) {
254
+ let r = [];
255
+ for (let [i, a] of (t?.children ?? []).entries()) {
256
+ n?.throwIfAborted();
257
+ let t = a.children.find((e) => v.includes(e.name));
258
+ if (!t) continue;
259
+ let o = `image ${i}`, s = d(t, "jpegImage"), c = s ?? d(t, "pngImage");
260
+ if (!c) continue;
261
+ let l = d(t, "imageMask"), u = {};
262
+ for (let e of t.children) (e.attributes.type === "Float" || e.attributes.type === "Integer" || e.attributes.type === "ScaledInteger") && (u[e.name] = f(e));
263
+ let p = u.imageWidth ?? 0, m = u.imageHeight ?? 0;
264
+ delete u.imageWidth, delete u.imageHeight, r.push({
265
+ name: d(a, "name")?.text ?? `image ${i}`,
266
+ guid: d(a, "guid")?.text ?? "",
267
+ associatedScanGuid: d(a, "associatedData3DGuid")?.text || void 0,
268
+ description: d(a, "description")?.text || void 0,
269
+ projection: t.name.replace("Representation", ""),
270
+ width: p,
271
+ height: m,
272
+ format: s ? "jpeg" : "png",
273
+ mime: s ? "image/jpeg" : "image/png",
274
+ data: _(e, c, o),
275
+ mask: l ? _(e, l, `${o} mask`) : void 0,
276
+ pose: g(a),
277
+ parameters: u
278
+ });
279
+ }
280
+ return r;
281
+ }
282
+ function b(t, n = {}) {
283
+ n.signal?.throwIfAborted();
284
+ let r = t instanceof Uint8Array ? t : new Uint8Array(t), i = c(r), a = new u(r, i.physicalLength, n.verifyChecksums ?? !0), o = a.read(l(i.xmlOffset), i.xmlLength), h = s(new TextDecoder().decode(o));
285
+ if (h.name !== "e57Root") throw TypeError(`E57 XML root is <${h.name}>, not <e57Root>; the file is corrupt`);
286
+ let g = d(h, "data3D"), _ = [];
287
+ for (let [t, r] of (g?.children ?? []).entries()) {
288
+ n.signal?.throwIfAborted();
289
+ let i = d(r, "points");
290
+ if (!i || i.attributes.type !== "CompressedVector") continue;
291
+ let o = Number(i.attributes.recordCount ?? 0), s = Number(i.attributes.fileOffset);
292
+ if (!Number.isInteger(o) || o < 0 || !Number.isFinite(s)) throw TypeError(`E57 scan ${t} has an invalid recordCount or fileOffset; the file is corrupt`);
293
+ let c = d(i, "codecs");
294
+ if (c && c.children.length) throw new e("unsupported", `E57 scan ${t} uses a codec other than bitPack; re-export it with the default codec`);
295
+ let l = d(i, "prototype");
296
+ if (!l) throw TypeError(`E57 scan ${t} has no prototype; the file is corrupt`);
297
+ let u = l.children.map((t) => {
298
+ let n = p(t);
299
+ if (!n) throw new e("unsupported", `E57 field ${t.name} of type ${t.attributes.type} is not supported; use Float, ScaledInteger or Integer fields`);
300
+ return n;
301
+ }), h = u.reduce((e, t) => e + t.bits, 0);
302
+ if (o > 2 ** 31 || o * h > a.length * 8) throw RangeError(`E57 scan ${t} claims ${o} records, more than the file can hold; the file is corrupt`);
303
+ let g = m(a, s, o, u, n.signal), v = (e) => g[u.findIndex((t) => t.name === e)], y = v("cartesianX"), b = v("cartesianY"), x = v("cartesianZ"), S = v("sphericalRange"), C = v("sphericalAzimuth"), w = v("sphericalElevation"), T = new Float64Array(o * 3), E;
304
+ if (y && b && x) {
305
+ for (let e = 0; e < o; e++) T.set([
306
+ y[e],
307
+ b[e],
308
+ x[e]
309
+ ], e * 3);
310
+ E = v("cartesianInvalidState");
311
+ } else if (S && C && w) {
312
+ for (let e = 0; e < o; e++) {
313
+ let t = S[e], n = Math.cos(w[e]);
314
+ T.set([
315
+ t * n * Math.cos(C[e]),
316
+ t * n * Math.sin(C[e]),
317
+ t * Math.sin(w[e])
318
+ ], e * 3);
319
+ }
320
+ E = v("sphericalInvalidState");
321
+ } else throw new e("unsupported", `E57 scan ${t} has neither cartesian nor spherical coordinates; it holds no points this reader can place`);
322
+ let D = d(r, "pose"), O = d(D ?? r, "rotation"), k = d(D ?? r, "translation"), [A, j, M, N] = O ? [
323
+ f(d(O, "w"), 1),
324
+ f(d(O, "x")),
325
+ f(d(O, "y")),
326
+ f(d(O, "z"))
327
+ ] : [
328
+ 1,
329
+ 0,
330
+ 0,
331
+ 0
332
+ ], P = Math.hypot(A, j, M, N) || 1;
333
+ A /= P, j /= P, M /= P, N /= P;
334
+ let F = k ? [
335
+ f(d(k, "x")),
336
+ f(d(k, "y")),
337
+ f(d(k, "z"))
338
+ ] : [
339
+ 0,
340
+ 0,
341
+ 0
342
+ ], I = new Float64Array(o * 3), L = new Uint8Array(o), R = [
343
+ 1 - 2 * (M * M + N * N),
344
+ 2 * (j * M - A * N),
345
+ 2 * (j * N + A * M),
346
+ 2 * (j * M + A * N),
347
+ 1 - 2 * (j * j + N * N),
348
+ 2 * (M * N - A * j),
349
+ 2 * (j * N - A * M),
350
+ 2 * (M * N + A * j),
351
+ 1 - 2 * (j * j + M * M)
352
+ ];
353
+ for (let e = 0; e < o; e++) {
354
+ let t = T[e * 3], r = T[e * 3 + 1], i = T[e * 3 + 2];
355
+ I[e * 3] = R[0] * t + R[1] * r + R[2] * i + F[0], I[e * 3 + 1] = R[3] * t + R[4] * r + R[5] * i + F[1], I[e * 3 + 2] = R[6] * t + R[7] * r + R[8] * i + F[2], L[e] = n.keepInvalid || !E || E[e] !== 2 ? 1 : 0;
356
+ }
357
+ let z = v("intensity"), B = d(r, "intensityLimits"), V = u.find((e) => e.name === "intensity"), H = f(d(B ?? r, "intensityMinimum"), V ? V.minimum * V.scale + V.offset : 0), U = f(d(B ?? r, "intensityMaximum"), V ? V.maximum * V.scale + V.offset : 1), W = d(r, "colorLimits"), G = v("colorRed"), K = v("colorGreen"), q = v("colorBlue"), J = [
358
+ "Red",
359
+ "Green",
360
+ "Blue"
361
+ ].map((e) => {
362
+ let t = u.find((t) => t.name === `color${e}`), n = f(d(W ?? r, `color${e}Minimum`), t ? t.minimum * t.scale + t.offset : 0);
363
+ return {
364
+ lo: n,
365
+ scale: 255 / (f(d(W ?? r, `color${e}Maximum`), t ? t.maximum * t.scale + t.offset : 255) - n || 1)
366
+ };
367
+ }), Y = (e, t) => Math.min(255, Math.max(0, Math.round((e - J[t].lo) * J[t].scale))), X = {}, Z = /* @__PURE__ */ new Set([
368
+ "cartesianX",
369
+ "cartesianY",
370
+ "cartesianZ",
371
+ "sphericalRange",
372
+ "sphericalAzimuth",
373
+ "sphericalElevation",
374
+ "intensity",
375
+ "colorRed",
376
+ "colorGreen",
377
+ "colorBlue"
378
+ ]);
379
+ u.forEach((e, t) => {
380
+ Z.has(e.name) || (X[e.name] = g[t]);
381
+ });
382
+ let Q = L.reduce((e, t) => e + t, 0), $ = (e, t, n) => {
383
+ let r = e(Q * t), i = 0;
384
+ for (let e = 0; e < o; e++) L[e] && n(r, i++ * t, e);
385
+ return r;
386
+ };
387
+ _.push({
388
+ scan: {
389
+ name: d(r, "name")?.text ?? `scan ${t}`,
390
+ guid: d(r, "guid")?.text ?? "",
391
+ pose: {
392
+ rotation: [
393
+ A,
394
+ j,
395
+ M,
396
+ N
397
+ ],
398
+ translation: F
399
+ },
400
+ fields: u,
401
+ recordCount: o,
402
+ intensity: z ? $((e) => new Float32Array(e), 1, (e, t, n) => {
403
+ e[t] = (z[n] - H) / (U - H || 1);
404
+ }) : void 0,
405
+ colors: G && K && q ? $((e) => new Uint8Array(e), 4, (e, t, n) => {
406
+ e[t] = Y(G[n], 0), e[t + 1] = Y(K[n], 1), e[t + 2] = Y(q[n], 2), e[t + 3] = 255;
407
+ }) : void 0,
408
+ attributes: Object.fromEntries(Object.entries(X).map(([e, t]) => [e, $((e) => new Float64Array(e), 1, (e, n, r) => e[n] = t[r])]))
409
+ },
410
+ world: I,
411
+ keep: L
412
+ });
413
+ }
414
+ let v = n.origin;
415
+ if (!v) {
416
+ let e = [
417
+ Infinity,
418
+ Infinity,
419
+ Infinity
420
+ ], t = [
421
+ -Infinity,
422
+ -Infinity,
423
+ -Infinity
424
+ ];
425
+ for (let { world: n, keep: r } of _) for (let i = 0; i < r.length; i++) if (r[i]) for (let r = 0; r < 3; r++) {
426
+ let a = n[i * 3 + r];
427
+ a < e[r] && (e[r] = a), a > t[r] && (t[r] = a);
428
+ }
429
+ v = e[0] <= t[0] ? [
430
+ 0,
431
+ 1,
432
+ 2
433
+ ].map((n) => (e[n] + t[n]) / 2) : [
434
+ 0,
435
+ 0,
436
+ 0
437
+ ];
438
+ }
439
+ let b = v;
440
+ return {
441
+ header: i,
442
+ xml: h,
443
+ origin: b,
444
+ scans: _.map(({ scan: e, world: t, keep: n }) => {
445
+ let r = n.reduce((e, t) => e + t, 0), i = new Float32Array(r * 3), a = 0;
446
+ for (let e = 0; e < n.length; e++) n[e] && (i[a * 3] = t[e * 3] - b[0], i[a * 3 + 1] = t[e * 3 + 1] - b[1], i[a * 3 + 2] = t[e * 3 + 2] - b[2], a++);
447
+ return {
448
+ ...e,
449
+ count: r,
450
+ positions: i
451
+ };
452
+ }),
453
+ images: n.images === !1 ? [] : y(a, d(h, "images2D"), n.signal),
454
+ coordinateMetadata: d(h, "coordinateMetadata")?.text
455
+ };
456
+ }
457
+ async function x(t, n = {}) {
458
+ let r = await (n.fetch ?? globalThis.fetch)(t, { signal: n.signal });
459
+ if (!r.ok) throw new e("failed", `GET ${t} answered ${r.status}; check the URL and the server`);
460
+ return b(await r.arrayBuffer(), n);
461
+ }
462
+ function S(e, t = {}) {
463
+ return C(e, t);
464
+ }
465
+ function C(e, r = {}) {
466
+ let a = [], o = 0, s = (e) => {
467
+ a.push(e), o += e.byteLength;
468
+ }, c = (e) => Math.floor(e / n) * t + e % n, l = (e) => `<![CDATA[${e.replaceAll("]]>", "]]]]><![CDATA[>")}]]>`;
469
+ s(/* @__PURE__ */ new Uint8Array(48));
470
+ let u = [], d = Math.min(r.packetBytes ?? 6e4, 64e3);
471
+ for (let [t, n] of e.entries()) {
472
+ let e = !!n.spherical, r = n.spherical ?? n.positions ?? [], i = r.length / 3, a = [];
473
+ (e ? [
474
+ "sphericalRange",
475
+ "sphericalAzimuth",
476
+ "sphericalElevation"
477
+ ] : [
478
+ "cartesianX",
479
+ "cartesianY",
480
+ "cartesianZ"
481
+ ]).forEach((t, o) => {
482
+ if (n.resolution && !e) {
483
+ let e = Infinity, s = -Infinity;
484
+ for (let t = 0; t < i; t++) e = Math.min(e, Math.round(r[t * 3 + o] / n.resolution)), s = Math.max(s, Math.round(r[t * 3 + o] / n.resolution));
485
+ i || (e = s = 0);
486
+ let c = {
487
+ name: t,
488
+ type: "ScaledInteger",
489
+ bits: s > e ? Math.ceil(Math.log2(s - e + 1)) : 0,
490
+ minimum: e,
491
+ maximum: s,
492
+ scale: n.resolution,
493
+ offset: 0
494
+ };
495
+ a.push({
496
+ field: c,
497
+ values: (t) => Math.round(r[t * 3 + o] / n.resolution) - e,
498
+ xml: `<${t} type="ScaledInteger" minimum="${e}" maximum="${s}" scale="${n.resolution}" offset="0"/>`
499
+ });
500
+ } else a.push({
501
+ field: {
502
+ name: t,
503
+ type: "Float",
504
+ bits: 64,
505
+ minimum: -Infinity,
506
+ maximum: Infinity,
507
+ scale: 1,
508
+ offset: 0
509
+ },
510
+ values: (e) => r[e * 3 + o],
511
+ xml: `<${t} type="Float" precision="double"/>`
512
+ });
513
+ });
514
+ let f = (e, t, n) => a.push({
515
+ field: {
516
+ name: e,
517
+ type: "Integer",
518
+ bits: Math.ceil(Math.log2(t + 1)),
519
+ minimum: 0,
520
+ maximum: t,
521
+ scale: 1,
522
+ offset: 0
523
+ },
524
+ values: n,
525
+ xml: `<${e} type="Integer" minimum="0" maximum="${t}"/>`
526
+ });
527
+ if (n.intensity && f("intensity", 65535, (e) => Math.round(Math.min(1, Math.max(0, n.intensity[e])) * 65535)), n.rgb) for (let [e, t] of [
528
+ "colorRed",
529
+ "colorGreen",
530
+ "colorBlue"
531
+ ].entries()) f(t, 255, (t) => n.rgb[t * 3 + e]);
532
+ n.invalid && f(e ? "sphericalInvalidState" : "cartesianInvalidState", 2, (e) => n.invalid[e]);
533
+ let p = a.map(({ field: e, values: t }) => {
534
+ if (e.type === "Float") {
535
+ let e = new Uint8Array(i * 8), n = new DataView(e.buffer);
536
+ for (let e = 0; e < i; e++) n.setFloat64(e * 8, t(e), !0);
537
+ return e;
538
+ }
539
+ let n = new Uint8Array(Math.ceil(i * e.bits / 8)), r = 0;
540
+ for (let a = 0; a < i; a++) {
541
+ let i = BigInt(t(a));
542
+ for (let t = 0; t < e.bits; t++, r++, i >>= 1n) i & 1n && (n[r >> 3] |= 1 << (r & 7));
543
+ }
544
+ return n;
545
+ }), m = o, h = /* @__PURE__ */ new Uint8Array(32);
546
+ s(h);
547
+ let g = o, _ = Math.max(8, Math.floor((d - 6 - a.length * 2) / Math.max(1, a.length) / 8) * 8), v = p.map(() => 0);
548
+ for (; v.some((e, t) => e < p[t].length);) {
549
+ let e = p.map((e, t) => e.subarray(v[t], Math.min(e.length, v[t] + _))), t = 6 + e.length * 2 + e.reduce((e, t) => e + t.length, 0);
550
+ t = Math.ceil(t / 4) * 4;
551
+ let n = new Uint8Array(t), r = new DataView(n.buffer);
552
+ r.setUint8(0, 1), r.setUint16(2, t - 1, !0), r.setUint16(4, e.length, !0);
553
+ let i = 6 + e.length * 2;
554
+ e.forEach((e, t) => {
555
+ r.setUint16(6 + t * 2, e.length, !0), n.set(e, i), i += e.length, v[t] += e.length;
556
+ }), s(n);
557
+ }
558
+ let y = new DataView(h.buffer);
559
+ y.setUint8(0, 1), y.setBigUint64(8, BigInt(o - m), !0), y.setBigUint64(16, BigInt(c(g)), !0);
560
+ let b = n.pose ? `<pose type="Structure"><rotation type="Structure">${[
561
+ "w",
562
+ "x",
563
+ "y",
564
+ "z"
565
+ ].map((e, t) => `<${e} type="Float">${(n.pose.rotation ?? [
566
+ 1,
567
+ 0,
568
+ 0,
569
+ 0
570
+ ])[t]}</${e}>`).join("")}</rotation><translation type="Structure">${[
571
+ "x",
572
+ "y",
573
+ "z"
574
+ ].map((e, t) => `<${e} type="Float">${(n.pose.translation ?? [
575
+ 0,
576
+ 0,
577
+ 0
578
+ ])[t]}</${e}>`).join("")}</translation></pose>` : "", x = n.intensity ? "<intensityLimits type=\"Structure\"><intensityMinimum type=\"Integer\">0</intensityMinimum><intensityMaximum type=\"Integer\">65535</intensityMaximum></intensityLimits>" : "", S = n.rgb ? `<colorLimits type="Structure">${[
579
+ "Red",
580
+ "Green",
581
+ "Blue"
582
+ ].map((e) => `<color${e}Minimum type="Integer">0</color${e}Minimum><color${e}Maximum type="Integer">255</color${e}Maximum>`).join("")}</colorLimits>` : "";
583
+ u.push(`<vectorChild type="Structure"><guid type="String"><![CDATA[scan-${t}]]></guid><name type="String">${l(n.name ?? `scan ${t}`)}</name>${b}${x}${S}<points type="CompressedVector" fileOffset="${c(m)}" recordCount="${i}"><prototype type="Structure">${a.map((e) => e.xml).join("")}</prototype><codecs type="Vector" allowHeterogeneousChildren="1"/></points></vectorChild>`);
584
+ }
585
+ let f = (e) => e ? `<pose type="Structure"><rotation type="Structure">${[
586
+ "w",
587
+ "x",
588
+ "y",
589
+ "z"
590
+ ].map((t, n) => `<${t} type="Float">${(e.rotation ?? [
591
+ 1,
592
+ 0,
593
+ 0,
594
+ 0
595
+ ])[n]}</${t}>`).join("")}</rotation><translation type="Structure">${[
596
+ "x",
597
+ "y",
598
+ "z"
599
+ ].map((t, n) => `<${t} type="Float">${(e.translation ?? [
600
+ 0,
601
+ 0,
602
+ 0
603
+ ])[n]}</${t}>`).join("")}</translation></pose>` : "", p = (e, t) => {
604
+ let n = Math.ceil((16 + t.length) / 4) * 4, r = new Uint8Array(n);
605
+ new DataView(r.buffer).setBigUint64(8, BigInt(n), !0), r.set(t, 16);
606
+ let i = o;
607
+ return s(r), `<${e} type="Blob" fileOffset="${c(i)}" length="${t.length}"/>`;
608
+ }, m = (r.images ?? []).map((e, t) => {
609
+ let n = `${e.projection}Representation`, r = Object.entries(e.parameters ?? {}).map(([e, t]) => `<${e} type="Float">${t}</${e}>`).join(""), i = p(e.format === "jpeg" ? "jpegImage" : "pngImage", e.data), a = e.mask ? p("imageMask", e.mask) : "";
610
+ return `<vectorChild type="Structure"><guid type="String"><![CDATA[image-${t}]]></guid><name type="String">${l(e.name ?? `image ${t}`)}</name>${e.scan === void 0 ? "" : `<associatedData3DGuid type="String"><![CDATA[scan-${e.scan}]]></associatedData3DGuid>`}${f(e.pose)}<${n} type="Structure">${i}${a}<imageWidth type="Integer">${e.width}</imageWidth><imageHeight type="Integer">${e.height}</imageHeight>${r}</${n}></vectorChild>`;
611
+ }), h = new TextEncoder().encode(`<?xml version="1.0" encoding="UTF-8"?>\n<e57Root type="Structure" xmlns="http://www.astm.org/COMMIT/E57/2010-e57-v1.0"><formatName type="String"><![CDATA[ASTM E57 3D Imaging Data File]]></formatName><guid type="String"><![CDATA[margo]]></guid><versionMajor type="Integer">1</versionMajor><versionMinor type="Integer">0</versionMinor><data3D type="Vector" allowHeterogeneousChildren="1">${u.join("")}</data3D><images2D type="Vector" allowHeterogeneousChildren="1">${m.join("")}</images2D></e57Root>`), g = o;
612
+ s(h);
613
+ let _ = Math.ceil(o / n), v = new Uint8Array(_ * t), y = new Uint8Array(_ * n), b = 0;
614
+ for (let e of a) y.set(e, b), b += e.byteLength;
615
+ let x = new DataView(y.buffer);
616
+ y.set(new TextEncoder().encode("ASTM-E57")), x.setUint32(8, 1, !0), x.setUint32(12, 0, !0), x.setBigUint64(16, BigInt(v.byteLength), !0), x.setBigUint64(24, BigInt(c(g)), !0), x.setBigUint64(32, BigInt(h.byteLength), !0), x.setBigUint64(40, BigInt(t), !0);
617
+ for (let e = 0; e < _; e++) {
618
+ let r = y.subarray(e * n, (e + 1) * n);
619
+ v.set(r, e * t), new DataView(v.buffer).setUint32(e * t + n, i(r), !1);
620
+ }
621
+ return v;
622
+ }
623
+ //#endregion
624
+ export { i as crc32c, x as loadE57, b as parseE57, s as parseXML, c as readE57Header, S as writeE57, C as writeE57Document };
@@ -0,0 +1,9 @@
1
+ import type { Camera } from '@margoengine/core';
2
+ /**
3
+ * Fills the frame uniform of the point shaders (`f`, 36 floats) for a view of `width` x `height` pixels drawn to a
4
+ * target of `format`; `view` is a scratch matrix.
5
+ * Returns whether the camera is orthographic: a clip matrix whose w does not depend on position, such as
6
+ * @margoengine/cameras makes. Pixels per world unit then come from the y row's length, and depth is linear: depth.y is
7
+ * NDC per world unit and the EDL and sphere value is 1 + distance from the near plane.
8
+ */
9
+ export declare function fillFrame(f: Float32Array, view: Float32Array, camera: Camera, width: number, height: number, format: string): boolean;
@@ -0,0 +1,16 @@
1
+ export { PointsPlugin } from './plugin.js';
2
+ export type { PointsPluginOptions, PointsPickOptions, PointsPickResult } from './plugin.js';
3
+ export { PointCloud } from './cloud.js';
4
+ export type { PointCloudData, PointCloudOptions, PointChannel } from './cloud.js';
5
+ export { SpriteBatch, SPRITE_STRIDE } from './sprites.js';
6
+ export type { SpriteOptions, SpriteBatchOptions } from './sprites.js';
7
+ export { PointsMaterial, SpriteMaterial } from './material.js';
8
+ export type { PointsMaterialOptions, SpriteMaterialOptions, BaseMaterialOptions, PointsTextureSource, PointsBlending, PointShape, PointShading, } from './material.js';
9
+ export { buildBlocks, expandBlockBounds, worldBox, boxInFrustum, cullBlocks, screenArea, allocateBudget, projectToPixels, pickPoint, boxScreenRect, packColors, mergeRanges, atlasRect, random, NO_BLOCK, } from './math.js';
10
+ export type { PointBlocks, PickRange, PointsPickHit } from './math.js';
11
+ export { ASPRS_CLASSES, CLASSIFICATION_COLORS, ELEVATION_STOPS, classificationColors, rampColors, rgb16ToRgba8, measurePointDistance, measurePath, measureArea, measureHeight, measureAngle, } from './attributes.js';
12
+ export type { ClassificationColorOptions, RampOptions } from './attributes.js';
13
+ export { parseColor } from './color.js';
14
+ export type { ColorInput } from './color.js';
15
+ export type { FogLike } from './shared/fog.js';
16
+ export type { MaskStyle } from './shared/selection-mask.js';