@speridlabs/visus 1.0.1 → 1.0.3

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,7 +1,7 @@
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 = (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
6
  import * as i from "three";
7
7
  var se = { exports: {} }, te = {};
@@ -18,23 +18,23 @@ var ue;
18
18
  function Se() {
19
19
  if (ue) return te;
20
20
  ue = 1;
21
- var M = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
22
- function s(n, r, t) {
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 (t !== void 0 && (a = "" + t), r.key !== void 0 && (a = "" + r.key), "key" in r) {
25
- t = {};
24
+ if (n !== void 0 && (a = "" + n), r.key !== void 0 && (a = "" + r.key), "key" in r) {
25
+ n = {};
26
26
  for (var c in r)
27
- c !== "key" && (t[c] = r[c]);
28
- } else t = r;
29
- return r = t.ref, {
30
- $$typeof: M,
31
- type: n,
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
33
  ref: r !== void 0 ? r : null,
34
- props: t
34
+ props: n
35
35
  };
36
36
  }
37
- return te.Fragment = e, te.jsx = s, te.jsxs = s, te;
37
+ return te.Fragment = e, te.jsx = o, te.jsxs = o, te;
38
38
  }
39
39
  var re = {};
40
40
  /**
@@ -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 he;
50
+ function _e() {
51
+ return he || (he = 1, process.env.NODE_ENV !== "production" && function() {
52
+ function T(s) {
53
+ if (s == null) return null;
54
+ if (typeof s == "function")
55
+ return s.$$typeof === w ? null : s.displayName || s.name || null;
56
+ if (typeof s == "string") return s;
57
+ switch (s) {
58
+ case _:
59
59
  return "Fragment";
60
60
  case q:
61
61
  return "Profiler";
62
- case O:
62
+ case B:
63
63
  return "StrictMode";
64
64
  case $:
65
65
  return "Suspense";
66
- case D:
66
+ case F:
67
67
  return "SuspenseList";
68
- case E:
68
+ case A:
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 f:
76
76
  return "Portal";
77
77
  case j:
78
- return (o.displayName || "Context") + ".Provider";
78
+ return (s.displayName || "Context") + ".Provider";
79
79
  case W:
80
- return (o._context.displayName || "Context") + ".Consumer";
80
+ return (s._context.displayName || "Context") + ".Consumer";
81
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;
82
+ var d = s.render;
83
+ return s = s.displayName, s || (s = d.displayName || d.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
84
+ case E:
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(o(d));
89
+ return T(s(d));
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 o(s) {
99
99
  try {
100
- e(o);
100
+ e(s);
101
101
  var d = !1;
102
102
  } catch {
103
103
  d = !0;
104
104
  }
105
105
  if (d) {
106
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(
107
+ var M = d.error, R = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
108
+ return M.call(
109
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
- z
112
- ), e(o);
111
+ R
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 t(s) {
116
+ if (s === _) return "<>";
117
+ if (typeof s == "object" && s !== null && s.$$typeof === O)
118
118
  return "<...>";
119
119
  try {
120
- var d = M(o);
120
+ var d = T(s);
121
121
  return d ? "<" + d + ">" : "<...>";
122
122
  } catch {
123
123
  return "<...>";
124
124
  }
125
125
  }
126
126
  function r() {
127
- var o = C.A;
128
- return o === null ? null : o.getOwner();
127
+ var s = P.A;
128
+ return s === null ? null : s.getOwner();
129
129
  }
130
- function t() {
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;
133
+ function a(s) {
134
+ if (U.call(s, "key")) {
135
+ var d = Object.getOwnPropertyDescriptor(s, "key").get;
136
136
  if (d && d.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 c(s, d) {
141
+ function M() {
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
144
  d
145
145
  ));
146
146
  }
147
- A.isReactWarning = !0, Object.defineProperty(o, "key", {
148
- get: A,
147
+ M.isReactWarning = !0, Object.defineProperty(s, "key", {
148
+ get: M,
149
149
  configurable: !0
150
150
  });
151
151
  }
152
- function l() {
153
- var o = M(this.type);
154
- return _[o] || (_[o] = !0, console.error(
152
+ function v() {
153
+ var s = T(this.type);
154
+ return C[s] || (C[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,
158
+ function g(s, d, M, R, L, u, z, D) {
159
+ return M = u.ref, s = {
160
+ $$typeof: m,
161
+ type: s,
162
162
  key: d,
163
- props: f,
164
- _owner: N
165
- }, (A !== void 0 ? A : null) !== null ? Object.defineProperty(o, "ref", {
163
+ props: u,
164
+ _owner: L
165
+ }, (M !== void 0 ? M : null) !== null ? Object.defineProperty(s, "ref", {
166
166
  enumerable: !1,
167
- get: l
168
- }) : Object.defineProperty(o, "ref", { enumerable: !1, value: null }), o._store = {}, Object.defineProperty(o._store, "validated", {
167
+ get: v
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: z
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: D
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 S(s, d, M, R, L, u, z, D) {
191
+ var l = d.children;
192
+ if (l !== void 0)
193
+ if (R)
194
+ if (V(l)) {
195
+ for (R = 0; R < l.length; R++)
196
+ b(l[R]);
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 b(u);
202
+ else b(l);
203
203
  if (U.call(d, "key")) {
204
- u = M(o);
205
- var I = Object.keys(d).filter(function(X) {
204
+ l = T(s);
205
+ var k = Object.keys(d).filter(function(X) {
206
206
  return X !== "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
+ R = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", G[l + R] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
209
209
  `A props object containing a "key" prop is being spread into JSX:
210
210
  let props = %s;
211
211
  <%s {...props} />
212
212
  React keys must be passed directly to JSX without using spread:
213
213
  let props = %s;
214
214
  <%s key={someKey} {...props} />`,
215
- z,
216
- u,
217
- I,
218
- u
219
- ), G[u + z] = !0);
215
+ R,
216
+ l,
217
+ k,
218
+ l
219
+ ), G[l + R] = !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 = {};
221
+ if (l = null, M !== void 0 && (o(M), l = "" + M), a(d) && (o(d.key), l = "" + d.key), "key" in d) {
222
+ M = {};
223
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,
224
+ Y !== "key" && (M[Y] = d[Y]);
225
+ } else M = d;
226
+ return l && c(
227
+ M,
228
+ typeof s == "function" ? s.displayName || s.name || "Unknown" : s
229
+ ), g(
230
+ s,
231
+ l,
231
232
  u,
232
- f,
233
- N,
233
+ L,
234
234
  r(),
235
- A,
236
- P,
237
- F
235
+ M,
236
+ z,
237
+ D
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 b(s) {
241
+ typeof s == "object" && s !== null && s.$$typeof === m && 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 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"), E = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), A = Symbol.for("react.activity"), w = Symbol.for("react.client.reference"), P = 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
246
  p = {
247
- "react-stack-bottom-frame": function(o) {
248
- return o();
247
+ "react-stack-bottom-frame": function(s) {
248
+ return s();
249
249
  }
250
250
  };
251
- var y, _ = {}, R = p["react-stack-bottom-frame"].bind(
251
+ var x, C = {}, I = p["react-stack-bottom-frame"].bind(
252
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++;
253
+ n
254
+ )(), N = y(t(n)), G = {};
255
+ re.Fragment = _, re.jsx = function(s, d, M, R, L) {
256
+ var u = 1e4 > P.recentlyCreatedOwnerStacks++;
257
257
  return S(
258
- o,
258
+ s,
259
259
  d,
260
- A,
260
+ M,
261
261
  !1,
262
- z,
263
- N,
264
- f ? Error("react-stack-top-frame") : R,
265
- f ? v(n(o)) : L
262
+ R,
263
+ L,
264
+ u ? Error("react-stack-top-frame") : I,
265
+ u ? y(t(s)) : N
266
266
  );
267
- }, re.jsxs = function(o, d, A, z, N) {
268
- var f = 1e4 > C.recentlyCreatedOwnerStacks++;
267
+ }, re.jsxs = function(s, d, M, R, L) {
268
+ var u = 1e4 > P.recentlyCreatedOwnerStacks++;
269
269
  return S(
270
- o,
270
+ s,
271
271
  d,
272
- A,
272
+ M,
273
273
  !0,
274
- z,
275
- N,
276
- f ? Error("react-stack-top-frame") : R,
277
- f ? v(n(o)) : L
274
+ R,
275
+ L,
276
+ u ? Error("react-stack-top-frame") : I,
277
+ u ? y(t(s)) : N
278
278
  );
279
279
  };
280
280
  }()), re;
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 Te() {
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 Me = Te();
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
+ 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
- g(this, "halfExtents", new i.Vector3());
293
+ h(this, "halfExtents", new i.Vector3());
294
294
  }
295
295
  /**
296
296
  * Reset the bounding box to its initial state
@@ -345,14 +345,14 @@ class le {
345
345
  class Ae {
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
+ 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 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, 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 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 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,18 +385,18 @@ 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 o = e * 3, t = e * 4, r = e * 3, n = e * 3;
389
389
  return {
390
390
  position: new i.Vector3(
391
- this.positions[s],
392
- this.positions[s + 1],
393
- this.positions[s + 2]
391
+ this.positions[o],
392
+ this.positions[o + 1],
393
+ this.positions[o + 2]
394
394
  ),
395
395
  rotation: new i.Quaternion(
396
- this.rotations[n],
397
- this.rotations[n + 1],
398
- this.rotations[n + 2],
399
- this.rotations[n + 3]
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
402
  scale: new i.Vector3(
@@ -405,9 +405,9 @@ class Ae {
405
405
  Math.exp(this.scales[r + 2])
406
406
  ),
407
407
  color: new i.Color(
408
- this.colors[t],
409
- this.colors[t + 1],
410
- this.colors[t + 2]
408
+ this.colors[n],
409
+ this.colors[n + 1],
410
+ this.colors[n + 2]
411
411
  ),
412
412
  opacity: this.opacities[e]
413
413
  };
@@ -419,12 +419,12 @@ class Ae {
419
419
  calculateBoundingBox() {
420
420
  this.boundingBox.reset();
421
421
  const e = new i.Vector3();
422
- for (let s = 0; s < this.numSplats; s++) {
423
- const n = s * 3;
422
+ for (let o = 0; o < this.numSplats; o++) {
423
+ const t = o * 3;
424
424
  e.set(
425
- this.positions[n],
426
- this.positions[n + 1],
427
- this.positions[n + 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;
@@ -439,19 +439,19 @@ class Ae {
439
439
  "position",
440
440
  new i.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 o = new Float32Array(this.numSplats * 3), t = new i.Quaternion(), r = new i.Euler();
443
+ for (let n = 0; n < this.numSplats; n++) {
444
+ const a = n * 4, c = n * 3;
445
+ t.set(
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
+ ), 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 i.BufferAttribute(s, 3)
454
+ new i.BufferAttribute(o, 3)
455
455
  ), e.setAttribute(
456
456
  "scale",
457
457
  new i.BufferAttribute(this.scales, 3)
@@ -464,7 +464,7 @@ class Ae {
464
464
  ), e;
465
465
  }
466
466
  }
467
- class Ee extends i.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,21 +472,21 @@ 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, o, t, r) {
476
+ const n = new i.FileLoader(this.manager);
477
+ n.setResponseType("arraybuffer"), n.setRequestHeader(this.requestHeader), n.setPath(this.path), n.setWithCredentials(this.withCredentials), n.load(
478
478
  e,
479
479
  (a) => {
480
480
  try {
481
- if (s) {
481
+ if (o) {
482
482
  const c = this.parse(a);
483
- s(c);
483
+ o(c);
484
484
  }
485
485
  } catch (c) {
486
486
  r ? r(c) : console.error(c), this.manager.itemError(e);
487
487
  }
488
488
  },
489
- n,
489
+ t,
490
490
  r
491
491
  );
492
492
  }
@@ -496,20 +496,20 @@ class Ee extends i.Loader {
496
496
  * @param onProgress Optional progress callback
497
497
  * @returns A Promise that resolves with the parsed SplatData
498
498
  */
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(
499
+ loadAsync(e, o) {
500
+ return new Promise((t, r) => {
501
+ const n = new i.FileLoader(this.manager);
502
+ n.setResponseType("arraybuffer"), n.setRequestHeader(this.requestHeader), n.setPath(this.path), n.setWithCredentials(this.withCredentials), n.load(
503
503
  e,
504
504
  (a) => {
505
505
  try {
506
506
  const c = this.parse(a);
507
- n(c);
507
+ t(c);
508
508
  } catch (c) {
509
509
  r(c), this.manager.itemError(e);
510
510
  }
511
511
  },
512
- s,
512
+ o,
513
513
  (a) => {
514
514
  r(a), this.manager.itemError(e);
515
515
  }
@@ -522,55 +522,53 @@ class Ee extends i.Loader {
522
522
  * @returns Parsed SplatData
523
523
  */
524
524
  parse(e) {
525
- const s = new TextDecoder(), n = new Uint8Array(e), r = [112, 108, 121, 10], t = `
525
+ const o = new TextDecoder(), t = new Uint8Array(e), r = [112, 108, 121, 10], n = `
526
526
  end_header
527
527
  `;
528
- for (let v = 0; v < r.length; v++)
529
- if (n[v] !== r[v])
528
+ for (let y = 0; y < r.length; y++)
529
+ if (t[y] !== r[y])
530
530
  throw new Error("Invalid PLY file: Missing magic bytes");
531
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;
532
+ for (let y = 0; y < t.length - n.length; y++) {
533
+ let x = !0;
534
+ for (let C = 0; C < n.length; C++)
535
+ if (t[y + C] !== n.charCodeAt(C)) {
536
+ x = !1;
537
537
  break;
538
538
  }
539
- if (y) {
540
- a = v + t.length;
539
+ if (x) {
540
+ a = y + n.length;
541
541
  break;
542
542
  }
543
543
  }
544
544
  if (a === 0)
545
545
  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 = [];
546
+ const v = o.decode(t.subarray(0, a)).split(`
547
+ `), g = [];
550
548
  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]) {
549
+ for (let y = 1; y < v.length; y++) {
550
+ const x = v[y].trim();
551
+ if (x === "" || x === "end_header") continue;
552
+ const C = x.split(" ");
553
+ switch (C[0]) {
556
554
  case "format":
557
- S = _[1];
555
+ S = C[1];
558
556
  break;
559
557
  case "element":
560
- m.push({
561
- name: _[1],
562
- count: parseInt(_[2], 10),
558
+ g.push({
559
+ name: C[1],
560
+ count: parseInt(C[2], 10),
563
561
  properties: []
564
562
  });
565
563
  break;
566
564
  case "property":
567
- if (m.length === 0)
565
+ if (g.length === 0)
568
566
  throw new Error(
569
567
  "Invalid PLY file: Property without element"
570
568
  );
571
- m[m.length - 1].properties.push({
572
- type: _[1],
573
- name: _[2],
569
+ g[g.length - 1].properties.push({
570
+ type: C[1],
571
+ name: C[2],
574
572
  storage: null
575
573
  });
576
574
  break;
@@ -578,136 +576,136 @@ end_header
578
576
  }
579
577
  if (S !== "binary_little_endian")
580
578
  throw new Error(`Unsupported PLY format: ${S}`);
581
- const b = m.find((v) => v.name === "vertex");
579
+ const b = g.find((y) => y.name === "vertex");
582
580
  if (!b)
583
581
  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")
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")
591
589
  ], H = [
592
- T("scale_0"),
593
- T("scale_1"),
594
- T("scale_2")
590
+ _("scale_0"),
591
+ _("scale_1"),
592
+ _("scale_2")
595
593
  ], $ = [
596
- T("f_dc_0"),
597
- T("f_dc_1"),
598
- T("f_dc_2")
599
- ], D = T("opacity");
594
+ _("f_dc_0"),
595
+ _("f_dc_1"),
596
+ _("f_dc_2")
597
+ ], F = _("opacity");
600
598
  if ([
601
- O,
599
+ B,
602
600
  q,
603
601
  W,
604
602
  ...j,
605
603
  ...H,
606
604
  ...$,
607
- D
608
- ].some((v) => v === -1))
605
+ F
606
+ ].some((y) => y === -1))
609
607
  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;
608
+ const O = 0.28209479177387814, A = (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(), P = 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 I = 0; I < b.properties.length; I++) {
616
+ const G = b.properties[I].type;
617
+ let s;
620
618
  switch (G) {
621
619
  case "char":
622
- o = x.getInt8(h), h += 1;
620
+ s = m.getInt8(f), f += 1;
623
621
  break;
624
622
  case "uchar":
625
- o = x.getUint8(h), h += 1;
623
+ s = m.getUint8(f), f += 1;
626
624
  break;
627
625
  case "short":
628
- o = x.getInt16(h, !0), h += 2;
626
+ s = m.getInt16(f, !0), f += 2;
629
627
  break;
630
628
  case "ushort":
631
- o = x.getUint16(h, !0), h += 2;
629
+ s = m.getUint16(f, !0), f += 2;
632
630
  break;
633
631
  case "int":
634
- o = x.getInt32(h, !0), h += 4;
632
+ s = m.getInt32(f, !0), f += 4;
635
633
  break;
636
634
  case "uint":
637
- o = x.getUint32(h, !0), h += 4;
635
+ s = m.getUint32(f, !0), f += 4;
638
636
  break;
639
637
  case "float":
640
- o = x.getFloat32(h, !0), h += 4;
638
+ s = m.getFloat32(f, !0), f += 4;
641
639
  break;
642
640
  case "double":
643
- o = x.getFloat64(h, !0), h += 8;
641
+ s = m.getFloat64(f, !0), f += 8;
644
642
  break;
645
643
  default:
646
644
  throw new Error(`Unsupported property type: ${G}`);
647
645
  }
648
- y.push(o);
646
+ x.push(s);
649
647
  }
650
648
  w.set(
651
- y[O],
652
- y[q],
653
- y[W]
654
- ), C.set(
655
- y[j[1]],
649
+ x[B],
650
+ x[q],
651
+ x[W]
652
+ ), P.set(
653
+ x[j[1]],
656
654
  // 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]],
655
+ x[j[2]],
656
+ x[j[3]],
657
+ x[j[0]]
658
+ ).normalize(), U.set(
659
+ x[H[0]],
662
660
  // Read directly assuming it's log scale
663
- y[H[1]],
664
- y[H[2]]
661
+ x[H[1]],
662
+ x[H[2]]
665
663
  ), V.set(
666
- 0.5 + y[$[0]] * B,
667
- 0.5 + y[$[1]] * B,
668
- 0.5 + y[$[2]] * B
664
+ 0.5 + x[$[0]] * O,
665
+ 0.5 + x[$[1]] * O,
666
+ 0.5 + x[$[2]] * O
669
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));
670
- const _ = E(y[D]);
668
+ const C = A(x[F]);
671
669
  p.setSplat(
672
- v,
670
+ y,
673
671
  w,
674
- C,
672
+ P,
675
673
  U,
676
674
  // Pass log scale directly
677
675
  V,
678
- _
676
+ C
679
677
  );
680
678
  }
681
679
  return p.calculateBoundingBox(), p;
682
680
  }
683
681
  }
684
- class _e extends i.EventDispatcher {
682
+ class Ee extends i.EventDispatcher {
685
683
  constructor() {
686
684
  super();
687
- g(this, "worker");
688
- g(this, "centers", null);
689
- g(this, "orderTexture", null);
685
+ h(this, "worker");
686
+ h(this, "centers", null);
687
+ h(this, "orderTexture", null);
690
688
  /** 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);
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);
696
694
  }
697
695
  /**
698
696
  * Handles messages received from the sorting worker.
699
697
  * @param event The message event from the worker.
700
698
  */
701
- onWorkerMessage(s) {
699
+ onWorkerMessage(o) {
702
700
  if (!this.orderTexture || !this.orderTexture.image)
703
701
  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))
702
+ const { order: t, count: r } = o.data, n = this.orderTexture.image.data;
703
+ if (!(n instanceof Uint32Array))
706
704
  return console.error(
707
705
  "SplatSorter: Order texture data is not a Uint32Array!"
708
706
  );
709
- t.set(new Uint32Array(n)), this.orderTexture.needsUpdate = !0;
710
- const a = t.buffer.slice(0), c = { order: a };
707
+ n.set(new Uint32Array(t)), this.orderTexture.needsUpdate = !0;
708
+ const a = n.buffer.slice(0), c = { order: a };
711
709
  this.worker.postMessage(c, [a]), this.dispatchEvent({ type: "updated", count: r });
712
710
  }
713
711
  /**
@@ -716,82 +714,87 @@ class _e extends i.EventDispatcher {
716
714
  * @param centers A Float32Array containing the center position (x, y, z) for each splat.
717
715
  * @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
718
716
  */
719
- init(s, n, r) {
720
- if (!s || !(s.image.data instanceof Uint32Array))
717
+ init(o, t, r) {
718
+ if (!o || !(o.image.data instanceof Uint32Array))
721
719
  throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
722
- if (!n || n.length % 3 !== 0)
720
+ if (!t || t.length % 3 !== 0)
723
721
  throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
724
- if (s.image.data.length < n.length / 3)
722
+ if (o.image.data.length < t.length / 3)
725
723
  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();
724
+ const n = t.length / 3;
725
+ this.orderTexture = o, this.centers = t.slice();
728
726
  const a = this.orderTexture.image.data;
729
- for (let b = 0; b < t; b++) a[b] = b;
727
+ for (let b = 0; b < n; b++) a[b] = b;
730
728
  this.orderTexture.needsUpdate = !0;
731
- const c = a.buffer.slice(0), l = this.centers.buffer.slice(0), m = {
729
+ const c = a.buffer.slice(0), v = this.centers.buffer.slice(0), g = {
732
730
  order: c,
733
- centers: l
731
+ centers: v
734
732
  }, S = [
735
733
  c,
736
- l
734
+ v
737
735
  ];
738
736
  if (r) {
739
737
  this.chunks = r.slice();
740
738
  const b = this.chunks.buffer.slice(0);
741
- m.chunks = b, S.push(b);
739
+ g.chunks = b, S.push(b);
742
740
  }
743
- this.worker.postMessage(m, S);
741
+ this.worker.postMessage(g, S), queueMicrotask(() => {
742
+ this.dispatchEvent({
743
+ type: "updated",
744
+ count: n
745
+ });
746
+ });
744
747
  }
745
748
  /**
746
749
  * Applies an optional mapping to filter or reorder splats before sorting.
747
750
  * The sorter will only consider splats whose original indices are present in the mapping.
748
751
  * @param mapping A Uint32Array where each element is the *original* index of a splat to include, or null to reset mapping.
749
752
  */
750
- setMapping(s) {
753
+ setMapping(o) {
751
754
  if (!this.centers)
752
755
  return console.warn(
753
756
  "SplatSorter: Cannot set mapping before initialization."
754
757
  );
755
- let n;
758
+ let t;
756
759
  const r = [];
757
- if (!s) {
758
- const l = this.centers.buffer.slice(0);
759
- return n = {
760
- centers: l,
760
+ if (!o) {
761
+ const v = this.centers.buffer.slice(0);
762
+ return t = {
763
+ centers: v,
761
764
  mapping: null
762
- }, r.push(l), this.worker.postMessage(n, r);
765
+ }, r.push(v), this.worker.postMessage(t, r);
763
766
  }
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) {
767
+ const n = new Float32Array(o.length * 3);
768
+ for (let v = 0; v < o.length; v++) {
769
+ const g = o[v];
770
+ if (g * 3 + 2 >= this.centers.length) {
768
771
  console.warn(
769
- `SplatSorter: Mapping index ${m} out of bounds.`
772
+ `SplatSorter: Mapping index ${g} out of bounds.`
770
773
  );
771
774
  continue;
772
775
  }
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];
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];
775
778
  }
776
- const a = t.buffer.slice(0), c = s.buffer.slice(0);
777
- n = {
779
+ const a = n.buffer.slice(0), c = o.buffer.slice(0);
780
+ t = {
778
781
  centers: a,
779
782
  mapping: c
780
- }, r.push(a, c), this.worker.postMessage(n, r);
783
+ }, r.push(a, c), this.worker.postMessage(t, r);
781
784
  }
782
785
  /**
783
786
  * Updates the camera parameters used for sorting.
784
787
  * @param position The camera's position in the sorter's local coordinate space.
785
788
  * @param direction The camera's forward direction in the sorter's local coordinate space.
786
789
  */
787
- setCamera(s, n) {
788
- const r = this.lastCameraPosition.distanceToSquared(s) > 1e-7, t = this.lastCameraDirection.dot(n) < 0.9999;
789
- if (!r && !t)
790
+ setCamera(o, t) {
791
+ const r = this.lastCameraPosition.distanceToSquared(o) > 1e-7, n = this.lastCameraDirection.dot(t) < 0.9999;
792
+ if (!r && !n)
790
793
  return;
791
- this.lastCameraPosition.copy(s), this.lastCameraDirection.copy(n);
794
+ this.lastCameraPosition.copy(o), this.lastCameraDirection.copy(t);
792
795
  const a = {
793
- cameraPosition: { x: s.x, y: s.y, z: s.z },
794
- cameraDirection: { x: n.x, y: n.y, z: n.z }
796
+ cameraPosition: { x: o.x, y: o.y, z: o.z },
797
+ cameraDirection: { x: t.x, y: t.y, z: t.z }
795
798
  };
796
799
  this.worker.postMessage(a);
797
800
  }
@@ -807,165 +810,165 @@ class _e extends i.EventDispatcher {
807
810
  */
808
811
  createWorkerCode() {
809
812
  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;
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, E, O) => {
817
+ for (; F <= E; ) {
818
+ const A = E + F >> 1, w = O(A);
819
+ if (w > 0) F = A + 1;
820
+ else if (w < 0) E = A - 1;
821
+ else return A;
819
822
  }
820
- return ~D;
823
+ return ~F;
821
824
  }, $ = () => {
822
- if (!n || !r || !c || !l)
825
+ if (!t || !r || !c || !v)
823
826
  return;
824
827
  if (r.length === 0) {
825
- const f = {
826
- order: n.buffer,
828
+ const u = {
829
+ order: t.buffer,
827
830
  count: 0
828
831
  };
829
- self.postMessage(f, [n.buffer]), n = null;
832
+ self.postMessage(u, [t.buffer]), t = null;
830
833
  return;
831
834
  }
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)
835
+ const F = c.x, E = c.y, O = c.z, A = v.x, w = v.y, P = v.z, U = 1e-4, V = Math.abs(F - S.x) > U || Math.abs(E - S.y) > U || Math.abs(O - S.z) > U, y = Math.abs(A - b.x) > U || Math.abs(w - b.y) > U || Math.abs(P - b.z) > U;
836
+ if (!g && !V && !y)
834
837
  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);
838
+ g = !1, S.x = F, S.y = E, S.z = O, b.x = A, b.y = w, b.z = P;
839
+ let x = 1 / 0, C = -1 / 0;
840
+ for (let u = 0; u < 8; ++u) {
841
+ const z = u & 1 ? p.x : m.x, D = u & 2 ? p.y : m.y, l = u & 4 ? p.z : m.z, k = z * A + D * w + l * P;
842
+ x = Math.min(x, k), C = Math.max(C, k);
840
843
  }
841
- const R = r.length / 3, L = _ - y, o = (1 << Math.max(
844
+ const I = r.length / 3, N = C - x, s = (1 << Math.max(
842
845
  10,
843
- Math.min(20, Math.ceil(Math.log2(R / 4)))
846
+ Math.min(20, Math.ceil(Math.log2(I / 4)))
844
847
  )) + 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;
848
+ if ((!f || f.length !== I) && (f = new Uint32Array(I)), !_ || _.length !== s ? _ = new Uint32Array(s) : _.fill(0), N < 1e-7) {
849
+ for (let u = 0; u < I; ++u) f[u] = 0;
850
+ _[0] = I;
851
+ } else if (n && n.length > 0) {
852
+ const u = n.length / 6;
850
853
  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(
854
+ for (let l = 0; l < u; ++l) {
855
+ const k = l * 6, Y = n[k + 0], X = n[k + 1], ne = n[k + 2], Z = n[k + 3], J = Y * A + X * w + ne * P - x, oe = J - Z, ee = J + Z, ie = Math.max(
853
856
  0,
854
- Math.floor(oe * O / L)
857
+ Math.floor(oe * B / N)
855
858
  ), ce = Math.min(
856
- O,
857
- Math.ceil(ee * O / L)
859
+ B,
860
+ Math.ceil(ee * B / N)
858
861
  );
859
862
  for (let Q = ie; Q < ce; ++Q)
860
863
  q[Q]++;
861
864
  }
862
- let P = 0;
863
- for (let u = 0; u < O; ++u) P += q[u];
865
+ let z = 0;
866
+ for (let l = 0; l < B; ++l) z += q[l];
864
867
  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(
868
+ for (let l = 1; l < B; ++l)
869
+ j[l - 1] = q[l - 1] / z * s >>> 0, W[l] = W[l - 1] + j[l - 1];
870
+ j[B - 1] = q[B - 1] / z * s >>> 0;
871
+ const D = N / B;
872
+ for (let l = 0; l < I; ++l) {
873
+ const k = l * 3, Y = r[k + 0], X = r[k + 1], ne = r[k + 2], Z = Y * A + X * w + ne * P, oe = (C - Z) / D, ee = Math.max(
871
874
  0,
872
875
  Math.min(
873
- O - 1,
876
+ B - 1,
874
877
  Math.floor(oe)
875
878
  )
876
- ), ie = oe - ee, ce = W[ee] + j[ee] * ie >>> 0, Q = Math.min(ce, o - 1);
877
- h[u] = Q, T[Q]++;
879
+ ), ie = oe - ee, ce = W[ee] + j[ee] * ie >>> 0, Q = Math.min(ce, s - 1);
880
+ f[l] = Q, _[Q]++;
878
881
  }
879
882
  } 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]++;
883
+ const u = (s - 1) / N;
884
+ for (let z = 0; z < I; ++z) {
885
+ const D = z * 3, l = r[D + 0], k = r[D + 1], Y = r[D + 2], X = l * A + k * w + Y * P, Z = (C - X) * u >>> 0, J = Math.min(Z, s - 1);
886
+ f[z] = J, _[J]++;
884
887
  }
885
888
  }
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;
889
+ for (let u = 1; u < s; u++)
890
+ _[u] += _[u - 1];
891
+ for (let u = I - 1; u >= 0; u--) {
892
+ const z = f[u], D = --_[z];
893
+ t[D] = a ? a[u] : u;
891
894
  }
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)
895
+ const d = F * A + E * w + O * P, M = (u) => {
896
+ if (!t) return -1 / 0;
897
+ const z = t[u], D = z;
898
+ if (!r || D * 3 + 2 >= r.length)
896
899
  return -1 / 0;
897
- const u = F * 3;
898
- return r[u] * E + r[u + 1] * w + r[u + 2] * C - d;
900
+ const l = D * 3;
901
+ return r[l] * A + r[l + 1] * w + r[l + 2] * P - d;
899
902
  };
900
- let z = R;
901
- if (R > 0 && A(R - 1) < 0) {
902
- const f = H(
903
+ let R = I;
904
+ if (I > 0 && M(I - 1) < 0) {
905
+ const u = H(
903
906
  0,
904
- R - 1,
905
- A
907
+ I - 1,
908
+ M
906
909
  );
907
- z = f < 0 ? ~f : f;
910
+ R = u < 0 ? ~u : u;
908
911
  }
909
- const N = {
910
- order: n.buffer,
911
- count: z
912
+ const L = {
913
+ order: t.buffer,
914
+ count: R
912
915
  };
913
- self.postMessage(N, [n.buffer]), n = null;
916
+ self.postMessage(L, [t.buffer]), t = null;
914
917
  };
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
918
+ self.onmessage = (F) => {
919
+ const E = F.data;
920
+ E.order && (t = new Uint32Array(E.order));
921
+ let O = !1;
922
+ if (E.centers && (r = new Float32Array(E.centers), O = !0, g = !0), Object.prototype.hasOwnProperty.call(E, "mapping") && (a = E.mapping ? new Uint32Array(E.mapping) : null, g = !0), E.chunks) {
923
+ if (n = new Float32Array(E.chunks), n.length > 0 && n[3] > 0)
924
+ for (let A = 0; A < n.length / 6; ++A) {
925
+ const w = A * 6, P = n[w + 0], U = n[w + 1], V = n[w + 2], y = n[w + 3], x = n[w + 4], C = n[w + 5];
926
+ n[w + 0] = (P + y) * 0.5, n[w + 1] = (U + x) * 0.5, n[w + 2] = (V + C) * 0.5, n[w + 3] = Math.sqrt(
927
+ (y - P) ** 2 + (x - U) ** 2 + (C - V) ** 2
925
928
  ) * 0.5;
926
929
  }
927
- m = !0;
930
+ g = !0;
928
931
  }
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]);
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 A = 1; A < r.length / 3; A++) {
935
+ const w = A * 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]);
934
937
  }
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), $();
938
+ } else O && r && r.length === 0 && (p.x = m.x = p.y = m.y = p.z = m.z = 0);
939
+ E.cameraPosition && (c = E.cameraPosition), E.cameraDirection && (v = E.cameraDirection), $();
937
940
  };
938
941
  }).toString()})();`;
939
942
  }
940
943
  }
941
- const ke = (M, e) => {
942
- const s = de(M), n = de(e);
943
- return s | n << 16;
944
+ const ke = (T, e) => {
945
+ const o = de(T), t = de(e);
946
+ return o | t << 16;
944
947
  };
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);
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);
950
953
  }
951
- const Ie = new ArrayBuffer(4), pe = new DataView(Ie), Re = (M) => (pe.setUint32(0, M, !0), pe.getFloat32(0, !0));
954
+ const Ie = new ArrayBuffer(4), pe = new DataView(Ie), Re = (T) => (pe.setUint32(0, T, !0), pe.getFloat32(0, !0));
952
955
  class ze {
953
956
  /**
954
957
  * Create a new TextureManager for a set of splats
955
958
  * @param splatData The splat data to manage textures for
956
959
  */
957
960
  constructor(e) {
958
- g(this, "transformA");
961
+ h(this, "transformA");
959
962
  // position xyz and rotation quaternion y,z components
960
- g(this, "transformB");
963
+ h(this, "transformB");
961
964
  // rotation quaternion x and scale xyz
962
- g(this, "colorTexture");
965
+ h(this, "colorTexture");
963
966
  // 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);
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);
969
972
  }
970
973
  /**
971
974
  * Create the transform A texture (positions and quaternion w component)
@@ -973,17 +976,17 @@ class ze {
973
976
  * @returns DataTexture containing position data
974
977
  */
975
978
  createTransformATexture(e) {
976
- const s = e.numSplats, n = new Float32Array(
979
+ const o = e.numSplats, t = new Float32Array(
977
980
  this.textureWidth * this.textureHeight * 4
978
981
  );
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);
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);
984
987
  }
985
988
  const r = new i.DataTexture(
986
- n,
989
+ t,
987
990
  this.textureWidth,
988
991
  this.textureHeight,
989
992
  i.RGBAFormat,
@@ -998,15 +1001,15 @@ class ze {
998
1001
  * @returns DataTexture containing scale and rotation data
999
1002
  */
1000
1003
  createTransformBTexture(e) {
1001
- const s = e.numSplats, n = new Float32Array(
1004
+ const o = e.numSplats, t = new Float32Array(
1002
1005
  this.textureWidth * this.textureHeight * 4
1003
1006
  );
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];
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];
1007
1010
  }
1008
1011
  const r = new i.DataTexture(
1009
- n,
1012
+ t,
1010
1013
  this.textureWidth,
1011
1014
  this.textureHeight,
1012
1015
  i.RGBAFormat,
@@ -1020,15 +1023,15 @@ class ze {
1020
1023
  * @returns DataTexture containing color data
1021
1024
  */
1022
1025
  createColorTexture(e) {
1023
- const s = e.numSplats, n = new Float32Array(
1026
+ const o = e.numSplats, t = new Float32Array(
1024
1027
  this.textureWidth * this.textureHeight * 4
1025
1028
  );
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];
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];
1029
1032
  }
1030
1033
  const r = new i.DataTexture(
1031
- n,
1034
+ t,
1032
1035
  this.textureWidth,
1033
1036
  this.textureHeight,
1034
1037
  i.RGBAFormat,
@@ -1042,17 +1045,17 @@ class ze {
1042
1045
  * @returns DataTexture for storing order indices
1043
1046
  */
1044
1047
  createOrderTexture(e) {
1045
- const s = new Uint32Array(this.textureWidth * this.textureHeight);
1048
+ const o = new Uint32Array(this.textureWidth * this.textureHeight);
1046
1049
  for (let r = 0; r < e; r++)
1047
- s[r] = r;
1048
- const n = new i.DataTexture(
1049
- s,
1050
+ o[r] = r;
1051
+ const t = new i.DataTexture(
1052
+ o,
1050
1053
  this.textureWidth,
1051
1054
  this.textureHeight,
1052
1055
  i.RedIntegerFormat,
1053
1056
  i.UnsignedIntType
1054
1057
  );
1055
- return n.needsUpdate = !0, n;
1058
+ return t.needsUpdate = !0, t;
1056
1059
  }
1057
1060
  dispose() {
1058
1061
  this.transformA.dispose(), this.transformB.dispose(), this.colorTexture.dispose(), this.orderTexture.dispose();
@@ -1316,7 +1319,7 @@ void main(void) {
1316
1319
  vUv = clippedCornerOffset;
1317
1320
  }
1318
1321
  `
1319
- ), Oe = (
1322
+ ), Be = (
1320
1323
  /* glsl */
1321
1324
  `
1322
1325
  precision highp float;
@@ -1350,9 +1353,9 @@ void main(void) {
1350
1353
  }
1351
1354
  `
1352
1355
  );
1353
- class Be extends i.ShaderMaterial {
1356
+ class Oe extends i.ShaderMaterial {
1354
1357
  constructor(e = {}) {
1355
- const s = {
1358
+ const o = {
1356
1359
  // Textures (values set via methods)
1357
1360
  transformA: { value: null },
1358
1361
  transformB: { value: null },
@@ -1366,8 +1369,8 @@ class Be extends i.ShaderMaterial {
1366
1369
  };
1367
1370
  super({
1368
1371
  vertexShader: Pe,
1369
- fragmentShader: Oe,
1370
- uniforms: s,
1372
+ fragmentShader: Be,
1373
+ uniforms: o,
1371
1374
  transparent: !0,
1372
1375
  blending: i.CustomBlending,
1373
1376
  // Premultiplied alpha blending:
@@ -1398,8 +1401,8 @@ class Be extends i.ShaderMaterial {
1398
1401
  * @param width Viewport width
1399
1402
  * @param height Viewport height
1400
1403
  */
1401
- updateViewport(e, s) {
1402
- this.uniforms.viewport.value.set(e, s);
1404
+ updateViewport(e, o) {
1405
+ this.uniforms.viewport.value.set(e, o);
1403
1406
  }
1404
1407
  /**
1405
1408
  * Set transform texture A (positions)
@@ -1444,31 +1447,40 @@ const K = class K extends i.Mesh {
1444
1447
  * @param splatData The splat data to render
1445
1448
  * @param options Rendering options
1446
1449
  */
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();
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();
1460
1478
  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(
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(
1462
1480
  this.textureManager.orderTexture,
1463
1481
  this.splatData.centers,
1464
1482
  a ?? void 0
1465
- ), this.sorter.addEventListener(
1466
- "updated",
1467
- (c) => {
1468
- const l = c.count;
1469
- this.geometry.instanceCount = Math.ceil(l / K.INSTANCE_SIZE), this.material.setNumSplats(l);
1470
- }
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);
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);
1472
1484
  }
1473
1485
  /**
1474
1486
  * Creates the instanced geometry for rendering splats.
@@ -1476,8 +1488,8 @@ const K = class K extends i.Mesh {
1476
1488
  * @param instanceSize Number of splats per instance.
1477
1489
  * @returns InstancedBufferGeometry
1478
1490
  */
1479
- static createInstancedGeometry(s, n) {
1480
- const r = Math.ceil(s / n), t = new i.BufferGeometry(), a = new Float32Array([
1491
+ static createInstancedGeometry(o, t) {
1492
+ const r = Math.ceil(o / t), n = new i.BufferGeometry(), a = new Float32Array([
1481
1493
  // x, y, splat_index_in_instance
1482
1494
  -1,
1483
1495
  -1,
@@ -1491,23 +1503,23 @@ const K = class K extends i.Mesh {
1491
1503
  -1,
1492
1504
  1,
1493
1505
  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;
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;
1499
1511
  }
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;
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;
1504
1516
  }
1505
- t.setAttribute("position", new i.BufferAttribute(l, 3)), t.setIndex(new i.BufferAttribute(m, 1));
1517
+ n.setAttribute("position", new i.BufferAttribute(v, 3)), n.setIndex(new i.BufferAttribute(g, 1));
1506
1518
  const S = new i.InstancedBufferGeometry();
1507
- S.index = t.index, S.setAttribute("position", t.getAttribute("position"));
1519
+ S.index = n.index, S.setAttribute("position", n.getAttribute("position"));
1508
1520
  const b = new Uint32Array(r);
1509
1521
  for (let p = 0; p < r; p++)
1510
- b[p] = p * n;
1522
+ b[p] = p * t;
1511
1523
  return S.setAttribute("splatInstanceIndex", new i.InstancedBufferAttribute(b, 1, !1)), S.instanceCount = 0, S;
1512
1524
  }
1513
1525
  /**
@@ -1515,14 +1527,14 @@ const K = class K extends i.Mesh {
1515
1527
  * @returns Float32Array containing chunk data [minX, minY, minZ, maxX, maxY, maxZ] or null.
1516
1528
  */
1517
1529
  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
1530
+ const o = this.splatData.boundingBox;
1531
+ return o.min.x === 1 / 0 || o.max.x === -1 / 0 ? null : new Float32Array([
1532
+ o.min.x,
1533
+ o.min.y,
1534
+ o.min.z,
1535
+ o.max.x,
1536
+ o.max.y,
1537
+ o.max.z
1526
1538
  ]);
1527
1539
  }
1528
1540
  /**
@@ -1530,18 +1542,17 @@ const K = class K extends i.Mesh {
1530
1542
  * @param width Viewport width
1531
1543
  * @param height Viewport height
1532
1544
  */
1533
- updateViewport(s, n) {
1534
- this.material.updateViewport(s, n);
1545
+ updateViewport(o, t) {
1546
+ o === this._vpW && t === this._vpH || (this._vpW = o, this._vpH = t, this.material.updateViewport(o, t));
1535
1547
  }
1536
1548
  /**
1537
1549
  * Sorts splats based on camera position and direction.
1538
1550
  * @param camera The camera to sort against.
1539
1551
  */
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));
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));
1545
1556
  }
1546
1557
  /**
1547
1558
  * THREE.js hook called before rendering the object.
@@ -1552,31 +1563,22 @@ const K = class K extends i.Mesh {
1552
1563
  */
1553
1564
  // prettier-ignore
1554
1565
  // @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;
1560
- if (l.enabled && l.isPresenting) {
1561
- const m = l.getCamera().cameras[0].view;
1562
- m && (a = m.width, c = m.height);
1563
- }
1564
- this.updateViewport(a, c);
1566
+ onBeforeRender(o, t, r) {
1567
+ this.sort(r), o.getSize(this._size), this.updateViewport(this._size.x, this._size.y);
1565
1568
  }
1566
1569
  /**
1567
1570
  * Dispose of resources
1568
1571
  */
1569
1572
  dispose() {
1570
- this.sorter.dispose(), this.geometry.dispose(), this.material.dispose(), this.textureManager.dispose();
1573
+ this.sorter.removeEventListener("updated", this.onSorterUpdated), this.sorter.dispose(), this.geometry.dispose(), this.material.dispose(), this.textureManager.dispose();
1571
1574
  }
1572
1575
  };
1573
- // Cached inverse matrix
1574
1576
  /** Number of splats combined into a single instanced draw call. */
1575
- g(K, "INSTANCE_SIZE", 128);
1577
+ h(K, "INSTANCE_SIZE", 128);
1576
1578
  let ae = K;
1577
- const Fe = Symbol.for("@speridlabs/visus/SplatMesh");
1579
+ const De = Symbol.for("@speridlabs/visus/SplatMesh");
1578
1580
  try {
1579
- Object.defineProperty(ae.prototype, Fe, {
1581
+ Object.defineProperty(ae.prototype, De, {
1580
1582
  value: !0,
1581
1583
  configurable: !1,
1582
1584
  enumerable: !1,
@@ -1586,20 +1588,22 @@ try {
1586
1588
  console.warn("Couldn't define Visus SplatMesh symbol");
1587
1589
  }
1588
1590
  const je = ({
1589
- plyUrl: M,
1590
- splatOptions: e = {},
1591
- ...s
1591
+ plyUrl: T,
1592
+ debug: e = !1,
1593
+ splatOptions: o = {},
1594
+ ...t
1592
1595
  }) => {
1593
- const n = ve(null), r = be(Ee, M), t = ge(
1594
- () => new ae(r, e || {}),
1595
- [r, e]
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]
1596
1600
  );
1597
1601
  return we(() => () => {
1598
- typeof (t == null ? void 0 : t.dispose) == "function" && t.dispose();
1599
- }, [t]), /* @__PURE__ */ Me.jsx("primitive", { ref: n, object: t, ...s });
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 });
1600
1604
  };
1601
1605
  export {
1602
- Ee as PlyLoader,
1606
+ Ce as PlyLoader,
1603
1607
  je as Splat,
1604
1608
  ae as SplatMesh
1605
1609
  };