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