@speridlabs/visus 2.1.0 → 2.2.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/dist/react.es.js CHANGED
@@ -1,8 +1,7 @@
1
- var ve = Object.defineProperty;
2
- var we = (A, e, n) => e in A ? ve(A, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : A[e] = n;
3
- var d = (A, e, n) => we(A, typeof e != "symbol" ? e + "" : e, n);
4
- import be, { useRef as Se, useMemo as Me, useEffect as _e } from "react";
5
- import { useLoader as Ae } from "@react-three/fiber";
1
+ var be = Object.defineProperty;
2
+ var Se = (x, e, o) => e in x ? be(x, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : x[e] = o;
3
+ var f = (x, e, o) => Se(x, typeof e != "symbol" ? e + "" : e, o);
4
+ import Me, { useState as Ce, useRef as Ae, useEffect as Te } from "react";
6
5
  import * as l from "three";
7
6
  var ce = { exports: {} }, ae = {};
8
7
  /**
@@ -14,27 +13,27 @@ var ce = { exports: {} }, ae = {};
14
13
  * This source code is licensed under the MIT license found in the
15
14
  * LICENSE file in the root directory of this source tree.
16
15
  */
17
- var pe;
18
- function Ce() {
19
- if (pe) return ae;
20
- pe = 1;
21
- var A = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
22
- function n(t, o, r) {
16
+ var me;
17
+ function _e() {
18
+ if (me) return ae;
19
+ me = 1;
20
+ var x = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
21
+ function o(t, r, n) {
23
22
  var a = null;
24
- if (r !== void 0 && (a = "" + r), o.key !== void 0 && (a = "" + o.key), "key" in o) {
25
- r = {};
26
- for (var i in o)
27
- i !== "key" && (r[i] = o[i]);
28
- } else r = o;
29
- return o = r.ref, {
30
- $$typeof: A,
23
+ if (n !== void 0 && (a = "" + n), r.key !== void 0 && (a = "" + r.key), "key" in r) {
24
+ n = {};
25
+ for (var i in r)
26
+ i !== "key" && (n[i] = r[i]);
27
+ } else n = r;
28
+ return r = n.ref, {
29
+ $$typeof: x,
31
30
  type: t,
32
31
  key: a,
33
- ref: o !== void 0 ? o : null,
34
- props: r
32
+ ref: r !== void 0 ? r : null,
33
+ props: n
35
34
  };
36
35
  }
37
- return ae.Fragment = e, ae.jsx = n, ae.jsxs = n, ae;
36
+ return ae.Fragment = e, ae.jsx = o, ae.jsxs = o, ae;
38
37
  }
39
38
  var ie = {};
40
39
  /**
@@ -46,47 +45,47 @@ var ie = {};
46
45
  * This source code is licensed under the MIT license found in the
47
46
  * LICENSE file in the root directory of this source tree.
48
47
  */
49
- var me;
50
- function Te() {
51
- return me || (me = 1, process.env.NODE_ENV !== "production" && function() {
52
- function A(s) {
48
+ var xe;
49
+ function ke() {
50
+ return xe || (xe = 1, process.env.NODE_ENV !== "production" && function() {
51
+ function x(s) {
53
52
  if (s == null) return null;
54
53
  if (typeof s == "function")
55
- return s.$$typeof === g ? null : s.displayName || s.name || null;
54
+ return s.$$typeof === v ? null : s.displayName || s.name || null;
56
55
  if (typeof s == "string") return s;
57
56
  switch (s) {
58
57
  case I:
59
58
  return "Fragment";
60
59
  case j:
61
60
  return "Profiler";
62
- case z:
61
+ case P:
63
62
  return "StrictMode";
64
63
  case L:
65
64
  return "Suspense";
66
- case _:
65
+ case A:
67
66
  return "SuspenseList";
68
- case C:
67
+ case T:
69
68
  return "Activity";
70
69
  }
71
70
  if (typeof s == "object")
72
71
  switch (typeof s.tag == "number" && console.error(
73
72
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
74
73
  ), s.$$typeof) {
75
- case b:
74
+ case S:
76
75
  return "Portal";
77
76
  case W:
78
77
  return (s.displayName || "Context") + ".Provider";
79
78
  case H:
80
79
  return (s._context.displayName || "Context") + ".Consumer";
81
- case ne:
80
+ case oe:
82
81
  var p = s.render;
83
82
  return s = s.displayName, s || (s = p.displayName || p.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
84
- case x:
85
- return p = s.displayName || null, p !== null ? p : A(s.type) || "Memo";
83
+ case g:
84
+ return p = s.displayName || null, p !== null ? p : x(s.type) || "Memo";
86
85
  case D:
87
86
  p = s._payload, s = s._init;
88
87
  try {
89
- return A(s(p));
88
+ return x(s(p));
90
89
  } catch {
91
90
  }
92
91
  }
@@ -95,7 +94,7 @@ function Te() {
95
94
  function e(s) {
96
95
  return "" + s;
97
96
  }
98
- function n(s) {
97
+ function o(s) {
99
98
  try {
100
99
  e(s);
101
100
  var p = !1;
@@ -104,8 +103,8 @@ function Te() {
104
103
  }
105
104
  if (p) {
106
105
  p = console;
107
- var S = p.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
108
- return S.call(
106
+ var M = p.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
107
+ return M.call(
109
108
  p,
110
109
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
111
110
  E
@@ -117,17 +116,17 @@ function Te() {
117
116
  if (typeof s == "object" && s !== null && s.$$typeof === D)
118
117
  return "<...>";
119
118
  try {
120
- var p = A(s);
119
+ var p = x(s);
121
120
  return p ? "<" + p + ">" : "<...>";
122
121
  } catch {
123
122
  return "<...>";
124
123
  }
125
124
  }
126
- function o() {
125
+ function r() {
127
126
  var s = R.A;
128
127
  return s === null ? null : s.getOwner();
129
128
  }
130
- function r() {
129
+ function n() {
131
130
  return Error("react-stack-top-frame");
132
131
  }
133
132
  function a(s) {
@@ -138,31 +137,31 @@ function Te() {
138
137
  return s.key !== void 0;
139
138
  }
140
139
  function i(s, p) {
141
- function S() {
140
+ function M() {
142
141
  Z || (Z = !0, console.error(
143
142
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
144
143
  p
145
144
  ));
146
145
  }
147
- S.isReactWarning = !0, Object.defineProperty(s, "key", {
148
- get: S,
146
+ M.isReactWarning = !0, Object.defineProperty(s, "key", {
147
+ get: M,
149
148
  configurable: !0
150
149
  });
151
150
  }
152
151
  function u() {
153
- var s = A(this.type);
152
+ var s = x(this.type);
154
153
  return U[s] || (U[s] = !0, console.error(
155
154
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
156
155
  )), s = this.props.ref, s !== void 0 ? s : null;
157
156
  }
158
- function v(s, p, S, E, m, c, y, P) {
159
- return S = c.ref, s = {
160
- $$typeof: w,
157
+ function w(s, p, M, E, m, c, y, z) {
158
+ return M = c.ref, s = {
159
+ $$typeof: b,
161
160
  type: s,
162
161
  key: p,
163
162
  props: c,
164
163
  _owner: m
165
- }, (S !== void 0 ? S : null) !== null ? Object.defineProperty(s, "ref", {
164
+ }, (M !== void 0 ? M : null) !== null ? Object.defineProperty(s, "ref", {
166
165
  enumerable: !1,
167
166
  get: u
168
167
  }) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
@@ -184,28 +183,28 @@ function Te() {
184
183
  configurable: !1,
185
184
  enumerable: !1,
186
185
  writable: !0,
187
- value: P
186
+ value: z
188
187
  }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
189
188
  }
190
- function M(s, p, S, E, m, c, y, P) {
191
- var h = p.children;
192
- if (h !== void 0)
189
+ function C(s, p, M, E, m, c, y, z) {
190
+ var d = p.children;
191
+ if (d !== void 0)
193
192
  if (E)
194
- if (X(h)) {
195
- for (E = 0; E < h.length; E++)
196
- T(h[E]);
197
- Object.freeze && Object.freeze(h);
193
+ if ($(d)) {
194
+ for (E = 0; E < d.length; E++)
195
+ _(d[E]);
196
+ Object.freeze && Object.freeze(d);
198
197
  } else
199
198
  console.error(
200
199
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
201
200
  );
202
- else T(h);
201
+ else _(d);
203
202
  if (B.call(p, "key")) {
204
- h = A(s);
205
- var k = Object.keys(p).filter(function(V) {
206
- return V !== "key";
203
+ d = x(s);
204
+ var k = Object.keys(p).filter(function(q) {
205
+ return q !== "key";
207
206
  });
208
- E = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", te[h + E] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
207
+ E = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", te[d + E] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
209
208
  `A props object containing a "key" prop is being spread into JSX:
210
209
  let props = %s;
211
210
  <%s {...props} />
@@ -213,84 +212,84 @@ React keys must be passed directly to JSX without using spread:
213
212
  let props = %s;
214
213
  <%s key={someKey} {...props} />`,
215
214
  E,
216
- h,
215
+ d,
217
216
  k,
218
- h
219
- ), te[h + E] = !0);
217
+ d
218
+ ), te[d + E] = !0);
220
219
  }
221
- if (h = null, S !== void 0 && (n(S), h = "" + S), a(p) && (n(p.key), h = "" + p.key), "key" in p) {
222
- S = {};
220
+ if (d = null, M !== void 0 && (o(M), d = "" + M), a(p) && (o(p.key), d = "" + p.key), "key" in p) {
221
+ M = {};
223
222
  for (var O in p)
224
- O !== "key" && (S[O] = p[O]);
225
- } else S = p;
226
- return h && i(
227
- S,
223
+ O !== "key" && (M[O] = p[O]);
224
+ } else M = p;
225
+ return d && i(
226
+ M,
228
227
  typeof s == "function" ? s.displayName || s.name || "Unknown" : s
229
- ), v(
228
+ ), w(
230
229
  s,
231
- h,
230
+ d,
232
231
  c,
233
232
  m,
234
- o(),
235
- S,
233
+ r(),
234
+ M,
236
235
  y,
237
- P
236
+ z
238
237
  );
239
238
  }
240
- function T(s) {
241
- typeof s == "object" && s !== null && s.$$typeof === w && s._store && (s._store.validated = 1);
239
+ function _(s) {
240
+ typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
242
241
  }
243
- var f = be, w = Symbol.for("react.transitional.element"), b = Symbol.for("react.portal"), I = Symbol.for("react.fragment"), z = Symbol.for("react.strict_mode"), j = Symbol.for("react.profiler"), H = Symbol.for("react.consumer"), W = Symbol.for("react.context"), ne = Symbol.for("react.forward_ref"), L = Symbol.for("react.suspense"), _ = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), C = Symbol.for("react.activity"), g = Symbol.for("react.client.reference"), R = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, X = Array.isArray, $ = console.createTask ? console.createTask : function() {
242
+ var h = Me, b = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), I = Symbol.for("react.fragment"), P = Symbol.for("react.strict_mode"), j = Symbol.for("react.profiler"), H = Symbol.for("react.consumer"), W = Symbol.for("react.context"), oe = Symbol.for("react.forward_ref"), L = Symbol.for("react.suspense"), A = Symbol.for("react.suspense_list"), g = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), T = Symbol.for("react.activity"), v = Symbol.for("react.client.reference"), R = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, $ = Array.isArray, X = console.createTask ? console.createTask : function() {
244
243
  return null;
245
244
  };
246
- f = {
245
+ h = {
247
246
  "react-stack-bottom-frame": function(s) {
248
247
  return s();
249
248
  }
250
249
  };
251
- var Z, U = {}, F = f["react-stack-bottom-frame"].bind(
252
- f,
253
- r
254
- )(), N = $(t(r)), te = {};
255
- ie.Fragment = I, ie.jsx = function(s, p, S, E, m) {
250
+ var Z, U = {}, F = h["react-stack-bottom-frame"].bind(
251
+ h,
252
+ n
253
+ )(), N = X(t(n)), te = {};
254
+ ie.Fragment = I, ie.jsx = function(s, p, M, E, m) {
256
255
  var c = 1e4 > R.recentlyCreatedOwnerStacks++;
257
- return M(
256
+ return C(
258
257
  s,
259
258
  p,
260
- S,
259
+ M,
261
260
  !1,
262
261
  E,
263
262
  m,
264
263
  c ? Error("react-stack-top-frame") : F,
265
- c ? $(t(s)) : N
264
+ c ? X(t(s)) : N
266
265
  );
267
- }, ie.jsxs = function(s, p, S, E, m) {
266
+ }, ie.jsxs = function(s, p, M, E, m) {
268
267
  var c = 1e4 > R.recentlyCreatedOwnerStacks++;
269
- return M(
268
+ return C(
270
269
  s,
271
270
  p,
272
- S,
271
+ M,
273
272
  !0,
274
273
  E,
275
274
  m,
276
275
  c ? Error("react-stack-top-frame") : F,
277
- c ? $(t(s)) : N
276
+ c ? X(t(s)) : N
278
277
  );
279
278
  };
280
279
  }()), ie;
281
280
  }
282
- var xe;
283
- function ke() {
284
- return xe || (xe = 1, process.env.NODE_ENV === "production" ? ce.exports = Ce() : ce.exports = Te()), ce.exports;
281
+ var ge;
282
+ function Ee() {
283
+ return ge || (ge = 1, process.env.NODE_ENV === "production" ? ce.exports = _e() : ce.exports = ke()), ce.exports;
285
284
  }
286
- var Ee = ke();
287
- class he {
285
+ var Ie = Ee();
286
+ class fe {
288
287
  constructor() {
289
- d(this, "min", new l.Vector3(1 / 0, 1 / 0, 1 / 0));
290
- d(this, "max", new l.Vector3(-1 / 0, -1 / 0, -1 / 0));
291
- d(this, "center", new l.Vector3());
288
+ f(this, "min", new l.Vector3(1 / 0, 1 / 0, 1 / 0));
289
+ f(this, "max", new l.Vector3(-1 / 0, -1 / 0, -1 / 0));
290
+ f(this, "center", new l.Vector3());
292
291
  /** Half extents (size/2) */
293
- d(this, "halfExtents", new l.Vector3());
292
+ f(this, "halfExtents", new l.Vector3());
294
293
  }
295
294
  /**
296
295
  * Reset the bounding box to its initial state
@@ -338,20 +337,20 @@ class he {
338
337
  * @returns New bounding box with the same values
339
338
  */
340
339
  clone() {
341
- const e = new he();
340
+ const e = new fe();
342
341
  return e.min.copy(this.min), e.max.copy(this.max), e.center.copy(this.center), e.halfExtents.copy(this.halfExtents), e;
343
342
  }
344
343
  }
345
- class Ie {
344
+ class Re {
346
345
  // TODO: there is no sh spherical harmonics
347
346
  constructor(e = 0) {
348
- d(this, "numSplats", 0);
349
- d(this, "positions");
350
- d(this, "rotations");
351
- d(this, "scales");
352
- d(this, "colors");
353
- d(this, "opacities");
354
- d(this, "boundingBox", new he());
347
+ f(this, "numSplats", 0);
348
+ f(this, "positions");
349
+ f(this, "rotations");
350
+ f(this, "scales");
351
+ f(this, "colors");
352
+ f(this, "opacities");
353
+ f(this, "boundingBox", new fe());
355
354
  this.numSplats = e, this.allocateBuffers(e);
356
355
  }
357
356
  allocateBuffers(e) {
@@ -366,13 +365,13 @@ class Ie {
366
365
  * @param color Color
367
366
  * @param opacity Opacity value
368
367
  */
369
- setSplat(e, n, t, o, r, a) {
368
+ setSplat(e, o, t, r, n, a) {
370
369
  if (e >= this.numSplats)
371
370
  throw new Error(
372
371
  `Splat index out of bounds: ${e} >= ${this.numSplats}`
373
372
  );
374
- const i = e * 3, u = e * 4, v = e * 3, M = e * 3;
375
- this.positions[i] = n.x, this.positions[i + 1] = n.y, this.positions[i + 2] = n.z, this.rotations[u] = t.x, this.rotations[u + 1] = t.y, this.rotations[u + 2] = t.z, this.rotations[u + 3] = t.w, this.scales[v] = o.x, this.scales[v + 1] = o.y, this.scales[v + 2] = o.z, this.colors[M] = r.r, this.colors[M + 1] = r.g, this.colors[M + 2] = r.b, this.opacities[e] = a;
373
+ const i = e * 3, u = e * 4, w = e * 3, C = e * 3;
374
+ this.positions[i] = o.x, this.positions[i + 1] = o.y, this.positions[i + 2] = o.z, this.rotations[u] = t.x, this.rotations[u + 1] = t.y, this.rotations[u + 2] = t.z, this.rotations[u + 3] = t.w, this.scales[w] = r.x, this.scales[w + 1] = r.y, this.scales[w + 2] = r.z, this.colors[C] = n.r, this.colors[C + 1] = n.g, this.colors[C + 2] = n.b, this.opacities[e] = a;
376
375
  }
377
376
  /**
378
377
  * Get a splat's data
@@ -384,12 +383,12 @@ class Ie {
384
383
  throw new Error(
385
384
  `Splat index out of bounds: ${e} >= ${this.numSplats}`
386
385
  );
387
- const n = e * 3, t = e * 4, o = e * 3, r = e * 3;
386
+ const o = e * 3, t = e * 4, r = e * 3, n = e * 3;
388
387
  return {
389
388
  position: new l.Vector3(
390
- this.positions[n],
391
- this.positions[n + 1],
392
- this.positions[n + 2]
389
+ this.positions[o],
390
+ this.positions[o + 1],
391
+ this.positions[o + 2]
393
392
  ),
394
393
  rotation: new l.Quaternion(
395
394
  this.rotations[t],
@@ -399,14 +398,14 @@ class Ie {
399
398
  ),
400
399
  // Convert log scale back to linear scale for external use
401
400
  scale: new l.Vector3(
402
- Math.exp(this.scales[o]),
403
- Math.exp(this.scales[o + 1]),
404
- Math.exp(this.scales[o + 2])
401
+ Math.exp(this.scales[r]),
402
+ Math.exp(this.scales[r + 1]),
403
+ Math.exp(this.scales[r + 2])
405
404
  ),
406
405
  color: new l.Color(
407
- this.colors[r],
408
- this.colors[r + 1],
409
- this.colors[r + 2]
406
+ this.colors[n],
407
+ this.colors[n + 1],
408
+ this.colors[n + 2]
410
409
  ),
411
410
  opacity: this.opacities[e]
412
411
  };
@@ -418,8 +417,8 @@ class Ie {
418
417
  calculateBoundingBox() {
419
418
  this.boundingBox.reset();
420
419
  const e = new l.Vector3();
421
- for (let n = 0; n < this.numSplats; n++) {
422
- const t = n * 3;
420
+ for (let o = 0; o < this.numSplats; o++) {
421
+ const t = o * 3;
423
422
  e.set(
424
423
  this.positions[t],
425
424
  this.positions[t + 1],
@@ -438,19 +437,19 @@ class Ie {
438
437
  "position",
439
438
  new l.BufferAttribute(this.positions, 3)
440
439
  );
441
- const n = new Float32Array(this.numSplats * 3), t = new l.Quaternion(), o = new l.Euler();
442
- for (let r = 0; r < this.numSplats; r++) {
443
- const a = r * 4, i = r * 3;
440
+ const o = new Float32Array(this.numSplats * 3), t = new l.Quaternion(), r = new l.Euler();
441
+ for (let n = 0; n < this.numSplats; n++) {
442
+ const a = n * 4, i = n * 3;
444
443
  t.set(
445
444
  this.rotations[a],
446
445
  this.rotations[a + 1],
447
446
  this.rotations[a + 2],
448
447
  this.rotations[a + 3]
449
- ), o.setFromQuaternion(t), n[i] = o.x, n[i + 1] = o.y, n[i + 2] = o.z;
448
+ ), r.setFromQuaternion(t), o[i] = r.x, o[i + 1] = r.y, o[i + 2] = r.z;
450
449
  }
451
450
  return e.setAttribute(
452
451
  "rotation",
453
- new l.BufferAttribute(n, 3)
452
+ new l.BufferAttribute(o, 3)
454
453
  ), e.setAttribute(
455
454
  "scale",
456
455
  new l.BufferAttribute(this.scales, 3)
@@ -463,35 +462,35 @@ class Ie {
463
462
  ), e;
464
463
  }
465
464
  }
466
- class Re extends l.Loader {
467
- constructor(n) {
468
- super(n);
469
- d(this, "requestId", 0);
470
- d(this, "worker");
471
- d(this, "pendingCallbacks", /* @__PURE__ */ new Map());
472
- const t = this.createWorkerCode(), o = new Blob([t], { type: "application/javascript" });
473
- this.worker = new Worker(URL.createObjectURL(o)), this.worker.onmessage = this.onWorkerMessage.bind(this);
465
+ class ze extends l.Loader {
466
+ constructor(o) {
467
+ super(o);
468
+ f(this, "requestId", 0);
469
+ f(this, "worker");
470
+ f(this, "pendingCallbacks", /* @__PURE__ */ new Map());
471
+ const t = this.createWorkerCode(), r = new Blob([t], { type: "application/javascript" });
472
+ this.worker = new Worker(URL.createObjectURL(r)), this.worker.onmessage = this.onWorkerMessage.bind(this);
474
473
  }
475
474
  /**
476
475
  * Handles messages received from the parsing worker
477
476
  * @param event The message event from the worker
478
477
  */
479
- onWorkerMessage(n) {
480
- const { requestId: t, error: o, result: r } = n.data, a = this.pendingCallbacks.get(t);
478
+ onWorkerMessage(o) {
479
+ const { requestId: t, error: r, result: n } = o.data, a = this.pendingCallbacks.get(t);
481
480
  if (!a) return console.warn(`PlyLoader: Received response for unknown request ${t}`);
482
- if (this.pendingCallbacks.delete(t), o) return a.reject(new Error(o));
483
- if (!r) return a.reject(new Error("Worker returned no result"));
481
+ if (this.pendingCallbacks.delete(t), r) return a.reject(new Error(r));
482
+ if (!n) return a.reject(new Error("Worker returned no result"));
484
483
  try {
485
- const i = new Ie(0);
486
- i.numSplats = r.numSplats, i.positions = new Float32Array(r.positions), i.rotations = new Float32Array(r.rotations), i.scales = new Float32Array(r.scales), i.colors = new Float32Array(r.colors), i.opacities = new Float32Array(r.opacities), i.boundingBox.min.set(
487
- r.boundingBox.minX,
488
- r.boundingBox.minY,
489
- r.boundingBox.minZ
484
+ const i = new Re(0);
485
+ i.numSplats = n.numSplats, i.positions = new Float32Array(n.positions), i.rotations = new Float32Array(n.rotations), i.scales = new Float32Array(n.scales), i.colors = new Float32Array(n.colors), i.opacities = new Float32Array(n.opacities), i.boundingBox.min.set(
486
+ n.boundingBox.minX,
487
+ n.boundingBox.minY,
488
+ n.boundingBox.minZ
490
489
  ), i.boundingBox.max.set(
491
- r.boundingBox.maxX,
492
- r.boundingBox.maxY,
493
- r.boundingBox.maxZ
494
- ), a.resolve(i);
490
+ n.boundingBox.maxX,
491
+ n.boundingBox.maxY,
492
+ n.boundingBox.maxZ
493
+ ), this.worker.terminate(), a.resolve(i);
495
494
  } catch (i) {
496
495
  a.reject(i);
497
496
  }
@@ -503,19 +502,19 @@ class Re extends l.Loader {
503
502
  * @param onProgress Optional progress callback
504
503
  * @param onError Optional error callback
505
504
  */
506
- load(n, t, o, r) {
505
+ load(o, t, r, n) {
507
506
  const a = new l.FileLoader(this.manager);
508
507
  a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
509
- n,
508
+ o,
510
509
  (i) => {
511
510
  this.parseAsync(i).then((u) => {
512
511
  t && t(u);
513
512
  }).catch((u) => {
514
- r ? r(u) : console.error(u), this.manager.itemError(n);
513
+ n ? n(u) : console.error(u), this.manager.itemError(o);
515
514
  });
516
515
  },
517
- o,
518
- r
516
+ r,
517
+ n
519
518
  );
520
519
  }
521
520
  /**
@@ -524,19 +523,19 @@ class Re extends l.Loader {
524
523
  * @param onProgress Optional progress callback
525
524
  * @returns A Promise that resolves with the parsed SplatData
526
525
  */
527
- loadAsync(n, t) {
528
- return new Promise((o, r) => {
526
+ loadAsync(o, t) {
527
+ return new Promise((r, n) => {
529
528
  const a = new l.FileLoader(this.manager);
530
529
  a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
531
- n,
530
+ o,
532
531
  (i) => {
533
- this.parseAsync(i).then(o).catch((u) => {
534
- r(u), this.manager.itemError(n);
532
+ this.parseAsync(i).then(r).catch((u) => {
533
+ n(u), this.manager.itemError(o);
535
534
  });
536
535
  },
537
536
  t,
538
537
  (i) => {
539
- r(i), this.manager.itemError(n);
538
+ n(i), this.manager.itemError(o);
540
539
  }
541
540
  );
542
541
  });
@@ -546,15 +545,15 @@ class Re extends l.Loader {
546
545
  * @param buffer ArrayBuffer containing PLY data
547
546
  * @returns Promise that resolves with parsed SplatData
548
547
  */
549
- parseAsync(n) {
550
- return new Promise((t, o) => {
551
- const r = this.requestId++;
552
- this.pendingCallbacks.set(r, { resolve: t, reject: o });
548
+ parseAsync(o) {
549
+ return new Promise((t, r) => {
550
+ const n = this.requestId++;
551
+ this.pendingCallbacks.set(n, { resolve: t, reject: r });
553
552
  const a = {
554
- requestId: r,
555
- buffer: n
553
+ requestId: n,
554
+ buffer: o
556
555
  };
557
- this.worker.postMessage(a, [n]);
556
+ this.worker.postMessage(a, [o]);
558
557
  });
559
558
  }
560
559
  /**
@@ -569,11 +568,11 @@ class Re extends l.Loader {
569
568
  */
570
569
  createWorkerCode() {
571
570
  return `(${(function() {
572
- self.onmessage = (o) => {
573
- const { requestId: r, buffer: a } = o.data;
571
+ self.onmessage = (r) => {
572
+ const { requestId: n, buffer: a } = r.data;
574
573
  try {
575
574
  const i = t(a), u = {
576
- requestId: r,
575
+ requestId: n,
577
576
  result: i
578
577
  };
579
578
  self.postMessage(u, [
@@ -585,14 +584,14 @@ class Re extends l.Loader {
585
584
  ]);
586
585
  } catch (i) {
587
586
  const u = {
588
- requestId: r,
587
+ requestId: n,
589
588
  error: i instanceof Error ? i.message : String(i)
590
589
  };
591
590
  self.postMessage(u);
592
591
  }
593
592
  };
594
- function t(o) {
595
- const r = new TextDecoder(), a = new Uint8Array(o), i = [112, 108, 121, 10], u = `
593
+ function t(r) {
594
+ const n = new TextDecoder(), a = new Uint8Array(r), i = [112, 108, 121, 10], u = `
596
595
  end_header
597
596
  `;
598
597
  for (let m = 0; m < i.length; m++)
@@ -600,7 +599,7 @@ end_header
600
599
  throw new Error(
601
600
  "Invalid PLY file: Missing magic bytes"
602
601
  );
603
- let v = 0;
602
+ let w = 0;
604
603
  for (let m = 0; m < a.length - u.length; m++) {
605
604
  let c = !0;
606
605
  for (let y = 0; y < u.length; y++)
@@ -609,79 +608,79 @@ end_header
609
608
  break;
610
609
  }
611
610
  if (c) {
612
- v = m + u.length;
611
+ w = m + u.length;
613
612
  break;
614
613
  }
615
614
  }
616
- if (v === 0)
615
+ if (w === 0)
617
616
  throw new Error(
618
617
  "Invalid PLY file: Could not find end of header"
619
618
  );
620
- const T = r.decode(
621
- a.subarray(0, v)
619
+ const _ = n.decode(
620
+ a.subarray(0, w)
622
621
  ).split(`
623
- `), f = [];
624
- let w = null;
625
- for (let m = 1; m < T.length; m++) {
626
- const c = T[m].trim();
622
+ `), h = [];
623
+ let b = null;
624
+ for (let m = 1; m < _.length; m++) {
625
+ const c = _[m].trim();
627
626
  if (c === "" || c === "end_header") continue;
628
627
  const y = c.split(" ");
629
628
  switch (y[0]) {
630
629
  case "format":
631
- w = y[1];
630
+ b = y[1];
632
631
  break;
633
632
  case "element":
634
- f.push({
633
+ h.push({
635
634
  name: y[1],
636
635
  count: parseInt(y[2], 10),
637
636
  properties: []
638
637
  });
639
638
  break;
640
639
  case "property":
641
- if (f.length === 0)
640
+ if (h.length === 0)
642
641
  throw new Error(
643
642
  "Invalid PLY file: Property without element"
644
643
  );
645
- f[f.length - 1].properties.push({
644
+ h[h.length - 1].properties.push({
646
645
  type: y[1],
647
646
  name: y[2]
648
647
  });
649
648
  break;
650
649
  }
651
650
  }
652
- if (w !== "binary_little_endian")
653
- throw new Error(`Unsupported PLY format: ${w}`);
654
- const b = f.find((m) => m.name === "vertex");
655
- if (!b)
651
+ if (b !== "binary_little_endian")
652
+ throw new Error(`Unsupported PLY format: ${b}`);
653
+ const S = h.find((m) => m.name === "vertex");
654
+ if (!S)
656
655
  throw new Error(
657
656
  "Invalid PLY file: No vertex element found"
658
657
  );
659
- const I = b.count, z = new Float32Array(I * 3), j = new Float32Array(I * 4), H = new Float32Array(I * 3), W = new Float32Array(I * 3), ne = new Float32Array(I), L = new DataView(o);
660
- let _ = v;
661
- const x = (m) => b.properties.findIndex(
658
+ const I = S.count, P = new Float32Array(I * 3), j = new Float32Array(I * 4), H = new Float32Array(I * 3), W = new Float32Array(I * 3), oe = new Float32Array(I), L = new DataView(r);
659
+ let A = w;
660
+ const g = (m) => S.properties.findIndex(
662
661
  (c) => c.name === m
663
- ), D = x("x"), C = x("y"), g = x("z"), R = [
664
- x("rot_0"),
665
- x("rot_1"),
666
- x("rot_2"),
667
- x("rot_3")
662
+ ), D = g("x"), T = g("y"), v = g("z"), R = [
663
+ g("rot_0"),
664
+ g("rot_1"),
665
+ g("rot_2"),
666
+ g("rot_3")
668
667
  ], B = [
669
- x("scale_0"),
670
- x("scale_1"),
671
- x("scale_2")
672
- ], X = [
673
- x("f_dc_0"),
674
- x("f_dc_1"),
675
- x("f_dc_2")
676
- ], $ = x("opacity");
668
+ g("scale_0"),
669
+ g("scale_1"),
670
+ g("scale_2")
671
+ ], $ = [
672
+ g("f_dc_0"),
673
+ g("f_dc_1"),
674
+ g("f_dc_2")
675
+ ], X = g("opacity");
677
676
  if ([
678
677
  D,
679
- C,
680
- g,
678
+ T,
679
+ v,
681
680
  ...R,
682
681
  ...B,
683
- ...X,
684
- $
682
+ ...$,
683
+ X
685
684
  ].some((m) => m === -1))
686
685
  throw new Error(
687
686
  "Invalid PLY file: Missing required properties"
@@ -691,73 +690,73 @@ end_header
691
690
  const c = Math.exp(m);
692
691
  return c / (1 + c);
693
692
  };
694
- let N = 1 / 0, te = 1 / 0, s = 1 / 0, p = -1 / 0, S = -1 / 0, E = -1 / 0;
693
+ let N = 1 / 0, te = 1 / 0, s = 1 / 0, p = -1 / 0, M = -1 / 0, E = -1 / 0;
695
694
  for (let m = 0; m < I; m++) {
696
695
  const c = [];
697
- for (let fe = 0; fe < b.properties.length; fe++) {
698
- const de = b.properties[fe].type;
696
+ for (let he = 0; he < S.properties.length; he++) {
697
+ const pe = S.properties[he].type;
699
698
  let ee;
700
- switch (de) {
699
+ switch (pe) {
701
700
  case "char":
702
- ee = L.getInt8(_), _ += 1;
701
+ ee = L.getInt8(A), A += 1;
703
702
  break;
704
703
  case "uchar":
705
- ee = L.getUint8(_), _ += 1;
704
+ ee = L.getUint8(A), A += 1;
706
705
  break;
707
706
  case "short":
708
- ee = L.getInt16(_, !0), _ += 2;
707
+ ee = L.getInt16(A, !0), A += 2;
709
708
  break;
710
709
  case "ushort":
711
- ee = L.getUint16(_, !0), _ += 2;
710
+ ee = L.getUint16(A, !0), A += 2;
712
711
  break;
713
712
  case "int":
714
- ee = L.getInt32(_, !0), _ += 4;
713
+ ee = L.getInt32(A, !0), A += 4;
715
714
  break;
716
715
  case "uint":
717
- ee = L.getUint32(_, !0), _ += 4;
716
+ ee = L.getUint32(A, !0), A += 4;
718
717
  break;
719
718
  case "float":
720
- ee = L.getFloat32(_, !0), _ += 4;
719
+ ee = L.getFloat32(A, !0), A += 4;
721
720
  break;
722
721
  case "double":
723
- ee = L.getFloat64(_, !0), _ += 8;
722
+ ee = L.getFloat64(A, !0), A += 8;
724
723
  break;
725
724
  default:
726
725
  throw new Error(
727
- `Unsupported property type: ${de}`
726
+ `Unsupported property type: ${pe}`
728
727
  );
729
728
  }
730
729
  c.push(ee);
731
730
  }
732
- const y = c[D], P = c[C], h = c[g], k = m * 3;
733
- z[k] = y, z[k + 1] = P, z[k + 2] = h, N = Math.min(N, y), te = Math.min(te, P), s = Math.min(s, h), p = Math.max(p, y), S = Math.max(S, P), E = Math.max(E, h);
734
- let O = c[R[1]], V = c[R[2]], G = c[R[3]], q = c[R[0]];
731
+ const y = c[D], z = c[T], d = c[v], k = m * 3;
732
+ P[k] = y, P[k + 1] = z, P[k + 2] = d, N = Math.min(N, y), te = Math.min(te, z), s = Math.min(s, d), p = Math.max(p, y), M = Math.max(M, z), E = Math.max(E, d);
733
+ let O = c[R[1]], q = c[R[2]], G = c[R[3]], V = c[R[0]];
735
734
  const Y = Math.sqrt(
736
- O * O + V * V + G * G + q * q
735
+ O * O + q * q + G * G + V * V
737
736
  );
738
- Y > 0 && (O /= Y, V /= Y, G /= Y, q /= Y), q < 0 && (O = -O, V = -V, G = -G, q = -q);
739
- const Q = m * 4;
740
- j[Q] = O, j[Q + 1] = V, j[Q + 2] = G, j[Q + 3] = q;
741
- const K = m * 3;
742
- H[K] = c[B[0]], H[K + 1] = c[B[1]], H[K + 2] = c[B[2]];
743
- let re = 0.5 + c[X[0]] * U, oe = 0.5 + c[X[1]] * U, J = 0.5 + c[X[2]] * U;
744
- re = Math.max(0, Math.min(1, re)), oe = Math.max(0, Math.min(1, oe)), J = Math.max(0, Math.min(1, J));
737
+ Y > 0 && (O /= Y, q /= Y, G /= Y, V /= Y), V < 0 && (O = -O, q = -q, G = -G, V = -V);
738
+ const K = m * 4;
739
+ j[K] = O, j[K + 1] = q, j[K + 2] = G, j[K + 3] = V;
740
+ const Q = m * 3;
741
+ H[Q] = c[B[0]], H[Q + 1] = c[B[1]], H[Q + 2] = c[B[2]];
742
+ let re = 0.5 + c[$[0]] * U, ne = 0.5 + c[$[1]] * U, J = 0.5 + c[$[2]] * U;
743
+ re = Math.max(0, Math.min(1, re)), ne = Math.max(0, Math.min(1, ne)), J = Math.max(0, Math.min(1, J));
745
744
  const ue = m * 3;
746
- W[ue] = re, W[ue + 1] = oe, W[ue + 2] = J, ne[m] = F(c[$]);
745
+ W[ue] = re, W[ue + 1] = ne, W[ue + 2] = J, oe[m] = F(c[X]);
747
746
  }
748
747
  return {
749
748
  numSplats: I,
750
- positions: z.buffer,
749
+ positions: P.buffer,
751
750
  rotations: j.buffer,
752
751
  scales: H.buffer,
753
752
  colors: W.buffer,
754
- opacities: ne.buffer,
753
+ opacities: oe.buffer,
755
754
  boundingBox: {
756
755
  minX: N,
757
756
  minY: te,
758
757
  minZ: s,
759
758
  maxX: p,
760
- maxY: S,
759
+ maxY: M,
761
760
  maxZ: E
762
761
  }
763
762
  };
@@ -768,31 +767,31 @@ end_header
768
767
  class Pe extends l.EventDispatcher {
769
768
  constructor() {
770
769
  super();
771
- d(this, "worker");
772
- d(this, "centers", null);
773
- d(this, "orderTexture", null);
770
+ f(this, "worker");
771
+ f(this, "centers", null);
772
+ f(this, "orderTexture", null);
774
773
  /** Bounding box data for optimization */
775
- d(this, "chunks", null);
776
- d(this, "lastCameraPosition", new l.Vector3());
777
- d(this, "lastCameraDirection", new l.Vector3());
778
- const n = this.createWorkerCode(), t = new Blob([n], { type: "application/javascript" });
774
+ f(this, "chunks", null);
775
+ f(this, "lastCameraPosition", new l.Vector3());
776
+ f(this, "lastCameraDirection", new l.Vector3());
777
+ const o = this.createWorkerCode(), t = new Blob([o], { type: "application/javascript" });
779
778
  this.worker = new Worker(URL.createObjectURL(t)), this.worker.onmessage = this.onWorkerMessage.bind(this);
780
779
  }
781
780
  /**
782
781
  * Handles messages received from the sorting worker.
783
782
  * @param event The message event from the worker.
784
783
  */
785
- onWorkerMessage(n) {
784
+ onWorkerMessage(o) {
786
785
  if (!this.orderTexture || !this.orderTexture.image)
787
786
  return console.error("SplatSorter: Order texture not initialized!");
788
- const { order: t, count: o } = n.data, r = this.orderTexture.image.data;
789
- if (!(r instanceof Uint32Array))
787
+ const { order: t, count: r } = o.data, n = this.orderTexture.image.data;
788
+ if (!(n instanceof Uint32Array))
790
789
  return console.error(
791
790
  "SplatSorter: Order texture data is not a Uint32Array!"
792
791
  );
793
- r.set(new Uint32Array(t)), this.orderTexture.needsUpdate = !0;
794
- const a = r.buffer.slice(0), i = { order: a };
795
- this.worker.postMessage(i, [a]), this.dispatchEvent({ type: "updated", count: o });
792
+ n.set(new Uint32Array(t)), this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
793
+ const a = n.buffer.slice(0), i = { order: a };
794
+ this.worker.postMessage(i, [a]), this.dispatchEvent({ type: "updated", count: r });
796
795
  }
797
796
  /**
798
797
  * Initializes the sorter with necessary data and textures.
@@ -801,31 +800,35 @@ class Pe extends l.EventDispatcher {
801
800
  * @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
802
801
  * @param transferOwnership Optional: If true, transfers ownership of centers buffer to worker (saves memory, main thread loses access). Default: false.
803
802
  */
804
- init(n, t, o, r = !1) {
805
- if (!n || !(n.image.data instanceof Uint32Array))
803
+ init(o, t, r, n = !1) {
804
+ if (!o || !(o.image.data instanceof Uint32Array))
806
805
  throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
807
806
  if (!t || t.length % 3 !== 0)
808
807
  throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
809
- if (n.image.data.length < t.length / 3)
808
+ if (o.image.data.length < t.length / 3)
810
809
  throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");
810
+ if (t.buffer.byteLength === 0)
811
+ throw new Error(
812
+ "SplatSorter: positions buffer is detached (likely React StrictMode + cached asset). "
813
+ );
811
814
  const a = t.length / 3;
812
- this.orderTexture = n, r ? this.centers = null : this.centers = t.slice();
815
+ this.orderTexture = o, n ? this.centers = null : this.centers = t.slice();
813
816
  const i = this.orderTexture.image.data;
814
- for (let f = 0; f < a; f++) i[f] = f;
815
- this.orderTexture.needsUpdate = !0;
816
- const u = i.buffer.slice(0), v = r ? t.buffer : t.buffer.slice(0), M = {
817
+ for (let h = 0; h < a; h++) i[h] = h;
818
+ this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
819
+ const u = i.buffer.slice(0), w = n ? t.buffer : t.buffer.slice(0), C = {
817
820
  order: u,
818
- centers: v
819
- }, T = [
821
+ centers: w
822
+ }, _ = [
820
823
  u,
821
- v
824
+ w
822
825
  ];
823
- if (o) {
824
- this.chunks = o.slice();
825
- const f = this.chunks.buffer.slice(0);
826
- M.chunks = f, T.push(f);
826
+ if (r) {
827
+ this.chunks = r.slice();
828
+ const h = this.chunks.buffer.slice(0);
829
+ C.chunks = h, _.push(h);
827
830
  }
828
- this.worker.postMessage(M, T), queueMicrotask(() => {
831
+ this.worker.postMessage(C, _), queueMicrotask(() => {
829
832
  this.dispatchEvent({
830
833
  type: "updated",
831
834
  count: a
@@ -837,50 +840,50 @@ class Pe extends l.EventDispatcher {
837
840
  * The sorter will only consider splats whose original indices are present in the mapping.
838
841
  * @param mapping A Uint32Array where each element is the *original* index of a splat to include, or null to reset mapping.
839
842
  */
840
- setMapping(n) {
843
+ setMapping(o) {
841
844
  if (!this.centers)
842
845
  return console.warn(
843
846
  "SplatSorter: Cannot set mapping before initialization."
844
847
  );
845
848
  let t;
846
- const o = [];
847
- if (!n) {
849
+ const r = [];
850
+ if (!o) {
848
851
  const u = this.centers.buffer.slice(0);
849
852
  return t = {
850
853
  centers: u,
851
854
  mapping: null
852
- }, o.push(u), this.worker.postMessage(t, o);
855
+ }, r.push(u), this.worker.postMessage(t, r);
853
856
  }
854
- const r = new Float32Array(n.length * 3);
855
- for (let u = 0; u < n.length; u++) {
856
- const v = n[u];
857
- if (v * 3 + 2 >= this.centers.length) {
857
+ const n = new Float32Array(o.length * 3);
858
+ for (let u = 0; u < o.length; u++) {
859
+ const w = o[u];
860
+ if (w * 3 + 2 >= this.centers.length) {
858
861
  console.warn(
859
- `SplatSorter: Mapping index ${v} out of bounds.`
862
+ `SplatSorter: Mapping index ${w} out of bounds.`
860
863
  );
861
864
  continue;
862
865
  }
863
- const M = v * 3, T = u * 3;
864
- r[T + 0] = this.centers[M + 0], r[T + 1] = this.centers[M + 1], r[T + 2] = this.centers[M + 2];
866
+ const C = w * 3, _ = u * 3;
867
+ n[_ + 0] = this.centers[C + 0], n[_ + 1] = this.centers[C + 1], n[_ + 2] = this.centers[C + 2];
865
868
  }
866
- const a = r.buffer.slice(0), i = n.buffer.slice(0);
869
+ const a = n.buffer.slice(0), i = o.buffer.slice(0);
867
870
  t = {
868
871
  centers: a,
869
872
  mapping: i
870
- }, o.push(a, i), this.worker.postMessage(t, o);
873
+ }, r.push(a, i), this.worker.postMessage(t, r);
871
874
  }
872
875
  /**
873
876
  * Updates the camera parameters used for sorting.
874
877
  * @param position The camera's position in the sorter's local coordinate space.
875
878
  * @param direction The camera's forward direction in the sorter's local coordinate space.
876
879
  */
877
- setCamera(n, t) {
878
- const o = this.lastCameraPosition.distanceToSquared(n) > 1e-7, r = this.lastCameraDirection.dot(t) < 0.9999;
879
- if (!o && !r)
880
+ setCamera(o, t) {
881
+ const r = this.lastCameraPosition.distanceToSquared(o) > 1e-7, n = this.lastCameraDirection.dot(t) < 0.9999;
882
+ if (!r && !n)
880
883
  return;
881
- this.lastCameraPosition.copy(n), this.lastCameraDirection.copy(t);
884
+ this.lastCameraPosition.copy(o), this.lastCameraDirection.copy(t);
882
885
  const a = {
883
- cameraPosition: { x: n.x, y: n.y, z: n.z },
886
+ cameraPosition: { x: o.x, y: o.y, z: o.z },
884
887
  cameraDirection: { x: t.x, y: t.y, z: t.z }
885
888
  };
886
889
  this.worker.postMessage(a);
@@ -897,21 +900,21 @@ class Pe extends l.EventDispatcher {
897
900
  */
898
901
  createWorkerCode() {
899
902
  return `(${(function() {
900
- let t = null, o = null, r = null, a = null, i = null, u = null, v = !1;
901
- const M = { x: 0, y: 0, z: 0 }, T = { x: 0, y: 0, z: 0 }, f = { x: 0, y: 0, z: 0 }, w = { x: 0, y: 0, z: 0 };
902
- let b = null, I = null;
903
- const z = 32, j = new Array(z).fill(0), H = new Array(z).fill(0), W = new Array(z).fill(0), ne = (_, x, D) => {
904
- for (; _ <= x; ) {
905
- const C = x + _ >> 1, g = D(C);
906
- if (g > 0) _ = C + 1;
907
- else if (g < 0) x = C - 1;
908
- else return C;
903
+ let t = null, r = null, n = null, a = null, i = null, u = null, w = !1;
904
+ const C = { x: 0, y: 0, z: 0 }, _ = { x: 0, y: 0, z: 0 }, h = { x: 0, y: 0, z: 0 }, b = { x: 0, y: 0, z: 0 };
905
+ let S = null, I = null;
906
+ const P = 32, j = new Array(P).fill(0), H = new Array(P).fill(0), W = new Array(P).fill(0), oe = (A, g, D) => {
907
+ for (; A <= g; ) {
908
+ const T = g + A >> 1, v = D(T);
909
+ if (v > 0) A = T + 1;
910
+ else if (v < 0) g = T - 1;
911
+ else return T;
909
912
  }
910
- return ~_;
913
+ return ~A;
911
914
  }, L = () => {
912
- if (!t || !o || !i || !u)
915
+ if (!t || !r || !i || !u)
913
916
  return;
914
- if (o.length === 0) {
917
+ if (r.length === 0) {
915
918
  const c = {
916
919
  order: t.buffer,
917
920
  count: 0
@@ -919,80 +922,80 @@ class Pe extends l.EventDispatcher {
919
922
  self.postMessage(c, [t.buffer]), t = null;
920
923
  return;
921
924
  }
922
- const _ = i.x, x = i.y, D = i.z, C = u.x, g = u.y, R = u.z, B = 1e-4, X = Math.abs(_ - M.x) > B || Math.abs(x - M.y) > B || Math.abs(D - M.z) > B, $ = Math.abs(C - T.x) > B || Math.abs(g - T.y) > B || Math.abs(R - T.z) > B;
923
- if (!v && !X && !$)
925
+ const A = i.x, g = i.y, D = i.z, T = u.x, v = u.y, R = u.z, B = 1e-4, $ = Math.abs(A - C.x) > B || Math.abs(g - C.y) > B || Math.abs(D - C.z) > B, X = Math.abs(T - _.x) > B || Math.abs(v - _.y) > B || Math.abs(R - _.z) > B;
926
+ if (!w && !$ && !X)
924
927
  return;
925
- v = !1, M.x = _, M.y = x, M.z = D, T.x = C, T.y = g, T.z = R;
928
+ w = !1, C.x = A, C.y = g, C.z = D, _.x = T, _.y = v, _.z = R;
926
929
  let Z = 1 / 0, U = -1 / 0;
927
930
  for (let c = 0; c < 8; ++c) {
928
- const y = c & 1 ? f.x : w.x, P = c & 2 ? f.y : w.y, h = c & 4 ? f.z : w.z, k = y * C + P * g + h * R;
931
+ const y = c & 1 ? h.x : b.x, z = c & 2 ? h.y : b.y, d = c & 4 ? h.z : b.z, k = y * T + z * v + d * R;
929
932
  Z = Math.min(Z, k), U = Math.max(U, k);
930
933
  }
931
- const F = o.length / 3, N = U - Z, s = (1 << Math.max(
934
+ const F = r.length / 3, N = U - Z, s = (1 << Math.max(
932
935
  10,
933
936
  Math.min(20, Math.ceil(Math.log2(F / 4)))
934
937
  )) + 1;
935
- if ((!b || b.length !== F) && (b = new Uint32Array(F)), !I || I.length !== s ? I = new Uint32Array(s) : I.fill(0), N < 1e-7) {
936
- for (let c = 0; c < F; ++c) b[c] = 0;
938
+ if ((!S || S.length !== F) && (S = new Uint32Array(F)), !I || I.length !== s ? I = new Uint32Array(s) : I.fill(0), N < 1e-7) {
939
+ for (let c = 0; c < F; ++c) S[c] = 0;
937
940
  I[0] = F;
938
- } else if (r && r.length > 0) {
939
- const c = r.length / 6;
941
+ } else if (n && n.length > 0) {
942
+ const c = n.length / 6;
940
943
  j.fill(0);
941
- for (let h = 0; h < c; ++h) {
942
- const k = h * 6, O = r[k + 0], V = r[k + 1], G = r[k + 2], q = r[k + 3], Y = O * C + V * g + G * R - Z, Q = Y - q, K = Y + q, re = Math.max(
944
+ for (let d = 0; d < c; ++d) {
945
+ const k = d * 6, O = n[k + 0], q = n[k + 1], G = n[k + 2], V = n[k + 3], Y = O * T + q * v + G * R - Z, K = Y - V, Q = Y + V, re = Math.max(
943
946
  0,
944
- Math.floor(Q * z / N)
945
- ), oe = Math.min(
946
- z,
947
- Math.ceil(K * z / N)
947
+ Math.floor(K * P / N)
948
+ ), ne = Math.min(
949
+ P,
950
+ Math.ceil(Q * P / N)
948
951
  );
949
- for (let J = re; J < oe; ++J)
952
+ for (let J = re; J < ne; ++J)
950
953
  j[J]++;
951
954
  }
952
955
  let y = 0;
953
- for (let h = 0; h < z; ++h) y += j[h];
956
+ for (let d = 0; d < P; ++d) y += j[d];
954
957
  W[0] = 0, H[0] = 0;
955
- for (let h = 1; h < z; ++h)
956
- W[h - 1] = j[h - 1] / y * s >>> 0, H[h] = H[h - 1] + W[h - 1];
957
- W[z - 1] = j[z - 1] / y * s >>> 0;
958
- const P = N / z;
959
- for (let h = 0; h < F; ++h) {
960
- const k = h * 3, O = o[k + 0], V = o[k + 1], G = o[k + 2], q = O * C + V * g + G * R, Q = (U - q) / P, K = Math.max(
958
+ for (let d = 1; d < P; ++d)
959
+ W[d - 1] = j[d - 1] / y * s >>> 0, H[d] = H[d - 1] + W[d - 1];
960
+ W[P - 1] = j[P - 1] / y * s >>> 0;
961
+ const z = N / P;
962
+ for (let d = 0; d < F; ++d) {
963
+ const k = d * 3, O = r[k + 0], q = r[k + 1], G = r[k + 2], V = O * T + q * v + G * R, K = (U - V) / z, Q = Math.max(
961
964
  0,
962
965
  Math.min(
963
- z - 1,
964
- Math.floor(Q)
966
+ P - 1,
967
+ Math.floor(K)
965
968
  )
966
- ), re = Q - K, oe = H[K] + W[K] * re >>> 0, J = Math.min(oe, s - 1);
967
- b[h] = J, I[J]++;
969
+ ), re = K - Q, ne = H[Q] + W[Q] * re >>> 0, J = Math.min(ne, s - 1);
970
+ S[d] = J, I[J]++;
968
971
  }
969
972
  } else {
970
973
  const c = (s - 1) / N;
971
974
  for (let y = 0; y < F; ++y) {
972
- const P = y * 3, h = o[P + 0], k = o[P + 1], O = o[P + 2], V = h * C + k * g + O * R, q = (U - V) * c >>> 0, Y = Math.min(q, s - 1);
973
- b[y] = Y, I[Y]++;
975
+ const z = y * 3, d = r[z + 0], k = r[z + 1], O = r[z + 2], q = d * T + k * v + O * R, V = (U - q) * c >>> 0, Y = Math.min(V, s - 1);
976
+ S[y] = Y, I[Y]++;
974
977
  }
975
978
  }
976
979
  for (let c = 1; c < s; c++)
977
980
  I[c] += I[c - 1];
978
981
  for (let c = F - 1; c >= 0; c--) {
979
- const y = b[c], P = --I[y];
980
- t[P] = a ? a[c] : c;
982
+ const y = S[c], z = --I[y];
983
+ t[z] = a ? a[c] : c;
981
984
  }
982
- const p = _ * C + x * g + D * R, S = (c) => {
985
+ const p = A * T + g * v + D * R, M = (c) => {
983
986
  if (!t) return -1 / 0;
984
- const y = t[c], P = y;
985
- if (!o || P * 3 + 2 >= o.length)
987
+ const y = t[c], z = y;
988
+ if (!r || z * 3 + 2 >= r.length)
986
989
  return -1 / 0;
987
- const h = P * 3;
988
- return o[h] * C + o[h + 1] * g + o[h + 2] * R - p;
990
+ const d = z * 3;
991
+ return r[d] * T + r[d + 1] * v + r[d + 2] * R - p;
989
992
  };
990
993
  let E = F;
991
- if (F > 0 && S(F - 1) < 0) {
992
- const c = ne(
994
+ if (F > 0 && M(F - 1) < 0) {
995
+ const c = oe(
993
996
  0,
994
997
  F - 1,
995
- S
998
+ M
996
999
  );
997
1000
  E = c < 0 ? ~c : c;
998
1001
  }
@@ -1002,60 +1005,60 @@ class Pe extends l.EventDispatcher {
1002
1005
  };
1003
1006
  self.postMessage(m, [t.buffer]), t = null;
1004
1007
  };
1005
- self.onmessage = (_) => {
1006
- const x = _.data;
1007
- x.order && (t = new Uint32Array(x.order));
1008
+ self.onmessage = (A) => {
1009
+ const g = A.data;
1010
+ g.order && (t = new Uint32Array(g.order));
1008
1011
  let D = !1;
1009
- if (x.centers && (o = new Float32Array(x.centers), D = !0, v = !0), Object.prototype.hasOwnProperty.call(x, "mapping") && (a = x.mapping ? new Uint32Array(x.mapping) : null, v = !0), x.chunks) {
1010
- if (r = new Float32Array(x.chunks), r.length > 0 && r[3] > 0)
1011
- for (let C = 0; C < r.length / 6; ++C) {
1012
- const g = C * 6, R = r[g + 0], B = r[g + 1], X = r[g + 2], $ = r[g + 3], Z = r[g + 4], U = r[g + 5];
1013
- r[g + 0] = (R + $) * 0.5, r[g + 1] = (B + Z) * 0.5, r[g + 2] = (X + U) * 0.5, r[g + 3] = Math.sqrt(
1014
- ($ - R) ** 2 + (Z - B) ** 2 + (U - X) ** 2
1012
+ if (g.centers && (r = new Float32Array(g.centers), D = !0, w = !0), Object.prototype.hasOwnProperty.call(g, "mapping") && (a = g.mapping ? new Uint32Array(g.mapping) : null, w = !0), g.chunks) {
1013
+ if (n = new Float32Array(g.chunks), n.length > 0 && n[3] > 0)
1014
+ for (let T = 0; T < n.length / 6; ++T) {
1015
+ const v = T * 6, R = n[v + 0], B = n[v + 1], $ = n[v + 2], X = n[v + 3], Z = n[v + 4], U = n[v + 5];
1016
+ n[v + 0] = (R + X) * 0.5, n[v + 1] = (B + Z) * 0.5, n[v + 2] = ($ + U) * 0.5, n[v + 3] = Math.sqrt(
1017
+ (X - R) ** 2 + (Z - B) ** 2 + (U - $) ** 2
1015
1018
  ) * 0.5;
1016
1019
  }
1017
- v = !0;
1020
+ w = !0;
1018
1021
  }
1019
- if (D && o && o.length > 0) {
1020
- f.x = w.x = o[0], f.y = w.y = o[1], f.z = w.z = o[2];
1021
- for (let C = 1; C < o.length / 3; C++) {
1022
- const g = C * 3;
1023
- f.x = Math.min(f.x, o[g + 0]), w.x = Math.max(w.x, o[g + 0]), f.y = Math.min(f.y, o[g + 1]), w.y = Math.max(w.y, o[g + 1]), f.z = Math.min(f.z, o[g + 2]), w.z = Math.max(w.z, o[g + 2]);
1022
+ if (D && r && r.length > 0) {
1023
+ h.x = b.x = r[0], h.y = b.y = r[1], h.z = b.z = r[2];
1024
+ for (let T = 1; T < r.length / 3; T++) {
1025
+ const v = T * 3;
1026
+ h.x = Math.min(h.x, r[v + 0]), b.x = Math.max(b.x, r[v + 0]), h.y = Math.min(h.y, r[v + 1]), b.y = Math.max(b.y, r[v + 1]), h.z = Math.min(h.z, r[v + 2]), b.z = Math.max(b.z, r[v + 2]);
1024
1027
  }
1025
- } else D && o && o.length === 0 && (f.x = w.x = f.y = w.y = f.z = w.z = 0);
1026
- x.cameraPosition && (i = x.cameraPosition), x.cameraDirection && (u = x.cameraDirection), L();
1028
+ } else D && r && r.length === 0 && (h.x = b.x = h.y = b.y = h.z = b.z = 0);
1029
+ g.cameraPosition && (i = g.cameraPosition), g.cameraDirection && (u = g.cameraDirection), L();
1027
1030
  };
1028
1031
  }).toString()})();`;
1029
1032
  }
1030
1033
  }
1031
- const ze = (A, e) => {
1032
- const n = ye(A), t = ye(e);
1033
- return n | t << 16;
1034
+ const Be = (x, e) => {
1035
+ const o = ye(x), t = ye(e);
1036
+ return o | t << 16;
1034
1037
  };
1035
- function ye(A) {
1036
- const e = new Float32Array([A]), t = new Int32Array(e.buffer)[0];
1037
- let o = t >> 16 & 32768, r = t >> 12 & 2047;
1038
+ function ye(x) {
1039
+ const e = new Float32Array([x]), t = new Int32Array(e.buffer)[0];
1040
+ let r = t >> 16 & 32768, n = t >> 12 & 2047;
1038
1041
  const a = t >> 23 & 255;
1039
- return a < 103 ? o : a > 142 ? (o |= 31744, o |= (a === 255 ? 0 : 1) && t & 8388607, o) : a < 113 ? (r |= 2048, o |= (r >> 114 - a) + (r >> 113 - a & 1), o) : (o |= a - 112 << 10 | r >> 1, o += r & 1, o);
1042
+ return a < 103 ? r : a > 142 ? (r |= 31744, r |= (a === 255 ? 0 : 1) && t & 8388607, r) : a < 113 ? (n |= 2048, r |= (n >> 114 - a) + (n >> 113 - a & 1), r) : (r |= a - 112 << 10 | n >> 1, r += n & 1, r);
1040
1043
  }
1041
- const Be = new ArrayBuffer(4), ge = new DataView(Be), Fe = (A) => (ge.setUint32(0, A, !0), ge.getFloat32(0, !0));
1042
- class Oe {
1044
+ const Fe = new ArrayBuffer(4), ve = new DataView(Fe), Oe = (x) => (ve.setUint32(0, x, !0), ve.getFloat32(0, !0));
1045
+ class De {
1043
1046
  /**
1044
1047
  * Create a new TextureManager for a set of splats
1045
1048
  * @param splatData The splat data to manage textures for
1046
1049
  */
1047
1050
  constructor(e) {
1048
- d(this, "transformA");
1051
+ f(this, "textureWidth");
1052
+ f(this, "textureHeight");
1053
+ f(this, "transformA");
1049
1054
  // position xyz and rotation quaternion y,z components
1050
- d(this, "transformB");
1055
+ f(this, "transformB");
1051
1056
  // rotation quaternion x and scale xyz
1052
- d(this, "colorTexture");
1057
+ f(this, "colorTexture");
1053
1058
  // color an opacity
1054
- d(this, "orderTexture");
1055
- d(this, "textureWidth");
1056
- d(this, "textureHeight");
1057
- const n = e.numSplats;
1058
- this.textureWidth = Math.ceil(Math.sqrt(n)), this.textureHeight = Math.ceil(n / this.textureWidth), this.transformA = this.createTransformATexture(e), this.transformB = this.createTransformBTexture(e), this.colorTexture = this.createColorTexture(e), this.orderTexture = this.createOrderTexture(n);
1059
+ f(this, "orderTexture");
1060
+ const o = e.numSplats;
1061
+ this.textureWidth = Math.ceil(Math.sqrt(o)), this.textureHeight = Math.ceil(o / this.textureWidth), this.transformA = this.createTransformATexture(e), this.transformB = this.createTransformBTexture(e), this.colorTexture = this.createColorTexture(e), this.orderTexture = this.createOrderTexture(o);
1059
1062
  }
1060
1063
  /**
1061
1064
  * Create the transform A texture (positions and quaternion w component)
@@ -1063,16 +1066,16 @@ class Oe {
1063
1066
  * @returns DataTexture containing position data
1064
1067
  */
1065
1068
  createTransformATexture(e) {
1066
- const n = e.numSplats, t = new Float32Array(
1069
+ const o = e.numSplats, t = new Float32Array(
1067
1070
  this.textureWidth * this.textureHeight * 4
1068
1071
  );
1069
- for (let r = 0; r < n; r++) {
1070
- const a = r * 4, i = r * 3, u = r * 4;
1072
+ for (let n = 0; n < o; n++) {
1073
+ const a = n * 4, i = n * 3, u = n * 4;
1071
1074
  t[a] = e.positions[i], t[a + 1] = e.positions[i + 1], t[a + 2] = e.positions[i + 2];
1072
- const v = e.rotations[u + 0], M = e.rotations[u + 1], T = ze(v, M);
1073
- t[a + 3] = Fe(T);
1075
+ const w = e.rotations[u + 0], C = e.rotations[u + 1], _ = Be(w, C);
1076
+ t[a + 3] = Oe(_);
1074
1077
  }
1075
- const o = new l.DataTexture(
1078
+ const r = new l.DataTexture(
1076
1079
  t,
1077
1080
  this.textureWidth,
1078
1081
  this.textureHeight,
@@ -1080,7 +1083,7 @@ class Oe {
1080
1083
  l.FloatType
1081
1084
  // Store as Float32, shader will reinterpret bits
1082
1085
  );
1083
- return o.needsUpdate = !0, o.magFilter = l.NearestFilter, o.minFilter = l.NearestFilter, o;
1086
+ return r.magFilter = l.NearestFilter, r.minFilter = l.NearestFilter, r.source.data.updateRanges || (r.source.data.updateRanges = []), r.needsUpdate = !0, r;
1084
1087
  }
1085
1088
  /**
1086
1089
  * Create the transform B texture (scale and rotation xyz)
@@ -1088,21 +1091,21 @@ class Oe {
1088
1091
  * @returns DataTexture containing scale and rotation data
1089
1092
  */
1090
1093
  createTransformBTexture(e) {
1091
- const n = e.numSplats, t = new Float32Array(
1094
+ const o = e.numSplats, t = new Float32Array(
1092
1095
  this.textureWidth * this.textureHeight * 4
1093
1096
  );
1094
- for (let r = 0; r < n; r++) {
1095
- const a = r * 4, i = r * 3, u = r * 4;
1097
+ for (let n = 0; n < o; n++) {
1098
+ const a = n * 4, i = n * 3, u = n * 4;
1096
1099
  t[a] = e.scales[i], t[a + 1] = e.scales[i + 1], t[a + 2] = e.scales[i + 2], t[a + 3] = e.rotations[u + 2];
1097
1100
  }
1098
- const o = new l.DataTexture(
1101
+ const r = new l.DataTexture(
1099
1102
  t,
1100
1103
  this.textureWidth,
1101
1104
  this.textureHeight,
1102
1105
  l.RGBAFormat,
1103
1106
  l.FloatType
1104
1107
  );
1105
- return o.needsUpdate = !0, o.magFilter = l.NearestFilter, o.minFilter = l.NearestFilter, o;
1108
+ return r.magFilter = l.NearestFilter, r.minFilter = l.NearestFilter, r.source.data.updateRanges || (r.source.data.updateRanges = []), r.needsUpdate = !0, r;
1106
1109
  }
1107
1110
  /**
1108
1111
  * Create the color texture (RGB and opacity)
@@ -1110,21 +1113,21 @@ class Oe {
1110
1113
  * @returns DataTexture containing color data
1111
1114
  */
1112
1115
  createColorTexture(e) {
1113
- const n = e.numSplats, t = new Float32Array(
1116
+ const o = e.numSplats, t = new Float32Array(
1114
1117
  this.textureWidth * this.textureHeight * 4
1115
1118
  );
1116
- for (let r = 0; r < n; r++) {
1117
- const a = r * 4, i = r * 3;
1118
- t[a] = e.colors[i], t[a + 1] = e.colors[i + 1], t[a + 2] = e.colors[i + 2], t[a + 3] = e.opacities[r];
1119
+ for (let n = 0; n < o; n++) {
1120
+ const a = n * 4, i = n * 3;
1121
+ t[a] = e.colors[i], t[a + 1] = e.colors[i + 1], t[a + 2] = e.colors[i + 2], t[a + 3] = e.opacities[n];
1119
1122
  }
1120
- const o = new l.DataTexture(
1123
+ const r = new l.DataTexture(
1121
1124
  t,
1122
1125
  this.textureWidth,
1123
1126
  this.textureHeight,
1124
1127
  l.RGBAFormat,
1125
1128
  l.FloatType
1126
1129
  );
1127
- return o.needsUpdate = !0, o;
1130
+ return r.source.data.updateRanges || (r.source.data.updateRanges = []), r.needsUpdate = !0, r;
1128
1131
  }
1129
1132
  /**
1130
1133
  * Create the order texture for sorting
@@ -1132,23 +1135,23 @@ class Oe {
1132
1135
  * @returns DataTexture for storing order indices
1133
1136
  */
1134
1137
  createOrderTexture(e) {
1135
- const n = new Uint32Array(this.textureWidth * this.textureHeight);
1136
- for (let o = 0; o < e; o++)
1137
- n[o] = o;
1138
+ const o = new Uint32Array(this.textureWidth * this.textureHeight);
1139
+ for (let r = 0; r < e; r++)
1140
+ o[r] = r;
1138
1141
  const t = new l.DataTexture(
1139
- n,
1142
+ o,
1140
1143
  this.textureWidth,
1141
1144
  this.textureHeight,
1142
1145
  l.RedIntegerFormat,
1143
1146
  l.UnsignedIntType
1144
1147
  );
1145
- return t.needsUpdate = !0, t;
1148
+ return t.source.data.updateRanges || (t.source.data.updateRanges = []), t.needsUpdate = !0, t;
1146
1149
  }
1147
1150
  dispose() {
1148
1151
  this.transformA.dispose(), this.transformB.dispose(), this.colorTexture.dispose(), this.orderTexture.dispose();
1149
1152
  }
1150
1153
  }
1151
- const De = (
1154
+ const Ue = (
1152
1155
  /* glsl */
1153
1156
  `
1154
1157
  precision highp float;
@@ -1406,7 +1409,7 @@ void main(void) {
1406
1409
  vUv = clippedCornerOffset;
1407
1410
  }
1408
1411
  `
1409
- ), Ue = (
1412
+ ), qe = (
1410
1413
  /* glsl */
1411
1414
  `
1412
1415
  precision highp float;
@@ -1442,7 +1445,7 @@ void main(void) {
1442
1445
  );
1443
1446
  class Ve extends l.ShaderMaterial {
1444
1447
  constructor(e = {}) {
1445
- const n = {
1448
+ const o = {
1446
1449
  // Textures (values set via methods)
1447
1450
  transformA: { value: null },
1448
1451
  transformB: { value: null },
@@ -1455,9 +1458,9 @@ class Ve extends l.ShaderMaterial {
1455
1458
  // Max splats to render (updated by sorter)
1456
1459
  };
1457
1460
  super({
1458
- vertexShader: De,
1459
- fragmentShader: Ue,
1460
- uniforms: n,
1461
+ vertexShader: Ue,
1462
+ fragmentShader: qe,
1463
+ uniforms: o,
1461
1464
  transparent: !0,
1462
1465
  blending: l.CustomBlending,
1463
1466
  // Premultiplied alpha blending:
@@ -1488,8 +1491,8 @@ class Ve extends l.ShaderMaterial {
1488
1491
  * @param width Viewport width
1489
1492
  * @param height Viewport height
1490
1493
  */
1491
- updateViewport(e, n) {
1492
- this.uniforms.viewport.value.set(e, n);
1494
+ updateViewport(e, o) {
1495
+ this.uniforms.viewport.value.set(e, o);
1493
1496
  }
1494
1497
  /**
1495
1498
  * Set transform texture A (positions)
@@ -1534,41 +1537,41 @@ const se = class se extends l.Mesh {
1534
1537
  * @param splatData The splat data to render
1535
1538
  * @param options Rendering options
1536
1539
  */
1537
- constructor(n, t = {}) {
1538
- const o = new Ve(t), r = se.createInstancedGeometry(n.numSplats, se.INSTANCE_SIZE);
1539
- super(r, o);
1540
- d(this, "sorter");
1541
- d(this, "splatData");
1542
- d(this, "options");
1543
- d(this, "textureManager");
1544
- d(this, "material");
1545
- d(this, "geometry");
1546
- d(this, "lastCameraPositionLocal", new l.Vector3());
1547
- d(this, "lastCameraDirectionLocal", new l.Vector3());
1548
- d(this, "invModelMatrix", new l.Matrix4());
1540
+ constructor(o, t = {}) {
1541
+ const r = new Ve(t), n = se.createInstancedGeometry(o.numSplats, se.INSTANCE_SIZE);
1542
+ super(n, r);
1543
+ f(this, "sorter");
1544
+ f(this, "splatData");
1545
+ f(this, "options");
1546
+ f(this, "textureManager");
1547
+ f(this, "material");
1548
+ f(this, "geometry");
1549
+ f(this, "lastCameraPositionLocal", new l.Vector3());
1550
+ f(this, "lastCameraDirectionLocal", new l.Vector3());
1551
+ f(this, "invModelMatrix", new l.Matrix4());
1549
1552
  // Cached inverse matrix
1550
- d(this, "_vpW", -1);
1551
- d(this, "_vpH", -1);
1552
- d(this, "_size", new l.Vector2());
1553
- d(this, "_camPosW", new l.Vector3());
1554
- d(this, "_camDirW", new l.Vector3());
1555
- d(this, "_camPosL", new l.Vector3());
1556
- d(this, "_camDirL", new l.Vector3());
1557
- d(this, "onSorterUpdated", (n) => {
1558
- const t = n.count;
1553
+ f(this, "_vpW", -1);
1554
+ f(this, "_vpH", -1);
1555
+ f(this, "_size", new l.Vector2());
1556
+ f(this, "_camPosW", new l.Vector3());
1557
+ f(this, "_camDirW", new l.Vector3());
1558
+ f(this, "_camPosL", new l.Vector3());
1559
+ f(this, "_camDirL", new l.Vector3());
1560
+ f(this, "onSorterUpdated", (o) => {
1561
+ const t = o.count;
1559
1562
  this.geometry.instanceCount = Math.ceil(t / se.INSTANCE_SIZE), this.material.setNumSplats(t);
1560
1563
  });
1561
- this.geometry = r, this.material = o, this.splatData = n, this.frustumCulled = !1, this.options = {
1564
+ this.geometry = n, this.material = r, this.splatData = o, this.frustumCulled = !1, this.options = {
1562
1565
  autoSort: !0,
1563
1566
  ...t
1564
- }, this.textureManager = new Oe(n), this.sorter = new Pe();
1567
+ }, this.textureManager = new De(o), this.sorter = new Pe();
1565
1568
  let a = this.createChunks() || void 0;
1566
1569
  a === null && console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."), a = void 0, this.sorter.addEventListener("updated", this.onSorterUpdated), this.sorter.init(
1567
1570
  this.textureManager.orderTexture,
1568
1571
  this.splatData.positions,
1569
1572
  a ?? void 0,
1570
1573
  !this.options.keepSplatData
1571
- ), this.material.setTransformA(this.textureManager.transformA), this.material.setTransformB(this.textureManager.transformB), this.material.setColorTexture(this.textureManager.colorTexture), this.material.setOrderTexture(this.textureManager.orderTexture), this.material.setNumSplats(0), this.geometry.boundingBox = n.boundingBox.toBox3(), this.geometry.boundingSphere = new l.Sphere(), this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere), this.options.keepSplatData || (this.splatData = null);
1574
+ ), this.material.setTransformA(this.textureManager.transformA), this.material.setTransformB(this.textureManager.transformB), this.material.setColorTexture(this.textureManager.colorTexture), this.material.setOrderTexture(this.textureManager.orderTexture), this.material.setNumSplats(0), this.geometry.boundingBox = o.boundingBox.toBox3(), this.geometry.boundingSphere = new l.Sphere(), this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere), this.options.keepSplatData || (this.splatData = null);
1572
1575
  }
1573
1576
  /**
1574
1577
  * Creates the instanced geometry for rendering splats.
@@ -1576,8 +1579,8 @@ const se = class se extends l.Mesh {
1576
1579
  * @param instanceSize Number of splats per instance.
1577
1580
  * @returns InstancedBufferGeometry
1578
1581
  */
1579
- static createInstancedGeometry(n, t) {
1580
- const o = Math.ceil(n / t), r = new l.BufferGeometry(), a = new Float32Array([
1582
+ static createInstancedGeometry(o, t) {
1583
+ const r = Math.ceil(o / t), n = new l.BufferGeometry(), a = new Float32Array([
1581
1584
  // x, y, splat_index_in_instance
1582
1585
  -1,
1583
1586
  -1,
@@ -1592,23 +1595,23 @@ const se = class se extends l.Mesh {
1592
1595
  1,
1593
1596
  0
1594
1597
  ]), i = new Uint16Array([0, 1, 2, 0, 2, 3]), u = new Float32Array(4 * 3 * t);
1595
- for (let f = 0; f < t; f++) {
1596
- const w = f * 4 * 3;
1597
- for (let b = 0; b < 4; b++)
1598
- u[w + b * 3 + 0] = a[b * 3 + 0], u[w + b * 3 + 1] = a[b * 3 + 1], u[w + b * 3 + 2] = f;
1598
+ for (let h = 0; h < t; h++) {
1599
+ const b = h * 4 * 3;
1600
+ for (let S = 0; S < 4; S++)
1601
+ u[b + S * 3 + 0] = a[S * 3 + 0], u[b + S * 3 + 1] = a[S * 3 + 1], u[b + S * 3 + 2] = h;
1599
1602
  }
1600
- const v = new Uint32Array(6 * t);
1601
- for (let f = 0; f < t; f++) {
1602
- const w = f * 6, b = f * 4;
1603
- v[w + 0] = i[0] + b, v[w + 1] = i[1] + b, v[w + 2] = i[2] + b, v[w + 3] = i[3] + b, v[w + 4] = i[4] + b, v[w + 5] = i[5] + b;
1603
+ const w = new Uint32Array(6 * t);
1604
+ for (let h = 0; h < t; h++) {
1605
+ const b = h * 6, S = h * 4;
1606
+ w[b + 0] = i[0] + S, w[b + 1] = i[1] + S, w[b + 2] = i[2] + S, w[b + 3] = i[3] + S, w[b + 4] = i[4] + S, w[b + 5] = i[5] + S;
1604
1607
  }
1605
- r.setAttribute("position", new l.BufferAttribute(u, 3)), r.setIndex(new l.BufferAttribute(v, 1));
1606
- const M = new l.InstancedBufferGeometry();
1607
- M.index = r.index, M.setAttribute("position", r.getAttribute("position"));
1608
- const T = new Uint32Array(o);
1609
- for (let f = 0; f < o; f++)
1610
- T[f] = f * t;
1611
- return M.setAttribute("splatInstanceIndex", new l.InstancedBufferAttribute(T, 1, !1)), M.instanceCount = 0, M;
1608
+ n.setAttribute("position", new l.BufferAttribute(u, 3)), n.setIndex(new l.BufferAttribute(w, 1));
1609
+ const C = new l.InstancedBufferGeometry();
1610
+ C.index = n.index, C.setAttribute("position", n.getAttribute("position"));
1611
+ const _ = new Uint32Array(r);
1612
+ for (let h = 0; h < r; h++)
1613
+ _[h] = h * t;
1614
+ return C.setAttribute("splatInstanceIndex", new l.InstancedBufferAttribute(_, 1, !1)), C.instanceCount = 0, C;
1612
1615
  }
1613
1616
  /**
1614
1617
  * Create chunks data (bounding box min/max) for the sorter.
@@ -1617,14 +1620,14 @@ const se = class se extends l.Mesh {
1617
1620
  createChunks() {
1618
1621
  if (!this.splatData)
1619
1622
  return null;
1620
- const n = this.splatData.boundingBox;
1621
- return n.min.x === 1 / 0 || n.max.x === -1 / 0 ? null : new Float32Array([
1622
- n.min.x,
1623
- n.min.y,
1624
- n.min.z,
1625
- n.max.x,
1626
- n.max.y,
1627
- n.max.z
1623
+ const o = this.splatData.boundingBox;
1624
+ return o.min.x === 1 / 0 || o.max.x === -1 / 0 ? null : new Float32Array([
1625
+ o.min.x,
1626
+ o.min.y,
1627
+ o.min.z,
1628
+ o.max.x,
1629
+ o.max.y,
1630
+ o.max.z
1628
1631
  ]);
1629
1632
  }
1630
1633
  /**
@@ -1632,17 +1635,17 @@ const se = class se extends l.Mesh {
1632
1635
  * @param width Viewport width
1633
1636
  * @param height Viewport height
1634
1637
  */
1635
- updateViewport(n, t) {
1636
- n === this._vpW && t === this._vpH || (this._vpW = n, this._vpH = t, this.material.updateViewport(n, t));
1638
+ updateViewport(o, t) {
1639
+ o === this._vpW && t === this._vpH || (this._vpW = o, this._vpH = t, this.material.updateViewport(o, t));
1637
1640
  }
1638
1641
  /**
1639
1642
  * Sorts splats based on camera position and direction.
1640
1643
  * @param camera The camera to sort against.
1641
1644
  */
1642
- sort(n) {
1643
- n.getWorldPosition(this._camPosW), n.getWorldDirection(this._camDirW), this.invModelMatrix.copy(this.matrixWorld).invert(), this._camPosL.copy(this._camPosW).applyMatrix4(this.invModelMatrix), this._camDirL.copy(this._camDirW).transformDirection(this.invModelMatrix);
1644
- const t = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6, o = this.lastCameraDirectionLocal.dot(this._camDirL) < 0.999;
1645
- this.options.autoSort && (t || o) && (this.lastCameraPositionLocal.copy(this._camPosL), this.lastCameraDirectionLocal.copy(this._camDirL), this.sorter.setCamera(this._camPosL, this._camDirL));
1645
+ sort(o) {
1646
+ o.getWorldPosition(this._camPosW), o.getWorldDirection(this._camDirW), this.invModelMatrix.copy(this.matrixWorld).invert(), this._camPosL.copy(this._camPosW).applyMatrix4(this.invModelMatrix), this._camDirL.copy(this._camDirW).transformDirection(this.invModelMatrix);
1647
+ const t = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6, r = this.lastCameraDirectionLocal.dot(this._camDirL) < 0.999;
1648
+ this.options.autoSort && (t || r) && (this.lastCameraPositionLocal.copy(this._camPosL), this.lastCameraDirectionLocal.copy(this._camDirL), this.sorter.setCamera(this._camPosL, this._camDirL));
1646
1649
  }
1647
1650
  /**
1648
1651
  * THREE.js hook called before rendering the object.
@@ -1653,8 +1656,8 @@ const se = class se extends l.Mesh {
1653
1656
  */
1654
1657
  // prettier-ignore
1655
1658
  // @ts-expect-error scene is not used
1656
- onBeforeRender(n, t, o) {
1657
- this.sort(o), n.getSize(this._size), this.updateViewport(this._size.x, this._size.y);
1659
+ onBeforeRender(o, t, r) {
1660
+ this.sort(r), o.getSize(this._size), this.updateViewport(this._size.x, this._size.y);
1658
1661
  }
1659
1662
  /**
1660
1663
  * Dispose of resources
@@ -1664,36 +1667,39 @@ const se = class se extends l.Mesh {
1664
1667
  }
1665
1668
  };
1666
1669
  /** Number of splats combined into a single instanced draw call. */
1667
- d(se, "INSTANCE_SIZE", 128);
1668
- let le = se;
1669
- const qe = Symbol.for("@speridlabs/visus/SplatMesh");
1670
- try {
1671
- Object.defineProperty(le.prototype, qe, {
1672
- value: !0,
1673
- configurable: !1,
1674
- enumerable: !1,
1675
- writable: !1
1676
- });
1677
- } catch {
1678
- console.warn("Couldn't define Visus SplatMesh symbol");
1679
- }
1680
- const Ye = ({
1681
- plyUrl: A,
1670
+ f(se, "INSTANCE_SIZE", 128);
1671
+ let de = se;
1672
+ const le = /* @__PURE__ */ new Map(), He = ({
1673
+ plyUrl: x,
1682
1674
  debug: e = !1,
1683
- splatOptions: n = {},
1675
+ splatOptions: o = {},
1684
1676
  ...t
1685
1677
  }) => {
1686
- typeof window < "u" && e && (window.__VISUS_SPLAT_DEBUG__ = !0), e && console.debug("SPLAT: rendering", { plyUrl: A, splatOptions: n, meshProps: t });
1687
- const o = Se(null), r = Ae(Re, A), a = Me(
1688
- () => new le(r, n || {}),
1689
- [r, n]
1690
- );
1691
- return _e(() => () => {
1692
- e && console.debug("SPLAT: disposing mesh for", A), typeof (a == null ? void 0 : a.dispose) == "function" && a.dispose();
1693
- }, [a]), /* @__PURE__ */ Ee.jsx("primitive", { ref: o, object: a, ...t });
1678
+ e && console.debug("SPLAT: rendering", { plyUrl: x, splatOptions: o, meshProps: t });
1679
+ const [r, n] = Ce(null), a = Ae(null);
1680
+ return Te(() => {
1681
+ const i = we(x, o);
1682
+ return je(x, o).then(
1683
+ (u) => {
1684
+ n(u);
1685
+ }
1686
+ ), () => {
1687
+ e && console.debug("SPLAT: releasing mesh for", x), We(i);
1688
+ };
1689
+ }, [x, o, e]), r ? /* @__PURE__ */ Ie.jsx("primitive", { ref: a, object: r, ...t }) : null;
1690
+ }, we = (x, e) => `${x}:${JSON.stringify(e)}`, je = async (x, e) => {
1691
+ const o = we(x, e), t = le.get(o);
1692
+ if (t)
1693
+ return t.refCount++, t.mesh;
1694
+ const n = await new ze().loadAsync(x), a = new de(n, e);
1695
+ return le.set(o, { mesh: a, refCount: 1 }), a;
1694
1696
  };
1697
+ function We(x) {
1698
+ const e = le.get(x);
1699
+ e && (e.refCount--, e.refCount <= 0 && (e.mesh.dispose(), le.delete(x)));
1700
+ }
1695
1701
  export {
1696
- Re as PlyLoader,
1697
- Ye as Splat,
1698
- le as SplatMesh
1702
+ ze as PlyLoader,
1703
+ He as Splat,
1704
+ de as SplatMesh
1699
1705
  };