@speridlabs/visus 1.0.2 → 1.0.4

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