@speridlabs/visus 1.0.0 → 1.0.1
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.umd.js +26 -13
- package/dist/react.es.js +317 -299
- package/package.json +1 -1
- package/dist/main.d.ts +0 -320
- package/dist/main.es.js +0 -1292
package/dist/react.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
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";
|
|
5
|
+
import { useLoader as be } from "@react-three/fiber";
|
|
6
6
|
import * as i from "three";
|
|
7
7
|
var se = { exports: {} }, te = {};
|
|
8
8
|
/**
|
|
@@ -15,23 +15,23 @@ var se = { exports: {} }, te = {};
|
|
|
15
15
|
* LICENSE file in the root directory of this source tree.
|
|
16
16
|
*/
|
|
17
17
|
var ue;
|
|
18
|
-
function
|
|
18
|
+
function Se() {
|
|
19
19
|
if (ue) return te;
|
|
20
20
|
ue = 1;
|
|
21
|
-
var
|
|
22
|
-
function s(n,
|
|
21
|
+
var M = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
22
|
+
function s(n, r, t) {
|
|
23
23
|
var a = null;
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
for (var c in
|
|
27
|
-
c !== "key" && (
|
|
28
|
-
} else
|
|
29
|
-
return
|
|
30
|
-
$$typeof:
|
|
24
|
+
if (t !== void 0 && (a = "" + t), r.key !== void 0 && (a = "" + r.key), "key" in r) {
|
|
25
|
+
t = {};
|
|
26
|
+
for (var c in r)
|
|
27
|
+
c !== "key" && (t[c] = r[c]);
|
|
28
|
+
} else t = r;
|
|
29
|
+
return r = t.ref, {
|
|
30
|
+
$$typeof: M,
|
|
31
31
|
type: n,
|
|
32
32
|
key: a,
|
|
33
|
-
ref:
|
|
34
|
-
props:
|
|
33
|
+
ref: r !== void 0 ? r : null,
|
|
34
|
+
props: t
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
return te.Fragment = e, te.jsx = s, te.jsxs = s, te;
|
|
@@ -46,10 +46,10 @@ 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
|
|
50
|
-
function
|
|
51
|
-
return
|
|
52
|
-
function
|
|
49
|
+
var fe;
|
|
50
|
+
function Te() {
|
|
51
|
+
return fe || (fe = 1, process.env.NODE_ENV !== "production" && function() {
|
|
52
|
+
function M(o) {
|
|
53
53
|
if (o == null) return null;
|
|
54
54
|
if (typeof o == "function")
|
|
55
55
|
return o.$$typeof === w ? null : o.displayName || o.name || null;
|
|
@@ -57,7 +57,7 @@ function Ce() {
|
|
|
57
57
|
switch (o) {
|
|
58
58
|
case T:
|
|
59
59
|
return "Fragment";
|
|
60
|
-
case
|
|
60
|
+
case q:
|
|
61
61
|
return "Profiler";
|
|
62
62
|
case O:
|
|
63
63
|
return "StrictMode";
|
|
@@ -72,9 +72,9 @@ function Ce() {
|
|
|
72
72
|
switch (typeof o.tag == "number" && console.error(
|
|
73
73
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
74
74
|
), o.$$typeof) {
|
|
75
|
-
case
|
|
75
|
+
case h:
|
|
76
76
|
return "Portal";
|
|
77
|
-
case
|
|
77
|
+
case j:
|
|
78
78
|
return (o.displayName || "Context") + ".Provider";
|
|
79
79
|
case W:
|
|
80
80
|
return (o._context.displayName || "Context") + ".Consumer";
|
|
@@ -82,11 +82,11 @@ function Ce() {
|
|
|
82
82
|
var d = o.render;
|
|
83
83
|
return o = o.displayName, o || (o = d.displayName || d.name || "", o = o !== "" ? "ForwardRef(" + o + ")" : "ForwardRef"), o;
|
|
84
84
|
case k:
|
|
85
|
-
return d = o.displayName || null, d !== null ? d :
|
|
85
|
+
return d = o.displayName || null, d !== null ? d : M(o.type) || "Memo";
|
|
86
86
|
case B:
|
|
87
87
|
d = o._payload, o = o._init;
|
|
88
88
|
try {
|
|
89
|
-
return
|
|
89
|
+
return M(o(d));
|
|
90
90
|
} catch {
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -117,17 +117,17 @@ function Ce() {
|
|
|
117
117
|
if (typeof o == "object" && o !== null && o.$$typeof === B)
|
|
118
118
|
return "<...>";
|
|
119
119
|
try {
|
|
120
|
-
var d =
|
|
120
|
+
var d = M(o);
|
|
121
121
|
return d ? "<" + d + ">" : "<...>";
|
|
122
122
|
} catch {
|
|
123
123
|
return "<...>";
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
function
|
|
127
|
-
var o =
|
|
126
|
+
function r() {
|
|
127
|
+
var o = C.A;
|
|
128
128
|
return o === null ? null : o.getOwner();
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function t() {
|
|
131
131
|
return Error("react-stack-top-frame");
|
|
132
132
|
}
|
|
133
133
|
function a(o) {
|
|
@@ -150,17 +150,17 @@ function Ce() {
|
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
function l() {
|
|
153
|
-
var o =
|
|
153
|
+
var o = M(this.type);
|
|
154
154
|
return _[o] || (_[o] = !0, console.error(
|
|
155
155
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
156
156
|
)), o = this.props.ref, o !== void 0 ? o : null;
|
|
157
157
|
}
|
|
158
|
-
function m(o, d, A, z, N,
|
|
159
|
-
return A =
|
|
158
|
+
function m(o, d, A, z, N, f, P, F) {
|
|
159
|
+
return A = f.ref, o = {
|
|
160
160
|
$$typeof: x,
|
|
161
161
|
type: o,
|
|
162
162
|
key: d,
|
|
163
|
-
props:
|
|
163
|
+
props: f,
|
|
164
164
|
_owner: N
|
|
165
165
|
}, (A !== void 0 ? A : null) !== null ? Object.defineProperty(o, "ref", {
|
|
166
166
|
enumerable: !1,
|
|
@@ -187,7 +187,7 @@ function Ce() {
|
|
|
187
187
|
value: F
|
|
188
188
|
}), Object.freeze && (Object.freeze(o.props), Object.freeze(o)), o;
|
|
189
189
|
}
|
|
190
|
-
function S(o, d, A, z, N,
|
|
190
|
+
function S(o, d, A, z, N, f, P, F) {
|
|
191
191
|
var u = d.children;
|
|
192
192
|
if (u !== void 0)
|
|
193
193
|
if (z)
|
|
@@ -201,11 +201,11 @@ function Ce() {
|
|
|
201
201
|
);
|
|
202
202
|
else b(u);
|
|
203
203
|
if (U.call(d, "key")) {
|
|
204
|
-
u =
|
|
205
|
-
var I = Object.keys(d).filter(function(
|
|
206
|
-
return
|
|
204
|
+
u = M(o);
|
|
205
|
+
var I = Object.keys(d).filter(function(X) {
|
|
206
|
+
return X !== "key";
|
|
207
207
|
});
|
|
208
|
-
z = 0 < I.length ? "{key: someKey, " + I.join(": ..., ") + ": ...}" : "{key: someKey}",
|
|
208
|
+
z = 0 < I.length ? "{key: someKey, " + I.join(": ..., ") + ": ...}" : "{key: someKey}", G[u + z] || (I = 0 < I.length ? "{" + I.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
209
209
|
`A props object containing a "key" prop is being spread into JSX:
|
|
210
210
|
let props = %s;
|
|
211
211
|
<%s {...props} />
|
|
@@ -216,7 +216,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
216
216
|
u,
|
|
217
217
|
I,
|
|
218
218
|
u
|
|
219
|
-
),
|
|
219
|
+
), G[u + z] = !0);
|
|
220
220
|
}
|
|
221
221
|
if (u = null, A !== void 0 && (s(A), u = "" + A), a(d) && (s(d.key), u = "" + d.key), "key" in d) {
|
|
222
222
|
A = {};
|
|
@@ -229,9 +229,9 @@ React keys must be passed directly to JSX without using spread:
|
|
|
229
229
|
), m(
|
|
230
230
|
o,
|
|
231
231
|
u,
|
|
232
|
-
|
|
232
|
+
f,
|
|
233
233
|
N,
|
|
234
|
-
|
|
234
|
+
r(),
|
|
235
235
|
A,
|
|
236
236
|
P,
|
|
237
237
|
F
|
|
@@ -240,7 +240,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
240
240
|
function b(o) {
|
|
241
241
|
typeof o == "object" && o !== null && o.$$typeof === x && o._store && (o._store.validated = 1);
|
|
242
242
|
}
|
|
243
|
-
var p =
|
|
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() {
|
|
244
244
|
return null;
|
|
245
245
|
};
|
|
246
246
|
p = {
|
|
@@ -250,10 +250,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
250
250
|
};
|
|
251
251
|
var y, _ = {}, R = p["react-stack-bottom-frame"].bind(
|
|
252
252
|
p,
|
|
253
|
-
|
|
254
|
-
)(), L =
|
|
253
|
+
t
|
|
254
|
+
)(), L = v(n(t)), G = {};
|
|
255
255
|
re.Fragment = T, re.jsx = function(o, d, A, z, N) {
|
|
256
|
-
var
|
|
256
|
+
var f = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
257
257
|
return S(
|
|
258
258
|
o,
|
|
259
259
|
d,
|
|
@@ -261,11 +261,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
261
261
|
!1,
|
|
262
262
|
z,
|
|
263
263
|
N,
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
f ? Error("react-stack-top-frame") : R,
|
|
265
|
+
f ? v(n(o)) : L
|
|
266
266
|
);
|
|
267
267
|
}, re.jsxs = function(o, d, A, z, N) {
|
|
268
|
-
var
|
|
268
|
+
var f = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
269
269
|
return S(
|
|
270
270
|
o,
|
|
271
271
|
d,
|
|
@@ -273,24 +273,24 @@ React keys must be passed directly to JSX without using spread:
|
|
|
273
273
|
!0,
|
|
274
274
|
z,
|
|
275
275
|
N,
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
f ? Error("react-stack-top-frame") : R,
|
|
277
|
+
f ? v(n(o)) : L
|
|
278
278
|
);
|
|
279
279
|
};
|
|
280
280
|
}()), re;
|
|
281
281
|
}
|
|
282
|
-
var
|
|
283
|
-
function
|
|
284
|
-
return
|
|
282
|
+
var he;
|
|
283
|
+
function Ce() {
|
|
284
|
+
return he || (he = 1, process.env.NODE_ENV === "production" ? se.exports = Se() : se.exports = Te()), se.exports;
|
|
285
285
|
}
|
|
286
|
-
var
|
|
286
|
+
var Me = Ce();
|
|
287
287
|
class le {
|
|
288
288
|
constructor() {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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());
|
|
292
292
|
/** Half extents (size/2) */
|
|
293
|
-
|
|
293
|
+
g(this, "halfExtents", new i.Vector3());
|
|
294
294
|
}
|
|
295
295
|
/**
|
|
296
296
|
* Reset the bounding box to its initial state
|
|
@@ -342,17 +342,17 @@ class le {
|
|
|
342
342
|
return e.min.copy(this.min), e.max.copy(this.max), e.center.copy(this.center), e.halfExtents.copy(this.halfExtents), e;
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
|
-
class
|
|
345
|
+
class Ae {
|
|
346
346
|
// TODO: there is no sh spherical harmonics
|
|
347
347
|
constructor(e = 0) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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());
|
|
356
356
|
this.numSplats = e, this.allocateBuffers(e);
|
|
357
357
|
}
|
|
358
358
|
allocateBuffers(e) {
|
|
@@ -367,13 +367,13 @@ class _e {
|
|
|
367
367
|
* @param color Color
|
|
368
368
|
* @param opacity Opacity value
|
|
369
369
|
*/
|
|
370
|
-
setSplat(e, s, n,
|
|
370
|
+
setSplat(e, s, n, r, t, a) {
|
|
371
371
|
if (e >= this.numSplats)
|
|
372
372
|
throw new Error(
|
|
373
373
|
`Splat index out of bounds: ${e} >= ${this.numSplats}`
|
|
374
374
|
);
|
|
375
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] =
|
|
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;
|
|
377
377
|
}
|
|
378
378
|
/**
|
|
379
379
|
* Get a splat's data
|
|
@@ -385,7 +385,7 @@ class _e {
|
|
|
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,
|
|
388
|
+
const s = e * 3, n = e * 4, r = e * 3, t = e * 3;
|
|
389
389
|
return {
|
|
390
390
|
position: new i.Vector3(
|
|
391
391
|
this.positions[s],
|
|
@@ -400,14 +400,14 @@ class _e {
|
|
|
400
400
|
),
|
|
401
401
|
// Convert log scale back to linear scale for external use
|
|
402
402
|
scale: new i.Vector3(
|
|
403
|
-
Math.exp(this.scales[
|
|
404
|
-
Math.exp(this.scales[
|
|
405
|
-
Math.exp(this.scales[
|
|
403
|
+
Math.exp(this.scales[r]),
|
|
404
|
+
Math.exp(this.scales[r + 1]),
|
|
405
|
+
Math.exp(this.scales[r + 2])
|
|
406
406
|
),
|
|
407
407
|
color: new i.Color(
|
|
408
|
-
this.colors[
|
|
409
|
-
this.colors[
|
|
410
|
-
this.colors[
|
|
408
|
+
this.colors[t],
|
|
409
|
+
this.colors[t + 1],
|
|
410
|
+
this.colors[t + 2]
|
|
411
411
|
),
|
|
412
412
|
opacity: this.opacities[e]
|
|
413
413
|
};
|
|
@@ -439,15 +439,15 @@ class _e {
|
|
|
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(),
|
|
443
|
-
for (let
|
|
444
|
-
const a =
|
|
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
445
|
n.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
|
-
),
|
|
450
|
+
), r.setFromQuaternion(n), s[c] = r.x, s[c + 1] = r.y, s[c + 2] = r.z;
|
|
451
451
|
}
|
|
452
452
|
return e.setAttribute(
|
|
453
453
|
"rotation",
|
|
@@ -464,7 +464,7 @@ class _e {
|
|
|
464
464
|
), e;
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
-
class
|
|
467
|
+
class Ee 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,9 +472,9 @@ class ke extends i.Loader {
|
|
|
472
472
|
* @param onProgress Optional progress callback
|
|
473
473
|
* @param onError Optional error callback
|
|
474
474
|
*/
|
|
475
|
-
load(e, s, n,
|
|
476
|
-
const
|
|
477
|
-
|
|
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(
|
|
478
478
|
e,
|
|
479
479
|
(a) => {
|
|
480
480
|
try {
|
|
@@ -483,11 +483,11 @@ class ke extends i.Loader {
|
|
|
483
483
|
s(c);
|
|
484
484
|
}
|
|
485
485
|
} catch (c) {
|
|
486
|
-
|
|
486
|
+
r ? r(c) : console.error(c), this.manager.itemError(e);
|
|
487
487
|
}
|
|
488
488
|
},
|
|
489
489
|
n,
|
|
490
|
-
|
|
490
|
+
r
|
|
491
491
|
);
|
|
492
492
|
}
|
|
493
493
|
/**
|
|
@@ -497,21 +497,21 @@ class ke extends i.Loader {
|
|
|
497
497
|
* @returns A Promise that resolves with the parsed SplatData
|
|
498
498
|
*/
|
|
499
499
|
loadAsync(e, s) {
|
|
500
|
-
return new Promise((n,
|
|
501
|
-
const
|
|
502
|
-
|
|
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(
|
|
503
503
|
e,
|
|
504
504
|
(a) => {
|
|
505
505
|
try {
|
|
506
506
|
const c = this.parse(a);
|
|
507
507
|
n(c);
|
|
508
508
|
} catch (c) {
|
|
509
|
-
|
|
509
|
+
r(c), this.manager.itemError(e);
|
|
510
510
|
}
|
|
511
511
|
},
|
|
512
512
|
s,
|
|
513
513
|
(a) => {
|
|
514
|
-
|
|
514
|
+
r(a), this.manager.itemError(e);
|
|
515
515
|
}
|
|
516
516
|
);
|
|
517
517
|
});
|
|
@@ -522,22 +522,22 @@ class ke extends i.Loader {
|
|
|
522
522
|
* @returns Parsed SplatData
|
|
523
523
|
*/
|
|
524
524
|
parse(e) {
|
|
525
|
-
const s = new TextDecoder(), n = new Uint8Array(e),
|
|
525
|
+
const s = new TextDecoder(), n = new Uint8Array(e), r = [112, 108, 121, 10], t = `
|
|
526
526
|
end_header
|
|
527
527
|
`;
|
|
528
|
-
for (let
|
|
529
|
-
if (n[
|
|
528
|
+
for (let v = 0; v < r.length; v++)
|
|
529
|
+
if (n[v] !== r[v])
|
|
530
530
|
throw new Error("Invalid PLY file: Missing magic bytes");
|
|
531
531
|
let a = 0;
|
|
532
|
-
for (let
|
|
532
|
+
for (let v = 0; v < n.length - t.length; v++) {
|
|
533
533
|
let y = !0;
|
|
534
|
-
for (let _ = 0; _ <
|
|
535
|
-
if (n[
|
|
534
|
+
for (let _ = 0; _ < t.length; _++)
|
|
535
|
+
if (n[v + _] !== t.charCodeAt(_)) {
|
|
536
536
|
y = !1;
|
|
537
537
|
break;
|
|
538
538
|
}
|
|
539
539
|
if (y) {
|
|
540
|
-
a =
|
|
540
|
+
a = v + t.length;
|
|
541
541
|
break;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
@@ -548,8 +548,8 @@ end_header
|
|
|
548
548
|
).split(`
|
|
549
549
|
`), m = [];
|
|
550
550
|
let S = null;
|
|
551
|
-
for (let
|
|
552
|
-
const y = l[
|
|
551
|
+
for (let v = 1; v < l.length; v++) {
|
|
552
|
+
const y = l[v].trim();
|
|
553
553
|
if (y === "" || y === "end_header") continue;
|
|
554
554
|
const _ = y.split(" ");
|
|
555
555
|
switch (_[0]) {
|
|
@@ -578,12 +578,12 @@ end_header
|
|
|
578
578
|
}
|
|
579
579
|
if (S !== "binary_little_endian")
|
|
580
580
|
throw new Error(`Unsupported PLY format: ${S}`);
|
|
581
|
-
const b = m.find((
|
|
581
|
+
const b = m.find((v) => v.name === "vertex");
|
|
582
582
|
if (!b)
|
|
583
583
|
throw new Error("Invalid PLY file: No vertex element found");
|
|
584
|
-
const p = new
|
|
585
|
-
let
|
|
586
|
-
const T = (
|
|
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
587
|
T("rot_0"),
|
|
588
588
|
T("rot_1"),
|
|
589
589
|
T("rot_2"),
|
|
@@ -599,65 +599,65 @@ end_header
|
|
|
599
599
|
], D = T("opacity");
|
|
600
600
|
if ([
|
|
601
601
|
O,
|
|
602
|
-
|
|
602
|
+
q,
|
|
603
603
|
W,
|
|
604
|
-
...
|
|
604
|
+
...j,
|
|
605
605
|
...H,
|
|
606
606
|
...$,
|
|
607
607
|
D
|
|
608
|
-
].some((
|
|
608
|
+
].some((v) => v === -1))
|
|
609
609
|
throw new Error("Invalid PLY file: Missing required properties");
|
|
610
|
-
const B = 0.28209479177387814, E = (
|
|
611
|
-
if (
|
|
612
|
-
const y = Math.exp(
|
|
610
|
+
const B = 0.28209479177387814, E = (v) => {
|
|
611
|
+
if (v > 0) return 1 / (1 + Math.exp(-v));
|
|
612
|
+
const y = Math.exp(v);
|
|
613
613
|
return y / (1 + y);
|
|
614
|
-
}, w = new i.Vector3(),
|
|
615
|
-
for (let
|
|
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
616
|
const y = [];
|
|
617
617
|
for (let R = 0; R < b.properties.length; R++) {
|
|
618
|
-
const
|
|
618
|
+
const G = b.properties[R].type;
|
|
619
619
|
let o;
|
|
620
|
-
switch (
|
|
620
|
+
switch (G) {
|
|
621
621
|
case "char":
|
|
622
|
-
o = x.getInt8(
|
|
622
|
+
o = x.getInt8(h), h += 1;
|
|
623
623
|
break;
|
|
624
624
|
case "uchar":
|
|
625
|
-
o = x.getUint8(
|
|
625
|
+
o = x.getUint8(h), h += 1;
|
|
626
626
|
break;
|
|
627
627
|
case "short":
|
|
628
|
-
o = x.getInt16(
|
|
628
|
+
o = x.getInt16(h, !0), h += 2;
|
|
629
629
|
break;
|
|
630
630
|
case "ushort":
|
|
631
|
-
o = x.getUint16(
|
|
631
|
+
o = x.getUint16(h, !0), h += 2;
|
|
632
632
|
break;
|
|
633
633
|
case "int":
|
|
634
|
-
o = x.getInt32(
|
|
634
|
+
o = x.getInt32(h, !0), h += 4;
|
|
635
635
|
break;
|
|
636
636
|
case "uint":
|
|
637
|
-
o = x.getUint32(
|
|
637
|
+
o = x.getUint32(h, !0), h += 4;
|
|
638
638
|
break;
|
|
639
639
|
case "float":
|
|
640
|
-
o = x.getFloat32(
|
|
640
|
+
o = x.getFloat32(h, !0), h += 4;
|
|
641
641
|
break;
|
|
642
642
|
case "double":
|
|
643
|
-
o = x.getFloat64(
|
|
643
|
+
o = x.getFloat64(h, !0), h += 8;
|
|
644
644
|
break;
|
|
645
645
|
default:
|
|
646
|
-
throw new Error(`Unsupported property type: ${
|
|
646
|
+
throw new Error(`Unsupported property type: ${G}`);
|
|
647
647
|
}
|
|
648
648
|
y.push(o);
|
|
649
649
|
}
|
|
650
650
|
w.set(
|
|
651
651
|
y[O],
|
|
652
|
-
y[
|
|
652
|
+
y[q],
|
|
653
653
|
y[W]
|
|
654
|
-
),
|
|
655
|
-
y[
|
|
654
|
+
), C.set(
|
|
655
|
+
y[j[1]],
|
|
656
656
|
// PLY stores rot 1,2,3,0 (x,y,z,w)
|
|
657
|
-
y[
|
|
658
|
-
y[
|
|
659
|
-
y[
|
|
660
|
-
).normalize(),
|
|
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
661
|
y[H[0]],
|
|
662
662
|
// Read directly assuming it's log scale
|
|
663
663
|
y[H[1]],
|
|
@@ -669,9 +669,9 @@ end_header
|
|
|
669
669
|
), V.r = Math.max(0, Math.min(1, V.r)), V.g = Math.max(0, Math.min(1, V.g)), V.b = Math.max(0, Math.min(1, V.b));
|
|
670
670
|
const _ = E(y[D]);
|
|
671
671
|
p.setSplat(
|
|
672
|
-
|
|
672
|
+
v,
|
|
673
673
|
w,
|
|
674
|
-
|
|
674
|
+
C,
|
|
675
675
|
U,
|
|
676
676
|
// Pass log scale directly
|
|
677
677
|
V,
|
|
@@ -681,16 +681,16 @@ end_header
|
|
|
681
681
|
return p.calculateBoundingBox(), p;
|
|
682
682
|
}
|
|
683
683
|
}
|
|
684
|
-
class
|
|
684
|
+
class _e extends i.EventDispatcher {
|
|
685
685
|
constructor() {
|
|
686
686
|
super();
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
687
|
+
g(this, "worker");
|
|
688
|
+
g(this, "centers", null);
|
|
689
|
+
g(this, "orderTexture", null);
|
|
690
690
|
/** Bounding box data for optimization */
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
691
|
+
g(this, "chunks", null);
|
|
692
|
+
g(this, "lastCameraPosition", new i.Vector3());
|
|
693
|
+
g(this, "lastCameraDirection", new i.Vector3());
|
|
694
694
|
const s = this.createWorkerCode(), n = new Blob([s], { type: "application/javascript" });
|
|
695
695
|
this.worker = new Worker(URL.createObjectURL(n)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
696
696
|
}
|
|
@@ -701,14 +701,14 @@ class Ie extends i.EventDispatcher {
|
|
|
701
701
|
onWorkerMessage(s) {
|
|
702
702
|
if (!this.orderTexture || !this.orderTexture.image)
|
|
703
703
|
return console.error("SplatSorter: Order texture not initialized!");
|
|
704
|
-
const { order: n, count:
|
|
705
|
-
if (!(
|
|
704
|
+
const { order: n, count: r } = s.data, t = this.orderTexture.image.data;
|
|
705
|
+
if (!(t instanceof Uint32Array))
|
|
706
706
|
return console.error(
|
|
707
707
|
"SplatSorter: Order texture data is not a Uint32Array!"
|
|
708
708
|
);
|
|
709
|
-
|
|
710
|
-
const a =
|
|
711
|
-
this.worker.postMessage(c, [a]), this.dispatchEvent({ type: "updated", count:
|
|
709
|
+
t.set(new Uint32Array(n)), this.orderTexture.needsUpdate = !0;
|
|
710
|
+
const a = t.buffer.slice(0), c = { order: a };
|
|
711
|
+
this.worker.postMessage(c, [a]), this.dispatchEvent({ type: "updated", count: r });
|
|
712
712
|
}
|
|
713
713
|
/**
|
|
714
714
|
* Initializes the sorter with necessary data and textures.
|
|
@@ -716,17 +716,17 @@ class Ie extends i.EventDispatcher {
|
|
|
716
716
|
* @param centers A Float32Array containing the center position (x, y, z) for each splat.
|
|
717
717
|
* @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
|
|
718
718
|
*/
|
|
719
|
-
init(s, n,
|
|
719
|
+
init(s, n, r) {
|
|
720
720
|
if (!s || !(s.image.data instanceof Uint32Array))
|
|
721
721
|
throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
|
|
722
722
|
if (!n || n.length % 3 !== 0)
|
|
723
723
|
throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
|
|
724
724
|
if (s.image.data.length < n.length / 3)
|
|
725
725
|
throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");
|
|
726
|
-
const
|
|
726
|
+
const t = n.length / 3;
|
|
727
727
|
this.orderTexture = s, this.centers = n.slice();
|
|
728
728
|
const a = this.orderTexture.image.data;
|
|
729
|
-
for (let b = 0; b <
|
|
729
|
+
for (let b = 0; b < t; b++) a[b] = b;
|
|
730
730
|
this.orderTexture.needsUpdate = !0;
|
|
731
731
|
const c = a.buffer.slice(0), l = this.centers.buffer.slice(0), m = {
|
|
732
732
|
order: c,
|
|
@@ -735,8 +735,8 @@ class Ie extends i.EventDispatcher {
|
|
|
735
735
|
c,
|
|
736
736
|
l
|
|
737
737
|
];
|
|
738
|
-
if (
|
|
739
|
-
this.chunks =
|
|
738
|
+
if (r) {
|
|
739
|
+
this.chunks = r.slice();
|
|
740
740
|
const b = this.chunks.buffer.slice(0);
|
|
741
741
|
m.chunks = b, S.push(b);
|
|
742
742
|
}
|
|
@@ -753,15 +753,15 @@ class Ie extends i.EventDispatcher {
|
|
|
753
753
|
"SplatSorter: Cannot set mapping before initialization."
|
|
754
754
|
);
|
|
755
755
|
let n;
|
|
756
|
-
const
|
|
756
|
+
const r = [];
|
|
757
757
|
if (!s) {
|
|
758
758
|
const l = this.centers.buffer.slice(0);
|
|
759
759
|
return n = {
|
|
760
760
|
centers: l,
|
|
761
761
|
mapping: null
|
|
762
|
-
},
|
|
762
|
+
}, r.push(l), this.worker.postMessage(n, r);
|
|
763
763
|
}
|
|
764
|
-
const
|
|
764
|
+
const t = new Float32Array(s.length * 3);
|
|
765
765
|
for (let l = 0; l < s.length; l++) {
|
|
766
766
|
const m = s[l];
|
|
767
767
|
if (m * 3 + 2 >= this.centers.length) {
|
|
@@ -771,13 +771,13 @@ class Ie extends i.EventDispatcher {
|
|
|
771
771
|
continue;
|
|
772
772
|
}
|
|
773
773
|
const S = m * 3, b = l * 3;
|
|
774
|
-
|
|
774
|
+
t[b + 0] = this.centers[S + 0], t[b + 1] = this.centers[S + 1], t[b + 2] = this.centers[S + 2];
|
|
775
775
|
}
|
|
776
|
-
const a =
|
|
776
|
+
const a = t.buffer.slice(0), c = s.buffer.slice(0);
|
|
777
777
|
n = {
|
|
778
778
|
centers: a,
|
|
779
779
|
mapping: c
|
|
780
|
-
},
|
|
780
|
+
}, r.push(a, c), this.worker.postMessage(n, r);
|
|
781
781
|
}
|
|
782
782
|
/**
|
|
783
783
|
* Updates the camera parameters used for sorting.
|
|
@@ -785,8 +785,8 @@ class Ie extends i.EventDispatcher {
|
|
|
785
785
|
* @param direction The camera's forward direction in the sorter's local coordinate space.
|
|
786
786
|
*/
|
|
787
787
|
setCamera(s, n) {
|
|
788
|
-
const
|
|
789
|
-
if (!
|
|
788
|
+
const r = this.lastCameraPosition.distanceToSquared(s) > 1e-7, t = this.lastCameraDirection.dot(n) < 0.9999;
|
|
789
|
+
if (!r && !t)
|
|
790
790
|
return;
|
|
791
791
|
this.lastCameraPosition.copy(s), this.lastCameraDirection.copy(n);
|
|
792
792
|
const a = {
|
|
@@ -807,10 +807,10 @@ class Ie extends i.EventDispatcher {
|
|
|
807
807
|
*/
|
|
808
808
|
createWorkerCode() {
|
|
809
809
|
return `(${(function() {
|
|
810
|
-
let n = null,
|
|
810
|
+
let n = null, r = null, t = null, a = null, c = null, l = null, m = !1;
|
|
811
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
|
|
813
|
-
const O = 32,
|
|
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
814
|
for (; D <= k; ) {
|
|
815
815
|
const E = k + D >> 1, w = B(E);
|
|
816
816
|
if (w > 0) D = E + 1;
|
|
@@ -819,37 +819,37 @@ class Ie extends i.EventDispatcher {
|
|
|
819
819
|
}
|
|
820
820
|
return ~D;
|
|
821
821
|
}, $ = () => {
|
|
822
|
-
if (!n || !
|
|
822
|
+
if (!n || !r || !c || !l)
|
|
823
823
|
return;
|
|
824
|
-
if (
|
|
825
|
-
const
|
|
824
|
+
if (r.length === 0) {
|
|
825
|
+
const f = {
|
|
826
826
|
order: n.buffer,
|
|
827
827
|
count: 0
|
|
828
828
|
};
|
|
829
|
-
self.postMessage(
|
|
829
|
+
self.postMessage(f, [n.buffer]), n = null;
|
|
830
830
|
return;
|
|
831
831
|
}
|
|
832
|
-
const D = c.x, k = c.y, B = c.z, E = l.x, w = l.y,
|
|
833
|
-
if (!m && !V && !
|
|
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)
|
|
834
834
|
return;
|
|
835
|
-
m = !1, S.x = D, S.y = k, S.z = B, b.x = E, b.y = w, b.z =
|
|
835
|
+
m = !1, S.x = D, S.y = k, S.z = B, b.x = E, b.y = w, b.z = C;
|
|
836
836
|
let y = 1 / 0, _ = -1 / 0;
|
|
837
|
-
for (let
|
|
838
|
-
const P =
|
|
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
839
|
y = Math.min(y, I), _ = Math.max(_, I);
|
|
840
840
|
}
|
|
841
|
-
const R =
|
|
841
|
+
const R = r.length / 3, L = _ - y, o = (1 << Math.max(
|
|
842
842
|
10,
|
|
843
843
|
Math.min(20, Math.ceil(Math.log2(R / 4)))
|
|
844
844
|
)) + 1;
|
|
845
|
-
if ((!
|
|
846
|
-
for (let
|
|
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
847
|
T[0] = R;
|
|
848
|
-
} else if (
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
for (let u = 0; u <
|
|
852
|
-
const I = u * 6, Y =
|
|
848
|
+
} else if (t && t.length > 0) {
|
|
849
|
+
const f = t.length / 6;
|
|
850
|
+
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(
|
|
853
853
|
0,
|
|
854
854
|
Math.floor(oe * O / L)
|
|
855
855
|
), ce = Math.min(
|
|
@@ -857,54 +857,54 @@ class Ie extends i.EventDispatcher {
|
|
|
857
857
|
Math.ceil(ee * O / L)
|
|
858
858
|
);
|
|
859
859
|
for (let Q = ie; Q < ce; ++Q)
|
|
860
|
-
|
|
860
|
+
q[Q]++;
|
|
861
861
|
}
|
|
862
862
|
let P = 0;
|
|
863
|
-
for (let u = 0; u < O; ++u) P +=
|
|
864
|
-
|
|
863
|
+
for (let u = 0; u < O; ++u) P += q[u];
|
|
864
|
+
j[0] = 0, W[0] = 0;
|
|
865
865
|
for (let u = 1; u < O; ++u)
|
|
866
|
-
|
|
867
|
-
|
|
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
868
|
const F = L / O;
|
|
869
869
|
for (let u = 0; u < R; ++u) {
|
|
870
|
-
const I = u * 3, Y =
|
|
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(
|
|
871
871
|
0,
|
|
872
872
|
Math.min(
|
|
873
873
|
O - 1,
|
|
874
874
|
Math.floor(oe)
|
|
875
875
|
)
|
|
876
|
-
), ie = oe - ee, ce = W[ee] +
|
|
877
|
-
|
|
876
|
+
), ie = oe - ee, ce = W[ee] + j[ee] * ie >>> 0, Q = Math.min(ce, o - 1);
|
|
877
|
+
h[u] = Q, T[Q]++;
|
|
878
878
|
}
|
|
879
879
|
} else {
|
|
880
|
-
const
|
|
880
|
+
const f = (o - 1) / L;
|
|
881
881
|
for (let P = 0; P < R; ++P) {
|
|
882
|
-
const F = P * 3, u =
|
|
883
|
-
|
|
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]++;
|
|
884
884
|
}
|
|
885
885
|
}
|
|
886
|
-
for (let
|
|
887
|
-
T[
|
|
888
|
-
for (let
|
|
889
|
-
const P = f
|
|
890
|
-
n[F] = a ? a[
|
|
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;
|
|
891
891
|
}
|
|
892
|
-
const d = D * E + k * w + B *
|
|
892
|
+
const d = D * E + k * w + B * C, A = (f) => {
|
|
893
893
|
if (!n) return -1 / 0;
|
|
894
|
-
const P = n[
|
|
895
|
-
if (!
|
|
894
|
+
const P = n[f], F = P;
|
|
895
|
+
if (!r || F * 3 + 2 >= r.length)
|
|
896
896
|
return -1 / 0;
|
|
897
897
|
const u = F * 3;
|
|
898
|
-
return
|
|
898
|
+
return r[u] * E + r[u + 1] * w + r[u + 2] * C - d;
|
|
899
899
|
};
|
|
900
900
|
let z = R;
|
|
901
901
|
if (R > 0 && A(R - 1) < 0) {
|
|
902
|
-
const
|
|
902
|
+
const f = H(
|
|
903
903
|
0,
|
|
904
904
|
R - 1,
|
|
905
905
|
A
|
|
906
906
|
);
|
|
907
|
-
z =
|
|
907
|
+
z = f < 0 ? ~f : f;
|
|
908
908
|
}
|
|
909
909
|
const N = {
|
|
910
910
|
order: n.buffer,
|
|
@@ -916,54 +916,54 @@ class Ie extends i.EventDispatcher {
|
|
|
916
916
|
const k = D.data;
|
|
917
917
|
k.order && (n = new Uint32Array(k.order));
|
|
918
918
|
let B = !1;
|
|
919
|
-
if (k.centers && (
|
|
920
|
-
if (
|
|
921
|
-
for (let E = 0; E <
|
|
922
|
-
const w = E * 6,
|
|
923
|
-
|
|
924
|
-
(
|
|
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
|
|
925
925
|
) * 0.5;
|
|
926
926
|
}
|
|
927
927
|
m = !0;
|
|
928
928
|
}
|
|
929
|
-
if (B &&
|
|
930
|
-
p.x = x.x =
|
|
931
|
-
for (let E = 1; E <
|
|
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
932
|
const w = E * 3;
|
|
933
|
-
p.x = Math.min(p.x,
|
|
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]);
|
|
934
934
|
}
|
|
935
|
-
} else B &&
|
|
935
|
+
} else B && r && r.length === 0 && (p.x = x.x = p.y = x.y = p.z = x.z = 0);
|
|
936
936
|
k.cameraPosition && (c = k.cameraPosition), k.cameraDirection && (l = k.cameraDirection), $();
|
|
937
937
|
};
|
|
938
938
|
}).toString()})();`;
|
|
939
939
|
}
|
|
940
940
|
}
|
|
941
|
-
const
|
|
942
|
-
const s = de(
|
|
941
|
+
const ke = (M, e) => {
|
|
942
|
+
const s = de(M), n = de(e);
|
|
943
943
|
return s | n << 16;
|
|
944
944
|
};
|
|
945
|
-
function de(
|
|
946
|
-
const e = new Float32Array([
|
|
947
|
-
let
|
|
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
948
|
const a = n >> 23 & 255;
|
|
949
|
-
return a < 103 ?
|
|
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);
|
|
950
950
|
}
|
|
951
|
-
const
|
|
952
|
-
class
|
|
951
|
+
const Ie = new ArrayBuffer(4), pe = new DataView(Ie), Re = (M) => (pe.setUint32(0, M, !0), pe.getFloat32(0, !0));
|
|
952
|
+
class ze {
|
|
953
953
|
/**
|
|
954
954
|
* Create a new TextureManager for a set of splats
|
|
955
955
|
* @param splatData The splat data to manage textures for
|
|
956
956
|
*/
|
|
957
957
|
constructor(e) {
|
|
958
|
-
|
|
958
|
+
g(this, "transformA");
|
|
959
959
|
// position xyz and rotation quaternion y,z components
|
|
960
|
-
|
|
960
|
+
g(this, "transformB");
|
|
961
961
|
// rotation quaternion x and scale xyz
|
|
962
|
-
|
|
962
|
+
g(this, "colorTexture");
|
|
963
963
|
// color an opacity
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
964
|
+
g(this, "orderTexture");
|
|
965
|
+
g(this, "textureWidth");
|
|
966
|
+
g(this, "textureHeight");
|
|
967
967
|
const s = e.numSplats;
|
|
968
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);
|
|
969
969
|
}
|
|
@@ -976,13 +976,13 @@ class Oe {
|
|
|
976
976
|
const s = e.numSplats, n = new Float32Array(
|
|
977
977
|
this.textureWidth * this.textureHeight * 4
|
|
978
978
|
);
|
|
979
|
-
for (let
|
|
980
|
-
const a =
|
|
979
|
+
for (let t = 0; t < s; t++) {
|
|
980
|
+
const a = t * 4, c = t * 3, l = t * 4;
|
|
981
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 =
|
|
983
|
-
n[a + 3] =
|
|
982
|
+
const m = e.rotations[l + 0], S = e.rotations[l + 1], b = ke(m, S);
|
|
983
|
+
n[a + 3] = Re(b);
|
|
984
984
|
}
|
|
985
|
-
const
|
|
985
|
+
const r = new i.DataTexture(
|
|
986
986
|
n,
|
|
987
987
|
this.textureWidth,
|
|
988
988
|
this.textureHeight,
|
|
@@ -990,7 +990,7 @@ class Oe {
|
|
|
990
990
|
i.FloatType
|
|
991
991
|
// Store as Float32, shader will reinterpret bits
|
|
992
992
|
);
|
|
993
|
-
return
|
|
993
|
+
return r.needsUpdate = !0, r.magFilter = i.NearestFilter, r.minFilter = i.NearestFilter, r;
|
|
994
994
|
}
|
|
995
995
|
/**
|
|
996
996
|
* Create the transform B texture (scale and rotation xyz)
|
|
@@ -1001,18 +1001,18 @@ class Oe {
|
|
|
1001
1001
|
const s = e.numSplats, n = new Float32Array(
|
|
1002
1002
|
this.textureWidth * this.textureHeight * 4
|
|
1003
1003
|
);
|
|
1004
|
-
for (let
|
|
1005
|
-
const a =
|
|
1004
|
+
for (let t = 0; t < s; t++) {
|
|
1005
|
+
const a = t * 4, c = t * 3, l = t * 4;
|
|
1006
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
1007
|
}
|
|
1008
|
-
const
|
|
1008
|
+
const r = new i.DataTexture(
|
|
1009
1009
|
n,
|
|
1010
1010
|
this.textureWidth,
|
|
1011
1011
|
this.textureHeight,
|
|
1012
1012
|
i.RGBAFormat,
|
|
1013
1013
|
i.FloatType
|
|
1014
1014
|
);
|
|
1015
|
-
return
|
|
1015
|
+
return r.needsUpdate = !0, r.magFilter = i.NearestFilter, r.minFilter = i.NearestFilter, r;
|
|
1016
1016
|
}
|
|
1017
1017
|
/**
|
|
1018
1018
|
* Create the color texture (RGB and opacity)
|
|
@@ -1023,18 +1023,18 @@ class Oe {
|
|
|
1023
1023
|
const s = e.numSplats, n = new Float32Array(
|
|
1024
1024
|
this.textureWidth * this.textureHeight * 4
|
|
1025
1025
|
);
|
|
1026
|
-
for (let
|
|
1027
|
-
const a =
|
|
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[
|
|
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
1029
|
}
|
|
1030
|
-
const
|
|
1030
|
+
const r = new i.DataTexture(
|
|
1031
1031
|
n,
|
|
1032
1032
|
this.textureWidth,
|
|
1033
1033
|
this.textureHeight,
|
|
1034
1034
|
i.RGBAFormat,
|
|
1035
1035
|
i.FloatType
|
|
1036
1036
|
);
|
|
1037
|
-
return
|
|
1037
|
+
return r.needsUpdate = !0, r;
|
|
1038
1038
|
}
|
|
1039
1039
|
/**
|
|
1040
1040
|
* Create the order texture for sorting
|
|
@@ -1043,8 +1043,8 @@ class Oe {
|
|
|
1043
1043
|
*/
|
|
1044
1044
|
createOrderTexture(e) {
|
|
1045
1045
|
const s = new Uint32Array(this.textureWidth * this.textureHeight);
|
|
1046
|
-
for (let
|
|
1047
|
-
s[
|
|
1046
|
+
for (let r = 0; r < e; r++)
|
|
1047
|
+
s[r] = r;
|
|
1048
1048
|
const n = new i.DataTexture(
|
|
1049
1049
|
s,
|
|
1050
1050
|
this.textureWidth,
|
|
@@ -1058,7 +1058,7 @@ class Oe {
|
|
|
1058
1058
|
this.transformA.dispose(), this.transformB.dispose(), this.colorTexture.dispose(), this.orderTexture.dispose();
|
|
1059
1059
|
}
|
|
1060
1060
|
}
|
|
1061
|
-
const
|
|
1061
|
+
const Pe = (
|
|
1062
1062
|
/* glsl */
|
|
1063
1063
|
`
|
|
1064
1064
|
precision highp float;
|
|
@@ -1264,6 +1264,10 @@ void main(void) {
|
|
|
1264
1264
|
float l1 = sqrt(lambda1) * scaleFactor; // scaleX
|
|
1265
1265
|
float l2 = sqrt(lambda2) * scaleFactor; // scaleY
|
|
1266
1266
|
|
|
1267
|
+
float vmin = min(512.0, min(viewport.x, viewport.y));
|
|
1268
|
+
l1 = min(l1, 2.0 * vmin);
|
|
1269
|
+
l2 = min(l2, 2.0 * vmin);
|
|
1270
|
+
|
|
1267
1271
|
// Early out tiny splats
|
|
1268
1272
|
if (l1 < 2.0 && l2 < 2.0) { // Check if smaller than ~2 pixel
|
|
1269
1273
|
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
@@ -1274,14 +1278,15 @@ void main(void) {
|
|
|
1274
1278
|
vec2 v1_scaled = l1 * v1_eigen;
|
|
1275
1279
|
vec2 v2_scaled = l2 * v2_eigen;
|
|
1276
1280
|
|
|
1277
|
-
// --- FRUSTUM CHECK
|
|
1281
|
+
// --- FRUSTUM CHECK (laxo, estilo PlayCanvas) ---
|
|
1278
1282
|
|
|
1279
|
-
vec2
|
|
1283
|
+
vec2 c = centerClip.ww / viewport; // pixel to clip
|
|
1284
|
+
float r = max(l1, l2); // radius in pixels
|
|
1280
1285
|
|
|
1281
|
-
//
|
|
1282
|
-
if (any(greaterThan(abs(centerClip.xy)
|
|
1283
|
-
|
|
1284
|
-
|
|
1286
|
+
// Remove if the center - radius is already out of -w..w
|
|
1287
|
+
if (any(greaterThan(abs(centerClip.xy) - vec2(r) * c, centerClip.ww))) {
|
|
1288
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
1289
|
+
return;
|
|
1285
1290
|
}
|
|
1286
1291
|
|
|
1287
1292
|
// --- END FRUSTUM CHECK ---
|
|
@@ -1311,7 +1316,7 @@ void main(void) {
|
|
|
1311
1316
|
vUv = clippedCornerOffset;
|
|
1312
1317
|
}
|
|
1313
1318
|
`
|
|
1314
|
-
),
|
|
1319
|
+
), Oe = (
|
|
1315
1320
|
/* glsl */
|
|
1316
1321
|
`
|
|
1317
1322
|
precision highp float;
|
|
@@ -1319,6 +1324,14 @@ precision highp float;
|
|
|
1319
1324
|
varying vec4 vColor; // Color and opacity passed from vertex shader
|
|
1320
1325
|
varying vec2 vUv; // Quad UV coordinates (-1 to 1) passed from vertex shader
|
|
1321
1326
|
|
|
1327
|
+
// Fast approximate e^x based on https://nic.schraudolph.org/pubs/Schraudolph99.pdf
|
|
1328
|
+
const float EXP_A = 12102203.0; // ≈ 2^23 / ln(2)
|
|
1329
|
+
const int EXP_BC_RMS = 1064866808; // (127 << 23) - 60801 * 8
|
|
1330
|
+
float fastExp(float x) {
|
|
1331
|
+
int i = int(EXP_A * x) + EXP_BC_RMS;
|
|
1332
|
+
return intBitsToFloat(i);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1322
1335
|
void main(void) {
|
|
1323
1336
|
|
|
1324
1337
|
float distSq = dot(vUv, vUv); // Calculate squared distance from center (in the quad's coordinate system)
|
|
@@ -1328,7 +1341,7 @@ void main(void) {
|
|
|
1328
1341
|
// The factor 4.0 corresponds to the original implementation's scaling.
|
|
1329
1342
|
// factor = 1 / (2 * sigma^2), where sigma controls the spread.
|
|
1330
1343
|
// Using 4.0 implies sigma^2 = 1/8.
|
|
1331
|
-
float alpha =
|
|
1344
|
+
float alpha = fastExp(-distSq * 4.0) * vColor.a;
|
|
1332
1345
|
|
|
1333
1346
|
if (alpha < 1.0 / 255.0) discard; // Discard fragments with very low alpha
|
|
1334
1347
|
|
|
@@ -1337,7 +1350,7 @@ void main(void) {
|
|
|
1337
1350
|
}
|
|
1338
1351
|
`
|
|
1339
1352
|
);
|
|
1340
|
-
class
|
|
1353
|
+
class Be extends i.ShaderMaterial {
|
|
1341
1354
|
constructor(e = {}) {
|
|
1342
1355
|
const s = {
|
|
1343
1356
|
// Textures (values set via methods)
|
|
@@ -1352,8 +1365,8 @@ class De extends i.ShaderMaterial {
|
|
|
1352
1365
|
// Max splats to render (updated by sorter)
|
|
1353
1366
|
};
|
|
1354
1367
|
super({
|
|
1355
|
-
vertexShader:
|
|
1356
|
-
fragmentShader:
|
|
1368
|
+
vertexShader: Pe,
|
|
1369
|
+
fragmentShader: Oe,
|
|
1357
1370
|
uniforms: s,
|
|
1358
1371
|
transparent: !0,
|
|
1359
1372
|
blending: i.CustomBlending,
|
|
@@ -1432,18 +1445,18 @@ const K = class K extends i.Mesh {
|
|
|
1432
1445
|
* @param options Rendering options
|
|
1433
1446
|
*/
|
|
1434
1447
|
constructor(s, n = {}) {
|
|
1435
|
-
const
|
|
1436
|
-
super(
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
this.geometry =
|
|
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();
|
|
1447
1460
|
let a = this.createChunks() || void 0;
|
|
1448
1461
|
a === null && console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."), a = void 0, this.sorter.init(
|
|
1449
1462
|
this.textureManager.orderTexture,
|
|
@@ -1464,7 +1477,7 @@ const K = class K extends i.Mesh {
|
|
|
1464
1477
|
* @returns InstancedBufferGeometry
|
|
1465
1478
|
*/
|
|
1466
1479
|
static createInstancedGeometry(s, n) {
|
|
1467
|
-
const
|
|
1480
|
+
const r = Math.ceil(s / n), t = new i.BufferGeometry(), a = new Float32Array([
|
|
1468
1481
|
// x, y, splat_index_in_instance
|
|
1469
1482
|
-1,
|
|
1470
1483
|
-1,
|
|
@@ -1481,19 +1494,19 @@ const K = class K extends i.Mesh {
|
|
|
1481
1494
|
]), c = new Uint16Array([0, 1, 2, 0, 2, 3]), l = new Float32Array(4 * 3 * n);
|
|
1482
1495
|
for (let p = 0; p < n; p++) {
|
|
1483
1496
|
const x = p * 4 * 3;
|
|
1484
|
-
for (let
|
|
1485
|
-
l[x +
|
|
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;
|
|
1486
1499
|
}
|
|
1487
1500
|
const m = new Uint32Array(6 * n);
|
|
1488
1501
|
for (let p = 0; p < n; p++) {
|
|
1489
|
-
const x = p * 6,
|
|
1490
|
-
m[x + 0] = c[0] +
|
|
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;
|
|
1491
1504
|
}
|
|
1492
|
-
|
|
1505
|
+
t.setAttribute("position", new i.BufferAttribute(l, 3)), t.setIndex(new i.BufferAttribute(m, 1));
|
|
1493
1506
|
const S = new i.InstancedBufferGeometry();
|
|
1494
|
-
S.index =
|
|
1495
|
-
const b = new Uint32Array(
|
|
1496
|
-
for (let p = 0; p <
|
|
1507
|
+
S.index = t.index, S.setAttribute("position", t.getAttribute("position"));
|
|
1508
|
+
const b = new Uint32Array(r);
|
|
1509
|
+
for (let p = 0; p < r; p++)
|
|
1497
1510
|
b[p] = p * n;
|
|
1498
1511
|
return S.setAttribute("splatInstanceIndex", new i.InstancedBufferAttribute(b, 1, !1)), S.instanceCount = 0, S;
|
|
1499
1512
|
}
|
|
@@ -1525,10 +1538,10 @@ const K = class K extends i.Mesh {
|
|
|
1525
1538
|
* @param camera The camera to sort against.
|
|
1526
1539
|
*/
|
|
1527
1540
|
sort(s) {
|
|
1528
|
-
const n = new i.Vector3(),
|
|
1529
|
-
s.getWorldPosition(n), s.getWorldDirection(
|
|
1530
|
-
const
|
|
1531
|
-
this.options.autoSort && (c || l) && (this.lastCameraPositionLocal.copy(
|
|
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));
|
|
1532
1545
|
}
|
|
1533
1546
|
/**
|
|
1534
1547
|
* THREE.js hook called before rendering the object.
|
|
@@ -1539,10 +1552,10 @@ const K = class K extends i.Mesh {
|
|
|
1539
1552
|
*/
|
|
1540
1553
|
// prettier-ignore
|
|
1541
1554
|
// @ts-expect-error scene is not used
|
|
1542
|
-
onBeforeRender(s, n,
|
|
1543
|
-
this.sort(
|
|
1544
|
-
const
|
|
1545
|
-
let { width: a, height: c } =
|
|
1555
|
+
onBeforeRender(s, n, r) {
|
|
1556
|
+
this.sort(r);
|
|
1557
|
+
const t = s.getSize(new i.Vector2());
|
|
1558
|
+
let { width: a, height: c } = t;
|
|
1546
1559
|
const l = s.xr;
|
|
1547
1560
|
if (l.enabled && l.isPresenting) {
|
|
1548
1561
|
const m = l.getCamera().cameras[0].view;
|
|
@@ -1559,29 +1572,34 @@ const K = class K extends i.Mesh {
|
|
|
1559
1572
|
};
|
|
1560
1573
|
// Cached inverse matrix
|
|
1561
1574
|
/** Number of splats combined into a single instanced draw call. */
|
|
1562
|
-
|
|
1563
|
-
let ae = K
|
|
1564
|
-
|
|
1575
|
+
g(K, "INSTANCE_SIZE", 128);
|
|
1576
|
+
let ae = K;
|
|
1577
|
+
const Fe = Symbol.for("@speridlabs/visus/SplatMesh");
|
|
1578
|
+
try {
|
|
1579
|
+
Object.defineProperty(ae.prototype, Fe, {
|
|
1580
|
+
value: !0,
|
|
1581
|
+
configurable: !1,
|
|
1582
|
+
enumerable: !1,
|
|
1583
|
+
writable: !1
|
|
1584
|
+
});
|
|
1585
|
+
} catch {
|
|
1586
|
+
console.warn("Couldn't define Visus SplatMesh symbol");
|
|
1587
|
+
}
|
|
1565
1588
|
const je = ({
|
|
1566
|
-
plyUrl:
|
|
1589
|
+
plyUrl: M,
|
|
1567
1590
|
splatOptions: e = {},
|
|
1568
1591
|
...s
|
|
1569
1592
|
}) => {
|
|
1570
|
-
const n = ve(null),
|
|
1571
|
-
() =>
|
|
1572
|
-
[
|
|
1593
|
+
const n = ve(null), r = be(Ee, M), t = ge(
|
|
1594
|
+
() => new ae(r, e || {}),
|
|
1595
|
+
[r, e]
|
|
1573
1596
|
);
|
|
1574
|
-
return
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
"Visus: The 'Splat' component's internal mesh ref is not an instance of the core SplatMesh. This usually means `extend` was not called correctly. Please ensure you have called `extend({ splatPrimitive: SplatMesh })` in your R3F setup, where 'SplatMesh' is the class imported from 'visus' (or 'visus/react')."
|
|
1578
|
-
), () => {
|
|
1579
|
-
a && typeof a.dispose == "function" && a.dispose();
|
|
1580
|
-
};
|
|
1581
|
-
}, []), /* @__PURE__ */ Ee.jsx("splatPrimitive", { ref: n, args: r, ...s });
|
|
1597
|
+
return we(() => () => {
|
|
1598
|
+
typeof (t == null ? void 0 : t.dispose) == "function" && t.dispose();
|
|
1599
|
+
}, [t]), /* @__PURE__ */ Me.jsx("primitive", { ref: n, object: t, ...s });
|
|
1582
1600
|
};
|
|
1583
1601
|
export {
|
|
1584
|
-
|
|
1602
|
+
Ee as PlyLoader,
|
|
1585
1603
|
je as Splat,
|
|
1586
1604
|
ae as SplatMesh
|
|
1587
1605
|
};
|