@speridlabs/visus 1.0.4 → 2.0.1

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,10 +1,10 @@
1
- var me = Object.defineProperty;
2
- var xe = (T, e, o) => e in T ? me(T, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : T[e] = o;
3
- var h = (T, e, o) => xe(T, typeof e != "symbol" ? e + "" : e, o);
4
- import ve, { useRef as ye, useMemo as ge, useEffect as we } from "react";
5
- import { useLoader as be } from "@react-three/fiber";
6
- import * as i from "three";
7
- var se = { exports: {} }, te = {};
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
+ import * as l from "three";
7
+ var ce = { exports: {} }, ae = {};
8
8
  /**
9
9
  * @license React
10
10
  * react-jsx-runtime.production.js
@@ -14,29 +14,29 @@ var se = { exports: {} }, te = {};
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 ue;
18
- function Se() {
19
- if (ue) return te;
20
- ue = 1;
21
- var T = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
22
- function o(t, r, n) {
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 (n !== void 0 && (a = "" + n), r.key !== void 0 && (a = "" + r.key), "key" in r) {
25
- n = {};
26
- for (var c in r)
27
- c !== "key" && (n[c] = r[c]);
28
- } else n = r;
29
- return r = n.ref, {
30
- $$typeof: T,
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
31
  type: t,
32
32
  key: a,
33
- ref: r !== void 0 ? r : null,
34
- props: n
33
+ ref: o !== void 0 ? o : null,
34
+ props: r
35
35
  };
36
36
  }
37
- return te.Fragment = e, te.jsx = o, te.jsxs = o, te;
37
+ return ae.Fragment = e, ae.jsx = n, ae.jsxs = n, ae;
38
38
  }
39
- var re = {};
39
+ var ie = {};
40
40
  /**
41
41
  * @license React
42
42
  * react-jsx-runtime.development.js
@@ -46,24 +46,24 @@ var re = {};
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 he;
50
- function _e() {
51
- return he || (he = 1, process.env.NODE_ENV !== "production" && function() {
52
- function T(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 === w ? 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 _:
58
+ case I:
59
59
  return "Fragment";
60
- case q:
60
+ case j:
61
61
  return "Profiler";
62
- case B:
62
+ case z:
63
63
  return "StrictMode";
64
- case $:
64
+ case L:
65
65
  return "Suspense";
66
- case F:
66
+ case _:
67
67
  return "SuspenseList";
68
68
  case C:
69
69
  return "Activity";
@@ -72,21 +72,21 @@ function _e() {
72
72
  switch (typeof s.tag == "number" && console.error(
73
73
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
74
74
  ), s.$$typeof) {
75
- case f:
75
+ case b:
76
76
  return "Portal";
77
- case j:
78
- return (s.displayName || "Context") + ".Provider";
79
77
  case W:
80
- return (s._context.displayName || "Context") + ".Consumer";
78
+ return (s.displayName || "Context") + ".Provider";
81
79
  case H:
82
- var d = s.render;
83
- return s = s.displayName, s || (s = d.displayName || d.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
84
- case k:
85
- return d = s.displayName || null, d !== null ? d : T(s.type) || "Memo";
86
- case O:
87
- d = s._payload, s = s._init;
80
+ return (s._context.displayName || "Context") + ".Consumer";
81
+ case ne:
82
+ var p = s.render;
83
+ 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";
86
+ case D:
87
+ p = s._payload, s = s._init;
88
88
  try {
89
- return T(s(d));
89
+ return A(s(p));
90
90
  } catch {
91
91
  }
92
92
  }
@@ -95,76 +95,76 @@ function _e() {
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
- var d = !1;
101
+ var p = !1;
102
102
  } catch {
103
- d = !0;
103
+ p = !0;
104
104
  }
105
- if (d) {
106
- d = console;
107
- var A = d.error, z = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
108
- return A.call(
109
- d,
105
+ if (p) {
106
+ p = console;
107
+ var S = p.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
108
+ return S.call(
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
- z
111
+ E
112
112
  ), e(s);
113
113
  }
114
114
  }
115
115
  function t(s) {
116
- if (s === _) return "<>";
117
- if (typeof s == "object" && s !== null && s.$$typeof === O)
116
+ if (s === I) return "<>";
117
+ if (typeof s == "object" && s !== null && s.$$typeof === D)
118
118
  return "<...>";
119
119
  try {
120
- var d = T(s);
121
- return d ? "<" + d + ">" : "<...>";
120
+ var p = A(s);
121
+ return p ? "<" + p + ">" : "<...>";
122
122
  } catch {
123
123
  return "<...>";
124
124
  }
125
125
  }
126
- function r() {
127
- var s = M.A;
126
+ function o() {
127
+ var s = R.A;
128
128
  return s === null ? null : s.getOwner();
129
129
  }
130
- function n() {
130
+ function r() {
131
131
  return Error("react-stack-top-frame");
132
132
  }
133
133
  function a(s) {
134
- if (U.call(s, "key")) {
135
- var d = Object.getOwnPropertyDescriptor(s, "key").get;
136
- if (d && d.isReactWarning) return !1;
134
+ if (B.call(s, "key")) {
135
+ var p = Object.getOwnPropertyDescriptor(s, "key").get;
136
+ if (p && p.isReactWarning) return !1;
137
137
  }
138
138
  return s.key !== void 0;
139
139
  }
140
- function c(s, d) {
141
- function A() {
142
- x || (x = !0, console.error(
140
+ function i(s, p) {
141
+ function S() {
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
- d
144
+ p
145
145
  ));
146
146
  }
147
- A.isReactWarning = !0, Object.defineProperty(s, "key", {
148
- get: A,
147
+ S.isReactWarning = !0, Object.defineProperty(s, "key", {
148
+ get: S,
149
149
  configurable: !0
150
150
  });
151
151
  }
152
- function v() {
153
- var s = T(this.type);
154
- return E[s] || (E[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, d, A, z, L, u, P, D) {
159
- return A = u.ref, s = {
160
- $$typeof: m,
158
+ function v(s, p, S, E, m, c, y, P) {
159
+ return S = c.ref, s = {
160
+ $$typeof: w,
161
161
  type: s,
162
- key: d,
163
- props: u,
164
- _owner: L
165
- }, (A !== void 0 ? A : null) !== null ? Object.defineProperty(s, "ref", {
162
+ key: p,
163
+ props: c,
164
+ _owner: m
165
+ }, (S !== void 0 ? S : null) !== null ? Object.defineProperty(s, "ref", {
166
166
  enumerable: !1,
167
- get: v
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,118 +179,118 @@ function _e() {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: P
182
+ value: y
183
183
  }), Object.defineProperty(s, "_debugTask", {
184
184
  configurable: !1,
185
185
  enumerable: !1,
186
186
  writable: !0,
187
- value: D
187
+ value: P
188
188
  }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
189
189
  }
190
- function S(s, d, A, z, L, u, P, D) {
191
- var l = d.children;
192
- if (l !== void 0)
193
- if (z)
194
- if (V(l)) {
195
- for (z = 0; z < l.length; z++)
196
- b(l[z]);
197
- Object.freeze && Object.freeze(l);
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 b(l);
203
- if (U.call(d, "key")) {
204
- l = T(s);
205
- var I = Object.keys(d).filter(function(X) {
206
- return X !== "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
- z = 0 < I.length ? "{key: someKey, " + I.join(": ..., ") + ": ...}" : "{key: someKey}", G[l + z] || (I = 0 < I.length ? "{" + I.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
- z,
216
- l,
217
- I,
218
- l
219
- ), G[l + z] = !0);
215
+ E,
216
+ h,
217
+ k,
218
+ h
219
+ ), te[h + E] = !0);
220
220
  }
221
- if (l = null, A !== void 0 && (o(A), l = "" + A), a(d) && (o(d.key), l = "" + d.key), "key" in d) {
222
- A = {};
223
- for (var Y in d)
224
- Y !== "key" && (A[Y] = d[Y]);
225
- } else A = d;
226
- return l && c(
227
- A,
221
+ if (h = null, S !== void 0 && (n(S), h = "" + S), a(p) && (n(p.key), h = "" + p.key), "key" in p) {
222
+ S = {};
223
+ for (var O in p)
224
+ O !== "key" && (S[O] = p[O]);
225
+ } else S = p;
226
+ return h && i(
227
+ S,
228
228
  typeof s == "function" ? s.displayName || s.name || "Unknown" : s
229
- ), g(
229
+ ), v(
230
230
  s,
231
- l,
232
- u,
233
- L,
234
- r(),
235
- A,
236
- P,
237
- D
231
+ h,
232
+ c,
233
+ m,
234
+ o(),
235
+ S,
236
+ y,
237
+ P
238
238
  );
239
239
  }
240
- function b(s) {
241
- typeof s == "object" && s !== null && s.$$typeof === m && 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 p = ve, m = Symbol.for("react.transitional.element"), f = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), B = Symbol.for("react.strict_mode"), q = Symbol.for("react.profiler"), W = Symbol.for("react.consumer"), j = Symbol.for("react.context"), H = Symbol.for("react.forward_ref"), $ = Symbol.for("react.suspense"), F = Symbol.for("react.suspense_list"), k = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), C = Symbol.for("react.activity"), w = Symbol.for("react.client.reference"), M = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, V = Array.isArray, y = 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
- p = {
246
+ f = {
247
247
  "react-stack-bottom-frame": function(s) {
248
248
  return s();
249
249
  }
250
250
  };
251
- var x, E = {}, R = p["react-stack-bottom-frame"].bind(
252
- p,
253
- n
254
- )(), N = y(t(n)), G = {};
255
- re.Fragment = _, re.jsx = function(s, d, A, z, L) {
256
- var u = 1e4 > M.recentlyCreatedOwnerStacks++;
257
- return S(
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
- d,
260
- A,
259
+ p,
260
+ S,
261
261
  !1,
262
- z,
263
- L,
264
- u ? Error("react-stack-top-frame") : R,
265
- u ? y(t(s)) : N
262
+ E,
263
+ m,
264
+ c ? Error("react-stack-top-frame") : F,
265
+ c ? $(t(s)) : N
266
266
  );
267
- }, re.jsxs = function(s, d, A, z, L) {
268
- var u = 1e4 > M.recentlyCreatedOwnerStacks++;
269
- return S(
267
+ }, ie.jsxs = function(s, p, S, E, m) {
268
+ var c = 1e4 > R.recentlyCreatedOwnerStacks++;
269
+ return M(
270
270
  s,
271
- d,
272
- A,
271
+ p,
272
+ S,
273
273
  !0,
274
- z,
275
- L,
276
- u ? Error("react-stack-top-frame") : R,
277
- u ? y(t(s)) : N
274
+ E,
275
+ m,
276
+ c ? Error("react-stack-top-frame") : F,
277
+ c ? $(t(s)) : N
278
278
  );
279
279
  };
280
- }()), re;
280
+ }()), ie;
281
281
  }
282
- var fe;
283
- function Te() {
284
- return fe || (fe = 1, process.env.NODE_ENV === "production" ? se.exports = Se() : se.exports = _e()), se.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 Me = Te();
287
- class le {
286
+ var Ee = ke();
287
+ class he {
288
288
  constructor() {
289
- h(this, "min", new i.Vector3(1 / 0, 1 / 0, 1 / 0));
290
- h(this, "max", new i.Vector3(-1 / 0, -1 / 0, -1 / 0));
291
- h(this, "center", new i.Vector3());
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());
292
292
  /** Half extents (size/2) */
293
- h(this, "halfExtents", new i.Vector3());
293
+ d(this, "halfExtents", new l.Vector3());
294
294
  }
295
295
  /**
296
296
  * Reset the bounding box to its initial state
@@ -331,32 +331,31 @@ class le {
331
331
  * @returns THREE.Box3 representation
332
332
  */
333
333
  toBox3() {
334
- return new i.Box3().set(this.min, this.max);
334
+ return new l.Box3().set(this.min, this.max);
335
335
  }
336
336
  /**
337
337
  * Create a clone of this bounding box
338
338
  * @returns New bounding box with the same values
339
339
  */
340
340
  clone() {
341
- const e = new le();
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 Ae {
345
+ class Ie {
346
346
  // TODO: there is no sh spherical harmonics
347
347
  constructor(e = 0) {
348
- h(this, "numSplats", 0);
349
- h(this, "positions");
350
- h(this, "rotations");
351
- h(this, "scales");
352
- h(this, "colors");
353
- h(this, "opacities");
354
- h(this, "centers");
355
- h(this, "boundingBox", new le());
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());
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 Ae {
367
366
  * @param color Color
368
367
  * @param opacity Opacity value
369
368
  */
370
- setSplat(e, o, t, r, n, 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 c = e * 3, v = e * 4, g = e * 3, S = e * 3;
376
- this.positions[c] = o.x, this.positions[c + 1] = o.y, this.positions[c + 2] = o.z, this.rotations[v] = t.x, this.rotations[v + 1] = t.y, this.rotations[v + 2] = t.z, this.rotations[v + 3] = t.w, this.scales[g] = r.x, this.scales[g + 1] = r.y, this.scales[g + 2] = r.z, this.colors[S] = n.r, this.colors[S + 1] = n.g, this.colors[S + 2] = n.b, this.opacities[e] = a, this.centers[c] = o.x, this.centers[c + 1] = o.y, this.centers[c + 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 Ae {
385
384
  throw new Error(
386
385
  `Splat index out of bounds: ${e} >= ${this.numSplats}`
387
386
  );
388
- const o = e * 3, t = e * 4, r = e * 3, n = e * 3;
387
+ const n = e * 3, t = e * 4, o = e * 3, r = e * 3;
389
388
  return {
390
- position: new i.Vector3(
391
- this.positions[o],
392
- this.positions[o + 1],
393
- this.positions[o + 2]
389
+ position: new l.Vector3(
390
+ this.positions[n],
391
+ this.positions[n + 1],
392
+ this.positions[n + 2]
394
393
  ),
395
- rotation: new i.Quaternion(
394
+ rotation: new l.Quaternion(
396
395
  this.rotations[t],
397
396
  this.rotations[t + 1],
398
397
  this.rotations[t + 2],
399
398
  this.rotations[t + 3]
400
399
  ),
401
400
  // Convert log scale back to linear scale for external use
402
- scale: new i.Vector3(
403
- Math.exp(this.scales[r]),
404
- Math.exp(this.scales[r + 1]),
405
- Math.exp(this.scales[r + 2])
401
+ scale: new l.Vector3(
402
+ Math.exp(this.scales[o]),
403
+ Math.exp(this.scales[o + 1]),
404
+ Math.exp(this.scales[o + 2])
406
405
  ),
407
- color: new i.Color(
408
- this.colors[n],
409
- this.colors[n + 1],
410
- this.colors[n + 2]
406
+ color: new l.Color(
407
+ this.colors[r],
408
+ this.colors[r + 1],
409
+ this.colors[r + 2]
411
410
  ),
412
411
  opacity: this.opacities[e]
413
412
  };
@@ -418,9 +417,9 @@ class Ae {
418
417
  */
419
418
  calculateBoundingBox() {
420
419
  this.boundingBox.reset();
421
- const e = new i.Vector3();
422
- for (let o = 0; o < this.numSplats; o++) {
423
- const t = o * 3;
420
+ const e = new l.Vector3();
421
+ for (let n = 0; n < this.numSplats; n++) {
422
+ const t = n * 3;
424
423
  e.set(
425
424
  this.positions[t],
426
425
  this.positions[t + 1],
@@ -434,37 +433,69 @@ class Ae {
434
433
  * This is for visualization/debugging purposes only, not for rendering
435
434
  */
436
435
  createDebugGeometry() {
437
- const e = new i.BufferGeometry();
436
+ const e = new l.BufferGeometry();
438
437
  e.setAttribute(
439
438
  "position",
440
- new i.BufferAttribute(this.positions, 3)
439
+ new l.BufferAttribute(this.positions, 3)
441
440
  );
442
- const o = new Float32Array(this.numSplats * 3), t = new i.Quaternion(), r = new i.Euler();
443
- for (let n = 0; n < this.numSplats; n++) {
444
- const a = n * 4, c = n * 3;
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;
445
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
- ), r.setFromQuaternion(t), o[c] = r.x, o[c + 1] = r.y, o[c + 2] = r.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 i.BufferAttribute(o, 3)
453
+ new l.BufferAttribute(n, 3)
455
454
  ), e.setAttribute(
456
455
  "scale",
457
- new i.BufferAttribute(this.scales, 3)
456
+ new l.BufferAttribute(this.scales, 3)
458
457
  ), e.setAttribute(
459
458
  "color",
460
- new i.BufferAttribute(this.colors, 3)
459
+ new l.BufferAttribute(this.colors, 3)
461
460
  ), e.setAttribute(
462
461
  "opacity",
463
- new i.BufferAttribute(this.opacities, 1)
462
+ new l.BufferAttribute(this.opacities, 1)
464
463
  ), e;
465
464
  }
466
465
  }
467
- class Ce extends i.Loader {
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);
474
+ }
475
+ /**
476
+ * Handles messages received from the parsing worker
477
+ * @param event The message event from the worker
478
+ */
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"));
484
+ 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
490
+ ), i.boundingBox.max.set(
491
+ r.boundingBox.maxX,
492
+ r.boundingBox.maxY,
493
+ r.boundingBox.maxZ
494
+ ), a.resolve(i);
495
+ } catch (i) {
496
+ a.reject(i);
497
+ }
498
+ }
468
499
  /**
469
500
  * Load a PLY file with Gaussian Splat data
470
501
  * @param url URL of the PLY file
@@ -472,21 +503,18 @@ class Ce extends i.Loader {
472
503
  * @param onProgress Optional progress callback
473
504
  * @param onError Optional error callback
474
505
  */
475
- load(e, o, t, r) {
476
- const n = new i.FileLoader(this.manager);
477
- n.setResponseType("arraybuffer"), n.setRequestHeader(this.requestHeader), n.setPath(this.path), n.setWithCredentials(this.withCredentials), n.load(
478
- e,
479
- (a) => {
480
- try {
481
- if (o) {
482
- const c = this.parse(a);
483
- o(c);
484
- }
485
- } catch (c) {
486
- r ? r(c) : console.error(c), this.manager.itemError(e);
487
- }
506
+ load(n, t, o, r) {
507
+ const a = new l.FileLoader(this.manager);
508
+ a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
509
+ n,
510
+ (i) => {
511
+ this.parseAsync(i).then((u) => {
512
+ t && t(u);
513
+ }).catch((u) => {
514
+ r ? r(u) : console.error(u), this.manager.itemError(n);
515
+ });
488
516
  },
489
- t,
517
+ o,
490
518
  r
491
519
  );
492
520
  }
@@ -496,252 +524,311 @@ class Ce extends i.Loader {
496
524
  * @param onProgress Optional progress callback
497
525
  * @returns A Promise that resolves with the parsed SplatData
498
526
  */
499
- loadAsync(e, o) {
500
- return new Promise((t, r) => {
501
- const n = new i.FileLoader(this.manager);
502
- n.setResponseType("arraybuffer"), n.setRequestHeader(this.requestHeader), n.setPath(this.path), n.setWithCredentials(this.withCredentials), n.load(
503
- e,
504
- (a) => {
505
- try {
506
- const c = this.parse(a);
507
- t(c);
508
- } catch (c) {
509
- r(c), this.manager.itemError(e);
510
- }
527
+ loadAsync(n, t) {
528
+ return new Promise((o, r) => {
529
+ const a = new l.FileLoader(this.manager);
530
+ a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
531
+ n,
532
+ (i) => {
533
+ this.parseAsync(i).then(o).catch((u) => {
534
+ r(u), this.manager.itemError(n);
535
+ });
511
536
  },
512
- o,
513
- (a) => {
514
- r(a), this.manager.itemError(e);
537
+ t,
538
+ (i) => {
539
+ r(i), this.manager.itemError(n);
515
540
  }
516
541
  );
517
542
  });
518
543
  }
519
544
  /**
520
- * Parse PLY buffer data into SplatData
545
+ * Parse PLY buffer data asynchronously using Web Worker
521
546
  * @param buffer ArrayBuffer containing PLY data
522
- * @returns Parsed SplatData
547
+ * @returns Promise that resolves with parsed SplatData
523
548
  */
524
- parse(e) {
525
- const o = new TextDecoder(), t = new Uint8Array(e), r = [112, 108, 121, 10], n = `
549
+ parseAsync(n) {
550
+ return new Promise((t, o) => {
551
+ const r = this.requestId++;
552
+ this.pendingCallbacks.set(r, { resolve: t, reject: o });
553
+ const a = {
554
+ requestId: r,
555
+ buffer: n
556
+ };
557
+ this.worker.postMessage(a, [n]);
558
+ });
559
+ }
560
+ /**
561
+ * Terminate the Web Worker and clean up resources
562
+ */
563
+ dispose() {
564
+ this.worker && this.worker.terminate(), this.pendingCallbacks.clear();
565
+ }
566
+ /**
567
+ * Creates the self-contained code for the parsing Web Worker
568
+ * @returns A string containing the JavaScript code for the worker
569
+ */
570
+ createWorkerCode() {
571
+ return `(${(function() {
572
+ self.onmessage = (o) => {
573
+ const { requestId: r, buffer: a } = o.data;
574
+ try {
575
+ const i = t(a), u = {
576
+ requestId: r,
577
+ result: i
578
+ };
579
+ self.postMessage(u, [
580
+ i.positions,
581
+ i.rotations,
582
+ i.scales,
583
+ i.colors,
584
+ i.opacities
585
+ ]);
586
+ } catch (i) {
587
+ const u = {
588
+ requestId: r,
589
+ error: i instanceof Error ? i.message : String(i)
590
+ };
591
+ self.postMessage(u);
592
+ }
593
+ };
594
+ function t(o) {
595
+ const r = new TextDecoder(), a = new Uint8Array(o), i = [112, 108, 121, 10], u = `
526
596
  end_header
527
597
  `;
528
- for (let y = 0; y < r.length; y++)
529
- if (t[y] !== r[y])
530
- throw new Error("Invalid PLY file: Missing magic bytes");
531
- let a = 0;
532
- for (let y = 0; y < t.length - n.length; y++) {
533
- let x = !0;
534
- for (let E = 0; E < n.length; E++)
535
- if (t[y + E] !== n.charCodeAt(E)) {
536
- x = !1;
537
- break;
538
- }
539
- if (x) {
540
- a = y + n.length;
541
- break;
542
- }
543
- }
544
- if (a === 0)
545
- throw new Error("Invalid PLY file: Could not find end of header");
546
- const v = o.decode(t.subarray(0, a)).split(`
547
- `), g = [];
548
- let S = null;
549
- for (let y = 1; y < v.length; y++) {
550
- const x = v[y].trim();
551
- if (x === "" || x === "end_header") continue;
552
- const E = x.split(" ");
553
- switch (E[0]) {
554
- case "format":
555
- S = E[1];
556
- break;
557
- case "element":
558
- g.push({
559
- name: E[1],
560
- count: parseInt(E[2], 10),
561
- properties: []
562
- });
563
- break;
564
- case "property":
565
- if (g.length === 0)
598
+ for (let m = 0; m < i.length; m++)
599
+ if (a[m] !== i[m])
566
600
  throw new Error(
567
- "Invalid PLY file: Property without element"
601
+ "Invalid PLY file: Missing magic bytes"
568
602
  );
569
- g[g.length - 1].properties.push({
570
- type: E[1],
571
- name: E[2],
572
- storage: null
573
- });
574
- break;
575
- }
576
- }
577
- if (S !== "binary_little_endian")
578
- throw new Error(`Unsupported PLY format: ${S}`);
579
- const b = g.find((y) => y.name === "vertex");
580
- if (!b)
581
- throw new Error("Invalid PLY file: No vertex element found");
582
- const p = new Ae(b.count), m = new DataView(e);
583
- let f = a;
584
- const _ = (y) => b.properties.findIndex((x) => x.name === y), B = _("x"), q = _("y"), W = _("z"), j = [
585
- _("rot_0"),
586
- _("rot_1"),
587
- _("rot_2"),
588
- _("rot_3")
589
- ], H = [
590
- _("scale_0"),
591
- _("scale_1"),
592
- _("scale_2")
593
- ], $ = [
594
- _("f_dc_0"),
595
- _("f_dc_1"),
596
- _("f_dc_2")
597
- ], F = _("opacity");
598
- if ([
599
- B,
600
- q,
601
- W,
602
- ...j,
603
- ...H,
604
- ...$,
605
- F
606
- ].some((y) => y === -1))
607
- throw new Error("Invalid PLY file: Missing required properties");
608
- const O = 0.28209479177387814, C = (y) => {
609
- if (y > 0) return 1 / (1 + Math.exp(-y));
610
- const x = Math.exp(y);
611
- return x / (1 + x);
612
- }, w = new i.Vector3(), M = new i.Quaternion(), U = new i.Vector3(), V = new i.Color();
613
- for (let y = 0; y < b.count; y++) {
614
- const x = [];
615
- for (let R = 0; R < b.properties.length; R++) {
616
- const G = b.properties[R].type;
617
- let s;
618
- switch (G) {
619
- case "char":
620
- s = m.getInt8(f), f += 1;
621
- break;
622
- case "uchar":
623
- s = m.getUint8(f), f += 1;
624
- break;
625
- case "short":
626
- s = m.getInt16(f, !0), f += 2;
627
- break;
628
- case "ushort":
629
- s = m.getUint16(f, !0), f += 2;
630
- break;
631
- case "int":
632
- s = m.getInt32(f, !0), f += 4;
633
- break;
634
- case "uint":
635
- s = m.getUint32(f, !0), f += 4;
636
- break;
637
- case "float":
638
- s = m.getFloat32(f, !0), f += 4;
639
- break;
640
- case "double":
641
- s = m.getFloat64(f, !0), f += 8;
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;
609
+ break;
610
+ }
611
+ if (c) {
612
+ v = m + u.length;
642
613
  break;
643
- default:
644
- throw new Error(`Unsupported property type: ${G}`);
614
+ }
615
+ }
616
+ if (v === 0)
617
+ throw new Error(
618
+ "Invalid PLY file: Could not find end of header"
619
+ );
620
+ const T = r.decode(
621
+ a.subarray(0, v)
622
+ ).split(`
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]) {
630
+ case "format":
631
+ w = y[1];
632
+ break;
633
+ case "element":
634
+ f.push({
635
+ name: y[1],
636
+ count: parseInt(y[2], 10),
637
+ properties: []
638
+ });
639
+ break;
640
+ case "property":
641
+ if (f.length === 0)
642
+ throw new Error(
643
+ "Invalid PLY file: Property without element"
644
+ );
645
+ f[f.length - 1].properties.push({
646
+ type: y[1],
647
+ name: y[2]
648
+ });
649
+ break;
650
+ }
651
+ }
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)
656
+ throw new Error(
657
+ "Invalid PLY file: No vertex element found"
658
+ );
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")
672
+ ], X = [
673
+ x("f_dc_0"),
674
+ x("f_dc_1"),
675
+ x("f_dc_2")
676
+ ], $ = x("opacity");
677
+ if ([
678
+ D,
679
+ C,
680
+ g,
681
+ ...R,
682
+ ...B,
683
+ ...X,
684
+ $
685
+ ].some((m) => m === -1))
686
+ throw new Error(
687
+ "Invalid PLY file: Missing required properties"
688
+ );
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);
693
+ };
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) {
701
+ case "char":
702
+ ee = L.getInt8(_), _ += 1;
703
+ break;
704
+ case "uchar":
705
+ ee = L.getUint8(_), _ += 1;
706
+ break;
707
+ case "short":
708
+ ee = L.getInt16(_, !0), _ += 2;
709
+ break;
710
+ case "ushort":
711
+ ee = L.getUint16(_, !0), _ += 2;
712
+ break;
713
+ case "int":
714
+ ee = L.getInt32(_, !0), _ += 4;
715
+ break;
716
+ case "uint":
717
+ ee = L.getUint32(_, !0), _ += 4;
718
+ break;
719
+ case "float":
720
+ ee = L.getFloat32(_, !0), _ += 4;
721
+ break;
722
+ case "double":
723
+ ee = L.getFloat64(_, !0), _ += 8;
724
+ break;
725
+ default:
726
+ throw new Error(
727
+ `Unsupported property type: ${de}`
728
+ );
729
+ }
730
+ c.push(ee);
731
+ }
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
737
+ );
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[$]);
645
747
  }
646
- x.push(s);
748
+ return {
749
+ numSplats: I,
750
+ positions: z.buffer,
751
+ rotations: j.buffer,
752
+ scales: H.buffer,
753
+ colors: W.buffer,
754
+ opacities: ne.buffer,
755
+ boundingBox: {
756
+ minX: N,
757
+ minY: te,
758
+ minZ: s,
759
+ maxX: p,
760
+ maxY: S,
761
+ maxZ: E
762
+ }
763
+ };
647
764
  }
648
- w.set(
649
- x[B],
650
- x[q],
651
- x[W]
652
- ), M.set(
653
- x[j[1]],
654
- // PLY stores rot 1,2,3,0 (x,y,z,w)
655
- x[j[2]],
656
- x[j[3]],
657
- x[j[0]]
658
- ).normalize(), M.w < 0 && (M.x = -M.x, M.y = -M.y, M.z = -M.z, M.w = -M.w), U.set(
659
- x[H[0]],
660
- // Read directly assuming it's log scale
661
- x[H[1]],
662
- x[H[2]]
663
- ), V.set(
664
- 0.5 + x[$[0]] * O,
665
- 0.5 + x[$[1]] * O,
666
- 0.5 + x[$[2]] * O
667
- ), V.r = Math.max(0, Math.min(1, V.r)), V.g = Math.max(0, Math.min(1, V.g)), V.b = Math.max(0, Math.min(1, V.b));
668
- const E = C(x[F]);
669
- p.setSplat(
670
- y,
671
- w,
672
- M,
673
- U,
674
- // Pass log scale directly
675
- V,
676
- E
677
- );
678
- }
679
- return p.calculateBoundingBox(), p;
765
+ }).toString()})();`;
680
766
  }
681
767
  }
682
- class Ee extends i.EventDispatcher {
768
+ class Pe extends l.EventDispatcher {
683
769
  constructor() {
684
770
  super();
685
- h(this, "worker");
686
- h(this, "centers", null);
687
- h(this, "orderTexture", null);
771
+ d(this, "worker");
772
+ d(this, "centers", null);
773
+ d(this, "orderTexture", null);
688
774
  /** Bounding box data for optimization */
689
- h(this, "chunks", null);
690
- h(this, "lastCameraPosition", new i.Vector3());
691
- h(this, "lastCameraDirection", new i.Vector3());
692
- const o = this.createWorkerCode(), t = new Blob([o], { type: "application/javascript" });
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" });
693
779
  this.worker = new Worker(URL.createObjectURL(t)), this.worker.onmessage = this.onWorkerMessage.bind(this);
694
780
  }
695
781
  /**
696
782
  * Handles messages received from the sorting worker.
697
783
  * @param event The message event from the worker.
698
784
  */
699
- onWorkerMessage(o) {
785
+ onWorkerMessage(n) {
700
786
  if (!this.orderTexture || !this.orderTexture.image)
701
787
  return console.error("SplatSorter: Order texture not initialized!");
702
- const { order: t, count: r } = o.data, n = this.orderTexture.image.data;
703
- if (!(n instanceof Uint32Array))
788
+ const { order: t, count: o } = n.data, r = this.orderTexture.image.data;
789
+ if (!(r instanceof Uint32Array))
704
790
  return console.error(
705
791
  "SplatSorter: Order texture data is not a Uint32Array!"
706
792
  );
707
- n.set(new Uint32Array(t)), this.orderTexture.needsUpdate = !0;
708
- const a = n.buffer.slice(0), c = { order: a };
709
- this.worker.postMessage(c, [a]), this.dispatchEvent({ type: "updated", count: r });
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 });
710
796
  }
711
797
  /**
712
798
  * Initializes the sorter with necessary data and textures.
713
799
  * @param orderTexture The THREE.DataTexture (R32UI) to store the sorted splat indices.
714
800
  * @param centers A Float32Array containing the center position (x, y, z) for each splat.
715
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.
716
803
  */
717
- init(o, t, r) {
718
- if (!o || !(o.image.data instanceof Uint32Array))
804
+ init(n, t, o, r = !1) {
805
+ if (!n || !(n.image.data instanceof Uint32Array))
719
806
  throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
720
807
  if (!t || t.length % 3 !== 0)
721
808
  throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
722
- if (o.image.data.length < t.length / 3)
809
+ if (n.image.data.length < t.length / 3)
723
810
  throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");
724
- const n = t.length / 3;
725
- this.orderTexture = o, this.centers = t.slice();
726
- const a = this.orderTexture.image.data;
727
- for (let b = 0; b < n; b++) a[b] = b;
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;
728
815
  this.orderTexture.needsUpdate = !0;
729
- const c = a.buffer.slice(0), v = this.centers.buffer.slice(0), g = {
730
- order: c,
816
+ const u = i.buffer.slice(0), v = r ? t.buffer : t.buffer.slice(0), M = {
817
+ order: u,
731
818
  centers: v
732
- }, S = [
733
- c,
819
+ }, T = [
820
+ u,
734
821
  v
735
822
  ];
736
- if (r) {
737
- this.chunks = r.slice();
738
- const b = this.chunks.buffer.slice(0);
739
- g.chunks = b, S.push(b);
823
+ if (o) {
824
+ this.chunks = o.slice();
825
+ const f = this.chunks.buffer.slice(0);
826
+ M.chunks = f, T.push(f);
740
827
  }
741
- this.worker.postMessage(g, S), queueMicrotask(() => {
828
+ this.worker.postMessage(M, T), queueMicrotask(() => {
742
829
  this.dispatchEvent({
743
830
  type: "updated",
744
- count: n
831
+ count: a
745
832
  });
746
833
  });
747
834
  }
@@ -750,50 +837,50 @@ class Ee extends i.EventDispatcher {
750
837
  * The sorter will only consider splats whose original indices are present in the mapping.
751
838
  * @param mapping A Uint32Array where each element is the *original* index of a splat to include, or null to reset mapping.
752
839
  */
753
- setMapping(o) {
840
+ setMapping(n) {
754
841
  if (!this.centers)
755
842
  return console.warn(
756
843
  "SplatSorter: Cannot set mapping before initialization."
757
844
  );
758
845
  let t;
759
- const r = [];
760
- if (!o) {
761
- const v = this.centers.buffer.slice(0);
846
+ const o = [];
847
+ if (!n) {
848
+ const u = this.centers.buffer.slice(0);
762
849
  return t = {
763
- centers: v,
850
+ centers: u,
764
851
  mapping: null
765
- }, r.push(v), this.worker.postMessage(t, r);
852
+ }, o.push(u), this.worker.postMessage(t, o);
766
853
  }
767
- const n = new Float32Array(o.length * 3);
768
- for (let v = 0; v < o.length; v++) {
769
- const g = o[v];
770
- 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) {
771
858
  console.warn(
772
- `SplatSorter: Mapping index ${g} out of bounds.`
859
+ `SplatSorter: Mapping index ${v} out of bounds.`
773
860
  );
774
861
  continue;
775
862
  }
776
- const S = g * 3, b = v * 3;
777
- n[b + 0] = this.centers[S + 0], n[b + 1] = this.centers[S + 1], n[b + 2] = this.centers[S + 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];
778
865
  }
779
- const a = n.buffer.slice(0), c = o.buffer.slice(0);
866
+ const a = r.buffer.slice(0), i = n.buffer.slice(0);
780
867
  t = {
781
868
  centers: a,
782
- mapping: c
783
- }, r.push(a, c), this.worker.postMessage(t, r);
869
+ mapping: i
870
+ }, o.push(a, i), this.worker.postMessage(t, o);
784
871
  }
785
872
  /**
786
873
  * Updates the camera parameters used for sorting.
787
874
  * @param position The camera's position in the sorter's local coordinate space.
788
875
  * @param direction The camera's forward direction in the sorter's local coordinate space.
789
876
  */
790
- setCamera(o, t) {
791
- const r = this.lastCameraPosition.distanceToSquared(o) > 1e-7, n = this.lastCameraDirection.dot(t) < 0.9999;
792
- if (!r && !n)
877
+ setCamera(n, t) {
878
+ const o = this.lastCameraPosition.distanceToSquared(n) > 1e-7, r = this.lastCameraDirection.dot(t) < 0.9999;
879
+ if (!o && !r)
793
880
  return;
794
- this.lastCameraPosition.copy(o), this.lastCameraDirection.copy(t);
881
+ this.lastCameraPosition.copy(n), this.lastCameraDirection.copy(t);
795
882
  const a = {
796
- cameraPosition: { x: o.x, y: o.y, z: o.z },
883
+ cameraPosition: { x: n.x, y: n.y, z: n.z },
797
884
  cameraDirection: { x: t.x, y: t.y, z: t.z }
798
885
  };
799
886
  this.worker.postMessage(a);
@@ -810,165 +897,165 @@ class Ee extends i.EventDispatcher {
810
897
  */
811
898
  createWorkerCode() {
812
899
  return `(${(function() {
813
- let t = null, r = null, n = null, a = null, c = null, v = null, g = !1;
814
- const S = { x: 0, y: 0, z: 0 }, b = { x: 0, y: 0, z: 0 }, p = { x: 0, y: 0, z: 0 }, m = { x: 0, y: 0, z: 0 };
815
- let f = null, _ = null;
816
- const B = 32, q = new Array(B).fill(0), W = new Array(B).fill(0), j = new Array(B).fill(0), H = (F, k, O) => {
817
- for (; F <= k; ) {
818
- const C = k + F >> 1, w = O(C);
819
- if (w > 0) F = C + 1;
820
- else if (w < 0) k = C - 1;
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;
821
908
  else return C;
822
909
  }
823
- return ~F;
824
- }, $ = () => {
825
- if (!t || !r || !c || !v)
910
+ return ~_;
911
+ }, L = () => {
912
+ if (!t || !o || !i || !u)
826
913
  return;
827
- if (r.length === 0) {
828
- const u = {
914
+ if (o.length === 0) {
915
+ const c = {
829
916
  order: t.buffer,
830
917
  count: 0
831
918
  };
832
- self.postMessage(u, [t.buffer]), t = null;
919
+ self.postMessage(c, [t.buffer]), t = null;
833
920
  return;
834
921
  }
835
- const F = c.x, k = c.y, O = c.z, C = v.x, w = v.y, M = v.z, U = 1e-4, V = Math.abs(F - S.x) > U || Math.abs(k - S.y) > U || Math.abs(O - S.z) > U, y = Math.abs(C - b.x) > U || Math.abs(w - b.y) > U || Math.abs(M - b.z) > U;
836
- if (!g && !V && !y)
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 && !$)
837
924
  return;
838
- g = !1, S.x = F, S.y = k, S.z = O, b.x = C, b.y = w, b.z = M;
839
- let x = 1 / 0, E = -1 / 0;
840
- for (let u = 0; u < 8; ++u) {
841
- const P = u & 1 ? p.x : m.x, D = u & 2 ? p.y : m.y, l = u & 4 ? p.z : m.z, I = P * C + D * w + l * M;
842
- x = Math.min(x, I), E = Math.max(E, I);
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;
927
+ 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;
929
+ Z = Math.min(Z, k), U = Math.max(U, k);
843
930
  }
844
- const R = r.length / 3, N = E - x, s = (1 << Math.max(
931
+ const F = o.length / 3, N = U - Z, s = (1 << Math.max(
845
932
  10,
846
- Math.min(20, Math.ceil(Math.log2(R / 4)))
933
+ Math.min(20, Math.ceil(Math.log2(F / 4)))
847
934
  )) + 1;
848
- if ((!f || f.length !== R) && (f = new Uint32Array(R)), !_ || _.length !== s ? _ = new Uint32Array(s) : _.fill(0), N < 1e-7) {
849
- for (let u = 0; u < R; ++u) f[u] = 0;
850
- _[0] = R;
851
- } else if (n && n.length > 0) {
852
- const u = n.length / 6;
853
- q.fill(0);
854
- for (let l = 0; l < u; ++l) {
855
- const I = l * 6, Y = n[I + 0], X = n[I + 1], ne = n[I + 2], Z = n[I + 3], J = Y * C + X * w + ne * M - x, oe = J - Z, ee = J + Z, ie = 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(
856
943
  0,
857
- Math.floor(oe * B / N)
858
- ), ce = Math.min(
859
- B,
860
- Math.ceil(ee * B / N)
944
+ Math.floor(Q * z / N)
945
+ ), oe = Math.min(
946
+ z,
947
+ Math.ceil(K * z / N)
861
948
  );
862
- for (let Q = ie; Q < ce; ++Q)
863
- q[Q]++;
949
+ for (let J = re; J < oe; ++J)
950
+ j[J]++;
864
951
  }
865
- let P = 0;
866
- for (let l = 0; l < B; ++l) P += q[l];
867
- j[0] = 0, W[0] = 0;
868
- for (let l = 1; l < B; ++l)
869
- j[l - 1] = q[l - 1] / P * s >>> 0, W[l] = W[l - 1] + j[l - 1];
870
- j[B - 1] = q[B - 1] / P * s >>> 0;
871
- const D = N / B;
872
- for (let l = 0; l < R; ++l) {
873
- const I = l * 3, Y = r[I + 0], X = r[I + 1], ne = r[I + 2], Z = Y * C + X * w + ne * M, oe = (E - Z) / D, ee = 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(
874
961
  0,
875
962
  Math.min(
876
- B - 1,
877
- Math.floor(oe)
963
+ z - 1,
964
+ Math.floor(Q)
878
965
  )
879
- ), ie = oe - ee, ce = W[ee] + j[ee] * ie >>> 0, Q = Math.min(ce, s - 1);
880
- f[l] = Q, _[Q]++;
966
+ ), re = Q - K, oe = H[K] + W[K] * re >>> 0, J = Math.min(oe, s - 1);
967
+ b[h] = J, I[J]++;
881
968
  }
882
969
  } else {
883
- const u = (s - 1) / N;
884
- for (let P = 0; P < R; ++P) {
885
- const D = P * 3, l = r[D + 0], I = r[D + 1], Y = r[D + 2], X = l * C + I * w + Y * M, Z = (E - X) * u >>> 0, J = Math.min(Z, s - 1);
886
- f[P] = J, _[J]++;
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]++;
887
974
  }
888
975
  }
889
- for (let u = 1; u < s; u++)
890
- _[u] += _[u - 1];
891
- for (let u = R - 1; u >= 0; u--) {
892
- const P = f[u], D = --_[P];
893
- t[D] = a ? a[u] : u;
976
+ for (let c = 1; c < s; 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;
894
981
  }
895
- const d = F * C + k * w + O * M, A = (u) => {
982
+ const p = _ * C + x * g + D * R, S = (c) => {
896
983
  if (!t) return -1 / 0;
897
- const P = t[u], D = P;
898
- if (!r || D * 3 + 2 >= r.length)
984
+ const y = t[c], P = y;
985
+ if (!o || P * 3 + 2 >= o.length)
899
986
  return -1 / 0;
900
- const l = D * 3;
901
- return r[l] * C + r[l + 1] * w + r[l + 2] * M - d;
987
+ const h = P * 3;
988
+ return o[h] * C + o[h + 1] * g + o[h + 2] * R - p;
902
989
  };
903
- let z = R;
904
- if (R > 0 && A(R - 1) < 0) {
905
- const u = H(
990
+ let E = F;
991
+ if (F > 0 && S(F - 1) < 0) {
992
+ const c = ne(
906
993
  0,
907
- R - 1,
908
- A
994
+ F - 1,
995
+ S
909
996
  );
910
- z = u < 0 ? ~u : u;
997
+ E = c < 0 ? ~c : c;
911
998
  }
912
- const L = {
999
+ const m = {
913
1000
  order: t.buffer,
914
- count: z
1001
+ count: E
915
1002
  };
916
- self.postMessage(L, [t.buffer]), t = null;
1003
+ self.postMessage(m, [t.buffer]), t = null;
917
1004
  };
918
- self.onmessage = (F) => {
919
- const k = F.data;
920
- k.order && (t = new Uint32Array(k.order));
921
- let O = !1;
922
- if (k.centers && (r = new Float32Array(k.centers), O = !0, g = !0), Object.prototype.hasOwnProperty.call(k, "mapping") && (a = k.mapping ? new Uint32Array(k.mapping) : null, g = !0), k.chunks) {
923
- if (n = new Float32Array(k.chunks), n.length > 0 && n[3] > 0)
924
- for (let C = 0; C < n.length / 6; ++C) {
925
- const w = C * 6, M = n[w + 0], U = n[w + 1], V = n[w + 2], y = n[w + 3], x = n[w + 4], E = n[w + 5];
926
- n[w + 0] = (M + y) * 0.5, n[w + 1] = (U + x) * 0.5, n[w + 2] = (V + E) * 0.5, n[w + 3] = Math.sqrt(
927
- (y - M) ** 2 + (x - U) ** 2 + (E - V) ** 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
928
1015
  ) * 0.5;
929
1016
  }
930
- g = !0;
1017
+ v = !0;
931
1018
  }
932
- if (O && r && r.length > 0) {
933
- p.x = m.x = r[0], p.y = m.y = r[1], p.z = m.z = r[2];
934
- for (let C = 1; C < r.length / 3; C++) {
935
- const w = C * 3;
936
- p.x = Math.min(p.x, r[w + 0]), m.x = Math.max(m.x, r[w + 0]), p.y = Math.min(p.y, r[w + 1]), m.y = Math.max(m.y, r[w + 1]), p.z = Math.min(p.z, r[w + 2]), m.z = Math.max(m.z, r[w + 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]);
937
1024
  }
938
- } else O && r && r.length === 0 && (p.x = m.x = p.y = m.y = p.z = m.z = 0);
939
- k.cameraPosition && (c = k.cameraPosition), k.cameraDirection && (v = k.cameraDirection), $();
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();
940
1027
  };
941
1028
  }).toString()})();`;
942
1029
  }
943
1030
  }
944
- const ke = (T, e) => {
945
- const o = de(T), t = de(e);
946
- return o | t << 16;
1031
+ const ze = (A, e) => {
1032
+ const n = ye(A), t = ye(e);
1033
+ return n | t << 16;
947
1034
  };
948
- function de(T) {
949
- const e = new Float32Array([T]), t = new Int32Array(e.buffer)[0];
950
- let r = t >> 16 & 32768, n = t >> 12 & 2047;
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;
951
1038
  const a = t >> 23 & 255;
952
- 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);
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);
953
1040
  }
954
- const Ie = new ArrayBuffer(4), pe = new DataView(Ie), Re = (T) => (pe.setUint32(0, T, !0), pe.getFloat32(0, !0));
955
- class ze {
1041
+ const Be = new ArrayBuffer(4), ge = new DataView(Be), Fe = (A) => (ge.setUint32(0, A, !0), ge.getFloat32(0, !0));
1042
+ class Oe {
956
1043
  /**
957
1044
  * Create a new TextureManager for a set of splats
958
1045
  * @param splatData The splat data to manage textures for
959
1046
  */
960
1047
  constructor(e) {
961
- h(this, "transformA");
1048
+ d(this, "transformA");
962
1049
  // position xyz and rotation quaternion y,z components
963
- h(this, "transformB");
1050
+ d(this, "transformB");
964
1051
  // rotation quaternion x and scale xyz
965
- h(this, "colorTexture");
1052
+ d(this, "colorTexture");
966
1053
  // color an opacity
967
- h(this, "orderTexture");
968
- h(this, "textureWidth");
969
- h(this, "textureHeight");
970
- const o = e.numSplats;
971
- 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);
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);
972
1059
  }
973
1060
  /**
974
1061
  * Create the transform A texture (positions and quaternion w component)
@@ -976,24 +1063,24 @@ class ze {
976
1063
  * @returns DataTexture containing position data
977
1064
  */
978
1065
  createTransformATexture(e) {
979
- const o = e.numSplats, t = new Float32Array(
1066
+ const n = e.numSplats, t = new Float32Array(
980
1067
  this.textureWidth * this.textureHeight * 4
981
1068
  );
982
- for (let n = 0; n < o; n++) {
983
- const a = n * 4, c = n * 3, v = n * 4;
984
- t[a] = e.positions[c], t[a + 1] = e.positions[c + 1], t[a + 2] = e.positions[c + 2];
985
- const g = e.rotations[v + 0], S = e.rotations[v + 1], b = ke(g, S);
986
- t[a + 3] = Re(b);
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);
987
1074
  }
988
- const r = new i.DataTexture(
1075
+ const o = new l.DataTexture(
989
1076
  t,
990
1077
  this.textureWidth,
991
1078
  this.textureHeight,
992
- i.RGBAFormat,
993
- i.FloatType
1079
+ l.RGBAFormat,
1080
+ l.FloatType
994
1081
  // Store as Float32, shader will reinterpret bits
995
1082
  );
996
- return r.needsUpdate = !0, r.magFilter = i.NearestFilter, r.minFilter = i.NearestFilter, r;
1083
+ return o.needsUpdate = !0, o.magFilter = l.NearestFilter, o.minFilter = l.NearestFilter, o;
997
1084
  }
998
1085
  /**
999
1086
  * Create the transform B texture (scale and rotation xyz)
@@ -1001,21 +1088,21 @@ class ze {
1001
1088
  * @returns DataTexture containing scale and rotation data
1002
1089
  */
1003
1090
  createTransformBTexture(e) {
1004
- const o = e.numSplats, t = new Float32Array(
1091
+ const n = e.numSplats, t = new Float32Array(
1005
1092
  this.textureWidth * this.textureHeight * 4
1006
1093
  );
1007
- for (let n = 0; n < o; n++) {
1008
- const a = n * 4, c = n * 3, v = n * 4;
1009
- t[a] = e.scales[c], t[a + 1] = e.scales[c + 1], t[a + 2] = e.scales[c + 2], t[a + 3] = e.rotations[v + 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];
1010
1097
  }
1011
- const r = new i.DataTexture(
1098
+ const o = new l.DataTexture(
1012
1099
  t,
1013
1100
  this.textureWidth,
1014
1101
  this.textureHeight,
1015
- i.RGBAFormat,
1016
- i.FloatType
1102
+ l.RGBAFormat,
1103
+ l.FloatType
1017
1104
  );
1018
- return r.needsUpdate = !0, r.magFilter = i.NearestFilter, r.minFilter = i.NearestFilter, r;
1105
+ return o.needsUpdate = !0, o.magFilter = l.NearestFilter, o.minFilter = l.NearestFilter, o;
1019
1106
  }
1020
1107
  /**
1021
1108
  * Create the color texture (RGB and opacity)
@@ -1023,21 +1110,21 @@ class ze {
1023
1110
  * @returns DataTexture containing color data
1024
1111
  */
1025
1112
  createColorTexture(e) {
1026
- const o = e.numSplats, t = new Float32Array(
1113
+ const n = e.numSplats, t = new Float32Array(
1027
1114
  this.textureWidth * this.textureHeight * 4
1028
1115
  );
1029
- for (let n = 0; n < o; n++) {
1030
- const a = n * 4, c = n * 3;
1031
- t[a] = e.colors[c], t[a + 1] = e.colors[c + 1], t[a + 2] = e.colors[c + 2], t[a + 3] = e.opacities[n];
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];
1032
1119
  }
1033
- const r = new i.DataTexture(
1120
+ const o = new l.DataTexture(
1034
1121
  t,
1035
1122
  this.textureWidth,
1036
1123
  this.textureHeight,
1037
- i.RGBAFormat,
1038
- i.FloatType
1124
+ l.RGBAFormat,
1125
+ l.FloatType
1039
1126
  );
1040
- return r.needsUpdate = !0, r;
1127
+ return o.needsUpdate = !0, o;
1041
1128
  }
1042
1129
  /**
1043
1130
  * Create the order texture for sorting
@@ -1045,15 +1132,15 @@ class ze {
1045
1132
  * @returns DataTexture for storing order indices
1046
1133
  */
1047
1134
  createOrderTexture(e) {
1048
- const o = new Uint32Array(this.textureWidth * this.textureHeight);
1049
- for (let r = 0; r < e; r++)
1050
- o[r] = r;
1051
- const t = new i.DataTexture(
1052
- 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,
1053
1140
  this.textureWidth,
1054
1141
  this.textureHeight,
1055
- i.RedIntegerFormat,
1056
- i.UnsignedIntType
1142
+ l.RedIntegerFormat,
1143
+ l.UnsignedIntType
1057
1144
  );
1058
1145
  return t.needsUpdate = !0, t;
1059
1146
  }
@@ -1061,7 +1148,7 @@ class ze {
1061
1148
  this.transformA.dispose(), this.transformB.dispose(), this.colorTexture.dispose(), this.orderTexture.dispose();
1062
1149
  }
1063
1150
  }
1064
- const Pe = (
1151
+ const De = (
1065
1152
  /* glsl */
1066
1153
  `
1067
1154
  precision highp float;
@@ -1319,7 +1406,7 @@ void main(void) {
1319
1406
  vUv = clippedCornerOffset;
1320
1407
  }
1321
1408
  `
1322
- ), Be = (
1409
+ ), Ue = (
1323
1410
  /* glsl */
1324
1411
  `
1325
1412
  precision highp float;
@@ -1353,56 +1440,56 @@ void main(void) {
1353
1440
  }
1354
1441
  `
1355
1442
  );
1356
- class Oe extends i.ShaderMaterial {
1443
+ class Ve extends l.ShaderMaterial {
1357
1444
  constructor(e = {}) {
1358
- const o = {
1445
+ const n = {
1359
1446
  // Textures (values set via methods)
1360
1447
  transformA: { value: null },
1361
1448
  transformB: { value: null },
1362
1449
  splatColor: { value: null },
1363
1450
  splatOrder: { value: null },
1364
1451
  // Other uniforms
1365
- viewport: { value: new i.Vector2(1, 1) },
1452
+ viewport: { value: new l.Vector2(1, 1) },
1366
1453
  // Will be updated
1367
1454
  numSplats: { value: 0 }
1368
1455
  // Max splats to render (updated by sorter)
1369
1456
  };
1370
1457
  super({
1371
- vertexShader: Pe,
1372
- fragmentShader: Be,
1373
- uniforms: o,
1458
+ vertexShader: De,
1459
+ fragmentShader: Ue,
1460
+ uniforms: n,
1374
1461
  transparent: !0,
1375
- blending: i.CustomBlending,
1462
+ blending: l.CustomBlending,
1376
1463
  // Premultiplied alpha blending:
1377
1464
  // color = src_color * src_alpha + dst_color * (1 - src_alpha)
1378
1465
  // alpha = src_alpha * 1 + dst_alpha * (1 - src_alpha)
1379
- blendSrc: i.OneFactor,
1466
+ blendSrc: l.OneFactor,
1380
1467
  // Using ONE because shader outputs premultiplied color (color * alpha)
1381
- blendDst: i.OneMinusSrcAlphaFactor,
1382
- blendSrcAlpha: i.OneFactor,
1468
+ blendDst: l.OneMinusSrcAlphaFactor,
1469
+ blendSrcAlpha: l.OneFactor,
1383
1470
  // source alpha comes from shader
1384
- blendDstAlpha: i.OneMinusSrcAlphaFactor,
1385
- blendEquation: i.AddEquation,
1386
- blendEquationAlpha: i.AddEquation,
1471
+ blendDstAlpha: l.OneMinusSrcAlphaFactor,
1472
+ blendEquation: l.AddEquation,
1473
+ blendEquationAlpha: l.AddEquation,
1387
1474
  depthTest: !0,
1388
1475
  depthWrite: !1,
1389
1476
  // Disable depth write for transparency
1390
- side: i.DoubleSide,
1477
+ side: l.DoubleSide,
1391
1478
  // Render both sides (or CULLFACE_NONE equivalent)
1392
1479
  // Optional settings from constructor
1393
1480
  alphaTest: e.alphaTest !== void 0 ? e.alphaTest : 0,
1394
1481
  // Typically 0 for blending
1395
1482
  toneMapped: e.toneMapped !== void 0 ? e.toneMapped : !1
1396
1483
  // prettier-ignore
1397
- }), e.alphaHash && (this.alphaHash = !0, this.depthWrite = !0, this.blending = i.NoBlending);
1484
+ }), e.alphaHash && (this.alphaHash = !0, this.depthWrite = !0, this.blending = l.NoBlending);
1398
1485
  }
1399
1486
  /**
1400
1487
  * Update the viewport size
1401
1488
  * @param width Viewport width
1402
1489
  * @param height Viewport height
1403
1490
  */
1404
- updateViewport(e, o) {
1405
- this.uniforms.viewport.value.set(e, o);
1491
+ updateViewport(e, n) {
1492
+ this.uniforms.viewport.value.set(e, n);
1406
1493
  }
1407
1494
  /**
1408
1495
  * Set transform texture A (positions)
@@ -1440,47 +1527,48 @@ class Oe extends i.ShaderMaterial {
1440
1527
  this.uniforms.numSplats.value = e;
1441
1528
  }
1442
1529
  }
1443
- const K = class K extends i.Mesh {
1530
+ const se = class se extends l.Mesh {
1444
1531
  // Match shader constant
1445
1532
  /**
1446
1533
  * Create a new SplatMesh for rendering Gaussian splats
1447
1534
  * @param splatData The splat data to render
1448
1535
  * @param options Rendering options
1449
1536
  */
1450
- constructor(o, t = {}) {
1451
- const r = new Oe(t), n = K.createInstancedGeometry(o.numSplats, K.INSTANCE_SIZE);
1452
- super(n, r);
1453
- h(this, "sorter");
1454
- h(this, "splatData");
1455
- h(this, "options");
1456
- h(this, "textureManager");
1457
- h(this, "material");
1458
- h(this, "geometry");
1459
- h(this, "lastCameraPositionLocal", new i.Vector3());
1460
- h(this, "lastCameraDirectionLocal", new i.Vector3());
1461
- h(this, "invModelMatrix", new i.Matrix4());
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());
1462
1549
  // Cached inverse matrix
1463
- h(this, "_vpW", -1);
1464
- h(this, "_vpH", -1);
1465
- h(this, "_size", new i.Vector2());
1466
- h(this, "_camPosW", new i.Vector3());
1467
- h(this, "_camDirW", new i.Vector3());
1468
- h(this, "_camPosL", new i.Vector3());
1469
- h(this, "_camDirL", new i.Vector3());
1470
- h(this, "onSorterUpdated", (o) => {
1471
- const t = o.count;
1472
- this.geometry.instanceCount = Math.ceil(t / K.INSTANCE_SIZE), this.material.setNumSplats(t);
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;
1559
+ this.geometry.instanceCount = Math.ceil(t / se.INSTANCE_SIZE), this.material.setNumSplats(t);
1473
1560
  });
1474
- this.geometry = n, this.material = r, this.splatData = o, this.frustumCulled = !1, this.options = {
1561
+ this.geometry = r, this.material = o, this.splatData = n, this.frustumCulled = !1, this.options = {
1475
1562
  autoSort: !0,
1476
1563
  ...t
1477
- }, this.textureManager = new ze(o), this.sorter = new Ee();
1564
+ }, this.textureManager = new Oe(n), this.sorter = new Pe();
1478
1565
  let a = this.createChunks() || void 0;
1479
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(
1480
1567
  this.textureManager.orderTexture,
1481
- this.splatData.centers,
1482
- a ?? void 0
1483
- ), 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 i.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);
1484
1572
  }
1485
1573
  /**
1486
1574
  * Creates the instanced geometry for rendering splats.
@@ -1488,8 +1576,8 @@ const K = class K extends i.Mesh {
1488
1576
  * @param instanceSize Number of splats per instance.
1489
1577
  * @returns InstancedBufferGeometry
1490
1578
  */
1491
- static createInstancedGeometry(o, t) {
1492
- const r = Math.ceil(o / t), n = new i.BufferGeometry(), a = new Float32Array([
1579
+ static createInstancedGeometry(n, t) {
1580
+ const o = Math.ceil(n / t), r = new l.BufferGeometry(), a = new Float32Array([
1493
1581
  // x, y, splat_index_in_instance
1494
1582
  -1,
1495
1583
  -1,
@@ -1503,38 +1591,40 @@ const K = class K extends i.Mesh {
1503
1591
  -1,
1504
1592
  1,
1505
1593
  0
1506
- ]), c = new Uint16Array([0, 1, 2, 0, 2, 3]), v = new Float32Array(4 * 3 * t);
1507
- for (let p = 0; p < t; p++) {
1508
- const m = p * 4 * 3;
1509
- for (let f = 0; f < 4; f++)
1510
- v[m + f * 3 + 0] = a[f * 3 + 0], v[m + f * 3 + 1] = a[f * 3 + 1], v[m + f * 3 + 2] = p;
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;
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;
1511
1599
  }
1512
- const g = new Uint32Array(6 * t);
1513
- for (let p = 0; p < t; p++) {
1514
- const m = p * 6, f = p * 4;
1515
- g[m + 0] = c[0] + f, g[m + 1] = c[1] + f, g[m + 2] = c[2] + f, g[m + 3] = c[3] + f, g[m + 4] = c[4] + f, g[m + 5] = c[5] + f;
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;
1516
1604
  }
1517
- n.setAttribute("position", new i.BufferAttribute(v, 3)), n.setIndex(new i.BufferAttribute(g, 1));
1518
- const S = new i.InstancedBufferGeometry();
1519
- S.index = n.index, S.setAttribute("position", n.getAttribute("position"));
1520
- const b = new Uint32Array(r);
1521
- for (let p = 0; p < r; p++)
1522
- b[p] = p * t;
1523
- return S.setAttribute("splatInstanceIndex", new i.InstancedBufferAttribute(b, 1, !1)), S.instanceCount = 0, S;
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;
1524
1612
  }
1525
1613
  /**
1526
1614
  * Create chunks data (bounding box min/max) for the sorter.
1527
1615
  * @returns Float32Array containing chunk data [minX, minY, minZ, maxX, maxY, maxZ] or null.
1528
1616
  */
1529
1617
  createChunks() {
1530
- const o = this.splatData.boundingBox;
1531
- return o.min.x === 1 / 0 || o.max.x === -1 / 0 ? null : new Float32Array([
1532
- o.min.x,
1533
- o.min.y,
1534
- o.min.z,
1535
- o.max.x,
1536
- o.max.y,
1537
- 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
1538
1628
  ]);
1539
1629
  }
1540
1630
  /**
@@ -1542,17 +1632,17 @@ const K = class K extends i.Mesh {
1542
1632
  * @param width Viewport width
1543
1633
  * @param height Viewport height
1544
1634
  */
1545
- updateViewport(o, t) {
1546
- o === this._vpW && t === this._vpH || (this._vpW = o, this._vpH = t, this.material.updateViewport(o, t));
1635
+ updateViewport(n, t) {
1636
+ n === this._vpW && t === this._vpH || (this._vpW = n, this._vpH = t, this.material.updateViewport(n, t));
1547
1637
  }
1548
1638
  /**
1549
1639
  * Sorts splats based on camera position and direction.
1550
1640
  * @param camera The camera to sort against.
1551
1641
  */
1552
- sort(o) {
1553
- 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);
1554
- const t = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6, r = this.lastCameraDirectionLocal.dot(this._camDirL) < 0.999;
1555
- this.options.autoSort && (t || r) && (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));
1556
1646
  }
1557
1647
  /**
1558
1648
  * THREE.js hook called before rendering the object.
@@ -1563,8 +1653,8 @@ const K = class K extends i.Mesh {
1563
1653
  */
1564
1654
  // prettier-ignore
1565
1655
  // @ts-expect-error scene is not used
1566
- onBeforeRender(o, t, r) {
1567
- this.sort(r), 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);
1568
1658
  }
1569
1659
  /**
1570
1660
  * Dispose of resources
@@ -1574,11 +1664,11 @@ const K = class K extends i.Mesh {
1574
1664
  }
1575
1665
  };
1576
1666
  /** Number of splats combined into a single instanced draw call. */
1577
- h(K, "INSTANCE_SIZE", 128);
1578
- let ae = K;
1579
- const De = Symbol.for("@speridlabs/visus/SplatMesh");
1667
+ d(se, "INSTANCE_SIZE", 128);
1668
+ let le = se;
1669
+ const qe = Symbol.for("@speridlabs/visus/SplatMesh");
1580
1670
  try {
1581
- Object.defineProperty(ae.prototype, De, {
1671
+ Object.defineProperty(le.prototype, qe, {
1582
1672
  value: !0,
1583
1673
  configurable: !1,
1584
1674
  enumerable: !1,
@@ -1587,23 +1677,23 @@ try {
1587
1677
  } catch {
1588
1678
  console.warn("Couldn't define Visus SplatMesh symbol");
1589
1679
  }
1590
- const je = ({
1591
- plyUrl: T,
1680
+ const Ye = ({
1681
+ plyUrl: A,
1592
1682
  debug: e = !1,
1593
- splatOptions: o = {},
1683
+ splatOptions: n = {},
1594
1684
  ...t
1595
1685
  }) => {
1596
- typeof window < "u" && e && (window.__VISUS_SPLAT_DEBUG__ = !0), e && console.debug("SPLAT: rendering", { plyUrl: T, splatOptions: o, meshProps: t });
1597
- const r = ye(null), n = be(Ce, T), a = ge(
1598
- () => new ae(n, o || {}),
1599
- [n, 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]
1600
1690
  );
1601
- return we(() => () => {
1602
- e && console.debug("SPLAT: disposing mesh for", T), typeof (a == null ? void 0 : a.dispose) == "function" && a.dispose();
1603
- }, [a]), /* @__PURE__ */ Me.jsx("primitive", { ref: r, object: a, ...t });
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 });
1604
1694
  };
1605
1695
  export {
1606
- Ce as PlyLoader,
1607
- je as Splat,
1608
- ae as SplatMesh
1696
+ Re as PlyLoader,
1697
+ Ye as Splat,
1698
+ le as SplatMesh
1609
1699
  };