@speridlabs/visus 1.0.1 → 1.0.2

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