@speridlabs/visus 1.0.3 → 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/main.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var lt = Object.defineProperty;
2
- var ht = (A, t, s) => t in A ? lt(A, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : A[t] = s;
3
- var c = (A, t, s) => ht(A, typeof t != "symbol" ? t + "" : t, s);
2
+ var ht = (I, t, s) => t in I ? lt(I, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : I[t] = s;
3
+ var c = (I, t, s) => ht(I, typeof t != "symbol" ? t + "" : t, s);
4
4
  import * as n from "three";
5
5
  class et {
6
6
  constructor() {
@@ -316,11 +316,11 @@ class dt extends n.EventDispatcher {
316
316
  let e = null, r = null, o = null, i = null, a = null, d = null, f = !1;
317
317
  const v = { x: 0, y: 0, z: 0 }, g = { x: 0, y: 0, z: 0 }, p = { x: 0, y: 0, z: 0 }, h = { x: 0, y: 0, z: 0 };
318
318
  let l = null, b = null;
319
- const T = 32, O = new Array(T).fill(0), q = new Array(T).fill(0), E = new Array(T).fill(0), R = (k, C, F) => {
320
- for (; k <= C; ) {
321
- const M = C + k >> 1, m = F(M);
319
+ const _ = 32, O = new Array(_).fill(0), q = new Array(_).fill(0), E = new Array(_).fill(0), R = (k, S, F) => {
320
+ for (; k <= S; ) {
321
+ const M = S + k >> 1, m = F(M);
322
322
  if (m > 0) k = M + 1;
323
- else if (m < 0) C = M - 1;
323
+ else if (m < 0) S = M - 1;
324
324
  else return M;
325
325
  }
326
326
  return ~k;
@@ -335,79 +335,79 @@ class dt extends n.EventDispatcher {
335
335
  self.postMessage(y, [e.buffer]), e = null;
336
336
  return;
337
337
  }
338
- const k = a.x, C = a.y, F = a.z, M = d.x, m = d.y, B = d.z, V = 1e-4, P = Math.abs(k - v.x) > V || Math.abs(C - v.y) > V || Math.abs(F - v.z) > V, x = Math.abs(M - g.x) > V || Math.abs(m - g.y) > V || Math.abs(B - g.z) > V;
338
+ const k = a.x, S = a.y, F = a.z, M = d.x, m = d.y, C = d.z, V = 1e-4, P = Math.abs(k - v.x) > V || Math.abs(S - v.y) > V || Math.abs(F - v.z) > V, x = Math.abs(M - g.x) > V || Math.abs(m - g.y) > V || Math.abs(C - g.z) > V;
339
339
  if (!f && !P && !x)
340
340
  return;
341
- f = !1, v.x = k, v.y = C, v.z = F, g.x = M, g.y = m, g.z = B;
342
- let u = 1 / 0, S = -1 / 0;
341
+ f = !1, v.x = k, v.y = S, v.z = F, g.x = M, g.y = m, g.z = C;
342
+ let u = 1 / 0, z = -1 / 0;
343
343
  for (let y = 0; y < 8; ++y) {
344
- const _ = y & 1 ? p.x : h.x, U = y & 2 ? p.y : h.y, w = y & 4 ? p.z : h.z, D = _ * M + U * m + w * B;
345
- u = Math.min(u, D), S = Math.max(S, D);
344
+ const B = y & 1 ? p.x : h.x, U = y & 2 ? p.y : h.y, w = y & 4 ? p.z : h.z, D = B * M + U * m + w * C;
345
+ u = Math.min(u, D), z = Math.max(z, D);
346
346
  }
347
- const I = r.length / 3, L = S - u, z = (1 << Math.max(
347
+ const T = r.length / 3, L = z - u, A = (1 << Math.max(
348
348
  10,
349
- Math.min(20, Math.ceil(Math.log2(I / 4)))
349
+ Math.min(20, Math.ceil(Math.log2(T / 4)))
350
350
  )) + 1;
351
- if ((!l || l.length !== I) && (l = new Uint32Array(I)), !b || b.length !== z ? b = new Uint32Array(z) : b.fill(0), L < 1e-7) {
352
- for (let y = 0; y < I; ++y) l[y] = 0;
353
- b[0] = I;
351
+ if ((!l || l.length !== T) && (l = new Uint32Array(T)), !b || b.length !== A ? b = new Uint32Array(A) : b.fill(0), L < 1e-7) {
352
+ for (let y = 0; y < T; ++y) l[y] = 0;
353
+ b[0] = T;
354
354
  } else if (o && o.length > 0) {
355
355
  const y = o.length / 6;
356
356
  O.fill(0);
357
357
  for (let w = 0; w < y; ++w) {
358
- const D = w * 6, X = o[D + 0], Z = o[D + 1], $ = o[D + 2], H = o[D + 3], Y = X * M + Z * m + $ * B - u, J = Y - H, G = Y + H, Q = Math.max(
358
+ const D = w * 6, X = o[D + 0], Z = o[D + 1], $ = o[D + 2], H = o[D + 3], Y = X * M + Z * m + $ * C - u, J = Y - H, G = Y + H, Q = Math.max(
359
359
  0,
360
- Math.floor(J * T / L)
360
+ Math.floor(J * _ / L)
361
361
  ), tt = Math.min(
362
- T,
363
- Math.ceil(G * T / L)
362
+ _,
363
+ Math.ceil(G * _ / L)
364
364
  );
365
365
  for (let N = Q; N < tt; ++N)
366
366
  O[N]++;
367
367
  }
368
- let _ = 0;
369
- for (let w = 0; w < T; ++w) _ += O[w];
368
+ let B = 0;
369
+ for (let w = 0; w < _; ++w) B += O[w];
370
370
  E[0] = 0, q[0] = 0;
371
- for (let w = 1; w < T; ++w)
372
- E[w - 1] = O[w - 1] / _ * z >>> 0, q[w] = q[w - 1] + E[w - 1];
373
- E[T - 1] = O[T - 1] / _ * z >>> 0;
374
- const U = L / T;
375
- for (let w = 0; w < I; ++w) {
376
- const D = w * 3, X = r[D + 0], Z = r[D + 1], $ = r[D + 2], H = X * M + Z * m + $ * B, J = (S - H) / U, G = Math.max(
371
+ for (let w = 1; w < _; ++w)
372
+ E[w - 1] = O[w - 1] / B * A >>> 0, q[w] = q[w - 1] + E[w - 1];
373
+ E[_ - 1] = O[_ - 1] / B * A >>> 0;
374
+ const U = L / _;
375
+ for (let w = 0; w < T; ++w) {
376
+ const D = w * 3, X = r[D + 0], Z = r[D + 1], $ = r[D + 2], H = X * M + Z * m + $ * C, J = (z - H) / U, G = Math.max(
377
377
  0,
378
378
  Math.min(
379
- T - 1,
379
+ _ - 1,
380
380
  Math.floor(J)
381
381
  )
382
- ), Q = J - G, tt = q[G] + E[G] * Q >>> 0, N = Math.min(tt, z - 1);
382
+ ), Q = J - G, tt = q[G] + E[G] * Q >>> 0, N = Math.min(tt, A - 1);
383
383
  l[w] = N, b[N]++;
384
384
  }
385
385
  } else {
386
- const y = (z - 1) / L;
387
- for (let _ = 0; _ < I; ++_) {
388
- const U = _ * 3, w = r[U + 0], D = r[U + 1], X = r[U + 2], Z = w * M + D * m + X * B, H = (S - Z) * y >>> 0, Y = Math.min(H, z - 1);
389
- l[_] = Y, b[Y]++;
386
+ const y = (A - 1) / L;
387
+ for (let B = 0; B < T; ++B) {
388
+ const U = B * 3, w = r[U + 0], D = r[U + 1], X = r[U + 2], Z = w * M + D * m + X * C, H = (z - Z) * y >>> 0, Y = Math.min(H, A - 1);
389
+ l[B] = Y, b[Y]++;
390
390
  }
391
391
  }
392
- for (let y = 1; y < z; y++)
392
+ for (let y = 1; y < A; y++)
393
393
  b[y] += b[y - 1];
394
- for (let y = I - 1; y >= 0; y--) {
395
- const _ = l[y], U = --b[_];
394
+ for (let y = T - 1; y >= 0; y--) {
395
+ const B = l[y], U = --b[B];
396
396
  e[U] = i ? i[y] : y;
397
397
  }
398
- const at = k * M + C * m + F * B, rt = (y) => {
398
+ const at = k * M + S * m + F * C, rt = (y) => {
399
399
  if (!e) return -1 / 0;
400
- const _ = e[y], U = _;
400
+ const B = e[y], U = B;
401
401
  if (!r || U * 3 + 2 >= r.length)
402
402
  return -1 / 0;
403
403
  const w = U * 3;
404
- return r[w] * M + r[w + 1] * m + r[w + 2] * B - at;
404
+ return r[w] * M + r[w + 1] * m + r[w + 2] * C - at;
405
405
  };
406
- let st = I;
407
- if (I > 0 && rt(I - 1) < 0) {
406
+ let st = T;
407
+ if (T > 0 && rt(T - 1) < 0) {
408
408
  const y = R(
409
409
  0,
410
- I - 1,
410
+ T - 1,
411
411
  rt
412
412
  );
413
413
  st = y < 0 ? ~y : y;
@@ -419,15 +419,15 @@ class dt extends n.EventDispatcher {
419
419
  self.postMessage(ct, [e.buffer]), e = null;
420
420
  };
421
421
  self.onmessage = (k) => {
422
- const C = k.data;
423
- C.order && (e = new Uint32Array(C.order));
422
+ const S = k.data;
423
+ S.order && (e = new Uint32Array(S.order));
424
424
  let F = !1;
425
- if (C.centers && (r = new Float32Array(C.centers), F = !0, f = !0), Object.prototype.hasOwnProperty.call(C, "mapping") && (i = C.mapping ? new Uint32Array(C.mapping) : null, f = !0), C.chunks) {
426
- if (o = new Float32Array(C.chunks), o.length > 0 && o[3] > 0)
425
+ if (S.centers && (r = new Float32Array(S.centers), F = !0, f = !0), Object.prototype.hasOwnProperty.call(S, "mapping") && (i = S.mapping ? new Uint32Array(S.mapping) : null, f = !0), S.chunks) {
426
+ if (o = new Float32Array(S.chunks), o.length > 0 && o[3] > 0)
427
427
  for (let M = 0; M < o.length / 6; ++M) {
428
- const m = M * 6, B = o[m + 0], V = o[m + 1], P = o[m + 2], x = o[m + 3], u = o[m + 4], S = o[m + 5];
429
- o[m + 0] = (B + x) * 0.5, o[m + 1] = (V + u) * 0.5, o[m + 2] = (P + S) * 0.5, o[m + 3] = Math.sqrt(
430
- (x - B) ** 2 + (u - V) ** 2 + (S - P) ** 2
428
+ const m = M * 6, C = o[m + 0], V = o[m + 1], P = o[m + 2], x = o[m + 3], u = o[m + 4], z = o[m + 5];
429
+ o[m + 0] = (C + x) * 0.5, o[m + 1] = (V + u) * 0.5, o[m + 2] = (P + z) * 0.5, o[m + 3] = Math.sqrt(
430
+ (x - C) ** 2 + (u - V) ** 2 + (z - P) ** 2
431
431
  ) * 0.5;
432
432
  }
433
433
  f = !0;
@@ -439,22 +439,22 @@ class dt extends n.EventDispatcher {
439
439
  p.x = Math.min(p.x, r[m + 0]), h.x = Math.max(h.x, r[m + 0]), p.y = Math.min(p.y, r[m + 1]), h.y = Math.max(h.y, r[m + 1]), p.z = Math.min(p.z, r[m + 2]), h.z = Math.max(h.z, r[m + 2]);
440
440
  }
441
441
  } else F && r && r.length === 0 && (p.x = h.x = p.y = h.y = p.z = h.z = 0);
442
- C.cameraPosition && (a = C.cameraPosition), C.cameraDirection && (d = C.cameraDirection), W();
442
+ S.cameraPosition && (a = S.cameraPosition), S.cameraDirection && (d = S.cameraDirection), W();
443
443
  };
444
444
  }).toString()})();`;
445
445
  }
446
446
  }
447
- const pt = (A, t) => {
448
- const s = ot(A), e = ot(t);
447
+ const pt = (I, t) => {
448
+ const s = ot(I), e = ot(t);
449
449
  return s | e << 16;
450
450
  };
451
- function ot(A) {
452
- const t = new Float32Array([A]), e = new Int32Array(t.buffer)[0];
451
+ function ot(I) {
452
+ const t = new Float32Array([I]), e = new Int32Array(t.buffer)[0];
453
453
  let r = e >> 16 & 32768, o = e >> 12 & 2047;
454
454
  const i = e >> 23 & 255;
455
455
  return i < 103 ? r : i > 142 ? (r |= 31744, r |= (i === 255 ? 0 : 1) && e & 8388607, r) : i < 113 ? (o |= 2048, r |= (o >> 114 - i) + (o >> 113 - i & 1), r) : (r |= i - 112 << 10 | o >> 1, r += o & 1, r);
456
456
  }
457
- const ft = new ArrayBuffer(4), nt = new DataView(ft), mt = (A) => (nt.setUint32(0, A, !0), nt.getFloat32(0, !0));
457
+ const ft = new ArrayBuffer(4), nt = new DataView(ft), mt = (I) => (nt.setUint32(0, I, !0), nt.getFloat32(0, !0));
458
458
  class xt {
459
459
  /**
460
460
  * Create a new TextureManager for a set of splats
@@ -1146,8 +1146,8 @@ end_header
1146
1146
  let i = 0;
1147
1147
  for (let x = 0; x < e.length - o.length; x++) {
1148
1148
  let u = !0;
1149
- for (let S = 0; S < o.length; S++)
1150
- if (e[x + S] !== o.charCodeAt(S)) {
1149
+ for (let z = 0; z < o.length; z++)
1150
+ if (e[x + z] !== o.charCodeAt(z)) {
1151
1151
  u = !1;
1152
1152
  break;
1153
1153
  }
@@ -1164,15 +1164,15 @@ end_header
1164
1164
  for (let x = 1; x < d.length; x++) {
1165
1165
  const u = d[x].trim();
1166
1166
  if (u === "" || u === "end_header") continue;
1167
- const S = u.split(" ");
1168
- switch (S[0]) {
1167
+ const z = u.split(" ");
1168
+ switch (z[0]) {
1169
1169
  case "format":
1170
- v = S[1];
1170
+ v = z[1];
1171
1171
  break;
1172
1172
  case "element":
1173
1173
  f.push({
1174
- name: S[1],
1175
- count: parseInt(S[2], 10),
1174
+ name: z[1],
1175
+ count: parseInt(z[2], 10),
1176
1176
  properties: []
1177
1177
  });
1178
1178
  break;
@@ -1182,8 +1182,8 @@ end_header
1182
1182
  "Invalid PLY file: Property without element"
1183
1183
  );
1184
1184
  f[f.length - 1].properties.push({
1185
- type: S[1],
1186
- name: S[2],
1185
+ type: z[1],
1186
+ name: z[2],
1187
1187
  storage: null
1188
1188
  });
1189
1189
  break;
@@ -1196,7 +1196,7 @@ end_header
1196
1196
  throw new Error("Invalid PLY file: No vertex element found");
1197
1197
  const p = new ut(g.count), h = new DataView(t);
1198
1198
  let l = i;
1199
- const b = (x) => g.properties.findIndex((u) => u.name === x), T = b("x"), O = b("y"), q = b("z"), E = [
1199
+ const b = (x) => g.properties.findIndex((u) => u.name === x), _ = b("x"), O = b("y"), q = b("z"), E = [
1200
1200
  b("rot_0"),
1201
1201
  b("rot_1"),
1202
1202
  b("rot_2"),
@@ -1211,7 +1211,7 @@ end_header
1211
1211
  b("f_dc_2")
1212
1212
  ], k = b("opacity");
1213
1213
  if ([
1214
- T,
1214
+ _,
1215
1215
  O,
1216
1216
  q,
1217
1217
  ...E,
@@ -1224,53 +1224,53 @@ end_header
1224
1224
  if (x > 0) return 1 / (1 + Math.exp(-x));
1225
1225
  const u = Math.exp(x);
1226
1226
  return u / (1 + u);
1227
- }, m = new n.Vector3(), B = new n.Quaternion(), V = new n.Vector3(), P = new n.Color();
1227
+ }, m = new n.Vector3(), C = new n.Quaternion(), V = new n.Vector3(), P = new n.Color();
1228
1228
  for (let x = 0; x < g.count; x++) {
1229
1229
  const u = [];
1230
- for (let I = 0; I < g.properties.length; I++) {
1231
- const K = g.properties[I].type;
1232
- let z;
1230
+ for (let T = 0; T < g.properties.length; T++) {
1231
+ const K = g.properties[T].type;
1232
+ let A;
1233
1233
  switch (K) {
1234
1234
  case "char":
1235
- z = h.getInt8(l), l += 1;
1235
+ A = h.getInt8(l), l += 1;
1236
1236
  break;
1237
1237
  case "uchar":
1238
- z = h.getUint8(l), l += 1;
1238
+ A = h.getUint8(l), l += 1;
1239
1239
  break;
1240
1240
  case "short":
1241
- z = h.getInt16(l, !0), l += 2;
1241
+ A = h.getInt16(l, !0), l += 2;
1242
1242
  break;
1243
1243
  case "ushort":
1244
- z = h.getUint16(l, !0), l += 2;
1244
+ A = h.getUint16(l, !0), l += 2;
1245
1245
  break;
1246
1246
  case "int":
1247
- z = h.getInt32(l, !0), l += 4;
1247
+ A = h.getInt32(l, !0), l += 4;
1248
1248
  break;
1249
1249
  case "uint":
1250
- z = h.getUint32(l, !0), l += 4;
1250
+ A = h.getUint32(l, !0), l += 4;
1251
1251
  break;
1252
1252
  case "float":
1253
- z = h.getFloat32(l, !0), l += 4;
1253
+ A = h.getFloat32(l, !0), l += 4;
1254
1254
  break;
1255
1255
  case "double":
1256
- z = h.getFloat64(l, !0), l += 8;
1256
+ A = h.getFloat64(l, !0), l += 8;
1257
1257
  break;
1258
1258
  default:
1259
1259
  throw new Error(`Unsupported property type: ${K}`);
1260
1260
  }
1261
- u.push(z);
1261
+ u.push(A);
1262
1262
  }
1263
1263
  m.set(
1264
- u[T],
1264
+ u[_],
1265
1265
  u[O],
1266
1266
  u[q]
1267
- ), B.set(
1267
+ ), C.set(
1268
1268
  u[E[1]],
1269
1269
  // PLY stores rot 1,2,3,0 (x,y,z,w)
1270
1270
  u[E[2]],
1271
1271
  u[E[3]],
1272
1272
  u[E[0]]
1273
- ).normalize(), V.set(
1273
+ ).normalize(), C.w < 0 && (C.x = -C.x, C.y = -C.y, C.z = -C.z, C.w = -C.w), V.set(
1274
1274
  u[R[0]],
1275
1275
  // Read directly assuming it's log scale
1276
1276
  u[R[1]],
@@ -1280,15 +1280,15 @@ end_header
1280
1280
  0.5 + u[W[1]] * F,
1281
1281
  0.5 + u[W[2]] * F
1282
1282
  ), P.r = Math.max(0, Math.min(1, P.r)), P.g = Math.max(0, Math.min(1, P.g)), P.b = Math.max(0, Math.min(1, P.b));
1283
- const S = M(u[k]);
1283
+ const z = M(u[k]);
1284
1284
  p.setSplat(
1285
1285
  x,
1286
1286
  m,
1287
- B,
1287
+ C,
1288
1288
  V,
1289
1289
  // Pass log scale directly
1290
1290
  P,
1291
- S
1291
+ z
1292
1292
  );
1293
1293
  }
1294
1294
  return p.calculateBoundingBox(), p;
package/dist/main.umd.js CHANGED
@@ -1,5 +1,5 @@
1
- (function(z,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],P):(z=typeof globalThis<"u"?globalThis:z||self,P(z.Visus={},z.THREE))})(this,function(z,P){"use strict";var St=Object.defineProperty;var Ct=(z,P,L)=>P in z?St(z,P,{enumerable:!0,configurable:!0,writable:!0,value:L}):z[P]=L;var c=(z,P,L)=>Ct(z,typeof P!="symbol"?P+"":P,L);if(typeof THREE>"u")throw new Error(`Visus UMD build requires Three.js as a global "THREE".
2
- Please include <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"><\/script> before loading visus/main.umd.js`);function L(I){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const s in I)if(s!=="default"){const e=Object.getOwnPropertyDescriptor(I,s);Object.defineProperty(t,s,e.get?e:{enumerable:!0,get:()=>I[s]})}}return t.default=I,Object.freeze(t)}const o=L(P);class Q{constructor(){c(this,"min",new o.Vector3(1/0,1/0,1/0));c(this,"max",new o.Vector3(-1/0,-1/0,-1/0));c(this,"center",new o.Vector3);c(this,"halfExtents",new o.Vector3)}reset(){this.min.set(1/0,1/0,1/0),this.max.set(-1/0,-1/0,-1/0),this.center.set(0,0,0),this.halfExtents.set(0,0,0)}expandByPoint(t){this.min.x=Math.min(this.min.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.min.z=Math.min(this.min.z,t.z),this.max.x=Math.max(this.max.x,t.x),this.max.y=Math.max(this.max.y,t.y),this.max.z=Math.max(this.max.z,t.z),this.updateDerived()}expandByBox(t){this.min.x=Math.min(this.min.x,t.min.x),this.min.y=Math.min(this.min.y,t.min.y),this.min.z=Math.min(this.min.z,t.min.z),this.max.x=Math.max(this.max.x,t.max.x),this.max.y=Math.max(this.max.y,t.max.y),this.max.z=Math.max(this.max.z,t.max.z),this.updateDerived()}updateDerived(){this.center.addVectors(this.min,this.max).multiplyScalar(.5),this.halfExtents.subVectors(this.max,this.min).multiplyScalar(.5)}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}toBox3(){return new o.Box3().set(this.min,this.max)}clone(){const t=new Q;return t.min.copy(this.min),t.max.copy(this.max),t.center.copy(this.center),t.halfExtents.copy(this.halfExtents),t}}class it{constructor(t=0){c(this,"numSplats",0);c(this,"positions");c(this,"rotations");c(this,"scales");c(this,"colors");c(this,"opacities");c(this,"centers");c(this,"boundingBox",new Q);this.numSplats=t,this.allocateBuffers(t)}allocateBuffers(t){this.positions=new Float32Array(t*3),this.rotations=new Float32Array(t*4),this.scales=new Float32Array(t*3),this.colors=new Float32Array(t*3),this.opacities=new Float32Array(t),this.centers=new Float32Array(t*3)}setSplat(t,s,e,r,n,i){if(t>=this.numSplats)throw new Error(`Splat index out of bounds: ${t} >= ${this.numSplats}`);const a=t*3,d=t*4,p=t*3,v=t*3;this.positions[a]=s.x,this.positions[a+1]=s.y,this.positions[a+2]=s.z,this.rotations[d]=e.x,this.rotations[d+1]=e.y,this.rotations[d+2]=e.z,this.rotations[d+3]=e.w,this.scales[p]=r.x,this.scales[p+1]=r.y,this.scales[p+2]=r.z,this.colors[v]=n.r,this.colors[v+1]=n.g,this.colors[v+2]=n.b,this.opacities[t]=i,this.centers[a]=s.x,this.centers[a+1]=s.y,this.centers[a+2]=s.z}getSplat(t){if(t>=this.numSplats)throw new Error(`Splat index out of bounds: ${t} >= ${this.numSplats}`);const s=t*3,e=t*4,r=t*3,n=t*3;return{position:new o.Vector3(this.positions[s],this.positions[s+1],this.positions[s+2]),rotation:new o.Quaternion(this.rotations[e],this.rotations[e+1],this.rotations[e+2],this.rotations[e+3]),scale:new o.Vector3(Math.exp(this.scales[r]),Math.exp(this.scales[r+1]),Math.exp(this.scales[r+2])),color:new o.Color(this.colors[n],this.colors[n+1],this.colors[n+2]),opacity:this.opacities[t]}}calculateBoundingBox(){this.boundingBox.reset();const t=new o.Vector3;for(let s=0;s<this.numSplats;s++){const e=s*3;t.set(this.positions[e],this.positions[e+1],this.positions[e+2]),this.boundingBox.expandByPoint(t)}return this.boundingBox}createDebugGeometry(){const t=new o.BufferGeometry;t.setAttribute("position",new o.BufferAttribute(this.positions,3));const s=new Float32Array(this.numSplats*3),e=new o.Quaternion,r=new o.Euler;for(let n=0;n<this.numSplats;n++){const i=n*4,a=n*3;e.set(this.rotations[i],this.rotations[i+1],this.rotations[i+2],this.rotations[i+3]),r.setFromQuaternion(e),s[a]=r.x,s[a+1]=r.y,s[a+2]=r.z}return t.setAttribute("rotation",new o.BufferAttribute(s,3)),t.setAttribute("scale",new o.BufferAttribute(this.scales,3)),t.setAttribute("color",new o.BufferAttribute(this.colors,3)),t.setAttribute("opacity",new o.BufferAttribute(this.opacities,1)),t}}class at extends o.EventDispatcher{constructor(){super();c(this,"worker");c(this,"centers",null);c(this,"orderTexture",null);c(this,"chunks",null);c(this,"lastCameraPosition",new o.Vector3);c(this,"lastCameraDirection",new o.Vector3);const s=this.createWorkerCode(),e=new Blob([s],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(e)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(s){if(!this.orderTexture||!this.orderTexture.image)return console.error("SplatSorter: Order texture not initialized!");const{order:e,count:r}=s.data,n=this.orderTexture.image.data;if(!(n instanceof Uint32Array))return console.error("SplatSorter: Order texture data is not a Uint32Array!");n.set(new Uint32Array(e)),this.orderTexture.needsUpdate=!0;const i=n.buffer.slice(0),a={order:i};this.worker.postMessage(a,[i]),this.dispatchEvent({type:"updated",count:r})}init(s,e,r){if(!s||!(s.image.data instanceof Uint32Array))throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");if(!e||e.length%3!==0)throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");if(s.image.data.length<e.length/3)throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");const n=e.length/3;this.orderTexture=s,this.centers=e.slice();const i=this.orderTexture.image.data;for(let g=0;g<n;g++)i[g]=g;this.orderTexture.needsUpdate=!0;const a=i.buffer.slice(0),d=this.centers.buffer.slice(0),p={order:a,centers:d},v=[a,d];if(r){this.chunks=r.slice();const g=this.chunks.buffer.slice(0);p.chunks=g,v.push(g)}this.worker.postMessage(p,v),queueMicrotask(()=>{this.dispatchEvent({type:"updated",count:n})})}setMapping(s){if(!this.centers)return console.warn("SplatSorter: Cannot set mapping before initialization.");let e;const r=[];if(!s){const d=this.centers.buffer.slice(0);return e={centers:d,mapping:null},r.push(d),this.worker.postMessage(e,r)}const n=new Float32Array(s.length*3);for(let d=0;d<s.length;d++){const p=s[d];if(p*3+2>=this.centers.length){console.warn(`SplatSorter: Mapping index ${p} out of bounds.`);continue}const v=p*3,g=d*3;n[g+0]=this.centers[v+0],n[g+1]=this.centers[v+1],n[g+2]=this.centers[v+2]}const i=n.buffer.slice(0),a=s.buffer.slice(0);e={centers:i,mapping:a},r.push(i,a),this.worker.postMessage(e,r)}setCamera(s,e){const r=this.lastCameraPosition.distanceToSquared(s)>1e-7,n=this.lastCameraDirection.dot(e)<.9999;if(!r&&!n)return;this.lastCameraPosition.copy(s),this.lastCameraDirection.copy(e);const i={cameraPosition:{x:s.x,y:s.y,z:s.z},cameraDirection:{x:e.x,y:e.y,z:e.z}};this.worker.postMessage(i)}dispose(){this.worker&&this.worker.terminate(),this.orderTexture=null,this.centers=null,this.chunks=null}createWorkerCode(){return`(${(function(){let e=null,r=null,n=null,i=null,a=null,d=null,p=!1;const v={x:0,y:0,z:0},g={x:0,y:0,z:0},f={x:0,y:0,z:0},h={x:0,y:0,z:0};let l=null,b=null;const _=32,q=new Array(_).fill(0),W=new Array(_).fill(0),R=new Array(_).fill(0),j=(D,S,F)=>{for(;D<=S;){const M=S+D>>1,m=F(M);if(m>0)D=M+1;else if(m<0)S=M-1;else return M}return~D},N=()=>{if(!e||!r||!a||!d)return;if(r.length===0){const y={order:e.buffer,count:0};self.postMessage(y,[e.buffer]),e=null;return}const D=a.x,S=a.y,F=a.z,M=d.x,m=d.y,k=d.z,U=1e-4,E=Math.abs(D-v.x)>U||Math.abs(S-v.y)>U||Math.abs(F-v.z)>U,x=Math.abs(M-g.x)>U||Math.abs(m-g.y)>U||Math.abs(k-g.z)>U;if(!p&&!E&&!x)return;p=!1,v.x=D,v.y=S,v.z=F,g.x=M,g.y=m,g.z=k;let u=1/0,C=-1/0;for(let y=0;y<8;++y){const B=y&1?f.x:h.x,O=y&2?f.y:h.y,w=y&4?f.z:h.z,V=B*M+O*m+w*k;u=Math.min(u,V),C=Math.max(C,V)}const T=r.length/3,Y=C-u,A=(1<<Math.max(10,Math.min(20,Math.ceil(Math.log2(T/4)))))+1;if((!l||l.length!==T)&&(l=new Uint32Array(T)),!b||b.length!==A?b=new Uint32Array(A):b.fill(0),Y<1e-7){for(let y=0;y<T;++y)l[y]=0;b[0]=T}else if(n&&n.length>0){const y=n.length/6;q.fill(0);for(let w=0;w<y;++w){const V=w*6,$=n[V+0],J=n[V+1],tt=n[V+2],X=n[V+3],Z=$*M+J*m+tt*k-u,et=Z-X,K=Z+X,nt=Math.max(0,Math.floor(et*_/Y)),ot=Math.min(_,Math.ceil(K*_/Y));for(let G=nt;G<ot;++G)q[G]++}let B=0;for(let w=0;w<_;++w)B+=q[w];R[0]=0,W[0]=0;for(let w=1;w<_;++w)R[w-1]=q[w-1]/B*A>>>0,W[w]=W[w-1]+R[w-1];R[_-1]=q[_-1]/B*A>>>0;const O=Y/_;for(let w=0;w<T;++w){const V=w*3,$=r[V+0],J=r[V+1],tt=r[V+2],X=$*M+J*m+tt*k,et=(C-X)/O,K=Math.max(0,Math.min(_-1,Math.floor(et))),nt=et-K,ot=W[K]+R[K]*nt>>>0,G=Math.min(ot,A-1);l[w]=G,b[G]++}}else{const y=(A-1)/Y;for(let B=0;B<T;++B){const O=B*3,w=r[O+0],V=r[O+1],$=r[O+2],J=w*M+V*m+$*k,X=(C-J)*y>>>0,Z=Math.min(X,A-1);l[B]=Z,b[Z]++}}for(let y=1;y<A;y++)b[y]+=b[y-1];for(let y=T-1;y>=0;y--){const B=l[y],O=--b[B];e[O]=i?i[y]:y}const bt=D*M+S*m+F*k,dt=y=>{if(!e)return-1/0;const B=e[y],O=B;if(!r||O*3+2>=r.length)return-1/0;const w=O*3;return r[w]*M+r[w+1]*m+r[w+2]*k-bt};let ft=T;if(T>0&&dt(T-1)<0){const y=j(0,T-1,dt);ft=y<0?~y:y}const Mt={order:e.buffer,count:ft};self.postMessage(Mt,[e.buffer]),e=null};self.onmessage=D=>{const S=D.data;S.order&&(e=new Uint32Array(S.order));let F=!1;if(S.centers&&(r=new Float32Array(S.centers),F=!0,p=!0),Object.prototype.hasOwnProperty.call(S,"mapping")&&(i=S.mapping?new Uint32Array(S.mapping):null,p=!0),S.chunks){if(n=new Float32Array(S.chunks),n.length>0&&n[3]>0)for(let M=0;M<n.length/6;++M){const m=M*6,k=n[m+0],U=n[m+1],E=n[m+2],x=n[m+3],u=n[m+4],C=n[m+5];n[m+0]=(k+x)*.5,n[m+1]=(U+u)*.5,n[m+2]=(E+C)*.5,n[m+3]=Math.sqrt((x-k)**2+(u-U)**2+(C-E)**2)*.5}p=!0}if(F&&r&&r.length>0){f.x=h.x=r[0],f.y=h.y=r[1],f.z=h.z=r[2];for(let M=1;M<r.length/3;M++){const m=M*3;f.x=Math.min(f.x,r[m+0]),h.x=Math.max(h.x,r[m+0]),f.y=Math.min(f.y,r[m+1]),h.y=Math.max(h.y,r[m+1]),f.z=Math.min(f.z,r[m+2]),h.z=Math.max(h.z,r[m+2])}}else F&&r&&r.length===0&&(f.x=h.x=f.y=h.y=f.z=h.z=0);S.cameraPosition&&(a=S.cameraPosition),S.cameraDirection&&(d=S.cameraDirection),N()}}).toString()})();`}}const pt=(I,t)=>{const s=ct(I),e=ct(t);return s|e<<16};function ct(I){const t=new Float32Array([I]),e=new Int32Array(t.buffer)[0];let r=e>>16&32768,n=e>>12&2047;const i=e>>23&255;return i<103?r:i>142?(r|=31744,r|=(i===255?0:1)&&e&8388607,r):i<113?(n|=2048,r|=(n>>114-i)+(n>>113-i&1),r):(r|=i-112<<10|n>>1,r+=n&1,r)}const mt=new ArrayBuffer(4),lt=new DataView(mt),xt=I=>(lt.setUint32(0,I,!0),lt.getFloat32(0,!0));class ht{constructor(t){c(this,"transformA");c(this,"transformB");c(this,"colorTexture");c(this,"orderTexture");c(this,"textureWidth");c(this,"textureHeight");const s=t.numSplats;this.textureWidth=Math.ceil(Math.sqrt(s)),this.textureHeight=Math.ceil(s/this.textureWidth),this.transformA=this.createTransformATexture(t),this.transformB=this.createTransformBTexture(t),this.colorTexture=this.createColorTexture(t),this.orderTexture=this.createOrderTexture(s)}createTransformATexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3,d=n*4;e[i]=t.positions[a],e[i+1]=t.positions[a+1],e[i+2]=t.positions[a+2];const p=t.rotations[d+0],v=t.rotations[d+1],g=pt(p,v);e[i+3]=xt(g)}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r.magFilter=o.NearestFilter,r.minFilter=o.NearestFilter,r}createTransformBTexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3,d=n*4;e[i]=t.scales[a],e[i+1]=t.scales[a+1],e[i+2]=t.scales[a+2],e[i+3]=t.rotations[d+2]}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r.magFilter=o.NearestFilter,r.minFilter=o.NearestFilter,r}createColorTexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3;e[i]=t.colors[a],e[i+1]=t.colors[a+1],e[i+2]=t.colors[a+2],e[i+3]=t.opacities[n]}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r}createOrderTexture(t){const s=new Uint32Array(this.textureWidth*this.textureHeight);for(let r=0;r<t;r++)s[r]=r;const e=new o.DataTexture(s,this.textureWidth,this.textureHeight,o.RedIntegerFormat,o.UnsignedIntType);return e.needsUpdate=!0,e}dispose(){this.transformA.dispose(),this.transformB.dispose(),this.colorTexture.dispose(),this.orderTexture.dispose()}}const yt=`
1
+ (function(A,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],P):(A=typeof globalThis<"u"?globalThis:A||self,P(A.Visus={},A.THREE))})(this,function(A,P){"use strict";var St=Object.defineProperty;var Ct=(A,P,L)=>P in A?St(A,P,{enumerable:!0,configurable:!0,writable:!0,value:L}):A[P]=L;var c=(A,P,L)=>Ct(A,typeof P!="symbol"?P+"":P,L);if(typeof THREE>"u")throw new Error(`Visus UMD build requires Three.js as a global "THREE".
2
+ Please include <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"><\/script> before loading visus/main.umd.js`);function L(T){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(T){for(const s in T)if(s!=="default"){const e=Object.getOwnPropertyDescriptor(T,s);Object.defineProperty(t,s,e.get?e:{enumerable:!0,get:()=>T[s]})}}return t.default=T,Object.freeze(t)}const o=L(P);class Q{constructor(){c(this,"min",new o.Vector3(1/0,1/0,1/0));c(this,"max",new o.Vector3(-1/0,-1/0,-1/0));c(this,"center",new o.Vector3);c(this,"halfExtents",new o.Vector3)}reset(){this.min.set(1/0,1/0,1/0),this.max.set(-1/0,-1/0,-1/0),this.center.set(0,0,0),this.halfExtents.set(0,0,0)}expandByPoint(t){this.min.x=Math.min(this.min.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.min.z=Math.min(this.min.z,t.z),this.max.x=Math.max(this.max.x,t.x),this.max.y=Math.max(this.max.y,t.y),this.max.z=Math.max(this.max.z,t.z),this.updateDerived()}expandByBox(t){this.min.x=Math.min(this.min.x,t.min.x),this.min.y=Math.min(this.min.y,t.min.y),this.min.z=Math.min(this.min.z,t.min.z),this.max.x=Math.max(this.max.x,t.max.x),this.max.y=Math.max(this.max.y,t.max.y),this.max.z=Math.max(this.max.z,t.max.z),this.updateDerived()}updateDerived(){this.center.addVectors(this.min,this.max).multiplyScalar(.5),this.halfExtents.subVectors(this.max,this.min).multiplyScalar(.5)}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}toBox3(){return new o.Box3().set(this.min,this.max)}clone(){const t=new Q;return t.min.copy(this.min),t.max.copy(this.max),t.center.copy(this.center),t.halfExtents.copy(this.halfExtents),t}}class it{constructor(t=0){c(this,"numSplats",0);c(this,"positions");c(this,"rotations");c(this,"scales");c(this,"colors");c(this,"opacities");c(this,"centers");c(this,"boundingBox",new Q);this.numSplats=t,this.allocateBuffers(t)}allocateBuffers(t){this.positions=new Float32Array(t*3),this.rotations=new Float32Array(t*4),this.scales=new Float32Array(t*3),this.colors=new Float32Array(t*3),this.opacities=new Float32Array(t),this.centers=new Float32Array(t*3)}setSplat(t,s,e,r,n,i){if(t>=this.numSplats)throw new Error(`Splat index out of bounds: ${t} >= ${this.numSplats}`);const a=t*3,d=t*4,p=t*3,v=t*3;this.positions[a]=s.x,this.positions[a+1]=s.y,this.positions[a+2]=s.z,this.rotations[d]=e.x,this.rotations[d+1]=e.y,this.rotations[d+2]=e.z,this.rotations[d+3]=e.w,this.scales[p]=r.x,this.scales[p+1]=r.y,this.scales[p+2]=r.z,this.colors[v]=n.r,this.colors[v+1]=n.g,this.colors[v+2]=n.b,this.opacities[t]=i,this.centers[a]=s.x,this.centers[a+1]=s.y,this.centers[a+2]=s.z}getSplat(t){if(t>=this.numSplats)throw new Error(`Splat index out of bounds: ${t} >= ${this.numSplats}`);const s=t*3,e=t*4,r=t*3,n=t*3;return{position:new o.Vector3(this.positions[s],this.positions[s+1],this.positions[s+2]),rotation:new o.Quaternion(this.rotations[e],this.rotations[e+1],this.rotations[e+2],this.rotations[e+3]),scale:new o.Vector3(Math.exp(this.scales[r]),Math.exp(this.scales[r+1]),Math.exp(this.scales[r+2])),color:new o.Color(this.colors[n],this.colors[n+1],this.colors[n+2]),opacity:this.opacities[t]}}calculateBoundingBox(){this.boundingBox.reset();const t=new o.Vector3;for(let s=0;s<this.numSplats;s++){const e=s*3;t.set(this.positions[e],this.positions[e+1],this.positions[e+2]),this.boundingBox.expandByPoint(t)}return this.boundingBox}createDebugGeometry(){const t=new o.BufferGeometry;t.setAttribute("position",new o.BufferAttribute(this.positions,3));const s=new Float32Array(this.numSplats*3),e=new o.Quaternion,r=new o.Euler;for(let n=0;n<this.numSplats;n++){const i=n*4,a=n*3;e.set(this.rotations[i],this.rotations[i+1],this.rotations[i+2],this.rotations[i+3]),r.setFromQuaternion(e),s[a]=r.x,s[a+1]=r.y,s[a+2]=r.z}return t.setAttribute("rotation",new o.BufferAttribute(s,3)),t.setAttribute("scale",new o.BufferAttribute(this.scales,3)),t.setAttribute("color",new o.BufferAttribute(this.colors,3)),t.setAttribute("opacity",new o.BufferAttribute(this.opacities,1)),t}}class at extends o.EventDispatcher{constructor(){super();c(this,"worker");c(this,"centers",null);c(this,"orderTexture",null);c(this,"chunks",null);c(this,"lastCameraPosition",new o.Vector3);c(this,"lastCameraDirection",new o.Vector3);const s=this.createWorkerCode(),e=new Blob([s],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(e)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(s){if(!this.orderTexture||!this.orderTexture.image)return console.error("SplatSorter: Order texture not initialized!");const{order:e,count:r}=s.data,n=this.orderTexture.image.data;if(!(n instanceof Uint32Array))return console.error("SplatSorter: Order texture data is not a Uint32Array!");n.set(new Uint32Array(e)),this.orderTexture.needsUpdate=!0;const i=n.buffer.slice(0),a={order:i};this.worker.postMessage(a,[i]),this.dispatchEvent({type:"updated",count:r})}init(s,e,r){if(!s||!(s.image.data instanceof Uint32Array))throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");if(!e||e.length%3!==0)throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");if(s.image.data.length<e.length/3)throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");const n=e.length/3;this.orderTexture=s,this.centers=e.slice();const i=this.orderTexture.image.data;for(let g=0;g<n;g++)i[g]=g;this.orderTexture.needsUpdate=!0;const a=i.buffer.slice(0),d=this.centers.buffer.slice(0),p={order:a,centers:d},v=[a,d];if(r){this.chunks=r.slice();const g=this.chunks.buffer.slice(0);p.chunks=g,v.push(g)}this.worker.postMessage(p,v),queueMicrotask(()=>{this.dispatchEvent({type:"updated",count:n})})}setMapping(s){if(!this.centers)return console.warn("SplatSorter: Cannot set mapping before initialization.");let e;const r=[];if(!s){const d=this.centers.buffer.slice(0);return e={centers:d,mapping:null},r.push(d),this.worker.postMessage(e,r)}const n=new Float32Array(s.length*3);for(let d=0;d<s.length;d++){const p=s[d];if(p*3+2>=this.centers.length){console.warn(`SplatSorter: Mapping index ${p} out of bounds.`);continue}const v=p*3,g=d*3;n[g+0]=this.centers[v+0],n[g+1]=this.centers[v+1],n[g+2]=this.centers[v+2]}const i=n.buffer.slice(0),a=s.buffer.slice(0);e={centers:i,mapping:a},r.push(i,a),this.worker.postMessage(e,r)}setCamera(s,e){const r=this.lastCameraPosition.distanceToSquared(s)>1e-7,n=this.lastCameraDirection.dot(e)<.9999;if(!r&&!n)return;this.lastCameraPosition.copy(s),this.lastCameraDirection.copy(e);const i={cameraPosition:{x:s.x,y:s.y,z:s.z},cameraDirection:{x:e.x,y:e.y,z:e.z}};this.worker.postMessage(i)}dispose(){this.worker&&this.worker.terminate(),this.orderTexture=null,this.centers=null,this.chunks=null}createWorkerCode(){return`(${(function(){let e=null,r=null,n=null,i=null,a=null,d=null,p=!1;const v={x:0,y:0,z:0},g={x:0,y:0,z:0},f={x:0,y:0,z:0},h={x:0,y:0,z:0};let l=null,b=null;const B=32,q=new Array(B).fill(0),W=new Array(B).fill(0),R=new Array(B).fill(0),j=(D,C,F)=>{for(;D<=C;){const M=C+D>>1,m=F(M);if(m>0)D=M+1;else if(m<0)C=M-1;else return M}return~D},N=()=>{if(!e||!r||!a||!d)return;if(r.length===0){const y={order:e.buffer,count:0};self.postMessage(y,[e.buffer]),e=null;return}const D=a.x,C=a.y,F=a.z,M=d.x,m=d.y,S=d.z,U=1e-4,E=Math.abs(D-v.x)>U||Math.abs(C-v.y)>U||Math.abs(F-v.z)>U,x=Math.abs(M-g.x)>U||Math.abs(m-g.y)>U||Math.abs(S-g.z)>U;if(!p&&!E&&!x)return;p=!1,v.x=D,v.y=C,v.z=F,g.x=M,g.y=m,g.z=S;let u=1/0,z=-1/0;for(let y=0;y<8;++y){const k=y&1?f.x:h.x,O=y&2?f.y:h.y,w=y&4?f.z:h.z,V=k*M+O*m+w*S;u=Math.min(u,V),z=Math.max(z,V)}const _=r.length/3,Y=z-u,I=(1<<Math.max(10,Math.min(20,Math.ceil(Math.log2(_/4)))))+1;if((!l||l.length!==_)&&(l=new Uint32Array(_)),!b||b.length!==I?b=new Uint32Array(I):b.fill(0),Y<1e-7){for(let y=0;y<_;++y)l[y]=0;b[0]=_}else if(n&&n.length>0){const y=n.length/6;q.fill(0);for(let w=0;w<y;++w){const V=w*6,$=n[V+0],J=n[V+1],tt=n[V+2],X=n[V+3],Z=$*M+J*m+tt*S-u,et=Z-X,K=Z+X,nt=Math.max(0,Math.floor(et*B/Y)),ot=Math.min(B,Math.ceil(K*B/Y));for(let G=nt;G<ot;++G)q[G]++}let k=0;for(let w=0;w<B;++w)k+=q[w];R[0]=0,W[0]=0;for(let w=1;w<B;++w)R[w-1]=q[w-1]/k*I>>>0,W[w]=W[w-1]+R[w-1];R[B-1]=q[B-1]/k*I>>>0;const O=Y/B;for(let w=0;w<_;++w){const V=w*3,$=r[V+0],J=r[V+1],tt=r[V+2],X=$*M+J*m+tt*S,et=(z-X)/O,K=Math.max(0,Math.min(B-1,Math.floor(et))),nt=et-K,ot=W[K]+R[K]*nt>>>0,G=Math.min(ot,I-1);l[w]=G,b[G]++}}else{const y=(I-1)/Y;for(let k=0;k<_;++k){const O=k*3,w=r[O+0],V=r[O+1],$=r[O+2],J=w*M+V*m+$*S,X=(z-J)*y>>>0,Z=Math.min(X,I-1);l[k]=Z,b[Z]++}}for(let y=1;y<I;y++)b[y]+=b[y-1];for(let y=_-1;y>=0;y--){const k=l[y],O=--b[k];e[O]=i?i[y]:y}const bt=D*M+C*m+F*S,dt=y=>{if(!e)return-1/0;const k=e[y],O=k;if(!r||O*3+2>=r.length)return-1/0;const w=O*3;return r[w]*M+r[w+1]*m+r[w+2]*S-bt};let ft=_;if(_>0&&dt(_-1)<0){const y=j(0,_-1,dt);ft=y<0?~y:y}const Mt={order:e.buffer,count:ft};self.postMessage(Mt,[e.buffer]),e=null};self.onmessage=D=>{const C=D.data;C.order&&(e=new Uint32Array(C.order));let F=!1;if(C.centers&&(r=new Float32Array(C.centers),F=!0,p=!0),Object.prototype.hasOwnProperty.call(C,"mapping")&&(i=C.mapping?new Uint32Array(C.mapping):null,p=!0),C.chunks){if(n=new Float32Array(C.chunks),n.length>0&&n[3]>0)for(let M=0;M<n.length/6;++M){const m=M*6,S=n[m+0],U=n[m+1],E=n[m+2],x=n[m+3],u=n[m+4],z=n[m+5];n[m+0]=(S+x)*.5,n[m+1]=(U+u)*.5,n[m+2]=(E+z)*.5,n[m+3]=Math.sqrt((x-S)**2+(u-U)**2+(z-E)**2)*.5}p=!0}if(F&&r&&r.length>0){f.x=h.x=r[0],f.y=h.y=r[1],f.z=h.z=r[2];for(let M=1;M<r.length/3;M++){const m=M*3;f.x=Math.min(f.x,r[m+0]),h.x=Math.max(h.x,r[m+0]),f.y=Math.min(f.y,r[m+1]),h.y=Math.max(h.y,r[m+1]),f.z=Math.min(f.z,r[m+2]),h.z=Math.max(h.z,r[m+2])}}else F&&r&&r.length===0&&(f.x=h.x=f.y=h.y=f.z=h.z=0);C.cameraPosition&&(a=C.cameraPosition),C.cameraDirection&&(d=C.cameraDirection),N()}}).toString()})();`}}const pt=(T,t)=>{const s=ct(T),e=ct(t);return s|e<<16};function ct(T){const t=new Float32Array([T]),e=new Int32Array(t.buffer)[0];let r=e>>16&32768,n=e>>12&2047;const i=e>>23&255;return i<103?r:i>142?(r|=31744,r|=(i===255?0:1)&&e&8388607,r):i<113?(n|=2048,r|=(n>>114-i)+(n>>113-i&1),r):(r|=i-112<<10|n>>1,r+=n&1,r)}const mt=new ArrayBuffer(4),lt=new DataView(mt),xt=T=>(lt.setUint32(0,T,!0),lt.getFloat32(0,!0));class ht{constructor(t){c(this,"transformA");c(this,"transformB");c(this,"colorTexture");c(this,"orderTexture");c(this,"textureWidth");c(this,"textureHeight");const s=t.numSplats;this.textureWidth=Math.ceil(Math.sqrt(s)),this.textureHeight=Math.ceil(s/this.textureWidth),this.transformA=this.createTransformATexture(t),this.transformB=this.createTransformBTexture(t),this.colorTexture=this.createColorTexture(t),this.orderTexture=this.createOrderTexture(s)}createTransformATexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3,d=n*4;e[i]=t.positions[a],e[i+1]=t.positions[a+1],e[i+2]=t.positions[a+2];const p=t.rotations[d+0],v=t.rotations[d+1],g=pt(p,v);e[i+3]=xt(g)}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r.magFilter=o.NearestFilter,r.minFilter=o.NearestFilter,r}createTransformBTexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3,d=n*4;e[i]=t.scales[a],e[i+1]=t.scales[a+1],e[i+2]=t.scales[a+2],e[i+3]=t.rotations[d+2]}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r.magFilter=o.NearestFilter,r.minFilter=o.NearestFilter,r}createColorTexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3;e[i]=t.colors[a],e[i+1]=t.colors[a+1],e[i+2]=t.colors[a+2],e[i+3]=t.opacities[n]}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r}createOrderTexture(t){const s=new Uint32Array(this.textureWidth*this.textureHeight);for(let r=0;r<t;r++)s[r]=r;const e=new o.DataTexture(s,this.textureWidth,this.textureHeight,o.RedIntegerFormat,o.UnsignedIntType);return e.needsUpdate=!0,e}dispose(){this.transformA.dispose(),this.transformB.dispose(),this.colorTexture.dispose(),this.orderTexture.dispose()}}const yt=`
3
3
  precision highp float;
4
4
  precision highp int;
5
5
  precision highp usampler2D;
@@ -286,5 +286,5 @@ void main(void) {
286
286
  }
287
287
  `;class ut extends o.ShaderMaterial{constructor(t={}){const s={transformA:{value:null},transformB:{value:null},splatColor:{value:null},splatOrder:{value:null},viewport:{value:new o.Vector2(1,1)},numSplats:{value:0}};super({vertexShader:yt,fragmentShader:gt,uniforms:s,transparent:!0,blending:o.CustomBlending,blendSrc:o.OneFactor,blendDst:o.OneMinusSrcAlphaFactor,blendSrcAlpha:o.OneFactor,blendDstAlpha:o.OneMinusSrcAlphaFactor,blendEquation:o.AddEquation,blendEquationAlpha:o.AddEquation,depthTest:!0,depthWrite:!1,side:o.DoubleSide,alphaTest:t.alphaTest!==void 0?t.alphaTest:0,toneMapped:t.toneMapped!==void 0?t.toneMapped:!1}),t.alphaHash&&(this.alphaHash=!0,this.depthWrite=!0,this.blending=o.NoBlending)}updateViewport(t,s){this.uniforms.viewport.value.set(t,s)}setTransformA(t){this.uniforms.transformA.value=t}setTransformB(t){this.uniforms.transformB.value=t}setColorTexture(t){this.uniforms.splatColor.value=t}setOrderTexture(t){this.uniforms.splatOrder.value=t}setNumSplats(t){this.uniforms.numSplats.value=t}}const H=class H extends o.Mesh{constructor(s,e={}){const r=new ut(e),n=H.createInstancedGeometry(s.numSplats,H.INSTANCE_SIZE);super(n,r);c(this,"sorter");c(this,"splatData");c(this,"options");c(this,"textureManager");c(this,"material");c(this,"geometry");c(this,"lastCameraPositionLocal",new o.Vector3);c(this,"lastCameraDirectionLocal",new o.Vector3);c(this,"invModelMatrix",new o.Matrix4);c(this,"_vpW",-1);c(this,"_vpH",-1);c(this,"_size",new o.Vector2);c(this,"_camPosW",new o.Vector3);c(this,"_camDirW",new o.Vector3);c(this,"_camPosL",new o.Vector3);c(this,"_camDirL",new o.Vector3);c(this,"onSorterUpdated",s=>{const e=s.count;this.geometry.instanceCount=Math.ceil(e/H.INSTANCE_SIZE),this.material.setNumSplats(e)});this.geometry=n,this.material=r,this.splatData=s,this.frustumCulled=!1,this.options={autoSort:!0,...e},this.textureManager=new ht(s),this.sorter=new at;let i=this.createChunks()||void 0;i===null&&console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."),i=void 0,this.sorter.addEventListener("updated",this.onSorterUpdated),this.sorter.init(this.textureManager.orderTexture,this.splatData.centers,i??void 0),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 o.Sphere,this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere)}static createInstancedGeometry(s,e){const r=Math.ceil(s/e),n=new o.BufferGeometry,i=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),a=new Uint16Array([0,1,2,0,2,3]),d=new Float32Array(4*3*e);for(let f=0;f<e;f++){const h=f*4*3;for(let l=0;l<4;l++)d[h+l*3+0]=i[l*3+0],d[h+l*3+1]=i[l*3+1],d[h+l*3+2]=f}const p=new Uint32Array(6*e);for(let f=0;f<e;f++){const h=f*6,l=f*4;p[h+0]=a[0]+l,p[h+1]=a[1]+l,p[h+2]=a[2]+l,p[h+3]=a[3]+l,p[h+4]=a[4]+l,p[h+5]=a[5]+l}n.setAttribute("position",new o.BufferAttribute(d,3)),n.setIndex(new o.BufferAttribute(p,1));const v=new o.InstancedBufferGeometry;v.index=n.index,v.setAttribute("position",n.getAttribute("position"));const g=new Uint32Array(r);for(let f=0;f<r;f++)g[f]=f*e;return v.setAttribute("splatInstanceIndex",new o.InstancedBufferAttribute(g,1,!1)),v.instanceCount=0,v}createChunks(){const s=this.splatData.boundingBox;return s.min.x===1/0||s.max.x===-1/0?null:new Float32Array([s.min.x,s.min.y,s.min.z,s.max.x,s.max.y,s.max.z])}updateViewport(s,e){s===this._vpW&&e===this._vpH||(this._vpW=s,this._vpH=e,this.material.updateViewport(s,e))}sort(s){s.getWorldPosition(this._camPosW),s.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);const e=this.lastCameraPositionLocal.distanceToSquared(this._camPosL)>1e-6,r=this.lastCameraDirectionLocal.dot(this._camDirL)<.999;this.options.autoSort&&(e||r)&&(this.lastCameraPositionLocal.copy(this._camPosL),this.lastCameraDirectionLocal.copy(this._camDirL),this.sorter.setCamera(this._camPosL,this._camDirL))}onBeforeRender(s,e,r){this.sort(r),s.getSize(this._size),this.updateViewport(this._size.x,this._size.y)}dispose(){this.sorter.removeEventListener("updated",this.onSorterUpdated),this.sorter.dispose(),this.geometry.dispose(),this.material.dispose(),this.textureManager.dispose()}};c(H,"INSTANCE_SIZE",128);let rt=H;class vt extends o.Loader{load(t,s,e,r){const n=new o.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(t,i=>{try{if(s){const a=this.parse(i);s(a)}}catch(a){r?r(a):console.error(a),this.manager.itemError(t)}},e,r)}loadAsync(t,s){return new Promise((e,r)=>{const n=new o.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(t,i=>{try{const a=this.parse(i);e(a)}catch(a){r(a),this.manager.itemError(t)}},s,i=>{r(i),this.manager.itemError(t)})})}parse(t){const s=new TextDecoder,e=new Uint8Array(t),r=[112,108,121,10],n=`
288
288
  end_header
289
- `;for(let x=0;x<r.length;x++)if(e[x]!==r[x])throw new Error("Invalid PLY file: Missing magic bytes");let i=0;for(let x=0;x<e.length-n.length;x++){let u=!0;for(let C=0;C<n.length;C++)if(e[x+C]!==n.charCodeAt(C)){u=!1;break}if(u){i=x+n.length;break}}if(i===0)throw new Error("Invalid PLY file: Could not find end of header");const d=s.decode(e.subarray(0,i)).split(`
290
- `),p=[];let v=null;for(let x=1;x<d.length;x++){const u=d[x].trim();if(u===""||u==="end_header")continue;const C=u.split(" ");switch(C[0]){case"format":v=C[1];break;case"element":p.push({name:C[1],count:parseInt(C[2],10),properties:[]});break;case"property":if(p.length===0)throw new Error("Invalid PLY file: Property without element");p[p.length-1].properties.push({type:C[1],name:C[2],storage:null});break}}if(v!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${v}`);const g=p.find(x=>x.name==="vertex");if(!g)throw new Error("Invalid PLY file: No vertex element found");const f=new it(g.count),h=new DataView(t);let l=i;const b=x=>g.properties.findIndex(u=>u.name===x),_=b("x"),q=b("y"),W=b("z"),R=[b("rot_0"),b("rot_1"),b("rot_2"),b("rot_3")],j=[b("scale_0"),b("scale_1"),b("scale_2")],N=[b("f_dc_0"),b("f_dc_1"),b("f_dc_2")],D=b("opacity");if([_,q,W,...R,...j,...N,D].some(x=>x===-1))throw new Error("Invalid PLY file: Missing required properties");const F=.28209479177387814,M=x=>{if(x>0)return 1/(1+Math.exp(-x));const u=Math.exp(x);return u/(1+u)},m=new o.Vector3,k=new o.Quaternion,U=new o.Vector3,E=new o.Color;for(let x=0;x<g.count;x++){const u=[];for(let T=0;T<g.properties.length;T++){const st=g.properties[T].type;let A;switch(st){case"char":A=h.getInt8(l),l+=1;break;case"uchar":A=h.getUint8(l),l+=1;break;case"short":A=h.getInt16(l,!0),l+=2;break;case"ushort":A=h.getUint16(l,!0),l+=2;break;case"int":A=h.getInt32(l,!0),l+=4;break;case"uint":A=h.getUint32(l,!0),l+=4;break;case"float":A=h.getFloat32(l,!0),l+=4;break;case"double":A=h.getFloat64(l,!0),l+=8;break;default:throw new Error(`Unsupported property type: ${st}`)}u.push(A)}m.set(u[_],u[q],u[W]),k.set(u[R[1]],u[R[2]],u[R[3]],u[R[0]]).normalize(),U.set(u[j[0]],u[j[1]],u[j[2]]),E.set(.5+u[N[0]]*F,.5+u[N[1]]*F,.5+u[N[2]]*F),E.r=Math.max(0,Math.min(1,E.r)),E.g=Math.max(0,Math.min(1,E.g)),E.b=Math.max(0,Math.min(1,E.b));const C=M(u[D]);f.setSplat(x,m,k,U,E,C)}return f.calculateBoundingBox(),f}}const wt="0.3.0";z.BoundingBox=Q,z.PlyLoader=vt,z.SplatData=it,z.SplatMaterial=ut,z.SplatMesh=rt,z.SplatSorter=at,z.TextureManager=ht,z.VERSION=wt,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});
289
+ `;for(let x=0;x<r.length;x++)if(e[x]!==r[x])throw new Error("Invalid PLY file: Missing magic bytes");let i=0;for(let x=0;x<e.length-n.length;x++){let u=!0;for(let z=0;z<n.length;z++)if(e[x+z]!==n.charCodeAt(z)){u=!1;break}if(u){i=x+n.length;break}}if(i===0)throw new Error("Invalid PLY file: Could not find end of header");const d=s.decode(e.subarray(0,i)).split(`
290
+ `),p=[];let v=null;for(let x=1;x<d.length;x++){const u=d[x].trim();if(u===""||u==="end_header")continue;const z=u.split(" ");switch(z[0]){case"format":v=z[1];break;case"element":p.push({name:z[1],count:parseInt(z[2],10),properties:[]});break;case"property":if(p.length===0)throw new Error("Invalid PLY file: Property without element");p[p.length-1].properties.push({type:z[1],name:z[2],storage:null});break}}if(v!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${v}`);const g=p.find(x=>x.name==="vertex");if(!g)throw new Error("Invalid PLY file: No vertex element found");const f=new it(g.count),h=new DataView(t);let l=i;const b=x=>g.properties.findIndex(u=>u.name===x),B=b("x"),q=b("y"),W=b("z"),R=[b("rot_0"),b("rot_1"),b("rot_2"),b("rot_3")],j=[b("scale_0"),b("scale_1"),b("scale_2")],N=[b("f_dc_0"),b("f_dc_1"),b("f_dc_2")],D=b("opacity");if([B,q,W,...R,...j,...N,D].some(x=>x===-1))throw new Error("Invalid PLY file: Missing required properties");const F=.28209479177387814,M=x=>{if(x>0)return 1/(1+Math.exp(-x));const u=Math.exp(x);return u/(1+u)},m=new o.Vector3,S=new o.Quaternion,U=new o.Vector3,E=new o.Color;for(let x=0;x<g.count;x++){const u=[];for(let _=0;_<g.properties.length;_++){const st=g.properties[_].type;let I;switch(st){case"char":I=h.getInt8(l),l+=1;break;case"uchar":I=h.getUint8(l),l+=1;break;case"short":I=h.getInt16(l,!0),l+=2;break;case"ushort":I=h.getUint16(l,!0),l+=2;break;case"int":I=h.getInt32(l,!0),l+=4;break;case"uint":I=h.getUint32(l,!0),l+=4;break;case"float":I=h.getFloat32(l,!0),l+=4;break;case"double":I=h.getFloat64(l,!0),l+=8;break;default:throw new Error(`Unsupported property type: ${st}`)}u.push(I)}m.set(u[B],u[q],u[W]),S.set(u[R[1]],u[R[2]],u[R[3]],u[R[0]]).normalize(),S.w<0&&(S.x=-S.x,S.y=-S.y,S.z=-S.z,S.w=-S.w),U.set(u[j[0]],u[j[1]],u[j[2]]),E.set(.5+u[N[0]]*F,.5+u[N[1]]*F,.5+u[N[2]]*F),E.r=Math.max(0,Math.min(1,E.r)),E.g=Math.max(0,Math.min(1,E.g)),E.b=Math.max(0,Math.min(1,E.b));const z=M(u[D]);f.setSplat(x,m,S,U,E,z)}return f.calculateBoundingBox(),f}}const wt="0.3.0";A.BoundingBox=Q,A.PlyLoader=vt,A.SplatData=it,A.SplatMaterial=ut,A.SplatMesh=rt,A.SplatSorter=at,A.TextureManager=ht,A.VERSION=wt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});