@speridlabs/visus 2.0.0 → 2.1.0

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