@speridlabs/visus 1.0.4 → 2.0.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,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 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";
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 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) {
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,
31
- type: t,
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,
32
32
  key: a,
33
- ref: r !== void 0 ? r : null,
34
- props: n
33
+ ref: n !== void 0 ? n : null,
34
+ props: t
35
35
  };
36
36
  }
37
- return te.Fragment = e, te.jsx = o, te.jsxs = o, te;
37
+ return ae.Fragment = e, ae.jsx = o, ae.jsxs = o, ae;
38
38
  }
39
- var re = {};
39
+ var ie = {};
40
40
  /**
41
41
  * @license React
42
42
  * react-jsx-runtime.development.js
@@ -46,47 +46,47 @@ 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 xe;
50
+ function ke() {
51
+ return xe || (xe = 1, process.env.NODE_ENV !== "production" && function() {
52
+ function _(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 === y ? null : s.displayName || s.name || null;
56
56
  if (typeof s == "string") return s;
57
57
  switch (s) {
58
- case _:
58
+ case E:
59
59
  return "Fragment";
60
60
  case q:
61
61
  return "Profiler";
62
- case B:
62
+ case P:
63
63
  return "StrictMode";
64
- case $:
64
+ case ee:
65
65
  return "Suspense";
66
- case F:
66
+ case R:
67
67
  return "SuspenseList";
68
- case C:
68
+ case T:
69
69
  return "Activity";
70
70
  }
71
71
  if (typeof s == "object")
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:
77
+ case N:
78
78
  return (s.displayName || "Context") + ".Provider";
79
- case W:
80
- return (s._context.displayName || "Context") + ".Consumer";
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 oe:
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 : _(s.type) || "Memo";
86
+ case C:
87
+ p = s._payload, s = s._init;
88
88
  try {
89
- return T(s(d));
89
+ return _(s(p));
90
90
  } catch {
91
91
  }
92
92
  }
@@ -98,73 +98,73 @@ function _e() {
98
98
  function o(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, I = 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
+ I
112
112
  ), e(s);
113
113
  }
114
114
  }
115
- function t(s) {
116
- if (s === _) return "<>";
117
- if (typeof s == "object" && s !== null && s.$$typeof === O)
115
+ function r(s) {
116
+ if (s === E) return "<>";
117
+ if (typeof s == "object" && s !== null && s.$$typeof === C)
118
118
  return "<...>";
119
119
  try {
120
- var d = T(s);
121
- return d ? "<" + d + ">" : "<...>";
120
+ var p = _(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 n() {
127
+ var s = B.A;
128
128
  return s === null ? null : s.getOwner();
129
129
  }
130
- function n() {
130
+ function t() {
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 (F.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
+ W || (W = !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 f() {
153
+ var s = _(this.type);
154
+ return Y[s] || (Y[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 g(s, p, S, I, D, c, h, w) {
159
+ return S = c.ref, s = {
160
+ $$typeof: v,
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: D
165
+ }, (S !== void 0 ? S : null) !== null ? Object.defineProperty(s, "ref", {
166
166
  enumerable: !1,
167
- get: v
167
+ get: f
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: h
183
183
  }), Object.defineProperty(s, "_debugTask", {
184
184
  configurable: !1,
185
185
  enumerable: !1,
186
186
  writable: !0,
187
- value: D
187
+ value: w
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 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);
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 M(u);
203
+ if (F.call(p, "key")) {
204
+ u = _(s);
205
+ var k = Object.keys(p).filter(function(U) {
206
+ return U !== "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
+ I = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", te[u + I] || (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
215
  I,
218
- l
219
- ), G[l + z] = !0);
216
+ u,
217
+ k,
218
+ u
219
+ ), te[u + I] = !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 (u = null, S !== void 0 && (o(S), u = "" + S), a(p) && (o(p.key), u = "" + 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 u && i(
227
+ S,
228
228
  typeof s == "function" ? s.displayName || s.name || "Unknown" : s
229
229
  ), g(
230
230
  s,
231
- l,
232
231
  u,
233
- L,
234
- r(),
235
- A,
236
- P,
237
- D
232
+ c,
233
+ D,
234
+ n(),
235
+ S,
236
+ h,
237
+ w
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 M(s) {
241
+ typeof s == "object" && s !== null && s.$$typeof === v && 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 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() {
244
244
  return null;
245
245
  };
246
- p = {
246
+ m = {
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 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(
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
+ I,
263
+ D,
264
+ c ? Error("react-stack-top-frame") : z,
265
+ c ? j(r(s)) : Z
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, I, D) {
268
+ var c = 1e4 > B.recentlyCreatedOwnerStacks++;
269
+ return A(
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
+ I,
275
+ D,
276
+ c ? Error("react-stack-top-frame") : z,
277
+ c ? j(r(s)) : Z
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 ye;
283
+ function Ee() {
284
+ return ye || (ye = 1, process.env.NODE_ENV === "production" ? ce.exports = Te() : ce.exports = ke()), ce.exports;
285
285
  }
286
- var Me = Te();
287
- class le {
286
+ var Ie = Ee();
287
+ class de {
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,28 +331,28 @@ 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 de();
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 Re {
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, "centers");
355
+ d(this, "boundingBox", new de());
356
356
  this.numSplats = e, this.allocateBuffers(e);
357
357
  }
358
358
  allocateBuffers(e) {
@@ -367,13 +367,13 @@ class Ae {
367
367
  * @param color Color
368
368
  * @param opacity Opacity value
369
369
  */
370
- setSplat(e, o, t, r, n, a) {
370
+ setSplat(e, o, r, n, t, a) {
371
371
  if (e >= this.numSplats)
372
372
  throw new Error(
373
373
  `Splat index out of bounds: ${e} >= ${this.numSplats}`
374
374
  );
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;
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;
377
377
  }
378
378
  /**
379
379
  * Get a splat's data
@@ -385,29 +385,29 @@ class Ae {
385
385
  throw new Error(
386
386
  `Splat index out of bounds: ${e} >= ${this.numSplats}`
387
387
  );
388
- const o = e * 3, t = e * 4, r = e * 3, n = e * 3;
388
+ const o = e * 3, r = e * 4, n = e * 3, t = e * 3;
389
389
  return {
390
- position: new i.Vector3(
390
+ position: new l.Vector3(
391
391
  this.positions[o],
392
392
  this.positions[o + 1],
393
393
  this.positions[o + 2]
394
394
  ),
395
- rotation: new i.Quaternion(
396
- this.rotations[t],
397
- this.rotations[t + 1],
398
- this.rotations[t + 2],
399
- this.rotations[t + 3]
395
+ rotation: new l.Quaternion(
396
+ this.rotations[r],
397
+ this.rotations[r + 1],
398
+ this.rotations[r + 2],
399
+ this.rotations[r + 3]
400
400
  ),
401
401
  // 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])
402
+ scale: new l.Vector3(
403
+ Math.exp(this.scales[n]),
404
+ Math.exp(this.scales[n + 1]),
405
+ Math.exp(this.scales[n + 2])
406
406
  ),
407
- color: new i.Color(
408
- this.colors[n],
409
- this.colors[n + 1],
410
- this.colors[n + 2]
407
+ color: new l.Color(
408
+ this.colors[t],
409
+ this.colors[t + 1],
410
+ this.colors[t + 2]
411
411
  ),
412
412
  opacity: this.opacities[e]
413
413
  };
@@ -418,13 +418,13 @@ class Ae {
418
418
  */
419
419
  calculateBoundingBox() {
420
420
  this.boundingBox.reset();
421
- const e = new i.Vector3();
421
+ const e = new l.Vector3();
422
422
  for (let o = 0; o < this.numSplats; o++) {
423
- const t = o * 3;
423
+ const r = o * 3;
424
424
  e.set(
425
- this.positions[t],
426
- this.positions[t + 1],
427
- this.positions[t + 2]
425
+ this.positions[r],
426
+ this.positions[r + 1],
427
+ this.positions[r + 2]
428
428
  ), this.boundingBox.expandByPoint(e);
429
429
  }
430
430
  return this.boundingBox;
@@ -434,37 +434,69 @@ class Ae {
434
434
  * This is for visualization/debugging purposes only, not for rendering
435
435
  */
436
436
  createDebugGeometry() {
437
- const e = new i.BufferGeometry();
437
+ const e = new l.BufferGeometry();
438
438
  e.setAttribute(
439
439
  "position",
440
- new i.BufferAttribute(this.positions, 3)
440
+ new l.BufferAttribute(this.positions, 3)
441
441
  );
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;
445
- t.set(
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(
446
446
  this.rotations[a],
447
447
  this.rotations[a + 1],
448
448
  this.rotations[a + 2],
449
449
  this.rotations[a + 3]
450
- ), r.setFromQuaternion(t), o[c] = r.x, o[c + 1] = r.y, o[c + 2] = r.z;
450
+ ), n.setFromQuaternion(r), o[i] = n.x, o[i + 1] = n.y, o[i + 2] = n.z;
451
451
  }
452
452
  return e.setAttribute(
453
453
  "rotation",
454
- new i.BufferAttribute(o, 3)
454
+ new l.BufferAttribute(o, 3)
455
455
  ), e.setAttribute(
456
456
  "scale",
457
- new i.BufferAttribute(this.scales, 3)
457
+ new l.BufferAttribute(this.scales, 3)
458
458
  ), e.setAttribute(
459
459
  "color",
460
- new i.BufferAttribute(this.colors, 3)
460
+ new l.BufferAttribute(this.colors, 3)
461
461
  ), e.setAttribute(
462
462
  "opacity",
463
- new i.BufferAttribute(this.opacities, 1)
463
+ new l.BufferAttribute(this.opacities, 1)
464
464
  ), e;
465
465
  }
466
466
  }
467
- class Ce extends i.Loader {
467
+ class Pe extends l.Loader {
468
+ constructor(o) {
469
+ super(o);
470
+ d(this, "requestId", 0);
471
+ d(this, "worker");
472
+ 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);
475
+ }
476
+ /**
477
+ * Handles messages received from the parsing worker
478
+ * @param event The message event from the worker
479
+ */
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"));
485
+ 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
491
+ ), i.boundingBox.max.set(
492
+ t.boundingBox.maxX,
493
+ t.boundingBox.maxY,
494
+ t.boundingBox.maxZ
495
+ ), a.resolve(i);
496
+ } catch (i) {
497
+ a.reject(i);
498
+ }
499
+ }
468
500
  /**
469
501
  * Load a PLY file with Gaussian Splat data
470
502
  * @param url URL of the PLY file
@@ -472,22 +504,19 @@ class Ce extends i.Loader {
472
504
  * @param onProgress Optional progress callback
473
505
  * @param onError Optional error callback
474
506
  */
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
- }
507
+ load(o, r, n, t) {
508
+ const a = new l.FileLoader(this.manager);
509
+ a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
510
+ o,
511
+ (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);
516
+ });
488
517
  },
489
- t,
490
- r
518
+ n,
519
+ t
491
520
  );
492
521
  }
493
522
  /**
@@ -496,201 +525,261 @@ class Ce extends i.Loader {
496
525
  * @param onProgress Optional progress callback
497
526
  * @returns A Promise that resolves with the parsed SplatData
498
527
  */
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
- }
511
- },
528
+ loadAsync(o, r) {
529
+ return new Promise((n, t) => {
530
+ const a = new l.FileLoader(this.manager);
531
+ a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
512
532
  o,
513
- (a) => {
514
- r(a), this.manager.itemError(e);
533
+ (i) => {
534
+ this.parseAsync(i).then(n).catch((f) => {
535
+ t(f), this.manager.itemError(o);
536
+ });
537
+ },
538
+ r,
539
+ (i) => {
540
+ t(i), this.manager.itemError(o);
515
541
  }
516
542
  );
517
543
  });
518
544
  }
519
545
  /**
520
- * Parse PLY buffer data into SplatData
546
+ * Parse PLY buffer data asynchronously using Web Worker
521
547
  * @param buffer ArrayBuffer containing PLY data
522
- * @returns Parsed SplatData
548
+ * @returns Promise that resolves with parsed SplatData
523
549
  */
524
- parse(e) {
525
- const o = new TextDecoder(), t = new Uint8Array(e), r = [112, 108, 121, 10], n = `
550
+ parseAsync(o) {
551
+ return new Promise((r, n) => {
552
+ const t = this.requestId++;
553
+ this.pendingCallbacks.set(t, { resolve: r, reject: n });
554
+ const a = {
555
+ requestId: t,
556
+ buffer: o
557
+ };
558
+ this.worker.postMessage(a, [o]);
559
+ });
560
+ }
561
+ /**
562
+ * Terminate the Web Worker and clean up resources
563
+ */
564
+ dispose() {
565
+ this.worker && this.worker.terminate(), this.pendingCallbacks.clear();
566
+ }
567
+ /**
568
+ * Creates the self-contained code for the parsing Web Worker
569
+ * @returns A string containing the JavaScript code for the worker
570
+ */
571
+ createWorkerCode() {
572
+ return `(${(function() {
573
+ self.onmessage = (n) => {
574
+ const { requestId: t, buffer: a } = n.data;
575
+ try {
576
+ const i = r(a), f = {
577
+ requestId: t,
578
+ result: i
579
+ };
580
+ self.postMessage(f, [
581
+ i.positions,
582
+ i.rotations,
583
+ i.scales,
584
+ i.colors,
585
+ i.opacities,
586
+ i.centers
587
+ ]);
588
+ } catch (i) {
589
+ const f = {
590
+ requestId: t,
591
+ error: i instanceof Error ? i.message : String(i)
592
+ };
593
+ self.postMessage(f);
594
+ }
595
+ };
596
+ function r(n) {
597
+ const t = new TextDecoder(), a = new Uint8Array(n), i = [112, 108, 121, 10], f = `
526
598
  end_header
527
599
  `;
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)
600
+ for (let c = 0; c < i.length; c++)
601
+ if (a[c] !== i[c])
566
602
  throw new Error(
567
- "Invalid PLY file: Property without element"
603
+ "Invalid PLY file: Missing magic bytes"
568
604
  );
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;
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;
611
+ break;
612
+ }
613
+ if (h) {
614
+ g = c + f.length;
642
615
  break;
643
- default:
644
- throw new Error(`Unsupported property type: ${G}`);
616
+ }
645
617
  }
646
- x.push(s);
618
+ if (g === 0)
619
+ throw new Error(
620
+ "Invalid PLY file: Could not find end of header"
621
+ );
622
+ const M = t.decode(
623
+ a.subarray(0, g)
624
+ ).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]) {
632
+ case "format":
633
+ v = w[1];
634
+ break;
635
+ case "element":
636
+ m.push({
637
+ name: w[1],
638
+ count: parseInt(w[2], 10),
639
+ properties: []
640
+ });
641
+ break;
642
+ case "property":
643
+ if (m.length === 0)
644
+ throw new Error(
645
+ "Invalid PLY file: Property without element"
646
+ );
647
+ m[m.length - 1].properties.push({
648
+ type: w[1],
649
+ name: w[2]
650
+ });
651
+ break;
652
+ }
653
+ }
654
+ if (v !== "binary_little_endian")
655
+ throw new Error(`Unsupported PLY format: ${v}`);
656
+ const b = m.find((c) => c.name === "vertex");
657
+ if (!b)
658
+ throw new Error(
659
+ "Invalid PLY file: No vertex element found"
660
+ );
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")
670
+ ], 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");
679
+ if ([
680
+ T,
681
+ y,
682
+ B,
683
+ ...F,
684
+ ...X,
685
+ ...j,
686
+ W
687
+ ].some((c) => c === -1))
688
+ throw new Error(
689
+ "Invalid PLY file: Missing required properties"
690
+ );
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);
695
+ };
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) {
703
+ case "char":
704
+ K = R.getInt8(x), x += 1;
705
+ break;
706
+ case "uchar":
707
+ K = R.getUint8(x), x += 1;
708
+ break;
709
+ case "short":
710
+ K = R.getInt16(x, !0), x += 2;
711
+ break;
712
+ case "ushort":
713
+ K = R.getUint16(x, !0), x += 2;
714
+ break;
715
+ case "int":
716
+ K = R.getInt32(x, !0), x += 4;
717
+ break;
718
+ case "uint":
719
+ K = R.getUint32(x, !0), x += 4;
720
+ break;
721
+ case "float":
722
+ K = R.getFloat32(x, !0), x += 4;
723
+ break;
724
+ case "double":
725
+ K = R.getFloat64(x, !0), x += 8;
726
+ break;
727
+ default:
728
+ throw new Error(
729
+ `Unsupported property type: ${pe}`
730
+ );
731
+ }
732
+ h.push(K);
733
+ }
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
739
+ );
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;
749
+ }
750
+ return {
751
+ numSplats: E,
752
+ positions: P.buffer,
753
+ rotations: q.buffer,
754
+ scales: H.buffer,
755
+ colors: N.buffer,
756
+ opacities: oe.buffer,
757
+ centers: ee.buffer,
758
+ boundingBox: {
759
+ minX: te,
760
+ minY: s,
761
+ minZ: p,
762
+ maxX: S,
763
+ maxY: I,
764
+ maxZ: D
765
+ }
766
+ };
647
767
  }
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;
768
+ }).toString()})();`;
680
769
  }
681
770
  }
682
- class Ee extends i.EventDispatcher {
771
+ class ze extends l.EventDispatcher {
683
772
  constructor() {
684
773
  super();
685
- h(this, "worker");
686
- h(this, "centers", null);
687
- h(this, "orderTexture", null);
774
+ d(this, "worker");
775
+ d(this, "centers", null);
776
+ d(this, "orderTexture", null);
688
777
  /** 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" });
693
- this.worker = new Worker(URL.createObjectURL(t)), this.worker.onmessage = this.onWorkerMessage.bind(this);
778
+ d(this, "chunks", null);
779
+ d(this, "lastCameraPosition", new l.Vector3());
780
+ 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);
694
783
  }
695
784
  /**
696
785
  * Handles messages received from the sorting worker.
@@ -699,14 +788,14 @@ class Ee extends i.EventDispatcher {
699
788
  onWorkerMessage(o) {
700
789
  if (!this.orderTexture || !this.orderTexture.image)
701
790
  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))
791
+ const { order: r, count: n } = o.data, t = this.orderTexture.image.data;
792
+ if (!(t instanceof Uint32Array))
704
793
  return console.error(
705
794
  "SplatSorter: Order texture data is not a Uint32Array!"
706
795
  );
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 });
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 });
710
799
  }
711
800
  /**
712
801
  * Initializes the sorter with necessary data and textures.
@@ -714,34 +803,34 @@ class Ee extends i.EventDispatcher {
714
803
  * @param centers A Float32Array containing the center position (x, y, z) for each splat.
715
804
  * @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
716
805
  */
717
- init(o, t, r) {
806
+ init(o, r, n) {
718
807
  if (!o || !(o.image.data instanceof Uint32Array))
719
808
  throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
720
- if (!t || t.length % 3 !== 0)
809
+ if (!r || r.length % 3 !== 0)
721
810
  throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
722
- if (o.image.data.length < t.length / 3)
811
+ if (o.image.data.length < r.length / 3)
723
812
  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();
813
+ const t = r.length / 3;
814
+ this.orderTexture = o, this.centers = r.slice();
726
815
  const a = this.orderTexture.image.data;
727
- for (let b = 0; b < n; b++) a[b] = b;
816
+ for (let M = 0; M < t; M++) a[M] = M;
728
817
  this.orderTexture.needsUpdate = !0;
729
- const c = a.buffer.slice(0), v = this.centers.buffer.slice(0), g = {
730
- order: c,
731
- centers: v
732
- }, S = [
733
- c,
734
- v
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
735
824
  ];
736
- if (r) {
737
- this.chunks = r.slice();
738
- const b = this.chunks.buffer.slice(0);
739
- g.chunks = b, S.push(b);
825
+ if (n) {
826
+ this.chunks = n.slice();
827
+ const M = this.chunks.buffer.slice(0);
828
+ g.chunks = M, A.push(M);
740
829
  }
741
- this.worker.postMessage(g, S), queueMicrotask(() => {
830
+ this.worker.postMessage(g, A), queueMicrotask(() => {
742
831
  this.dispatchEvent({
743
832
  type: "updated",
744
- count: n
833
+ count: t
745
834
  });
746
835
  });
747
836
  }
@@ -755,46 +844,46 @@ class Ee extends i.EventDispatcher {
755
844
  return console.warn(
756
845
  "SplatSorter: Cannot set mapping before initialization."
757
846
  );
758
- let t;
759
- const r = [];
847
+ let r;
848
+ const n = [];
760
849
  if (!o) {
761
- const v = this.centers.buffer.slice(0);
762
- return t = {
763
- centers: v,
850
+ const f = this.centers.buffer.slice(0);
851
+ return r = {
852
+ centers: f,
764
853
  mapping: null
765
- }, r.push(v), this.worker.postMessage(t, r);
854
+ }, n.push(f), this.worker.postMessage(r, n);
766
855
  }
767
- const n = new Float32Array(o.length * 3);
768
- for (let v = 0; v < o.length; v++) {
769
- const g = o[v];
856
+ const t = new Float32Array(o.length * 3);
857
+ for (let f = 0; f < o.length; f++) {
858
+ const g = o[f];
770
859
  if (g * 3 + 2 >= this.centers.length) {
771
860
  console.warn(
772
861
  `SplatSorter: Mapping index ${g} out of bounds.`
773
862
  );
774
863
  continue;
775
864
  }
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];
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];
778
867
  }
779
- const a = n.buffer.slice(0), c = o.buffer.slice(0);
780
- t = {
868
+ const a = t.buffer.slice(0), i = o.buffer.slice(0);
869
+ r = {
781
870
  centers: a,
782
- mapping: c
783
- }, r.push(a, c), this.worker.postMessage(t, r);
871
+ mapping: i
872
+ }, n.push(a, i), this.worker.postMessage(r, n);
784
873
  }
785
874
  /**
786
875
  * Updates the camera parameters used for sorting.
787
876
  * @param position The camera's position in the sorter's local coordinate space.
788
877
  * @param direction The camera's forward direction in the sorter's local coordinate space.
789
878
  */
790
- setCamera(o, t) {
791
- const r = this.lastCameraPosition.distanceToSquared(o) > 1e-7, n = this.lastCameraDirection.dot(t) < 0.9999;
792
- if (!r && !n)
879
+ setCamera(o, r) {
880
+ const n = this.lastCameraPosition.distanceToSquared(o) > 1e-7, t = this.lastCameraDirection.dot(r) < 0.9999;
881
+ if (!n && !t)
793
882
  return;
794
- this.lastCameraPosition.copy(o), this.lastCameraDirection.copy(t);
883
+ this.lastCameraPosition.copy(o), this.lastCameraDirection.copy(r);
795
884
  const a = {
796
885
  cameraPosition: { x: o.x, y: o.y, z: o.z },
797
- cameraDirection: { x: t.x, y: t.y, z: t.z }
886
+ cameraDirection: { x: r.x, y: r.y, z: r.z }
798
887
  };
799
888
  this.worker.postMessage(a);
800
889
  }
@@ -810,163 +899,163 @@ class Ee extends i.EventDispatcher {
810
899
  */
811
900
  createWorkerCode() {
812
901
  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;
821
- else return C;
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;
822
911
  }
823
- return ~F;
824
- }, $ = () => {
825
- if (!t || !r || !c || !v)
912
+ return ~R;
913
+ }, ee = () => {
914
+ if (!r || !n || !i || !f)
826
915
  return;
827
- if (r.length === 0) {
828
- const u = {
829
- order: t.buffer,
916
+ if (n.length === 0) {
917
+ const c = {
918
+ order: r.buffer,
830
919
  count: 0
831
920
  };
832
- self.postMessage(u, [t.buffer]), t = null;
921
+ self.postMessage(c, [r.buffer]), r = null;
833
922
  return;
834
923
  }
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)
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)
837
926
  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);
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;
929
+ 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);
843
932
  }
844
- const R = r.length / 3, N = E - x, s = (1 << Math.max(
933
+ const z = n.length / 3, Z = Y - W, s = (1 << Math.max(
845
934
  10,
846
- Math.min(20, Math.ceil(Math.log2(R / 4)))
935
+ Math.min(20, Math.ceil(Math.log2(z / 4)))
847
936
  )) + 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;
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;
853
942
  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(
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(
856
945
  0,
857
- Math.floor(oe * B / N)
858
- ), ce = Math.min(
859
- B,
860
- Math.ceil(ee * B / N)
946
+ Math.floor(G * P / Z)
947
+ ), ne = Math.min(
948
+ P,
949
+ Math.ceil(J * P / Z)
861
950
  );
862
- for (let Q = ie; Q < ce; ++Q)
951
+ for (let Q = re; Q < ne; ++Q)
863
952
  q[Q]++;
864
953
  }
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(
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(
874
963
  0,
875
964
  Math.min(
876
- B - 1,
877
- Math.floor(oe)
965
+ P - 1,
966
+ Math.floor(G)
878
967
  )
879
- ), ie = oe - ee, ce = W[ee] + j[ee] * ie >>> 0, Q = Math.min(ce, s - 1);
880
- f[l] = Q, _[Q]++;
968
+ ), re = G - J, ne = H[J] + N[J] * re >>> 0, Q = Math.min(ne, s - 1);
969
+ b[u] = Q, E[Q]++;
881
970
  }
882
971
  } 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]++;
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]++;
887
976
  }
888
977
  }
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;
978
+ 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;
894
983
  }
895
- const d = F * C + k * w + O * M, A = (u) => {
896
- if (!t) return -1 / 0;
897
- const P = t[u], D = P;
898
- if (!r || D * 3 + 2 >= r.length)
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)
899
988
  return -1 / 0;
900
- const l = D * 3;
901
- return r[l] * C + r[l + 1] * w + r[l + 2] * M - d;
989
+ const u = w * 3;
990
+ return n[u] * T + n[u + 1] * y + n[u + 2] * B - p;
902
991
  };
903
- let z = R;
904
- if (R > 0 && A(R - 1) < 0) {
905
- const u = H(
992
+ let I = z;
993
+ if (z > 0 && S(z - 1) < 0) {
994
+ const c = oe(
906
995
  0,
907
- R - 1,
908
- A
996
+ z - 1,
997
+ S
909
998
  );
910
- z = u < 0 ? ~u : u;
999
+ I = c < 0 ? ~c : c;
911
1000
  }
912
- const L = {
913
- order: t.buffer,
914
- count: z
1001
+ const D = {
1002
+ order: r.buffer,
1003
+ count: I
915
1004
  };
916
- self.postMessage(L, [t.buffer]), t = null;
1005
+ self.postMessage(D, [r.buffer]), r = null;
917
1006
  };
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
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
928
1017
  ) * 0.5;
929
1018
  }
930
1019
  g = !0;
931
1020
  }
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]);
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]);
937
1026
  }
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), $();
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();
940
1029
  };
941
1030
  }).toString()})();`;
942
1031
  }
943
1032
  }
944
- const ke = (T, e) => {
945
- const o = de(T), t = de(e);
946
- return o | t << 16;
1033
+ const Be = (_, e) => {
1034
+ const o = ge(_), r = ge(e);
1035
+ return o | r << 16;
947
1036
  };
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;
951
- 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);
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);
953
1042
  }
954
- const Ie = new ArrayBuffer(4), pe = new DataView(Ie), Re = (T) => (pe.setUint32(0, T, !0), pe.getFloat32(0, !0));
955
- class ze {
1043
+ const Fe = new ArrayBuffer(4), ve = new DataView(Fe), Oe = (_) => (ve.setUint32(0, _, !0), ve.getFloat32(0, !0));
1044
+ class De {
956
1045
  /**
957
1046
  * Create a new TextureManager for a set of splats
958
1047
  * @param splatData The splat data to manage textures for
959
1048
  */
960
1049
  constructor(e) {
961
- h(this, "transformA");
1050
+ d(this, "transformA");
962
1051
  // position xyz and rotation quaternion y,z components
963
- h(this, "transformB");
1052
+ d(this, "transformB");
964
1053
  // rotation quaternion x and scale xyz
965
- h(this, "colorTexture");
1054
+ d(this, "colorTexture");
966
1055
  // color an opacity
967
- h(this, "orderTexture");
968
- h(this, "textureWidth");
969
- h(this, "textureHeight");
1056
+ d(this, "orderTexture");
1057
+ d(this, "textureWidth");
1058
+ d(this, "textureHeight");
970
1059
  const o = e.numSplats;
971
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);
972
1061
  }
@@ -976,24 +1065,24 @@ class ze {
976
1065
  * @returns DataTexture containing position data
977
1066
  */
978
1067
  createTransformATexture(e) {
979
- const o = e.numSplats, t = new Float32Array(
1068
+ const o = e.numSplats, r = new Float32Array(
980
1069
  this.textureWidth * this.textureHeight * 4
981
1070
  );
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);
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);
987
1076
  }
988
- const r = new i.DataTexture(
989
- t,
1077
+ const n = new l.DataTexture(
1078
+ r,
990
1079
  this.textureWidth,
991
1080
  this.textureHeight,
992
- i.RGBAFormat,
993
- i.FloatType
1081
+ l.RGBAFormat,
1082
+ l.FloatType
994
1083
  // Store as Float32, shader will reinterpret bits
995
1084
  );
996
- return r.needsUpdate = !0, r.magFilter = i.NearestFilter, r.minFilter = i.NearestFilter, r;
1085
+ return n.needsUpdate = !0, n.magFilter = l.NearestFilter, n.minFilter = l.NearestFilter, n;
997
1086
  }
998
1087
  /**
999
1088
  * Create the transform B texture (scale and rotation xyz)
@@ -1001,21 +1090,21 @@ class ze {
1001
1090
  * @returns DataTexture containing scale and rotation data
1002
1091
  */
1003
1092
  createTransformBTexture(e) {
1004
- const o = e.numSplats, t = new Float32Array(
1093
+ const o = e.numSplats, r = new Float32Array(
1005
1094
  this.textureWidth * this.textureHeight * 4
1006
1095
  );
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];
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];
1010
1099
  }
1011
- const r = new i.DataTexture(
1012
- t,
1100
+ const n = new l.DataTexture(
1101
+ r,
1013
1102
  this.textureWidth,
1014
1103
  this.textureHeight,
1015
- i.RGBAFormat,
1016
- i.FloatType
1104
+ l.RGBAFormat,
1105
+ l.FloatType
1017
1106
  );
1018
- return r.needsUpdate = !0, r.magFilter = i.NearestFilter, r.minFilter = i.NearestFilter, r;
1107
+ return n.needsUpdate = !0, n.magFilter = l.NearestFilter, n.minFilter = l.NearestFilter, n;
1019
1108
  }
1020
1109
  /**
1021
1110
  * Create the color texture (RGB and opacity)
@@ -1023,21 +1112,21 @@ class ze {
1023
1112
  * @returns DataTexture containing color data
1024
1113
  */
1025
1114
  createColorTexture(e) {
1026
- const o = e.numSplats, t = new Float32Array(
1115
+ const o = e.numSplats, r = new Float32Array(
1027
1116
  this.textureWidth * this.textureHeight * 4
1028
1117
  );
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];
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];
1032
1121
  }
1033
- const r = new i.DataTexture(
1034
- t,
1122
+ const n = new l.DataTexture(
1123
+ r,
1035
1124
  this.textureWidth,
1036
1125
  this.textureHeight,
1037
- i.RGBAFormat,
1038
- i.FloatType
1126
+ l.RGBAFormat,
1127
+ l.FloatType
1039
1128
  );
1040
- return r.needsUpdate = !0, r;
1129
+ return n.needsUpdate = !0, n;
1041
1130
  }
1042
1131
  /**
1043
1132
  * Create the order texture for sorting
@@ -1046,22 +1135,22 @@ class ze {
1046
1135
  */
1047
1136
  createOrderTexture(e) {
1048
1137
  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(
1138
+ for (let n = 0; n < e; n++)
1139
+ o[n] = n;
1140
+ const r = new l.DataTexture(
1052
1141
  o,
1053
1142
  this.textureWidth,
1054
1143
  this.textureHeight,
1055
- i.RedIntegerFormat,
1056
- i.UnsignedIntType
1144
+ l.RedIntegerFormat,
1145
+ l.UnsignedIntType
1057
1146
  );
1058
- return t.needsUpdate = !0, t;
1147
+ return r.needsUpdate = !0, r;
1059
1148
  }
1060
1149
  dispose() {
1061
1150
  this.transformA.dispose(), this.transformB.dispose(), this.colorTexture.dispose(), this.orderTexture.dispose();
1062
1151
  }
1063
1152
  }
1064
- const Pe = (
1153
+ const Ue = (
1065
1154
  /* glsl */
1066
1155
  `
1067
1156
  precision highp float;
@@ -1319,7 +1408,7 @@ void main(void) {
1319
1408
  vUv = clippedCornerOffset;
1320
1409
  }
1321
1410
  `
1322
- ), Be = (
1411
+ ), Ve = (
1323
1412
  /* glsl */
1324
1413
  `
1325
1414
  precision highp float;
@@ -1353,7 +1442,7 @@ void main(void) {
1353
1442
  }
1354
1443
  `
1355
1444
  );
1356
- class Oe extends i.ShaderMaterial {
1445
+ class qe extends l.ShaderMaterial {
1357
1446
  constructor(e = {}) {
1358
1447
  const o = {
1359
1448
  // Textures (values set via methods)
@@ -1362,39 +1451,39 @@ class Oe extends i.ShaderMaterial {
1362
1451
  splatColor: { value: null },
1363
1452
  splatOrder: { value: null },
1364
1453
  // Other uniforms
1365
- viewport: { value: new i.Vector2(1, 1) },
1454
+ viewport: { value: new l.Vector2(1, 1) },
1366
1455
  // Will be updated
1367
1456
  numSplats: { value: 0 }
1368
1457
  // Max splats to render (updated by sorter)
1369
1458
  };
1370
1459
  super({
1371
- vertexShader: Pe,
1372
- fragmentShader: Be,
1460
+ vertexShader: Ue,
1461
+ fragmentShader: Ve,
1373
1462
  uniforms: o,
1374
1463
  transparent: !0,
1375
- blending: i.CustomBlending,
1464
+ blending: l.CustomBlending,
1376
1465
  // Premultiplied alpha blending:
1377
1466
  // color = src_color * src_alpha + dst_color * (1 - src_alpha)
1378
1467
  // alpha = src_alpha * 1 + dst_alpha * (1 - src_alpha)
1379
- blendSrc: i.OneFactor,
1468
+ blendSrc: l.OneFactor,
1380
1469
  // Using ONE because shader outputs premultiplied color (color * alpha)
1381
- blendDst: i.OneMinusSrcAlphaFactor,
1382
- blendSrcAlpha: i.OneFactor,
1470
+ blendDst: l.OneMinusSrcAlphaFactor,
1471
+ blendSrcAlpha: l.OneFactor,
1383
1472
  // source alpha comes from shader
1384
- blendDstAlpha: i.OneMinusSrcAlphaFactor,
1385
- blendEquation: i.AddEquation,
1386
- blendEquationAlpha: i.AddEquation,
1473
+ blendDstAlpha: l.OneMinusSrcAlphaFactor,
1474
+ blendEquation: l.AddEquation,
1475
+ blendEquationAlpha: l.AddEquation,
1387
1476
  depthTest: !0,
1388
1477
  depthWrite: !1,
1389
1478
  // Disable depth write for transparency
1390
- side: i.DoubleSide,
1479
+ side: l.DoubleSide,
1391
1480
  // Render both sides (or CULLFACE_NONE equivalent)
1392
1481
  // Optional settings from constructor
1393
1482
  alphaTest: e.alphaTest !== void 0 ? e.alphaTest : 0,
1394
1483
  // Typically 0 for blending
1395
1484
  toneMapped: e.toneMapped !== void 0 ? e.toneMapped : !1
1396
1485
  // prettier-ignore
1397
- }), e.alphaHash && (this.alphaHash = !0, this.depthWrite = !0, this.blending = i.NoBlending);
1486
+ }), e.alphaHash && (this.alphaHash = !0, this.depthWrite = !0, this.blending = l.NoBlending);
1398
1487
  }
1399
1488
  /**
1400
1489
  * Update the viewport size
@@ -1440,47 +1529,47 @@ class Oe extends i.ShaderMaterial {
1440
1529
  this.uniforms.numSplats.value = e;
1441
1530
  }
1442
1531
  }
1443
- const K = class K extends i.Mesh {
1532
+ const se = class se extends l.Mesh {
1444
1533
  // Match shader constant
1445
1534
  /**
1446
1535
  * Create a new SplatMesh for rendering Gaussian splats
1447
1536
  * @param splatData The splat data to render
1448
1537
  * @param options Rendering options
1449
1538
  */
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());
1539
+ constructor(o, r = {}) {
1540
+ const n = new qe(r), t = se.createInstancedGeometry(o.numSplats, se.INSTANCE_SIZE);
1541
+ super(t, n);
1542
+ d(this, "sorter");
1543
+ d(this, "splatData");
1544
+ d(this, "options");
1545
+ d(this, "textureManager");
1546
+ d(this, "material");
1547
+ d(this, "geometry");
1548
+ d(this, "lastCameraPositionLocal", new l.Vector3());
1549
+ d(this, "lastCameraDirectionLocal", new l.Vector3());
1550
+ d(this, "invModelMatrix", new l.Matrix4());
1462
1551
  // 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);
1552
+ d(this, "_vpW", -1);
1553
+ d(this, "_vpH", -1);
1554
+ d(this, "_size", new l.Vector2());
1555
+ d(this, "_camPosW", new l.Vector3());
1556
+ d(this, "_camDirW", new l.Vector3());
1557
+ d(this, "_camPosL", new l.Vector3());
1558
+ 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);
1473
1562
  });
1474
- this.geometry = n, this.material = r, this.splatData = o, this.frustumCulled = !1, this.options = {
1563
+ this.geometry = t, this.material = n, this.splatData = o, this.frustumCulled = !1, this.options = {
1475
1564
  autoSort: !0,
1476
- ...t
1477
- }, this.textureManager = new ze(o), this.sorter = new Ee();
1565
+ ...r
1566
+ }, this.textureManager = new De(o), this.sorter = new ze();
1478
1567
  let a = this.createChunks() || void 0;
1479
1568
  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
1569
  this.textureManager.orderTexture,
1481
1570
  this.splatData.centers,
1482
1571
  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);
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);
1484
1573
  }
1485
1574
  /**
1486
1575
  * Creates the instanced geometry for rendering splats.
@@ -1488,8 +1577,8 @@ const K = class K extends i.Mesh {
1488
1577
  * @param instanceSize Number of splats per instance.
1489
1578
  * @returns InstancedBufferGeometry
1490
1579
  */
1491
- static createInstancedGeometry(o, t) {
1492
- const r = Math.ceil(o / t), n = new i.BufferGeometry(), a = new Float32Array([
1580
+ static createInstancedGeometry(o, r) {
1581
+ const n = Math.ceil(o / r), t = new l.BufferGeometry(), a = new Float32Array([
1493
1582
  // x, y, splat_index_in_instance
1494
1583
  -1,
1495
1584
  -1,
@@ -1503,24 +1592,24 @@ const K = class K extends i.Mesh {
1503
1592
  -1,
1504
1593
  1,
1505
1594
  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;
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;
1598
+ 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;
1511
1600
  }
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;
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;
1516
1605
  }
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;
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;
1524
1613
  }
1525
1614
  /**
1526
1615
  * Create chunks data (bounding box min/max) for the sorter.
@@ -1542,8 +1631,8 @@ const K = class K extends i.Mesh {
1542
1631
  * @param width Viewport width
1543
1632
  * @param height Viewport height
1544
1633
  */
1545
- updateViewport(o, t) {
1546
- o === this._vpW && t === this._vpH || (this._vpW = o, this._vpH = t, this.material.updateViewport(o, t));
1634
+ updateViewport(o, r) {
1635
+ o === this._vpW && r === this._vpH || (this._vpW = o, this._vpH = r, this.material.updateViewport(o, r));
1547
1636
  }
1548
1637
  /**
1549
1638
  * Sorts splats based on camera position and direction.
@@ -1551,8 +1640,8 @@ const K = class K extends i.Mesh {
1551
1640
  */
1552
1641
  sort(o) {
1553
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);
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));
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));
1556
1645
  }
1557
1646
  /**
1558
1647
  * THREE.js hook called before rendering the object.
@@ -1563,8 +1652,8 @@ const K = class K extends i.Mesh {
1563
1652
  */
1564
1653
  // prettier-ignore
1565
1654
  // @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);
1655
+ onBeforeRender(o, r, n) {
1656
+ this.sort(n), o.getSize(this._size), this.updateViewport(this._size.x, this._size.y);
1568
1657
  }
1569
1658
  /**
1570
1659
  * Dispose of resources
@@ -1574,11 +1663,11 @@ const K = class K extends i.Mesh {
1574
1663
  }
1575
1664
  };
1576
1665
  /** 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");
1666
+ d(se, "INSTANCE_SIZE", 128);
1667
+ let le = se;
1668
+ const je = Symbol.for("@speridlabs/visus/SplatMesh");
1580
1669
  try {
1581
- Object.defineProperty(ae.prototype, De, {
1670
+ Object.defineProperty(le.prototype, je, {
1582
1671
  value: !0,
1583
1672
  configurable: !1,
1584
1673
  enumerable: !1,
@@ -1587,23 +1676,23 @@ try {
1587
1676
  } catch {
1588
1677
  console.warn("Couldn't define Visus SplatMesh symbol");
1589
1678
  }
1590
- const je = ({
1591
- plyUrl: T,
1679
+ const He = ({
1680
+ plyUrl: _,
1592
1681
  debug: e = !1,
1593
1682
  splatOptions: o = {},
1594
- ...t
1683
+ ...r
1595
1684
  }) => {
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]
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]
1600
1689
  );
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 });
1690
+ 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 });
1604
1693
  };
1605
1694
  export {
1606
- Ce as PlyLoader,
1607
- je as Splat,
1608
- ae as SplatMesh
1695
+ Pe as PlyLoader,
1696
+ He as Splat,
1697
+ le as SplatMesh
1609
1698
  };