@speridlabs/visus 2.1.1 → 2.3.0
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/README.md +1 -0
- package/dist/main.es.js +1 -0
- package/dist/main.umd.js +1 -1
- package/dist/react.es.js +536 -533
- package/package.json +1 -1
package/dist/react.es.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import { useLoader as Ae } from "@react-three/fiber";
|
|
1
|
+
var be = Object.defineProperty;
|
|
2
|
+
var Se = (x, e, o) => e in x ? be(x, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : x[e] = o;
|
|
3
|
+
var f = (x, e, o) => Se(x, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
import Me, { useState as Ce, useRef as Ae, useEffect as Te } from "react";
|
|
6
5
|
import * as l from "three";
|
|
7
6
|
var ce = { exports: {} }, ae = {};
|
|
8
7
|
/**
|
|
@@ -14,27 +13,27 @@ var ce = { exports: {} }, ae = {};
|
|
|
14
13
|
* This source code is licensed under the MIT license found in the
|
|
15
14
|
* LICENSE file in the root directory of this source tree.
|
|
16
15
|
*/
|
|
17
|
-
var
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
function
|
|
16
|
+
var me;
|
|
17
|
+
function _e() {
|
|
18
|
+
if (me) return ae;
|
|
19
|
+
me = 1;
|
|
20
|
+
var x = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
21
|
+
function o(t, r, n) {
|
|
23
22
|
var a = null;
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
for (var i in
|
|
27
|
-
i !== "key" && (
|
|
28
|
-
} else
|
|
29
|
-
return
|
|
30
|
-
$$typeof:
|
|
31
|
-
type:
|
|
23
|
+
if (n !== void 0 && (a = "" + n), r.key !== void 0 && (a = "" + r.key), "key" in r) {
|
|
24
|
+
n = {};
|
|
25
|
+
for (var i in r)
|
|
26
|
+
i !== "key" && (n[i] = r[i]);
|
|
27
|
+
} else n = r;
|
|
28
|
+
return r = n.ref, {
|
|
29
|
+
$$typeof: x,
|
|
30
|
+
type: t,
|
|
32
31
|
key: a,
|
|
33
|
-
ref:
|
|
34
|
-
props:
|
|
32
|
+
ref: r !== void 0 ? r : null,
|
|
33
|
+
props: n
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
|
-
return ae.Fragment = e, ae.jsx =
|
|
36
|
+
return ae.Fragment = e, ae.jsx = o, ae.jsxs = o, ae;
|
|
38
37
|
}
|
|
39
38
|
var ie = {};
|
|
40
39
|
/**
|
|
@@ -46,24 +45,24 @@ var ie = {};
|
|
|
46
45
|
* This source code is licensed under the MIT license found in the
|
|
47
46
|
* LICENSE file in the root directory of this source tree.
|
|
48
47
|
*/
|
|
49
|
-
var
|
|
50
|
-
function
|
|
51
|
-
return
|
|
52
|
-
function
|
|
48
|
+
var xe;
|
|
49
|
+
function ke() {
|
|
50
|
+
return xe || (xe = 1, process.env.NODE_ENV !== "production" && function() {
|
|
51
|
+
function x(s) {
|
|
53
52
|
if (s == null) return null;
|
|
54
53
|
if (typeof s == "function")
|
|
55
|
-
return s.$$typeof ===
|
|
54
|
+
return s.$$typeof === v ? null : s.displayName || s.name || null;
|
|
56
55
|
if (typeof s == "string") return s;
|
|
57
56
|
switch (s) {
|
|
58
57
|
case I:
|
|
59
58
|
return "Fragment";
|
|
60
59
|
case j:
|
|
61
60
|
return "Profiler";
|
|
62
|
-
case
|
|
61
|
+
case P:
|
|
63
62
|
return "StrictMode";
|
|
64
|
-
case
|
|
63
|
+
case L:
|
|
65
64
|
return "Suspense";
|
|
66
|
-
case
|
|
65
|
+
case A:
|
|
67
66
|
return "SuspenseList";
|
|
68
67
|
case T:
|
|
69
68
|
return "Activity";
|
|
@@ -72,21 +71,21 @@ function Ce() {
|
|
|
72
71
|
switch (typeof s.tag == "number" && console.error(
|
|
73
72
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
74
73
|
), s.$$typeof) {
|
|
75
|
-
case
|
|
74
|
+
case S:
|
|
76
75
|
return "Portal";
|
|
77
|
-
case
|
|
76
|
+
case W:
|
|
78
77
|
return (s.displayName || "Context") + ".Provider";
|
|
79
78
|
case H:
|
|
80
79
|
return (s._context.displayName || "Context") + ".Consumer";
|
|
81
|
-
case
|
|
80
|
+
case oe:
|
|
82
81
|
var p = s.render;
|
|
83
82
|
return s = s.displayName, s || (s = p.displayName || p.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
|
|
84
|
-
case
|
|
85
|
-
return p = s.displayName || null, p !== null ? p :
|
|
83
|
+
case g:
|
|
84
|
+
return p = s.displayName || null, p !== null ? p : x(s.type) || "Memo";
|
|
86
85
|
case D:
|
|
87
86
|
p = s._payload, s = s._init;
|
|
88
87
|
try {
|
|
89
|
-
return
|
|
88
|
+
return x(s(p));
|
|
90
89
|
} catch {
|
|
91
90
|
}
|
|
92
91
|
}
|
|
@@ -95,7 +94,7 @@ function Ce() {
|
|
|
95
94
|
function e(s) {
|
|
96
95
|
return "" + s;
|
|
97
96
|
}
|
|
98
|
-
function
|
|
97
|
+
function o(s) {
|
|
99
98
|
try {
|
|
100
99
|
e(s);
|
|
101
100
|
var p = !1;
|
|
@@ -104,30 +103,30 @@ function Ce() {
|
|
|
104
103
|
}
|
|
105
104
|
if (p) {
|
|
106
105
|
p = console;
|
|
107
|
-
var
|
|
108
|
-
return
|
|
106
|
+
var M = p.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
|
|
107
|
+
return M.call(
|
|
109
108
|
p,
|
|
110
109
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
111
110
|
E
|
|
112
111
|
), e(s);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
|
-
function
|
|
114
|
+
function t(s) {
|
|
116
115
|
if (s === I) return "<>";
|
|
117
116
|
if (typeof s == "object" && s !== null && s.$$typeof === D)
|
|
118
117
|
return "<...>";
|
|
119
118
|
try {
|
|
120
|
-
var p =
|
|
119
|
+
var p = x(s);
|
|
121
120
|
return p ? "<" + p + ">" : "<...>";
|
|
122
121
|
} catch {
|
|
123
122
|
return "<...>";
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
|
-
function
|
|
125
|
+
function r() {
|
|
127
126
|
var s = R.A;
|
|
128
127
|
return s === null ? null : s.getOwner();
|
|
129
128
|
}
|
|
130
|
-
function
|
|
129
|
+
function n() {
|
|
131
130
|
return Error("react-stack-top-frame");
|
|
132
131
|
}
|
|
133
132
|
function a(s) {
|
|
@@ -138,31 +137,31 @@ function Ce() {
|
|
|
138
137
|
return s.key !== void 0;
|
|
139
138
|
}
|
|
140
139
|
function i(s, p) {
|
|
141
|
-
function
|
|
140
|
+
function M() {
|
|
142
141
|
Z || (Z = !0, console.error(
|
|
143
142
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
144
143
|
p
|
|
145
144
|
));
|
|
146
145
|
}
|
|
147
|
-
|
|
148
|
-
get:
|
|
146
|
+
M.isReactWarning = !0, Object.defineProperty(s, "key", {
|
|
147
|
+
get: M,
|
|
149
148
|
configurable: !0
|
|
150
149
|
});
|
|
151
150
|
}
|
|
152
151
|
function u() {
|
|
153
|
-
var s =
|
|
152
|
+
var s = x(this.type);
|
|
154
153
|
return U[s] || (U[s] = !0, console.error(
|
|
155
154
|
"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
155
|
)), s = this.props.ref, s !== void 0 ? s : null;
|
|
157
156
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
160
|
-
$$typeof:
|
|
157
|
+
function w(s, p, M, E, m, c, y, z) {
|
|
158
|
+
return M = c.ref, s = {
|
|
159
|
+
$$typeof: b,
|
|
161
160
|
type: s,
|
|
162
161
|
key: p,
|
|
163
162
|
props: c,
|
|
164
163
|
_owner: m
|
|
165
|
-
}, (
|
|
164
|
+
}, (M !== void 0 ? M : null) !== null ? Object.defineProperty(s, "ref", {
|
|
166
165
|
enumerable: !1,
|
|
167
166
|
get: u
|
|
168
167
|
}) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
|
|
@@ -179,33 +178,33 @@ function Ce() {
|
|
|
179
178
|
configurable: !1,
|
|
180
179
|
enumerable: !1,
|
|
181
180
|
writable: !0,
|
|
182
|
-
value:
|
|
181
|
+
value: y
|
|
183
182
|
}), Object.defineProperty(s, "_debugTask", {
|
|
184
183
|
configurable: !1,
|
|
185
184
|
enumerable: !1,
|
|
186
185
|
writable: !0,
|
|
187
|
-
value:
|
|
186
|
+
value: z
|
|
188
187
|
}), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
|
|
189
188
|
}
|
|
190
|
-
function
|
|
191
|
-
var
|
|
192
|
-
if (
|
|
189
|
+
function C(s, p, M, E, m, c, y, z) {
|
|
190
|
+
var d = p.children;
|
|
191
|
+
if (d !== void 0)
|
|
193
192
|
if (E)
|
|
194
|
-
if (
|
|
195
|
-
for (E = 0; E <
|
|
196
|
-
|
|
197
|
-
Object.freeze && Object.freeze(
|
|
193
|
+
if ($(d)) {
|
|
194
|
+
for (E = 0; E < d.length; E++)
|
|
195
|
+
_(d[E]);
|
|
196
|
+
Object.freeze && Object.freeze(d);
|
|
198
197
|
} else
|
|
199
198
|
console.error(
|
|
200
199
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
201
200
|
);
|
|
202
|
-
else
|
|
201
|
+
else _(d);
|
|
203
202
|
if (B.call(p, "key")) {
|
|
204
|
-
|
|
205
|
-
var k = Object.keys(p).filter(function(
|
|
206
|
-
return
|
|
203
|
+
d = x(s);
|
|
204
|
+
var k = Object.keys(p).filter(function(q) {
|
|
205
|
+
return q !== "key";
|
|
207
206
|
});
|
|
208
|
-
E = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", te[
|
|
207
|
+
E = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", te[d + E] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
209
208
|
`A props object containing a "key" prop is being spread into JSX:
|
|
210
209
|
let props = %s;
|
|
211
210
|
<%s {...props} />
|
|
@@ -213,84 +212,84 @@ React keys must be passed directly to JSX without using spread:
|
|
|
213
212
|
let props = %s;
|
|
214
213
|
<%s key={someKey} {...props} />`,
|
|
215
214
|
E,
|
|
216
|
-
|
|
215
|
+
d,
|
|
217
216
|
k,
|
|
218
|
-
|
|
219
|
-
), te[
|
|
217
|
+
d
|
|
218
|
+
), te[d + E] = !0);
|
|
220
219
|
}
|
|
221
|
-
if (
|
|
222
|
-
|
|
220
|
+
if (d = null, M !== void 0 && (o(M), d = "" + M), a(p) && (o(p.key), d = "" + p.key), "key" in p) {
|
|
221
|
+
M = {};
|
|
223
222
|
for (var O in p)
|
|
224
|
-
O !== "key" && (
|
|
225
|
-
} else
|
|
226
|
-
return
|
|
227
|
-
|
|
223
|
+
O !== "key" && (M[O] = p[O]);
|
|
224
|
+
} else M = p;
|
|
225
|
+
return d && i(
|
|
226
|
+
M,
|
|
228
227
|
typeof s == "function" ? s.displayName || s.name || "Unknown" : s
|
|
229
|
-
),
|
|
228
|
+
), w(
|
|
230
229
|
s,
|
|
231
|
-
|
|
230
|
+
d,
|
|
232
231
|
c,
|
|
233
232
|
m,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
r(),
|
|
234
|
+
M,
|
|
235
|
+
y,
|
|
236
|
+
z
|
|
238
237
|
);
|
|
239
238
|
}
|
|
240
|
-
function
|
|
241
|
-
typeof s == "object" && s !== null && s.$$typeof ===
|
|
239
|
+
function _(s) {
|
|
240
|
+
typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
|
|
242
241
|
}
|
|
243
|
-
var
|
|
242
|
+
var h = Me, b = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), I = Symbol.for("react.fragment"), P = Symbol.for("react.strict_mode"), j = Symbol.for("react.profiler"), H = Symbol.for("react.consumer"), W = Symbol.for("react.context"), oe = Symbol.for("react.forward_ref"), L = Symbol.for("react.suspense"), A = Symbol.for("react.suspense_list"), g = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), T = Symbol.for("react.activity"), v = Symbol.for("react.client.reference"), R = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, $ = Array.isArray, X = console.createTask ? console.createTask : function() {
|
|
244
243
|
return null;
|
|
245
244
|
};
|
|
246
|
-
|
|
245
|
+
h = {
|
|
247
246
|
"react-stack-bottom-frame": function(s) {
|
|
248
247
|
return s();
|
|
249
248
|
}
|
|
250
249
|
};
|
|
251
|
-
var Z, U = {}, F =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
)(), N =
|
|
255
|
-
ie.Fragment = I, ie.jsx = function(s, p,
|
|
250
|
+
var Z, U = {}, F = h["react-stack-bottom-frame"].bind(
|
|
251
|
+
h,
|
|
252
|
+
n
|
|
253
|
+
)(), N = X(t(n)), te = {};
|
|
254
|
+
ie.Fragment = I, ie.jsx = function(s, p, M, E, m) {
|
|
256
255
|
var c = 1e4 > R.recentlyCreatedOwnerStacks++;
|
|
257
|
-
return
|
|
256
|
+
return C(
|
|
258
257
|
s,
|
|
259
258
|
p,
|
|
260
|
-
|
|
259
|
+
M,
|
|
261
260
|
!1,
|
|
262
261
|
E,
|
|
263
262
|
m,
|
|
264
263
|
c ? Error("react-stack-top-frame") : F,
|
|
265
|
-
c ?
|
|
264
|
+
c ? X(t(s)) : N
|
|
266
265
|
);
|
|
267
|
-
}, ie.jsxs = function(s, p,
|
|
266
|
+
}, ie.jsxs = function(s, p, M, E, m) {
|
|
268
267
|
var c = 1e4 > R.recentlyCreatedOwnerStacks++;
|
|
269
|
-
return
|
|
268
|
+
return C(
|
|
270
269
|
s,
|
|
271
270
|
p,
|
|
272
|
-
|
|
271
|
+
M,
|
|
273
272
|
!0,
|
|
274
273
|
E,
|
|
275
274
|
m,
|
|
276
275
|
c ? Error("react-stack-top-frame") : F,
|
|
277
|
-
c ?
|
|
276
|
+
c ? X(t(s)) : N
|
|
278
277
|
);
|
|
279
278
|
};
|
|
280
279
|
}()), ie;
|
|
281
280
|
}
|
|
282
|
-
var
|
|
283
|
-
function
|
|
284
|
-
return
|
|
281
|
+
var ge;
|
|
282
|
+
function Ee() {
|
|
283
|
+
return ge || (ge = 1, process.env.NODE_ENV === "production" ? ce.exports = _e() : ce.exports = ke()), ce.exports;
|
|
285
284
|
}
|
|
286
|
-
var
|
|
285
|
+
var Ie = Ee();
|
|
287
286
|
class fe {
|
|
288
287
|
constructor() {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
288
|
+
f(this, "min", new l.Vector3(1 / 0, 1 / 0, 1 / 0));
|
|
289
|
+
f(this, "max", new l.Vector3(-1 / 0, -1 / 0, -1 / 0));
|
|
290
|
+
f(this, "center", new l.Vector3());
|
|
292
291
|
/** Half extents (size/2) */
|
|
293
|
-
|
|
292
|
+
f(this, "halfExtents", new l.Vector3());
|
|
294
293
|
}
|
|
295
294
|
/**
|
|
296
295
|
* Reset the bounding box to its initial state
|
|
@@ -342,16 +341,16 @@ class fe {
|
|
|
342
341
|
return e.min.copy(this.min), e.max.copy(this.max), e.center.copy(this.center), e.halfExtents.copy(this.halfExtents), e;
|
|
343
342
|
}
|
|
344
343
|
}
|
|
345
|
-
class
|
|
344
|
+
class Re {
|
|
346
345
|
// TODO: there is no sh spherical harmonics
|
|
347
346
|
constructor(e = 0) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
347
|
+
f(this, "numSplats", 0);
|
|
348
|
+
f(this, "positions");
|
|
349
|
+
f(this, "rotations");
|
|
350
|
+
f(this, "scales");
|
|
351
|
+
f(this, "colors");
|
|
352
|
+
f(this, "opacities");
|
|
353
|
+
f(this, "boundingBox", new fe());
|
|
355
354
|
this.numSplats = e, this.allocateBuffers(e);
|
|
356
355
|
}
|
|
357
356
|
allocateBuffers(e) {
|
|
@@ -366,13 +365,13 @@ class Ie {
|
|
|
366
365
|
* @param color Color
|
|
367
366
|
* @param opacity Opacity value
|
|
368
367
|
*/
|
|
369
|
-
setSplat(e,
|
|
368
|
+
setSplat(e, o, t, r, n, a) {
|
|
370
369
|
if (e >= this.numSplats)
|
|
371
370
|
throw new Error(
|
|
372
371
|
`Splat index out of bounds: ${e} >= ${this.numSplats}`
|
|
373
372
|
);
|
|
374
|
-
const i = e * 3, u = e * 4,
|
|
375
|
-
this.positions[i] =
|
|
373
|
+
const i = e * 3, u = e * 4, w = e * 3, C = e * 3;
|
|
374
|
+
this.positions[i] = o.x, this.positions[i + 1] = o.y, this.positions[i + 2] = o.z, this.rotations[u] = t.x, this.rotations[u + 1] = t.y, this.rotations[u + 2] = t.z, this.rotations[u + 3] = t.w, this.scales[w] = r.x, this.scales[w + 1] = r.y, this.scales[w + 2] = r.z, this.colors[C] = n.r, this.colors[C + 1] = n.g, this.colors[C + 2] = n.b, this.opacities[e] = a;
|
|
376
375
|
}
|
|
377
376
|
/**
|
|
378
377
|
* Get a splat's data
|
|
@@ -384,29 +383,29 @@ class Ie {
|
|
|
384
383
|
throw new Error(
|
|
385
384
|
`Splat index out of bounds: ${e} >= ${this.numSplats}`
|
|
386
385
|
);
|
|
387
|
-
const
|
|
386
|
+
const o = e * 3, t = e * 4, r = e * 3, n = e * 3;
|
|
388
387
|
return {
|
|
389
388
|
position: new l.Vector3(
|
|
390
|
-
this.positions[
|
|
391
|
-
this.positions[
|
|
392
|
-
this.positions[
|
|
389
|
+
this.positions[o],
|
|
390
|
+
this.positions[o + 1],
|
|
391
|
+
this.positions[o + 2]
|
|
393
392
|
),
|
|
394
393
|
rotation: new l.Quaternion(
|
|
395
|
-
this.rotations[
|
|
396
|
-
this.rotations[
|
|
397
|
-
this.rotations[
|
|
398
|
-
this.rotations[
|
|
394
|
+
this.rotations[t],
|
|
395
|
+
this.rotations[t + 1],
|
|
396
|
+
this.rotations[t + 2],
|
|
397
|
+
this.rotations[t + 3]
|
|
399
398
|
),
|
|
400
399
|
// Convert log scale back to linear scale for external use
|
|
401
400
|
scale: new l.Vector3(
|
|
402
|
-
Math.exp(this.scales[
|
|
403
|
-
Math.exp(this.scales[
|
|
404
|
-
Math.exp(this.scales[
|
|
401
|
+
Math.exp(this.scales[r]),
|
|
402
|
+
Math.exp(this.scales[r + 1]),
|
|
403
|
+
Math.exp(this.scales[r + 2])
|
|
405
404
|
),
|
|
406
405
|
color: new l.Color(
|
|
407
|
-
this.colors[
|
|
408
|
-
this.colors[
|
|
409
|
-
this.colors[
|
|
406
|
+
this.colors[n],
|
|
407
|
+
this.colors[n + 1],
|
|
408
|
+
this.colors[n + 2]
|
|
410
409
|
),
|
|
411
410
|
opacity: this.opacities[e]
|
|
412
411
|
};
|
|
@@ -418,12 +417,12 @@ class Ie {
|
|
|
418
417
|
calculateBoundingBox() {
|
|
419
418
|
this.boundingBox.reset();
|
|
420
419
|
const e = new l.Vector3();
|
|
421
|
-
for (let
|
|
422
|
-
const
|
|
420
|
+
for (let o = 0; o < this.numSplats; o++) {
|
|
421
|
+
const t = o * 3;
|
|
423
422
|
e.set(
|
|
424
|
-
this.positions[
|
|
425
|
-
this.positions[
|
|
426
|
-
this.positions[
|
|
423
|
+
this.positions[t],
|
|
424
|
+
this.positions[t + 1],
|
|
425
|
+
this.positions[t + 2]
|
|
427
426
|
), this.boundingBox.expandByPoint(e);
|
|
428
427
|
}
|
|
429
428
|
return this.boundingBox;
|
|
@@ -438,19 +437,19 @@ class Ie {
|
|
|
438
437
|
"position",
|
|
439
438
|
new l.BufferAttribute(this.positions, 3)
|
|
440
439
|
);
|
|
441
|
-
const
|
|
442
|
-
for (let
|
|
443
|
-
const a =
|
|
444
|
-
|
|
440
|
+
const o = new Float32Array(this.numSplats * 3), t = new l.Quaternion(), r = new l.Euler();
|
|
441
|
+
for (let n = 0; n < this.numSplats; n++) {
|
|
442
|
+
const a = n * 4, i = n * 3;
|
|
443
|
+
t.set(
|
|
445
444
|
this.rotations[a],
|
|
446
445
|
this.rotations[a + 1],
|
|
447
446
|
this.rotations[a + 2],
|
|
448
447
|
this.rotations[a + 3]
|
|
449
|
-
),
|
|
448
|
+
), r.setFromQuaternion(t), o[i] = r.x, o[i + 1] = r.y, o[i + 2] = r.z;
|
|
450
449
|
}
|
|
451
450
|
return e.setAttribute(
|
|
452
451
|
"rotation",
|
|
453
|
-
new l.BufferAttribute(
|
|
452
|
+
new l.BufferAttribute(o, 3)
|
|
454
453
|
), e.setAttribute(
|
|
455
454
|
"scale",
|
|
456
455
|
new l.BufferAttribute(this.scales, 3)
|
|
@@ -463,34 +462,35 @@ class Ie {
|
|
|
463
462
|
), e;
|
|
464
463
|
}
|
|
465
464
|
}
|
|
466
|
-
class
|
|
467
|
-
constructor(
|
|
468
|
-
super(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
this.
|
|
465
|
+
class ze extends l.Loader {
|
|
466
|
+
constructor(o) {
|
|
467
|
+
super(o);
|
|
468
|
+
f(this, "requestId", 0);
|
|
469
|
+
f(this, "worker");
|
|
470
|
+
f(this, "pendingCallbacks", /* @__PURE__ */ new Map());
|
|
471
|
+
this.withCredentials = !0;
|
|
472
|
+
const t = this.createWorkerCode(), r = new Blob([t], { type: "application/javascript" });
|
|
473
|
+
this.worker = new Worker(URL.createObjectURL(r)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
474
474
|
}
|
|
475
475
|
/**
|
|
476
476
|
* Handles messages received from the parsing worker
|
|
477
477
|
* @param event The message event from the worker
|
|
478
478
|
*/
|
|
479
|
-
onWorkerMessage(
|
|
480
|
-
const { requestId:
|
|
481
|
-
if (!a) return console.warn(`PlyLoader: Received response for unknown request ${
|
|
482
|
-
if (this.pendingCallbacks.delete(
|
|
483
|
-
if (!
|
|
479
|
+
onWorkerMessage(o) {
|
|
480
|
+
const { requestId: t, error: r, result: n } = o.data, a = this.pendingCallbacks.get(t);
|
|
481
|
+
if (!a) return console.warn(`PlyLoader: Received response for unknown request ${t}`);
|
|
482
|
+
if (this.pendingCallbacks.delete(t), r) return a.reject(new Error(r));
|
|
483
|
+
if (!n) return a.reject(new Error("Worker returned no result"));
|
|
484
484
|
try {
|
|
485
|
-
const i = new
|
|
486
|
-
i.numSplats =
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
485
|
+
const i = new Re(0);
|
|
486
|
+
i.numSplats = n.numSplats, i.positions = new Float32Array(n.positions), i.rotations = new Float32Array(n.rotations), i.scales = new Float32Array(n.scales), i.colors = new Float32Array(n.colors), i.opacities = new Float32Array(n.opacities), i.boundingBox.min.set(
|
|
487
|
+
n.boundingBox.minX,
|
|
488
|
+
n.boundingBox.minY,
|
|
489
|
+
n.boundingBox.minZ
|
|
490
490
|
), i.boundingBox.max.set(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
491
|
+
n.boundingBox.maxX,
|
|
492
|
+
n.boundingBox.maxY,
|
|
493
|
+
n.boundingBox.maxZ
|
|
494
494
|
), this.worker.terminate(), a.resolve(i);
|
|
495
495
|
} catch (i) {
|
|
496
496
|
a.reject(i);
|
|
@@ -503,19 +503,19 @@ class Re extends l.Loader {
|
|
|
503
503
|
* @param onProgress Optional progress callback
|
|
504
504
|
* @param onError Optional error callback
|
|
505
505
|
*/
|
|
506
|
-
load(
|
|
506
|
+
load(o, t, r, n) {
|
|
507
507
|
const a = new l.FileLoader(this.manager);
|
|
508
508
|
a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
|
|
509
|
-
|
|
509
|
+
o,
|
|
510
510
|
(i) => {
|
|
511
511
|
this.parseAsync(i).then((u) => {
|
|
512
|
-
|
|
512
|
+
t && t(u);
|
|
513
513
|
}).catch((u) => {
|
|
514
|
-
|
|
514
|
+
n ? n(u) : console.error(u), this.manager.itemError(o);
|
|
515
515
|
});
|
|
516
516
|
},
|
|
517
|
-
|
|
518
|
-
|
|
517
|
+
r,
|
|
518
|
+
n
|
|
519
519
|
);
|
|
520
520
|
}
|
|
521
521
|
/**
|
|
@@ -524,19 +524,19 @@ class Re extends l.Loader {
|
|
|
524
524
|
* @param onProgress Optional progress callback
|
|
525
525
|
* @returns A Promise that resolves with the parsed SplatData
|
|
526
526
|
*/
|
|
527
|
-
loadAsync(
|
|
528
|
-
return new Promise((
|
|
527
|
+
loadAsync(o, t) {
|
|
528
|
+
return new Promise((r, n) => {
|
|
529
529
|
const a = new l.FileLoader(this.manager);
|
|
530
530
|
a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setPath(this.path), a.setWithCredentials(this.withCredentials), a.load(
|
|
531
|
-
|
|
531
|
+
o,
|
|
532
532
|
(i) => {
|
|
533
|
-
this.parseAsync(i).then(
|
|
534
|
-
|
|
533
|
+
this.parseAsync(i).then(r).catch((u) => {
|
|
534
|
+
n(u), this.manager.itemError(o);
|
|
535
535
|
});
|
|
536
536
|
},
|
|
537
|
-
|
|
537
|
+
t,
|
|
538
538
|
(i) => {
|
|
539
|
-
|
|
539
|
+
n(i), this.manager.itemError(o);
|
|
540
540
|
}
|
|
541
541
|
);
|
|
542
542
|
});
|
|
@@ -546,15 +546,15 @@ class Re extends l.Loader {
|
|
|
546
546
|
* @param buffer ArrayBuffer containing PLY data
|
|
547
547
|
* @returns Promise that resolves with parsed SplatData
|
|
548
548
|
*/
|
|
549
|
-
parseAsync(
|
|
550
|
-
return new Promise((
|
|
551
|
-
const
|
|
552
|
-
this.pendingCallbacks.set(
|
|
549
|
+
parseAsync(o) {
|
|
550
|
+
return new Promise((t, r) => {
|
|
551
|
+
const n = this.requestId++;
|
|
552
|
+
this.pendingCallbacks.set(n, { resolve: t, reject: r });
|
|
553
553
|
const a = {
|
|
554
|
-
requestId:
|
|
555
|
-
buffer:
|
|
554
|
+
requestId: n,
|
|
555
|
+
buffer: o
|
|
556
556
|
};
|
|
557
|
-
this.worker.postMessage(a, [
|
|
557
|
+
this.worker.postMessage(a, [o]);
|
|
558
558
|
});
|
|
559
559
|
}
|
|
560
560
|
/**
|
|
@@ -569,11 +569,11 @@ class Re extends l.Loader {
|
|
|
569
569
|
*/
|
|
570
570
|
createWorkerCode() {
|
|
571
571
|
return `(${(function() {
|
|
572
|
-
self.onmessage = (
|
|
573
|
-
const { requestId:
|
|
572
|
+
self.onmessage = (r) => {
|
|
573
|
+
const { requestId: n, buffer: a } = r.data;
|
|
574
574
|
try {
|
|
575
|
-
const i =
|
|
576
|
-
requestId:
|
|
575
|
+
const i = t(a), u = {
|
|
576
|
+
requestId: n,
|
|
577
577
|
result: i
|
|
578
578
|
};
|
|
579
579
|
self.postMessage(u, [
|
|
@@ -585,14 +585,14 @@ class Re extends l.Loader {
|
|
|
585
585
|
]);
|
|
586
586
|
} catch (i) {
|
|
587
587
|
const u = {
|
|
588
|
-
requestId:
|
|
588
|
+
requestId: n,
|
|
589
589
|
error: i instanceof Error ? i.message : String(i)
|
|
590
590
|
};
|
|
591
591
|
self.postMessage(u);
|
|
592
592
|
}
|
|
593
593
|
};
|
|
594
|
-
function r
|
|
595
|
-
const
|
|
594
|
+
function t(r) {
|
|
595
|
+
const n = new TextDecoder(), a = new Uint8Array(r), i = [112, 108, 121, 10], u = `
|
|
596
596
|
end_header
|
|
597
597
|
`;
|
|
598
598
|
for (let m = 0; m < i.length; m++)
|
|
@@ -600,88 +600,88 @@ end_header
|
|
|
600
600
|
throw new Error(
|
|
601
601
|
"Invalid PLY file: Missing magic bytes"
|
|
602
602
|
);
|
|
603
|
-
let
|
|
603
|
+
let w = 0;
|
|
604
604
|
for (let m = 0; m < a.length - u.length; m++) {
|
|
605
605
|
let c = !0;
|
|
606
|
-
for (let
|
|
607
|
-
if (a[m +
|
|
606
|
+
for (let y = 0; y < u.length; y++)
|
|
607
|
+
if (a[m + y] !== u.charCodeAt(y)) {
|
|
608
608
|
c = !1;
|
|
609
609
|
break;
|
|
610
610
|
}
|
|
611
611
|
if (c) {
|
|
612
|
-
|
|
612
|
+
w = m + u.length;
|
|
613
613
|
break;
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
|
-
if (
|
|
616
|
+
if (w === 0)
|
|
617
617
|
throw new Error(
|
|
618
618
|
"Invalid PLY file: Could not find end of header"
|
|
619
619
|
);
|
|
620
|
-
const
|
|
621
|
-
a.subarray(0,
|
|
620
|
+
const _ = n.decode(
|
|
621
|
+
a.subarray(0, w)
|
|
622
622
|
).split(`
|
|
623
|
-
`),
|
|
624
|
-
let
|
|
625
|
-
for (let m = 1; m <
|
|
626
|
-
const c =
|
|
623
|
+
`), h = [];
|
|
624
|
+
let b = null;
|
|
625
|
+
for (let m = 1; m < _.length; m++) {
|
|
626
|
+
const c = _[m].trim();
|
|
627
627
|
if (c === "" || c === "end_header") continue;
|
|
628
|
-
const
|
|
629
|
-
switch (
|
|
628
|
+
const y = c.split(" ");
|
|
629
|
+
switch (y[0]) {
|
|
630
630
|
case "format":
|
|
631
|
-
|
|
631
|
+
b = y[1];
|
|
632
632
|
break;
|
|
633
633
|
case "element":
|
|
634
|
-
|
|
635
|
-
name:
|
|
636
|
-
count: parseInt(
|
|
634
|
+
h.push({
|
|
635
|
+
name: y[1],
|
|
636
|
+
count: parseInt(y[2], 10),
|
|
637
637
|
properties: []
|
|
638
638
|
});
|
|
639
639
|
break;
|
|
640
640
|
case "property":
|
|
641
|
-
if (
|
|
641
|
+
if (h.length === 0)
|
|
642
642
|
throw new Error(
|
|
643
643
|
"Invalid PLY file: Property without element"
|
|
644
644
|
);
|
|
645
|
-
|
|
646
|
-
type:
|
|
647
|
-
name:
|
|
645
|
+
h[h.length - 1].properties.push({
|
|
646
|
+
type: y[1],
|
|
647
|
+
name: y[2]
|
|
648
648
|
});
|
|
649
649
|
break;
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
|
-
if (
|
|
653
|
-
throw new Error(`Unsupported PLY format: ${
|
|
654
|
-
const
|
|
655
|
-
if (!
|
|
652
|
+
if (b !== "binary_little_endian")
|
|
653
|
+
throw new Error(`Unsupported PLY format: ${b}`);
|
|
654
|
+
const S = h.find((m) => m.name === "vertex");
|
|
655
|
+
if (!S)
|
|
656
656
|
throw new Error(
|
|
657
657
|
"Invalid PLY file: No vertex element found"
|
|
658
658
|
);
|
|
659
|
-
const I =
|
|
660
|
-
let
|
|
661
|
-
const
|
|
659
|
+
const I = S.count, P = new Float32Array(I * 3), j = new Float32Array(I * 4), H = new Float32Array(I * 3), W = new Float32Array(I * 3), oe = new Float32Array(I), L = new DataView(r);
|
|
660
|
+
let A = w;
|
|
661
|
+
const g = (m) => S.properties.findIndex(
|
|
662
662
|
(c) => c.name === m
|
|
663
|
-
), D =
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
663
|
+
), D = g("x"), T = g("y"), v = g("z"), R = [
|
|
664
|
+
g("rot_0"),
|
|
665
|
+
g("rot_1"),
|
|
666
|
+
g("rot_2"),
|
|
667
|
+
g("rot_3")
|
|
668
668
|
], B = [
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
],
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
],
|
|
669
|
+
g("scale_0"),
|
|
670
|
+
g("scale_1"),
|
|
671
|
+
g("scale_2")
|
|
672
|
+
], $ = [
|
|
673
|
+
g("f_dc_0"),
|
|
674
|
+
g("f_dc_1"),
|
|
675
|
+
g("f_dc_2")
|
|
676
|
+
], X = g("opacity");
|
|
677
677
|
if ([
|
|
678
678
|
D,
|
|
679
679
|
T,
|
|
680
|
-
|
|
680
|
+
v,
|
|
681
681
|
...R,
|
|
682
682
|
...B,
|
|
683
|
-
|
|
684
|
-
|
|
683
|
+
...$,
|
|
684
|
+
X
|
|
685
685
|
].some((m) => m === -1))
|
|
686
686
|
throw new Error(
|
|
687
687
|
"Invalid PLY file: Missing required properties"
|
|
@@ -691,73 +691,73 @@ end_header
|
|
|
691
691
|
const c = Math.exp(m);
|
|
692
692
|
return c / (1 + c);
|
|
693
693
|
};
|
|
694
|
-
let N = 1 / 0, te = 1 / 0, s = 1 / 0, p = -1 / 0,
|
|
694
|
+
let N = 1 / 0, te = 1 / 0, s = 1 / 0, p = -1 / 0, M = -1 / 0, E = -1 / 0;
|
|
695
695
|
for (let m = 0; m < I; m++) {
|
|
696
696
|
const c = [];
|
|
697
|
-
for (let
|
|
698
|
-
const
|
|
697
|
+
for (let he = 0; he < S.properties.length; he++) {
|
|
698
|
+
const pe = S.properties[he].type;
|
|
699
699
|
let ee;
|
|
700
|
-
switch (
|
|
700
|
+
switch (pe) {
|
|
701
701
|
case "char":
|
|
702
|
-
ee =
|
|
702
|
+
ee = L.getInt8(A), A += 1;
|
|
703
703
|
break;
|
|
704
704
|
case "uchar":
|
|
705
|
-
ee =
|
|
705
|
+
ee = L.getUint8(A), A += 1;
|
|
706
706
|
break;
|
|
707
707
|
case "short":
|
|
708
|
-
ee =
|
|
708
|
+
ee = L.getInt16(A, !0), A += 2;
|
|
709
709
|
break;
|
|
710
710
|
case "ushort":
|
|
711
|
-
ee =
|
|
711
|
+
ee = L.getUint16(A, !0), A += 2;
|
|
712
712
|
break;
|
|
713
713
|
case "int":
|
|
714
|
-
ee =
|
|
714
|
+
ee = L.getInt32(A, !0), A += 4;
|
|
715
715
|
break;
|
|
716
716
|
case "uint":
|
|
717
|
-
ee =
|
|
717
|
+
ee = L.getUint32(A, !0), A += 4;
|
|
718
718
|
break;
|
|
719
719
|
case "float":
|
|
720
|
-
ee =
|
|
720
|
+
ee = L.getFloat32(A, !0), A += 4;
|
|
721
721
|
break;
|
|
722
722
|
case "double":
|
|
723
|
-
ee =
|
|
723
|
+
ee = L.getFloat64(A, !0), A += 8;
|
|
724
724
|
break;
|
|
725
725
|
default:
|
|
726
726
|
throw new Error(
|
|
727
|
-
`Unsupported property type: ${
|
|
727
|
+
`Unsupported property type: ${pe}`
|
|
728
728
|
);
|
|
729
729
|
}
|
|
730
730
|
c.push(ee);
|
|
731
731
|
}
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
let O = c[R[1]],
|
|
732
|
+
const y = c[D], z = c[T], d = c[v], k = m * 3;
|
|
733
|
+
P[k] = y, P[k + 1] = z, P[k + 2] = d, N = Math.min(N, y), te = Math.min(te, z), s = Math.min(s, d), p = Math.max(p, y), M = Math.max(M, z), E = Math.max(E, d);
|
|
734
|
+
let O = c[R[1]], q = c[R[2]], G = c[R[3]], V = c[R[0]];
|
|
735
735
|
const Y = Math.sqrt(
|
|
736
|
-
O * O +
|
|
736
|
+
O * O + q * q + G * G + V * V
|
|
737
737
|
);
|
|
738
|
-
Y > 0 && (O /= Y,
|
|
739
|
-
const
|
|
740
|
-
j[
|
|
741
|
-
const
|
|
742
|
-
H[
|
|
743
|
-
let re = 0.5 + c[
|
|
744
|
-
re = Math.max(0, Math.min(1, re)),
|
|
738
|
+
Y > 0 && (O /= Y, q /= Y, G /= Y, V /= Y), V < 0 && (O = -O, q = -q, G = -G, V = -V);
|
|
739
|
+
const K = m * 4;
|
|
740
|
+
j[K] = O, j[K + 1] = q, j[K + 2] = G, j[K + 3] = V;
|
|
741
|
+
const Q = m * 3;
|
|
742
|
+
H[Q] = c[B[0]], H[Q + 1] = c[B[1]], H[Q + 2] = c[B[2]];
|
|
743
|
+
let re = 0.5 + c[$[0]] * U, ne = 0.5 + c[$[1]] * U, J = 0.5 + c[$[2]] * U;
|
|
744
|
+
re = Math.max(0, Math.min(1, re)), ne = Math.max(0, Math.min(1, ne)), J = Math.max(0, Math.min(1, J));
|
|
745
745
|
const ue = m * 3;
|
|
746
|
-
|
|
746
|
+
W[ue] = re, W[ue + 1] = ne, W[ue + 2] = J, oe[m] = F(c[X]);
|
|
747
747
|
}
|
|
748
748
|
return {
|
|
749
749
|
numSplats: I,
|
|
750
|
-
positions:
|
|
750
|
+
positions: P.buffer,
|
|
751
751
|
rotations: j.buffer,
|
|
752
752
|
scales: H.buffer,
|
|
753
|
-
colors:
|
|
754
|
-
opacities:
|
|
753
|
+
colors: W.buffer,
|
|
754
|
+
opacities: oe.buffer,
|
|
755
755
|
boundingBox: {
|
|
756
756
|
minX: N,
|
|
757
757
|
minY: te,
|
|
758
758
|
minZ: s,
|
|
759
759
|
maxX: p,
|
|
760
|
-
maxY:
|
|
760
|
+
maxY: M,
|
|
761
761
|
maxZ: E
|
|
762
762
|
}
|
|
763
763
|
};
|
|
@@ -768,31 +768,31 @@ end_header
|
|
|
768
768
|
class Pe extends l.EventDispatcher {
|
|
769
769
|
constructor() {
|
|
770
770
|
super();
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
771
|
+
f(this, "worker");
|
|
772
|
+
f(this, "centers", null);
|
|
773
|
+
f(this, "orderTexture", null);
|
|
774
774
|
/** Bounding box data for optimization */
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
const
|
|
779
|
-
this.worker = new Worker(URL.createObjectURL(
|
|
775
|
+
f(this, "chunks", null);
|
|
776
|
+
f(this, "lastCameraPosition", new l.Vector3());
|
|
777
|
+
f(this, "lastCameraDirection", new l.Vector3());
|
|
778
|
+
const o = this.createWorkerCode(), t = new Blob([o], { type: "application/javascript" });
|
|
779
|
+
this.worker = new Worker(URL.createObjectURL(t)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
780
780
|
}
|
|
781
781
|
/**
|
|
782
782
|
* Handles messages received from the sorting worker.
|
|
783
783
|
* @param event The message event from the worker.
|
|
784
784
|
*/
|
|
785
|
-
onWorkerMessage(
|
|
785
|
+
onWorkerMessage(o) {
|
|
786
786
|
if (!this.orderTexture || !this.orderTexture.image)
|
|
787
787
|
return console.error("SplatSorter: Order texture not initialized!");
|
|
788
|
-
const { order:
|
|
789
|
-
if (!(
|
|
788
|
+
const { order: t, count: r } = o.data, n = this.orderTexture.image.data;
|
|
789
|
+
if (!(n instanceof Uint32Array))
|
|
790
790
|
return console.error(
|
|
791
791
|
"SplatSorter: Order texture data is not a Uint32Array!"
|
|
792
792
|
);
|
|
793
|
-
|
|
794
|
-
const a =
|
|
795
|
-
this.worker.postMessage(i, [a]), this.dispatchEvent({ type: "updated", count:
|
|
793
|
+
n.set(new Uint32Array(t)), this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
|
|
794
|
+
const a = n.buffer.slice(0), i = { order: a };
|
|
795
|
+
this.worker.postMessage(i, [a]), this.dispatchEvent({ type: "updated", count: r });
|
|
796
796
|
}
|
|
797
797
|
/**
|
|
798
798
|
* Initializes the sorter with necessary data and textures.
|
|
@@ -801,35 +801,35 @@ class Pe extends l.EventDispatcher {
|
|
|
801
801
|
* @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
|
|
802
802
|
* @param transferOwnership Optional: If true, transfers ownership of centers buffer to worker (saves memory, main thread loses access). Default: false.
|
|
803
803
|
*/
|
|
804
|
-
init(
|
|
805
|
-
if (!
|
|
804
|
+
init(o, t, r, n = !1) {
|
|
805
|
+
if (!o || !(o.image.data instanceof Uint32Array))
|
|
806
806
|
throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
|
|
807
|
-
if (!
|
|
807
|
+
if (!t || t.length % 3 !== 0)
|
|
808
808
|
throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
|
|
809
|
-
if (
|
|
809
|
+
if (o.image.data.length < t.length / 3)
|
|
810
810
|
throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");
|
|
811
|
-
if (
|
|
811
|
+
if (t.buffer.byteLength === 0)
|
|
812
812
|
throw new Error(
|
|
813
813
|
"SplatSorter: positions buffer is detached (likely React StrictMode + cached asset). "
|
|
814
814
|
);
|
|
815
|
-
const a =
|
|
816
|
-
this.orderTexture =
|
|
815
|
+
const a = t.length / 3;
|
|
816
|
+
this.orderTexture = o, n ? this.centers = null : this.centers = t.slice();
|
|
817
817
|
const i = this.orderTexture.image.data;
|
|
818
|
-
for (let
|
|
818
|
+
for (let h = 0; h < a; h++) i[h] = h;
|
|
819
819
|
this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
|
|
820
|
-
const u = i.buffer.slice(0),
|
|
820
|
+
const u = i.buffer.slice(0), w = n ? t.buffer : t.buffer.slice(0), C = {
|
|
821
821
|
order: u,
|
|
822
|
-
centers:
|
|
823
|
-
},
|
|
822
|
+
centers: w
|
|
823
|
+
}, _ = [
|
|
824
824
|
u,
|
|
825
|
-
|
|
825
|
+
w
|
|
826
826
|
];
|
|
827
|
-
if (
|
|
828
|
-
this.chunks =
|
|
829
|
-
const
|
|
830
|
-
|
|
827
|
+
if (r) {
|
|
828
|
+
this.chunks = r.slice();
|
|
829
|
+
const h = this.chunks.buffer.slice(0);
|
|
830
|
+
C.chunks = h, _.push(h);
|
|
831
831
|
}
|
|
832
|
-
this.worker.postMessage(
|
|
832
|
+
this.worker.postMessage(C, _), queueMicrotask(() => {
|
|
833
833
|
this.dispatchEvent({
|
|
834
834
|
type: "updated",
|
|
835
835
|
count: a
|
|
@@ -841,51 +841,51 @@ class Pe extends l.EventDispatcher {
|
|
|
841
841
|
* The sorter will only consider splats whose original indices are present in the mapping.
|
|
842
842
|
* @param mapping A Uint32Array where each element is the *original* index of a splat to include, or null to reset mapping.
|
|
843
843
|
*/
|
|
844
|
-
setMapping(
|
|
844
|
+
setMapping(o) {
|
|
845
845
|
if (!this.centers)
|
|
846
846
|
return console.warn(
|
|
847
847
|
"SplatSorter: Cannot set mapping before initialization."
|
|
848
848
|
);
|
|
849
|
-
let
|
|
850
|
-
const
|
|
851
|
-
if (!
|
|
849
|
+
let t;
|
|
850
|
+
const r = [];
|
|
851
|
+
if (!o) {
|
|
852
852
|
const u = this.centers.buffer.slice(0);
|
|
853
|
-
return
|
|
853
|
+
return t = {
|
|
854
854
|
centers: u,
|
|
855
855
|
mapping: null
|
|
856
|
-
},
|
|
856
|
+
}, r.push(u), this.worker.postMessage(t, r);
|
|
857
857
|
}
|
|
858
|
-
const
|
|
859
|
-
for (let u = 0; u <
|
|
860
|
-
const
|
|
861
|
-
if (
|
|
858
|
+
const n = new Float32Array(o.length * 3);
|
|
859
|
+
for (let u = 0; u < o.length; u++) {
|
|
860
|
+
const w = o[u];
|
|
861
|
+
if (w * 3 + 2 >= this.centers.length) {
|
|
862
862
|
console.warn(
|
|
863
|
-
`SplatSorter: Mapping index ${
|
|
863
|
+
`SplatSorter: Mapping index ${w} out of bounds.`
|
|
864
864
|
);
|
|
865
865
|
continue;
|
|
866
866
|
}
|
|
867
|
-
const
|
|
868
|
-
|
|
867
|
+
const C = w * 3, _ = u * 3;
|
|
868
|
+
n[_ + 0] = this.centers[C + 0], n[_ + 1] = this.centers[C + 1], n[_ + 2] = this.centers[C + 2];
|
|
869
869
|
}
|
|
870
|
-
const a =
|
|
871
|
-
|
|
870
|
+
const a = n.buffer.slice(0), i = o.buffer.slice(0);
|
|
871
|
+
t = {
|
|
872
872
|
centers: a,
|
|
873
873
|
mapping: i
|
|
874
|
-
},
|
|
874
|
+
}, r.push(a, i), this.worker.postMessage(t, r);
|
|
875
875
|
}
|
|
876
876
|
/**
|
|
877
877
|
* Updates the camera parameters used for sorting.
|
|
878
878
|
* @param position The camera's position in the sorter's local coordinate space.
|
|
879
879
|
* @param direction The camera's forward direction in the sorter's local coordinate space.
|
|
880
880
|
*/
|
|
881
|
-
setCamera(
|
|
882
|
-
const
|
|
883
|
-
if (!
|
|
881
|
+
setCamera(o, t) {
|
|
882
|
+
const r = this.lastCameraPosition.distanceToSquared(o) > 1e-7, n = this.lastCameraDirection.dot(t) < 0.9999;
|
|
883
|
+
if (!r && !n)
|
|
884
884
|
return;
|
|
885
|
-
this.lastCameraPosition.copy(
|
|
885
|
+
this.lastCameraPosition.copy(o), this.lastCameraDirection.copy(t);
|
|
886
886
|
const a = {
|
|
887
|
-
cameraPosition: { x:
|
|
888
|
-
cameraDirection: { x:
|
|
887
|
+
cameraPosition: { x: o.x, y: o.y, z: o.z },
|
|
888
|
+
cameraDirection: { x: t.x, y: t.y, z: t.z }
|
|
889
889
|
};
|
|
890
890
|
this.worker.postMessage(a);
|
|
891
891
|
}
|
|
@@ -901,165 +901,165 @@ class Pe extends l.EventDispatcher {
|
|
|
901
901
|
*/
|
|
902
902
|
createWorkerCode() {
|
|
903
903
|
return `(${(function() {
|
|
904
|
-
let
|
|
905
|
-
const
|
|
906
|
-
let
|
|
907
|
-
const
|
|
908
|
-
for (;
|
|
909
|
-
const T =
|
|
910
|
-
if (
|
|
911
|
-
else if (
|
|
904
|
+
let t = null, r = null, n = null, a = null, i = null, u = null, w = !1;
|
|
905
|
+
const C = { x: 0, y: 0, z: 0 }, _ = { x: 0, y: 0, z: 0 }, h = { x: 0, y: 0, z: 0 }, b = { x: 0, y: 0, z: 0 };
|
|
906
|
+
let S = null, I = null;
|
|
907
|
+
const P = 32, j = new Array(P).fill(0), H = new Array(P).fill(0), W = new Array(P).fill(0), oe = (A, g, D) => {
|
|
908
|
+
for (; A <= g; ) {
|
|
909
|
+
const T = g + A >> 1, v = D(T);
|
|
910
|
+
if (v > 0) A = T + 1;
|
|
911
|
+
else if (v < 0) g = T - 1;
|
|
912
912
|
else return T;
|
|
913
913
|
}
|
|
914
|
-
return ~
|
|
915
|
-
},
|
|
916
|
-
if (!
|
|
914
|
+
return ~A;
|
|
915
|
+
}, L = () => {
|
|
916
|
+
if (!t || !r || !i || !u)
|
|
917
917
|
return;
|
|
918
|
-
if (
|
|
918
|
+
if (r.length === 0) {
|
|
919
919
|
const c = {
|
|
920
|
-
order:
|
|
920
|
+
order: t.buffer,
|
|
921
921
|
count: 0
|
|
922
922
|
};
|
|
923
|
-
self.postMessage(c, [
|
|
923
|
+
self.postMessage(c, [t.buffer]), t = null;
|
|
924
924
|
return;
|
|
925
925
|
}
|
|
926
|
-
const
|
|
927
|
-
if (!
|
|
926
|
+
const A = i.x, g = i.y, D = i.z, T = u.x, v = u.y, R = u.z, B = 1e-4, $ = Math.abs(A - C.x) > B || Math.abs(g - C.y) > B || Math.abs(D - C.z) > B, X = Math.abs(T - _.x) > B || Math.abs(v - _.y) > B || Math.abs(R - _.z) > B;
|
|
927
|
+
if (!w && !$ && !X)
|
|
928
928
|
return;
|
|
929
|
-
|
|
929
|
+
w = !1, C.x = A, C.y = g, C.z = D, _.x = T, _.y = v, _.z = R;
|
|
930
930
|
let Z = 1 / 0, U = -1 / 0;
|
|
931
931
|
for (let c = 0; c < 8; ++c) {
|
|
932
|
-
const
|
|
932
|
+
const y = c & 1 ? h.x : b.x, z = c & 2 ? h.y : b.y, d = c & 4 ? h.z : b.z, k = y * T + z * v + d * R;
|
|
933
933
|
Z = Math.min(Z, k), U = Math.max(U, k);
|
|
934
934
|
}
|
|
935
|
-
const F =
|
|
935
|
+
const F = r.length / 3, N = U - Z, s = (1 << Math.max(
|
|
936
936
|
10,
|
|
937
937
|
Math.min(20, Math.ceil(Math.log2(F / 4)))
|
|
938
938
|
)) + 1;
|
|
939
|
-
if ((!
|
|
940
|
-
for (let c = 0; c < F; ++c)
|
|
939
|
+
if ((!S || S.length !== F) && (S = new Uint32Array(F)), !I || I.length !== s ? I = new Uint32Array(s) : I.fill(0), N < 1e-7) {
|
|
940
|
+
for (let c = 0; c < F; ++c) S[c] = 0;
|
|
941
941
|
I[0] = F;
|
|
942
|
-
} else if (
|
|
943
|
-
const c =
|
|
942
|
+
} else if (n && n.length > 0) {
|
|
943
|
+
const c = n.length / 6;
|
|
944
944
|
j.fill(0);
|
|
945
|
-
for (let
|
|
946
|
-
const k =
|
|
945
|
+
for (let d = 0; d < c; ++d) {
|
|
946
|
+
const k = d * 6, O = n[k + 0], q = n[k + 1], G = n[k + 2], V = n[k + 3], Y = O * T + q * v + G * R - Z, K = Y - V, Q = Y + V, re = Math.max(
|
|
947
947
|
0,
|
|
948
|
-
Math.floor(
|
|
949
|
-
),
|
|
950
|
-
|
|
951
|
-
Math.ceil(
|
|
948
|
+
Math.floor(K * P / N)
|
|
949
|
+
), ne = Math.min(
|
|
950
|
+
P,
|
|
951
|
+
Math.ceil(Q * P / N)
|
|
952
952
|
);
|
|
953
|
-
for (let J = re; J <
|
|
953
|
+
for (let J = re; J < ne; ++J)
|
|
954
954
|
j[J]++;
|
|
955
955
|
}
|
|
956
|
-
let
|
|
957
|
-
for (let
|
|
958
|
-
|
|
959
|
-
for (let
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
const
|
|
963
|
-
for (let
|
|
964
|
-
const k =
|
|
956
|
+
let y = 0;
|
|
957
|
+
for (let d = 0; d < P; ++d) y += j[d];
|
|
958
|
+
W[0] = 0, H[0] = 0;
|
|
959
|
+
for (let d = 1; d < P; ++d)
|
|
960
|
+
W[d - 1] = j[d - 1] / y * s >>> 0, H[d] = H[d - 1] + W[d - 1];
|
|
961
|
+
W[P - 1] = j[P - 1] / y * s >>> 0;
|
|
962
|
+
const z = N / P;
|
|
963
|
+
for (let d = 0; d < F; ++d) {
|
|
964
|
+
const k = d * 3, O = r[k + 0], q = r[k + 1], G = r[k + 2], V = O * T + q * v + G * R, K = (U - V) / z, Q = Math.max(
|
|
965
965
|
0,
|
|
966
966
|
Math.min(
|
|
967
|
-
|
|
968
|
-
Math.floor(
|
|
967
|
+
P - 1,
|
|
968
|
+
Math.floor(K)
|
|
969
969
|
)
|
|
970
|
-
), re =
|
|
971
|
-
|
|
970
|
+
), re = K - Q, ne = H[Q] + W[Q] * re >>> 0, J = Math.min(ne, s - 1);
|
|
971
|
+
S[d] = J, I[J]++;
|
|
972
972
|
}
|
|
973
973
|
} else {
|
|
974
974
|
const c = (s - 1) / N;
|
|
975
|
-
for (let
|
|
976
|
-
const
|
|
977
|
-
|
|
975
|
+
for (let y = 0; y < F; ++y) {
|
|
976
|
+
const z = y * 3, d = r[z + 0], k = r[z + 1], O = r[z + 2], q = d * T + k * v + O * R, V = (U - q) * c >>> 0, Y = Math.min(V, s - 1);
|
|
977
|
+
S[y] = Y, I[Y]++;
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
for (let c = 1; c < s; c++)
|
|
981
981
|
I[c] += I[c - 1];
|
|
982
982
|
for (let c = F - 1; c >= 0; c--) {
|
|
983
|
-
const
|
|
984
|
-
|
|
983
|
+
const y = S[c], z = --I[y];
|
|
984
|
+
t[z] = a ? a[c] : c;
|
|
985
985
|
}
|
|
986
|
-
const p =
|
|
987
|
-
if (!
|
|
988
|
-
const
|
|
989
|
-
if (!
|
|
986
|
+
const p = A * T + g * v + D * R, M = (c) => {
|
|
987
|
+
if (!t) return -1 / 0;
|
|
988
|
+
const y = t[c], z = y;
|
|
989
|
+
if (!r || z * 3 + 2 >= r.length)
|
|
990
990
|
return -1 / 0;
|
|
991
|
-
const
|
|
992
|
-
return
|
|
991
|
+
const d = z * 3;
|
|
992
|
+
return r[d] * T + r[d + 1] * v + r[d + 2] * R - p;
|
|
993
993
|
};
|
|
994
994
|
let E = F;
|
|
995
|
-
if (F > 0 &&
|
|
996
|
-
const c =
|
|
995
|
+
if (F > 0 && M(F - 1) < 0) {
|
|
996
|
+
const c = oe(
|
|
997
997
|
0,
|
|
998
998
|
F - 1,
|
|
999
|
-
|
|
999
|
+
M
|
|
1000
1000
|
);
|
|
1001
1001
|
E = c < 0 ? ~c : c;
|
|
1002
1002
|
}
|
|
1003
1003
|
const m = {
|
|
1004
|
-
order:
|
|
1004
|
+
order: t.buffer,
|
|
1005
1005
|
count: E
|
|
1006
1006
|
};
|
|
1007
|
-
self.postMessage(m, [
|
|
1007
|
+
self.postMessage(m, [t.buffer]), t = null;
|
|
1008
1008
|
};
|
|
1009
|
-
self.onmessage = (
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1009
|
+
self.onmessage = (A) => {
|
|
1010
|
+
const g = A.data;
|
|
1011
|
+
g.order && (t = new Uint32Array(g.order));
|
|
1012
1012
|
let D = !1;
|
|
1013
|
-
if (
|
|
1014
|
-
if (
|
|
1015
|
-
for (let T = 0; T <
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
(
|
|
1013
|
+
if (g.centers && (r = new Float32Array(g.centers), D = !0, w = !0), Object.prototype.hasOwnProperty.call(g, "mapping") && (a = g.mapping ? new Uint32Array(g.mapping) : null, w = !0), g.chunks) {
|
|
1014
|
+
if (n = new Float32Array(g.chunks), n.length > 0 && n[3] > 0)
|
|
1015
|
+
for (let T = 0; T < n.length / 6; ++T) {
|
|
1016
|
+
const v = T * 6, R = n[v + 0], B = n[v + 1], $ = n[v + 2], X = n[v + 3], Z = n[v + 4], U = n[v + 5];
|
|
1017
|
+
n[v + 0] = (R + X) * 0.5, n[v + 1] = (B + Z) * 0.5, n[v + 2] = ($ + U) * 0.5, n[v + 3] = Math.sqrt(
|
|
1018
|
+
(X - R) ** 2 + (Z - B) ** 2 + (U - $) ** 2
|
|
1019
1019
|
) * 0.5;
|
|
1020
1020
|
}
|
|
1021
|
-
|
|
1021
|
+
w = !0;
|
|
1022
1022
|
}
|
|
1023
|
-
if (D &&
|
|
1024
|
-
|
|
1025
|
-
for (let T = 1; T <
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1023
|
+
if (D && r && r.length > 0) {
|
|
1024
|
+
h.x = b.x = r[0], h.y = b.y = r[1], h.z = b.z = r[2];
|
|
1025
|
+
for (let T = 1; T < r.length / 3; T++) {
|
|
1026
|
+
const v = T * 3;
|
|
1027
|
+
h.x = Math.min(h.x, r[v + 0]), b.x = Math.max(b.x, r[v + 0]), h.y = Math.min(h.y, r[v + 1]), b.y = Math.max(b.y, r[v + 1]), h.z = Math.min(h.z, r[v + 2]), b.z = Math.max(b.z, r[v + 2]);
|
|
1028
1028
|
}
|
|
1029
|
-
} else D &&
|
|
1030
|
-
|
|
1029
|
+
} else D && r && r.length === 0 && (h.x = b.x = h.y = b.y = h.z = b.z = 0);
|
|
1030
|
+
g.cameraPosition && (i = g.cameraPosition), g.cameraDirection && (u = g.cameraDirection), L();
|
|
1031
1031
|
};
|
|
1032
1032
|
}).toString()})();`;
|
|
1033
1033
|
}
|
|
1034
1034
|
}
|
|
1035
|
-
const
|
|
1036
|
-
const
|
|
1037
|
-
return
|
|
1035
|
+
const Be = (x, e) => {
|
|
1036
|
+
const o = ye(x), t = ye(e);
|
|
1037
|
+
return o | t << 16;
|
|
1038
1038
|
};
|
|
1039
|
-
function
|
|
1040
|
-
const e = new Float32Array([
|
|
1041
|
-
let
|
|
1042
|
-
const a =
|
|
1043
|
-
return a < 103 ?
|
|
1039
|
+
function ye(x) {
|
|
1040
|
+
const e = new Float32Array([x]), t = new Int32Array(e.buffer)[0];
|
|
1041
|
+
let r = t >> 16 & 32768, n = t >> 12 & 2047;
|
|
1042
|
+
const a = t >> 23 & 255;
|
|
1043
|
+
return a < 103 ? r : a > 142 ? (r |= 31744, r |= (a === 255 ? 0 : 1) && t & 8388607, r) : a < 113 ? (n |= 2048, r |= (n >> 114 - a) + (n >> 113 - a & 1), r) : (r |= a - 112 << 10 | n >> 1, r += n & 1, r);
|
|
1044
1044
|
}
|
|
1045
|
-
const
|
|
1046
|
-
class
|
|
1045
|
+
const Fe = new ArrayBuffer(4), ve = new DataView(Fe), Oe = (x) => (ve.setUint32(0, x, !0), ve.getFloat32(0, !0));
|
|
1046
|
+
class De {
|
|
1047
1047
|
/**
|
|
1048
1048
|
* Create a new TextureManager for a set of splats
|
|
1049
1049
|
* @param splatData The splat data to manage textures for
|
|
1050
1050
|
*/
|
|
1051
1051
|
constructor(e) {
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1052
|
+
f(this, "textureWidth");
|
|
1053
|
+
f(this, "textureHeight");
|
|
1054
|
+
f(this, "transformA");
|
|
1055
1055
|
// position xyz and rotation quaternion y,z components
|
|
1056
|
-
|
|
1056
|
+
f(this, "transformB");
|
|
1057
1057
|
// rotation quaternion x and scale xyz
|
|
1058
|
-
|
|
1058
|
+
f(this, "colorTexture");
|
|
1059
1059
|
// color an opacity
|
|
1060
|
-
|
|
1061
|
-
const
|
|
1062
|
-
this.textureWidth = Math.ceil(Math.sqrt(
|
|
1060
|
+
f(this, "orderTexture");
|
|
1061
|
+
const o = e.numSplats;
|
|
1062
|
+
this.textureWidth = Math.ceil(Math.sqrt(o)), this.textureHeight = Math.ceil(o / this.textureWidth), this.transformA = this.createTransformATexture(e), this.transformB = this.createTransformBTexture(e), this.colorTexture = this.createColorTexture(e), this.orderTexture = this.createOrderTexture(o);
|
|
1063
1063
|
}
|
|
1064
1064
|
/**
|
|
1065
1065
|
* Create the transform A texture (positions and quaternion w component)
|
|
@@ -1067,24 +1067,24 @@ class Oe {
|
|
|
1067
1067
|
* @returns DataTexture containing position data
|
|
1068
1068
|
*/
|
|
1069
1069
|
createTransformATexture(e) {
|
|
1070
|
-
const
|
|
1070
|
+
const o = e.numSplats, t = new Float32Array(
|
|
1071
1071
|
this.textureWidth * this.textureHeight * 4
|
|
1072
1072
|
);
|
|
1073
|
-
for (let
|
|
1074
|
-
const a =
|
|
1075
|
-
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1073
|
+
for (let n = 0; n < o; n++) {
|
|
1074
|
+
const a = n * 4, i = n * 3, u = n * 4;
|
|
1075
|
+
t[a] = e.positions[i], t[a + 1] = e.positions[i + 1], t[a + 2] = e.positions[i + 2];
|
|
1076
|
+
const w = e.rotations[u + 0], C = e.rotations[u + 1], _ = Be(w, C);
|
|
1077
|
+
t[a + 3] = Oe(_);
|
|
1078
1078
|
}
|
|
1079
|
-
const
|
|
1080
|
-
|
|
1079
|
+
const r = new l.DataTexture(
|
|
1080
|
+
t,
|
|
1081
1081
|
this.textureWidth,
|
|
1082
1082
|
this.textureHeight,
|
|
1083
1083
|
l.RGBAFormat,
|
|
1084
1084
|
l.FloatType
|
|
1085
1085
|
// Store as Float32, shader will reinterpret bits
|
|
1086
1086
|
);
|
|
1087
|
-
return
|
|
1087
|
+
return r.magFilter = l.NearestFilter, r.minFilter = l.NearestFilter, r.source.data.updateRanges || (r.source.data.updateRanges = []), r.needsUpdate = !0, r;
|
|
1088
1088
|
}
|
|
1089
1089
|
/**
|
|
1090
1090
|
* Create the transform B texture (scale and rotation xyz)
|
|
@@ -1092,21 +1092,21 @@ class Oe {
|
|
|
1092
1092
|
* @returns DataTexture containing scale and rotation data
|
|
1093
1093
|
*/
|
|
1094
1094
|
createTransformBTexture(e) {
|
|
1095
|
-
const
|
|
1095
|
+
const o = e.numSplats, t = new Float32Array(
|
|
1096
1096
|
this.textureWidth * this.textureHeight * 4
|
|
1097
1097
|
);
|
|
1098
|
-
for (let
|
|
1099
|
-
const a =
|
|
1100
|
-
|
|
1098
|
+
for (let n = 0; n < o; n++) {
|
|
1099
|
+
const a = n * 4, i = n * 3, u = n * 4;
|
|
1100
|
+
t[a] = e.scales[i], t[a + 1] = e.scales[i + 1], t[a + 2] = e.scales[i + 2], t[a + 3] = e.rotations[u + 2];
|
|
1101
1101
|
}
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1102
|
+
const r = new l.DataTexture(
|
|
1103
|
+
t,
|
|
1104
1104
|
this.textureWidth,
|
|
1105
1105
|
this.textureHeight,
|
|
1106
1106
|
l.RGBAFormat,
|
|
1107
1107
|
l.FloatType
|
|
1108
1108
|
);
|
|
1109
|
-
return
|
|
1109
|
+
return r.magFilter = l.NearestFilter, r.minFilter = l.NearestFilter, r.source.data.updateRanges || (r.source.data.updateRanges = []), r.needsUpdate = !0, r;
|
|
1110
1110
|
}
|
|
1111
1111
|
/**
|
|
1112
1112
|
* Create the color texture (RGB and opacity)
|
|
@@ -1114,21 +1114,21 @@ class Oe {
|
|
|
1114
1114
|
* @returns DataTexture containing color data
|
|
1115
1115
|
*/
|
|
1116
1116
|
createColorTexture(e) {
|
|
1117
|
-
const
|
|
1117
|
+
const o = e.numSplats, t = new Float32Array(
|
|
1118
1118
|
this.textureWidth * this.textureHeight * 4
|
|
1119
1119
|
);
|
|
1120
|
-
for (let
|
|
1121
|
-
const a =
|
|
1122
|
-
|
|
1120
|
+
for (let n = 0; n < o; n++) {
|
|
1121
|
+
const a = n * 4, i = n * 3;
|
|
1122
|
+
t[a] = e.colors[i], t[a + 1] = e.colors[i + 1], t[a + 2] = e.colors[i + 2], t[a + 3] = e.opacities[n];
|
|
1123
1123
|
}
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1124
|
+
const r = new l.DataTexture(
|
|
1125
|
+
t,
|
|
1126
1126
|
this.textureWidth,
|
|
1127
1127
|
this.textureHeight,
|
|
1128
1128
|
l.RGBAFormat,
|
|
1129
1129
|
l.FloatType
|
|
1130
1130
|
);
|
|
1131
|
-
return
|
|
1131
|
+
return r.source.data.updateRanges || (r.source.data.updateRanges = []), r.needsUpdate = !0, r;
|
|
1132
1132
|
}
|
|
1133
1133
|
/**
|
|
1134
1134
|
* Create the order texture for sorting
|
|
@@ -1136,23 +1136,23 @@ class Oe {
|
|
|
1136
1136
|
* @returns DataTexture for storing order indices
|
|
1137
1137
|
*/
|
|
1138
1138
|
createOrderTexture(e) {
|
|
1139
|
-
const
|
|
1140
|
-
for (let
|
|
1141
|
-
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1139
|
+
const o = new Uint32Array(this.textureWidth * this.textureHeight);
|
|
1140
|
+
for (let r = 0; r < e; r++)
|
|
1141
|
+
o[r] = r;
|
|
1142
|
+
const t = new l.DataTexture(
|
|
1143
|
+
o,
|
|
1144
1144
|
this.textureWidth,
|
|
1145
1145
|
this.textureHeight,
|
|
1146
1146
|
l.RedIntegerFormat,
|
|
1147
1147
|
l.UnsignedIntType
|
|
1148
1148
|
);
|
|
1149
|
-
return
|
|
1149
|
+
return t.source.data.updateRanges || (t.source.data.updateRanges = []), t.needsUpdate = !0, t;
|
|
1150
1150
|
}
|
|
1151
1151
|
dispose() {
|
|
1152
1152
|
this.transformA.dispose(), this.transformB.dispose(), this.colorTexture.dispose(), this.orderTexture.dispose();
|
|
1153
1153
|
}
|
|
1154
1154
|
}
|
|
1155
|
-
const
|
|
1155
|
+
const Ue = (
|
|
1156
1156
|
/* glsl */
|
|
1157
1157
|
`
|
|
1158
1158
|
precision highp float;
|
|
@@ -1410,7 +1410,7 @@ void main(void) {
|
|
|
1410
1410
|
vUv = clippedCornerOffset;
|
|
1411
1411
|
}
|
|
1412
1412
|
`
|
|
1413
|
-
),
|
|
1413
|
+
), qe = (
|
|
1414
1414
|
/* glsl */
|
|
1415
1415
|
`
|
|
1416
1416
|
precision highp float;
|
|
@@ -1446,7 +1446,7 @@ void main(void) {
|
|
|
1446
1446
|
);
|
|
1447
1447
|
class Ve extends l.ShaderMaterial {
|
|
1448
1448
|
constructor(e = {}) {
|
|
1449
|
-
const
|
|
1449
|
+
const o = {
|
|
1450
1450
|
// Textures (values set via methods)
|
|
1451
1451
|
transformA: { value: null },
|
|
1452
1452
|
transformB: { value: null },
|
|
@@ -1459,9 +1459,9 @@ class Ve extends l.ShaderMaterial {
|
|
|
1459
1459
|
// Max splats to render (updated by sorter)
|
|
1460
1460
|
};
|
|
1461
1461
|
super({
|
|
1462
|
-
vertexShader:
|
|
1463
|
-
fragmentShader:
|
|
1464
|
-
uniforms:
|
|
1462
|
+
vertexShader: Ue,
|
|
1463
|
+
fragmentShader: qe,
|
|
1464
|
+
uniforms: o,
|
|
1465
1465
|
transparent: !0,
|
|
1466
1466
|
blending: l.CustomBlending,
|
|
1467
1467
|
// Premultiplied alpha blending:
|
|
@@ -1492,8 +1492,8 @@ class Ve extends l.ShaderMaterial {
|
|
|
1492
1492
|
* @param width Viewport width
|
|
1493
1493
|
* @param height Viewport height
|
|
1494
1494
|
*/
|
|
1495
|
-
updateViewport(e,
|
|
1496
|
-
this.uniforms.viewport.value.set(e,
|
|
1495
|
+
updateViewport(e, o) {
|
|
1496
|
+
this.uniforms.viewport.value.set(e, o);
|
|
1497
1497
|
}
|
|
1498
1498
|
/**
|
|
1499
1499
|
* Set transform texture A (positions)
|
|
@@ -1538,41 +1538,41 @@ const se = class se extends l.Mesh {
|
|
|
1538
1538
|
* @param splatData The splat data to render
|
|
1539
1539
|
* @param options Rendering options
|
|
1540
1540
|
*/
|
|
1541
|
-
constructor(
|
|
1542
|
-
const
|
|
1543
|
-
super(
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1541
|
+
constructor(o, t = {}) {
|
|
1542
|
+
const r = new Ve(t), n = se.createInstancedGeometry(o.numSplats, se.INSTANCE_SIZE);
|
|
1543
|
+
super(n, r);
|
|
1544
|
+
f(this, "sorter");
|
|
1545
|
+
f(this, "splatData");
|
|
1546
|
+
f(this, "options");
|
|
1547
|
+
f(this, "textureManager");
|
|
1548
|
+
f(this, "material");
|
|
1549
|
+
f(this, "geometry");
|
|
1550
|
+
f(this, "lastCameraPositionLocal", new l.Vector3());
|
|
1551
|
+
f(this, "lastCameraDirectionLocal", new l.Vector3());
|
|
1552
|
+
f(this, "invModelMatrix", new l.Matrix4());
|
|
1553
1553
|
// Cached inverse matrix
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
const
|
|
1563
|
-
this.geometry.instanceCount = Math.ceil(
|
|
1554
|
+
f(this, "_vpW", -1);
|
|
1555
|
+
f(this, "_vpH", -1);
|
|
1556
|
+
f(this, "_size", new l.Vector2());
|
|
1557
|
+
f(this, "_camPosW", new l.Vector3());
|
|
1558
|
+
f(this, "_camDirW", new l.Vector3());
|
|
1559
|
+
f(this, "_camPosL", new l.Vector3());
|
|
1560
|
+
f(this, "_camDirL", new l.Vector3());
|
|
1561
|
+
f(this, "onSorterUpdated", (o) => {
|
|
1562
|
+
const t = o.count;
|
|
1563
|
+
this.geometry.instanceCount = Math.ceil(t / se.INSTANCE_SIZE), this.material.setNumSplats(t);
|
|
1564
1564
|
});
|
|
1565
|
-
this.geometry =
|
|
1565
|
+
this.geometry = n, this.material = r, this.splatData = o, this.frustumCulled = !1, this.options = {
|
|
1566
1566
|
autoSort: !0,
|
|
1567
|
-
...
|
|
1568
|
-
}, this.textureManager = new
|
|
1567
|
+
...t
|
|
1568
|
+
}, this.textureManager = new De(o), this.sorter = new Pe();
|
|
1569
1569
|
let a = this.createChunks() || void 0;
|
|
1570
1570
|
a === null && console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."), a = void 0, this.sorter.addEventListener("updated", this.onSorterUpdated), this.sorter.init(
|
|
1571
1571
|
this.textureManager.orderTexture,
|
|
1572
1572
|
this.splatData.positions,
|
|
1573
1573
|
a ?? void 0,
|
|
1574
1574
|
!this.options.keepSplatData
|
|
1575
|
-
), 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 =
|
|
1575
|
+
), this.material.setTransformA(this.textureManager.transformA), this.material.setTransformB(this.textureManager.transformB), this.material.setColorTexture(this.textureManager.colorTexture), this.material.setOrderTexture(this.textureManager.orderTexture), this.material.setNumSplats(0), this.geometry.boundingBox = o.boundingBox.toBox3(), this.geometry.boundingSphere = new l.Sphere(), this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere), this.options.keepSplatData || (this.splatData = null);
|
|
1576
1576
|
}
|
|
1577
1577
|
/**
|
|
1578
1578
|
* Creates the instanced geometry for rendering splats.
|
|
@@ -1580,8 +1580,8 @@ const se = class se extends l.Mesh {
|
|
|
1580
1580
|
* @param instanceSize Number of splats per instance.
|
|
1581
1581
|
* @returns InstancedBufferGeometry
|
|
1582
1582
|
*/
|
|
1583
|
-
static createInstancedGeometry(
|
|
1584
|
-
const
|
|
1583
|
+
static createInstancedGeometry(o, t) {
|
|
1584
|
+
const r = Math.ceil(o / t), n = new l.BufferGeometry(), a = new Float32Array([
|
|
1585
1585
|
// x, y, splat_index_in_instance
|
|
1586
1586
|
-1,
|
|
1587
1587
|
-1,
|
|
@@ -1595,24 +1595,24 @@ const se = class se extends l.Mesh {
|
|
|
1595
1595
|
-1,
|
|
1596
1596
|
1,
|
|
1597
1597
|
0
|
|
1598
|
-
]), i = new Uint16Array([0, 1, 2, 0, 2, 3]), u = new Float32Array(4 * 3 *
|
|
1599
|
-
for (let
|
|
1600
|
-
const
|
|
1601
|
-
for (let
|
|
1602
|
-
u[
|
|
1598
|
+
]), i = new Uint16Array([0, 1, 2, 0, 2, 3]), u = new Float32Array(4 * 3 * t);
|
|
1599
|
+
for (let h = 0; h < t; h++) {
|
|
1600
|
+
const b = h * 4 * 3;
|
|
1601
|
+
for (let S = 0; S < 4; S++)
|
|
1602
|
+
u[b + S * 3 + 0] = a[S * 3 + 0], u[b + S * 3 + 1] = a[S * 3 + 1], u[b + S * 3 + 2] = h;
|
|
1603
1603
|
}
|
|
1604
|
-
const
|
|
1605
|
-
for (let
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1604
|
+
const w = new Uint32Array(6 * t);
|
|
1605
|
+
for (let h = 0; h < t; h++) {
|
|
1606
|
+
const b = h * 6, S = h * 4;
|
|
1607
|
+
w[b + 0] = i[0] + S, w[b + 1] = i[1] + S, w[b + 2] = i[2] + S, w[b + 3] = i[3] + S, w[b + 4] = i[4] + S, w[b + 5] = i[5] + S;
|
|
1608
1608
|
}
|
|
1609
|
-
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1612
|
-
const
|
|
1613
|
-
for (let
|
|
1614
|
-
|
|
1615
|
-
return
|
|
1609
|
+
n.setAttribute("position", new l.BufferAttribute(u, 3)), n.setIndex(new l.BufferAttribute(w, 1));
|
|
1610
|
+
const C = new l.InstancedBufferGeometry();
|
|
1611
|
+
C.index = n.index, C.setAttribute("position", n.getAttribute("position"));
|
|
1612
|
+
const _ = new Uint32Array(r);
|
|
1613
|
+
for (let h = 0; h < r; h++)
|
|
1614
|
+
_[h] = h * t;
|
|
1615
|
+
return C.setAttribute("splatInstanceIndex", new l.InstancedBufferAttribute(_, 1, !1)), C.instanceCount = 0, C;
|
|
1616
1616
|
}
|
|
1617
1617
|
/**
|
|
1618
1618
|
* Create chunks data (bounding box min/max) for the sorter.
|
|
@@ -1621,14 +1621,14 @@ const se = class se extends l.Mesh {
|
|
|
1621
1621
|
createChunks() {
|
|
1622
1622
|
if (!this.splatData)
|
|
1623
1623
|
return null;
|
|
1624
|
-
const
|
|
1625
|
-
return
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1624
|
+
const o = this.splatData.boundingBox;
|
|
1625
|
+
return o.min.x === 1 / 0 || o.max.x === -1 / 0 ? null : new Float32Array([
|
|
1626
|
+
o.min.x,
|
|
1627
|
+
o.min.y,
|
|
1628
|
+
o.min.z,
|
|
1629
|
+
o.max.x,
|
|
1630
|
+
o.max.y,
|
|
1631
|
+
o.max.z
|
|
1632
1632
|
]);
|
|
1633
1633
|
}
|
|
1634
1634
|
/**
|
|
@@ -1636,17 +1636,17 @@ const se = class se extends l.Mesh {
|
|
|
1636
1636
|
* @param width Viewport width
|
|
1637
1637
|
* @param height Viewport height
|
|
1638
1638
|
*/
|
|
1639
|
-
updateViewport(
|
|
1640
|
-
|
|
1639
|
+
updateViewport(o, t) {
|
|
1640
|
+
o === this._vpW && t === this._vpH || (this._vpW = o, this._vpH = t, this.material.updateViewport(o, t));
|
|
1641
1641
|
}
|
|
1642
1642
|
/**
|
|
1643
1643
|
* Sorts splats based on camera position and direction.
|
|
1644
1644
|
* @param camera The camera to sort against.
|
|
1645
1645
|
*/
|
|
1646
|
-
sort(
|
|
1647
|
-
|
|
1648
|
-
const
|
|
1649
|
-
this.options.autoSort && (
|
|
1646
|
+
sort(o) {
|
|
1647
|
+
o.getWorldPosition(this._camPosW), o.getWorldDirection(this._camDirW), this.invModelMatrix.copy(this.matrixWorld).invert(), this._camPosL.copy(this._camPosW).applyMatrix4(this.invModelMatrix), this._camDirL.copy(this._camDirW).transformDirection(this.invModelMatrix);
|
|
1648
|
+
const t = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6, r = this.lastCameraDirectionLocal.dot(this._camDirL) < 0.999;
|
|
1649
|
+
this.options.autoSort && (t || r) && (this.lastCameraPositionLocal.copy(this._camPosL), this.lastCameraDirectionLocal.copy(this._camDirL), this.sorter.setCamera(this._camPosL, this._camDirL));
|
|
1650
1650
|
}
|
|
1651
1651
|
/**
|
|
1652
1652
|
* THREE.js hook called before rendering the object.
|
|
@@ -1657,8 +1657,8 @@ const se = class se extends l.Mesh {
|
|
|
1657
1657
|
*/
|
|
1658
1658
|
// prettier-ignore
|
|
1659
1659
|
// @ts-expect-error scene is not used
|
|
1660
|
-
onBeforeRender(
|
|
1661
|
-
this.sort(
|
|
1660
|
+
onBeforeRender(o, t, r) {
|
|
1661
|
+
this.sort(r), o.getSize(this._size), this.updateViewport(this._size.x, this._size.y);
|
|
1662
1662
|
}
|
|
1663
1663
|
/**
|
|
1664
1664
|
* Dispose of resources
|
|
@@ -1668,36 +1668,39 @@ const se = class se extends l.Mesh {
|
|
|
1668
1668
|
}
|
|
1669
1669
|
};
|
|
1670
1670
|
/** Number of splats combined into a single instanced draw call. */
|
|
1671
|
-
|
|
1672
|
-
let
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
Object.defineProperty(le.prototype, qe, {
|
|
1676
|
-
value: !0,
|
|
1677
|
-
configurable: !1,
|
|
1678
|
-
enumerable: !1,
|
|
1679
|
-
writable: !1
|
|
1680
|
-
});
|
|
1681
|
-
} catch {
|
|
1682
|
-
console.warn("Couldn't define Visus SplatMesh symbol");
|
|
1683
|
-
}
|
|
1684
|
-
const Ye = ({
|
|
1685
|
-
plyUrl: A,
|
|
1671
|
+
f(se, "INSTANCE_SIZE", 128);
|
|
1672
|
+
let de = se;
|
|
1673
|
+
const le = /* @__PURE__ */ new Map(), He = ({
|
|
1674
|
+
plyUrl: x,
|
|
1686
1675
|
debug: e = !1,
|
|
1687
|
-
splatOptions:
|
|
1688
|
-
...
|
|
1676
|
+
splatOptions: o = {},
|
|
1677
|
+
...t
|
|
1689
1678
|
}) => {
|
|
1690
|
-
|
|
1691
|
-
const
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1679
|
+
e && console.debug("SPLAT: rendering", { plyUrl: x, splatOptions: o, meshProps: t });
|
|
1680
|
+
const [r, n] = Ce(null), a = Ae(null);
|
|
1681
|
+
return Te(() => {
|
|
1682
|
+
const i = we(x, o);
|
|
1683
|
+
return je(x, o).then(
|
|
1684
|
+
(u) => {
|
|
1685
|
+
n(u);
|
|
1686
|
+
}
|
|
1687
|
+
), () => {
|
|
1688
|
+
e && console.debug("SPLAT: releasing mesh for", x), We(i);
|
|
1689
|
+
};
|
|
1690
|
+
}, [x, o, e]), r ? /* @__PURE__ */ Ie.jsx("primitive", { ref: a, object: r, ...t }) : null;
|
|
1691
|
+
}, we = (x, e) => `${x}:${JSON.stringify(e)}`, je = async (x, e) => {
|
|
1692
|
+
const o = we(x, e), t = le.get(o);
|
|
1693
|
+
if (t)
|
|
1694
|
+
return t.refCount++, t.mesh;
|
|
1695
|
+
const n = await new ze().loadAsync(x), a = new de(n, e);
|
|
1696
|
+
return le.set(o, { mesh: a, refCount: 1 }), a;
|
|
1698
1697
|
};
|
|
1698
|
+
function We(x) {
|
|
1699
|
+
const e = le.get(x);
|
|
1700
|
+
e && (e.refCount--, e.refCount <= 0 && (e.mesh.dispose(), le.delete(x)));
|
|
1701
|
+
}
|
|
1699
1702
|
export {
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
+
ze as PlyLoader,
|
|
1704
|
+
He as Splat,
|
|
1705
|
+
de as SplatMesh
|
|
1703
1706
|
};
|