@speridlabs/visus 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.es.js +1074 -929
- package/dist/main.umd.js +6 -6
- package/dist/react.es.js +1212 -1067
- 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 Nt = Object.defineProperty;
|
|
2
|
+
var $t = (a, t, e) => t in a ? Nt(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
+
var x = (a, t, e) => $t(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import * as l from "three";
|
|
5
|
+
class wt {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
x(this, "min", new l.Vector3(1 / 0, 1 / 0, 1 / 0));
|
|
8
|
+
x(this, "max", new l.Vector3(-1 / 0, -1 / 0, -1 / 0));
|
|
9
|
+
x(this, "center", new l.Vector3());
|
|
10
10
|
/** Half extents (size/2) */
|
|
11
|
-
|
|
11
|
+
x(this, "halfExtents", new l.Vector3());
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Reset the bounding box to its initial state
|
|
@@ -20,15 +20,15 @@ class ye {
|
|
|
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(t) {
|
|
24
|
+
this.min.x = Math.min(this.min.x, t.x), this.min.y = Math.min(this.min.y, t.y), this.min.z = Math.min(this.min.z, t.z), this.max.x = Math.max(this.max.x, t.x), this.max.y = Math.max(this.max.y, t.y), this.max.z = Math.max(this.max.z, t.z), this.updateDerived();
|
|
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(t) {
|
|
31
|
+
this.min.x = Math.min(this.min.x, t.min.x), this.min.y = Math.min(this.min.y, t.min.y), this.min.z = Math.min(this.min.z, t.min.z), this.max.x = Math.max(this.max.x, t.max.x), this.max.y = Math.max(this.max.y, t.max.y), this.max.z = Math.max(this.max.z, t.max.z), this.updateDerived();
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Update the center and half extents based on min/max
|
|
@@ -41,38 +41,38 @@ class ye {
|
|
|
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(t) {
|
|
45
|
+
return t.x >= this.min.x && t.x <= this.max.x && t.y >= this.min.y && t.y <= this.max.y && t.z >= this.min.z && t.z <= this.max.z;
|
|
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 l.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 t = new wt();
|
|
60
|
+
return t.min.copy(this.min), t.max.copy(this.max), t.center.copy(this.center), t.halfExtents.copy(this.halfExtents), t;
|
|
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 jt {
|
|
64
|
+
constructor(t = 0) {
|
|
65
|
+
x(this, "numSplats", 0);
|
|
66
|
+
x(this, "positions");
|
|
67
|
+
x(this, "rotations");
|
|
68
|
+
x(this, "scales");
|
|
69
|
+
x(this, "colors");
|
|
70
|
+
x(this, "opacities");
|
|
71
|
+
x(this, "boundingBox", new wt());
|
|
72
|
+
this.numSplats = t, this.allocateBuffers(t);
|
|
73
|
+
}
|
|
74
|
+
allocateBuffers(t) {
|
|
75
|
+
this.positions = new Float32Array(t * 3), this.rotations = new Float32Array(t * 4), this.scales = new Float32Array(t * 3), this.colors = new Float32Array(t * 3), this.opacities = new Float32Array(t);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Set data for a specific splat
|
|
@@ -83,49 +83,49 @@ class Oe {
|
|
|
83
83
|
* @param color Color
|
|
84
84
|
* @param opacity Opacity value
|
|
85
85
|
*/
|
|
86
|
-
setSplat(
|
|
87
|
-
if (
|
|
86
|
+
setSplat(t, e, s, n, r, o) {
|
|
87
|
+
if (t >= this.numSplats)
|
|
88
88
|
throw new Error(
|
|
89
|
-
`Splat index out of bounds: ${
|
|
89
|
+
`Splat index out of bounds: ${t} >= ${this.numSplats}`
|
|
90
90
|
);
|
|
91
|
-
const i =
|
|
92
|
-
this.positions[i] =
|
|
91
|
+
const i = t * 3, u = t * 4, y = t * 3, m = t * 3;
|
|
92
|
+
this.positions[i] = e.x, this.positions[i + 1] = e.y, this.positions[i + 2] = e.z, this.rotations[u] = s.x, this.rotations[u + 1] = s.y, this.rotations[u + 2] = s.z, this.rotations[u + 3] = s.w, this.scales[y] = n.x, this.scales[y + 1] = n.y, this.scales[y + 2] = n.z, this.colors[m] = r.r, this.colors[m + 1] = r.g, this.colors[m + 2] = r.b, this.opacities[t] = o;
|
|
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(t) {
|
|
100
|
+
if (t >= this.numSplats)
|
|
101
101
|
throw new Error(
|
|
102
|
-
`Splat index out of bounds: ${
|
|
102
|
+
`Splat index out of bounds: ${t} >= ${this.numSplats}`
|
|
103
103
|
);
|
|
104
|
-
const
|
|
104
|
+
const e = t * 3, s = t * 4, n = t * 3, r = t * 3;
|
|
105
105
|
return {
|
|
106
|
-
position: new
|
|
107
|
-
this.positions[
|
|
108
|
-
this.positions[
|
|
109
|
-
this.positions[
|
|
106
|
+
position: new l.Vector3(
|
|
107
|
+
this.positions[e],
|
|
108
|
+
this.positions[e + 1],
|
|
109
|
+
this.positions[e + 2]
|
|
110
110
|
),
|
|
111
|
-
rotation: new
|
|
111
|
+
rotation: new l.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
|
|
119
|
-
Math.exp(this.scales[
|
|
120
|
-
Math.exp(this.scales[
|
|
121
|
-
Math.exp(this.scales[
|
|
118
|
+
scale: new l.Vector3(
|
|
119
|
+
Math.exp(this.scales[n]),
|
|
120
|
+
Math.exp(this.scales[n + 1]),
|
|
121
|
+
Math.exp(this.scales[n + 2])
|
|
122
122
|
),
|
|
123
|
-
color: new
|
|
124
|
-
this.colors[
|
|
125
|
-
this.colors[
|
|
126
|
-
this.colors[
|
|
123
|
+
color: new l.Color(
|
|
124
|
+
this.colors[r],
|
|
125
|
+
this.colors[r + 1],
|
|
126
|
+
this.colors[r + 2]
|
|
127
127
|
),
|
|
128
|
-
opacity: this.opacities[
|
|
128
|
+
opacity: this.opacities[t]
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
@@ -134,14 +134,14 @@ class Oe {
|
|
|
134
134
|
*/
|
|
135
135
|
calculateBoundingBox() {
|
|
136
136
|
this.boundingBox.reset();
|
|
137
|
-
const
|
|
138
|
-
for (let
|
|
139
|
-
const s =
|
|
140
|
-
|
|
137
|
+
const t = new l.Vector3();
|
|
138
|
+
for (let e = 0; e < this.numSplats; e++) {
|
|
139
|
+
const s = e * 3;
|
|
140
|
+
t.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(t);
|
|
145
145
|
}
|
|
146
146
|
return this.boundingBox;
|
|
147
147
|
}
|
|
@@ -150,97 +150,134 @@ class Oe {
|
|
|
150
150
|
* This is for visualization/debugging purposes only, not for rendering
|
|
151
151
|
*/
|
|
152
152
|
createDebugGeometry() {
|
|
153
|
-
const
|
|
154
|
-
|
|
153
|
+
const t = new l.BufferGeometry();
|
|
154
|
+
t.setAttribute(
|
|
155
155
|
"position",
|
|
156
|
-
new
|
|
156
|
+
new l.BufferAttribute(this.positions, 3)
|
|
157
157
|
);
|
|
158
|
-
const
|
|
159
|
-
for (let
|
|
160
|
-
const o =
|
|
158
|
+
const e = new Float32Array(this.numSplats * 3), s = new l.Quaternion(), n = new l.Euler();
|
|
159
|
+
for (let r = 0; r < this.numSplats; r++) {
|
|
160
|
+
const o = r * 4, i = r * 3;
|
|
161
161
|
s.set(
|
|
162
162
|
this.rotations[o],
|
|
163
163
|
this.rotations[o + 1],
|
|
164
164
|
this.rotations[o + 2],
|
|
165
165
|
this.rotations[o + 3]
|
|
166
|
-
),
|
|
166
|
+
), n.setFromQuaternion(s), e[i] = n.x, e[i + 1] = n.y, e[i + 2] = n.z;
|
|
167
167
|
}
|
|
168
|
-
return
|
|
168
|
+
return t.setAttribute(
|
|
169
169
|
"rotation",
|
|
170
|
-
new
|
|
171
|
-
),
|
|
170
|
+
new l.BufferAttribute(e, 3)
|
|
171
|
+
), t.setAttribute(
|
|
172
172
|
"scale",
|
|
173
|
-
new
|
|
174
|
-
),
|
|
173
|
+
new l.BufferAttribute(this.scales, 3)
|
|
174
|
+
), t.setAttribute(
|
|
175
175
|
"color",
|
|
176
|
-
new
|
|
177
|
-
),
|
|
176
|
+
new l.BufferAttribute(this.colors, 3)
|
|
177
|
+
), t.setAttribute(
|
|
178
178
|
"opacity",
|
|
179
|
-
new
|
|
180
|
-
),
|
|
179
|
+
new l.BufferAttribute(this.opacities, 1)
|
|
180
|
+
), t;
|
|
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 Ft {
|
|
187
187
|
// Upper 8 bits of 16-bit means
|
|
188
|
-
constructor(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
constructor(t, e, s) {
|
|
189
|
+
x(this, "ranges");
|
|
190
|
+
x(this, "version", 1);
|
|
191
|
+
x(this, "numSplats", 0);
|
|
192
|
+
x(this, "boundingBox", new wt());
|
|
192
193
|
// Original SOGS textures
|
|
193
|
-
|
|
194
|
+
x(this, "sh0");
|
|
194
195
|
// SH DC coefficients + alpha
|
|
195
|
-
|
|
196
|
+
x(this, "quats");
|
|
196
197
|
// Quaternion components + mode
|
|
197
|
-
|
|
198
|
+
x(this, "scales");
|
|
198
199
|
// Scale values (8-bit)
|
|
199
|
-
|
|
200
|
+
x(this, "means_l");
|
|
200
201
|
// Lower 8 bits of 16-bit means
|
|
201
|
-
|
|
202
|
-
this.ranges =
|
|
202
|
+
x(this, "means_u");
|
|
203
|
+
this.ranges = e, this.numSplats = t, 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();
|
|
203
204
|
}
|
|
204
205
|
calculateBoundingBox() {
|
|
205
206
|
this.boundingBox.reset();
|
|
206
|
-
const { mins:
|
|
207
|
+
const { mins: t, maxs: e } = this.ranges.means, s = (n) => Math.sign(n) * (Math.exp(Math.abs(n)) - 1);
|
|
207
208
|
return this.boundingBox.center.set(
|
|
208
|
-
(s(
|
|
209
|
-
(s(
|
|
210
|
-
(s(
|
|
209
|
+
(s(t[0]) + s(e[0])) * 0.5,
|
|
210
|
+
(s(t[1]) + s(e[1])) * 0.5,
|
|
211
|
+
(s(t[2]) + s(e[2])) * 0.5
|
|
211
212
|
), this.boundingBox.halfExtents.set(
|
|
212
|
-
(s(
|
|
213
|
-
(s(
|
|
214
|
-
(s(
|
|
213
|
+
(s(e[0]) - s(t[0])) * 0.5,
|
|
214
|
+
(s(e[1]) - s(t[1])) * 0.5,
|
|
215
|
+
(s(e[2]) - s(t[2])) * 0.5
|
|
215
216
|
), this.boundingBox;
|
|
216
217
|
}
|
|
217
218
|
dispose() {
|
|
218
219
|
this.sh0.dispose(), this.quats.dispose(), this.scales.dispose(), this.means_l.dispose(), this.means_u.dispose();
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
|
-
class
|
|
222
|
+
class Pt {
|
|
223
|
+
// Upper 8 bits of 16-bit means
|
|
224
|
+
constructor(t, e, s) {
|
|
225
|
+
x(this, "ranges");
|
|
226
|
+
x(this, "version", 2);
|
|
227
|
+
x(this, "numSplats", 0);
|
|
228
|
+
x(this, "boundingBox", new wt());
|
|
229
|
+
// Original SOGS textures
|
|
230
|
+
x(this, "sh0");
|
|
231
|
+
// SH DC coefficients + alpha
|
|
232
|
+
x(this, "quats");
|
|
233
|
+
// Quaternion components + mode
|
|
234
|
+
x(this, "scales");
|
|
235
|
+
// Scale values (8-bit)
|
|
236
|
+
x(this, "means_l");
|
|
237
|
+
// Lower 8 bits of 16-bit means
|
|
238
|
+
x(this, "means_u");
|
|
239
|
+
this.ranges = e, this.numSplats = t, 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
|
+
}
|
|
241
|
+
calculateBoundingBox() {
|
|
242
|
+
this.boundingBox.reset();
|
|
243
|
+
const { mins: t, maxs: e } = this.ranges.means, s = (n) => Math.sign(n) * (Math.exp(Math.abs(n)) - 1);
|
|
244
|
+
return this.boundingBox.center.set(
|
|
245
|
+
(s(t[0]) + s(e[0])) * 0.5,
|
|
246
|
+
(s(t[1]) + s(e[1])) * 0.5,
|
|
247
|
+
(s(t[2]) + s(e[2])) * 0.5
|
|
248
|
+
), this.boundingBox.halfExtents.set(
|
|
249
|
+
(s(e[0]) - s(t[0])) * 0.5,
|
|
250
|
+
(s(e[1]) - s(t[1])) * 0.5,
|
|
251
|
+
(s(e[2]) - s(t[2])) * 0.5
|
|
252
|
+
), this.boundingBox;
|
|
253
|
+
}
|
|
254
|
+
dispose() {
|
|
255
|
+
this.sh0.dispose(), this.quats.dispose(), this.scales.dispose(), this.means_l.dispose(), this.means_u.dispose();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
class At {
|
|
222
259
|
// RGBA32UI - (Position + Rotation + Scale)
|
|
223
260
|
// RGBA32UI Texture Content:
|
|
224
261
|
// .r = Means Lower (RGB)
|
|
225
262
|
// .g = Means Upper (RGB)
|
|
226
263
|
// .b = Rotation (RGBA)
|
|
227
264
|
// .a = Scale (RGB)
|
|
228
|
-
constructor(
|
|
265
|
+
constructor(t, e, s, n, r, o, i, u) {
|
|
229
266
|
// Info data - cpu
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
267
|
+
x(this, "numSplats");
|
|
268
|
+
x(this, "textureWidth");
|
|
269
|
+
x(this, "textureHeight");
|
|
270
|
+
x(this, "ranges");
|
|
271
|
+
x(this, "centers");
|
|
235
272
|
// TODO: see if necesary or can be compressed somehow
|
|
236
|
-
|
|
273
|
+
x(this, "boundingBox");
|
|
237
274
|
// GPU Textures
|
|
238
|
-
|
|
275
|
+
x(this, "packedColor");
|
|
239
276
|
// RGBA8 - (Color + Opacity)
|
|
240
277
|
// RGBA8 Texture Content:
|
|
241
278
|
// .rgb = Color, .a = Opacity
|
|
242
|
-
|
|
243
|
-
this.numSplats =
|
|
279
|
+
x(this, "packedGeometry");
|
|
280
|
+
this.numSplats = t, this.textureWidth = e, this.textureHeight = s, this.boundingBox = u, this.ranges = i, this.centers = n, this.packedColor = o, this.packedGeometry = r;
|
|
244
281
|
}
|
|
245
282
|
/**
|
|
246
283
|
* Optional: Reconstruct a full JS object for a specific splat.
|
|
@@ -255,34 +292,34 @@ class Be {
|
|
|
255
292
|
// public abstract deserialize(): ISplat;
|
|
256
293
|
// public abstract returnPacked(): ISplat;
|
|
257
294
|
}
|
|
258
|
-
class
|
|
295
|
+
class Yt extends l.EventDispatcher {
|
|
259
296
|
constructor() {
|
|
260
297
|
super();
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
298
|
+
x(this, "worker");
|
|
299
|
+
x(this, "centers", null);
|
|
300
|
+
x(this, "orderTexture", null);
|
|
264
301
|
/** Bounding box data for optimization */
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const
|
|
302
|
+
x(this, "chunks", null);
|
|
303
|
+
x(this, "lastCameraPosition", new l.Vector3());
|
|
304
|
+
x(this, "lastCameraDirection", new l.Vector3());
|
|
305
|
+
const e = this.createWorkerCode(), s = new Blob([e], { type: "application/javascript" });
|
|
269
306
|
this.worker = new Worker(URL.createObjectURL(s)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
270
307
|
}
|
|
271
308
|
/**
|
|
272
309
|
* Handles messages received from the sorting worker.
|
|
273
310
|
* @param event The message event from the worker.
|
|
274
311
|
*/
|
|
275
|
-
onWorkerMessage(
|
|
312
|
+
onWorkerMessage(e) {
|
|
276
313
|
if (!this.orderTexture || !this.orderTexture.image)
|
|
277
314
|
return console.error("SplatSorter: Order texture not initialized!");
|
|
278
|
-
const { order: s, count:
|
|
279
|
-
if (!(
|
|
315
|
+
const { order: s, count: n } = e.data, r = this.orderTexture.image.data;
|
|
316
|
+
if (!(r instanceof Uint32Array))
|
|
280
317
|
return console.error(
|
|
281
318
|
"SplatSorter: Order texture data is not a Uint32Array!"
|
|
282
319
|
);
|
|
283
|
-
|
|
284
|
-
const o =
|
|
285
|
-
this.worker.postMessage(i, [o]), this.dispatchEvent({ type: "updated", count:
|
|
320
|
+
r.set(new Uint32Array(s)), this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
|
|
321
|
+
const o = r.buffer.slice(0), i = { order: o };
|
|
322
|
+
this.worker.postMessage(i, [o]), this.dispatchEvent({ type: "updated", count: n });
|
|
286
323
|
}
|
|
287
324
|
/**
|
|
288
325
|
* Initializes the sorter with necessary data and textures.
|
|
@@ -291,35 +328,35 @@ class Le extends h.EventDispatcher {
|
|
|
291
328
|
* @param chunks Optional: A Float32Array containing bounding box chunk data [minX, minY, minZ, maxX, maxY, maxZ, ...] for optimization.
|
|
292
329
|
* @param transferOwnership Optional: If true, transfers ownership of centers buffer to worker (saves memory, main thread loses access). Default: false.
|
|
293
330
|
*/
|
|
294
|
-
init(
|
|
295
|
-
if (!
|
|
331
|
+
init(e, s, n, r = !1) {
|
|
332
|
+
if (!e || !(e.image.data instanceof Uint32Array))
|
|
296
333
|
throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");
|
|
297
334
|
if (!s || s.length % 3 !== 0)
|
|
298
335
|
throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");
|
|
299
|
-
if (
|
|
336
|
+
if (e.image.data.length < s.length / 3)
|
|
300
337
|
throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");
|
|
301
338
|
if (s.buffer.byteLength === 0)
|
|
302
339
|
throw new Error(
|
|
303
340
|
"SplatSorter: positions buffer is detached (likely React StrictMode + cached asset). "
|
|
304
341
|
);
|
|
305
342
|
const o = s.length / 3;
|
|
306
|
-
this.orderTexture =
|
|
343
|
+
this.orderTexture = e, r ? this.centers = null : this.centers = s.slice();
|
|
307
344
|
const i = this.orderTexture.image.data;
|
|
308
|
-
for (let
|
|
345
|
+
for (let h = 0; h < o; h++) i[h] = h;
|
|
309
346
|
this.orderTexture.source.data.updateRanges || (this.orderTexture.source.data.updateRanges = []), this.orderTexture.needsUpdate = !0;
|
|
310
|
-
const u = i.buffer.slice(0),
|
|
347
|
+
const u = i.buffer.slice(0), y = r ? s.buffer : s.buffer.slice(0), m = {
|
|
311
348
|
order: u,
|
|
312
|
-
centers:
|
|
349
|
+
centers: y
|
|
313
350
|
}, c = [
|
|
314
351
|
u,
|
|
315
|
-
|
|
352
|
+
y
|
|
316
353
|
];
|
|
317
|
-
if (
|
|
318
|
-
this.chunks =
|
|
319
|
-
const
|
|
320
|
-
|
|
354
|
+
if (n) {
|
|
355
|
+
this.chunks = n.slice();
|
|
356
|
+
const h = this.chunks.buffer.slice(0);
|
|
357
|
+
m.chunks = h, c.push(h);
|
|
321
358
|
}
|
|
322
|
-
this.worker.postMessage(
|
|
359
|
+
this.worker.postMessage(m, c), queueMicrotask(() => {
|
|
323
360
|
this.dispatchEvent({
|
|
324
361
|
type: "updated",
|
|
325
362
|
count: o
|
|
@@ -331,50 +368,50 @@ class Le extends h.EventDispatcher {
|
|
|
331
368
|
* The sorter will only consider splats whose original indices are present in the mapping.
|
|
332
369
|
* @param mapping A Uint32Array where each element is the *original* index of a splat to include, or null to reset mapping.
|
|
333
370
|
*/
|
|
334
|
-
setMapping(
|
|
371
|
+
setMapping(e) {
|
|
335
372
|
if (!this.centers)
|
|
336
373
|
return console.warn(
|
|
337
374
|
"SplatSorter: Cannot set mapping before initialization."
|
|
338
375
|
);
|
|
339
376
|
let s;
|
|
340
|
-
const
|
|
341
|
-
if (!
|
|
377
|
+
const n = [];
|
|
378
|
+
if (!e) {
|
|
342
379
|
const u = this.centers.buffer.slice(0);
|
|
343
380
|
return s = {
|
|
344
381
|
centers: u,
|
|
345
382
|
mapping: null
|
|
346
|
-
},
|
|
383
|
+
}, n.push(u), this.worker.postMessage(s, n);
|
|
347
384
|
}
|
|
348
|
-
const
|
|
349
|
-
for (let u = 0; u <
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
385
|
+
const r = new Float32Array(e.length * 3);
|
|
386
|
+
for (let u = 0; u < e.length; u++) {
|
|
387
|
+
const y = e[u];
|
|
388
|
+
if (y * 3 + 2 >= this.centers.length) {
|
|
352
389
|
console.warn(
|
|
353
|
-
`SplatSorter: Mapping index ${
|
|
390
|
+
`SplatSorter: Mapping index ${y} out of bounds.`
|
|
354
391
|
);
|
|
355
392
|
continue;
|
|
356
393
|
}
|
|
357
|
-
const
|
|
358
|
-
|
|
394
|
+
const m = y * 3, c = u * 3;
|
|
395
|
+
r[c + 0] = this.centers[m + 0], r[c + 1] = this.centers[m + 1], r[c + 2] = this.centers[m + 2];
|
|
359
396
|
}
|
|
360
|
-
const o =
|
|
397
|
+
const o = r.buffer.slice(0), i = e.buffer.slice(0);
|
|
361
398
|
s = {
|
|
362
399
|
centers: o,
|
|
363
400
|
mapping: i
|
|
364
|
-
},
|
|
401
|
+
}, n.push(o, i), this.worker.postMessage(s, n);
|
|
365
402
|
}
|
|
366
403
|
/**
|
|
367
404
|
* Updates the camera parameters used for sorting.
|
|
368
405
|
* @param position The camera's position in the sorter's local coordinate space.
|
|
369
406
|
* @param direction The camera's forward direction in the sorter's local coordinate space.
|
|
370
407
|
*/
|
|
371
|
-
setCamera(
|
|
372
|
-
const
|
|
373
|
-
if (!
|
|
408
|
+
setCamera(e, s) {
|
|
409
|
+
const n = this.lastCameraPosition.distanceToSquared(e) > 1e-7, r = this.lastCameraDirection.dot(s) < 0.9999;
|
|
410
|
+
if (!n && !r)
|
|
374
411
|
return;
|
|
375
|
-
this.lastCameraPosition.copy(
|
|
412
|
+
this.lastCameraPosition.copy(e), this.lastCameraDirection.copy(s);
|
|
376
413
|
const o = {
|
|
377
|
-
cameraPosition: { x:
|
|
414
|
+
cameraPosition: { x: e.x, y: e.y, z: e.z },
|
|
378
415
|
cameraDirection: { x: s.x, y: s.y, z: s.z }
|
|
379
416
|
};
|
|
380
417
|
this.worker.postMessage(o);
|
|
@@ -391,186 +428,186 @@ class Le extends h.EventDispatcher {
|
|
|
391
428
|
*/
|
|
392
429
|
createWorkerCode() {
|
|
393
430
|
return `(${(function() {
|
|
394
|
-
let s = null,
|
|
395
|
-
const
|
|
396
|
-
let
|
|
397
|
-
const
|
|
398
|
-
for (;
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
401
|
-
else if (
|
|
402
|
-
else return
|
|
431
|
+
let s = null, n = null, r = null, o = null, i = null, u = null, y = !1;
|
|
432
|
+
const m = { x: 0, y: 0, z: 0 }, c = { x: 0, y: 0, z: 0 }, h = { x: 0, y: 0, z: 0 }, d = { x: 0, y: 0, z: 0 };
|
|
433
|
+
let w = null, A = null;
|
|
434
|
+
const b = 32, z = new Array(b).fill(0), _ = new Array(b).fill(0), F = new Array(b).fill(0), O = (k, M, B) => {
|
|
435
|
+
for (; k <= M; ) {
|
|
436
|
+
const S = M + k >> 1, g = B(S);
|
|
437
|
+
if (g > 0) k = S + 1;
|
|
438
|
+
else if (g < 0) M = S - 1;
|
|
439
|
+
else return S;
|
|
403
440
|
}
|
|
404
|
-
return ~
|
|
405
|
-
},
|
|
406
|
-
if (!s || !
|
|
441
|
+
return ~k;
|
|
442
|
+
}, V = () => {
|
|
443
|
+
if (!s || !n || !i || !u)
|
|
407
444
|
return;
|
|
408
|
-
if (
|
|
409
|
-
const
|
|
445
|
+
if (n.length === 0) {
|
|
446
|
+
const p = {
|
|
410
447
|
order: s.buffer,
|
|
411
448
|
count: 0
|
|
412
449
|
};
|
|
413
|
-
self.postMessage(
|
|
450
|
+
self.postMessage(p, [s.buffer]), s = null;
|
|
414
451
|
return;
|
|
415
452
|
}
|
|
416
|
-
const
|
|
417
|
-
if (!
|
|
453
|
+
const k = i.x, M = i.y, B = i.z, S = u.x, g = u.y, v = u.z, T = 1e-4, U = Math.abs(k - m.x) > T || Math.abs(M - m.y) > T || Math.abs(B - m.z) > T, I = Math.abs(S - c.x) > T || Math.abs(g - c.y) > T || Math.abs(v - c.z) > T;
|
|
454
|
+
if (!y && !U && !I)
|
|
418
455
|
return;
|
|
419
|
-
|
|
420
|
-
let
|
|
421
|
-
for (let
|
|
422
|
-
const
|
|
423
|
-
|
|
456
|
+
y = !1, m.x = k, m.y = M, m.z = B, c.x = S, c.y = g, c.z = v;
|
|
457
|
+
let P = 1 / 0, f = -1 / 0;
|
|
458
|
+
for (let p = 0; p < 8; ++p) {
|
|
459
|
+
const q = p & 1 ? h.x : d.x, L = p & 2 ? h.y : d.y, E = p & 4 ? h.z : d.z, G = q * S + L * g + E * v;
|
|
460
|
+
P = Math.min(P, G), f = Math.max(f, G);
|
|
424
461
|
}
|
|
425
|
-
const
|
|
462
|
+
const C = n.length / 3, Y = f - P, R = (1 << Math.max(
|
|
426
463
|
10,
|
|
427
|
-
Math.min(20, Math.ceil(Math.log2(
|
|
464
|
+
Math.min(20, Math.ceil(Math.log2(C / 4)))
|
|
428
465
|
)) + 1;
|
|
429
|
-
if ((!
|
|
430
|
-
for (let
|
|
431
|
-
|
|
432
|
-
} else if (
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
for (let
|
|
436
|
-
const
|
|
466
|
+
if ((!w || w.length !== C) && (w = new Uint32Array(C)), !A || A.length !== R ? A = new Uint32Array(R) : A.fill(0), Y < 1e-7) {
|
|
467
|
+
for (let p = 0; p < C; ++p) w[p] = 0;
|
|
468
|
+
A[0] = C;
|
|
469
|
+
} else if (r && r.length > 0) {
|
|
470
|
+
const p = r.length / 6;
|
|
471
|
+
z.fill(0);
|
|
472
|
+
for (let E = 0; E < p; ++E) {
|
|
473
|
+
const G = E * 6, X = r[G + 0], j = r[G + 1], Q = r[G + 2], $ = r[G + 3], K = X * S + j * g + Q * v - P, tt = K - $, et = K + $, mt = Math.max(
|
|
437
474
|
0,
|
|
438
|
-
Math.floor(
|
|
439
|
-
),
|
|
440
|
-
|
|
441
|
-
Math.ceil(
|
|
475
|
+
Math.floor(tt * b / Y)
|
|
476
|
+
), dt = Math.min(
|
|
477
|
+
b,
|
|
478
|
+
Math.ceil(et * b / Y)
|
|
442
479
|
);
|
|
443
|
-
for (let
|
|
444
|
-
|
|
480
|
+
for (let ot = mt; ot < dt; ++ot)
|
|
481
|
+
z[ot]++;
|
|
445
482
|
}
|
|
446
|
-
let
|
|
447
|
-
for (let
|
|
448
|
-
|
|
449
|
-
for (let
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
for (let
|
|
454
|
-
const
|
|
483
|
+
let q = 0;
|
|
484
|
+
for (let E = 0; E < b; ++E) q += z[E];
|
|
485
|
+
F[0] = 0, _[0] = 0;
|
|
486
|
+
for (let E = 1; E < b; ++E)
|
|
487
|
+
F[E - 1] = z[E - 1] / q * R >>> 0, _[E] = _[E - 1] + F[E - 1];
|
|
488
|
+
F[b - 1] = z[b - 1] / q * R >>> 0;
|
|
489
|
+
const L = Y / b;
|
|
490
|
+
for (let E = 0; E < C; ++E) {
|
|
491
|
+
const G = E * 3, X = n[G + 0], j = n[G + 1], Q = n[G + 2], $ = X * S + j * g + Q * v, tt = (f - $) / L, et = Math.max(
|
|
455
492
|
0,
|
|
456
493
|
Math.min(
|
|
457
|
-
|
|
458
|
-
Math.floor(
|
|
494
|
+
b - 1,
|
|
495
|
+
Math.floor(tt)
|
|
459
496
|
)
|
|
460
|
-
),
|
|
461
|
-
|
|
497
|
+
), mt = tt - et, dt = _[et] + F[et] * mt >>> 0, ot = Math.min(dt, R - 1);
|
|
498
|
+
w[E] = ot, A[ot]++;
|
|
462
499
|
}
|
|
463
500
|
} else {
|
|
464
|
-
const
|
|
465
|
-
for (let
|
|
466
|
-
const
|
|
467
|
-
|
|
501
|
+
const p = (R - 1) / Y;
|
|
502
|
+
for (let q = 0; q < C; ++q) {
|
|
503
|
+
const L = q * 3, E = n[L + 0], G = n[L + 1], X = n[L + 2], j = E * S + G * g + X * v, $ = (f - j) * p >>> 0, K = Math.min($, R - 1);
|
|
504
|
+
w[q] = K, A[K]++;
|
|
468
505
|
}
|
|
469
506
|
}
|
|
470
|
-
for (let
|
|
471
|
-
|
|
472
|
-
for (let
|
|
473
|
-
const
|
|
474
|
-
s[
|
|
507
|
+
for (let p = 1; p < R; p++)
|
|
508
|
+
A[p] += A[p - 1];
|
|
509
|
+
for (let p = C - 1; p >= 0; p--) {
|
|
510
|
+
const q = w[p], L = --A[q];
|
|
511
|
+
s[L] = o ? o[p] : p;
|
|
475
512
|
}
|
|
476
|
-
const
|
|
513
|
+
const J = k * S + M * g + B * v, Z = (p) => {
|
|
477
514
|
if (!s) return -1 / 0;
|
|
478
|
-
const
|
|
479
|
-
if (!
|
|
515
|
+
const q = s[p], L = q;
|
|
516
|
+
if (!n || L * 3 + 2 >= n.length)
|
|
480
517
|
return -1 / 0;
|
|
481
|
-
const
|
|
482
|
-
return
|
|
518
|
+
const E = L * 3;
|
|
519
|
+
return n[E] * S + n[E + 1] * g + n[E + 2] * v - J;
|
|
483
520
|
};
|
|
484
|
-
let H =
|
|
485
|
-
if (
|
|
486
|
-
const
|
|
521
|
+
let H = C;
|
|
522
|
+
if (C > 0 && Z(C - 1) < 0) {
|
|
523
|
+
const p = O(
|
|
487
524
|
0,
|
|
488
|
-
|
|
489
|
-
|
|
525
|
+
C - 1,
|
|
526
|
+
Z
|
|
490
527
|
);
|
|
491
|
-
H =
|
|
528
|
+
H = p < 0 ? ~p : p;
|
|
492
529
|
}
|
|
493
|
-
const
|
|
530
|
+
const D = {
|
|
494
531
|
order: s.buffer,
|
|
495
532
|
count: H
|
|
496
533
|
};
|
|
497
|
-
self.postMessage(
|
|
534
|
+
self.postMessage(D, [s.buffer]), s = null;
|
|
498
535
|
};
|
|
499
|
-
self.onmessage = (
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
let
|
|
503
|
-
if (
|
|
504
|
-
if (
|
|
505
|
-
for (let
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
(
|
|
536
|
+
self.onmessage = (k) => {
|
|
537
|
+
const M = k.data;
|
|
538
|
+
M.order && (s = new Uint32Array(M.order));
|
|
539
|
+
let B = !1;
|
|
540
|
+
if (M.centers && (n = new Float32Array(M.centers), B = !0, y = !0), Object.prototype.hasOwnProperty.call(M, "mapping") && (o = M.mapping ? new Uint32Array(M.mapping) : null, y = !0), M.chunks) {
|
|
541
|
+
if (r = new Float32Array(M.chunks), r.length > 0 && r[3] > 0)
|
|
542
|
+
for (let S = 0; S < r.length / 6; ++S) {
|
|
543
|
+
const g = S * 6, v = r[g + 0], T = r[g + 1], U = r[g + 2], I = r[g + 3], P = r[g + 4], f = r[g + 5];
|
|
544
|
+
r[g + 0] = (v + I) * 0.5, r[g + 1] = (T + P) * 0.5, r[g + 2] = (U + f) * 0.5, r[g + 3] = Math.sqrt(
|
|
545
|
+
(I - v) ** 2 + (P - T) ** 2 + (f - U) ** 2
|
|
509
546
|
) * 0.5;
|
|
510
547
|
}
|
|
511
|
-
|
|
548
|
+
y = !0;
|
|
512
549
|
}
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
for (let
|
|
516
|
-
const
|
|
517
|
-
|
|
550
|
+
if (B && n && n.length > 0) {
|
|
551
|
+
h.x = d.x = n[0], h.y = d.y = n[1], h.z = d.z = n[2];
|
|
552
|
+
for (let S = 1; S < n.length / 3; S++) {
|
|
553
|
+
const g = S * 3;
|
|
554
|
+
h.x = Math.min(h.x, n[g + 0]), d.x = Math.max(d.x, n[g + 0]), h.y = Math.min(h.y, n[g + 1]), d.y = Math.max(d.y, n[g + 1]), h.z = Math.min(h.z, n[g + 2]), d.z = Math.max(d.z, n[g + 2]);
|
|
518
555
|
}
|
|
519
|
-
} else
|
|
520
|
-
|
|
556
|
+
} else B && n && n.length === 0 && (h.x = d.x = h.y = d.y = h.z = d.z = 0);
|
|
557
|
+
M.cameraPosition && (i = M.cameraPosition), M.cameraDirection && (u = M.cameraDirection), V();
|
|
521
558
|
};
|
|
522
559
|
}).toString()})();`;
|
|
523
560
|
}
|
|
524
561
|
}
|
|
525
|
-
class
|
|
526
|
-
constructor(
|
|
527
|
-
|
|
562
|
+
class Ht {
|
|
563
|
+
constructor(t) {
|
|
564
|
+
x(this, "packedGeometry");
|
|
528
565
|
// RGBA32UI
|
|
529
|
-
|
|
566
|
+
x(this, "packedColor");
|
|
530
567
|
// RGBA8
|
|
531
|
-
|
|
568
|
+
x(this, "orderTexture");
|
|
532
569
|
// RB32UI
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
this.width =
|
|
570
|
+
x(this, "width");
|
|
571
|
+
x(this, "height");
|
|
572
|
+
this.width = t.textureWidth, this.height = t.textureHeight, this.packedColor = this.createColorTexture(t), this.packedGeometry = this.createGeometryTexture(t), this.orderTexture = this.createOrderTexture(t.numSplats);
|
|
536
573
|
}
|
|
537
|
-
createGeometryTexture(
|
|
538
|
-
const
|
|
539
|
-
|
|
574
|
+
createGeometryTexture(t) {
|
|
575
|
+
const e = new l.DataTexture(
|
|
576
|
+
t.packedGeometry,
|
|
540
577
|
this.width,
|
|
541
578
|
this.height,
|
|
542
|
-
|
|
543
|
-
|
|
579
|
+
l.RGBAIntegerFormat,
|
|
580
|
+
l.UnsignedIntType
|
|
544
581
|
);
|
|
545
|
-
return
|
|
582
|
+
return e.internalFormat = "RGBA32UI", e.minFilter = l.NearestFilter, e.magFilter = l.NearestFilter, e.needsUpdate = !0, e;
|
|
546
583
|
}
|
|
547
|
-
createColorTexture(
|
|
548
|
-
const
|
|
549
|
-
|
|
584
|
+
createColorTexture(t) {
|
|
585
|
+
const e = new l.DataTexture(
|
|
586
|
+
t.packedColor,
|
|
550
587
|
this.width,
|
|
551
588
|
this.height,
|
|
552
|
-
|
|
553
|
-
|
|
589
|
+
l.RGBAFormat,
|
|
590
|
+
l.UnsignedByteType
|
|
554
591
|
);
|
|
555
|
-
return
|
|
592
|
+
return e.minFilter = l.NearestFilter, e.magFilter = l.NearestFilter, e.needsUpdate = !0, e;
|
|
556
593
|
}
|
|
557
|
-
createOrderTexture(
|
|
558
|
-
const
|
|
559
|
-
for (let
|
|
560
|
-
const s = new
|
|
561
|
-
|
|
594
|
+
createOrderTexture(t) {
|
|
595
|
+
const e = new Uint32Array(this.width * this.height);
|
|
596
|
+
for (let n = 0; n < t; n++) e[n] = n;
|
|
597
|
+
const s = new l.DataTexture(
|
|
598
|
+
e,
|
|
562
599
|
this.width,
|
|
563
600
|
this.height,
|
|
564
|
-
|
|
565
|
-
|
|
601
|
+
l.RedIntegerFormat,
|
|
602
|
+
l.UnsignedIntType
|
|
566
603
|
);
|
|
567
|
-
return s.minFilter =
|
|
604
|
+
return s.minFilter = l.NearestFilter, s.magFilter = l.NearestFilter, s.needsUpdate = !0, s;
|
|
568
605
|
}
|
|
569
606
|
dispose() {
|
|
570
607
|
this.packedGeometry.dispose(), this.packedColor.dispose(), this.orderTexture.dispose();
|
|
571
608
|
}
|
|
572
609
|
}
|
|
573
|
-
const
|
|
610
|
+
const Zt = (
|
|
574
611
|
/* glsl */
|
|
575
612
|
`
|
|
576
613
|
precision highp float;
|
|
@@ -795,7 +832,7 @@ void main() {
|
|
|
795
832
|
vColor = vec4(max(clr.rgb, vec3(0.0)), clr.a);
|
|
796
833
|
}
|
|
797
834
|
`
|
|
798
|
-
),
|
|
835
|
+
), Xt = (
|
|
799
836
|
/* glsl */
|
|
800
837
|
`
|
|
801
838
|
precision highp float;
|
|
@@ -831,9 +868,9 @@ void main(void) {
|
|
|
831
868
|
}
|
|
832
869
|
`
|
|
833
870
|
);
|
|
834
|
-
class
|
|
835
|
-
constructor(
|
|
836
|
-
const
|
|
871
|
+
class Qt extends l.ShaderMaterial {
|
|
872
|
+
constructor(t = {}) {
|
|
873
|
+
const e = {
|
|
837
874
|
// Packed Textures
|
|
838
875
|
packedGeometry: { value: null },
|
|
839
876
|
// RGBA32UI: .r=MeansLow, .g=MeansHigh, .b=Quats, .a=Scales
|
|
@@ -842,114 +879,114 @@ class je extends h.ShaderMaterial {
|
|
|
842
879
|
splatOrder: { value: null },
|
|
843
880
|
// Index map
|
|
844
881
|
// Decompression Ranges
|
|
845
|
-
meansMin: { value: new
|
|
846
|
-
meansMax: { value: new
|
|
847
|
-
scalesMin: { value: new
|
|
848
|
-
scalesMax: { value: new
|
|
849
|
-
sh0Min: { value: new
|
|
850
|
-
sh0Max: { value: new
|
|
882
|
+
meansMin: { value: new l.Vector3() },
|
|
883
|
+
meansMax: { value: new l.Vector3() },
|
|
884
|
+
scalesMin: { value: new l.Vector3() },
|
|
885
|
+
scalesMax: { value: new l.Vector3() },
|
|
886
|
+
sh0Min: { value: new l.Vector3() },
|
|
887
|
+
sh0Max: { value: new l.Vector3() },
|
|
851
888
|
// Render State
|
|
852
889
|
texWidth: { value: 0 },
|
|
853
|
-
viewport: { value: new
|
|
890
|
+
viewport: { value: new l.Vector2(1, 1) },
|
|
854
891
|
numSplats: { value: 0 }
|
|
855
892
|
};
|
|
856
893
|
super({
|
|
857
|
-
uniforms:
|
|
858
|
-
vertexShader:
|
|
859
|
-
fragmentShader:
|
|
894
|
+
uniforms: e,
|
|
895
|
+
vertexShader: Zt,
|
|
896
|
+
fragmentShader: Xt,
|
|
860
897
|
transparent: !0,
|
|
861
|
-
glslVersion:
|
|
862
|
-
blendSrc:
|
|
863
|
-
blendSrcAlpha:
|
|
864
|
-
blending:
|
|
865
|
-
blendEquation:
|
|
866
|
-
blendEquationAlpha:
|
|
867
|
-
blendDst:
|
|
868
|
-
blendDstAlpha:
|
|
898
|
+
glslVersion: l.GLSL3,
|
|
899
|
+
blendSrc: l.OneFactor,
|
|
900
|
+
blendSrcAlpha: l.OneFactor,
|
|
901
|
+
blending: l.CustomBlending,
|
|
902
|
+
blendEquation: l.AddEquation,
|
|
903
|
+
blendEquationAlpha: l.AddEquation,
|
|
904
|
+
blendDst: l.OneMinusSrcAlphaFactor,
|
|
905
|
+
blendDstAlpha: l.OneMinusSrcAlphaFactor,
|
|
869
906
|
depthTest: !0,
|
|
870
907
|
depthWrite: !1,
|
|
871
|
-
side:
|
|
872
|
-
alphaTest:
|
|
873
|
-
toneMapped:
|
|
874
|
-
}),
|
|
908
|
+
side: l.DoubleSide,
|
|
909
|
+
alphaTest: t.alphaTest ?? 0,
|
|
910
|
+
toneMapped: t.toneMapped ?? !1
|
|
911
|
+
}), t.alphaHash && (this.alphaHash = !0, this.depthWrite = !0, this.blending = l.NoBlending);
|
|
875
912
|
}
|
|
876
|
-
setTexWidth(
|
|
877
|
-
this.uniforms.texWidth.value =
|
|
913
|
+
setTexWidth(t) {
|
|
914
|
+
this.uniforms.texWidth.value = t | 0;
|
|
878
915
|
}
|
|
879
916
|
/**
|
|
880
917
|
* Update the viewport size
|
|
881
918
|
* @param width Viewport width
|
|
882
919
|
* @param height Viewport height
|
|
883
920
|
*/
|
|
884
|
-
updateViewport(
|
|
885
|
-
this.uniforms.viewport.value.set(
|
|
921
|
+
updateViewport(t, e) {
|
|
922
|
+
this.uniforms.viewport.value.set(t, e);
|
|
886
923
|
}
|
|
887
924
|
/**
|
|
888
925
|
* Set the main packed geometry texture (RGBA32UI)
|
|
889
926
|
*/
|
|
890
|
-
setPackedGeometry(
|
|
891
|
-
this.uniforms.packedGeometry.value =
|
|
927
|
+
setPackedGeometry(t) {
|
|
928
|
+
this.uniforms.packedGeometry.value = t;
|
|
892
929
|
}
|
|
893
930
|
/**
|
|
894
931
|
* Set the packed color texture (RGBA8)
|
|
895
932
|
*/
|
|
896
|
-
setPackedColor(
|
|
897
|
-
this.uniforms.packedColor.value =
|
|
933
|
+
setPackedColor(t) {
|
|
934
|
+
this.uniforms.packedColor.value = t;
|
|
898
935
|
}
|
|
899
936
|
/**
|
|
900
937
|
* Set order texture for sorting
|
|
901
938
|
*/
|
|
902
|
-
setOrderTexture(
|
|
903
|
-
this.uniforms.splatOrder.value =
|
|
939
|
+
setOrderTexture(t) {
|
|
940
|
+
this.uniforms.splatOrder.value = t;
|
|
904
941
|
}
|
|
905
942
|
/**
|
|
906
943
|
* Set the ranges needed to decompress the packed floats
|
|
907
944
|
*/
|
|
908
|
-
setRanges(
|
|
909
|
-
this.uniforms.meansMin.value.copy(
|
|
945
|
+
setRanges(t) {
|
|
946
|
+
this.uniforms.meansMin.value.copy(t.means.min), this.uniforms.meansMax.value.copy(t.means.max), this.uniforms.scalesMin.value.copy(t.scales.min), this.uniforms.scalesMax.value.copy(t.scales.max), this.uniforms.sh0Min.value.copy(t.sh0.min), this.uniforms.sh0Max.value.copy(t.sh0.max);
|
|
910
947
|
}
|
|
911
948
|
/**
|
|
912
949
|
* Set number of splats to render
|
|
913
950
|
* @param count Number of splats
|
|
914
951
|
*/
|
|
915
|
-
setNumSplats(
|
|
916
|
-
this.uniforms.numSplats.value =
|
|
952
|
+
setNumSplats(t) {
|
|
953
|
+
this.uniforms.numSplats.value = t;
|
|
917
954
|
}
|
|
918
955
|
}
|
|
919
|
-
const
|
|
956
|
+
const xt = class xt extends l.Mesh {
|
|
920
957
|
// Match shader constant
|
|
921
958
|
/**
|
|
922
959
|
* Create a new SplatMesh for rendering Gaussian splats
|
|
923
960
|
* @param splatData The splat data to render
|
|
924
961
|
* @param options Rendering options
|
|
925
962
|
*/
|
|
926
|
-
constructor(
|
|
927
|
-
const
|
|
928
|
-
super(
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
963
|
+
constructor(e, s = {}) {
|
|
964
|
+
const n = new Qt(s), r = xt.createInstancedGeometry(e.numSplats, xt.INSTANCE_SIZE);
|
|
965
|
+
super(r, n);
|
|
966
|
+
x(this, "sorter");
|
|
967
|
+
x(this, "options");
|
|
968
|
+
x(this, "splatData");
|
|
969
|
+
x(this, "textureManager");
|
|
970
|
+
x(this, "material");
|
|
971
|
+
x(this, "geometry");
|
|
972
|
+
x(this, "lastCameraPositionLocal", new l.Vector3());
|
|
973
|
+
x(this, "lastCameraDirectionLocal", new l.Vector3());
|
|
974
|
+
x(this, "invModelMatrix", new l.Matrix4());
|
|
938
975
|
// Cached inverse matrix
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
const s =
|
|
948
|
-
this.geometry.instanceCount = Math.ceil(s /
|
|
976
|
+
x(this, "_vpW", -1);
|
|
977
|
+
x(this, "_vpH", -1);
|
|
978
|
+
x(this, "_size", new l.Vector2());
|
|
979
|
+
x(this, "_camPosW", new l.Vector3());
|
|
980
|
+
x(this, "_camDirW", new l.Vector3());
|
|
981
|
+
x(this, "_camPosL", new l.Vector3());
|
|
982
|
+
x(this, "_camDirL", new l.Vector3());
|
|
983
|
+
x(this, "onSorterUpdated", (e) => {
|
|
984
|
+
const s = e.count;
|
|
985
|
+
this.geometry.instanceCount = Math.ceil(s / xt.INSTANCE_SIZE), this.material.setNumSplats(s);
|
|
949
986
|
});
|
|
950
|
-
this.geometry =
|
|
987
|
+
this.geometry = r, this.material = n, this.options = { autoSort: !0, ...s }, this.splatData = e, this.frustumCulled = !1, this.sorter = new Yt(), this.textureManager = new Ht(e);
|
|
951
988
|
let o = this.createChunks() || void 0;
|
|
952
|
-
o === null && console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."), o = void 0, this.sorter.addEventListener("updated", this.onSorterUpdated), this.sorter.init(this.textureManager.orderTexture, this.splatData.centers, o ?? void 0, !this.options.keepSplatData), this.material.setRanges(
|
|
989
|
+
o === null && console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."), o = void 0, this.sorter.addEventListener("updated", this.onSorterUpdated), this.sorter.init(this.textureManager.orderTexture, this.splatData.centers, o ?? void 0, !this.options.keepSplatData), this.material.setRanges(e.ranges), this.material.setTexWidth(e.textureWidth), this.material.setPackedColor(this.textureManager.packedColor), this.material.setOrderTexture(this.textureManager.orderTexture), this.material.setPackedGeometry(this.textureManager.packedGeometry), this.material.setNumSplats(0), this.geometry.boundingBox = e.boundingBox.toBox3(), this.geometry.boundingSphere = new l.Sphere(), this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere), this.options.keepSplatData || (this.splatData = null);
|
|
953
990
|
}
|
|
954
991
|
/**
|
|
955
992
|
* Creates the instanced geometry for rendering splats.
|
|
@@ -957,8 +994,8 @@ const fe = class fe extends h.Mesh {
|
|
|
957
994
|
* @param instanceSize Number of splats per instance.
|
|
958
995
|
* @returns InstancedBufferGeometry
|
|
959
996
|
*/
|
|
960
|
-
static createInstancedGeometry(
|
|
961
|
-
const
|
|
997
|
+
static createInstancedGeometry(e, s) {
|
|
998
|
+
const n = Math.ceil(e / s), r = new l.BufferGeometry(), o = new Float32Array([
|
|
962
999
|
// x, y, splat_index_in_instance
|
|
963
1000
|
-1,
|
|
964
1001
|
-1,
|
|
@@ -973,23 +1010,23 @@ const fe = class fe extends h.Mesh {
|
|
|
973
1010
|
1,
|
|
974
1011
|
0
|
|
975
1012
|
]), i = new Uint16Array([0, 1, 2, 0, 2, 3]), u = new Float32Array(4 * 3 * s);
|
|
976
|
-
for (let
|
|
977
|
-
const
|
|
978
|
-
for (let
|
|
979
|
-
u[
|
|
1013
|
+
for (let h = 0; h < s; h++) {
|
|
1014
|
+
const d = h * 4 * 3;
|
|
1015
|
+
for (let w = 0; w < 4; w++)
|
|
1016
|
+
u[d + w * 3 + 0] = o[w * 3 + 0], u[d + w * 3 + 1] = o[w * 3 + 1], u[d + w * 3 + 2] = h;
|
|
980
1017
|
}
|
|
981
|
-
const
|
|
982
|
-
for (let
|
|
983
|
-
const
|
|
984
|
-
|
|
1018
|
+
const y = new Uint32Array(6 * s);
|
|
1019
|
+
for (let h = 0; h < s; h++) {
|
|
1020
|
+
const d = h * 6, w = h * 4;
|
|
1021
|
+
y[d + 0] = i[0] + w, y[d + 1] = i[1] + w, y[d + 2] = i[2] + w, y[d + 3] = i[3] + w, y[d + 4] = i[4] + w, y[d + 5] = i[5] + w;
|
|
985
1022
|
}
|
|
986
|
-
|
|
987
|
-
const
|
|
988
|
-
|
|
989
|
-
const c = new Uint32Array(
|
|
990
|
-
for (let
|
|
991
|
-
c[
|
|
992
|
-
return
|
|
1023
|
+
r.setAttribute("position", new l.BufferAttribute(u, 3)), r.setIndex(new l.BufferAttribute(y, 1));
|
|
1024
|
+
const m = new l.InstancedBufferGeometry();
|
|
1025
|
+
m.index = r.index, m.setAttribute("position", r.getAttribute("position"));
|
|
1026
|
+
const c = new Uint32Array(n);
|
|
1027
|
+
for (let h = 0; h < n; h++)
|
|
1028
|
+
c[h] = h * s;
|
|
1029
|
+
return m.setAttribute("splatInstanceIndex", new l.InstancedBufferAttribute(c, 1, !1)), m.instanceCount = 0, m;
|
|
993
1030
|
}
|
|
994
1031
|
/**
|
|
995
1032
|
* Create chunks data (bounding box min/max) for the sorter.
|
|
@@ -998,14 +1035,14 @@ const fe = class fe extends h.Mesh {
|
|
|
998
1035
|
createChunks() {
|
|
999
1036
|
if (!this.splatData)
|
|
1000
1037
|
return null;
|
|
1001
|
-
const
|
|
1002
|
-
return
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1038
|
+
const e = this.splatData.boundingBox;
|
|
1039
|
+
return e.min.x === 1 / 0 || e.max.x === -1 / 0 ? null : new Float32Array([
|
|
1040
|
+
e.min.x,
|
|
1041
|
+
e.min.y,
|
|
1042
|
+
e.min.z,
|
|
1043
|
+
e.max.x,
|
|
1044
|
+
e.max.y,
|
|
1045
|
+
e.max.z
|
|
1009
1046
|
]);
|
|
1010
1047
|
}
|
|
1011
1048
|
/**
|
|
@@ -1013,17 +1050,17 @@ const fe = class fe extends h.Mesh {
|
|
|
1013
1050
|
* @param width Viewport width
|
|
1014
1051
|
* @param height Viewport height
|
|
1015
1052
|
*/
|
|
1016
|
-
updateViewport(
|
|
1017
|
-
|
|
1053
|
+
updateViewport(e, s) {
|
|
1054
|
+
e === this._vpW && s === this._vpH || (this._vpW = e, this._vpH = s, this.material.updateViewport(e, s));
|
|
1018
1055
|
}
|
|
1019
1056
|
/**
|
|
1020
1057
|
* Sorts splats based on camera position and direction.
|
|
1021
1058
|
* @param camera The camera to sort against.
|
|
1022
1059
|
*/
|
|
1023
|
-
sort(
|
|
1024
|
-
|
|
1025
|
-
const s = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6,
|
|
1026
|
-
this.options.autoSort && (s ||
|
|
1060
|
+
sort(e) {
|
|
1061
|
+
e.getWorldPosition(this._camPosW), e.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
|
+
const s = this.lastCameraPositionLocal.distanceToSquared(this._camPosL) > 1e-6, n = this.lastCameraDirectionLocal.dot(this._camDirL) < 0.999;
|
|
1063
|
+
this.options.autoSort && (s || n) && (this.lastCameraPositionLocal.copy(this._camPosL), this.lastCameraDirectionLocal.copy(this._camDirL), this.sorter.setCamera(this._camPosL, this._camDirL));
|
|
1027
1064
|
}
|
|
1028
1065
|
/**
|
|
1029
1066
|
* THREE.js hook called before rendering the object.
|
|
@@ -1034,8 +1071,8 @@ const fe = class fe extends h.Mesh {
|
|
|
1034
1071
|
*/
|
|
1035
1072
|
// prettier-ignore
|
|
1036
1073
|
// @ts-expect-error scene is not used
|
|
1037
|
-
onBeforeRender(
|
|
1038
|
-
this.sort(
|
|
1074
|
+
onBeforeRender(e, s, n) {
|
|
1075
|
+
this.sort(n), e.getSize(this._size), this.updateViewport(this._size.x, this._size.y);
|
|
1039
1076
|
}
|
|
1040
1077
|
/**
|
|
1041
1078
|
* Dispose of resources
|
|
@@ -1045,33 +1082,33 @@ const fe = class fe extends h.Mesh {
|
|
|
1045
1082
|
}
|
|
1046
1083
|
};
|
|
1047
1084
|
/** Number of splats combined into a single instanced draw call. */
|
|
1048
|
-
|
|
1049
|
-
let
|
|
1050
|
-
const
|
|
1051
|
-
class
|
|
1085
|
+
x(xt, "INSTANCE_SIZE", 128);
|
|
1086
|
+
let Rt = xt;
|
|
1087
|
+
const ft = 0.28209479177387814;
|
|
1088
|
+
class gt {
|
|
1052
1089
|
/**
|
|
1053
1090
|
* Packs PLY data (Float32) into the Unified SOGS-like Format.
|
|
1054
1091
|
*/
|
|
1055
1092
|
// prettier-ignore
|
|
1056
|
-
static packPly(
|
|
1057
|
-
const
|
|
1058
|
-
for (let c = 0; c <
|
|
1059
|
-
const
|
|
1060
|
-
u[
|
|
1061
|
-
let
|
|
1062
|
-
const
|
|
1063
|
-
let
|
|
1064
|
-
|
|
1065
|
-
let
|
|
1066
|
-
|
|
1067
|
-
const
|
|
1068
|
-
u[
|
|
1069
|
-
const H = this.norm(
|
|
1070
|
-
u[
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1093
|
+
static packPly(t) {
|
|
1094
|
+
const e = t.numSplats, s = Math.ceil(Math.sqrt(e)), n = Math.ceil(e / s), r = s * n, { ranges: o, colorScale: i } = this.calculatePlyRanges(t), u = new Uint32Array(r * 4), y = new Uint8Array(r * 4), m = new l.Quaternion();
|
|
1095
|
+
for (let c = 0; c < e; c++) {
|
|
1096
|
+
const h = c * 4, d = c * 3, w = c * 4, A = t.positions[d + 0], b = t.positions[d + 1], z = t.positions[d + 2], _ = this.clamp01(this.norm(A, o.means.min.x, o.means.max.x)), F = this.clamp01(this.norm(b, o.means.min.y, o.means.max.y)), O = this.clamp01(this.norm(z, o.means.min.z, o.means.max.z)), V = _ * 65535 | 0, k = F * 65535 | 0, M = O * 65535 | 0;
|
|
1097
|
+
u[h + 0] = this.pack4Bytes(V & 255, k & 255, M & 255, 0), u[h + 1] = this.pack4Bytes(V >> 8, k >> 8, M >> 8, 0), m.set(t.rotations[w], t.rotations[w + 1], t.rotations[w + 2], t.rotations[w + 3]).normalize();
|
|
1098
|
+
let B = m.w, S = m.x, g = m.y, v = m.z;
|
|
1099
|
+
const T = Math.abs(B), U = Math.abs(S), I = Math.abs(g), P = Math.abs(v);
|
|
1100
|
+
let f = 0, C = T;
|
|
1101
|
+
U > C && (C = U, f = 1), I > C && (C = I, f = 2), P > C && (C = P, f = 3), (f === 0 ? B : f === 1 ? S : f === 2 ? g : v) < 0 && (B = -B, S = -S, g = -g, v = -v);
|
|
1102
|
+
let W = 0, R = 0, J = 0;
|
|
1103
|
+
f === 0 && (W = S, R = g, J = v), f === 1 && (W = B, R = g, J = v), f === 2 && (W = B, R = S, J = v), f === 3 && (W = B, R = S, J = g);
|
|
1104
|
+
const Z = (et) => Math.min(255, Math.max(0, Math.round((0.5 + et / Math.SQRT2) * 255)));
|
|
1105
|
+
u[h + 2] = this.pack4Bytes(Z(W), Z(R), Z(J), f);
|
|
1106
|
+
const H = this.norm(t.scales[d + 0], o.scales.min.x, o.scales.max.x), D = this.norm(t.scales[d + 1], o.scales.min.y, o.scales.max.y), p = this.norm(t.scales[d + 2], o.scales.min.z, o.scales.max.z);
|
|
1107
|
+
u[h + 3] = this.pack4Bytes(Math.floor(H * 255), Math.floor(D * 255), Math.floor(p * 255), 0);
|
|
1108
|
+
const q = this.clamp01(t.colors[d + 0] * i), L = this.clamp01(t.colors[d + 1] * i), E = this.clamp01(t.colors[d + 2] * i), G = (q - 0.5) / ft, X = (L - 0.5) / ft, j = (E - 0.5) / ft, Q = this.clamp01(this.norm(G, o.sh0.min.x, o.sh0.max.x)), $ = this.clamp01(this.norm(X, o.sh0.min.y, o.sh0.max.y)), K = this.clamp01(this.norm(j, o.sh0.min.z, o.sh0.max.z)), tt = this.clamp01(t.opacities[c]);
|
|
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(tt * 255);
|
|
1073
1110
|
}
|
|
1074
|
-
return new
|
|
1111
|
+
return new At(e, s, n, t.positions, u, y, o, t.boundingBox);
|
|
1075
1112
|
}
|
|
1076
1113
|
/**
|
|
1077
1114
|
* Packs SOGS data.
|
|
@@ -1079,125 +1116,201 @@ class Se {
|
|
|
1079
1116
|
* Decodes centers for sorting.
|
|
1080
1117
|
*/
|
|
1081
1118
|
// prettier-ignore
|
|
1082
|
-
static packSogs(
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1119
|
+
static packSogs(t) {
|
|
1120
|
+
var g, v, T;
|
|
1121
|
+
const e = t.numSplats;
|
|
1122
|
+
let s = Math.ceil(Math.sqrt(e)), n = Math.ceil(e / s);
|
|
1123
|
+
const r = ((g = t.means_l) == null ? void 0 : g.image) ?? ((v = t.sh0) == null ? void 0 : v.image) ?? ((T = t.quats) == null ? void 0 : T.image);
|
|
1124
|
+
r && typeof r.width == "number" && typeof r.height == "number" && (s = r.width, n = r.height);
|
|
1125
|
+
const o = s * n;
|
|
1126
|
+
if (o < e) throw new Error(`SOG v1 texture too small: ${s}x${n}=${o} < count=${e}`);
|
|
1127
|
+
const i = this.convertSogsRanges(t.ranges), u = t.ranges.means.mins[0], y = t.ranges.means.mins[1], m = t.ranges.means.mins[2], c = t.ranges.means.maxs[0], h = t.ranges.means.maxs[1], d = t.ranges.means.maxs[2], w = (U) => Math.sign(U) * (Math.exp(Math.abs(U)) - 1), A = new l.Vector3(
|
|
1128
|
+
w(u),
|
|
1129
|
+
w(y),
|
|
1130
|
+
w(m)
|
|
1131
|
+
), b = new l.Vector3(
|
|
1132
|
+
w(c),
|
|
1133
|
+
w(h),
|
|
1134
|
+
w(d)
|
|
1091
1135
|
);
|
|
1092
|
-
|
|
1093
|
-
const
|
|
1094
|
-
for (let
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1136
|
+
i.means.min.copy(A), i.means.max.copy(b);
|
|
1137
|
+
const z = t, _ = this.getPixels(z.means_l), F = this.getPixels(z.means_u), O = this.getPixels(z.quats), V = this.getPixels(z.scales), k = this.getPixels(z.sh0), M = new Uint32Array(o * 4), B = new Uint8Array(o * 4), S = new Float32Array(e * 3);
|
|
1138
|
+
for (let U = 0; U < e; U++) {
|
|
1139
|
+
const I = U * 4, P = F[I + 0], f = _[I + 0], C = F[I + 1], Y = _[I + 1], W = F[I + 2], R = _[I + 2], J = (P << 8 | f) / 65535, Z = (C << 8 | Y) / 65535, H = (W << 8 | R) / 65535, D = this.sogsDecode(J, u, c), p = this.sogsDecode(Z, y, h), q = this.sogsDecode(H, m, d);
|
|
1140
|
+
S[U * 3 + 0] = D, S[U * 3 + 1] = p, S[U * 3 + 2] = q;
|
|
1141
|
+
const L = this.clamp01(this.norm(D, A.x, b.x)) * 65535 | 0, E = this.clamp01(this.norm(p, A.y, b.y)) * 65535 | 0, G = this.clamp01(this.norm(q, A.z, b.z)) * 65535 | 0;
|
|
1142
|
+
M[I + 0] = this.pack4Bytes(L & 255, E & 255, G & 255, 0), M[I + 1] = this.pack4Bytes(L >> 8, E >> 8, G >> 8, 0), M[I + 3] = this.pack4Bytes(V[I], V[I + 1], V[I + 2], 0);
|
|
1143
|
+
const j = O[I + 3] - 252;
|
|
1144
|
+
M[I + 2] = this.pack4Bytes(O[I + 0], O[I + 1], O[I + 2], j), B[I + 0] = k[I], B[I + 1] = k[I + 1], B[I + 2] = k[I + 2];
|
|
1145
|
+
const Q = k[I + 3] / 255, $ = t.ranges.sh0.mins[3] + (t.ranges.sh0.maxs[3] - t.ranges.sh0.mins[3]) * Q, K = 1 / (1 + Math.exp(-$));
|
|
1146
|
+
B[I + 3] = Math.round(Math.max(0, Math.min(1, K)) * 255);
|
|
1147
|
+
}
|
|
1148
|
+
return new At(e, s, n, S, M, B, i, t.boundingBox);
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Packs SOG V2 data.
|
|
1152
|
+
*/
|
|
1153
|
+
static packSog2(t) {
|
|
1154
|
+
var T, U, I;
|
|
1155
|
+
const e = t.numSplats;
|
|
1156
|
+
let s = Math.ceil(Math.sqrt(e)), n = Math.ceil(e / s);
|
|
1157
|
+
const r = ((T = t.means_l) == null ? void 0 : T.image) ?? ((U = t.sh0) == null ? void 0 : U.image) ?? ((I = t.quats) == null ? void 0 : I.image);
|
|
1158
|
+
r && typeof r.width == "number" && typeof r.height == "number" && (s = r.width, n = r.height);
|
|
1159
|
+
const o = s * n;
|
|
1160
|
+
if (o < e) throw new Error(`SOG v2 texture too small: ${s}x${n}=${o} < count=${e}`);
|
|
1161
|
+
const i = t.ranges.means.mins[0], u = t.ranges.means.mins[1], y = t.ranges.means.mins[2], m = t.ranges.means.maxs[0], c = t.ranges.means.maxs[1], h = t.ranges.means.maxs[2], d = (P) => Math.sign(P) * (Math.exp(Math.abs(P)) - 1), w = new l.Vector3(
|
|
1162
|
+
d(i),
|
|
1163
|
+
d(u),
|
|
1164
|
+
d(y)
|
|
1165
|
+
), A = new l.Vector3(
|
|
1166
|
+
d(m),
|
|
1167
|
+
d(c),
|
|
1168
|
+
d(h)
|
|
1169
|
+
), b = (P) => {
|
|
1170
|
+
let f = 1 / 0, C = -1 / 0;
|
|
1171
|
+
for (const R of P)
|
|
1172
|
+
Number.isFinite(R) && (f = Math.min(f, R), C = Math.max(C, R));
|
|
1173
|
+
(!Number.isFinite(f) || !Number.isFinite(C)) && (f = 0, C = 1);
|
|
1174
|
+
const Y = C - f || 1, W = new Uint8Array(256);
|
|
1175
|
+
for (let R = 0; R < 256; R++) {
|
|
1176
|
+
const Z = ((R < P.length && Number.isFinite(P[R]) ? P[R] : f + (C - f) * (R / 255)) - f) / Y, H = Math.max(0, Math.min(255, Math.round(Z * 255)));
|
|
1177
|
+
W[R] = H;
|
|
1178
|
+
}
|
|
1179
|
+
return { cbMin: f, cbMax: C, lut: W };
|
|
1180
|
+
}, z = b(t.ranges.scales.codebook), _ = b(t.ranges.sh0.codebook), F = {
|
|
1181
|
+
means: { min: w.clone(), max: A.clone() },
|
|
1182
|
+
scales: {
|
|
1183
|
+
min: new l.Vector3(
|
|
1184
|
+
z.cbMin,
|
|
1185
|
+
z.cbMin,
|
|
1186
|
+
z.cbMin
|
|
1187
|
+
),
|
|
1188
|
+
max: new l.Vector3(
|
|
1189
|
+
z.cbMax,
|
|
1190
|
+
z.cbMax,
|
|
1191
|
+
z.cbMax
|
|
1192
|
+
)
|
|
1193
|
+
},
|
|
1194
|
+
sh0: {
|
|
1195
|
+
min: new l.Vector3(
|
|
1196
|
+
_.cbMin,
|
|
1197
|
+
_.cbMin,
|
|
1198
|
+
_.cbMin
|
|
1199
|
+
),
|
|
1200
|
+
max: new l.Vector3(
|
|
1201
|
+
_.cbMax,
|
|
1202
|
+
_.cbMax,
|
|
1203
|
+
_.cbMax
|
|
1204
|
+
)
|
|
1205
|
+
}
|
|
1206
|
+
}, O = this.getPixels(t.means_l), V = this.getPixels(t.means_u), k = this.getPixels(t.quats), M = this.getPixels(t.scales), B = this.getPixels(t.sh0), S = new Uint32Array(o * 4), g = new Uint8Array(o * 4), v = new Float32Array(e * 3);
|
|
1207
|
+
for (let P = 0; P < e; P++) {
|
|
1208
|
+
const f = P * 4, C = V[f + 0], Y = O[f + 0], W = V[f + 1], R = O[f + 1], J = V[f + 2], Z = O[f + 2], H = (C << 8 | Y) / 65535, D = (W << 8 | R) / 65535, p = (J << 8 | Z) / 65535, q = this.sogsDecode(H, i, m), L = this.sogsDecode(D, u, c), E = this.sogsDecode(p, y, h);
|
|
1209
|
+
v[P * 3 + 0] = q, v[P * 3 + 1] = L, v[P * 3 + 2] = E;
|
|
1210
|
+
const G = this.clamp01(this.norm(q, w.x, A.x)) * 65535 | 0, X = this.clamp01(this.norm(L, w.y, A.y)) * 65535 | 0, j = this.clamp01(this.norm(E, w.z, A.z)) * 65535 | 0;
|
|
1211
|
+
S[f + 0] = this.pack4Bytes(G & 255, X & 255, j & 255, 0), S[f + 1] = this.pack4Bytes(G >> 8, X >> 8, j >> 8, 0);
|
|
1212
|
+
const $ = k[f + 3] - 252 & 3;
|
|
1213
|
+
S[f + 2] = this.pack4Bytes(k[f + 0], k[f + 1], k[f + 2], $);
|
|
1214
|
+
const K = z.lut[M[f + 0]], tt = z.lut[M[f + 1]], et = z.lut[M[f + 2]];
|
|
1215
|
+
S[f + 3] = this.pack4Bytes(K, tt, et, 0), g[f + 0] = _.lut[B[f + 0]], g[f + 1] = _.lut[B[f + 1]], g[f + 2] = _.lut[B[f + 2]], g[f + 3] = B[f + 3];
|
|
1103
1216
|
}
|
|
1104
|
-
return new
|
|
1217
|
+
return new At(e, s, n, v, S, g, F, t.boundingBox);
|
|
1105
1218
|
}
|
|
1106
1219
|
// --- Helpers ---
|
|
1107
1220
|
// prettier-ignore
|
|
1108
|
-
static pack4Bytes(
|
|
1109
|
-
return (
|
|
1221
|
+
static pack4Bytes(t, e, s, n) {
|
|
1222
|
+
return (t & 255) << 24 | (e & 255) << 16 | (s & 255) << 8 | n & 255;
|
|
1110
1223
|
}
|
|
1111
1224
|
// prettier-ignore
|
|
1112
|
-
static getPixels(
|
|
1113
|
-
const
|
|
1114
|
-
if (
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1117
|
-
const o =
|
|
1225
|
+
static getPixels(t) {
|
|
1226
|
+
const e = t.image, s = e.width, n = e.height;
|
|
1227
|
+
if (e.data && (e.data instanceof Uint8Array || e.data instanceof Uint8ClampedArray)) return new Uint8Array(e.data);
|
|
1228
|
+
const r = document.createElement("canvas");
|
|
1229
|
+
r.width = s, r.height = n;
|
|
1230
|
+
const o = r.getContext("2d", { willReadFrequently: !0 });
|
|
1118
1231
|
if (!o) throw new Error("Canvas init failed");
|
|
1119
|
-
return o.drawImage(
|
|
1232
|
+
return o.drawImage(e, 0, 0), new Uint8Array(o.getImageData(0, 0, s, n).data);
|
|
1120
1233
|
}
|
|
1121
|
-
static convertSogsRanges(
|
|
1122
|
-
const
|
|
1234
|
+
static convertSogsRanges(t) {
|
|
1235
|
+
const e = (s) => new l.Vector3(s[0], s[1], s[2]);
|
|
1123
1236
|
return {
|
|
1124
|
-
sh0: { min: t
|
|
1125
|
-
means: { min: t
|
|
1126
|
-
scales: { min: t
|
|
1237
|
+
sh0: { min: e(t.sh0.mins), max: e(t.sh0.maxs) },
|
|
1238
|
+
means: { min: e(t.means.mins), max: e(t.means.maxs) },
|
|
1239
|
+
scales: { min: e(t.scales.mins), max: e(t.scales.maxs) }
|
|
1127
1240
|
};
|
|
1128
1241
|
}
|
|
1129
|
-
static calculatePlyRanges(
|
|
1130
|
-
const
|
|
1242
|
+
static calculatePlyRanges(t) {
|
|
1243
|
+
const e = new l.Vector3(1 / 0, 1 / 0, 1 / 0), s = new l.Vector3(-1 / 0, -1 / 0, -1 / 0), n = new l.Vector3(1 / 0, 1 / 0, 1 / 0), r = new l.Vector3(-1 / 0, -1 / 0, -1 / 0), o = new l.Vector3(1 / 0, 1 / 0, 1 / 0), i = new l.Vector3(-1 / 0, -1 / 0, -1 / 0);
|
|
1131
1244
|
let u = 0;
|
|
1132
|
-
for (let
|
|
1133
|
-
const c =
|
|
1134
|
-
|
|
1245
|
+
for (let m = 0; m < t.numSplats; m++) {
|
|
1246
|
+
const c = m * 3, h = t.positions[c + 0], d = t.positions[c + 1], w = t.positions[c + 2];
|
|
1247
|
+
e.x = Math.min(e.x, h), s.x = Math.max(s.x, h), e.y = Math.min(e.y, d), s.y = Math.max(s.y, d), e.z = Math.min(e.z, w), s.z = Math.max(s.z, w), n.x = Math.min(n.x, t.scales[c]), r.x = Math.max(r.x, t.scales[c]), n.y = Math.min(n.y, t.scales[c + 1]), r.y = Math.max(r.y, t.scales[c + 1]), n.z = Math.min(n.z, t.scales[c + 2]), r.z = Math.max(r.z, t.scales[c + 2]), u = Math.max(
|
|
1135
1248
|
u,
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1249
|
+
t.colors[c],
|
|
1250
|
+
t.colors[c + 1],
|
|
1251
|
+
t.colors[c + 2]
|
|
1139
1252
|
);
|
|
1140
1253
|
}
|
|
1141
|
-
const
|
|
1142
|
-
for (let
|
|
1143
|
-
const c =
|
|
1144
|
-
o.x = Math.min(o.x,
|
|
1254
|
+
const y = u > 1.5 ? 1 / 255 : 1;
|
|
1255
|
+
for (let m = 0; m < t.numSplats; m++) {
|
|
1256
|
+
const c = m * 3, h = this.clamp01(t.colors[c + 0] * y), d = this.clamp01(t.colors[c + 1] * y), w = this.clamp01(t.colors[c + 2] * y), A = (h - 0.5) / ft, b = (d - 0.5) / ft, z = (w - 0.5) / ft;
|
|
1257
|
+
o.x = Math.min(o.x, A), i.x = Math.max(i.x, A), o.y = Math.min(o.y, b), i.y = Math.max(i.y, b), o.z = Math.min(o.z, z), i.z = Math.max(i.z, z);
|
|
1145
1258
|
}
|
|
1146
1259
|
return {
|
|
1147
|
-
colorScale:
|
|
1260
|
+
colorScale: y,
|
|
1148
1261
|
ranges: {
|
|
1149
1262
|
sh0: { min: o, max: i },
|
|
1150
|
-
means: { min:
|
|
1151
|
-
scales: { min:
|
|
1263
|
+
means: { min: e, max: s },
|
|
1264
|
+
scales: { min: n, max: r }
|
|
1152
1265
|
}
|
|
1153
1266
|
};
|
|
1154
1267
|
}
|
|
1155
|
-
static clamp01(
|
|
1156
|
-
return Math.max(0, Math.min(1,
|
|
1268
|
+
static clamp01(t) {
|
|
1269
|
+
return Math.max(0, Math.min(1, t));
|
|
1157
1270
|
}
|
|
1158
1271
|
// prettier-ignore
|
|
1159
1272
|
// private static lerp(a: number, b: number, t: number) { return a + (b - a) * t; } // prettier-ignore
|
|
1160
1273
|
// private static invSogsMap(v: number) { return Math.sign(v) * Math.log(Math.abs(v) + 1) } // prettier-ignore
|
|
1161
|
-
static norm(
|
|
1162
|
-
return (
|
|
1274
|
+
static norm(t, e, s) {
|
|
1275
|
+
return (t - e) / (s - e || 1);
|
|
1163
1276
|
}
|
|
1164
1277
|
// prettier-ignore
|
|
1165
|
-
static sogsDecode(
|
|
1166
|
-
const
|
|
1167
|
-
return Math.sign(
|
|
1278
|
+
static sogsDecode(t, e, s) {
|
|
1279
|
+
const n = e + (s - e) * t;
|
|
1280
|
+
return Math.sign(n) * (Math.exp(Math.abs(n)) - 1);
|
|
1168
1281
|
}
|
|
1169
1282
|
}
|
|
1170
|
-
class
|
|
1171
|
-
constructor(
|
|
1172
|
-
super(
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1283
|
+
class ve extends l.Loader {
|
|
1284
|
+
constructor(e) {
|
|
1285
|
+
super(e);
|
|
1286
|
+
x(this, "requestId", 0);
|
|
1287
|
+
x(this, "worker");
|
|
1288
|
+
x(this, "pendingCallbacks", /* @__PURE__ */ new Map());
|
|
1176
1289
|
this.withCredentials = !0;
|
|
1177
|
-
const s = this.createWorkerCode(),
|
|
1178
|
-
this.worker = new Worker(URL.createObjectURL(
|
|
1290
|
+
const s = this.createWorkerCode(), n = new Blob([s], { type: "application/javascript" });
|
|
1291
|
+
this.worker = new Worker(URL.createObjectURL(n)), this.worker.onmessage = this.onWorkerMessage.bind(this);
|
|
1179
1292
|
}
|
|
1180
1293
|
/**
|
|
1181
1294
|
* Handles messages received from the parsing worker
|
|
1182
1295
|
* @param event The message event from the worker
|
|
1183
1296
|
*/
|
|
1184
|
-
onWorkerMessage(
|
|
1185
|
-
const { requestId: s, error:
|
|
1297
|
+
onWorkerMessage(e) {
|
|
1298
|
+
const { requestId: s, error: n, result: r } = e.data, o = this.pendingCallbacks.get(s);
|
|
1186
1299
|
if (!o) return console.warn(`PlyLoader: Received response for unknown request ${s}`);
|
|
1187
|
-
if (this.pendingCallbacks.delete(s),
|
|
1188
|
-
if (!
|
|
1300
|
+
if (this.pendingCallbacks.delete(s), n) return o.reject(new Error(n));
|
|
1301
|
+
if (!r) return o.reject(new Error("Worker returned no result"));
|
|
1189
1302
|
try {
|
|
1190
|
-
const i = new
|
|
1191
|
-
i.numSplats =
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1303
|
+
const i = new jt(0);
|
|
1304
|
+
i.numSplats = r.numSplats, i.positions = new Float32Array(r.positions), i.rotations = new Float32Array(r.rotations), i.scales = new Float32Array(r.scales), i.colors = new Float32Array(r.colors), i.opacities = new Float32Array(r.opacities), i.boundingBox.min.set(
|
|
1305
|
+
r.boundingBox.minX,
|
|
1306
|
+
r.boundingBox.minY,
|
|
1307
|
+
r.boundingBox.minZ
|
|
1195
1308
|
), i.boundingBox.max.set(
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1309
|
+
r.boundingBox.maxX,
|
|
1310
|
+
r.boundingBox.maxY,
|
|
1311
|
+
r.boundingBox.maxZ
|
|
1199
1312
|
), this.worker.terminate();
|
|
1200
|
-
const u =
|
|
1313
|
+
const u = gt.packPly(i);
|
|
1201
1314
|
i.dispose(), o.resolve(u);
|
|
1202
1315
|
} catch (i) {
|
|
1203
1316
|
o.reject(i);
|
|
@@ -1210,19 +1323,19 @@ class dt extends h.Loader {
|
|
|
1210
1323
|
* @param onProgress Optional progress callback
|
|
1211
1324
|
* @param onError Optional error callback
|
|
1212
1325
|
*/
|
|
1213
|
-
load(
|
|
1214
|
-
const o = new
|
|
1326
|
+
load(e, s, n, r) {
|
|
1327
|
+
const o = new l.FileLoader(this.manager);
|
|
1215
1328
|
o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setPath(this.path), o.setWithCredentials(this.withCredentials), o.load(
|
|
1216
|
-
|
|
1329
|
+
e,
|
|
1217
1330
|
(i) => {
|
|
1218
1331
|
this.parseAsync(i).then((u) => {
|
|
1219
1332
|
s && s(u);
|
|
1220
1333
|
}).catch((u) => {
|
|
1221
|
-
|
|
1334
|
+
r ? r(u) : console.error(u), this.manager.itemError(e);
|
|
1222
1335
|
});
|
|
1223
1336
|
},
|
|
1224
|
-
|
|
1225
|
-
|
|
1337
|
+
n,
|
|
1338
|
+
r
|
|
1226
1339
|
);
|
|
1227
1340
|
}
|
|
1228
1341
|
/**
|
|
@@ -1231,19 +1344,19 @@ class dt extends h.Loader {
|
|
|
1231
1344
|
* @param onProgress Optional progress callback
|
|
1232
1345
|
* @returns A Promise that resolves with the parsed SplatData
|
|
1233
1346
|
*/
|
|
1234
|
-
loadAsync(
|
|
1235
|
-
return new Promise((
|
|
1236
|
-
const o = new
|
|
1347
|
+
loadAsync(e, s) {
|
|
1348
|
+
return new Promise((n, r) => {
|
|
1349
|
+
const o = new l.FileLoader(this.manager);
|
|
1237
1350
|
o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setPath(this.path), o.setWithCredentials(this.withCredentials), o.load(
|
|
1238
|
-
|
|
1351
|
+
e,
|
|
1239
1352
|
(i) => {
|
|
1240
|
-
this.parseAsync(i).then(
|
|
1241
|
-
|
|
1353
|
+
this.parseAsync(i).then(n).catch((u) => {
|
|
1354
|
+
r(u), this.manager.itemError(e);
|
|
1242
1355
|
});
|
|
1243
1356
|
},
|
|
1244
1357
|
s,
|
|
1245
1358
|
(i) => {
|
|
1246
|
-
|
|
1359
|
+
r(i), this.manager.itemError(e);
|
|
1247
1360
|
}
|
|
1248
1361
|
);
|
|
1249
1362
|
});
|
|
@@ -1253,15 +1366,15 @@ class dt extends h.Loader {
|
|
|
1253
1366
|
* @param buffer ArrayBuffer containing PLY data
|
|
1254
1367
|
* @returns Promise that resolves with parsed SplatData
|
|
1255
1368
|
*/
|
|
1256
|
-
parseAsync(
|
|
1257
|
-
return new Promise((s,
|
|
1258
|
-
const
|
|
1259
|
-
this.pendingCallbacks.set(
|
|
1369
|
+
parseAsync(e) {
|
|
1370
|
+
return new Promise((s, n) => {
|
|
1371
|
+
const r = this.requestId++;
|
|
1372
|
+
this.pendingCallbacks.set(r, { resolve: s, reject: n });
|
|
1260
1373
|
const o = {
|
|
1261
|
-
requestId:
|
|
1262
|
-
buffer:
|
|
1374
|
+
requestId: r,
|
|
1375
|
+
buffer: e
|
|
1263
1376
|
};
|
|
1264
|
-
this.worker.postMessage(o, [
|
|
1377
|
+
this.worker.postMessage(o, [e]);
|
|
1265
1378
|
});
|
|
1266
1379
|
}
|
|
1267
1380
|
/**
|
|
@@ -1276,11 +1389,11 @@ class dt extends h.Loader {
|
|
|
1276
1389
|
*/
|
|
1277
1390
|
createWorkerCode() {
|
|
1278
1391
|
return `(${(function() {
|
|
1279
|
-
self.onmessage = (
|
|
1280
|
-
const { requestId:
|
|
1392
|
+
self.onmessage = (n) => {
|
|
1393
|
+
const { requestId: r, buffer: o } = n.data;
|
|
1281
1394
|
try {
|
|
1282
1395
|
const i = s(o), u = {
|
|
1283
|
-
requestId:
|
|
1396
|
+
requestId: r,
|
|
1284
1397
|
result: i
|
|
1285
1398
|
};
|
|
1286
1399
|
self.postMessage(u, [
|
|
@@ -1292,179 +1405,179 @@ class dt extends h.Loader {
|
|
|
1292
1405
|
]);
|
|
1293
1406
|
} catch (i) {
|
|
1294
1407
|
const u = {
|
|
1295
|
-
requestId:
|
|
1408
|
+
requestId: r,
|
|
1296
1409
|
error: i instanceof Error ? i.message : String(i)
|
|
1297
1410
|
};
|
|
1298
1411
|
self.postMessage(u);
|
|
1299
1412
|
}
|
|
1300
1413
|
};
|
|
1301
|
-
function s(
|
|
1302
|
-
const
|
|
1414
|
+
function s(n) {
|
|
1415
|
+
const r = new TextDecoder(), o = new Uint8Array(n), i = [112, 108, 121, 10], u = `
|
|
1303
1416
|
end_header
|
|
1304
1417
|
`;
|
|
1305
|
-
for (let
|
|
1306
|
-
if (o[
|
|
1418
|
+
for (let D = 0; D < i.length; D++)
|
|
1419
|
+
if (o[D] !== i[D])
|
|
1307
1420
|
throw new Error(
|
|
1308
1421
|
"Invalid PLY file: Missing magic bytes"
|
|
1309
1422
|
);
|
|
1310
|
-
let
|
|
1311
|
-
for (let
|
|
1312
|
-
let
|
|
1313
|
-
for (let
|
|
1314
|
-
if (o[
|
|
1315
|
-
|
|
1423
|
+
let y = 0;
|
|
1424
|
+
for (let D = 0; D < o.length - u.length; D++) {
|
|
1425
|
+
let p = !0;
|
|
1426
|
+
for (let q = 0; q < u.length; q++)
|
|
1427
|
+
if (o[D + q] !== u.charCodeAt(q)) {
|
|
1428
|
+
p = !1;
|
|
1316
1429
|
break;
|
|
1317
1430
|
}
|
|
1318
|
-
if (
|
|
1319
|
-
|
|
1431
|
+
if (p) {
|
|
1432
|
+
y = D + u.length;
|
|
1320
1433
|
break;
|
|
1321
1434
|
}
|
|
1322
1435
|
}
|
|
1323
|
-
if (
|
|
1436
|
+
if (y === 0)
|
|
1324
1437
|
throw new Error(
|
|
1325
1438
|
"Invalid PLY file: Could not find end of header"
|
|
1326
1439
|
);
|
|
1327
|
-
const c =
|
|
1328
|
-
o.subarray(0,
|
|
1440
|
+
const c = r.decode(
|
|
1441
|
+
o.subarray(0, y)
|
|
1329
1442
|
).split(`
|
|
1330
|
-
`),
|
|
1331
|
-
let
|
|
1332
|
-
for (let
|
|
1333
|
-
const
|
|
1334
|
-
if (
|
|
1335
|
-
const
|
|
1336
|
-
switch (
|
|
1443
|
+
`), h = [];
|
|
1444
|
+
let d = null;
|
|
1445
|
+
for (let D = 1; D < c.length; D++) {
|
|
1446
|
+
const p = c[D].trim();
|
|
1447
|
+
if (p === "" || p === "end_header") continue;
|
|
1448
|
+
const q = p.split(" ");
|
|
1449
|
+
switch (q[0]) {
|
|
1337
1450
|
case "format":
|
|
1338
|
-
|
|
1451
|
+
d = q[1];
|
|
1339
1452
|
break;
|
|
1340
1453
|
case "element":
|
|
1341
|
-
|
|
1342
|
-
name:
|
|
1343
|
-
count: parseInt(
|
|
1454
|
+
h.push({
|
|
1455
|
+
name: q[1],
|
|
1456
|
+
count: parseInt(q[2], 10),
|
|
1344
1457
|
properties: []
|
|
1345
1458
|
});
|
|
1346
1459
|
break;
|
|
1347
1460
|
case "property":
|
|
1348
|
-
if (
|
|
1461
|
+
if (h.length === 0)
|
|
1349
1462
|
throw new Error(
|
|
1350
1463
|
"Invalid PLY file: Property without element"
|
|
1351
1464
|
);
|
|
1352
|
-
|
|
1353
|
-
type:
|
|
1354
|
-
name:
|
|
1465
|
+
h[h.length - 1].properties.push({
|
|
1466
|
+
type: q[1],
|
|
1467
|
+
name: q[2]
|
|
1355
1468
|
});
|
|
1356
1469
|
break;
|
|
1357
1470
|
}
|
|
1358
1471
|
}
|
|
1359
|
-
if (
|
|
1360
|
-
throw new Error(`Unsupported PLY format: ${
|
|
1361
|
-
const
|
|
1362
|
-
if (!
|
|
1472
|
+
if (d !== "binary_little_endian")
|
|
1473
|
+
throw new Error(`Unsupported PLY format: ${d}`);
|
|
1474
|
+
const w = h.find((D) => D.name === "vertex");
|
|
1475
|
+
if (!w)
|
|
1363
1476
|
throw new Error(
|
|
1364
1477
|
"Invalid PLY file: No vertex element found"
|
|
1365
1478
|
);
|
|
1366
|
-
const
|
|
1367
|
-
let
|
|
1368
|
-
const
|
|
1369
|
-
(
|
|
1370
|
-
),
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
], q = [
|
|
1376
|
-
A("scale_0"),
|
|
1377
|
-
A("scale_1"),
|
|
1378
|
-
A("scale_2")
|
|
1479
|
+
const A = w.count, b = new Float32Array(A * 3), z = new Float32Array(A * 4), _ = new Float32Array(A * 3), F = new Float32Array(A * 3), O = new Float32Array(A), V = new DataView(n);
|
|
1480
|
+
let k = y;
|
|
1481
|
+
const M = (D) => w.properties.findIndex(
|
|
1482
|
+
(p) => p.name === D
|
|
1483
|
+
), B = M("x"), S = M("y"), g = M("z"), v = [
|
|
1484
|
+
M("rot_0"),
|
|
1485
|
+
M("rot_1"),
|
|
1486
|
+
M("rot_2"),
|
|
1487
|
+
M("rot_3")
|
|
1379
1488
|
], T = [
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
],
|
|
1489
|
+
M("scale_0"),
|
|
1490
|
+
M("scale_1"),
|
|
1491
|
+
M("scale_2")
|
|
1492
|
+
], U = [
|
|
1493
|
+
M("f_dc_0"),
|
|
1494
|
+
M("f_dc_1"),
|
|
1495
|
+
M("f_dc_2")
|
|
1496
|
+
], I = M("opacity");
|
|
1384
1497
|
if ([
|
|
1385
|
-
|
|
1498
|
+
B,
|
|
1499
|
+
S,
|
|
1386
1500
|
g,
|
|
1387
|
-
|
|
1388
|
-
...I,
|
|
1389
|
-
...q,
|
|
1501
|
+
...v,
|
|
1390
1502
|
...T,
|
|
1391
|
-
|
|
1392
|
-
|
|
1503
|
+
...U,
|
|
1504
|
+
I
|
|
1505
|
+
].some((D) => D === -1))
|
|
1393
1506
|
throw new Error(
|
|
1394
1507
|
"Invalid PLY file: Missing required properties"
|
|
1395
1508
|
);
|
|
1396
|
-
const
|
|
1397
|
-
if (
|
|
1398
|
-
const
|
|
1399
|
-
return
|
|
1509
|
+
const f = 0.28209479177387814, C = (D) => {
|
|
1510
|
+
if (D > 0) return 1 / (1 + Math.exp(-D));
|
|
1511
|
+
const p = Math.exp(D);
|
|
1512
|
+
return p / (1 + p);
|
|
1400
1513
|
};
|
|
1401
|
-
let
|
|
1402
|
-
for (let
|
|
1403
|
-
const
|
|
1404
|
-
for (let
|
|
1405
|
-
const
|
|
1406
|
-
let
|
|
1407
|
-
switch (
|
|
1514
|
+
let Y = 1 / 0, W = 1 / 0, R = 1 / 0, J = -1 / 0, Z = -1 / 0, H = -1 / 0;
|
|
1515
|
+
for (let D = 0; D < A; D++) {
|
|
1516
|
+
const p = [];
|
|
1517
|
+
for (let St = 0; St < w.properties.length; St++) {
|
|
1518
|
+
const Et = w.properties[St].type;
|
|
1519
|
+
let ct;
|
|
1520
|
+
switch (Et) {
|
|
1408
1521
|
case "char":
|
|
1409
|
-
|
|
1522
|
+
ct = V.getInt8(k), k += 1;
|
|
1410
1523
|
break;
|
|
1411
1524
|
case "uchar":
|
|
1412
|
-
|
|
1525
|
+
ct = V.getUint8(k), k += 1;
|
|
1413
1526
|
break;
|
|
1414
1527
|
case "short":
|
|
1415
|
-
|
|
1528
|
+
ct = V.getInt16(k, !0), k += 2;
|
|
1416
1529
|
break;
|
|
1417
1530
|
case "ushort":
|
|
1418
|
-
|
|
1531
|
+
ct = V.getUint16(k, !0), k += 2;
|
|
1419
1532
|
break;
|
|
1420
1533
|
case "int":
|
|
1421
|
-
|
|
1534
|
+
ct = V.getInt32(k, !0), k += 4;
|
|
1422
1535
|
break;
|
|
1423
1536
|
case "uint":
|
|
1424
|
-
|
|
1537
|
+
ct = V.getUint32(k, !0), k += 4;
|
|
1425
1538
|
break;
|
|
1426
1539
|
case "float":
|
|
1427
|
-
|
|
1540
|
+
ct = V.getFloat32(k, !0), k += 4;
|
|
1428
1541
|
break;
|
|
1429
1542
|
case "double":
|
|
1430
|
-
|
|
1543
|
+
ct = V.getFloat64(k, !0), k += 8;
|
|
1431
1544
|
break;
|
|
1432
1545
|
default:
|
|
1433
1546
|
throw new Error(
|
|
1434
|
-
`Unsupported property type: ${
|
|
1547
|
+
`Unsupported property type: ${Et}`
|
|
1435
1548
|
);
|
|
1436
1549
|
}
|
|
1437
|
-
|
|
1550
|
+
p.push(ct);
|
|
1438
1551
|
}
|
|
1439
|
-
const
|
|
1440
|
-
|
|
1441
|
-
let
|
|
1552
|
+
const q = p[B], L = p[S], E = p[g], G = D * 3;
|
|
1553
|
+
b[G] = q, b[G + 1] = L, b[G + 2] = E, Y = Math.min(Y, q), W = Math.min(W, L), R = Math.min(R, E), J = Math.max(J, q), Z = Math.max(Z, L), H = Math.max(H, E);
|
|
1554
|
+
let X = p[v[1]], j = p[v[2]], Q = p[v[3]], $ = p[v[0]];
|
|
1442
1555
|
const K = Math.sqrt(
|
|
1443
|
-
|
|
1556
|
+
X * X + j * j + Q * Q + $ * $
|
|
1444
1557
|
);
|
|
1445
|
-
K > 0 && (
|
|
1446
|
-
const
|
|
1447
|
-
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1450
|
-
let
|
|
1451
|
-
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1558
|
+
K > 0 && (X /= K, j /= K, Q /= K, $ /= K), $ < 0 && (X = -X, j = -j, Q = -Q, $ = -$);
|
|
1559
|
+
const tt = D * 4;
|
|
1560
|
+
z[tt] = X, z[tt + 1] = j, z[tt + 2] = Q, z[tt + 3] = $;
|
|
1561
|
+
const et = D * 3;
|
|
1562
|
+
_[et] = p[T[0]], _[et + 1] = p[T[1]], _[et + 2] = p[T[2]];
|
|
1563
|
+
let mt = 0.5 + p[U[0]] * f, dt = 0.5 + p[U[1]] * f, ot = 0.5 + p[U[2]] * f;
|
|
1564
|
+
mt = Math.max(0, Math.min(1, mt)), dt = Math.max(0, Math.min(1, dt)), ot = Math.max(0, Math.min(1, ot));
|
|
1565
|
+
const bt = D * 3;
|
|
1566
|
+
F[bt] = mt, F[bt + 1] = dt, F[bt + 2] = ot, O[D] = C(p[I]);
|
|
1454
1567
|
}
|
|
1455
1568
|
return {
|
|
1456
|
-
numSplats:
|
|
1457
|
-
positions:
|
|
1458
|
-
rotations:
|
|
1459
|
-
scales:
|
|
1460
|
-
colors:
|
|
1461
|
-
opacities:
|
|
1569
|
+
numSplats: A,
|
|
1570
|
+
positions: b.buffer,
|
|
1571
|
+
rotations: z.buffer,
|
|
1572
|
+
scales: _.buffer,
|
|
1573
|
+
colors: F.buffer,
|
|
1574
|
+
opacities: O.buffer,
|
|
1462
1575
|
boundingBox: {
|
|
1463
|
-
minX:
|
|
1464
|
-
minY:
|
|
1465
|
-
minZ:
|
|
1466
|
-
maxX:
|
|
1467
|
-
maxY:
|
|
1576
|
+
minX: Y,
|
|
1577
|
+
minY: W,
|
|
1578
|
+
minZ: R,
|
|
1579
|
+
maxX: J,
|
|
1580
|
+
maxY: Z,
|
|
1468
1581
|
maxZ: H
|
|
1469
1582
|
}
|
|
1470
1583
|
};
|
|
@@ -1472,7 +1585,7 @@ end_header
|
|
|
1472
1585
|
}).toString()})();`;
|
|
1473
1586
|
}
|
|
1474
1587
|
}
|
|
1475
|
-
var
|
|
1588
|
+
var st = Uint8Array, pt = Uint16Array, Jt = Int32Array, Vt = new st([
|
|
1476
1589
|
0,
|
|
1477
1590
|
0,
|
|
1478
1591
|
0,
|
|
@@ -1507,7 +1620,7 @@ var ee = Uint8Array, de = Uint16Array, He = Int32Array, Fe = new ee([
|
|
|
1507
1620
|
0,
|
|
1508
1621
|
/* impossible */
|
|
1509
1622
|
0
|
|
1510
|
-
]),
|
|
1623
|
+
]), Tt = new st([
|
|
1511
1624
|
0,
|
|
1512
1625
|
0,
|
|
1513
1626
|
0,
|
|
@@ -1541,65 +1654,65 @@ var ee = Uint8Array, de = Uint16Array, He = Int32Array, Fe = new ee([
|
|
|
1541
1654
|
/* unused */
|
|
1542
1655
|
0,
|
|
1543
1656
|
0
|
|
1544
|
-
]),
|
|
1545
|
-
for (var
|
|
1546
|
-
|
|
1547
|
-
for (var
|
|
1548
|
-
for (var
|
|
1549
|
-
r
|
|
1550
|
-
return { b:
|
|
1551
|
-
},
|
|
1552
|
-
|
|
1553
|
-
var
|
|
1554
|
-
for (var
|
|
1555
|
-
var
|
|
1556
|
-
|
|
1657
|
+
]), Kt = new st([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), Ot = function(a, t) {
|
|
1658
|
+
for (var e = new pt(31), s = 0; s < 31; ++s)
|
|
1659
|
+
e[s] = t += 1 << a[s - 1];
|
|
1660
|
+
for (var n = new Jt(e[30]), s = 1; s < 30; ++s)
|
|
1661
|
+
for (var r = e[s]; r < e[s + 1]; ++r)
|
|
1662
|
+
n[r] = r - e[s] << 5 | s;
|
|
1663
|
+
return { b: e, r: n };
|
|
1664
|
+
}, Lt = Ot(Vt, 2), Gt = Lt.b, te = Lt.r;
|
|
1665
|
+
Gt[28] = 258, te[258] = 28;
|
|
1666
|
+
var ee = Ot(Tt, 0), se = ee.b, zt = new pt(32768);
|
|
1667
|
+
for (var N = 0; N < 32768; ++N) {
|
|
1668
|
+
var lt = (N & 43690) >> 1 | (N & 21845) << 1;
|
|
1669
|
+
lt = (lt & 52428) >> 2 | (lt & 13107) << 2, lt = (lt & 61680) >> 4 | (lt & 3855) << 4, zt[N] = ((lt & 65280) >> 8 | (lt & 255) << 8) >> 1;
|
|
1557
1670
|
}
|
|
1558
|
-
var
|
|
1559
|
-
for (var s = a.length,
|
|
1560
|
-
a[
|
|
1561
|
-
var o = new
|
|
1562
|
-
for (
|
|
1563
|
-
o[
|
|
1671
|
+
var yt = function(a, t, e) {
|
|
1672
|
+
for (var s = a.length, n = 0, r = new pt(t); n < s; ++n)
|
|
1673
|
+
a[n] && ++r[a[n] - 1];
|
|
1674
|
+
var o = new pt(t);
|
|
1675
|
+
for (n = 1; n < t; ++n)
|
|
1676
|
+
o[n] = o[n - 1] + r[n - 1] << 1;
|
|
1564
1677
|
var i;
|
|
1565
|
-
if (
|
|
1566
|
-
i = new
|
|
1567
|
-
var u = 15 -
|
|
1568
|
-
for (
|
|
1569
|
-
if (a[
|
|
1570
|
-
for (var
|
|
1571
|
-
i[
|
|
1678
|
+
if (e) {
|
|
1679
|
+
i = new pt(1 << t);
|
|
1680
|
+
var u = 15 - t;
|
|
1681
|
+
for (n = 0; n < s; ++n)
|
|
1682
|
+
if (a[n])
|
|
1683
|
+
for (var y = n << 4 | a[n], m = t - a[n], c = o[a[n] - 1]++ << m, h = c | (1 << m) - 1; c <= h; ++c)
|
|
1684
|
+
i[zt[c] >> u] = y;
|
|
1572
1685
|
} else
|
|
1573
|
-
for (i = new
|
|
1574
|
-
a[
|
|
1686
|
+
for (i = new pt(s), n = 0; n < s; ++n)
|
|
1687
|
+
a[n] && (i[n] = zt[o[a[n] - 1]++] >> 15 - a[n]);
|
|
1575
1688
|
return i;
|
|
1576
|
-
},
|
|
1577
|
-
for (var
|
|
1578
|
-
|
|
1579
|
-
for (var
|
|
1580
|
-
|
|
1581
|
-
for (var
|
|
1582
|
-
|
|
1583
|
-
for (var
|
|
1584
|
-
|
|
1585
|
-
var
|
|
1586
|
-
for (var
|
|
1587
|
-
|
|
1588
|
-
var
|
|
1589
|
-
for (var
|
|
1590
|
-
a[
|
|
1591
|
-
return
|
|
1592
|
-
},
|
|
1593
|
-
var s =
|
|
1594
|
-
return (a[s] | a[s + 1] << 8) >> (
|
|
1595
|
-
},
|
|
1596
|
-
var
|
|
1597
|
-
return (a[
|
|
1598
|
-
},
|
|
1689
|
+
}, vt = new st(288);
|
|
1690
|
+
for (var N = 0; N < 144; ++N)
|
|
1691
|
+
vt[N] = 8;
|
|
1692
|
+
for (var N = 144; N < 256; ++N)
|
|
1693
|
+
vt[N] = 9;
|
|
1694
|
+
for (var N = 256; N < 280; ++N)
|
|
1695
|
+
vt[N] = 7;
|
|
1696
|
+
for (var N = 280; N < 288; ++N)
|
|
1697
|
+
vt[N] = 8;
|
|
1698
|
+
var Wt = new st(32);
|
|
1699
|
+
for (var N = 0; N < 32; ++N)
|
|
1700
|
+
Wt[N] = 5;
|
|
1701
|
+
var ne = /* @__PURE__ */ yt(vt, 9, 1), re = /* @__PURE__ */ yt(Wt, 5, 1), kt = function(a) {
|
|
1702
|
+
for (var t = a[0], e = 1; e < a.length; ++e)
|
|
1703
|
+
a[e] > t && (t = a[e]);
|
|
1704
|
+
return t;
|
|
1705
|
+
}, rt = function(a, t, e) {
|
|
1706
|
+
var s = t / 8 | 0;
|
|
1707
|
+
return (a[s] | a[s + 1] << 8) >> (t & 7) & e;
|
|
1708
|
+
}, It = function(a, t) {
|
|
1709
|
+
var e = t / 8 | 0;
|
|
1710
|
+
return (a[e] | a[e + 1] << 8 | a[e + 2] << 16) >> (t & 7);
|
|
1711
|
+
}, ae = function(a) {
|
|
1599
1712
|
return (a + 7) / 8 | 0;
|
|
1600
|
-
},
|
|
1601
|
-
return (
|
|
1602
|
-
},
|
|
1713
|
+
}, qt = function(a, t, e) {
|
|
1714
|
+
return (t == null || t < 0) && (t = 0), (e == null || e > a.length) && (e = a.length), new st(a.subarray(t, e));
|
|
1715
|
+
}, oe = [
|
|
1603
1716
|
"unexpected EOF",
|
|
1604
1717
|
"invalid block type",
|
|
1605
1718
|
"invalid length/literal",
|
|
@@ -1615,250 +1728,272 @@ var Qe = /* @__PURE__ */ pe(xe, 9, 1), Je = /* @__PURE__ */ pe(Ue, 5, 1), ve = f
|
|
|
1615
1728
|
"stream finishing",
|
|
1616
1729
|
"invalid zip data"
|
|
1617
1730
|
// determined by unknown compression method
|
|
1618
|
-
],
|
|
1619
|
-
var s = new Error(
|
|
1620
|
-
if (s.code = a, Error.captureStackTrace && Error.captureStackTrace(s,
|
|
1731
|
+
], nt = function(a, t, e) {
|
|
1732
|
+
var s = new Error(t || oe[a]);
|
|
1733
|
+
if (s.code = a, Error.captureStackTrace && Error.captureStackTrace(s, nt), !e)
|
|
1621
1734
|
throw s;
|
|
1622
1735
|
return s;
|
|
1623
|
-
},
|
|
1624
|
-
var
|
|
1625
|
-
if (!
|
|
1626
|
-
return
|
|
1627
|
-
var o = !
|
|
1628
|
-
o && (
|
|
1629
|
-
var
|
|
1630
|
-
var Q =
|
|
1631
|
-
if (
|
|
1632
|
-
var
|
|
1633
|
-
|
|
1736
|
+
}, ie = function(a, t, e, s) {
|
|
1737
|
+
var n = a.length, r = s ? s.length : 0;
|
|
1738
|
+
if (!n || t.f && !t.l)
|
|
1739
|
+
return e || new st(0);
|
|
1740
|
+
var o = !e, i = o || t.i != 2, u = t.i;
|
|
1741
|
+
o && (e = new st(n * 3));
|
|
1742
|
+
var y = function(j) {
|
|
1743
|
+
var Q = e.length;
|
|
1744
|
+
if (j > Q) {
|
|
1745
|
+
var $ = new st(Math.max(Q * 2, j));
|
|
1746
|
+
$.set(e), e = $;
|
|
1634
1747
|
}
|
|
1635
|
-
},
|
|
1748
|
+
}, m = t.f || 0, c = t.p || 0, h = t.b || 0, d = t.l, w = t.d, A = t.m, b = t.n, z = n * 8;
|
|
1636
1749
|
do {
|
|
1637
|
-
if (!
|
|
1638
|
-
|
|
1639
|
-
var
|
|
1640
|
-
if (c += 3,
|
|
1641
|
-
if (
|
|
1642
|
-
|
|
1643
|
-
else if (
|
|
1644
|
-
var
|
|
1750
|
+
if (!d) {
|
|
1751
|
+
m = rt(a, c, 1);
|
|
1752
|
+
var _ = rt(a, c + 1, 3);
|
|
1753
|
+
if (c += 3, _)
|
|
1754
|
+
if (_ == 1)
|
|
1755
|
+
d = ne, w = re, A = 9, b = 5;
|
|
1756
|
+
else if (_ == 2) {
|
|
1757
|
+
var k = rt(a, c, 31) + 257, M = rt(a, c + 10, 15) + 4, B = k + rt(a, c + 5, 31) + 1;
|
|
1645
1758
|
c += 14;
|
|
1646
|
-
for (var
|
|
1647
|
-
|
|
1648
|
-
c +=
|
|
1649
|
-
for (var
|
|
1650
|
-
var
|
|
1651
|
-
c +=
|
|
1652
|
-
var
|
|
1653
|
-
if (
|
|
1654
|
-
|
|
1759
|
+
for (var S = new st(B), g = new st(19), v = 0; v < M; ++v)
|
|
1760
|
+
g[Kt[v]] = rt(a, c + v * 3, 7);
|
|
1761
|
+
c += M * 3;
|
|
1762
|
+
for (var T = kt(g), U = (1 << T) - 1, I = yt(g, T, 1), v = 0; v < B; ) {
|
|
1763
|
+
var P = I[rt(a, c, U)];
|
|
1764
|
+
c += P & 15;
|
|
1765
|
+
var F = P >> 4;
|
|
1766
|
+
if (F < 16)
|
|
1767
|
+
S[v++] = F;
|
|
1655
1768
|
else {
|
|
1656
|
-
var
|
|
1657
|
-
for (
|
|
1658
|
-
|
|
1769
|
+
var f = 0, C = 0;
|
|
1770
|
+
for (F == 16 ? (C = 3 + rt(a, c, 3), c += 2, f = S[v - 1]) : F == 17 ? (C = 3 + rt(a, c, 7), c += 3) : F == 18 && (C = 11 + rt(a, c, 127), c += 7); C--; )
|
|
1771
|
+
S[v++] = f;
|
|
1659
1772
|
}
|
|
1660
1773
|
}
|
|
1661
|
-
var
|
|
1662
|
-
|
|
1774
|
+
var Y = S.subarray(0, k), W = S.subarray(k);
|
|
1775
|
+
A = kt(Y), b = kt(W), d = yt(Y, A, 1), w = yt(W, b, 1);
|
|
1663
1776
|
} else
|
|
1664
|
-
|
|
1777
|
+
nt(1);
|
|
1665
1778
|
else {
|
|
1666
|
-
var
|
|
1667
|
-
if (
|
|
1668
|
-
u &&
|
|
1779
|
+
var F = ae(c) + 4, O = a[F - 4] | a[F - 3] << 8, V = F + O;
|
|
1780
|
+
if (V > n) {
|
|
1781
|
+
u && nt(0);
|
|
1669
1782
|
break;
|
|
1670
1783
|
}
|
|
1671
|
-
i &&
|
|
1784
|
+
i && y(h + O), e.set(a.subarray(F, V), h), t.b = h += O, t.p = c = V * 8, t.f = m;
|
|
1672
1785
|
continue;
|
|
1673
1786
|
}
|
|
1674
|
-
if (c >
|
|
1675
|
-
u &&
|
|
1787
|
+
if (c > z) {
|
|
1788
|
+
u && nt(0);
|
|
1676
1789
|
break;
|
|
1677
1790
|
}
|
|
1678
1791
|
}
|
|
1679
|
-
i &&
|
|
1680
|
-
for (var
|
|
1681
|
-
var
|
|
1682
|
-
if (c +=
|
|
1683
|
-
u &&
|
|
1792
|
+
i && y(h + 131072);
|
|
1793
|
+
for (var R = (1 << A) - 1, J = (1 << b) - 1, Z = c; ; Z = c) {
|
|
1794
|
+
var f = d[It(a, c) & R], H = f >> 4;
|
|
1795
|
+
if (c += f & 15, c > z) {
|
|
1796
|
+
u && nt(0);
|
|
1684
1797
|
break;
|
|
1685
1798
|
}
|
|
1686
|
-
if (
|
|
1687
|
-
|
|
1799
|
+
if (f || nt(2), H < 256)
|
|
1800
|
+
e[h++] = H;
|
|
1688
1801
|
else if (H == 256) {
|
|
1689
|
-
|
|
1802
|
+
Z = c, d = null;
|
|
1690
1803
|
break;
|
|
1691
1804
|
} else {
|
|
1692
|
-
var
|
|
1805
|
+
var D = H - 254;
|
|
1693
1806
|
if (H > 264) {
|
|
1694
|
-
var
|
|
1695
|
-
|
|
1807
|
+
var v = H - 257, p = Vt[v];
|
|
1808
|
+
D = rt(a, c, (1 << p) - 1) + Gt[v], c += p;
|
|
1696
1809
|
}
|
|
1697
|
-
var
|
|
1698
|
-
|
|
1699
|
-
var
|
|
1700
|
-
if (
|
|
1701
|
-
var
|
|
1702
|
-
|
|
1810
|
+
var q = w[It(a, c) & J], L = q >> 4;
|
|
1811
|
+
q || nt(3), c += q & 15;
|
|
1812
|
+
var W = se[L];
|
|
1813
|
+
if (L > 3) {
|
|
1814
|
+
var p = Tt[L];
|
|
1815
|
+
W += It(a, c) & (1 << p) - 1, c += p;
|
|
1703
1816
|
}
|
|
1704
|
-
if (c >
|
|
1705
|
-
u &&
|
|
1817
|
+
if (c > z) {
|
|
1818
|
+
u && nt(0);
|
|
1706
1819
|
break;
|
|
1707
1820
|
}
|
|
1708
|
-
i &&
|
|
1709
|
-
var
|
|
1710
|
-
if (
|
|
1711
|
-
var
|
|
1712
|
-
for (
|
|
1713
|
-
|
|
1821
|
+
i && y(h + 131072);
|
|
1822
|
+
var E = h + D;
|
|
1823
|
+
if (h < W) {
|
|
1824
|
+
var G = r - W, X = Math.min(W, E);
|
|
1825
|
+
for (G + h < 0 && nt(3); h < X; ++h)
|
|
1826
|
+
e[h] = s[G + h];
|
|
1714
1827
|
}
|
|
1715
|
-
for (;
|
|
1716
|
-
|
|
1828
|
+
for (; h < E; ++h)
|
|
1829
|
+
e[h] = e[h - W];
|
|
1717
1830
|
}
|
|
1718
1831
|
}
|
|
1719
|
-
|
|
1720
|
-
} while (!
|
|
1721
|
-
return
|
|
1722
|
-
},
|
|
1723
|
-
return a[
|
|
1724
|
-
},
|
|
1725
|
-
return (a[
|
|
1726
|
-
},
|
|
1727
|
-
return
|
|
1832
|
+
t.l = d, t.p = Z, t.b = h, t.f = m, d && (m = 1, t.m = A, t.d = w, t.n = b);
|
|
1833
|
+
} while (!m);
|
|
1834
|
+
return h != e.length && o ? qt(e, 0, h) : e.subarray(0, h);
|
|
1835
|
+
}, ce = /* @__PURE__ */ new st(0), it = function(a, t) {
|
|
1836
|
+
return a[t] | a[t + 1] << 8;
|
|
1837
|
+
}, at = function(a, t) {
|
|
1838
|
+
return (a[t] | a[t + 1] << 8 | a[t + 2] << 16 | a[t + 3] << 24) >>> 0;
|
|
1839
|
+
}, Ct = function(a, t) {
|
|
1840
|
+
return at(a, t) + at(a, t + 4) * 4294967296;
|
|
1728
1841
|
};
|
|
1729
|
-
function
|
|
1730
|
-
return
|
|
1842
|
+
function le(a, t) {
|
|
1843
|
+
return ie(a, { i: 2 }, t && t.out, t && t.dictionary);
|
|
1731
1844
|
}
|
|
1732
|
-
var
|
|
1845
|
+
var Dt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), he = 0;
|
|
1733
1846
|
try {
|
|
1734
|
-
|
|
1847
|
+
Dt.decode(ce, { stream: !0 }), he = 1;
|
|
1735
1848
|
} catch {
|
|
1736
1849
|
}
|
|
1737
|
-
var
|
|
1738
|
-
for (var
|
|
1739
|
-
var s = a[
|
|
1740
|
-
if (
|
|
1741
|
-
return { s:
|
|
1742
|
-
|
|
1850
|
+
var ue = function(a) {
|
|
1851
|
+
for (var t = "", e = 0; ; ) {
|
|
1852
|
+
var s = a[e++], n = (s > 127) + (s > 223) + (s > 239);
|
|
1853
|
+
if (e + n > a.length)
|
|
1854
|
+
return { s: t, r: qt(a, e - 1) };
|
|
1855
|
+
n ? n == 3 ? (s = ((s & 15) << 18 | (a[e++] & 63) << 12 | (a[e++] & 63) << 6 | a[e++] & 63) - 65536, t += String.fromCharCode(55296 | s >> 10, 56320 | s & 1023)) : n & 1 ? t += String.fromCharCode((s & 31) << 6 | a[e++] & 63) : t += String.fromCharCode((s & 15) << 12 | (a[e++] & 63) << 6 | a[e++] & 63) : t += String.fromCharCode(s);
|
|
1743
1856
|
}
|
|
1744
1857
|
};
|
|
1745
|
-
function
|
|
1746
|
-
if (
|
|
1747
|
-
for (var
|
|
1748
|
-
|
|
1749
|
-
return
|
|
1858
|
+
function me(a, t) {
|
|
1859
|
+
if (t) {
|
|
1860
|
+
for (var e = "", s = 0; s < a.length; s += 16384)
|
|
1861
|
+
e += String.fromCharCode.apply(null, a.subarray(s, s + 16384));
|
|
1862
|
+
return e;
|
|
1750
1863
|
} else {
|
|
1751
|
-
if (
|
|
1752
|
-
return
|
|
1753
|
-
var
|
|
1754
|
-
return
|
|
1864
|
+
if (Dt)
|
|
1865
|
+
return Dt.decode(a);
|
|
1866
|
+
var n = ue(a), r = n.s, e = n.r;
|
|
1867
|
+
return e.length && nt(8), r;
|
|
1755
1868
|
}
|
|
1756
1869
|
}
|
|
1757
|
-
var
|
|
1758
|
-
return
|
|
1759
|
-
},
|
|
1760
|
-
var s =
|
|
1761
|
-
return [
|
|
1762
|
-
},
|
|
1763
|
-
for (;
|
|
1870
|
+
var de = function(a, t) {
|
|
1871
|
+
return t + 30 + it(a, t + 26) + it(a, t + 28);
|
|
1872
|
+
}, fe = function(a, t, e) {
|
|
1873
|
+
var s = it(a, t + 28), n = me(a.subarray(t + 46, t + 46 + s), !(it(a, t + 8) & 2048)), r = t + 46 + s, o = at(a, t + 20), i = e && o == 4294967295 ? pe(a, r) : [o, at(a, t + 24), at(a, t + 42)], u = i[0], y = i[1], m = i[2];
|
|
1874
|
+
return [it(a, t + 10), u, y, n, r + it(a, t + 30) + it(a, t + 32), m];
|
|
1875
|
+
}, pe = function(a, t) {
|
|
1876
|
+
for (; it(a, t) != 1; t += 4 + it(a, t + 2))
|
|
1764
1877
|
;
|
|
1765
|
-
return [
|
|
1878
|
+
return [Ct(a, t + 12), Ct(a, t + 4), Ct(a, t + 20)];
|
|
1766
1879
|
};
|
|
1767
|
-
function
|
|
1768
|
-
for (var
|
|
1769
|
-
(!s || a.length - s > 65558) &&
|
|
1770
|
-
var
|
|
1771
|
-
if (!
|
|
1880
|
+
function xe(a, t) {
|
|
1881
|
+
for (var e = {}, s = a.length - 22; at(a, s) != 101010256; --s)
|
|
1882
|
+
(!s || a.length - s > 65558) && nt(13);
|
|
1883
|
+
var n = it(a, s + 8);
|
|
1884
|
+
if (!n)
|
|
1772
1885
|
return {};
|
|
1773
|
-
var
|
|
1886
|
+
var r = at(a, s + 16), o = r == 4294967295 || n == 65535;
|
|
1774
1887
|
if (o) {
|
|
1775
|
-
var i =
|
|
1776
|
-
o =
|
|
1888
|
+
var i = at(a, s - 12);
|
|
1889
|
+
o = at(a, i) == 101075792, o && (n = at(a, i + 32), r = at(a, i + 48));
|
|
1777
1890
|
}
|
|
1778
|
-
for (var u = 0; u <
|
|
1779
|
-
var
|
|
1780
|
-
|
|
1891
|
+
for (var u = 0; u < n; ++u) {
|
|
1892
|
+
var y = fe(a, r, o), m = y[0], c = y[1], h = y[2], d = y[3], w = y[4], A = y[5], b = de(a, A);
|
|
1893
|
+
r = w, m ? m == 8 ? e[d] = le(a.subarray(b, b + c), { out: new st(h) }) : nt(14, "unknown compression type " + m) : e[d] = qt(a, b, b + c);
|
|
1781
1894
|
}
|
|
1782
|
-
return
|
|
1895
|
+
return e;
|
|
1783
1896
|
}
|
|
1784
|
-
const
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
if (
|
|
1794
|
-
throw new Error(
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
)
|
|
1824
|
-
|
|
1897
|
+
const Mt = (a) => typeof a == "number" && Number.isFinite(a), ht = (a, t) => {
|
|
1898
|
+
const e = a[t];
|
|
1899
|
+
if (typeof e != "object" || e === null)
|
|
1900
|
+
throw new Error(`Invalid SOG metadata section: ${t}`);
|
|
1901
|
+
return e;
|
|
1902
|
+
}, ut = (a, t) => {
|
|
1903
|
+
const e = a.files;
|
|
1904
|
+
if (!Array.isArray(e))
|
|
1905
|
+
throw new Error(`${t}.files is not an array`);
|
|
1906
|
+
if (!e.every((s) => typeof s == "string"))
|
|
1907
|
+
throw new Error(`${t}.files contains non-strings`);
|
|
1908
|
+
return e;
|
|
1909
|
+
}, Bt = (a, t) => {
|
|
1910
|
+
const e = a.mins, s = a.maxs;
|
|
1911
|
+
if (!Array.isArray(e) || e.length !== 3)
|
|
1912
|
+
throw new Error(`${t}.mins must be length-3`);
|
|
1913
|
+
if (!Array.isArray(s) || s.length !== 3)
|
|
1914
|
+
throw new Error(`${t}.maxs must be length-3`);
|
|
1915
|
+
if (![...e, ...s].every(Mt))
|
|
1916
|
+
throw new Error(`${t}.mins/maxs must be finite numbers`);
|
|
1917
|
+
return {
|
|
1918
|
+
mins: [e[0], e[1], e[2]],
|
|
1919
|
+
maxs: [s[0], s[1], s[2]]
|
|
1920
|
+
};
|
|
1921
|
+
}, ge = (a, t) => {
|
|
1922
|
+
const e = a.mins, s = a.maxs;
|
|
1923
|
+
if (!Array.isArray(e) || e.length !== 4)
|
|
1924
|
+
throw new Error(`${t}.mins must be length-4`);
|
|
1925
|
+
if (!Array.isArray(s) || s.length !== 4)
|
|
1926
|
+
throw new Error(`${t}.maxs must be length-4`);
|
|
1927
|
+
if (![...e, ...s].every(Mt))
|
|
1928
|
+
throw new Error(`${t}.mins/maxs must be finite numbers`);
|
|
1929
|
+
return {
|
|
1930
|
+
mins: [e[0], e[1], e[2], e[3]],
|
|
1931
|
+
maxs: [s[0], s[1], s[2], s[3]]
|
|
1932
|
+
};
|
|
1933
|
+
}, _t = (a, t) => {
|
|
1934
|
+
const e = a.codebook;
|
|
1935
|
+
if (!Array.isArray(e))
|
|
1936
|
+
throw new Error(`${t}.codebook is not an array`);
|
|
1937
|
+
if (!e.every(Mt))
|
|
1938
|
+
throw new Error(`${t}.codebook contains non-finite numbers`);
|
|
1939
|
+
return e;
|
|
1940
|
+
}, Ut = (a) => {
|
|
1941
|
+
if (typeof a != "object" || a === null) throw new Error("Invalid SOG metadata: not an object");
|
|
1942
|
+
const t = a, e = t.version ?? 1;
|
|
1943
|
+
if (e !== 1 && e !== 2) throw new Error(`Unsupported SOG version: ${String(e)}`);
|
|
1944
|
+
if (e === 1) {
|
|
1945
|
+
const m = ht(t, "means"), c = ht(t, "sh0"), h = ht(t, "quats"), d = ht(t, "scales"), w = typeof t.count == "number" && Number.isFinite(t.count) ? t.count : void 0, A = Array.isArray(m.shape) ? m.shape : void 0, b = A && typeof A[0] == "number" ? A[0] : void 0;
|
|
1946
|
+
if (w === void 0 && b === void 0) throw new Error("Invalid SOGS metadata: unable to determine splat count");
|
|
1947
|
+
if (w !== void 0 && b !== void 0 && w !== b) throw new Error("Inconsistent SOGS metadata: count does not match means.shape[0]");
|
|
1825
1948
|
return {
|
|
1826
|
-
|
|
1827
|
-
|
|
1949
|
+
version: 1,
|
|
1950
|
+
numSplats: (w ?? b) | 0,
|
|
1951
|
+
files: {
|
|
1952
|
+
sh0: ut(c, "sh0"),
|
|
1953
|
+
means: ut(m, "means"),
|
|
1954
|
+
quats: ut(h, "quats"),
|
|
1955
|
+
scales: ut(d, "scales")
|
|
1956
|
+
},
|
|
1957
|
+
ranges: {
|
|
1958
|
+
sh0: ge(c, "sh0"),
|
|
1959
|
+
means: Bt(m, "means"),
|
|
1960
|
+
scales: Bt(d, "scales")
|
|
1961
|
+
}
|
|
1828
1962
|
};
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
return S;
|
|
1834
|
-
};
|
|
1963
|
+
}
|
|
1964
|
+
const s = t.count;
|
|
1965
|
+
if (!Mt(s)) throw new Error('Invalid SOG v2 metadata: missing/invalid "count"');
|
|
1966
|
+
const n = s | 0, r = ht(t, "means"), o = ht(t, "sh0"), i = ht(t, "quats"), u = ht(t, "scales");
|
|
1835
1967
|
return {
|
|
1836
|
-
|
|
1968
|
+
version: 2,
|
|
1969
|
+
numSplats: n,
|
|
1837
1970
|
files: {
|
|
1838
|
-
sh0:
|
|
1839
|
-
means:
|
|
1840
|
-
quats:
|
|
1841
|
-
scales:
|
|
1971
|
+
sh0: ut(o, "sh0"),
|
|
1972
|
+
means: ut(r, "means"),
|
|
1973
|
+
quats: ut(i, "quats"),
|
|
1974
|
+
scales: ut(u, "scales")
|
|
1842
1975
|
},
|
|
1843
1976
|
ranges: {
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
scales:
|
|
1847
|
-
}
|
|
1977
|
+
means: Bt(r, "means"),
|
|
1978
|
+
sh0: { codebook: _t(o, "sh0") },
|
|
1979
|
+
scales: { codebook: _t(u, "scales") }
|
|
1980
|
+
},
|
|
1981
|
+
antialias: typeof t.antialias == "boolean" ? t.antialias : void 0
|
|
1982
|
+
// prettier-ignore
|
|
1848
1983
|
};
|
|
1849
1984
|
};
|
|
1850
|
-
class
|
|
1851
|
-
constructor(
|
|
1852
|
-
super(
|
|
1985
|
+
class Me extends l.Loader {
|
|
1986
|
+
constructor(t) {
|
|
1987
|
+
super(t), this.withCredentials = !0;
|
|
1853
1988
|
}
|
|
1854
1989
|
/**
|
|
1855
1990
|
* Detect if a buffer is a ZIP file by checking magic bytes
|
|
1856
1991
|
* ZIP files start with signature: PK\x03\x04 (0x50 0x4B 0x03 0x04)
|
|
1857
1992
|
*/
|
|
1858
|
-
isZipBuffer(
|
|
1859
|
-
if (
|
|
1860
|
-
const
|
|
1861
|
-
return
|
|
1993
|
+
isZipBuffer(t) {
|
|
1994
|
+
if (t.byteLength < 4) return !1;
|
|
1995
|
+
const e = new Uint8Array(t, 0, 4);
|
|
1996
|
+
return e[0] === 80 && e[1] === 75 && e[2] === 3 && e[3] === 4;
|
|
1862
1997
|
}
|
|
1863
1998
|
/**
|
|
1864
1999
|
* Load a SOGS file (meta.json + textures)
|
|
@@ -1867,19 +2002,19 @@ class ft extends h.Loader {
|
|
|
1867
2002
|
* @param onProgress Optional progress callback
|
|
1868
2003
|
* @param onError Optional error callback
|
|
1869
2004
|
*/
|
|
1870
|
-
load(
|
|
1871
|
-
const
|
|
1872
|
-
|
|
1873
|
-
|
|
2005
|
+
load(t, e, s, n) {
|
|
2006
|
+
const r = new l.FileLoader(this.manager);
|
|
2007
|
+
r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setPath(this.path), r.setWithCredentials(this.withCredentials), r.load(
|
|
2008
|
+
t,
|
|
1874
2009
|
(o) => {
|
|
1875
|
-
this.parseAsync(
|
|
1876
|
-
|
|
2010
|
+
this.parseAsync(t, o).then((i) => {
|
|
2011
|
+
e && e(i);
|
|
1877
2012
|
}).catch((i) => {
|
|
1878
|
-
this.manager.itemError(
|
|
2013
|
+
this.manager.itemError(t), n && n(i), console.error("Error loading SOGS meta:", i);
|
|
1879
2014
|
});
|
|
1880
2015
|
},
|
|
1881
2016
|
s,
|
|
1882
|
-
|
|
2017
|
+
n
|
|
1883
2018
|
);
|
|
1884
2019
|
}
|
|
1885
2020
|
/**
|
|
@@ -1888,52 +2023,52 @@ class ft extends h.Loader {
|
|
|
1888
2023
|
* @param onProgress Optional progress callback
|
|
1889
2024
|
* @returns A Promise that resolves with the parsed SplatData
|
|
1890
2025
|
*/
|
|
1891
|
-
loadAsync(
|
|
1892
|
-
return new Promise((s,
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1895
|
-
|
|
2026
|
+
loadAsync(t, e) {
|
|
2027
|
+
return new Promise((s, n) => {
|
|
2028
|
+
const r = new l.FileLoader(this.manager);
|
|
2029
|
+
r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setPath(this.path), r.setWithCredentials(this.withCredentials), r.load(
|
|
2030
|
+
t,
|
|
1896
2031
|
(o) => {
|
|
1897
|
-
this.parseAsync(
|
|
1898
|
-
|
|
2032
|
+
this.parseAsync(t, o).then(s).catch((i) => {
|
|
2033
|
+
n(i), this.manager.itemError(t);
|
|
1899
2034
|
});
|
|
1900
2035
|
},
|
|
1901
|
-
|
|
2036
|
+
e,
|
|
1902
2037
|
(o) => {
|
|
1903
|
-
|
|
2038
|
+
n(o), this.manager.itemError(t);
|
|
1904
2039
|
}
|
|
1905
2040
|
);
|
|
1906
2041
|
});
|
|
1907
2042
|
}
|
|
1908
|
-
async parseAsync(
|
|
1909
|
-
if (!(
|
|
1910
|
-
if (this.isZipBuffer(
|
|
1911
|
-
const
|
|
1912
|
-
return this.parseMetaAsync(
|
|
2043
|
+
async parseAsync(t, e) {
|
|
2044
|
+
if (!(e instanceof ArrayBuffer)) throw new Error("SOGS loader: expected ArrayBuffer payload");
|
|
2045
|
+
if (this.isZipBuffer(e)) return this.parseZipAsync(e);
|
|
2046
|
+
const n = new TextDecoder("utf-8").decode(e), r = JSON.parse(n);
|
|
2047
|
+
return this.parseMetaAsync(t, r);
|
|
1913
2048
|
}
|
|
1914
|
-
async parseMetaAsync(
|
|
1915
|
-
const { numSplats:
|
|
1916
|
-
|
|
1917
|
-
const
|
|
2049
|
+
async parseMetaAsync(t, e) {
|
|
2050
|
+
const s = Ut(e), { numSplats: n, files: r, ranges: o, version: i } = s, u = new l.TextureLoader(this.manager);
|
|
2051
|
+
u.setPath(this.path), u.setRequestHeader(this.requestHeader), u.setWithCredentials(this.withCredentials);
|
|
2052
|
+
const y = (F, O) => {
|
|
1918
2053
|
try {
|
|
1919
|
-
return new URL(
|
|
2054
|
+
return new URL(O, F).toString();
|
|
1920
2055
|
} catch {
|
|
1921
|
-
return
|
|
2056
|
+
return F.substring(0, F.lastIndexOf("/") + 1) + O;
|
|
1922
2057
|
}
|
|
1923
|
-
},
|
|
1924
|
-
const
|
|
1925
|
-
return new Promise((
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
(
|
|
1929
|
-
|
|
2058
|
+
}, m = (F, O) => {
|
|
2059
|
+
const V = y(t, F);
|
|
2060
|
+
return new Promise((k, M) => {
|
|
2061
|
+
u.load(
|
|
2062
|
+
V,
|
|
2063
|
+
(B) => {
|
|
2064
|
+
B.generateMipmaps = !1, B.magFilter = l.NearestFilter, B.minFilter = l.NearestFilter, B.flipY = !1, k(B);
|
|
1930
2065
|
},
|
|
1931
2066
|
void 0,
|
|
1932
|
-
(
|
|
1933
|
-
const
|
|
1934
|
-
|
|
2067
|
+
(B) => {
|
|
2068
|
+
const S = B instanceof Error ? B.message : String(B);
|
|
2069
|
+
M(
|
|
1935
2070
|
new Error(
|
|
1936
|
-
`SOGS loader: failed to load ${
|
|
2071
|
+
`SOGS loader: failed to load ${O} (${F}): ${S}`
|
|
1937
2072
|
)
|
|
1938
2073
|
);
|
|
1939
2074
|
}
|
|
@@ -1944,49 +2079,54 @@ class ft extends h.Loader {
|
|
|
1944
2079
|
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)");
|
|
1945
2080
|
if (!Array.isArray(r.quats) || r.quats.length < 1) throw new Error("SOGS loader: files.quats must have at least 1 entry");
|
|
1946
2081
|
if (!Array.isArray(r.scales) || r.scales.length < 1) throw new Error("SOGS loader: files.scales must have at least 1 entry");
|
|
1947
|
-
const [
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
]),
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
2082
|
+
const [c, h, d, w, A] = await Promise.all([
|
|
2083
|
+
m(r.means[0], "means_l"),
|
|
2084
|
+
m(r.means[1], "means_u"),
|
|
2085
|
+
m(r.quats[0], "quats"),
|
|
2086
|
+
m(r.scales[0], "scales"),
|
|
2087
|
+
m(r.sh0[0], "sh0")
|
|
2088
|
+
]), b = { means_l: c, means_u: h, quats: d, scales: w, sh0: A };
|
|
2089
|
+
if (i === 1) {
|
|
2090
|
+
const F = new Ft(n, o, b), O = gt.packSogs(F);
|
|
2091
|
+
return F.dispose(), O;
|
|
2092
|
+
}
|
|
2093
|
+
const z = new Pt(n, o, b), _ = gt.packSog2(z);
|
|
2094
|
+
return z.dispose(), _;
|
|
2095
|
+
}
|
|
2096
|
+
async parseZipAsync(t) {
|
|
2097
|
+
const e = xe(new Uint8Array(t)), s = Object.keys(e), n = s.find((g) => g.toLowerCase().endsWith("meta.json")) ?? null;
|
|
2098
|
+
if (!n) throw new Error("SOGS loader: zip missing meta.json");
|
|
2099
|
+
const r = n.includes("/") ? n.slice(0, n.lastIndexOf("/") + 1) : "", o = new TextDecoder(), i = JSON.parse(o.decode(e[n])), u = Ut(i), { numSplats: y, files: m, ranges: c, version: h } = u, d = (g) => g.replace(/\\/g, "/").replace(/^\.?\//, ""), w = (g) => {
|
|
2100
|
+
const v = d(g), T = [d(r + v), v];
|
|
2101
|
+
for (const P of T) {
|
|
2102
|
+
const f = e[P];
|
|
2103
|
+
if (f) return f;
|
|
1964
2104
|
}
|
|
1965
|
-
const
|
|
1966
|
-
if (
|
|
1967
|
-
throw new Error(`SOGS loader: zip missing file "${
|
|
1968
|
-
},
|
|
1969
|
-
const
|
|
1970
|
-
return
|
|
1971
|
-
},
|
|
1972
|
-
|
|
1973
|
-
const
|
|
1974
|
-
const
|
|
1975
|
-
type:
|
|
1976
|
-
}),
|
|
1977
|
-
return new Promise((
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
(
|
|
1981
|
-
URL.revokeObjectURL(
|
|
2105
|
+
const U = v.split("/").pop(), I = s.find((P) => d(P).endsWith("/" + v)) ?? s.find((P) => d(P).endsWith("/" + U)) ?? s.find((P) => d(P) === U) ?? null;
|
|
2106
|
+
if (I) return e[I];
|
|
2107
|
+
throw new Error(`SOGS loader: zip missing file "${g}"`);
|
|
2108
|
+
}, A = (g) => {
|
|
2109
|
+
const v = g.toLowerCase();
|
|
2110
|
+
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 l.TextureLoader(this.manager);
|
|
2112
|
+
b.setRequestHeader(this.requestHeader), b.setWithCredentials(this.withCredentials);
|
|
2113
|
+
const z = (g, v) => {
|
|
2114
|
+
const T = w(g), U = new Blob([T], {
|
|
2115
|
+
type: A(g)
|
|
2116
|
+
}), I = URL.createObjectURL(U);
|
|
2117
|
+
return new Promise((P, f) => {
|
|
2118
|
+
b.load(
|
|
2119
|
+
I,
|
|
2120
|
+
(C) => {
|
|
2121
|
+
URL.revokeObjectURL(I), C.generateMipmaps = !1, C.magFilter = l.NearestFilter, C.minFilter = l.NearestFilter, C.flipY = !1, P(C);
|
|
1982
2122
|
},
|
|
1983
2123
|
void 0,
|
|
1984
|
-
(
|
|
1985
|
-
URL.revokeObjectURL(
|
|
1986
|
-
const
|
|
1987
|
-
|
|
2124
|
+
(C) => {
|
|
2125
|
+
URL.revokeObjectURL(I);
|
|
2126
|
+
const Y = C instanceof Error ? C.message : String(C);
|
|
2127
|
+
f(
|
|
1988
2128
|
new Error(
|
|
1989
|
-
`SOGS loader: failed to load ${
|
|
2129
|
+
`SOGS loader: failed to load ${v} from zip (${g}): ${Y}`
|
|
1990
2130
|
)
|
|
1991
2131
|
);
|
|
1992
2132
|
}
|
|
@@ -1997,25 +2137,30 @@ class ft extends h.Loader {
|
|
|
1997
2137
|
if (!Array.isArray(m.means) || m.means.length < 2) throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");
|
|
1998
2138
|
if (!Array.isArray(m.quats) || m.quats.length < 1) throw new Error("SOGS loader: files.quats must have at least 1 entry");
|
|
1999
2139
|
if (!Array.isArray(m.scales) || m.scales.length < 1) throw new Error("SOGS loader: files.scales must have at least 1 entry");
|
|
2000
|
-
const [
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
]),
|
|
2007
|
-
|
|
2140
|
+
const [_, F, O, V, k] = await Promise.all([
|
|
2141
|
+
z(m.means[0], "means_l"),
|
|
2142
|
+
z(m.means[1], "means_u"),
|
|
2143
|
+
z(m.quats[0], "quats"),
|
|
2144
|
+
z(m.scales[0], "scales"),
|
|
2145
|
+
z(m.sh0[0], "sh0")
|
|
2146
|
+
]), M = { means_l: _, means_u: F, quats: O, scales: V, sh0: k };
|
|
2147
|
+
if (h === 1) {
|
|
2148
|
+
const g = new Ft(y, c, M), v = gt.packSogs(g);
|
|
2149
|
+
return g.dispose(), v;
|
|
2150
|
+
}
|
|
2151
|
+
const B = new Pt(y, c, M), S = gt.packSog2(B);
|
|
2152
|
+
return B.dispose(), S;
|
|
2008
2153
|
}
|
|
2009
2154
|
}
|
|
2010
|
-
const
|
|
2155
|
+
const be = "0.3.0";
|
|
2011
2156
|
export {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2157
|
+
wt as BoundingBox,
|
|
2158
|
+
ve as PlyLoader,
|
|
2159
|
+
Me as SogsLoader,
|
|
2160
|
+
At as SplatData,
|
|
2161
|
+
Qt as SplatMaterial,
|
|
2162
|
+
Rt as SplatMesh,
|
|
2163
|
+
Yt as SplatSorter,
|
|
2164
|
+
Ht as TextureManager,
|
|
2165
|
+
be as VERSION
|
|
2021
2166
|
};
|