@speridlabs/visus 2.4.3 → 2.5.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/dist/main.d.ts +454 -344
- package/dist/main.es.js +1160 -946
- package/dist/main.umd.js +80 -12
- package/dist/react.d.ts +8 -1
- package/dist/react.es.js +1046 -833
- package/package.json +1 -1
package/dist/main.es.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
class
|
|
1
|
+
var Ye = Object.defineProperty;
|
|
2
|
+
var Ze = (a, e, t) => e in a ? Ye(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var d = (a, e, t) => Ze(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import * as c from "three";
|
|
5
|
+
class we {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
d(this, "min", new c.Vector3(1 / 0, 1 / 0, 1 / 0));
|
|
8
|
+
d(this, "max", new c.Vector3(-1 / 0, -1 / 0, -1 / 0));
|
|
9
|
+
d(this, "center", new c.Vector3());
|
|
10
10
|
/** Half extents (size/2) */
|
|
11
|
-
|
|
11
|
+
d(this, "halfExtents", new c.Vector3());
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Reset the bounding box to its initial state
|
|
@@ -20,15 +20,15 @@ class wt {
|
|
|
20
20
|
* Expand the bounding box to include the given point
|
|
21
21
|
* @param point Point to include in the bounding box
|
|
22
22
|
*/
|
|
23
|
-
expandByPoint(
|
|
24
|
-
this.min.x = Math.min(this.min.x,
|
|
23
|
+
expandByPoint(e) {
|
|
24
|
+
this.min.x = Math.min(this.min.x, e.x), this.min.y = Math.min(this.min.y, e.y), this.min.z = Math.min(this.min.z, e.z), this.max.x = Math.max(this.max.x, e.x), this.max.y = Math.max(this.max.y, e.y), this.max.z = Math.max(this.max.z, e.z), this.updateDerived();
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Expand this bounding box to include another bounding box
|
|
28
28
|
* @param box Bounding box to include
|
|
29
29
|
*/
|
|
30
|
-
expandByBox(
|
|
31
|
-
this.min.x = Math.min(this.min.x,
|
|
30
|
+
expandByBox(e) {
|
|
31
|
+
this.min.x = Math.min(this.min.x, e.min.x), this.min.y = Math.min(this.min.y, e.min.y), this.min.z = Math.min(this.min.z, e.min.z), this.max.x = Math.max(this.max.x, e.max.x), this.max.y = Math.max(this.max.y, e.max.y), this.max.z = Math.max(this.max.z, e.max.z), this.updateDerived();
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Update the center and half extents based on min/max
|
|
@@ -41,38 +41,38 @@ class wt {
|
|
|
41
41
|
* @param point Point to check
|
|
42
42
|
* @returns True if the point is inside the box
|
|
43
43
|
*/
|
|
44
|
-
containsPoint(
|
|
45
|
-
return
|
|
44
|
+
containsPoint(e) {
|
|
45
|
+
return e.x >= this.min.x && e.x <= this.max.x && e.y >= this.min.y && e.y <= this.max.y && e.z >= this.min.z && e.z <= this.max.z;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Create a Three.js Box3 from this bounding box
|
|
49
49
|
* @returns THREE.Box3 representation
|
|
50
50
|
*/
|
|
51
51
|
toBox3() {
|
|
52
|
-
return new
|
|
52
|
+
return new c.Box3().set(this.min, this.max);
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Create a clone of this bounding box
|
|
56
56
|
* @returns New bounding box with the same values
|
|
57
57
|
*/
|
|
58
58
|
clone() {
|
|
59
|
-
const
|
|
60
|
-
return
|
|
59
|
+
const e = new we();
|
|
60
|
+
return e.min.copy(this.min), e.max.copy(this.max), e.center.copy(this.center), e.halfExtents.copy(this.halfExtents), e;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
class
|
|
64
|
-
constructor(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.numSplats =
|
|
73
|
-
}
|
|
74
|
-
allocateBuffers(
|
|
75
|
-
this.positions = new Float32Array(
|
|
63
|
+
class Xe {
|
|
64
|
+
constructor(e = 0) {
|
|
65
|
+
d(this, "numSplats", 0);
|
|
66
|
+
d(this, "positions");
|
|
67
|
+
d(this, "rotations");
|
|
68
|
+
d(this, "scales");
|
|
69
|
+
d(this, "colors");
|
|
70
|
+
d(this, "opacities");
|
|
71
|
+
d(this, "boundingBox", new we());
|
|
72
|
+
this.numSplats = e, this.allocateBuffers(e);
|
|
73
|
+
}
|
|
74
|
+
allocateBuffers(e) {
|
|
75
|
+
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);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Set data for a specific splat
|
|
@@ -83,49 +83,49 @@ class jt {
|
|
|
83
83
|
* @param color Color
|
|
84
84
|
* @param opacity Opacity value
|
|
85
85
|
*/
|
|
86
|
-
setSplat(
|
|
87
|
-
if (
|
|
86
|
+
setSplat(e, t, s, n, r, i) {
|
|
87
|
+
if (e >= this.numSplats)
|
|
88
88
|
throw new Error(
|
|
89
|
-
`Splat index out of bounds: ${
|
|
89
|
+
`Splat index out of bounds: ${e} >= ${this.numSplats}`
|
|
90
90
|
);
|
|
91
|
-
const
|
|
92
|
-
this.positions[
|
|
91
|
+
const o = e * 3, m = e * 4, y = e * 3, u = e * 3;
|
|
92
|
+
this.positions[o] = t.x, this.positions[o + 1] = t.y, this.positions[o + 2] = t.z, this.rotations[m] = s.x, this.rotations[m + 1] = s.y, this.rotations[m + 2] = s.z, this.rotations[m + 3] = s.w, this.scales[y] = n.x, this.scales[y + 1] = n.y, this.scales[y + 2] = n.z, this.colors[u] = r.r, this.colors[u + 1] = r.g, this.colors[u + 2] = r.b, this.opacities[e] = i;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Get a splat's data
|
|
96
96
|
* @param index Splat index
|
|
97
97
|
* @returns Object containing splat data (linear scale)
|
|
98
98
|
*/
|
|
99
|
-
getSplat(
|
|
100
|
-
if (
|
|
99
|
+
getSplat(e) {
|
|
100
|
+
if (e >= this.numSplats)
|
|
101
101
|
throw new Error(
|
|
102
|
-
`Splat index out of bounds: ${
|
|
102
|
+
`Splat index out of bounds: ${e} >= ${this.numSplats}`
|
|
103
103
|
);
|
|
104
|
-
const
|
|
104
|
+
const t = e * 3, s = e * 4, n = e * 3, r = e * 3;
|
|
105
105
|
return {
|
|
106
|
-
position: new
|
|
107
|
-
this.positions[
|
|
108
|
-
this.positions[
|
|
109
|
-
this.positions[
|
|
106
|
+
position: new c.Vector3(
|
|
107
|
+
this.positions[t],
|
|
108
|
+
this.positions[t + 1],
|
|
109
|
+
this.positions[t + 2]
|
|
110
110
|
),
|
|
111
|
-
rotation: new
|
|
111
|
+
rotation: new c.Quaternion(
|
|
112
112
|
this.rotations[s],
|
|
113
113
|
this.rotations[s + 1],
|
|
114
114
|
this.rotations[s + 2],
|
|
115
115
|
this.rotations[s + 3]
|
|
116
116
|
),
|
|
117
117
|
// Convert log scale back to linear scale for external use
|
|
118
|
-
scale: new
|
|
118
|
+
scale: new c.Vector3(
|
|
119
119
|
Math.exp(this.scales[n]),
|
|
120
120
|
Math.exp(this.scales[n + 1]),
|
|
121
121
|
Math.exp(this.scales[n + 2])
|
|
122
122
|
),
|
|
123
|
-
color: new
|
|
123
|
+
color: new c.Color(
|
|
124
124
|
this.colors[r],
|
|
125
125
|
this.colors[r + 1],
|
|
126
126
|
this.colors[r + 2]
|
|
127
127
|
),
|
|
128
|
-
opacity: this.opacities[
|
|
128
|
+
opacity: this.opacities[e]
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
@@ -134,14 +134,14 @@ class jt {
|
|
|
134
134
|
*/
|
|
135
135
|
calculateBoundingBox() {
|
|
136
136
|
this.boundingBox.reset();
|
|
137
|
-
const
|
|
138
|
-
for (let
|
|
139
|
-
const s =
|
|
140
|
-
|
|
137
|
+
const e = new c.Vector3();
|
|
138
|
+
for (let t = 0; t < this.numSplats; t++) {
|
|
139
|
+
const s = t * 3;
|
|
140
|
+
e.set(
|
|
141
141
|
this.positions[s],
|
|
142
142
|
this.positions[s + 1],
|
|
143
143
|
this.positions[s + 2]
|
|
144
|
-
), this.boundingBox.expandByPoint(
|
|
144
|
+
), this.boundingBox.expandByPoint(e);
|
|
145
145
|
}
|
|
146
146
|
return this.boundingBox;
|
|
147
147
|
}
|
|
@@ -150,134 +150,134 @@ class jt {
|
|
|
150
150
|
* This is for visualization/debugging purposes only, not for rendering
|
|
151
151
|
*/
|
|
152
152
|
createDebugGeometry() {
|
|
153
|
-
const
|
|
154
|
-
|
|
153
|
+
const e = new c.BufferGeometry();
|
|
154
|
+
e.setAttribute(
|
|
155
155
|
"position",
|
|
156
|
-
new
|
|
156
|
+
new c.BufferAttribute(this.positions, 3)
|
|
157
157
|
);
|
|
158
|
-
const
|
|
158
|
+
const t = new Float32Array(this.numSplats * 3), s = new c.Quaternion(), n = new c.Euler();
|
|
159
159
|
for (let r = 0; r < this.numSplats; r++) {
|
|
160
|
-
const
|
|
160
|
+
const i = r * 4, o = r * 3;
|
|
161
161
|
s.set(
|
|
162
|
-
this.rotations[
|
|
163
|
-
this.rotations[
|
|
164
|
-
this.rotations[
|
|
165
|
-
this.rotations[
|
|
166
|
-
), n.setFromQuaternion(s),
|
|
162
|
+
this.rotations[i],
|
|
163
|
+
this.rotations[i + 1],
|
|
164
|
+
this.rotations[i + 2],
|
|
165
|
+
this.rotations[i + 3]
|
|
166
|
+
), n.setFromQuaternion(s), t[o] = n.x, t[o + 1] = n.y, t[o + 2] = n.z;
|
|
167
167
|
}
|
|
168
|
-
return
|
|
168
|
+
return e.setAttribute(
|
|
169
169
|
"rotation",
|
|
170
|
-
new
|
|
171
|
-
),
|
|
170
|
+
new c.BufferAttribute(t, 3)
|
|
171
|
+
), e.setAttribute(
|
|
172
172
|
"scale",
|
|
173
|
-
new
|
|
174
|
-
),
|
|
173
|
+
new c.BufferAttribute(this.scales, 3)
|
|
174
|
+
), e.setAttribute(
|
|
175
175
|
"color",
|
|
176
|
-
new
|
|
177
|
-
),
|
|
176
|
+
new c.BufferAttribute(this.colors, 3)
|
|
177
|
+
), e.setAttribute(
|
|
178
178
|
"opacity",
|
|
179
|
-
new
|
|
180
|
-
),
|
|
179
|
+
new c.BufferAttribute(this.opacities, 1)
|
|
180
|
+
), e;
|
|
181
181
|
}
|
|
182
182
|
dispose() {
|
|
183
183
|
this.numSplats = 0, this.scales = new Float32Array(0), this.colors = new Float32Array(0), this.positions = new Float32Array(0), this.rotations = new Float32Array(0), this.opacities = new Float32Array(0);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
class
|
|
186
|
+
class Ee {
|
|
187
187
|
// Upper 8 bits of 16-bit means
|
|
188
|
-
constructor(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
constructor(e, t, s) {
|
|
189
|
+
d(this, "ranges");
|
|
190
|
+
d(this, "version", 1);
|
|
191
|
+
d(this, "numSplats", 0);
|
|
192
|
+
d(this, "boundingBox", new we());
|
|
193
193
|
// Original SOGS textures
|
|
194
|
-
|
|
194
|
+
d(this, "sh0");
|
|
195
195
|
// SH DC coefficients + alpha
|
|
196
|
-
|
|
196
|
+
d(this, "quats");
|
|
197
197
|
// Quaternion components + mode
|
|
198
|
-
|
|
198
|
+
d(this, "scales");
|
|
199
199
|
// Scale values (8-bit)
|
|
200
|
-
|
|
200
|
+
d(this, "means_l");
|
|
201
201
|
// Lower 8 bits of 16-bit means
|
|
202
|
-
|
|
203
|
-
this.ranges =
|
|
202
|
+
d(this, "means_u");
|
|
203
|
+
this.ranges = t, this.numSplats = e, this.sh0 = s.sh0, this.quats = s.quats, this.scales = s.scales, this.means_l = s.means_l, this.means_u = s.means_u, this.boundingBox = this.calculateBoundingBox();
|
|
204
204
|
}
|
|
205
205
|
calculateBoundingBox() {
|
|
206
206
|
this.boundingBox.reset();
|
|
207
|
-
const { mins:
|
|
207
|
+
const { mins: e, maxs: t } = this.ranges.means, s = (n) => Math.sign(n) * (Math.exp(Math.abs(n)) - 1);
|
|
208
208
|
return this.boundingBox.center.set(
|
|
209
|
-
(s(
|
|
210
|
-
(s(
|
|
211
|
-
(s(
|
|
209
|
+
(s(e[0]) + s(t[0])) * 0.5,
|
|
210
|
+
(s(e[1]) + s(t[1])) * 0.5,
|
|
211
|
+
(s(e[2]) + s(t[2])) * 0.5
|
|
212
212
|
), this.boundingBox.halfExtents.set(
|
|
213
|
-
(s(
|
|
214
|
-
(s(
|
|
215
|
-
(s(
|
|
213
|
+
(s(t[0]) - s(e[0])) * 0.5,
|
|
214
|
+
(s(t[1]) - s(e[1])) * 0.5,
|
|
215
|
+
(s(t[2]) - s(e[2])) * 0.5
|
|
216
216
|
), this.boundingBox;
|
|
217
217
|
}
|
|
218
218
|
dispose() {
|
|
219
219
|
this.sh0.dispose(), this.quats.dispose(), this.scales.dispose(), this.means_l.dispose(), this.means_u.dispose();
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
class
|
|
222
|
+
class qe {
|
|
223
223
|
// Upper 8 bits of 16-bit means
|
|
224
|
-
constructor(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
constructor(e, t, s) {
|
|
225
|
+
d(this, "ranges");
|
|
226
|
+
d(this, "version", 2);
|
|
227
|
+
d(this, "numSplats", 0);
|
|
228
|
+
d(this, "boundingBox", new we());
|
|
229
229
|
// Original SOGS textures
|
|
230
|
-
|
|
230
|
+
d(this, "sh0");
|
|
231
231
|
// SH DC coefficients + alpha
|
|
232
|
-
|
|
232
|
+
d(this, "quats");
|
|
233
233
|
// Quaternion components + mode
|
|
234
|
-
|
|
234
|
+
d(this, "scales");
|
|
235
235
|
// Scale values (8-bit)
|
|
236
|
-
|
|
236
|
+
d(this, "means_l");
|
|
237
237
|
// Lower 8 bits of 16-bit means
|
|
238
|
-
|
|
239
|
-
this.ranges =
|
|
238
|
+
d(this, "means_u");
|
|
239
|
+
this.ranges = t, this.numSplats = e, this.sh0 = s.sh0, this.quats = s.quats, this.scales = s.scales, this.means_l = s.means_l, this.means_u = s.means_u, this.boundingBox = this.calculateBoundingBox();
|
|
240
240
|
}
|
|
241
241
|
calculateBoundingBox() {
|
|
242
242
|
this.boundingBox.reset();
|
|
243
|
-
const { mins:
|
|
243
|
+
const { mins: e, maxs: t } = this.ranges.means, s = (n) => Math.sign(n) * (Math.exp(Math.abs(n)) - 1);
|
|
244
244
|
return this.boundingBox.center.set(
|
|
245
|
-
(s(
|
|
246
|
-
(s(
|
|
247
|
-
(s(
|
|
245
|
+
(s(e[0]) + s(t[0])) * 0.5,
|
|
246
|
+
(s(e[1]) + s(t[1])) * 0.5,
|
|
247
|
+
(s(e[2]) + s(t[2])) * 0.5
|
|
248
248
|
), this.boundingBox.halfExtents.set(
|
|
249
|
-
(s(
|
|
250
|
-
(s(
|
|
251
|
-
(s(
|
|
249
|
+
(s(t[0]) - s(e[0])) * 0.5,
|
|
250
|
+
(s(t[1]) - s(e[1])) * 0.5,
|
|
251
|
+
(s(t[2]) - s(e[2])) * 0.5
|
|
252
252
|
), this.boundingBox;
|
|
253
253
|
}
|
|
254
254
|
dispose() {
|
|
255
255
|
this.sh0.dispose(), this.quats.dispose(), this.scales.dispose(), this.means_l.dispose(), this.means_u.dispose();
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
class
|
|
258
|
+
class Ae {
|
|
259
259
|
// RGBA32UI - (Position + Rotation + Scale)
|
|
260
260
|
// RGBA32UI Texture Content:
|
|
261
261
|
// .r = Means Lower (RGB)
|
|
262
262
|
// .g = Means Upper (RGB)
|
|
263
263
|
// .b = Rotation (RGBA)
|
|
264
264
|
// .a = Scale (RGB)
|
|
265
|
-
constructor(
|
|
265
|
+
constructor(e, t, s, n, r, i, o, m) {
|
|
266
266
|
// Info data - cpu
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
267
|
+
d(this, "numSplats");
|
|
268
|
+
d(this, "textureWidth");
|
|
269
|
+
d(this, "textureHeight");
|
|
270
|
+
d(this, "ranges");
|
|
271
|
+
d(this, "centers");
|
|
272
272
|
// TODO: see if necesary or can be compressed somehow
|
|
273
|
-
|
|
273
|
+
d(this, "boundingBox");
|
|
274
274
|
// GPU Textures
|
|
275
|
-
|
|
275
|
+
d(this, "packedColor");
|
|
276
276
|
// RGBA8 - (Color + Opacity)
|
|
277
277
|
// RGBA8 Texture Content:
|
|
278
278
|
// .rgb = Color, .a = Opacity
|
|
279
|
-
|
|
280
|
-
this.numSplats =
|
|
279
|
+
d(this, "packedGeometry");
|
|
280
|
+
this.numSplats = e, this.textureWidth = t, this.textureHeight = s, this.boundingBox = m, this.ranges = o, this.centers = n, this.packedColor = i, this.packedGeometry = r;
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
283
283
|
* Optional: Reconstruct a full JS object for a specific splat.
|
|
@@ -292,34 +292,34 @@ class At {
|
|
|
292
292
|
// public abstract deserialize(): ISplat;
|
|
293
293
|
// public abstract returnPacked(): ISplat;
|
|
294
294
|
}
|
|
295
|
-
class
|
|
295
|
+
class Qe extends c.EventDispatcher {
|
|
296
296
|
constructor() {
|
|
297
297
|
super();
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
d(this, "worker");
|
|
299
|
+
d(this, "centers", null);
|
|
300
|
+
d(this, "orderTexture", null);
|
|
301
301
|
/** Bounding box data for optimization */
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
302
|
+
d(this, "chunks", null);
|
|
303
|
+
d(this, "lastCameraPosition", new c.Vector3());
|
|
304
|
+
d(this, "lastCameraDirection", new c.Vector3());
|
|
305
|
+
const t = this.createWorkerCode(), s = new Blob([t], { type: "application/javascript" });
|
|
306
306
|
this.worker = new Worker(URL.createObjectURL(s)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
307
307
|
}
|
|
308
308
|
/**
|
|
309
309
|
* Handles messages received from the sorting worker.
|
|
310
310
|
* @param event The message event from the worker.
|
|
311
311
|
*/
|
|
312
|
-
onWorkerMessage(
|
|
312
|
+
onWorkerMessage(t) {
|
|
313
313
|
if (!this.orderTexture || !this.orderTexture.image)
|
|
314
314
|
return console.error("SplatSorter: Order texture not initialized!");
|
|
315
|
-
const { order: s, count: n } =
|
|
315
|
+
const { order: s, count: n } = t.data, r = this.orderTexture.image.data;
|
|
316
316
|
if (!(r instanceof Uint32Array))
|
|
317
317
|
return console.error(
|
|
318
318
|
"SplatSorter: Order texture data is not a Uint32Array!"
|
|
319
319
|
);
|
|
320
320
|
r.set(new Uint32Array(s)), this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
|
|
321
|
-
const
|
|
322
|
-
this.worker.postMessage(
|
|
321
|
+
const i = r.buffer.slice(0), o = { order: i };
|
|
322
|
+
this.worker.postMessage(o, [i]), this.dispatchEvent({ type: "updated", count: n });
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
325
325
|
* Initializes the sorter with necessary data and textures.
|
|
@@ -328,38 +328,38 @@ class Yt extends l.EventDispatcher {
|
|
|
328
328
|
* @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
|
|
329
329
|
* @param transferOwnership Optional: If true, transfers ownership of centers buffer to worker (saves memory, main thread loses access). Default: false.
|
|
330
330
|
*/
|
|
331
|
-
init(
|
|
332
|
-
if (!
|
|
331
|
+
init(t, s, n, r = !1) {
|
|
332
|
+
if (!t || !(t.image.data instanceof Uint32Array))
|
|
333
333
|
throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
|
|
334
334
|
if (!s || s.length % 3 !== 0)
|
|
335
335
|
throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
|
|
336
|
-
if (
|
|
336
|
+
if (t.image.data.length < s.length / 3)
|
|
337
337
|
throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");
|
|
338
338
|
if (s.buffer.byteLength === 0)
|
|
339
339
|
throw new Error(
|
|
340
340
|
"SplatSorter: positions buffer is detached (likely React StrictMode + cached asset). "
|
|
341
341
|
);
|
|
342
|
-
const
|
|
343
|
-
this.orderTexture =
|
|
344
|
-
const
|
|
345
|
-
for (let h = 0; h <
|
|
342
|
+
const i = s.length / 3;
|
|
343
|
+
this.orderTexture = t, r ? this.centers = null : this.centers = s.slice();
|
|
344
|
+
const o = this.orderTexture.image.data;
|
|
345
|
+
for (let h = 0; h < i; h++) o[h] = h;
|
|
346
346
|
this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
|
|
347
|
-
const
|
|
348
|
-
order:
|
|
347
|
+
const m = o.buffer.slice(0), y = r ? s.buffer : s.buffer.slice(0), u = {
|
|
348
|
+
order: m,
|
|
349
349
|
centers: y
|
|
350
|
-
},
|
|
351
|
-
|
|
350
|
+
}, l = [
|
|
351
|
+
m,
|
|
352
352
|
y
|
|
353
353
|
];
|
|
354
354
|
if (n) {
|
|
355
355
|
this.chunks = n.slice();
|
|
356
356
|
const h = this.chunks.buffer.slice(0);
|
|
357
|
-
|
|
357
|
+
u.chunks = h, l.push(h);
|
|
358
358
|
}
|
|
359
|
-
this.worker.postMessage(
|
|
359
|
+
this.worker.postMessage(u, l), queueMicrotask(() => {
|
|
360
360
|
this.dispatchEvent({
|
|
361
361
|
type: "updated",
|
|
362
|
-
count:
|
|
362
|
+
count: i
|
|
363
363
|
});
|
|
364
364
|
});
|
|
365
365
|
}
|
|
@@ -368,53 +368,53 @@ class Yt extends l.EventDispatcher {
|
|
|
368
368
|
* The sorter will only consider splats whose original indices are present in the mapping.
|
|
369
369
|
* @param mapping A Uint32Array where each element is the *original* index of a splat to include, or null to reset mapping.
|
|
370
370
|
*/
|
|
371
|
-
setMapping(
|
|
371
|
+
setMapping(t) {
|
|
372
372
|
if (!this.centers)
|
|
373
373
|
return console.warn(
|
|
374
374
|
"SplatSorter: Cannot set mapping before initialization."
|
|
375
375
|
);
|
|
376
376
|
let s;
|
|
377
377
|
const n = [];
|
|
378
|
-
if (!
|
|
379
|
-
const
|
|
378
|
+
if (!t) {
|
|
379
|
+
const m = this.centers.buffer.slice(0);
|
|
380
380
|
return s = {
|
|
381
|
-
centers:
|
|
381
|
+
centers: m,
|
|
382
382
|
mapping: null
|
|
383
|
-
}, n.push(
|
|
383
|
+
}, n.push(m), this.worker.postMessage(s, n);
|
|
384
384
|
}
|
|
385
|
-
const r = new Float32Array(
|
|
386
|
-
for (let
|
|
387
|
-
const y =
|
|
385
|
+
const r = new Float32Array(t.length * 3);
|
|
386
|
+
for (let m = 0; m < t.length; m++) {
|
|
387
|
+
const y = t[m];
|
|
388
388
|
if (y * 3 + 2 >= this.centers.length) {
|
|
389
389
|
console.warn(
|
|
390
390
|
`SplatSorter: Mapping index ${y} out of bounds.`
|
|
391
391
|
);
|
|
392
392
|
continue;
|
|
393
393
|
}
|
|
394
|
-
const
|
|
395
|
-
r[
|
|
394
|
+
const u = y * 3, l = m * 3;
|
|
395
|
+
r[l + 0] = this.centers[u + 0], r[l + 1] = this.centers[u + 1], r[l + 2] = this.centers[u + 2];
|
|
396
396
|
}
|
|
397
|
-
const
|
|
397
|
+
const i = r.buffer.slice(0), o = t.buffer.slice(0);
|
|
398
398
|
s = {
|
|
399
|
-
centers:
|
|
400
|
-
mapping:
|
|
401
|
-
}, n.push(
|
|
399
|
+
centers: i,
|
|
400
|
+
mapping: o
|
|
401
|
+
}, n.push(i, o), this.worker.postMessage(s, n);
|
|
402
402
|
}
|
|
403
403
|
/**
|
|
404
404
|
* Updates the camera parameters used for sorting.
|
|
405
405
|
* @param position The camera's position in the sorter's local coordinate space.
|
|
406
406
|
* @param direction The camera's forward direction in the sorter's local coordinate space.
|
|
407
407
|
*/
|
|
408
|
-
setCamera(
|
|
409
|
-
const n = this.lastCameraPosition.distanceToSquared(
|
|
408
|
+
setCamera(t, s) {
|
|
409
|
+
const n = this.lastCameraPosition.distanceToSquared(t) > 1e-7, r = this.lastCameraDirection.dot(s) < 0.9999;
|
|
410
410
|
if (!n && !r)
|
|
411
411
|
return;
|
|
412
|
-
this.lastCameraPosition.copy(
|
|
413
|
-
const
|
|
414
|
-
cameraPosition: { x:
|
|
412
|
+
this.lastCameraPosition.copy(t), this.lastCameraDirection.copy(s);
|
|
413
|
+
const i = {
|
|
414
|
+
cameraPosition: { x: t.x, y: t.y, z: t.z },
|
|
415
415
|
cameraDirection: { x: s.x, y: s.y, z: s.z }
|
|
416
416
|
};
|
|
417
|
-
this.worker.postMessage(
|
|
417
|
+
this.worker.postMessage(i);
|
|
418
418
|
}
|
|
419
419
|
/**
|
|
420
420
|
* Terminates the Web Worker and cleans up resources.
|
|
@@ -428,186 +428,336 @@ class Yt extends l.EventDispatcher {
|
|
|
428
428
|
*/
|
|
429
429
|
createWorkerCode() {
|
|
430
430
|
return `(${(function() {
|
|
431
|
-
let s = null, n = null, r = null,
|
|
432
|
-
const
|
|
431
|
+
let s = null, n = null, r = null, i = null, o = null, m = null, y = !1;
|
|
432
|
+
const u = { x: 0, y: 0, z: 0 }, l = { x: 0, y: 0, z: 0 }, h = { x: 0, y: 0, z: 0 }, f = { x: 0, y: 0, z: 0 };
|
|
433
433
|
let w = null, A = null;
|
|
434
|
-
const b = 32,
|
|
435
|
-
for (;
|
|
436
|
-
const S = M +
|
|
437
|
-
if (g > 0)
|
|
434
|
+
const b = 32, B = new Array(b).fill(0), T = new Array(b).fill(0), E = new Array(b).fill(0), U = (C, M, k) => {
|
|
435
|
+
for (; C <= M; ) {
|
|
436
|
+
const S = M + C >> 1, g = k(S);
|
|
437
|
+
if (g > 0) C = S + 1;
|
|
438
438
|
else if (g < 0) M = S - 1;
|
|
439
439
|
else return S;
|
|
440
440
|
}
|
|
441
|
-
return ~
|
|
442
|
-
},
|
|
443
|
-
if (!s || !n || !
|
|
441
|
+
return ~C;
|
|
442
|
+
}, R = () => {
|
|
443
|
+
if (!s || !n || !o || !m)
|
|
444
444
|
return;
|
|
445
445
|
if (n.length === 0) {
|
|
446
|
-
const
|
|
446
|
+
const x = {
|
|
447
447
|
order: s.buffer,
|
|
448
448
|
count: 0
|
|
449
449
|
};
|
|
450
|
-
self.postMessage(
|
|
450
|
+
self.postMessage(x, [s.buffer]), s = null;
|
|
451
451
|
return;
|
|
452
452
|
}
|
|
453
|
-
const
|
|
454
|
-
if (!y && !
|
|
453
|
+
const C = o.x, M = o.y, k = o.z, S = m.x, g = m.y, v = m.z, O = 1e-4, V = Math.abs(C - u.x) > O || Math.abs(M - u.y) > O || Math.abs(k - u.z) > O, I = Math.abs(S - l.x) > O || Math.abs(g - l.y) > O || Math.abs(v - l.z) > O;
|
|
454
|
+
if (!y && !V && !I)
|
|
455
455
|
return;
|
|
456
|
-
y = !1,
|
|
457
|
-
let
|
|
458
|
-
for (let
|
|
459
|
-
const
|
|
460
|
-
|
|
456
|
+
y = !1, u.x = C, u.y = M, u.z = k, l.x = S, l.y = g, l.z = v;
|
|
457
|
+
let q = 1 / 0, p = -1 / 0;
|
|
458
|
+
for (let x = 0; x < 8; ++x) {
|
|
459
|
+
const D = x & 1 ? h.x : f.x, L = x & 2 ? h.y : f.y, P = x & 4 ? h.z : f.z, G = D * S + L * g + P * v;
|
|
460
|
+
q = Math.min(q, G), p = Math.max(p, G);
|
|
461
461
|
}
|
|
462
|
-
const
|
|
462
|
+
const _ = n.length / 3, H = p - q, F = (1 << Math.max(
|
|
463
463
|
10,
|
|
464
|
-
Math.min(20, Math.ceil(Math.log2(
|
|
464
|
+
Math.min(20, Math.ceil(Math.log2(_ / 4)))
|
|
465
465
|
)) + 1;
|
|
466
|
-
if ((!w || w.length !==
|
|
467
|
-
for (let
|
|
468
|
-
A[0] =
|
|
466
|
+
if ((!w || w.length !== _) && (w = new Uint32Array(_)), !A || A.length !== F ? A = new Uint32Array(F) : A.fill(0), H < 1e-7) {
|
|
467
|
+
for (let x = 0; x < _; ++x) w[x] = 0;
|
|
468
|
+
A[0] = _;
|
|
469
469
|
} else if (r && r.length > 0) {
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
for (let
|
|
473
|
-
const G =
|
|
470
|
+
const x = r.length / 6;
|
|
471
|
+
B.fill(0);
|
|
472
|
+
for (let P = 0; P < x; ++P) {
|
|
473
|
+
const G = P * 6, X = r[G + 0], j = r[G + 1], Q = r[G + 2], $ = r[G + 3], K = X * S + j * g + Q * v - q, ee = K - $, te = K + $, ue = Math.max(
|
|
474
474
|
0,
|
|
475
|
-
Math.floor(
|
|
476
|
-
),
|
|
475
|
+
Math.floor(ee * b / H)
|
|
476
|
+
), de = Math.min(
|
|
477
477
|
b,
|
|
478
|
-
Math.ceil(
|
|
478
|
+
Math.ceil(te * b / H)
|
|
479
479
|
);
|
|
480
|
-
for (let
|
|
481
|
-
|
|
480
|
+
for (let ie = ue; ie < de; ++ie)
|
|
481
|
+
B[ie]++;
|
|
482
482
|
}
|
|
483
|
-
let
|
|
484
|
-
for (let
|
|
485
|
-
|
|
486
|
-
for (let
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const L =
|
|
490
|
-
for (let
|
|
491
|
-
const G =
|
|
483
|
+
let D = 0;
|
|
484
|
+
for (let P = 0; P < b; ++P) D += B[P];
|
|
485
|
+
E[0] = 0, T[0] = 0;
|
|
486
|
+
for (let P = 1; P < b; ++P)
|
|
487
|
+
E[P - 1] = B[P - 1] / D * F >>> 0, T[P] = T[P - 1] + E[P - 1];
|
|
488
|
+
E[b - 1] = B[b - 1] / D * F >>> 0;
|
|
489
|
+
const L = H / b;
|
|
490
|
+
for (let P = 0; P < _; ++P) {
|
|
491
|
+
const G = P * 3, X = n[G + 0], j = n[G + 1], Q = n[G + 2], $ = X * S + j * g + Q * v, ee = (p - $) / L, te = Math.max(
|
|
492
492
|
0,
|
|
493
493
|
Math.min(
|
|
494
494
|
b - 1,
|
|
495
|
-
Math.floor(
|
|
495
|
+
Math.floor(ee)
|
|
496
496
|
)
|
|
497
|
-
),
|
|
498
|
-
w[
|
|
497
|
+
), ue = ee - te, de = T[te] + E[te] * ue >>> 0, ie = Math.min(de, F - 1);
|
|
498
|
+
w[P] = ie, A[ie]++;
|
|
499
499
|
}
|
|
500
500
|
} else {
|
|
501
|
-
const
|
|
502
|
-
for (let
|
|
503
|
-
const L =
|
|
504
|
-
w[
|
|
501
|
+
const x = (F - 1) / H;
|
|
502
|
+
for (let D = 0; D < _; ++D) {
|
|
503
|
+
const L = D * 3, P = n[L + 0], G = n[L + 1], X = n[L + 2], j = P * S + G * g + X * v, $ = (p - j) * x >>> 0, K = Math.min($, F - 1);
|
|
504
|
+
w[D] = K, A[K]++;
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
for (let
|
|
508
|
-
A[
|
|
509
|
-
for (let
|
|
510
|
-
const
|
|
511
|
-
s[L] =
|
|
507
|
+
for (let x = 1; x < F; x++)
|
|
508
|
+
A[x] += A[x - 1];
|
|
509
|
+
for (let x = _ - 1; x >= 0; x--) {
|
|
510
|
+
const D = w[x], L = --A[D];
|
|
511
|
+
s[L] = i ? i[x] : x;
|
|
512
512
|
}
|
|
513
|
-
const J =
|
|
513
|
+
const J = C * S + M * g + k * v, Z = (x) => {
|
|
514
514
|
if (!s) return -1 / 0;
|
|
515
|
-
const
|
|
515
|
+
const D = s[x], L = D;
|
|
516
516
|
if (!n || L * 3 + 2 >= n.length)
|
|
517
517
|
return -1 / 0;
|
|
518
|
-
const
|
|
519
|
-
return n[
|
|
518
|
+
const P = L * 3;
|
|
519
|
+
return n[P] * S + n[P + 1] * g + n[P + 2] * v - J;
|
|
520
520
|
};
|
|
521
|
-
let
|
|
522
|
-
if (
|
|
523
|
-
const
|
|
521
|
+
let Y = _;
|
|
522
|
+
if (_ > 0 && Z(_ - 1) < 0) {
|
|
523
|
+
const x = U(
|
|
524
524
|
0,
|
|
525
|
-
|
|
525
|
+
_ - 1,
|
|
526
526
|
Z
|
|
527
527
|
);
|
|
528
|
-
|
|
528
|
+
Y = x < 0 ? ~x : x;
|
|
529
529
|
}
|
|
530
|
-
const
|
|
530
|
+
const z = {
|
|
531
531
|
order: s.buffer,
|
|
532
|
-
count:
|
|
532
|
+
count: Y
|
|
533
533
|
};
|
|
534
|
-
self.postMessage(
|
|
534
|
+
self.postMessage(z, [s.buffer]), s = null;
|
|
535
535
|
};
|
|
536
|
-
self.onmessage = (
|
|
537
|
-
const M =
|
|
536
|
+
self.onmessage = (C) => {
|
|
537
|
+
const M = C.data;
|
|
538
538
|
M.order && (s = new Uint32Array(M.order));
|
|
539
|
-
let
|
|
540
|
-
if (M.centers && (n = new Float32Array(M.centers),
|
|
539
|
+
let k = !1;
|
|
540
|
+
if (M.centers && (n = new Float32Array(M.centers), k = !0, y = !0), Object.prototype.hasOwnProperty.call(M, "mapping") && (i = M.mapping ? new Uint32Array(M.mapping) : null, y = !0), M.chunks) {
|
|
541
541
|
if (r = new Float32Array(M.chunks), r.length > 0 && r[3] > 0)
|
|
542
542
|
for (let S = 0; S < r.length / 6; ++S) {
|
|
543
|
-
const g = S * 6, v = r[g + 0],
|
|
544
|
-
r[g + 0] = (v + I) * 0.5, r[g + 1] = (
|
|
545
|
-
(I - v) ** 2 + (
|
|
543
|
+
const g = S * 6, v = r[g + 0], O = r[g + 1], V = r[g + 2], I = r[g + 3], q = r[g + 4], p = r[g + 5];
|
|
544
|
+
r[g + 0] = (v + I) * 0.5, r[g + 1] = (O + q) * 0.5, r[g + 2] = (V + p) * 0.5, r[g + 3] = Math.sqrt(
|
|
545
|
+
(I - v) ** 2 + (q - O) ** 2 + (p - V) ** 2
|
|
546
546
|
) * 0.5;
|
|
547
547
|
}
|
|
548
548
|
y = !0;
|
|
549
549
|
}
|
|
550
|
-
if (
|
|
551
|
-
h.x =
|
|
550
|
+
if (k && n && n.length > 0) {
|
|
551
|
+
h.x = f.x = n[0], h.y = f.y = n[1], h.z = f.z = n[2];
|
|
552
552
|
for (let S = 1; S < n.length / 3; S++) {
|
|
553
553
|
const g = S * 3;
|
|
554
|
-
h.x = Math.min(h.x, n[g + 0]),
|
|
554
|
+
h.x = Math.min(h.x, n[g + 0]), f.x = Math.max(f.x, n[g + 0]), h.y = Math.min(h.y, n[g + 1]), f.y = Math.max(f.y, n[g + 1]), h.z = Math.min(h.z, n[g + 2]), f.z = Math.max(f.z, n[g + 2]);
|
|
555
555
|
}
|
|
556
|
-
} else
|
|
557
|
-
M.cameraPosition && (
|
|
556
|
+
} else k && n && n.length === 0 && (h.x = f.x = h.y = f.y = h.z = f.z = 0);
|
|
557
|
+
M.cameraPosition && (o = M.cameraPosition), M.cameraDirection && (m = M.cameraDirection), R();
|
|
558
558
|
};
|
|
559
559
|
}).toString()})();`;
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
562
|
+
const Je = {
|
|
563
|
+
type: "wave",
|
|
564
|
+
defaultDuration: 3,
|
|
565
|
+
shaderCode: (
|
|
566
|
+
/* glsl */
|
|
567
|
+
`
|
|
568
|
+
void applyAnimation(
|
|
569
|
+
inout vec3 position,
|
|
570
|
+
inout vec3 scale,
|
|
571
|
+
inout vec4 color,
|
|
572
|
+
float progress,
|
|
573
|
+
vec3 center
|
|
574
|
+
) {
|
|
575
|
+
const float DIST_K = 0.3;
|
|
576
|
+
const float WAVE_GAIN = 1.2;
|
|
577
|
+
const float INV_WAVE_W = 20.0;
|
|
578
|
+
const vec3 GLOW = vec3(1.0, 1.0, 1.0);
|
|
579
|
+
|
|
580
|
+
float dist = length(position - center);
|
|
581
|
+
float normalizedDist = 1.0 - exp(-dist * DIST_K);
|
|
582
|
+
float waveProgress = progress * WAVE_GAIN;
|
|
583
|
+
|
|
584
|
+
float glowIntensity = clamp(1.0 - abs(normalizedDist - waveProgress) * INV_WAVE_W, 0.0, 1.0);
|
|
585
|
+
color.rgb = mix(color.rgb, GLOW, glowIntensity);
|
|
586
|
+
}
|
|
587
|
+
`
|
|
588
|
+
)
|
|
589
|
+
}, Ke = {
|
|
590
|
+
type: "spread",
|
|
591
|
+
defaultDuration: 3,
|
|
592
|
+
shaderCode: (
|
|
593
|
+
/* glsl */
|
|
594
|
+
`
|
|
595
|
+
void applyAnimation(
|
|
596
|
+
inout vec3 position,
|
|
597
|
+
inout vec3 scale,
|
|
598
|
+
inout vec4 color,
|
|
599
|
+
float progress,
|
|
600
|
+
vec3 center
|
|
601
|
+
) {
|
|
602
|
+
const float DIST_K = 0.3;
|
|
603
|
+
const float WAVE_GAIN = 1.2;
|
|
604
|
+
const float SPHERE_LOG = -6.0;
|
|
605
|
+
const float INV_WAVE_W = 20.0; // 1.0 / 0.05 wave width, precomputed
|
|
606
|
+
const vec3 GOLD = vec3(1.0, 1.0, 1.0); // pure white
|
|
607
|
+
|
|
608
|
+
float dist = length(position - center);
|
|
609
|
+
float normalizedDist = 1.0 - exp(-dist * DIST_K);
|
|
610
|
+
float waveProgress = progress * WAVE_GAIN;
|
|
611
|
+
|
|
612
|
+
float revealed = step(normalizedDist, waveProgress);
|
|
613
|
+
scale = mix(vec3(SPHERE_LOG), scale, revealed);
|
|
614
|
+
|
|
615
|
+
float glowIntensity = clamp(1.0 - abs(normalizedDist - waveProgress) * INV_WAVE_W, 0.0, 1.0);
|
|
616
|
+
color.rgb = mix(color.rgb, GOLD, glowIntensity);
|
|
617
|
+
}
|
|
618
|
+
`
|
|
619
|
+
)
|
|
620
|
+
}, et = {
|
|
621
|
+
type: "none",
|
|
622
|
+
defaultDuration: 0,
|
|
623
|
+
shaderCode: (
|
|
624
|
+
/* glsl */
|
|
625
|
+
`
|
|
626
|
+
void applyAnimation(
|
|
627
|
+
inout vec3 position,
|
|
628
|
+
inout vec3 scale,
|
|
629
|
+
inout vec4 color,
|
|
630
|
+
float progress,
|
|
631
|
+
vec3 center
|
|
632
|
+
) {}
|
|
633
|
+
`
|
|
634
|
+
)
|
|
635
|
+
}, Fe = {
|
|
636
|
+
spread: Ke,
|
|
637
|
+
wave: Je,
|
|
638
|
+
none: et
|
|
639
|
+
}, Le = (a) => Fe[a] ?? Fe.none, Te = {
|
|
640
|
+
linear: (a) => a,
|
|
641
|
+
easeInQuad: (a) => a * a,
|
|
642
|
+
easeOutQuad: (a) => a * (2 - a),
|
|
643
|
+
easeInOutQuad: (a) => a < 0.5 ? 2 * a * a : -1 + (4 - 2 * a) * a,
|
|
644
|
+
easeInCubic: (a) => a * a * a,
|
|
645
|
+
easeOutCubic: (a) => 1 - Math.pow(1 - a, 3),
|
|
646
|
+
easeInOutCubic: (a) => a < 0.5 ? 4 * a * a * a : 1 - Math.pow(-2 * a + 2, 3) / 2,
|
|
647
|
+
easeOutExpo: (a) => a === 1 ? 1 : 1 - Math.pow(2, -10 * a)
|
|
648
|
+
}, tt = (a) => Te[a] ?? Te.linear;
|
|
649
|
+
class st {
|
|
650
|
+
constructor(e) {
|
|
651
|
+
d(this, "_progress", 0);
|
|
652
|
+
d(this, "_isPlaying", !1);
|
|
653
|
+
d(this, "_isComplete", !1);
|
|
654
|
+
d(this, "_startTime", 0);
|
|
655
|
+
d(this, "_duration");
|
|
656
|
+
d(this, "_delay");
|
|
657
|
+
d(this, "_easing");
|
|
658
|
+
d(this, "_type");
|
|
659
|
+
d(this, "_autoPlay");
|
|
660
|
+
// Animation center (set from bounding box)
|
|
661
|
+
d(this, "_center", new c.Vector3());
|
|
662
|
+
const t = Le(e.type);
|
|
663
|
+
this._type = e.type, this._duration = e.duration ?? t.defaultDuration, this._delay = e.delay ?? 0, this._easing = tt(e.easing ?? "easeOutCubic"), this._autoPlay = e.autoPlay ?? !0;
|
|
664
|
+
}
|
|
665
|
+
/** Current progress 0-1 (eased) */
|
|
666
|
+
get progress() {
|
|
667
|
+
return this._progress;
|
|
668
|
+
}
|
|
669
|
+
get isPlaying() {
|
|
670
|
+
return this._isPlaying;
|
|
671
|
+
}
|
|
672
|
+
get isComplete() {
|
|
673
|
+
return this._isComplete;
|
|
674
|
+
}
|
|
675
|
+
get type() {
|
|
676
|
+
return this._type;
|
|
677
|
+
}
|
|
678
|
+
get center() {
|
|
679
|
+
return this._center;
|
|
680
|
+
}
|
|
681
|
+
/** Set the animation center point (typically bounding box center) */
|
|
682
|
+
setCenter(e) {
|
|
683
|
+
this._center.copy(e);
|
|
684
|
+
}
|
|
685
|
+
play() {
|
|
686
|
+
this._startTime = -1, this._isPlaying = !0, this._isComplete = !1, this._progress = 0;
|
|
687
|
+
}
|
|
688
|
+
stop() {
|
|
689
|
+
this._isPlaying = !1;
|
|
690
|
+
}
|
|
691
|
+
reset() {
|
|
692
|
+
this._progress = 0, this._isPlaying = !1, this._isComplete = !1, this._startTime = 0;
|
|
693
|
+
}
|
|
694
|
+
/** Skip to end state */
|
|
695
|
+
complete() {
|
|
696
|
+
this._progress = 1, this._isPlaying = !1, this._isComplete = !0;
|
|
697
|
+
}
|
|
698
|
+
/** Called from onBeforeRender - returns true if uniforms need update */
|
|
699
|
+
update(e) {
|
|
700
|
+
if (!this._isPlaying) return !1;
|
|
701
|
+
this._startTime < 0 && (this._startTime = e + this._delay);
|
|
702
|
+
const t = e - this._startTime;
|
|
703
|
+
if (t < 0) return !1;
|
|
704
|
+
const s = Math.min(t / this._duration, 1);
|
|
705
|
+
return this._progress = this._easing(s), s >= 1 && (this._isPlaying = !1, this._isComplete = !0, this._progress = 1), !0;
|
|
706
|
+
}
|
|
707
|
+
/** Should auto-play be triggered on load? */
|
|
708
|
+
shouldAutoPlay() {
|
|
709
|
+
return this._autoPlay && !this._isComplete;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
class nt {
|
|
713
|
+
constructor(e) {
|
|
714
|
+
d(this, "packedGeometry");
|
|
565
715
|
// RGBA32UI
|
|
566
|
-
|
|
716
|
+
d(this, "packedColor");
|
|
567
717
|
// RGBA8
|
|
568
|
-
|
|
718
|
+
d(this, "orderTexture");
|
|
569
719
|
// RB32UI
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
this.width =
|
|
720
|
+
d(this, "width");
|
|
721
|
+
d(this, "height");
|
|
722
|
+
this.width = e.textureWidth, this.height = e.textureHeight, this.packedColor = this.createColorTexture(e), this.packedGeometry = this.createGeometryTexture(e), this.orderTexture = this.createOrderTexture(e.numSplats);
|
|
573
723
|
}
|
|
574
|
-
createGeometryTexture(
|
|
575
|
-
const
|
|
576
|
-
|
|
724
|
+
createGeometryTexture(e) {
|
|
725
|
+
const t = new c.DataTexture(
|
|
726
|
+
e.packedGeometry,
|
|
577
727
|
this.width,
|
|
578
728
|
this.height,
|
|
579
|
-
|
|
580
|
-
|
|
729
|
+
c.RGBAIntegerFormat,
|
|
730
|
+
c.UnsignedIntType
|
|
581
731
|
);
|
|
582
|
-
return
|
|
732
|
+
return t.internalFormat = "RGBA32UI", t.minFilter = c.NearestFilter, t.magFilter = c.NearestFilter, t.needsUpdate = !0, t;
|
|
583
733
|
}
|
|
584
|
-
createColorTexture(
|
|
585
|
-
const
|
|
586
|
-
|
|
734
|
+
createColorTexture(e) {
|
|
735
|
+
const t = new c.DataTexture(
|
|
736
|
+
e.packedColor,
|
|
587
737
|
this.width,
|
|
588
738
|
this.height,
|
|
589
|
-
|
|
590
|
-
|
|
739
|
+
c.RGBAFormat,
|
|
740
|
+
c.UnsignedByteType
|
|
591
741
|
);
|
|
592
|
-
return
|
|
742
|
+
return t.minFilter = c.NearestFilter, t.magFilter = c.NearestFilter, t.needsUpdate = !0, t;
|
|
593
743
|
}
|
|
594
|
-
createOrderTexture(
|
|
595
|
-
const
|
|
596
|
-
for (let n = 0; n <
|
|
597
|
-
const s = new
|
|
598
|
-
|
|
744
|
+
createOrderTexture(e) {
|
|
745
|
+
const t = new Uint32Array(this.width * this.height);
|
|
746
|
+
for (let n = 0; n < e; n++) t[n] = n;
|
|
747
|
+
const s = new c.DataTexture(
|
|
748
|
+
t,
|
|
599
749
|
this.width,
|
|
600
750
|
this.height,
|
|
601
|
-
|
|
602
|
-
|
|
751
|
+
c.RedIntegerFormat,
|
|
752
|
+
c.UnsignedIntType
|
|
603
753
|
);
|
|
604
|
-
return s.minFilter =
|
|
754
|
+
return s.minFilter = c.NearestFilter, s.magFilter = c.NearestFilter, s.needsUpdate = !0, s;
|
|
605
755
|
}
|
|
606
756
|
dispose() {
|
|
607
757
|
this.packedGeometry.dispose(), this.packedColor.dispose(), this.orderTexture.dispose();
|
|
608
758
|
}
|
|
609
759
|
}
|
|
610
|
-
const
|
|
760
|
+
const Ve = (
|
|
611
761
|
/* glsl */
|
|
612
762
|
`
|
|
613
763
|
precision highp float;
|
|
@@ -632,6 +782,12 @@ uniform vec3 scalesMax;
|
|
|
632
782
|
uniform vec3 sh0Min;
|
|
633
783
|
uniform vec3 sh0Max;
|
|
634
784
|
|
|
785
|
+
// --- Animation Uniforms ---
|
|
786
|
+
uniform float animationProgress; // 0 = start, 1 = complete
|
|
787
|
+
uniform vec3 animationCenter; // Center point for animation
|
|
788
|
+
|
|
789
|
+
/* @ANIMATION_CODE */
|
|
790
|
+
|
|
635
791
|
// --- Attributes ---
|
|
636
792
|
in uint splatInstanceIndex;
|
|
637
793
|
|
|
@@ -730,11 +886,10 @@ void main() {
|
|
|
730
886
|
else if (mode == 2u) quat = vec4(abc.xy, d, abc.z); // stored (w,x,z)
|
|
731
887
|
else quat = vec4(abc, d); // stored (w,x,y)
|
|
732
888
|
|
|
733
|
-
// Decompress Scale
|
|
889
|
+
// Decompress Scale (log-space)
|
|
734
890
|
uvec3 sB = unpackBytes(geom.w).xyz;
|
|
735
891
|
vec3 sNorm = vec3(sB) * (1.0 / 255.0);
|
|
736
|
-
vec3
|
|
737
|
-
vec3 scale = exp(sLerp); // log scale stored
|
|
892
|
+
vec3 scale = mix(scalesMin, scalesMax, sNorm); // log-space scale
|
|
738
893
|
|
|
739
894
|
// Decompress Color & Opacity
|
|
740
895
|
vec4 clr;
|
|
@@ -742,6 +897,12 @@ void main() {
|
|
|
742
897
|
clr.rgb = vec3(0.5) + sh * SH_C0;
|
|
743
898
|
clr.a = colorRaw.a; // Opacity passed directly (linear or sigmoid handled by loader)
|
|
744
899
|
|
|
900
|
+
// --- Apply Animation (modifies position, scale, color in place) ---
|
|
901
|
+
/* @ANIMATION_CALL */
|
|
902
|
+
|
|
903
|
+
// Convert log-space scale to linear scale
|
|
904
|
+
scale = exp(scale);
|
|
905
|
+
|
|
745
906
|
// --- Standard Gaussian Splat Projection ---
|
|
746
907
|
|
|
747
908
|
// View Space Setup
|
|
@@ -795,9 +956,12 @@ void main() {
|
|
|
795
956
|
float l2 = 2.0 * min(sqrt(2.0 * lambda2), vmin);
|
|
796
957
|
|
|
797
958
|
// Discard tiny splats
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
959
|
+
// TODO: this branch might create some performance issues - check
|
|
960
|
+
if (animationProgress >= 1.0) {
|
|
961
|
+
if (l1 < 2.0 && l2 < 2.0) {
|
|
962
|
+
gl_Position = DISCARD_VERTEX;
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
801
965
|
}
|
|
802
966
|
|
|
803
967
|
vec2 diagVec = normalize(vec2(offDiagonal, lambda1 - diagonal1));
|
|
@@ -832,7 +996,7 @@ void main() {
|
|
|
832
996
|
vColor = vec4(max(clr.rgb, vec3(0.0)), clr.a);
|
|
833
997
|
}
|
|
834
998
|
`
|
|
835
|
-
),
|
|
999
|
+
), at = (
|
|
836
1000
|
/* glsl */
|
|
837
1001
|
`
|
|
838
1002
|
precision highp float;
|
|
@@ -868,9 +1032,9 @@ void main(void) {
|
|
|
868
1032
|
}
|
|
869
1033
|
`
|
|
870
1034
|
);
|
|
871
|
-
class
|
|
1035
|
+
class rt extends c.ShaderMaterial {
|
|
872
1036
|
constructor(t = {}) {
|
|
873
|
-
const
|
|
1037
|
+
const s = {
|
|
874
1038
|
// Packed Textures
|
|
875
1039
|
packedGeometry: { value: null },
|
|
876
1040
|
// RGBA32UI: .r=MeansLow, .g=MeansHigh, .b=Quats, .a=Scales
|
|
@@ -879,36 +1043,42 @@ class Qt extends l.ShaderMaterial {
|
|
|
879
1043
|
splatOrder: { value: null },
|
|
880
1044
|
// Index map
|
|
881
1045
|
// Decompression Ranges
|
|
882
|
-
meansMin: { value: new
|
|
883
|
-
meansMax: { value: new
|
|
884
|
-
scalesMin: { value: new
|
|
885
|
-
scalesMax: { value: new
|
|
886
|
-
sh0Min: { value: new
|
|
887
|
-
sh0Max: { value: new
|
|
1046
|
+
meansMin: { value: new c.Vector3() },
|
|
1047
|
+
meansMax: { value: new c.Vector3() },
|
|
1048
|
+
scalesMin: { value: new c.Vector3() },
|
|
1049
|
+
scalesMax: { value: new c.Vector3() },
|
|
1050
|
+
sh0Min: { value: new c.Vector3() },
|
|
1051
|
+
sh0Max: { value: new c.Vector3() },
|
|
888
1052
|
// Render State
|
|
889
1053
|
texWidth: { value: 0 },
|
|
890
|
-
viewport: { value: new
|
|
891
|
-
numSplats: { value: 0 }
|
|
1054
|
+
viewport: { value: new c.Vector2(1, 1) },
|
|
1055
|
+
numSplats: { value: 0 },
|
|
1056
|
+
// Animation State
|
|
1057
|
+
animationProgress: { value: 1 },
|
|
1058
|
+
// 1 = no animation active
|
|
1059
|
+
animationCenter: { value: new c.Vector3() }
|
|
892
1060
|
};
|
|
893
1061
|
super({
|
|
894
|
-
uniforms:
|
|
895
|
-
vertexShader:
|
|
896
|
-
fragmentShader:
|
|
1062
|
+
uniforms: s,
|
|
1063
|
+
vertexShader: Ve,
|
|
1064
|
+
fragmentShader: at,
|
|
897
1065
|
transparent: !0,
|
|
898
|
-
glslVersion:
|
|
899
|
-
blendSrc:
|
|
900
|
-
blendSrcAlpha:
|
|
901
|
-
blending:
|
|
902
|
-
blendEquation:
|
|
903
|
-
blendEquationAlpha:
|
|
904
|
-
blendDst:
|
|
905
|
-
blendDstAlpha:
|
|
1066
|
+
glslVersion: c.GLSL3,
|
|
1067
|
+
blendSrc: c.OneFactor,
|
|
1068
|
+
blendSrcAlpha: c.OneFactor,
|
|
1069
|
+
blending: c.CustomBlending,
|
|
1070
|
+
blendEquation: c.AddEquation,
|
|
1071
|
+
blendEquationAlpha: c.AddEquation,
|
|
1072
|
+
blendDst: c.OneMinusSrcAlphaFactor,
|
|
1073
|
+
blendDstAlpha: c.OneMinusSrcAlphaFactor,
|
|
906
1074
|
depthTest: !0,
|
|
907
1075
|
depthWrite: !1,
|
|
908
|
-
side:
|
|
1076
|
+
side: c.DoubleSide,
|
|
909
1077
|
alphaTest: t.alphaTest ?? 0,
|
|
910
1078
|
toneMapped: t.toneMapped ?? !1
|
|
911
|
-
})
|
|
1079
|
+
});
|
|
1080
|
+
d(this, "_shaderTemplate");
|
|
1081
|
+
t.alphaHash && (this.alphaHash = !0, this.depthWrite = !0, this.blending = c.NoBlending), this._shaderTemplate = Ve;
|
|
912
1082
|
}
|
|
913
1083
|
setTexWidth(t) {
|
|
914
1084
|
this.uniforms.texWidth.value = t | 0;
|
|
@@ -918,8 +1088,8 @@ class Qt extends l.ShaderMaterial {
|
|
|
918
1088
|
* @param width Viewport width
|
|
919
1089
|
* @param height Viewport height
|
|
920
1090
|
*/
|
|
921
|
-
updateViewport(t,
|
|
922
|
-
this.uniforms.viewport.value.set(t,
|
|
1091
|
+
updateViewport(t, s) {
|
|
1092
|
+
this.uniforms.viewport.value.set(t, s);
|
|
923
1093
|
}
|
|
924
1094
|
/**
|
|
925
1095
|
* Set the main packed geometry texture (RGBA32UI)
|
|
@@ -952,41 +1122,78 @@ class Qt extends l.ShaderMaterial {
|
|
|
952
1122
|
setNumSplats(t) {
|
|
953
1123
|
this.uniforms.numSplats.value = t;
|
|
954
1124
|
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Configure animation effect. Rebuilds shader with effect's GLSL code.
|
|
1127
|
+
* @param effect - Animation effect to use (null to disable)
|
|
1128
|
+
*/
|
|
1129
|
+
setAnimation(t) {
|
|
1130
|
+
let s = this._shaderTemplate;
|
|
1131
|
+
t && t.type !== "none" ? (s = s.replace(
|
|
1132
|
+
"/* @ANIMATION_CODE */",
|
|
1133
|
+
t.shaderCode
|
|
1134
|
+
), s = s.replace(
|
|
1135
|
+
"/* @ANIMATION_CALL */",
|
|
1136
|
+
`if (animationProgress < 1.0) {
|
|
1137
|
+
applyAnimation(modelCenter, scale, clr, animationProgress, animationCenter);
|
|
1138
|
+
}`
|
|
1139
|
+
)) : (s = s.replace("/* @ANIMATION_CODE */", ""), s = s.replace("/* @ANIMATION_CALL */", "")), this.vertexShader = s, this.needsUpdate = !0;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Set animation progress (0 = start, 1 = complete/no animation)
|
|
1143
|
+
*/
|
|
1144
|
+
setAnimationProgress(t) {
|
|
1145
|
+
this.uniforms.animationProgress.value = t;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Set animation center point
|
|
1149
|
+
*/
|
|
1150
|
+
setAnimationCenter(t) {
|
|
1151
|
+
this.uniforms.animationCenter.value.copy(t);
|
|
1152
|
+
}
|
|
955
1153
|
}
|
|
956
|
-
const
|
|
1154
|
+
const xe = class xe extends c.Mesh {
|
|
957
1155
|
// Match shader constant
|
|
958
1156
|
/**
|
|
959
1157
|
* Create a new SplatMesh for rendering Gaussian splats
|
|
960
1158
|
* @param splatData The splat data to render
|
|
961
1159
|
* @param options Rendering options
|
|
962
1160
|
*/
|
|
963
|
-
constructor(
|
|
964
|
-
const n = new
|
|
1161
|
+
constructor(t, s = {}) {
|
|
1162
|
+
const n = new rt(s), r = xe.createInstancedGeometry(t.numSplats, xe.INSTANCE_SIZE);
|
|
965
1163
|
super(r, n);
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1164
|
+
d(this, "sorter");
|
|
1165
|
+
d(this, "options");
|
|
1166
|
+
d(this, "splatData");
|
|
1167
|
+
d(this, "textureManager");
|
|
1168
|
+
/** Animation controller (null if no animation configured) */
|
|
1169
|
+
d(this, "animation", null);
|
|
1170
|
+
d(this, "material");
|
|
1171
|
+
d(this, "geometry");
|
|
1172
|
+
d(this, "lastCameraPositionLocal", new c.Vector3());
|
|
1173
|
+
d(this, "lastCameraDirectionLocal", new c.Vector3());
|
|
1174
|
+
d(this, "invModelMatrix", new c.Matrix4());
|
|
975
1175
|
// Cached inverse matrix
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
const s =
|
|
985
|
-
this.geometry.instanceCount = Math.ceil(s /
|
|
1176
|
+
d(this, "_vpW", -1);
|
|
1177
|
+
d(this, "_vpH", -1);
|
|
1178
|
+
d(this, "_size", new c.Vector2());
|
|
1179
|
+
d(this, "_camPosW", new c.Vector3());
|
|
1180
|
+
d(this, "_camDirW", new c.Vector3());
|
|
1181
|
+
d(this, "_camPosL", new c.Vector3());
|
|
1182
|
+
d(this, "_camDirL", new c.Vector3());
|
|
1183
|
+
d(this, "onSorterUpdated", (t) => {
|
|
1184
|
+
const s = t.count;
|
|
1185
|
+
this.geometry.instanceCount = Math.ceil(s / xe.INSTANCE_SIZE), this.material.setNumSplats(s);
|
|
986
1186
|
});
|
|
987
|
-
this.geometry = r, this.material = n, this.options = { autoSort: !0, ...s }, this.splatData =
|
|
988
|
-
let
|
|
989
|
-
|
|
1187
|
+
this.geometry = r, this.material = n, this.options = { autoSort: !0, ...s }, this.splatData = t, this.frustumCulled = !1, this.sorter = new Qe(), this.textureManager = new nt(t);
|
|
1188
|
+
let i = this.createChunks() || void 0;
|
|
1189
|
+
if (i === null && console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."), i = void 0, this.sorter.addEventListener("updated", this.onSorterUpdated), this.sorter.init(this.textureManager.orderTexture, this.splatData.centers, i ?? void 0, !this.options.keepSplatData), this.material.setRanges(t.ranges), this.material.setTexWidth(t.textureWidth), this.material.setPackedColor(this.textureManager.packedColor), this.material.setOrderTexture(this.textureManager.orderTexture), this.material.setPackedGeometry(this.textureManager.packedGeometry), this.material.setNumSplats(0), s.animation && s.animation.type !== "none") {
|
|
1190
|
+
this.animation = new st(s.animation);
|
|
1191
|
+
const o = new c.Vector3();
|
|
1192
|
+
t.boundingBox.toBox3().getCenter(o), this.animation.setCenter(o);
|
|
1193
|
+
const m = Le(s.animation.type);
|
|
1194
|
+
this.material.setAnimation(m), this.material.setAnimationCenter(o), this.material.setAnimationProgress(0);
|
|
1195
|
+
}
|
|
1196
|
+
this.geometry.boundingBox = t.boundingBox.toBox3(), this.geometry.boundingSphere = new c.Sphere(), this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere), this.options.keepSplatData || (this.splatData = null);
|
|
990
1197
|
}
|
|
991
1198
|
/**
|
|
992
1199
|
* Creates the instanced geometry for rendering splats.
|
|
@@ -994,8 +1201,8 @@ const xt = class xt extends l.Mesh {
|
|
|
994
1201
|
* @param instanceSize Number of splats per instance.
|
|
995
1202
|
* @returns InstancedBufferGeometry
|
|
996
1203
|
*/
|
|
997
|
-
static createInstancedGeometry(
|
|
998
|
-
const n = Math.ceil(
|
|
1204
|
+
static createInstancedGeometry(t, s) {
|
|
1205
|
+
const n = Math.ceil(t / s), r = new c.BufferGeometry(), i = new Float32Array([
|
|
999
1206
|
// x, y, splat_index_in_instance
|
|
1000
1207
|
-1,
|
|
1001
1208
|
-1,
|
|
@@ -1009,24 +1216,24 @@ const xt = class xt extends l.Mesh {
|
|
|
1009
1216
|
-1,
|
|
1010
1217
|
1,
|
|
1011
1218
|
0
|
|
1012
|
-
]),
|
|
1219
|
+
]), o = new Uint16Array([0, 1, 2, 0, 2, 3]), m = new Float32Array(4 * 3 * s);
|
|
1013
1220
|
for (let h = 0; h < s; h++) {
|
|
1014
|
-
const
|
|
1221
|
+
const f = h * 4 * 3;
|
|
1015
1222
|
for (let w = 0; w < 4; w++)
|
|
1016
|
-
|
|
1223
|
+
m[f + w * 3 + 0] = i[w * 3 + 0], m[f + w * 3 + 1] = i[w * 3 + 1], m[f + w * 3 + 2] = h;
|
|
1017
1224
|
}
|
|
1018
1225
|
const y = new Uint32Array(6 * s);
|
|
1019
1226
|
for (let h = 0; h < s; h++) {
|
|
1020
|
-
const
|
|
1021
|
-
y[
|
|
1227
|
+
const f = h * 6, w = h * 4;
|
|
1228
|
+
y[f + 0] = o[0] + w, y[f + 1] = o[1] + w, y[f + 2] = o[2] + w, y[f + 3] = o[3] + w, y[f + 4] = o[4] + w, y[f + 5] = o[5] + w;
|
|
1022
1229
|
}
|
|
1023
|
-
r.setAttribute("position", new
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1230
|
+
r.setAttribute("position", new c.BufferAttribute(m, 3)), r.setIndex(new c.BufferAttribute(y, 1));
|
|
1231
|
+
const u = new c.InstancedBufferGeometry();
|
|
1232
|
+
u.index = r.index, u.setAttribute("position", r.getAttribute("position"));
|
|
1233
|
+
const l = new Uint32Array(n);
|
|
1027
1234
|
for (let h = 0; h < n; h++)
|
|
1028
|
-
|
|
1029
|
-
return
|
|
1235
|
+
l[h] = h * s;
|
|
1236
|
+
return u.setAttribute("splatInstanceIndex", new c.InstancedBufferAttribute(l, 1, !1)), u.instanceCount = 0, u;
|
|
1030
1237
|
}
|
|
1031
1238
|
/**
|
|
1032
1239
|
* Create chunks data (bounding box min/max) for the sorter.
|
|
@@ -1035,14 +1242,14 @@ const xt = class xt extends l.Mesh {
|
|
|
1035
1242
|
createChunks() {
|
|
1036
1243
|
if (!this.splatData)
|
|
1037
1244
|
return null;
|
|
1038
|
-
const
|
|
1039
|
-
return
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1245
|
+
const t = this.splatData.boundingBox;
|
|
1246
|
+
return t.min.x === 1 / 0 || t.max.x === -1 / 0 ? null : new Float32Array([
|
|
1247
|
+
t.min.x,
|
|
1248
|
+
t.min.y,
|
|
1249
|
+
t.min.z,
|
|
1250
|
+
t.max.x,
|
|
1251
|
+
t.max.y,
|
|
1252
|
+
t.max.z
|
|
1046
1253
|
]);
|
|
1047
1254
|
}
|
|
1048
1255
|
/**
|
|
@@ -1050,15 +1257,15 @@ const xt = class xt extends l.Mesh {
|
|
|
1050
1257
|
* @param width Viewport width
|
|
1051
1258
|
* @param height Viewport height
|
|
1052
1259
|
*/
|
|
1053
|
-
updateViewport(
|
|
1054
|
-
|
|
1260
|
+
updateViewport(t, s) {
|
|
1261
|
+
t === this._vpW && s === this._vpH || (this._vpW = t, this._vpH = s, this.material.updateViewport(t, s));
|
|
1055
1262
|
}
|
|
1056
1263
|
/**
|
|
1057
1264
|
* Sorts splats based on camera position and direction.
|
|
1058
1265
|
* @param camera The camera to sort against.
|
|
1059
1266
|
*/
|
|
1060
|
-
sort(
|
|
1061
|
-
|
|
1267
|
+
sort(t) {
|
|
1268
|
+
t.getWorldPosition(this._camPosW), t.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);
|
|
1062
1269
|
const s = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6, n = this.lastCameraDirectionLocal.dot(this._camDirL) < 0.999;
|
|
1063
1270
|
this.options.autoSort && (s || n) && (this.lastCameraPositionLocal.copy(this._camPosL), this.lastCameraDirectionLocal.copy(this._camDirL), this.sorter.setCamera(this._camPosL, this._camDirL));
|
|
1064
1271
|
}
|
|
@@ -1071,8 +1278,13 @@ const xt = class xt extends l.Mesh {
|
|
|
1071
1278
|
*/
|
|
1072
1279
|
// prettier-ignore
|
|
1073
1280
|
// @ts-expect-error scene is not used
|
|
1074
|
-
onBeforeRender(
|
|
1075
|
-
this.sort(n),
|
|
1281
|
+
onBeforeRender(t, s, n) {
|
|
1282
|
+
if (this.sort(n), t.getSize(this._size), this.updateViewport(this._size.x, this._size.y), this.animation) {
|
|
1283
|
+
if (!this.animation.isPlaying && this.animation.shouldAutoPlay()) return this.animation.play();
|
|
1284
|
+
if (!this.animation.isPlaying || this.animation.isComplete) return;
|
|
1285
|
+
const r = performance.now() / 1e3;
|
|
1286
|
+
this.animation.update(r) && this.material.setAnimationProgress(this.animation.progress);
|
|
1287
|
+
}
|
|
1076
1288
|
}
|
|
1077
1289
|
/**
|
|
1078
1290
|
* Dispose of resources
|
|
@@ -1082,33 +1294,33 @@ const xt = class xt extends l.Mesh {
|
|
|
1082
1294
|
}
|
|
1083
1295
|
};
|
|
1084
1296
|
/** Number of splats combined into a single instanced draw call. */
|
|
1085
|
-
|
|
1086
|
-
let
|
|
1087
|
-
const
|
|
1088
|
-
class
|
|
1297
|
+
d(xe, "INSTANCE_SIZE", 128);
|
|
1298
|
+
let Re = xe;
|
|
1299
|
+
const fe = 0.28209479177387814;
|
|
1300
|
+
class ge {
|
|
1089
1301
|
/**
|
|
1090
1302
|
* Packs PLY data (Float32) into the Unified SOGS-like Format.
|
|
1091
1303
|
*/
|
|
1092
1304
|
// prettier-ignore
|
|
1093
|
-
static packPly(
|
|
1094
|
-
const
|
|
1095
|
-
for (let
|
|
1096
|
-
const h =
|
|
1097
|
-
|
|
1098
|
-
let
|
|
1099
|
-
const
|
|
1100
|
-
let
|
|
1101
|
-
|
|
1102
|
-
let W = 0,
|
|
1103
|
-
|
|
1104
|
-
const Z = (
|
|
1105
|
-
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
const
|
|
1109
|
-
y[h + 0] = Math.round(Q * 255), y[h + 1] = Math.round($ * 255), y[h + 2] = Math.round(K * 255), y[h + 3] = Math.round(
|
|
1305
|
+
static packPly(e) {
|
|
1306
|
+
const t = e.numSplats, s = Math.ceil(Math.sqrt(t)), n = Math.ceil(t / s), r = s * n, { ranges: i, colorScale: o } = this.calculatePlyRanges(e), m = new Uint32Array(r * 4), y = new Uint8Array(r * 4), u = new c.Quaternion();
|
|
1307
|
+
for (let l = 0; l < t; l++) {
|
|
1308
|
+
const h = l * 4, f = l * 3, w = l * 4, A = e.positions[f + 0], b = e.positions[f + 1], B = e.positions[f + 2], T = this.clamp01(this.norm(A, i.means.min.x, i.means.max.x)), E = this.clamp01(this.norm(b, i.means.min.y, i.means.max.y)), U = this.clamp01(this.norm(B, i.means.min.z, i.means.max.z)), R = T * 65535 | 0, C = E * 65535 | 0, M = U * 65535 | 0;
|
|
1309
|
+
m[h + 0] = this.pack4Bytes(R & 255, C & 255, M & 255, 0), m[h + 1] = this.pack4Bytes(R >> 8, C >> 8, M >> 8, 0), u.set(e.rotations[w], e.rotations[w + 1], e.rotations[w + 2], e.rotations[w + 3]).normalize();
|
|
1310
|
+
let k = u.w, S = u.x, g = u.y, v = u.z;
|
|
1311
|
+
const O = Math.abs(k), V = Math.abs(S), I = Math.abs(g), q = Math.abs(v);
|
|
1312
|
+
let p = 0, _ = O;
|
|
1313
|
+
V > _ && (_ = V, p = 1), I > _ && (_ = I, p = 2), q > _ && (_ = q, p = 3), (p === 0 ? k : p === 1 ? S : p === 2 ? g : v) < 0 && (k = -k, S = -S, g = -g, v = -v);
|
|
1314
|
+
let W = 0, F = 0, J = 0;
|
|
1315
|
+
p === 0 && (W = S, F = g, J = v), p === 1 && (W = k, F = g, J = v), p === 2 && (W = k, F = S, J = v), p === 3 && (W = k, F = S, J = g);
|
|
1316
|
+
const Z = (te) => Math.min(255, Math.max(0, Math.round((0.5 + te / Math.SQRT2) * 255)));
|
|
1317
|
+
m[h + 2] = this.pack4Bytes(Z(W), Z(F), Z(J), p);
|
|
1318
|
+
const Y = this.norm(e.scales[f + 0], i.scales.min.x, i.scales.max.x), z = this.norm(e.scales[f + 1], i.scales.min.y, i.scales.max.y), x = this.norm(e.scales[f + 2], i.scales.min.z, i.scales.max.z);
|
|
1319
|
+
m[h + 3] = this.pack4Bytes(Math.floor(Y * 255), Math.floor(z * 255), Math.floor(x * 255), 0);
|
|
1320
|
+
const D = this.clamp01(e.colors[f + 0] * o), L = this.clamp01(e.colors[f + 1] * o), P = this.clamp01(e.colors[f + 2] * o), G = (D - 0.5) / fe, X = (L - 0.5) / fe, j = (P - 0.5) / fe, Q = this.clamp01(this.norm(G, i.sh0.min.x, i.sh0.max.x)), $ = this.clamp01(this.norm(X, i.sh0.min.y, i.sh0.max.y)), K = this.clamp01(this.norm(j, i.sh0.min.z, i.sh0.max.z)), ee = this.clamp01(e.opacities[l]);
|
|
1321
|
+
y[h + 0] = Math.round(Q * 255), y[h + 1] = Math.round($ * 255), y[h + 2] = Math.round(K * 255), y[h + 3] = Math.round(ee * 255);
|
|
1110
1322
|
}
|
|
1111
|
-
return new
|
|
1323
|
+
return new Ae(t, s, n, e.positions, m, y, i, e.boundingBox);
|
|
1112
1324
|
}
|
|
1113
1325
|
/**
|
|
1114
1326
|
* Packs SOGS data.
|
|
@@ -1116,176 +1328,176 @@ class gt {
|
|
|
1116
1328
|
* Decodes centers for sorting.
|
|
1117
1329
|
*/
|
|
1118
1330
|
// prettier-ignore
|
|
1119
|
-
static packSogs(
|
|
1120
|
-
var g, v,
|
|
1121
|
-
const
|
|
1122
|
-
let s = Math.ceil(Math.sqrt(
|
|
1123
|
-
const r = ((g =
|
|
1331
|
+
static packSogs(e) {
|
|
1332
|
+
var g, v, O;
|
|
1333
|
+
const t = e.numSplats;
|
|
1334
|
+
let s = Math.ceil(Math.sqrt(t)), n = Math.ceil(t / s);
|
|
1335
|
+
const r = ((g = e.means_l) == null ? void 0 : g.image) ?? ((v = e.sh0) == null ? void 0 : v.image) ?? ((O = e.quats) == null ? void 0 : O.image);
|
|
1124
1336
|
r && typeof r.width == "number" && typeof r.height == "number" && (s = r.width, n = r.height);
|
|
1125
|
-
const
|
|
1126
|
-
if (
|
|
1127
|
-
const
|
|
1128
|
-
w(
|
|
1337
|
+
const i = s * n;
|
|
1338
|
+
if (i < t) throw new Error(`SOG v1 texture too small: ${s}x${n}=${i} < count=${t}`);
|
|
1339
|
+
const o = this.convertSogsRanges(e.ranges), m = e.ranges.means.mins[0], y = e.ranges.means.mins[1], u = e.ranges.means.mins[2], l = e.ranges.means.maxs[0], h = e.ranges.means.maxs[1], f = e.ranges.means.maxs[2], w = (V) => Math.sign(V) * (Math.exp(Math.abs(V)) - 1), A = new c.Vector3(
|
|
1340
|
+
w(m),
|
|
1129
1341
|
w(y),
|
|
1130
|
-
w(
|
|
1131
|
-
), b = new
|
|
1132
|
-
w(
|
|
1342
|
+
w(u)
|
|
1343
|
+
), b = new c.Vector3(
|
|
1344
|
+
w(l),
|
|
1133
1345
|
w(h),
|
|
1134
|
-
w(
|
|
1346
|
+
w(f)
|
|
1135
1347
|
);
|
|
1136
|
-
|
|
1137
|
-
const
|
|
1138
|
-
for (let
|
|
1139
|
-
const I =
|
|
1140
|
-
S[
|
|
1141
|
-
const L = this.clamp01(this.norm(
|
|
1142
|
-
M[I + 0] = this.pack4Bytes(L & 255,
|
|
1143
|
-
const j =
|
|
1144
|
-
M[I + 2] = this.pack4Bytes(
|
|
1145
|
-
const Q =
|
|
1146
|
-
|
|
1348
|
+
o.means.min.copy(A), o.means.max.copy(b);
|
|
1349
|
+
const B = e, T = this.getPixels(B.means_l), E = this.getPixels(B.means_u), U = this.getPixels(B.quats), R = this.getPixels(B.scales), C = this.getPixels(B.sh0), M = new Uint32Array(i * 4), k = new Uint8Array(i * 4), S = new Float32Array(t * 3);
|
|
1350
|
+
for (let V = 0; V < t; V++) {
|
|
1351
|
+
const I = V * 4, q = E[I + 0], p = T[I + 0], _ = E[I + 1], H = T[I + 1], W = E[I + 2], F = T[I + 2], J = (q << 8 | p) / 65535, Z = (_ << 8 | H) / 65535, Y = (W << 8 | F) / 65535, z = this.sogsDecode(J, m, l), x = this.sogsDecode(Z, y, h), D = this.sogsDecode(Y, u, f);
|
|
1352
|
+
S[V * 3 + 0] = z, S[V * 3 + 1] = x, S[V * 3 + 2] = D;
|
|
1353
|
+
const L = this.clamp01(this.norm(z, A.x, b.x)) * 65535 | 0, P = this.clamp01(this.norm(x, A.y, b.y)) * 65535 | 0, G = this.clamp01(this.norm(D, A.z, b.z)) * 65535 | 0;
|
|
1354
|
+
M[I + 0] = this.pack4Bytes(L & 255, P & 255, G & 255, 0), M[I + 1] = this.pack4Bytes(L >> 8, P >> 8, G >> 8, 0), M[I + 3] = this.pack4Bytes(R[I], R[I + 1], R[I + 2], 0);
|
|
1355
|
+
const j = U[I + 3] - 252;
|
|
1356
|
+
M[I + 2] = this.pack4Bytes(U[I + 0], U[I + 1], U[I + 2], j), k[I + 0] = C[I], k[I + 1] = C[I + 1], k[I + 2] = C[I + 2];
|
|
1357
|
+
const Q = C[I + 3] / 255, $ = e.ranges.sh0.mins[3] + (e.ranges.sh0.maxs[3] - e.ranges.sh0.mins[3]) * Q, K = 1 / (1 + Math.exp(-$));
|
|
1358
|
+
k[I + 3] = Math.round(Math.max(0, Math.min(1, K)) * 255);
|
|
1147
1359
|
}
|
|
1148
|
-
return new
|
|
1360
|
+
return new Ae(t, s, n, S, M, k, o, e.boundingBox);
|
|
1149
1361
|
}
|
|
1150
1362
|
/**
|
|
1151
1363
|
* Packs SOG V2 data.
|
|
1152
1364
|
*/
|
|
1153
|
-
static packSog2(
|
|
1154
|
-
var
|
|
1155
|
-
const
|
|
1156
|
-
let s = Math.ceil(Math.sqrt(
|
|
1157
|
-
const r = ((
|
|
1365
|
+
static packSog2(e) {
|
|
1366
|
+
var O, V, I;
|
|
1367
|
+
const t = e.numSplats;
|
|
1368
|
+
let s = Math.ceil(Math.sqrt(t)), n = Math.ceil(t / s);
|
|
1369
|
+
const r = ((O = e.means_l) == null ? void 0 : O.image) ?? ((V = e.sh0) == null ? void 0 : V.image) ?? ((I = e.quats) == null ? void 0 : I.image);
|
|
1158
1370
|
r && typeof r.width == "number" && typeof r.height == "number" && (s = r.width, n = r.height);
|
|
1159
|
-
const
|
|
1160
|
-
if (
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
), A = new
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
), b = (
|
|
1170
|
-
let
|
|
1171
|
-
for (const
|
|
1172
|
-
Number.isFinite(
|
|
1173
|
-
(!Number.isFinite(
|
|
1174
|
-
const
|
|
1175
|
-
for (let
|
|
1176
|
-
const Z = ((
|
|
1177
|
-
W[
|
|
1371
|
+
const i = s * n;
|
|
1372
|
+
if (i < t) throw new Error(`SOG v2 texture too small: ${s}x${n}=${i} < count=${t}`);
|
|
1373
|
+
const o = e.ranges.means.mins[0], m = e.ranges.means.mins[1], y = e.ranges.means.mins[2], u = e.ranges.means.maxs[0], l = e.ranges.means.maxs[1], h = e.ranges.means.maxs[2], f = (q) => Math.sign(q) * (Math.exp(Math.abs(q)) - 1), w = new c.Vector3(
|
|
1374
|
+
f(o),
|
|
1375
|
+
f(m),
|
|
1376
|
+
f(y)
|
|
1377
|
+
), A = new c.Vector3(
|
|
1378
|
+
f(u),
|
|
1379
|
+
f(l),
|
|
1380
|
+
f(h)
|
|
1381
|
+
), b = (q) => {
|
|
1382
|
+
let p = 1 / 0, _ = -1 / 0;
|
|
1383
|
+
for (const F of q)
|
|
1384
|
+
Number.isFinite(F) && (p = Math.min(p, F), _ = Math.max(_, F));
|
|
1385
|
+
(!Number.isFinite(p) || !Number.isFinite(_)) && (p = 0, _ = 1);
|
|
1386
|
+
const H = _ - p || 1, W = new Uint8Array(256);
|
|
1387
|
+
for (let F = 0; F < 256; F++) {
|
|
1388
|
+
const Z = ((F < q.length && Number.isFinite(q[F]) ? q[F] : p + (_ - p) * (F / 255)) - p) / H, Y = Math.max(0, Math.min(255, Math.round(Z * 255)));
|
|
1389
|
+
W[F] = Y;
|
|
1178
1390
|
}
|
|
1179
|
-
return { cbMin:
|
|
1180
|
-
},
|
|
1391
|
+
return { cbMin: p, cbMax: _, lut: W };
|
|
1392
|
+
}, B = b(e.ranges.scales.codebook), T = b(e.ranges.sh0.codebook), E = {
|
|
1181
1393
|
means: { min: w.clone(), max: A.clone() },
|
|
1182
1394
|
scales: {
|
|
1183
|
-
min: new
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1395
|
+
min: new c.Vector3(
|
|
1396
|
+
B.cbMin,
|
|
1397
|
+
B.cbMin,
|
|
1398
|
+
B.cbMin
|
|
1187
1399
|
),
|
|
1188
|
-
max: new
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1400
|
+
max: new c.Vector3(
|
|
1401
|
+
B.cbMax,
|
|
1402
|
+
B.cbMax,
|
|
1403
|
+
B.cbMax
|
|
1192
1404
|
)
|
|
1193
1405
|
},
|
|
1194
1406
|
sh0: {
|
|
1195
|
-
min: new
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1407
|
+
min: new c.Vector3(
|
|
1408
|
+
T.cbMin,
|
|
1409
|
+
T.cbMin,
|
|
1410
|
+
T.cbMin
|
|
1199
1411
|
),
|
|
1200
|
-
max: new
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1412
|
+
max: new c.Vector3(
|
|
1413
|
+
T.cbMax,
|
|
1414
|
+
T.cbMax,
|
|
1415
|
+
T.cbMax
|
|
1204
1416
|
)
|
|
1205
1417
|
}
|
|
1206
|
-
},
|
|
1207
|
-
for (let
|
|
1208
|
-
const
|
|
1209
|
-
v[
|
|
1210
|
-
const G = this.clamp01(this.norm(
|
|
1211
|
-
S[
|
|
1212
|
-
const $ =
|
|
1213
|
-
S[
|
|
1214
|
-
const K =
|
|
1215
|
-
S[
|
|
1418
|
+
}, U = this.getPixels(e.means_l), R = this.getPixels(e.means_u), C = this.getPixels(e.quats), M = this.getPixels(e.scales), k = this.getPixels(e.sh0), S = new Uint32Array(i * 4), g = new Uint8Array(i * 4), v = new Float32Array(t * 3);
|
|
1419
|
+
for (let q = 0; q < t; q++) {
|
|
1420
|
+
const p = q * 4, _ = R[p + 0], H = U[p + 0], W = R[p + 1], F = U[p + 1], J = R[p + 2], Z = U[p + 2], Y = (_ << 8 | H) / 65535, z = (W << 8 | F) / 65535, x = (J << 8 | Z) / 65535, D = this.sogsDecode(Y, o, u), L = this.sogsDecode(z, m, l), P = this.sogsDecode(x, y, h);
|
|
1421
|
+
v[q * 3 + 0] = D, v[q * 3 + 1] = L, v[q * 3 + 2] = P;
|
|
1422
|
+
const G = this.clamp01(this.norm(D, w.x, A.x)) * 65535 | 0, X = this.clamp01(this.norm(L, w.y, A.y)) * 65535 | 0, j = this.clamp01(this.norm(P, w.z, A.z)) * 65535 | 0;
|
|
1423
|
+
S[p + 0] = this.pack4Bytes(G & 255, X & 255, j & 255, 0), S[p + 1] = this.pack4Bytes(G >> 8, X >> 8, j >> 8, 0);
|
|
1424
|
+
const $ = C[p + 3] - 252 & 3;
|
|
1425
|
+
S[p + 2] = this.pack4Bytes(C[p + 0], C[p + 1], C[p + 2], $);
|
|
1426
|
+
const K = B.lut[M[p + 0]], ee = B.lut[M[p + 1]], te = B.lut[M[p + 2]];
|
|
1427
|
+
S[p + 3] = this.pack4Bytes(K, ee, te, 0), g[p + 0] = T.lut[k[p + 0]], g[p + 1] = T.lut[k[p + 1]], g[p + 2] = T.lut[k[p + 2]], g[p + 3] = k[p + 3];
|
|
1216
1428
|
}
|
|
1217
|
-
return new
|
|
1429
|
+
return new Ae(t, s, n, v, S, g, E, e.boundingBox);
|
|
1218
1430
|
}
|
|
1219
1431
|
// --- Helpers ---
|
|
1220
1432
|
// prettier-ignore
|
|
1221
|
-
static pack4Bytes(
|
|
1222
|
-
return (
|
|
1433
|
+
static pack4Bytes(e, t, s, n) {
|
|
1434
|
+
return (e & 255) << 24 | (t & 255) << 16 | (s & 255) << 8 | n & 255;
|
|
1223
1435
|
}
|
|
1224
1436
|
// prettier-ignore
|
|
1225
|
-
static getPixels(
|
|
1226
|
-
const
|
|
1227
|
-
if (
|
|
1437
|
+
static getPixels(e) {
|
|
1438
|
+
const t = e.image, s = t.width, n = t.height;
|
|
1439
|
+
if (t.data && (t.data instanceof Uint8Array || t.data instanceof Uint8ClampedArray)) return new Uint8Array(t.data);
|
|
1228
1440
|
const r = document.createElement("canvas");
|
|
1229
1441
|
r.width = s, r.height = n;
|
|
1230
|
-
const
|
|
1231
|
-
if (!
|
|
1232
|
-
return
|
|
1442
|
+
const i = r.getContext("2d", { willReadFrequently: !0 });
|
|
1443
|
+
if (!i) throw new Error("Canvas init failed");
|
|
1444
|
+
return i.drawImage(t, 0, 0), new Uint8Array(i.getImageData(0, 0, s, n).data);
|
|
1233
1445
|
}
|
|
1234
|
-
static convertSogsRanges(
|
|
1235
|
-
const
|
|
1446
|
+
static convertSogsRanges(e) {
|
|
1447
|
+
const t = (s) => new c.Vector3(s[0], s[1], s[2]);
|
|
1236
1448
|
return {
|
|
1237
|
-
sh0: { min: e
|
|
1238
|
-
means: { min: e
|
|
1239
|
-
scales: { min: e
|
|
1449
|
+
sh0: { min: t(e.sh0.mins), max: t(e.sh0.maxs) },
|
|
1450
|
+
means: { min: t(e.means.mins), max: t(e.means.maxs) },
|
|
1451
|
+
scales: { min: t(e.scales.mins), max: t(e.scales.maxs) }
|
|
1240
1452
|
};
|
|
1241
1453
|
}
|
|
1242
|
-
static calculatePlyRanges(
|
|
1243
|
-
const
|
|
1244
|
-
let
|
|
1245
|
-
for (let
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1454
|
+
static calculatePlyRanges(e) {
|
|
1455
|
+
const t = new c.Vector3(1 / 0, 1 / 0, 1 / 0), s = new c.Vector3(-1 / 0, -1 / 0, -1 / 0), n = new c.Vector3(1 / 0, 1 / 0, 1 / 0), r = new c.Vector3(-1 / 0, -1 / 0, -1 / 0), i = new c.Vector3(1 / 0, 1 / 0, 1 / 0), o = new c.Vector3(-1 / 0, -1 / 0, -1 / 0);
|
|
1456
|
+
let m = 0;
|
|
1457
|
+
for (let u = 0; u < e.numSplats; u++) {
|
|
1458
|
+
const l = u * 3, h = e.positions[l + 0], f = e.positions[l + 1], w = e.positions[l + 2];
|
|
1459
|
+
t.x = Math.min(t.x, h), s.x = Math.max(s.x, h), t.y = Math.min(t.y, f), s.y = Math.max(s.y, f), t.z = Math.min(t.z, w), s.z = Math.max(s.z, w), n.x = Math.min(n.x, e.scales[l]), r.x = Math.max(r.x, e.scales[l]), n.y = Math.min(n.y, e.scales[l + 1]), r.y = Math.max(r.y, e.scales[l + 1]), n.z = Math.min(n.z, e.scales[l + 2]), r.z = Math.max(r.z, e.scales[l + 2]), m = Math.max(
|
|
1460
|
+
m,
|
|
1461
|
+
e.colors[l],
|
|
1462
|
+
e.colors[l + 1],
|
|
1463
|
+
e.colors[l + 2]
|
|
1252
1464
|
);
|
|
1253
1465
|
}
|
|
1254
|
-
const y =
|
|
1255
|
-
for (let
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1466
|
+
const y = m > 1.5 ? 1 / 255 : 1;
|
|
1467
|
+
for (let u = 0; u < e.numSplats; u++) {
|
|
1468
|
+
const l = u * 3, h = this.clamp01(e.colors[l + 0] * y), f = this.clamp01(e.colors[l + 1] * y), w = this.clamp01(e.colors[l + 2] * y), A = (h - 0.5) / fe, b = (f - 0.5) / fe, B = (w - 0.5) / fe;
|
|
1469
|
+
i.x = Math.min(i.x, A), o.x = Math.max(o.x, A), i.y = Math.min(i.y, b), o.y = Math.max(o.y, b), i.z = Math.min(i.z, B), o.z = Math.max(o.z, B);
|
|
1258
1470
|
}
|
|
1259
1471
|
return {
|
|
1260
1472
|
colorScale: y,
|
|
1261
1473
|
ranges: {
|
|
1262
|
-
sh0: { min:
|
|
1263
|
-
means: { min:
|
|
1474
|
+
sh0: { min: i, max: o },
|
|
1475
|
+
means: { min: t, max: s },
|
|
1264
1476
|
scales: { min: n, max: r }
|
|
1265
1477
|
}
|
|
1266
1478
|
};
|
|
1267
1479
|
}
|
|
1268
|
-
static clamp01(
|
|
1269
|
-
return Math.max(0, Math.min(1,
|
|
1480
|
+
static clamp01(e) {
|
|
1481
|
+
return Math.max(0, Math.min(1, e));
|
|
1270
1482
|
}
|
|
1271
1483
|
// prettier-ignore
|
|
1272
1484
|
// private static lerp(a: number, b: number, t: number) { return a + (b - a) * t; } // prettier-ignore
|
|
1273
1485
|
// private static invSogsMap(v: number) { return Math.sign(v) * Math.log(Math.abs(v) + 1) } // prettier-ignore
|
|
1274
|
-
static norm(
|
|
1275
|
-
return (
|
|
1486
|
+
static norm(e, t, s) {
|
|
1487
|
+
return (e - t) / (s - t || 1);
|
|
1276
1488
|
}
|
|
1277
1489
|
// prettier-ignore
|
|
1278
|
-
static sogsDecode(
|
|
1279
|
-
const n =
|
|
1490
|
+
static sogsDecode(e, t, s) {
|
|
1491
|
+
const n = t + (s - t) * e;
|
|
1280
1492
|
return Math.sign(n) * (Math.exp(Math.abs(n)) - 1);
|
|
1281
1493
|
}
|
|
1282
1494
|
}
|
|
1283
|
-
class
|
|
1284
|
-
constructor(
|
|
1285
|
-
super(
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1495
|
+
class kt extends c.Loader {
|
|
1496
|
+
constructor(t, s) {
|
|
1497
|
+
super(t);
|
|
1498
|
+
d(this, "requestId", 0);
|
|
1499
|
+
d(this, "worker");
|
|
1500
|
+
d(this, "pendingCallbacks", /* @__PURE__ */ new Map());
|
|
1289
1501
|
this.withCredentials = (s == null ? void 0 : s.withCredentials) ?? !1;
|
|
1290
1502
|
const n = this.createWorkerCode(), r = new Blob([n], { type: "application/javascript" });
|
|
1291
1503
|
this.worker = new Worker(URL.createObjectURL(r)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
@@ -1294,26 +1506,26 @@ class ve extends l.Loader {
|
|
|
1294
1506
|
* Handles messages received from the parsing worker
|
|
1295
1507
|
* @param event The message event from the worker
|
|
1296
1508
|
*/
|
|
1297
|
-
onWorkerMessage(
|
|
1298
|
-
const { requestId: s, error: n, result: r } =
|
|
1299
|
-
if (!
|
|
1300
|
-
if (this.pendingCallbacks.delete(s), n) return
|
|
1301
|
-
if (!r) return
|
|
1509
|
+
onWorkerMessage(t) {
|
|
1510
|
+
const { requestId: s, error: n, result: r } = t.data, i = this.pendingCallbacks.get(s);
|
|
1511
|
+
if (!i) return console.warn(`PlyLoader: Received response for unknown request ${s}`);
|
|
1512
|
+
if (this.pendingCallbacks.delete(s), n) return i.reject(new Error(n));
|
|
1513
|
+
if (!r) return i.reject(new Error("Worker returned no result"));
|
|
1302
1514
|
try {
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1515
|
+
const o = new Xe(0);
|
|
1516
|
+
o.numSplats = r.numSplats, o.positions = new Float32Array(r.positions), o.rotations = new Float32Array(r.rotations), o.scales = new Float32Array(r.scales), o.colors = new Float32Array(r.colors), o.opacities = new Float32Array(r.opacities), o.boundingBox.min.set(
|
|
1305
1517
|
r.boundingBox.minX,
|
|
1306
1518
|
r.boundingBox.minY,
|
|
1307
1519
|
r.boundingBox.minZ
|
|
1308
|
-
),
|
|
1520
|
+
), o.boundingBox.max.set(
|
|
1309
1521
|
r.boundingBox.maxX,
|
|
1310
1522
|
r.boundingBox.maxY,
|
|
1311
1523
|
r.boundingBox.maxZ
|
|
1312
1524
|
), this.worker.terminate();
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
} catch (
|
|
1316
|
-
|
|
1525
|
+
const m = ge.packPly(o);
|
|
1526
|
+
o.dispose(), i.resolve(m);
|
|
1527
|
+
} catch (o) {
|
|
1528
|
+
i.reject(o);
|
|
1317
1529
|
}
|
|
1318
1530
|
}
|
|
1319
1531
|
/**
|
|
@@ -1323,15 +1535,15 @@ class ve extends l.Loader {
|
|
|
1323
1535
|
* @param onProgress Optional progress callback
|
|
1324
1536
|
* @param onError Optional error callback
|
|
1325
1537
|
*/
|
|
1326
|
-
load(
|
|
1327
|
-
const
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
(
|
|
1331
|
-
this.parseAsync(
|
|
1332
|
-
s && s(
|
|
1333
|
-
}).catch((
|
|
1334
|
-
r ? r(
|
|
1538
|
+
load(t, s, n, r) {
|
|
1539
|
+
const i = new c.FileLoader(this.manager);
|
|
1540
|
+
i.setResponseType("arraybuffer"), i.setRequestHeader(this.requestHeader), i.setPath(this.path), i.setWithCredentials(this.withCredentials), i.load(
|
|
1541
|
+
t,
|
|
1542
|
+
(o) => {
|
|
1543
|
+
this.parseAsync(o).then((m) => {
|
|
1544
|
+
s && s(m);
|
|
1545
|
+
}).catch((m) => {
|
|
1546
|
+
r ? r(m) : console.error(m), this.manager.itemError(t);
|
|
1335
1547
|
});
|
|
1336
1548
|
},
|
|
1337
1549
|
n,
|
|
@@ -1344,19 +1556,19 @@ class ve extends l.Loader {
|
|
|
1344
1556
|
* @param onProgress Optional progress callback
|
|
1345
1557
|
* @returns A Promise that resolves with the parsed SplatData
|
|
1346
1558
|
*/
|
|
1347
|
-
loadAsync(
|
|
1559
|
+
loadAsync(t, s) {
|
|
1348
1560
|
return new Promise((n, r) => {
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
(
|
|
1353
|
-
this.parseAsync(
|
|
1354
|
-
r(
|
|
1561
|
+
const i = new c.FileLoader(this.manager);
|
|
1562
|
+
i.setResponseType("arraybuffer"), i.setRequestHeader(this.requestHeader), i.setPath(this.path), i.setWithCredentials(this.withCredentials), i.load(
|
|
1563
|
+
t,
|
|
1564
|
+
(o) => {
|
|
1565
|
+
this.parseAsync(o).then(n).catch((m) => {
|
|
1566
|
+
r(m), this.manager.itemError(t);
|
|
1355
1567
|
});
|
|
1356
1568
|
},
|
|
1357
1569
|
s,
|
|
1358
|
-
(
|
|
1359
|
-
r(
|
|
1570
|
+
(o) => {
|
|
1571
|
+
r(o), this.manager.itemError(t);
|
|
1360
1572
|
}
|
|
1361
1573
|
);
|
|
1362
1574
|
});
|
|
@@ -1366,15 +1578,15 @@ class ve extends l.Loader {
|
|
|
1366
1578
|
* @param buffer ArrayBuffer containing PLY data
|
|
1367
1579
|
* @returns Promise that resolves with parsed SplatData
|
|
1368
1580
|
*/
|
|
1369
|
-
parseAsync(
|
|
1581
|
+
parseAsync(t) {
|
|
1370
1582
|
return new Promise((s, n) => {
|
|
1371
1583
|
const r = this.requestId++;
|
|
1372
1584
|
this.pendingCallbacks.set(r, { resolve: s, reject: n });
|
|
1373
|
-
const
|
|
1585
|
+
const i = {
|
|
1374
1586
|
requestId: r,
|
|
1375
|
-
buffer:
|
|
1587
|
+
buffer: t
|
|
1376
1588
|
};
|
|
1377
|
-
this.worker.postMessage(
|
|
1589
|
+
this.worker.postMessage(i, [t]);
|
|
1378
1590
|
});
|
|
1379
1591
|
}
|
|
1380
1592
|
/**
|
|
@@ -1390,46 +1602,46 @@ class ve extends l.Loader {
|
|
|
1390
1602
|
createWorkerCode() {
|
|
1391
1603
|
return `(${(function() {
|
|
1392
1604
|
self.onmessage = (n) => {
|
|
1393
|
-
const { requestId: r, buffer:
|
|
1605
|
+
const { requestId: r, buffer: i } = n.data;
|
|
1394
1606
|
try {
|
|
1395
|
-
const
|
|
1607
|
+
const o = s(i), m = {
|
|
1396
1608
|
requestId: r,
|
|
1397
|
-
result:
|
|
1609
|
+
result: o
|
|
1398
1610
|
};
|
|
1399
|
-
self.postMessage(
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1611
|
+
self.postMessage(m, [
|
|
1612
|
+
o.positions,
|
|
1613
|
+
o.rotations,
|
|
1614
|
+
o.scales,
|
|
1615
|
+
o.colors,
|
|
1616
|
+
o.opacities
|
|
1405
1617
|
]);
|
|
1406
|
-
} catch (
|
|
1407
|
-
const
|
|
1618
|
+
} catch (o) {
|
|
1619
|
+
const m = {
|
|
1408
1620
|
requestId: r,
|
|
1409
|
-
error:
|
|
1621
|
+
error: o instanceof Error ? o.message : String(o)
|
|
1410
1622
|
};
|
|
1411
|
-
self.postMessage(
|
|
1623
|
+
self.postMessage(m);
|
|
1412
1624
|
}
|
|
1413
1625
|
};
|
|
1414
1626
|
function s(n) {
|
|
1415
|
-
const r = new TextDecoder(),
|
|
1627
|
+
const r = new TextDecoder(), i = new Uint8Array(n), o = [112, 108, 121, 10], m = `
|
|
1416
1628
|
end_header
|
|
1417
1629
|
`;
|
|
1418
|
-
for (let
|
|
1419
|
-
if (
|
|
1630
|
+
for (let z = 0; z < o.length; z++)
|
|
1631
|
+
if (i[z] !== o[z])
|
|
1420
1632
|
throw new Error(
|
|
1421
1633
|
"Invalid PLY file: Missing magic bytes"
|
|
1422
1634
|
);
|
|
1423
1635
|
let y = 0;
|
|
1424
|
-
for (let
|
|
1425
|
-
let
|
|
1426
|
-
for (let
|
|
1427
|
-
if (
|
|
1428
|
-
|
|
1636
|
+
for (let z = 0; z < i.length - m.length; z++) {
|
|
1637
|
+
let x = !0;
|
|
1638
|
+
for (let D = 0; D < m.length; D++)
|
|
1639
|
+
if (i[z + D] !== m.charCodeAt(D)) {
|
|
1640
|
+
x = !1;
|
|
1429
1641
|
break;
|
|
1430
1642
|
}
|
|
1431
|
-
if (
|
|
1432
|
-
y =
|
|
1643
|
+
if (x) {
|
|
1644
|
+
y = z + m.length;
|
|
1433
1645
|
break;
|
|
1434
1646
|
}
|
|
1435
1647
|
}
|
|
@@ -1437,23 +1649,23 @@ end_header
|
|
|
1437
1649
|
throw new Error(
|
|
1438
1650
|
"Invalid PLY file: Could not find end of header"
|
|
1439
1651
|
);
|
|
1440
|
-
const
|
|
1441
|
-
|
|
1652
|
+
const l = r.decode(
|
|
1653
|
+
i.subarray(0, y)
|
|
1442
1654
|
).split(`
|
|
1443
1655
|
`), h = [];
|
|
1444
|
-
let
|
|
1445
|
-
for (let
|
|
1446
|
-
const
|
|
1447
|
-
if (
|
|
1448
|
-
const
|
|
1449
|
-
switch (
|
|
1656
|
+
let f = null;
|
|
1657
|
+
for (let z = 1; z < l.length; z++) {
|
|
1658
|
+
const x = l[z].trim();
|
|
1659
|
+
if (x === "" || x === "end_header") continue;
|
|
1660
|
+
const D = x.split(" ");
|
|
1661
|
+
switch (D[0]) {
|
|
1450
1662
|
case "format":
|
|
1451
|
-
|
|
1663
|
+
f = D[1];
|
|
1452
1664
|
break;
|
|
1453
1665
|
case "element":
|
|
1454
1666
|
h.push({
|
|
1455
|
-
name:
|
|
1456
|
-
count: parseInt(
|
|
1667
|
+
name: D[1],
|
|
1668
|
+
count: parseInt(D[2], 10),
|
|
1457
1669
|
properties: []
|
|
1458
1670
|
});
|
|
1459
1671
|
break;
|
|
@@ -1463,129 +1675,129 @@ end_header
|
|
|
1463
1675
|
"Invalid PLY file: Property without element"
|
|
1464
1676
|
);
|
|
1465
1677
|
h[h.length - 1].properties.push({
|
|
1466
|
-
type:
|
|
1467
|
-
name:
|
|
1678
|
+
type: D[1],
|
|
1679
|
+
name: D[2]
|
|
1468
1680
|
});
|
|
1469
1681
|
break;
|
|
1470
1682
|
}
|
|
1471
1683
|
}
|
|
1472
|
-
if (
|
|
1473
|
-
throw new Error(`Unsupported PLY format: ${
|
|
1474
|
-
const w = h.find((
|
|
1684
|
+
if (f !== "binary_little_endian")
|
|
1685
|
+
throw new Error(`Unsupported PLY format: ${f}`);
|
|
1686
|
+
const w = h.find((z) => z.name === "vertex");
|
|
1475
1687
|
if (!w)
|
|
1476
1688
|
throw new Error(
|
|
1477
1689
|
"Invalid PLY file: No vertex element found"
|
|
1478
1690
|
);
|
|
1479
|
-
const A = w.count, b = new Float32Array(A * 3),
|
|
1480
|
-
let
|
|
1481
|
-
const M = (
|
|
1482
|
-
(
|
|
1483
|
-
),
|
|
1691
|
+
const A = w.count, b = new Float32Array(A * 3), B = new Float32Array(A * 4), T = new Float32Array(A * 3), E = new Float32Array(A * 3), U = new Float32Array(A), R = new DataView(n);
|
|
1692
|
+
let C = y;
|
|
1693
|
+
const M = (z) => w.properties.findIndex(
|
|
1694
|
+
(x) => x.name === z
|
|
1695
|
+
), k = M("x"), S = M("y"), g = M("z"), v = [
|
|
1484
1696
|
M("rot_0"),
|
|
1485
1697
|
M("rot_1"),
|
|
1486
1698
|
M("rot_2"),
|
|
1487
1699
|
M("rot_3")
|
|
1488
|
-
],
|
|
1700
|
+
], O = [
|
|
1489
1701
|
M("scale_0"),
|
|
1490
1702
|
M("scale_1"),
|
|
1491
1703
|
M("scale_2")
|
|
1492
|
-
],
|
|
1704
|
+
], V = [
|
|
1493
1705
|
M("f_dc_0"),
|
|
1494
1706
|
M("f_dc_1"),
|
|
1495
1707
|
M("f_dc_2")
|
|
1496
1708
|
], I = M("opacity");
|
|
1497
1709
|
if ([
|
|
1498
|
-
|
|
1710
|
+
k,
|
|
1499
1711
|
S,
|
|
1500
1712
|
g,
|
|
1501
1713
|
...v,
|
|
1502
|
-
...
|
|
1503
|
-
...
|
|
1714
|
+
...O,
|
|
1715
|
+
...V,
|
|
1504
1716
|
I
|
|
1505
|
-
].some((
|
|
1717
|
+
].some((z) => z === -1))
|
|
1506
1718
|
throw new Error(
|
|
1507
1719
|
"Invalid PLY file: Missing required properties"
|
|
1508
1720
|
);
|
|
1509
|
-
const
|
|
1510
|
-
if (
|
|
1511
|
-
const
|
|
1512
|
-
return
|
|
1721
|
+
const p = 0.28209479177387814, _ = (z) => {
|
|
1722
|
+
if (z > 0) return 1 / (1 + Math.exp(-z));
|
|
1723
|
+
const x = Math.exp(z);
|
|
1724
|
+
return x / (1 + x);
|
|
1513
1725
|
};
|
|
1514
|
-
let
|
|
1515
|
-
for (let
|
|
1516
|
-
const
|
|
1517
|
-
for (let
|
|
1518
|
-
const
|
|
1519
|
-
let
|
|
1520
|
-
switch (
|
|
1726
|
+
let H = 1 / 0, W = 1 / 0, F = 1 / 0, J = -1 / 0, Z = -1 / 0, Y = -1 / 0;
|
|
1727
|
+
for (let z = 0; z < A; z++) {
|
|
1728
|
+
const x = [];
|
|
1729
|
+
for (let Se = 0; Se < w.properties.length; Se++) {
|
|
1730
|
+
const Pe = w.properties[Se].type;
|
|
1731
|
+
let ce;
|
|
1732
|
+
switch (Pe) {
|
|
1521
1733
|
case "char":
|
|
1522
|
-
|
|
1734
|
+
ce = R.getInt8(C), C += 1;
|
|
1523
1735
|
break;
|
|
1524
1736
|
case "uchar":
|
|
1525
|
-
|
|
1737
|
+
ce = R.getUint8(C), C += 1;
|
|
1526
1738
|
break;
|
|
1527
1739
|
case "short":
|
|
1528
|
-
|
|
1740
|
+
ce = R.getInt16(C, !0), C += 2;
|
|
1529
1741
|
break;
|
|
1530
1742
|
case "ushort":
|
|
1531
|
-
|
|
1743
|
+
ce = R.getUint16(C, !0), C += 2;
|
|
1532
1744
|
break;
|
|
1533
1745
|
case "int":
|
|
1534
|
-
|
|
1746
|
+
ce = R.getInt32(C, !0), C += 4;
|
|
1535
1747
|
break;
|
|
1536
1748
|
case "uint":
|
|
1537
|
-
|
|
1749
|
+
ce = R.getUint32(C, !0), C += 4;
|
|
1538
1750
|
break;
|
|
1539
1751
|
case "float":
|
|
1540
|
-
|
|
1752
|
+
ce = R.getFloat32(C, !0), C += 4;
|
|
1541
1753
|
break;
|
|
1542
1754
|
case "double":
|
|
1543
|
-
|
|
1755
|
+
ce = R.getFloat64(C, !0), C += 8;
|
|
1544
1756
|
break;
|
|
1545
1757
|
default:
|
|
1546
1758
|
throw new Error(
|
|
1547
|
-
`Unsupported property type: ${
|
|
1759
|
+
`Unsupported property type: ${Pe}`
|
|
1548
1760
|
);
|
|
1549
1761
|
}
|
|
1550
|
-
|
|
1762
|
+
x.push(ce);
|
|
1551
1763
|
}
|
|
1552
|
-
const
|
|
1553
|
-
b[G] =
|
|
1554
|
-
let X =
|
|
1764
|
+
const D = x[k], L = x[S], P = x[g], G = z * 3;
|
|
1765
|
+
b[G] = D, b[G + 1] = L, b[G + 2] = P, H = Math.min(H, D), W = Math.min(W, L), F = Math.min(F, P), J = Math.max(J, D), Z = Math.max(Z, L), Y = Math.max(Y, P);
|
|
1766
|
+
let X = x[v[1]], j = x[v[2]], Q = x[v[3]], $ = x[v[0]];
|
|
1555
1767
|
const K = Math.sqrt(
|
|
1556
1768
|
X * X + j * j + Q * Q + $ * $
|
|
1557
1769
|
);
|
|
1558
1770
|
K > 0 && (X /= K, j /= K, Q /= K, $ /= K), $ < 0 && (X = -X, j = -j, Q = -Q, $ = -$);
|
|
1559
|
-
const
|
|
1560
|
-
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1563
|
-
let
|
|
1564
|
-
|
|
1565
|
-
const
|
|
1566
|
-
|
|
1771
|
+
const ee = z * 4;
|
|
1772
|
+
B[ee] = X, B[ee + 1] = j, B[ee + 2] = Q, B[ee + 3] = $;
|
|
1773
|
+
const te = z * 3;
|
|
1774
|
+
T[te] = x[O[0]], T[te + 1] = x[O[1]], T[te + 2] = x[O[2]];
|
|
1775
|
+
let ue = 0.5 + x[V[0]] * p, de = 0.5 + x[V[1]] * p, ie = 0.5 + x[V[2]] * p;
|
|
1776
|
+
ue = Math.max(0, Math.min(1, ue)), de = Math.max(0, Math.min(1, de)), ie = Math.max(0, Math.min(1, ie));
|
|
1777
|
+
const be = z * 3;
|
|
1778
|
+
E[be] = ue, E[be + 1] = de, E[be + 2] = ie, U[z] = _(x[I]);
|
|
1567
1779
|
}
|
|
1568
1780
|
return {
|
|
1569
1781
|
numSplats: A,
|
|
1570
1782
|
positions: b.buffer,
|
|
1571
|
-
rotations:
|
|
1572
|
-
scales:
|
|
1573
|
-
colors:
|
|
1574
|
-
opacities:
|
|
1783
|
+
rotations: B.buffer,
|
|
1784
|
+
scales: T.buffer,
|
|
1785
|
+
colors: E.buffer,
|
|
1786
|
+
opacities: U.buffer,
|
|
1575
1787
|
boundingBox: {
|
|
1576
|
-
minX:
|
|
1788
|
+
minX: H,
|
|
1577
1789
|
minY: W,
|
|
1578
|
-
minZ:
|
|
1790
|
+
minZ: F,
|
|
1579
1791
|
maxX: J,
|
|
1580
1792
|
maxY: Z,
|
|
1581
|
-
maxZ:
|
|
1793
|
+
maxZ: Y
|
|
1582
1794
|
}
|
|
1583
1795
|
};
|
|
1584
1796
|
}
|
|
1585
1797
|
}).toString()})();`;
|
|
1586
1798
|
}
|
|
1587
1799
|
}
|
|
1588
|
-
var
|
|
1800
|
+
var se = Uint8Array, pe = Uint16Array, it = Int32Array, Ge = new se([
|
|
1589
1801
|
0,
|
|
1590
1802
|
0,
|
|
1591
1803
|
0,
|
|
@@ -1620,7 +1832,7 @@ var st = Uint8Array, pt = Uint16Array, Jt = Int32Array, Vt = new st([
|
|
|
1620
1832
|
0,
|
|
1621
1833
|
/* impossible */
|
|
1622
1834
|
0
|
|
1623
|
-
]),
|
|
1835
|
+
]), We = new se([
|
|
1624
1836
|
0,
|
|
1625
1837
|
0,
|
|
1626
1838
|
0,
|
|
@@ -1654,65 +1866,65 @@ var st = Uint8Array, pt = Uint16Array, Jt = Int32Array, Vt = new st([
|
|
|
1654
1866
|
/* unused */
|
|
1655
1867
|
0,
|
|
1656
1868
|
0
|
|
1657
|
-
]),
|
|
1658
|
-
for (var
|
|
1659
|
-
|
|
1660
|
-
for (var n = new
|
|
1661
|
-
for (var r =
|
|
1662
|
-
n[r] = r -
|
|
1663
|
-
return { b:
|
|
1664
|
-
},
|
|
1665
|
-
|
|
1666
|
-
var
|
|
1869
|
+
]), ot = new se([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), Ne = function(a, e) {
|
|
1870
|
+
for (var t = new pe(31), s = 0; s < 31; ++s)
|
|
1871
|
+
t[s] = e += 1 << a[s - 1];
|
|
1872
|
+
for (var n = new it(t[30]), s = 1; s < 30; ++s)
|
|
1873
|
+
for (var r = t[s]; r < t[s + 1]; ++r)
|
|
1874
|
+
n[r] = r - t[s] << 5 | s;
|
|
1875
|
+
return { b: t, r: n };
|
|
1876
|
+
}, $e = Ne(Ge, 2), je = $e.b, ct = $e.r;
|
|
1877
|
+
je[28] = 258, ct[258] = 28;
|
|
1878
|
+
var lt = Ne(We, 0), ht = lt.b, Be = new pe(32768);
|
|
1667
1879
|
for (var N = 0; N < 32768; ++N) {
|
|
1668
|
-
var
|
|
1669
|
-
|
|
1880
|
+
var le = (N & 43690) >> 1 | (N & 21845) << 1;
|
|
1881
|
+
le = (le & 52428) >> 2 | (le & 13107) << 2, le = (le & 61680) >> 4 | (le & 3855) << 4, Be[N] = ((le & 65280) >> 8 | (le & 255) << 8) >> 1;
|
|
1670
1882
|
}
|
|
1671
|
-
var
|
|
1672
|
-
for (var s = a.length, n = 0, r = new
|
|
1883
|
+
var ye = function(a, e, t) {
|
|
1884
|
+
for (var s = a.length, n = 0, r = new pe(e); n < s; ++n)
|
|
1673
1885
|
a[n] && ++r[a[n] - 1];
|
|
1674
|
-
var
|
|
1675
|
-
for (n = 1; n <
|
|
1676
|
-
|
|
1677
|
-
var
|
|
1678
|
-
if (
|
|
1679
|
-
|
|
1680
|
-
var
|
|
1886
|
+
var i = new pe(e);
|
|
1887
|
+
for (n = 1; n < e; ++n)
|
|
1888
|
+
i[n] = i[n - 1] + r[n - 1] << 1;
|
|
1889
|
+
var o;
|
|
1890
|
+
if (t) {
|
|
1891
|
+
o = new pe(1 << e);
|
|
1892
|
+
var m = 15 - e;
|
|
1681
1893
|
for (n = 0; n < s; ++n)
|
|
1682
1894
|
if (a[n])
|
|
1683
|
-
for (var y = n << 4 | a[n],
|
|
1684
|
-
|
|
1895
|
+
for (var y = n << 4 | a[n], u = e - a[n], l = i[a[n] - 1]++ << u, h = l | (1 << u) - 1; l <= h; ++l)
|
|
1896
|
+
o[Be[l] >> m] = y;
|
|
1685
1897
|
} else
|
|
1686
|
-
for (
|
|
1687
|
-
a[n] && (
|
|
1688
|
-
return
|
|
1689
|
-
},
|
|
1898
|
+
for (o = new pe(s), n = 0; n < s; ++n)
|
|
1899
|
+
a[n] && (o[n] = Be[i[a[n] - 1]++] >> 15 - a[n]);
|
|
1900
|
+
return o;
|
|
1901
|
+
}, ve = new se(288);
|
|
1690
1902
|
for (var N = 0; N < 144; ++N)
|
|
1691
|
-
|
|
1903
|
+
ve[N] = 8;
|
|
1692
1904
|
for (var N = 144; N < 256; ++N)
|
|
1693
|
-
|
|
1905
|
+
ve[N] = 9;
|
|
1694
1906
|
for (var N = 256; N < 280; ++N)
|
|
1695
|
-
|
|
1907
|
+
ve[N] = 7;
|
|
1696
1908
|
for (var N = 280; N < 288; ++N)
|
|
1697
|
-
|
|
1698
|
-
var
|
|
1909
|
+
ve[N] = 8;
|
|
1910
|
+
var He = new se(32);
|
|
1699
1911
|
for (var N = 0; N < 32; ++N)
|
|
1700
|
-
|
|
1701
|
-
var
|
|
1702
|
-
for (var
|
|
1703
|
-
a[
|
|
1704
|
-
return
|
|
1705
|
-
},
|
|
1706
|
-
var s =
|
|
1707
|
-
return (a[s] | a[s + 1] << 8) >> (
|
|
1708
|
-
},
|
|
1709
|
-
var
|
|
1710
|
-
return (a[
|
|
1711
|
-
},
|
|
1912
|
+
He[N] = 5;
|
|
1913
|
+
var mt = /* @__PURE__ */ ye(ve, 9, 1), ut = /* @__PURE__ */ ye(He, 5, 1), Ce = function(a) {
|
|
1914
|
+
for (var e = a[0], t = 1; t < a.length; ++t)
|
|
1915
|
+
a[t] > e && (e = a[t]);
|
|
1916
|
+
return e;
|
|
1917
|
+
}, ae = function(a, e, t) {
|
|
1918
|
+
var s = e / 8 | 0;
|
|
1919
|
+
return (a[s] | a[s + 1] << 8) >> (e & 7) & t;
|
|
1920
|
+
}, Ie = function(a, e) {
|
|
1921
|
+
var t = e / 8 | 0;
|
|
1922
|
+
return (a[t] | a[t + 1] << 8 | a[t + 2] << 16) >> (e & 7);
|
|
1923
|
+
}, dt = function(a) {
|
|
1712
1924
|
return (a + 7) / 8 | 0;
|
|
1713
|
-
},
|
|
1714
|
-
return (
|
|
1715
|
-
},
|
|
1925
|
+
}, De = function(a, e, t) {
|
|
1926
|
+
return (e == null || e < 0) && (e = 0), (t == null || t > a.length) && (t = a.length), new se(a.subarray(e, t));
|
|
1927
|
+
}, ft = [
|
|
1716
1928
|
"unexpected EOF",
|
|
1717
1929
|
"invalid block type",
|
|
1718
1930
|
"invalid length/literal",
|
|
@@ -1728,272 +1940,272 @@ var ne = /* @__PURE__ */ yt(vt, 9, 1), re = /* @__PURE__ */ yt(Wt, 5, 1), kt = f
|
|
|
1728
1940
|
"stream finishing",
|
|
1729
1941
|
"invalid zip data"
|
|
1730
1942
|
// determined by unknown compression method
|
|
1731
|
-
],
|
|
1732
|
-
var s = new Error(
|
|
1733
|
-
if (s.code = a, Error.captureStackTrace && Error.captureStackTrace(s,
|
|
1943
|
+
], ne = function(a, e, t) {
|
|
1944
|
+
var s = new Error(e || ft[a]);
|
|
1945
|
+
if (s.code = a, Error.captureStackTrace && Error.captureStackTrace(s, ne), !t)
|
|
1734
1946
|
throw s;
|
|
1735
1947
|
return s;
|
|
1736
|
-
},
|
|
1948
|
+
}, pt = function(a, e, t, s) {
|
|
1737
1949
|
var n = a.length, r = s ? s.length : 0;
|
|
1738
|
-
if (!n ||
|
|
1739
|
-
return
|
|
1740
|
-
var
|
|
1741
|
-
|
|
1950
|
+
if (!n || e.f && !e.l)
|
|
1951
|
+
return t || new se(0);
|
|
1952
|
+
var i = !t, o = i || e.i != 2, m = e.i;
|
|
1953
|
+
i && (t = new se(n * 3));
|
|
1742
1954
|
var y = function(j) {
|
|
1743
|
-
var Q =
|
|
1955
|
+
var Q = t.length;
|
|
1744
1956
|
if (j > Q) {
|
|
1745
|
-
var $ = new
|
|
1746
|
-
$.set(
|
|
1957
|
+
var $ = new se(Math.max(Q * 2, j));
|
|
1958
|
+
$.set(t), t = $;
|
|
1747
1959
|
}
|
|
1748
|
-
},
|
|
1960
|
+
}, u = e.f || 0, l = e.p || 0, h = e.b || 0, f = e.l, w = e.d, A = e.m, b = e.n, B = n * 8;
|
|
1749
1961
|
do {
|
|
1750
|
-
if (!
|
|
1751
|
-
|
|
1752
|
-
var
|
|
1753
|
-
if (
|
|
1754
|
-
if (
|
|
1755
|
-
|
|
1756
|
-
else if (
|
|
1757
|
-
var
|
|
1758
|
-
|
|
1759
|
-
for (var S = new
|
|
1760
|
-
g[
|
|
1761
|
-
|
|
1762
|
-
for (var
|
|
1763
|
-
var
|
|
1764
|
-
|
|
1765
|
-
var
|
|
1766
|
-
if (
|
|
1767
|
-
S[v++] =
|
|
1962
|
+
if (!f) {
|
|
1963
|
+
u = ae(a, l, 1);
|
|
1964
|
+
var T = ae(a, l + 1, 3);
|
|
1965
|
+
if (l += 3, T)
|
|
1966
|
+
if (T == 1)
|
|
1967
|
+
f = mt, w = ut, A = 9, b = 5;
|
|
1968
|
+
else if (T == 2) {
|
|
1969
|
+
var C = ae(a, l, 31) + 257, M = ae(a, l + 10, 15) + 4, k = C + ae(a, l + 5, 31) + 1;
|
|
1970
|
+
l += 14;
|
|
1971
|
+
for (var S = new se(k), g = new se(19), v = 0; v < M; ++v)
|
|
1972
|
+
g[ot[v]] = ae(a, l + v * 3, 7);
|
|
1973
|
+
l += M * 3;
|
|
1974
|
+
for (var O = Ce(g), V = (1 << O) - 1, I = ye(g, O, 1), v = 0; v < k; ) {
|
|
1975
|
+
var q = I[ae(a, l, V)];
|
|
1976
|
+
l += q & 15;
|
|
1977
|
+
var E = q >> 4;
|
|
1978
|
+
if (E < 16)
|
|
1979
|
+
S[v++] = E;
|
|
1768
1980
|
else {
|
|
1769
|
-
var
|
|
1770
|
-
for (
|
|
1771
|
-
S[v++] =
|
|
1981
|
+
var p = 0, _ = 0;
|
|
1982
|
+
for (E == 16 ? (_ = 3 + ae(a, l, 3), l += 2, p = S[v - 1]) : E == 17 ? (_ = 3 + ae(a, l, 7), l += 3) : E == 18 && (_ = 11 + ae(a, l, 127), l += 7); _--; )
|
|
1983
|
+
S[v++] = p;
|
|
1772
1984
|
}
|
|
1773
1985
|
}
|
|
1774
|
-
var
|
|
1775
|
-
A =
|
|
1986
|
+
var H = S.subarray(0, C), W = S.subarray(C);
|
|
1987
|
+
A = Ce(H), b = Ce(W), f = ye(H, A, 1), w = ye(W, b, 1);
|
|
1776
1988
|
} else
|
|
1777
|
-
|
|
1989
|
+
ne(1);
|
|
1778
1990
|
else {
|
|
1779
|
-
var
|
|
1780
|
-
if (
|
|
1781
|
-
|
|
1991
|
+
var E = dt(l) + 4, U = a[E - 4] | a[E - 3] << 8, R = E + U;
|
|
1992
|
+
if (R > n) {
|
|
1993
|
+
m && ne(0);
|
|
1782
1994
|
break;
|
|
1783
1995
|
}
|
|
1784
|
-
|
|
1996
|
+
o && y(h + U), t.set(a.subarray(E, R), h), e.b = h += U, e.p = l = R * 8, e.f = u;
|
|
1785
1997
|
continue;
|
|
1786
1998
|
}
|
|
1787
|
-
if (
|
|
1788
|
-
|
|
1999
|
+
if (l > B) {
|
|
2000
|
+
m && ne(0);
|
|
1789
2001
|
break;
|
|
1790
2002
|
}
|
|
1791
2003
|
}
|
|
1792
|
-
|
|
1793
|
-
for (var
|
|
1794
|
-
var
|
|
1795
|
-
if (
|
|
1796
|
-
|
|
2004
|
+
o && y(h + 131072);
|
|
2005
|
+
for (var F = (1 << A) - 1, J = (1 << b) - 1, Z = l; ; Z = l) {
|
|
2006
|
+
var p = f[Ie(a, l) & F], Y = p >> 4;
|
|
2007
|
+
if (l += p & 15, l > B) {
|
|
2008
|
+
m && ne(0);
|
|
1797
2009
|
break;
|
|
1798
2010
|
}
|
|
1799
|
-
if (
|
|
1800
|
-
|
|
1801
|
-
else if (
|
|
1802
|
-
Z =
|
|
2011
|
+
if (p || ne(2), Y < 256)
|
|
2012
|
+
t[h++] = Y;
|
|
2013
|
+
else if (Y == 256) {
|
|
2014
|
+
Z = l, f = null;
|
|
1803
2015
|
break;
|
|
1804
2016
|
} else {
|
|
1805
|
-
var
|
|
1806
|
-
if (
|
|
1807
|
-
var v =
|
|
1808
|
-
|
|
2017
|
+
var z = Y - 254;
|
|
2018
|
+
if (Y > 264) {
|
|
2019
|
+
var v = Y - 257, x = Ge[v];
|
|
2020
|
+
z = ae(a, l, (1 << x) - 1) + je[v], l += x;
|
|
1809
2021
|
}
|
|
1810
|
-
var
|
|
1811
|
-
|
|
1812
|
-
var W =
|
|
2022
|
+
var D = w[Ie(a, l) & J], L = D >> 4;
|
|
2023
|
+
D || ne(3), l += D & 15;
|
|
2024
|
+
var W = ht[L];
|
|
1813
2025
|
if (L > 3) {
|
|
1814
|
-
var
|
|
1815
|
-
W +=
|
|
2026
|
+
var x = We[L];
|
|
2027
|
+
W += Ie(a, l) & (1 << x) - 1, l += x;
|
|
1816
2028
|
}
|
|
1817
|
-
if (
|
|
1818
|
-
|
|
2029
|
+
if (l > B) {
|
|
2030
|
+
m && ne(0);
|
|
1819
2031
|
break;
|
|
1820
2032
|
}
|
|
1821
|
-
|
|
1822
|
-
var
|
|
2033
|
+
o && y(h + 131072);
|
|
2034
|
+
var P = h + z;
|
|
1823
2035
|
if (h < W) {
|
|
1824
|
-
var G = r - W, X = Math.min(W,
|
|
1825
|
-
for (G + h < 0 &&
|
|
1826
|
-
|
|
2036
|
+
var G = r - W, X = Math.min(W, P);
|
|
2037
|
+
for (G + h < 0 && ne(3); h < X; ++h)
|
|
2038
|
+
t[h] = s[G + h];
|
|
1827
2039
|
}
|
|
1828
|
-
for (; h <
|
|
1829
|
-
|
|
2040
|
+
for (; h < P; ++h)
|
|
2041
|
+
t[h] = t[h - W];
|
|
1830
2042
|
}
|
|
1831
2043
|
}
|
|
1832
|
-
|
|
1833
|
-
} while (!
|
|
1834
|
-
return h !=
|
|
1835
|
-
},
|
|
1836
|
-
return a[
|
|
1837
|
-
},
|
|
1838
|
-
return (a[
|
|
1839
|
-
},
|
|
1840
|
-
return
|
|
2044
|
+
e.l = f, e.p = Z, e.b = h, e.f = u, f && (u = 1, e.m = A, e.d = w, e.n = b);
|
|
2045
|
+
} while (!u);
|
|
2046
|
+
return h != t.length && i ? De(t, 0, h) : t.subarray(0, h);
|
|
2047
|
+
}, xt = /* @__PURE__ */ new se(0), oe = function(a, e) {
|
|
2048
|
+
return a[e] | a[e + 1] << 8;
|
|
2049
|
+
}, re = function(a, e) {
|
|
2050
|
+
return (a[e] | a[e + 1] << 8 | a[e + 2] << 16 | a[e + 3] << 24) >>> 0;
|
|
2051
|
+
}, _e = function(a, e) {
|
|
2052
|
+
return re(a, e) + re(a, e + 4) * 4294967296;
|
|
1841
2053
|
};
|
|
1842
|
-
function
|
|
1843
|
-
return
|
|
2054
|
+
function gt(a, e) {
|
|
2055
|
+
return pt(a, { i: 2 }, e && e.out, e && e.dictionary);
|
|
1844
2056
|
}
|
|
1845
|
-
var
|
|
2057
|
+
var ze = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), yt = 0;
|
|
1846
2058
|
try {
|
|
1847
|
-
|
|
2059
|
+
ze.decode(xt, { stream: !0 }), yt = 1;
|
|
1848
2060
|
} catch {
|
|
1849
2061
|
}
|
|
1850
|
-
var
|
|
1851
|
-
for (var
|
|
1852
|
-
var s = a[
|
|
1853
|
-
if (
|
|
1854
|
-
return { s:
|
|
1855
|
-
n ? n == 3 ? (s = ((s & 15) << 18 | (a[
|
|
2062
|
+
var wt = function(a) {
|
|
2063
|
+
for (var e = "", t = 0; ; ) {
|
|
2064
|
+
var s = a[t++], n = (s > 127) + (s > 223) + (s > 239);
|
|
2065
|
+
if (t + n > a.length)
|
|
2066
|
+
return { s: e, r: De(a, t - 1) };
|
|
2067
|
+
n ? n == 3 ? (s = ((s & 15) << 18 | (a[t++] & 63) << 12 | (a[t++] & 63) << 6 | a[t++] & 63) - 65536, e += String.fromCharCode(55296 | s >> 10, 56320 | s & 1023)) : n & 1 ? e += String.fromCharCode((s & 31) << 6 | a[t++] & 63) : e += String.fromCharCode((s & 15) << 12 | (a[t++] & 63) << 6 | a[t++] & 63) : e += String.fromCharCode(s);
|
|
1856
2068
|
}
|
|
1857
2069
|
};
|
|
1858
|
-
function
|
|
1859
|
-
if (
|
|
1860
|
-
for (var
|
|
1861
|
-
|
|
1862
|
-
return
|
|
2070
|
+
function vt(a, e) {
|
|
2071
|
+
if (e) {
|
|
2072
|
+
for (var t = "", s = 0; s < a.length; s += 16384)
|
|
2073
|
+
t += String.fromCharCode.apply(null, a.subarray(s, s + 16384));
|
|
2074
|
+
return t;
|
|
1863
2075
|
} else {
|
|
1864
|
-
if (
|
|
1865
|
-
return
|
|
1866
|
-
var n =
|
|
1867
|
-
return
|
|
2076
|
+
if (ze)
|
|
2077
|
+
return ze.decode(a);
|
|
2078
|
+
var n = wt(a), r = n.s, t = n.r;
|
|
2079
|
+
return t.length && ne(8), r;
|
|
1868
2080
|
}
|
|
1869
2081
|
}
|
|
1870
|
-
var
|
|
1871
|
-
return
|
|
1872
|
-
},
|
|
1873
|
-
var s =
|
|
1874
|
-
return [
|
|
1875
|
-
},
|
|
1876
|
-
for (;
|
|
2082
|
+
var Mt = function(a, e) {
|
|
2083
|
+
return e + 30 + oe(a, e + 26) + oe(a, e + 28);
|
|
2084
|
+
}, bt = function(a, e, t) {
|
|
2085
|
+
var s = oe(a, e + 28), n = vt(a.subarray(e + 46, e + 46 + s), !(oe(a, e + 8) & 2048)), r = e + 46 + s, i = re(a, e + 20), o = t && i == 4294967295 ? St(a, r) : [i, re(a, e + 24), re(a, e + 42)], m = o[0], y = o[1], u = o[2];
|
|
2086
|
+
return [oe(a, e + 10), m, y, n, r + oe(a, e + 30) + oe(a, e + 32), u];
|
|
2087
|
+
}, St = function(a, e) {
|
|
2088
|
+
for (; oe(a, e) != 1; e += 4 + oe(a, e + 2))
|
|
1877
2089
|
;
|
|
1878
|
-
return [
|
|
2090
|
+
return [_e(a, e + 12), _e(a, e + 4), _e(a, e + 20)];
|
|
1879
2091
|
};
|
|
1880
|
-
function
|
|
1881
|
-
for (var
|
|
1882
|
-
(!s || a.length - s > 65558) &&
|
|
1883
|
-
var n =
|
|
2092
|
+
function At(a, e) {
|
|
2093
|
+
for (var t = {}, s = a.length - 22; re(a, s) != 101010256; --s)
|
|
2094
|
+
(!s || a.length - s > 65558) && ne(13);
|
|
2095
|
+
var n = oe(a, s + 8);
|
|
1884
2096
|
if (!n)
|
|
1885
2097
|
return {};
|
|
1886
|
-
var r =
|
|
1887
|
-
if (
|
|
1888
|
-
var
|
|
1889
|
-
|
|
2098
|
+
var r = re(a, s + 16), i = r == 4294967295 || n == 65535;
|
|
2099
|
+
if (i) {
|
|
2100
|
+
var o = re(a, s - 12);
|
|
2101
|
+
i = re(a, o) == 101075792, i && (n = re(a, o + 32), r = re(a, o + 48));
|
|
1890
2102
|
}
|
|
1891
|
-
for (var
|
|
1892
|
-
var y =
|
|
1893
|
-
r = w,
|
|
2103
|
+
for (var m = 0; m < n; ++m) {
|
|
2104
|
+
var y = bt(a, r, i), u = y[0], l = y[1], h = y[2], f = y[3], w = y[4], A = y[5], b = Mt(a, A);
|
|
2105
|
+
r = w, u ? u == 8 ? t[f] = gt(a.subarray(b, b + l), { out: new se(h) }) : ne(14, "unknown compression type " + u) : t[f] = De(a, b, b + l);
|
|
1894
2106
|
}
|
|
1895
|
-
return
|
|
2107
|
+
return t;
|
|
1896
2108
|
}
|
|
1897
|
-
const
|
|
1898
|
-
const
|
|
1899
|
-
if (typeof
|
|
1900
|
-
throw new Error(`Invalid SOG metadata section: ${
|
|
1901
|
-
return
|
|
1902
|
-
},
|
|
1903
|
-
const
|
|
1904
|
-
if (!Array.isArray(
|
|
1905
|
-
throw new Error(`${
|
|
1906
|
-
if (!
|
|
1907
|
-
throw new Error(`${
|
|
1908
|
-
return
|
|
1909
|
-
},
|
|
1910
|
-
const
|
|
1911
|
-
if (!Array.isArray(
|
|
1912
|
-
throw new Error(`${
|
|
2109
|
+
const Me = (a) => typeof a == "number" && Number.isFinite(a), he = (a, e) => {
|
|
2110
|
+
const t = a[e];
|
|
2111
|
+
if (typeof t != "object" || t === null)
|
|
2112
|
+
throw new Error(`Invalid SOG metadata section: ${e}`);
|
|
2113
|
+
return t;
|
|
2114
|
+
}, me = (a, e) => {
|
|
2115
|
+
const t = a.files;
|
|
2116
|
+
if (!Array.isArray(t))
|
|
2117
|
+
throw new Error(`${e}.files is not an array`);
|
|
2118
|
+
if (!t.every((s) => typeof s == "string"))
|
|
2119
|
+
throw new Error(`${e}.files contains non-strings`);
|
|
2120
|
+
return t;
|
|
2121
|
+
}, ke = (a, e) => {
|
|
2122
|
+
const t = a.mins, s = a.maxs;
|
|
2123
|
+
if (!Array.isArray(t) || t.length !== 3)
|
|
2124
|
+
throw new Error(`${e}.mins must be length-3`);
|
|
1913
2125
|
if (!Array.isArray(s) || s.length !== 3)
|
|
1914
|
-
throw new Error(`${
|
|
1915
|
-
if (![...
|
|
1916
|
-
throw new Error(`${
|
|
2126
|
+
throw new Error(`${e}.maxs must be length-3`);
|
|
2127
|
+
if (![...t, ...s].every(Me))
|
|
2128
|
+
throw new Error(`${e}.mins/maxs must be finite numbers`);
|
|
1917
2129
|
return {
|
|
1918
|
-
mins: [
|
|
2130
|
+
mins: [t[0], t[1], t[2]],
|
|
1919
2131
|
maxs: [s[0], s[1], s[2]]
|
|
1920
2132
|
};
|
|
1921
|
-
},
|
|
1922
|
-
const
|
|
1923
|
-
if (!Array.isArray(
|
|
1924
|
-
throw new Error(`${
|
|
2133
|
+
}, Ct = (a, e) => {
|
|
2134
|
+
const t = a.mins, s = a.maxs;
|
|
2135
|
+
if (!Array.isArray(t) || t.length !== 4)
|
|
2136
|
+
throw new Error(`${e}.mins must be length-4`);
|
|
1925
2137
|
if (!Array.isArray(s) || s.length !== 4)
|
|
1926
|
-
throw new Error(`${
|
|
1927
|
-
if (![...
|
|
1928
|
-
throw new Error(`${
|
|
2138
|
+
throw new Error(`${e}.maxs must be length-4`);
|
|
2139
|
+
if (![...t, ...s].every(Me))
|
|
2140
|
+
throw new Error(`${e}.mins/maxs must be finite numbers`);
|
|
1929
2141
|
return {
|
|
1930
|
-
mins: [
|
|
2142
|
+
mins: [t[0], t[1], t[2], t[3]],
|
|
1931
2143
|
maxs: [s[0], s[1], s[2], s[3]]
|
|
1932
2144
|
};
|
|
1933
|
-
},
|
|
1934
|
-
const
|
|
1935
|
-
if (!Array.isArray(
|
|
1936
|
-
throw new Error(`${
|
|
1937
|
-
if (!
|
|
1938
|
-
throw new Error(`${
|
|
1939
|
-
return
|
|
1940
|
-
},
|
|
2145
|
+
}, Oe = (a, e) => {
|
|
2146
|
+
const t = a.codebook;
|
|
2147
|
+
if (!Array.isArray(t))
|
|
2148
|
+
throw new Error(`${e}.codebook is not an array`);
|
|
2149
|
+
if (!t.every(Me))
|
|
2150
|
+
throw new Error(`${e}.codebook contains non-finite numbers`);
|
|
2151
|
+
return t;
|
|
2152
|
+
}, Ue = (a) => {
|
|
1941
2153
|
if (typeof a != "object" || a === null) throw new Error("Invalid SOG metadata: not an object");
|
|
1942
|
-
const
|
|
1943
|
-
if (
|
|
1944
|
-
if (
|
|
1945
|
-
const
|
|
2154
|
+
const e = a, t = e.version ?? 1;
|
|
2155
|
+
if (t !== 1 && t !== 2) throw new Error(`Unsupported SOG version: ${String(t)}`);
|
|
2156
|
+
if (t === 1) {
|
|
2157
|
+
const u = he(e, "means"), l = he(e, "sh0"), h = he(e, "quats"), f = he(e, "scales"), w = typeof e.count == "number" && Number.isFinite(e.count) ? e.count : void 0, A = Array.isArray(u.shape) ? u.shape : void 0, b = A && typeof A[0] == "number" ? A[0] : void 0;
|
|
1946
2158
|
if (w === void 0 && b === void 0) throw new Error("Invalid SOGS metadata: unable to determine splat count");
|
|
1947
2159
|
if (w !== void 0 && b !== void 0 && w !== b) throw new Error("Inconsistent SOGS metadata: count does not match means.shape[0]");
|
|
1948
2160
|
return {
|
|
1949
2161
|
version: 1,
|
|
1950
2162
|
numSplats: (w ?? b) | 0,
|
|
1951
2163
|
files: {
|
|
1952
|
-
sh0:
|
|
1953
|
-
means:
|
|
1954
|
-
quats:
|
|
1955
|
-
scales:
|
|
2164
|
+
sh0: me(l, "sh0"),
|
|
2165
|
+
means: me(u, "means"),
|
|
2166
|
+
quats: me(h, "quats"),
|
|
2167
|
+
scales: me(f, "scales")
|
|
1956
2168
|
},
|
|
1957
2169
|
ranges: {
|
|
1958
|
-
sh0:
|
|
1959
|
-
means:
|
|
1960
|
-
scales:
|
|
2170
|
+
sh0: Ct(l, "sh0"),
|
|
2171
|
+
means: ke(u, "means"),
|
|
2172
|
+
scales: ke(f, "scales")
|
|
1961
2173
|
}
|
|
1962
2174
|
};
|
|
1963
2175
|
}
|
|
1964
|
-
const s =
|
|
1965
|
-
if (!
|
|
1966
|
-
const n = s | 0, r =
|
|
2176
|
+
const s = e.count;
|
|
2177
|
+
if (!Me(s)) throw new Error('Invalid SOG v2 metadata: missing/invalid "count"');
|
|
2178
|
+
const n = s | 0, r = he(e, "means"), i = he(e, "sh0"), o = he(e, "quats"), m = he(e, "scales");
|
|
1967
2179
|
return {
|
|
1968
2180
|
version: 2,
|
|
1969
2181
|
numSplats: n,
|
|
1970
2182
|
files: {
|
|
1971
|
-
sh0:
|
|
1972
|
-
means:
|
|
1973
|
-
quats:
|
|
1974
|
-
scales:
|
|
2183
|
+
sh0: me(i, "sh0"),
|
|
2184
|
+
means: me(r, "means"),
|
|
2185
|
+
quats: me(o, "quats"),
|
|
2186
|
+
scales: me(m, "scales")
|
|
1975
2187
|
},
|
|
1976
2188
|
ranges: {
|
|
1977
|
-
means:
|
|
1978
|
-
sh0: { codebook:
|
|
1979
|
-
scales: { codebook:
|
|
2189
|
+
means: ke(r, "means"),
|
|
2190
|
+
sh0: { codebook: Oe(i, "sh0") },
|
|
2191
|
+
scales: { codebook: Oe(m, "scales") }
|
|
1980
2192
|
},
|
|
1981
|
-
antialias: typeof
|
|
2193
|
+
antialias: typeof e.antialias == "boolean" ? e.antialias : void 0
|
|
1982
2194
|
// prettier-ignore
|
|
1983
2195
|
};
|
|
1984
2196
|
};
|
|
1985
|
-
class
|
|
1986
|
-
constructor(
|
|
1987
|
-
super(
|
|
2197
|
+
class Bt extends c.Loader {
|
|
2198
|
+
constructor(e, t) {
|
|
2199
|
+
super(e), this.withCredentials = (t == null ? void 0 : t.withCredentials) ?? !1;
|
|
1988
2200
|
}
|
|
1989
2201
|
/**
|
|
1990
2202
|
* Detect if a buffer is a ZIP file by checking magic bytes
|
|
1991
2203
|
* ZIP files start with signature: PK\x03\x04 (0x50 0x4B 0x03 0x04)
|
|
1992
2204
|
*/
|
|
1993
|
-
isZipBuffer(
|
|
1994
|
-
if (
|
|
1995
|
-
const
|
|
1996
|
-
return
|
|
2205
|
+
isZipBuffer(e) {
|
|
2206
|
+
if (e.byteLength < 4) return !1;
|
|
2207
|
+
const t = new Uint8Array(e, 0, 4);
|
|
2208
|
+
return t[0] === 80 && t[1] === 75 && t[2] === 3 && t[3] === 4;
|
|
1997
2209
|
}
|
|
1998
2210
|
/**
|
|
1999
2211
|
* Load a SOGS file (meta.json + textures)
|
|
@@ -2002,15 +2214,15 @@ class Me extends l.Loader {
|
|
|
2002
2214
|
* @param onProgress Optional progress callback
|
|
2003
2215
|
* @param onError Optional error callback
|
|
2004
2216
|
*/
|
|
2005
|
-
load(
|
|
2006
|
-
const r = new
|
|
2217
|
+
load(e, t, s, n) {
|
|
2218
|
+
const r = new c.FileLoader(this.manager);
|
|
2007
2219
|
r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setPath(this.path), r.setWithCredentials(this.withCredentials), r.load(
|
|
2008
|
-
|
|
2009
|
-
(
|
|
2010
|
-
this.parseAsync(
|
|
2011
|
-
|
|
2012
|
-
}).catch((
|
|
2013
|
-
this.manager.itemError(
|
|
2220
|
+
e,
|
|
2221
|
+
(i) => {
|
|
2222
|
+
this.parseAsync(e, i).then((o) => {
|
|
2223
|
+
t && t(o);
|
|
2224
|
+
}).catch((o) => {
|
|
2225
|
+
this.manager.itemError(e), n && n(o), console.error("Error loading SOGS meta:", o);
|
|
2014
2226
|
});
|
|
2015
2227
|
},
|
|
2016
2228
|
s,
|
|
@@ -2023,52 +2235,52 @@ class Me extends l.Loader {
|
|
|
2023
2235
|
* @param onProgress Optional progress callback
|
|
2024
2236
|
* @returns A Promise that resolves with the parsed SplatData
|
|
2025
2237
|
*/
|
|
2026
|
-
loadAsync(
|
|
2238
|
+
loadAsync(e, t) {
|
|
2027
2239
|
return new Promise((s, n) => {
|
|
2028
|
-
const r = new
|
|
2240
|
+
const r = new c.FileLoader(this.manager);
|
|
2029
2241
|
r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setPath(this.path), r.setWithCredentials(this.withCredentials), r.load(
|
|
2030
|
-
|
|
2031
|
-
(
|
|
2032
|
-
this.parseAsync(
|
|
2033
|
-
n(
|
|
2242
|
+
e,
|
|
2243
|
+
(i) => {
|
|
2244
|
+
this.parseAsync(e, i).then(s).catch((o) => {
|
|
2245
|
+
n(o), this.manager.itemError(e);
|
|
2034
2246
|
});
|
|
2035
2247
|
},
|
|
2036
|
-
|
|
2037
|
-
(
|
|
2038
|
-
n(
|
|
2248
|
+
t,
|
|
2249
|
+
(i) => {
|
|
2250
|
+
n(i), this.manager.itemError(e);
|
|
2039
2251
|
}
|
|
2040
2252
|
);
|
|
2041
2253
|
});
|
|
2042
2254
|
}
|
|
2043
|
-
async parseAsync(
|
|
2044
|
-
if (!(
|
|
2045
|
-
if (this.isZipBuffer(
|
|
2046
|
-
const n = new TextDecoder("utf-8").decode(
|
|
2047
|
-
return this.parseMetaAsync(
|
|
2255
|
+
async parseAsync(e, t) {
|
|
2256
|
+
if (!(t instanceof ArrayBuffer)) throw new Error("SOGS loader: expected ArrayBuffer payload");
|
|
2257
|
+
if (this.isZipBuffer(t)) return this.parseZipAsync(t);
|
|
2258
|
+
const n = new TextDecoder("utf-8").decode(t), r = JSON.parse(n);
|
|
2259
|
+
return this.parseMetaAsync(e, r);
|
|
2048
2260
|
}
|
|
2049
|
-
async parseMetaAsync(
|
|
2050
|
-
const s =
|
|
2051
|
-
|
|
2052
|
-
const y = (
|
|
2261
|
+
async parseMetaAsync(e, t) {
|
|
2262
|
+
const s = Ue(t), { numSplats: n, files: r, ranges: i, version: o } = s, m = new c.TextureLoader(this.manager);
|
|
2263
|
+
m.setPath(this.path), m.setRequestHeader(this.requestHeader), m.setWithCredentials(this.withCredentials);
|
|
2264
|
+
const y = (E, U) => {
|
|
2053
2265
|
try {
|
|
2054
|
-
return new URL(
|
|
2266
|
+
return new URL(U, E).toString();
|
|
2055
2267
|
} catch {
|
|
2056
|
-
return
|
|
2268
|
+
return E.substring(0, E.lastIndexOf("/") + 1) + U;
|
|
2057
2269
|
}
|
|
2058
|
-
},
|
|
2059
|
-
const
|
|
2060
|
-
return new Promise((
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
(
|
|
2064
|
-
|
|
2270
|
+
}, u = (E, U) => {
|
|
2271
|
+
const R = y(e, E);
|
|
2272
|
+
return new Promise((C, M) => {
|
|
2273
|
+
m.load(
|
|
2274
|
+
R,
|
|
2275
|
+
(k) => {
|
|
2276
|
+
k.generateMipmaps = !1, k.magFilter = c.NearestFilter, k.minFilter = c.NearestFilter, k.flipY = !1, C(k);
|
|
2065
2277
|
},
|
|
2066
2278
|
void 0,
|
|
2067
|
-
(
|
|
2068
|
-
const S =
|
|
2279
|
+
(k) => {
|
|
2280
|
+
const S = k instanceof Error ? k.message : String(k);
|
|
2069
2281
|
M(
|
|
2070
2282
|
new Error(
|
|
2071
|
-
`SOGS loader: failed to load ${
|
|
2283
|
+
`SOGS loader: failed to load ${U} (${E}): ${S}`
|
|
2072
2284
|
)
|
|
2073
2285
|
);
|
|
2074
2286
|
}
|
|
@@ -2079,88 +2291,90 @@ class Me extends l.Loader {
|
|
|
2079
2291
|
if (!Array.isArray(r.means) || r.means.length < 2) throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");
|
|
2080
2292
|
if (!Array.isArray(r.quats) || r.quats.length < 1) throw new Error("SOGS loader: files.quats must have at least 1 entry");
|
|
2081
2293
|
if (!Array.isArray(r.scales) || r.scales.length < 1) throw new Error("SOGS loader: files.scales must have at least 1 entry");
|
|
2082
|
-
const [
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
]), b = { means_l:
|
|
2089
|
-
if (
|
|
2090
|
-
const
|
|
2091
|
-
return
|
|
2294
|
+
const [l, h, f, w, A] = await Promise.all([
|
|
2295
|
+
u(r.means[0], "means_l"),
|
|
2296
|
+
u(r.means[1], "means_u"),
|
|
2297
|
+
u(r.quats[0], "quats"),
|
|
2298
|
+
u(r.scales[0], "scales"),
|
|
2299
|
+
u(r.sh0[0], "sh0")
|
|
2300
|
+
]), b = { means_l: l, means_u: h, quats: f, scales: w, sh0: A };
|
|
2301
|
+
if (o === 1) {
|
|
2302
|
+
const E = new Ee(n, i, b), U = ge.packSogs(E);
|
|
2303
|
+
return E.dispose(), U;
|
|
2092
2304
|
}
|
|
2093
|
-
const
|
|
2094
|
-
return
|
|
2305
|
+
const B = new qe(n, i, b), T = ge.packSog2(B);
|
|
2306
|
+
return B.dispose(), T;
|
|
2095
2307
|
}
|
|
2096
|
-
async parseZipAsync(
|
|
2097
|
-
const
|
|
2308
|
+
async parseZipAsync(e) {
|
|
2309
|
+
const t = At(new Uint8Array(e)), s = Object.keys(t), n = s.find((g) => g.toLowerCase().endsWith("meta.json")) ?? null;
|
|
2098
2310
|
if (!n) throw new Error("SOGS loader: zip missing meta.json");
|
|
2099
|
-
const r = n.includes("/") ? n.slice(0, n.lastIndexOf("/") + 1) : "",
|
|
2100
|
-
const v =
|
|
2101
|
-
for (const
|
|
2102
|
-
const
|
|
2103
|
-
if (
|
|
2311
|
+
const r = n.includes("/") ? n.slice(0, n.lastIndexOf("/") + 1) : "", i = new TextDecoder(), o = JSON.parse(i.decode(t[n])), m = Ue(o), { numSplats: y, files: u, ranges: l, version: h } = m, f = (g) => g.replace(/\\/g, "/").replace(/^\.?\//, ""), w = (g) => {
|
|
2312
|
+
const v = f(g), O = [f(r + v), v];
|
|
2313
|
+
for (const q of O) {
|
|
2314
|
+
const p = t[q];
|
|
2315
|
+
if (p) return p;
|
|
2104
2316
|
}
|
|
2105
|
-
const
|
|
2106
|
-
if (I) return
|
|
2317
|
+
const V = v.split("/").pop(), I = s.find((q) => f(q).endsWith("/" + v)) ?? s.find((q) => f(q).endsWith("/" + V)) ?? s.find((q) => f(q) === V) ?? null;
|
|
2318
|
+
if (I) return t[I];
|
|
2107
2319
|
throw new Error(`SOGS loader: zip missing file "${g}"`);
|
|
2108
2320
|
}, A = (g) => {
|
|
2109
2321
|
const v = g.toLowerCase();
|
|
2110
2322
|
return v.endsWith(".png") ? "image/png" : v.endsWith(".jpg") || v.endsWith(".jpeg") ? "image/jpeg" : v.endsWith(".webp") ? "image/webp" : "application/octet-stream";
|
|
2111
|
-
}, b = new
|
|
2323
|
+
}, b = new c.TextureLoader(this.manager);
|
|
2112
2324
|
b.setRequestHeader(this.requestHeader), b.setWithCredentials(this.withCredentials);
|
|
2113
|
-
const
|
|
2114
|
-
const
|
|
2325
|
+
const B = (g, v) => {
|
|
2326
|
+
const O = w(g), V = new Blob([O], {
|
|
2115
2327
|
type: A(g)
|
|
2116
|
-
}), I = URL.createObjectURL(
|
|
2117
|
-
return new Promise((
|
|
2328
|
+
}), I = URL.createObjectURL(V);
|
|
2329
|
+
return new Promise((q, p) => {
|
|
2118
2330
|
b.load(
|
|
2119
2331
|
I,
|
|
2120
|
-
(
|
|
2121
|
-
URL.revokeObjectURL(I),
|
|
2332
|
+
(_) => {
|
|
2333
|
+
URL.revokeObjectURL(I), _.generateMipmaps = !1, _.magFilter = c.NearestFilter, _.minFilter = c.NearestFilter, _.flipY = !1, q(_);
|
|
2122
2334
|
},
|
|
2123
2335
|
void 0,
|
|
2124
|
-
(
|
|
2336
|
+
(_) => {
|
|
2125
2337
|
URL.revokeObjectURL(I);
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2338
|
+
const H = _ instanceof Error ? _.message : String(_);
|
|
2339
|
+
p(
|
|
2128
2340
|
new Error(
|
|
2129
|
-
`SOGS loader: failed to load ${v} from zip (${g}): ${
|
|
2341
|
+
`SOGS loader: failed to load ${v} from zip (${g}): ${H}`
|
|
2130
2342
|
)
|
|
2131
2343
|
);
|
|
2132
2344
|
}
|
|
2133
2345
|
);
|
|
2134
2346
|
});
|
|
2135
2347
|
};
|
|
2136
|
-
if (!Array.isArray(
|
|
2137
|
-
if (!Array.isArray(
|
|
2138
|
-
if (!Array.isArray(
|
|
2139
|
-
if (!Array.isArray(
|
|
2140
|
-
const [
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
]), M = { means_l:
|
|
2348
|
+
if (!Array.isArray(u.sh0) || u.sh0.length < 1) throw new Error("SOGS loader: files.sh0 must have at least 1 entry (sh0)");
|
|
2349
|
+
if (!Array.isArray(u.means) || u.means.length < 2) throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");
|
|
2350
|
+
if (!Array.isArray(u.quats) || u.quats.length < 1) throw new Error("SOGS loader: files.quats must have at least 1 entry");
|
|
2351
|
+
if (!Array.isArray(u.scales) || u.scales.length < 1) throw new Error("SOGS loader: files.scales must have at least 1 entry");
|
|
2352
|
+
const [T, E, U, R, C] = await Promise.all([
|
|
2353
|
+
B(u.means[0], "means_l"),
|
|
2354
|
+
B(u.means[1], "means_u"),
|
|
2355
|
+
B(u.quats[0], "quats"),
|
|
2356
|
+
B(u.scales[0], "scales"),
|
|
2357
|
+
B(u.sh0[0], "sh0")
|
|
2358
|
+
]), M = { means_l: T, means_u: E, quats: U, scales: R, sh0: C };
|
|
2147
2359
|
if (h === 1) {
|
|
2148
|
-
const g = new
|
|
2360
|
+
const g = new Ee(y, l, M), v = ge.packSogs(g);
|
|
2149
2361
|
return g.dispose(), v;
|
|
2150
2362
|
}
|
|
2151
|
-
const
|
|
2152
|
-
return
|
|
2363
|
+
const k = new qe(y, l, M), S = ge.packSog2(k);
|
|
2364
|
+
return k.dispose(), S;
|
|
2153
2365
|
}
|
|
2154
2366
|
}
|
|
2155
|
-
const
|
|
2367
|
+
const zt = "0.3.0";
|
|
2156
2368
|
export {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2369
|
+
st as AnimationController,
|
|
2370
|
+
we as BoundingBox,
|
|
2371
|
+
kt as PlyLoader,
|
|
2372
|
+
Bt as SogsLoader,
|
|
2373
|
+
Ae as SplatData,
|
|
2374
|
+
rt as SplatMaterial,
|
|
2375
|
+
Re as SplatMesh,
|
|
2376
|
+
Qe as SplatSorter,
|
|
2377
|
+
nt as TextureManager,
|
|
2378
|
+
zt as VERSION,
|
|
2379
|
+
Le as getEffect
|
|
2166
2380
|
};
|