@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
@@ -0,0 +1,545 @@
1
+ import { t as e } from "./screen-door-CALlYs39.js";
2
+ import { MargoError as t } from "@margoengine/math/errors";
3
+ import { createScreenPoint as n, projectPoint as r } from "@margoengine/math/mat4";
4
+ import { createRandom as i } from "@margoengine/math/mathutils";
5
+ import { parseColor as a } from "@margoengine/math/color";
6
+ //#region src/math.ts
7
+ var o = n(), s = 4294967295, c = i;
8
+ function l(e, t, n, r, i, a) {
9
+ for (; n > t;) {
10
+ let o = t + n >>> 1, s = i[e[t] * 3 + a], c = i[e[o] * 3 + a], l = i[e[n] * 3 + a], u = s < c ? c < l ? c : s < l ? l : s : s < l ? s : c < l ? l : c, d = t, f = n;
11
+ for (; d <= f;) {
12
+ for (; i[e[d] * 3 + a] < u;) d++;
13
+ for (; i[e[f] * 3 + a] > u;) f--;
14
+ if (d <= f) {
15
+ let t = e[d];
16
+ e[d] = e[f], e[f] = t, d++, f--;
17
+ }
18
+ }
19
+ if (r <= f) n = f;
20
+ else if (r >= d) t = d;
21
+ else return;
22
+ }
23
+ }
24
+ function u(e, t, n = 16384, r = 1) {
25
+ if (!Number.isInteger(t) || t < 0 || e.length < t * 3) throw RangeError("positions holds fewer than count points; pass an integer count of at most positions.length / 3.");
26
+ if (!Number.isInteger(n) || n < 1) throw RangeError("blockSize must be a positive integer");
27
+ let i = new Uint32Array(t), a = 0;
28
+ for (let n = 0; n < t; n++) {
29
+ let t = e[n * 3], r = e[n * 3 + 1], o = e[n * 3 + 2];
30
+ Number.isFinite(t) && Number.isFinite(r) && Number.isFinite(o) && (i[a++] = n);
31
+ }
32
+ let o = [], u = a ? [0, a] : [];
33
+ for (; u.length;) {
34
+ let t = u.pop(), r = u.pop();
35
+ if (t - r <= n) {
36
+ o.push(r, t);
37
+ continue;
38
+ }
39
+ let a = Infinity, s = Infinity, c = Infinity, d = -Infinity, f = -Infinity, p = -Infinity;
40
+ for (let n = r; n < t; n++) {
41
+ let t = i[n] * 3, r = e[t], o = e[t + 1], l = e[t + 2];
42
+ r < a && (a = r), r > d && (d = r), o < s && (s = o), o > f && (f = o), l < c && (c = l), l > p && (p = l);
43
+ }
44
+ let m = d - a, h = f - s, g = p - c, _ = m >= h && m >= g ? 0 : h >= g ? 1 : 2, v = r + t >>> 1;
45
+ l(i, r, t - 1, v, e, _), u.push(v, t, r, v);
46
+ }
47
+ let d = o.length / 2, f = new Uint32Array(d), p = new Uint32Array(d), m = new Float32Array(d * 6), h = new Uint32Array(t).fill(s);
48
+ for (let t = 0; t < d; t++) {
49
+ let n = o[t * 2], a = o[t * 2 + 1];
50
+ f[t] = n, p[t] = a - n;
51
+ let s = c((r ^ Math.imul(t + 1, 2654435761)) >>> 0);
52
+ for (let e = a - 1; e > n; e--) {
53
+ let t = n + Math.floor(s() * (e - n + 1)), r = i[e];
54
+ i[e] = i[t], i[t] = r;
55
+ }
56
+ let l = Infinity, u = Infinity, d = Infinity, g = -Infinity, _ = -Infinity, v = -Infinity;
57
+ for (let r = n; r < a; r++) {
58
+ let n = i[r], a = n * 3, o = e[a], s = e[a + 1], c = e[a + 2];
59
+ h[n] = t, o < l && (l = o), o > g && (g = o), s < u && (u = s), s > _ && (_ = s), c < d && (d = c), c > v && (v = c);
60
+ }
61
+ m[t * 6] = l, m[t * 6 + 1] = u, m[t * 6 + 2] = d, m[t * 6 + 3] = g, m[t * 6 + 4] = _, m[t * 6 + 5] = v;
62
+ }
63
+ return {
64
+ order: i,
65
+ starts: f,
66
+ counts: p,
67
+ bounds: m,
68
+ blockOf: h,
69
+ length: d,
70
+ finite: a
71
+ };
72
+ }
73
+ function d(e, t, n, r) {
74
+ let { bounds: i, blockOf: a } = e, o = 0;
75
+ for (let e = n; e < n + r; e++) {
76
+ let n = a[e];
77
+ if (n === 4294967295) continue;
78
+ let r = t[e * 3], s = t[e * 3 + 1], c = t[e * 3 + 2];
79
+ if (!(Number.isFinite(r) && Number.isFinite(s) && Number.isFinite(c))) continue;
80
+ let l = n * 6, u = !1;
81
+ r < i[l] && (i[l] = r, u = !0), r > i[l + 3] && (i[l + 3] = r, u = !0), s < i[l + 1] && (i[l + 1] = s, u = !0), s > i[l + 4] && (i[l + 4] = s, u = !0), c < i[l + 2] && (i[l + 2] = c, u = !0), c > i[l + 5] && (i[l + 5] = c, u = !0), u && o++;
82
+ }
83
+ return o;
84
+ }
85
+ function f(e, t, n, r) {
86
+ let i = t * 6, a = (e[i] + e[i + 3]) / 2, o = (e[i + 1] + e[i + 4]) / 2, s = (e[i + 2] + e[i + 5]) / 2, c = (e[i + 3] - e[i]) / 2, l = (e[i + 4] - e[i + 1]) / 2, u = (e[i + 5] - e[i + 2]) / 2, d = n;
87
+ for (let e = 0; e < 3; e++) r[e] = d[e] * a + d[4 + e] * o + d[8 + e] * s + d[12 + e], r[3 + e] = Math.abs(d[e]) * c + Math.abs(d[4 + e]) * l + Math.abs(d[8 + e]) * u;
88
+ }
89
+ function p(e, t, n = 0) {
90
+ for (let r = 0; r < 6; r++) {
91
+ let i = t[r * 4], a = t[r * 4 + 1], o = t[r * 4 + 2], s = t[r * 4 + 3];
92
+ if (i * e[0] + a * e[1] + o * e[2] + s + (Math.abs(i) * e[3] + Math.abs(a) * e[4] + Math.abs(o) * e[5]) + n < 0) return !1;
93
+ }
94
+ return !0;
95
+ }
96
+ function m(e, t, n, r, i = 0) {
97
+ let a = /* @__PURE__ */ new Float64Array(6), o = 0;
98
+ for (let s = 0; s < e.length; s++) e.counts[s] && (f(e.bounds, s, t, a), p(a, n, i) && (r[o++] = s));
99
+ return o;
100
+ }
101
+ function h(e, t, n, r, i, a = !1) {
102
+ let o = Math.hypot(e[3], e[4], e[5]);
103
+ if (a) return Math.min(r * i, Math.PI * (o * n) ** 2);
104
+ let s = Math.hypot(e[0] - t[0], e[1] - t[1], e[2] - t[2]), c = r * i;
105
+ if (s <= o) return c;
106
+ let l = o * n / Math.sqrt(s * s - o * o);
107
+ return Math.min(c, Math.PI * l * l);
108
+ }
109
+ function g(e, t, n, r, i) {
110
+ if (!(r >= 0)) throw RangeError("budget must be non-negative");
111
+ r = Math.floor(r);
112
+ let a = 0;
113
+ for (let t = 0; t < n; t++) a += e[t];
114
+ if (a <= r) {
115
+ for (let t = 0; t < n; t++) i[t] = e[t];
116
+ return a;
117
+ }
118
+ let o = new Float64Array(n), s = new Float64Array(n), c = Array(n);
119
+ for (let r = 0; r < n; r++) o[r] = Math.max(1e-9, t[r] || 0), s[r] = e[r] / o[r], c[r] = r;
120
+ c.sort((e, t) => s[e] - s[t]);
121
+ let l = new Float64Array(n + 1);
122
+ for (let e = n - 1; e >= 0; e--) l[e] = l[e + 1] + o[c[e]];
123
+ let u = r, d = 0;
124
+ for (; d < n; d++) {
125
+ let t = c[d], n = u * o[t] / l[d];
126
+ if (e[t] > n) break;
127
+ i[t] = e[t], u -= e[t];
128
+ }
129
+ let f = l[d], p = 0, m = [];
130
+ for (let t = d; t < n; t++) {
131
+ let n = c[t], r = u * o[n] / f, a = Math.min(e[n] - 1, Math.floor(r));
132
+ i[n] = a, p += a, m.push([r - a, n]);
133
+ }
134
+ let h = u - p;
135
+ m.sort((e, t) => t[0] - e[0]);
136
+ for (let t = 0; h > 0 && m.length; t = (t + 1) % m.length) {
137
+ let n = m[t][1];
138
+ if (i[n] < e[n]) i[n]++, h--;
139
+ else if (m.every(([, t]) => i[t] >= e[t])) break;
140
+ }
141
+ let g = 0;
142
+ for (let e = 0; e < n; e++) g += i[e];
143
+ return g;
144
+ }
145
+ function _(e, t, n, i, a, s, c) {
146
+ let l = r(e, t, n, i, a, s, "webgpu", o);
147
+ return !l.inFront || !(l.depth >= 0 && l.depth <= 1) ? !1 : (c[0] = l.x, c[1] = l.y, c[2] = e[3] || e[7] || e[11] ? l.w : l.depth, !0);
148
+ }
149
+ function v(e, t, n, r, i, a, o, s, c, l) {
150
+ let u = /* @__PURE__ */ new Float64Array(3), d = [], f = 1 + 1e-9, p = c * c * f, m = Infinity, h = Infinity;
151
+ for (let g of n) for (let n = g.start; n < g.start + g.count; n++) {
152
+ let g = t ? t[n] : n;
153
+ if (l?.(g) || !_(r, e[g * 3], e[g * 3 + 1], e[g * 3 + 2], i, a, u)) continue;
154
+ let v = u[0] - o, y = u[1] - s, b = v * v + y * y;
155
+ if (b > p || b > h) continue;
156
+ let x = Math.hypot(v, y);
157
+ x > c || x > m + .5 || (x < m && (m = x, h = (m + .5) * (m + .5) * f), d.push(g, x, u[2], u[0], u[1]));
158
+ }
159
+ let g = null;
160
+ for (let e = 0; e < d.length; e += 5) d[e + 1] > m + .5 || (!g || d[e + 2] < g.depth) && (g = {
161
+ index: d[e],
162
+ distance: d[e + 1],
163
+ depth: d[e + 2],
164
+ screen: [d[e + 3], d[e + 4]]
165
+ });
166
+ return g;
167
+ }
168
+ function y(e, t, n, r) {
169
+ let i = /* @__PURE__ */ new Float64Array(3), a = [
170
+ Infinity,
171
+ Infinity,
172
+ -Infinity,
173
+ -Infinity
174
+ ];
175
+ for (let o = 0; o < 8; o++) {
176
+ let s = e[0] + (o & 1 ? e[3] : -e[3]), c = e[1] + (o & 2 ? e[4] : -e[4]), l = e[2] + (o & 4 ? e[5] : -e[5]), u = t[3] * s + t[7] * c + t[11] * l + t[15];
177
+ if (!(u > 1e-6)) return null;
178
+ let d = t[0] * s + t[4] * c + t[8] * l + t[12], f = t[1] * s + t[5] * c + t[9] * l + t[13];
179
+ i[0] = (d / u * .5 + .5) * n, i[1] = (.5 - f / u * .5) * r, a[0] = Math.min(a[0], i[0]), a[1] = Math.min(a[1], i[1]), a[2] = Math.max(a[2], i[0]), a[3] = Math.max(a[3], i[1]);
180
+ }
181
+ return a;
182
+ }
183
+ function b(e, t, n, r, i = 0) {
184
+ if (t !== 3 && t !== 4) throw RangeError("Colors need 3 (RGB) or 4 (RGBA) components");
185
+ if (e.length < n * t) throw RangeError("source holds fewer color values than count * components; pass one value per component for every point.");
186
+ if ((i + n) * 4 > r.length) throw RangeError("The color range runs past the end of the cloud; use a smaller offset or count.");
187
+ let a = e instanceof Uint8Array || e instanceof Uint8ClampedArray ? 1 / 255 : 1;
188
+ for (let o = 0; o < n; o++) for (let n = 0; n < 4; n++) {
189
+ let s = n < t ? e[o * t + n] * a : 1;
190
+ if (!(s >= 0) || !Number.isFinite(s)) throw RangeError(`Color of point ${i + o} is ${s}; pass finite numbers of 0 or more`);
191
+ r[(i + o) * 4 + n] = s;
192
+ }
193
+ return r;
194
+ }
195
+ function x(e, t, n, r, i = 0) {
196
+ if (t !== 3 && t !== 4) throw RangeError("Colors need 3 (RGB) or 4 (RGBA) components");
197
+ if (e.length < n * t) throw RangeError("source holds fewer color values than count * components; pass one value per component for every point.");
198
+ if (i + n > r.length) throw RangeError("The color range runs past the end of the cloud; use a smaller offset or count.");
199
+ let a = e instanceof Uint8Array || e instanceof Uint8ClampedArray ? (e) => e : (e) => e > 0 ? e < 1 ? Math.round(e * 255) : 255 : 0;
200
+ for (let o = 0; o < n; o++) {
201
+ let n = o * t, s = a(e[n]), c = a(e[n + 1]), l = a(e[n + 2]), u = t === 4 ? a(e[n + 3]) : 255;
202
+ r[i + o] = (s | c << 8 | l << 16 | u << 24) >>> 0;
203
+ }
204
+ return r;
205
+ }
206
+ function S(e) {
207
+ e.sort((e, t) => e[0] - t[0]);
208
+ let t = 0;
209
+ for (let n of e) t && n[0] <= e[t - 1][1] ? e[t - 1][1] = Math.max(e[t - 1][1], n[1]) : e[t++] = [n[0], n[1]];
210
+ return e.length = t, e;
211
+ }
212
+ function C(e, t, n, r = 0) {
213
+ if (![
214
+ e,
215
+ t,
216
+ n
217
+ ].every(Number.isInteger) || t < 1 || n < 1 || e < 0 || e >= t * n) throw RangeError("Atlas cell index must be an integer below columns * rows; pass an index inside the atlas grid.");
218
+ let i = e % t, a = Math.floor(e / t), o = 1 / t, s = 1 / n;
219
+ return [
220
+ i * o + r,
221
+ a * s + r,
222
+ (i + 1) * o - r,
223
+ (a + 1) * s - r
224
+ ];
225
+ }
226
+ //#endregion
227
+ //#region src/material.ts
228
+ var w = (e, t) => {
229
+ if (typeof e != "number" || !(e >= 0 && e <= 1)) throw RangeError(`${t} must be in [0, 1]`);
230
+ };
231
+ function T(e) {
232
+ if (!Array.isArray(e)) throw TypeError("Points material clippingPlanes must be an array of [a, b, c, d] planes");
233
+ if (e.length > 6) throw RangeError("Points material clippingPlanes holds at most 6 planes; pass fewer");
234
+ let t = [];
235
+ for (let n of e) {
236
+ if (!Array.isArray(n) || n.length !== 4 || !n.every((e) => typeof e == "number" && Number.isFinite(Math.fround(e)))) throw TypeError("Points material clipping plane must be four finite numbers [a, b, c, d]");
237
+ let e = Math.hypot(n[0], n[1], n[2]);
238
+ if (!e) throw TypeError("Points material clipping plane needs a non-zero normal [a, b, c]");
239
+ t.push(n[0] / e, n[1] / e, n[2] / e, n[3] / e);
240
+ }
241
+ return t;
242
+ }
243
+ var E = class {
244
+ constructor(e, t) {
245
+ this.color = new Float32Array([
246
+ 1,
247
+ 1,
248
+ 1
249
+ ]), this.opacity = 1, this.mapFilter = "linear", this.alphaTest = 0, this.blending = "normal", this.depthTest = !0, this.depthWrite = null, this.fog = !0, this.mapVersion = 0, this.source = null, this.clipping = [], this.clipAll = !1, this.transparent = e, this.mipmaps = t;
250
+ }
251
+ get map() {
252
+ return this.source;
253
+ }
254
+ set map(e) {
255
+ if (e !== null && typeof e != "object" && typeof e != "function") throw TypeError("map must be a texture source, a function of the device or null");
256
+ e !== this.source && (this.source = e, this.mapVersion++);
257
+ }
258
+ get clippingPlanes() {
259
+ let e = [];
260
+ for (let t = 0; t < this.clipping.length; t += 4) e.push(this.clipping.slice(t, t + 4));
261
+ return e;
262
+ }
263
+ set clippingPlanes(e) {
264
+ this.clipping = T(e);
265
+ }
266
+ get clipIntersection() {
267
+ return this.clipAll;
268
+ }
269
+ set clipIntersection(e) {
270
+ if (typeof e != "boolean") throw TypeError("Points material clipIntersection must be a boolean; pass true or false");
271
+ this.clipAll = e;
272
+ }
273
+ needsUpdate() {
274
+ this.mapVersion++;
275
+ }
276
+ setColor(e) {
277
+ return a(e, this.color), this;
278
+ }
279
+ get writesDepth() {
280
+ return this.depthWrite ?? !this.transparent;
281
+ }
282
+ apply(e) {
283
+ e.color !== void 0 && this.setColor(e.color), e.opacity !== void 0 && (this.opacity = e.opacity), e.map !== void 0 && (this.map = e.map), e.mapFilter !== void 0 && (this.mapFilter = e.mapFilter), e.mipmaps !== void 0 && (this.mipmaps = e.mipmaps), e.alphaTest !== void 0 && (this.alphaTest = e.alphaTest), e.transparent !== void 0 && (this.transparent = e.transparent), e.blending !== void 0 && (this.blending = e.blending), e.depthTest !== void 0 && (this.depthTest = e.depthTest), e.depthWrite !== void 0 && (this.depthWrite = e.depthWrite), e.fog !== void 0 && (this.fog = e.fog), e.clippingPlanes !== void 0 && (this.clippingPlanes = e.clippingPlanes), e.clipIntersection !== void 0 && (this.clipIntersection = e.clipIntersection);
284
+ }
285
+ validate() {
286
+ if (w(this.opacity, "opacity"), w(this.alphaTest, "alphaTest"), !["linear", "nearest"].includes(this.mapFilter)) throw RangeError("mapFilter must be 'linear' or 'nearest'");
287
+ if (!["normal", "additive"].includes(this.blending)) throw RangeError("blending must be 'normal' or 'additive'");
288
+ if (typeof this.transparent != "boolean" || typeof this.depthTest != "boolean" || typeof this.fog != "boolean" || typeof this.mipmaps != "boolean" || this.depthWrite !== null && typeof this.depthWrite != "boolean") throw TypeError("transparent, depthTest, depthWrite, fog and mipmaps must be booleans");
289
+ for (let e of this.color) if (!Number.isFinite(e) || e < 0) throw RangeError("color must be finite and non-negative");
290
+ }
291
+ }, D = class extends E {
292
+ constructor(e = {}) {
293
+ super(!1, !0), this.size = 4, this.sizeUnits = "pixels", this.minPixelSize = 1, this.maxPixelSize = 256, this.shape = "square", this.vertexColors = !0, this.shading = "flat", this.edl = !1, this.adaptiveSize = 0, this.set(e);
294
+ }
295
+ get sizeAttenuation() {
296
+ return this.sizeUnits === "world";
297
+ }
298
+ set sizeAttenuation(e) {
299
+ this.sizeUnits = e ? "world" : "pixels";
300
+ }
301
+ set(e) {
302
+ return this.apply(e), e.size !== void 0 && (this.size = e.size), e.sizeAttenuation !== void 0 && (this.sizeAttenuation = e.sizeAttenuation), e.sizeUnits !== void 0 && (this.sizeUnits = e.sizeUnits), e.minPixelSize !== void 0 && (this.minPixelSize = e.minPixelSize), e.maxPixelSize !== void 0 && (this.maxPixelSize = e.maxPixelSize), e.shape !== void 0 && (this.shape = e.shape), e.vertexColors !== void 0 && (this.vertexColors = e.vertexColors), e.shading !== void 0 && (this.shading = e.shading), e.edl !== void 0 && (this.edl = e.edl), e.adaptiveSize !== void 0 && (this.adaptiveSize = e.adaptiveSize), e.ditherFade !== void 0 && (this.ditherFade = e.ditherFade), this.validate(), this;
303
+ }
304
+ validate() {
305
+ if (super.validate(), this.ditherFade && e(this.ditherFade), !(this.size >= 0) || !Number.isFinite(this.size)) throw RangeError("size must be finite and non-negative");
306
+ if (!(this.minPixelSize >= 0) || !(this.maxPixelSize >= this.minPixelSize) || !Number.isFinite(this.maxPixelSize)) throw RangeError("Need 0 <= minPixelSize <= maxPixelSize");
307
+ if (!["pixels", "world"].includes(this.sizeUnits)) throw RangeError("sizeUnits must be 'pixels' or 'world'");
308
+ if (!(this.adaptiveSize >= 0) || !Number.isFinite(this.adaptiveSize)) throw RangeError("adaptiveSize must be finite and 0 or more");
309
+ if (!["square", "round"].includes(this.shape)) throw RangeError("shape must be 'square' or 'round'");
310
+ if (!["flat", "sphere"].includes(this.shading)) throw RangeError("shading must be 'flat' or 'sphere'");
311
+ if (typeof this.vertexColors != "boolean" || typeof this.edl != "boolean") throw TypeError("vertexColors and edl must be booleans");
312
+ }
313
+ }, O = class extends E {
314
+ constructor(e = {}) {
315
+ super(!0, !1), this.rotation = 0, this.sizeUnits = "world", this.set(e);
316
+ }
317
+ get sizeAttenuation() {
318
+ return this.sizeUnits === "world";
319
+ }
320
+ set sizeAttenuation(e) {
321
+ this.sizeUnits = e ? "world" : "pixels";
322
+ }
323
+ set(e) {
324
+ return this.apply(e), e.rotation !== void 0 && (this.rotation = e.rotation), e.sizeAttenuation !== void 0 && (this.sizeAttenuation = e.sizeAttenuation), e.sizeUnits !== void 0 && (this.sizeUnits = e.sizeUnits), this.validate(), this;
325
+ }
326
+ validate() {
327
+ if (super.validate(), !Number.isFinite(this.rotation)) throw RangeError("rotation must be finite");
328
+ if (!["pixels", "world"].includes(this.sizeUnits)) throw RangeError("sizeUnits must be 'pixels' or 'world'");
329
+ }
330
+ }, k = [
331
+ "fade",
332
+ "highlight",
333
+ "filter"
334
+ ], A = /* @__PURE__ */ new Float32Array(1), j = new Uint32Array(A.buffer), M = (e, t) => Math.round(255 * Math.min(1, Math.max(0, t ? e <= .0031308 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - .055 : e))), N = (e, t) => {
335
+ if (!e || typeof e != "object") throw TypeError("A mask style is an object; pass { mode, fade }");
336
+ let n = {
337
+ ...t,
338
+ ...e
339
+ };
340
+ if (!k.includes(n.mode)) throw RangeError("Unknown mask mode; use 'fade', 'highlight' or 'filter'");
341
+ for (let e of [n.fade, n.highlightAmount]) if (typeof e != "number" || !(e >= 0 && e <= 1)) throw RangeError("Mask fade and amount must be in [0, 1]");
342
+ if (n.highlight?.length !== 3 || ![...n.highlight].every((e) => e >= 0 && e < Infinity)) throw RangeError("Mask highlight is a linear [r, g, b] of finite values of 0 or more; pass such an array");
343
+ return Object.freeze(n);
344
+ };
345
+ function P(e, t) {
346
+ let n = t.highlight;
347
+ return A[0] = t.fade, e[0] = k.indexOf(t.mode), e[1] = j[0], e[2] = (M(n[0], 1) | M(n[1], 1) << 8 | M(n[2], 1) << 16 | M(t.highlightAmount) << 24) >>> 0, e[3] = 1, e;
348
+ }
349
+ function F(e, t, n = 0) {
350
+ for (let r = 0; r < t.length; r++) {
351
+ let i = 4 + (n + r >>> 5), a = 1 << (n + r & 31), o = t[r];
352
+ if (typeof o != "boolean" && (typeof o != "number" || o !== o)) throw TypeError("Mask values are booleans or numbers; pass true or a value above 0 to select");
353
+ e[i] = (o > 0 ? e[i] | a : e[i] & ~a) >>> 0;
354
+ }
355
+ return e;
356
+ }
357
+ var I = (e, t) => (e[4 + (t >>> 5)] >>> (t & 31) & 1) == 1, L = class {
358
+ mask = null;
359
+ maskVersion = 0;
360
+ #e = Object.freeze({
361
+ mode: "fade",
362
+ fade: .12,
363
+ highlight: Object.freeze([
364
+ 1,
365
+ .4508,
366
+ .0194
367
+ ]),
368
+ highlightAmount: .7
369
+ });
370
+ get maskStyle() {
371
+ return this.#e;
372
+ }
373
+ setMaskStyle(e) {
374
+ return this.#e = N(e, this.#e), this.mask && P(this.mask, this.#e), this.maskVersion++, this;
375
+ }
376
+ updateMask(e, n) {
377
+ if (!this.mask) throw new t("state", "There is no selection mask; call setMask first");
378
+ if (!Number.isInteger(e) || e < 0 || e + n.length > this.count) throw RangeError(`Mask values ${e}..${e + n.length} pass the ${this.count} elements; pass fewer`);
379
+ return F(this.mask, n, e), this.maskVersion++, this;
380
+ }
381
+ isSelected(e) {
382
+ return !this.mask || I(this.mask, e);
383
+ }
384
+ takeMaskStyle(e) {
385
+ return e && (this.#e = N(e, this.#e)), this.#e;
386
+ }
387
+ }, R = class extends L {
388
+ get memoryResources() {
389
+ let e = this.owner?.memoryFor?.(this);
390
+ return {
391
+ cpu: [
392
+ this.positions,
393
+ this.colors,
394
+ this.sizes,
395
+ this.mask,
396
+ this.normals,
397
+ this.matrix,
398
+ this.sourceIndex,
399
+ this.blocks.order,
400
+ this.blocks.starts,
401
+ this.blocks.counts,
402
+ this.blocks.bounds,
403
+ this.blocks.blockOf,
404
+ ...e?.cpu ?? []
405
+ ],
406
+ gpu: e?.gpu ?? []
407
+ };
408
+ }
409
+ constructor(e) {
410
+ if (super(), this.visible = !0, this.colors = null, this.colorComponents = 3, this.sizes = null, this.stats = {
411
+ blocksVisible: 0,
412
+ pointsVisible: 0,
413
+ pointsDrawn: 0
414
+ }, this.structure = 0, this.dirty = {
415
+ positions: [],
416
+ colors: [],
417
+ sizes: []
418
+ }, this.mesh = null, !e || typeof e != "object" || !e.positions) throw TypeError("PointCloud needs positions");
419
+ let { positions: t } = e;
420
+ if (t.length % 3) throw RangeError("positions length must be a multiple of 3");
421
+ if (this.name = e.name ?? "", this.matrix = e.matrix ?? new Float32Array([
422
+ 1,
423
+ 0,
424
+ 0,
425
+ 0,
426
+ 0,
427
+ 1,
428
+ 0,
429
+ 0,
430
+ 0,
431
+ 0,
432
+ 1,
433
+ 0,
434
+ 0,
435
+ 0,
436
+ 0,
437
+ 1
438
+ ]), !(this.matrix instanceof Float32Array) || this.matrix.length !== 16) throw TypeError("PointCloud matrix must be a Float32Array of 16 numbers");
439
+ if (this.count = t.length / 3, this.blockSize = e.blockSize ?? 16384, this.seed = e.seed ?? 1, this.cullMargin = e.cullMargin ?? 0, this.colorFormat = e.colorFormat ?? "rgba8", this.colorFormat !== "rgba8" && this.colorFormat !== "float") throw RangeError("colorFormat must be 'rgba8' or 'float'");
440
+ if (this.colorSpace = e.colorSpace ?? (this.colorFormat === "float" ? "linear" : "srgb"), this.colorSpace !== "srgb" && this.colorSpace !== "linear") throw RangeError("colorSpace must be 'srgb' or 'linear'");
441
+ if (!Number.isFinite(this.cullMargin) || this.cullMargin < 0) throw RangeError("cullMargin must be finite and non-negative");
442
+ this.material = e.material instanceof D ? e.material : new D(e.material);
443
+ let n = t instanceof Float32Array ? t : Float32Array.from(t), r = e.normals ?? null;
444
+ if (r && r.length !== t.length) throw RangeError(`normals needs ${t.length} values (xyz per point); pass one normal a point`);
445
+ e.colors && this.setColors(e.colors, e.colorComponents, !1), e.sizes && this.setSizes(e.sizes, !1);
446
+ let i = u(n, this.count, this.blockSize, this.seed);
447
+ if (this.direct = e.reorder === !0, this.direct) {
448
+ let e = new Uint32Array(this.count);
449
+ e.set(i.order.subarray(0, i.finite));
450
+ let t = i.finite;
451
+ for (let n = 0; n < this.count; n++) i.blockOf[n] === 4294967295 && (e[t++] = n);
452
+ let a = (t, n) => {
453
+ let r = new t.constructor(t.length);
454
+ for (let i = 0; i < this.count; i++) for (let a = 0; a < n; a++) r[i * n + a] = t[e[i] * n + a];
455
+ return r;
456
+ };
457
+ n = a(n, 3), this.colors &&= a(this.colors, this.colorStride), this.sizes &&= a(this.sizes, 1), r &&= a(r, 3);
458
+ let o = new Uint32Array(this.count).fill(s);
459
+ for (let e = 0; e < i.length; e++) o.fill(e, i.starts[e], i.starts[e] + i.counts[e]);
460
+ let c = new Uint32Array(this.count);
461
+ for (let e = 0; e < this.count; e++) c[e] = e;
462
+ this.blocks = {
463
+ ...i,
464
+ order: c,
465
+ blockOf: o
466
+ }, this.sourceIndex = e;
467
+ } else this.blocks = i, this.sourceIndex = null;
468
+ this.positions = n, this.normals = r;
469
+ }
470
+ get colorStride() {
471
+ return this.colorFormat === "float" ? 4 : 1;
472
+ }
473
+ get floatColors() {
474
+ return this.colors && this.colorFormat === "float" ? new Float32Array(this.colors.buffer, this.colors.byteOffset, this.colors.length) : null;
475
+ }
476
+ get attachedMesh() {
477
+ return this.mesh;
478
+ }
479
+ attach(e) {
480
+ return this.mesh = e, this;
481
+ }
482
+ updatePositions(e, t) {
483
+ let n = this.range(e, t.length, 3);
484
+ return this.positions.set(t, e * 3), d(this.blocks, this.positions, e, n), this.dirty.positions.push([e, e + n]), this;
485
+ }
486
+ updateColors(e, n, r = this.colorComponents) {
487
+ if (!this.colors) throw new t("state", "The cloud has no per-point colors; call setColors first");
488
+ let i = this.range(e, n.length, r), a = this.floatColors;
489
+ return a ? b(n, r, i, a, e) : x(n, r, i, this.colors, e), this.dirty.colors.push([e, e + i]), this;
490
+ }
491
+ updateSizes(e, n) {
492
+ if (!this.sizes) throw new t("state", "The cloud has no per-point sizes; call setSizes first");
493
+ let r = this.range(e, n.length, 1);
494
+ for (let e = 0; e < r; e++) if (!(n[e] >= 0) || !Number.isFinite(n[e])) throw RangeError("sizes must be finite and non-negative");
495
+ return this.sizes.set(n, e), this.dirty.sizes.push([e, e + r]), this;
496
+ }
497
+ markDirty(e, t = 0, n = this.count - t) {
498
+ return this.range(t, n, 1), e === "positions" && d(this.blocks, this.positions, t, n), this.dirty[e].push([t, t + n]), this;
499
+ }
500
+ setColors(e, t, n = !0) {
501
+ if (e === null) this.colors = null;
502
+ else {
503
+ let n = t ?? (e.length === this.count * 4 && e.length !== this.count * 3 ? 4 : 3);
504
+ if (e.length !== this.count * n) throw RangeError(`colors needs ${this.count * n} values (${n} per point)`);
505
+ this.colorComponents = n, this.colors = this.colorFormat === "float" ? new Uint32Array(b(e, n, this.count, new Float32Array(this.count * 4)).buffer) : x(e, n, this.count, new Uint32Array(this.count));
506
+ }
507
+ return n && this.structure++, this;
508
+ }
509
+ setSizes(e, t = !0) {
510
+ if (e === null) this.sizes = null;
511
+ else {
512
+ if (e.length !== this.count) throw RangeError(`sizes needs ${this.count} values`);
513
+ let t = e instanceof Float32Array ? e : Float32Array.from(e);
514
+ for (let e = 0; e < t.length; e++) if (!(t[e] >= 0) || !Number.isFinite(t[e])) throw RangeError("sizes must be finite and non-negative");
515
+ this.sizes = t;
516
+ }
517
+ return t && this.structure++, this;
518
+ }
519
+ setMask(e, t) {
520
+ let n = this.takeMaskStyle(t), r = this.mask !== null;
521
+ if (e !== null && e.length !== this.count) throw RangeError(`A mask needs ${this.count} values, one a point; pass one value per point`);
522
+ return this.mask = e === null ? null : F(P(new Uint32Array(4 + Math.ceil(this.count / 32)), n), e), r !== (this.mask !== null) && this.structure++, this.maskVersion++, this;
523
+ }
524
+ rebuild() {
525
+ if (this.direct) throw new t("state", "A reordered cloud cannot be rebuilt; create a new PointCloud");
526
+ return this.blocks = u(this.positions, this.count, this.blockSize, this.seed), this.structure++, this;
527
+ }
528
+ dispose() {
529
+ this.owner?.remove(this);
530
+ }
531
+ [Symbol.dispose ?? Symbol()]() {
532
+ this.dispose();
533
+ }
534
+ bind(e) {
535
+ if (e && this.owner && this.owner !== e) throw new t("attached", "The cloud already belongs to another plugin; remove it from that plugin first");
536
+ this.owner = e;
537
+ }
538
+ range(e, t, n) {
539
+ let r = t / n;
540
+ if (!Number.isInteger(e) || !Number.isInteger(r) || e < 0 || e + r > this.count) throw RangeError(`Range ${e}..${e + r} is outside the cloud of ${this.count} points; pass an integer start and values that fit inside the cloud.`);
541
+ return r;
542
+ }
543
+ };
544
+ //#endregion
545
+ export { c as _, s as a, p as c, m as d, d as f, _ as g, v as h, a as i, y as l, x as m, D as n, g as o, S as p, O as r, C as s, R as t, u, h as v, f as y };