@manycore/aholo-viewer 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +14937 -0
- package/dist/index.js +68061 -0
- package/dist/index.js.map +7 -0
- package/dist/splat-worker.js +3728 -0
- package/dist/splat-worker.js.map +7 -0
- package/package.json +35 -0
|
@@ -0,0 +1,3728 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/fflate@0.8.2/node_modules/fflate/esm/browser.js
|
|
2
|
+
var u8 = Uint8Array;
|
|
3
|
+
var u16 = Uint16Array;
|
|
4
|
+
var i32 = Int32Array;
|
|
5
|
+
var fleb = new u8([
|
|
6
|
+
0,
|
|
7
|
+
0,
|
|
8
|
+
0,
|
|
9
|
+
0,
|
|
10
|
+
0,
|
|
11
|
+
0,
|
|
12
|
+
0,
|
|
13
|
+
0,
|
|
14
|
+
1,
|
|
15
|
+
1,
|
|
16
|
+
1,
|
|
17
|
+
1,
|
|
18
|
+
2,
|
|
19
|
+
2,
|
|
20
|
+
2,
|
|
21
|
+
2,
|
|
22
|
+
3,
|
|
23
|
+
3,
|
|
24
|
+
3,
|
|
25
|
+
3,
|
|
26
|
+
4,
|
|
27
|
+
4,
|
|
28
|
+
4,
|
|
29
|
+
4,
|
|
30
|
+
5,
|
|
31
|
+
5,
|
|
32
|
+
5,
|
|
33
|
+
5,
|
|
34
|
+
0,
|
|
35
|
+
/* unused */
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
38
|
+
/* impossible */
|
|
39
|
+
0
|
|
40
|
+
]);
|
|
41
|
+
var fdeb = new u8([
|
|
42
|
+
0,
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
0,
|
|
46
|
+
1,
|
|
47
|
+
1,
|
|
48
|
+
2,
|
|
49
|
+
2,
|
|
50
|
+
3,
|
|
51
|
+
3,
|
|
52
|
+
4,
|
|
53
|
+
4,
|
|
54
|
+
5,
|
|
55
|
+
5,
|
|
56
|
+
6,
|
|
57
|
+
6,
|
|
58
|
+
7,
|
|
59
|
+
7,
|
|
60
|
+
8,
|
|
61
|
+
8,
|
|
62
|
+
9,
|
|
63
|
+
9,
|
|
64
|
+
10,
|
|
65
|
+
10,
|
|
66
|
+
11,
|
|
67
|
+
11,
|
|
68
|
+
12,
|
|
69
|
+
12,
|
|
70
|
+
13,
|
|
71
|
+
13,
|
|
72
|
+
/* unused */
|
|
73
|
+
0,
|
|
74
|
+
0
|
|
75
|
+
]);
|
|
76
|
+
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
77
|
+
var freb = function(eb, start) {
|
|
78
|
+
var b = new u16(31);
|
|
79
|
+
for (var i = 0; i < 31; ++i) {
|
|
80
|
+
b[i] = start += 1 << eb[i - 1];
|
|
81
|
+
}
|
|
82
|
+
var r = new i32(b[30]);
|
|
83
|
+
for (var i = 1; i < 30; ++i) {
|
|
84
|
+
for (var j = b[i]; j < b[i + 1]; ++j) {
|
|
85
|
+
r[j] = j - b[i] << 5 | i;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { b, r };
|
|
89
|
+
};
|
|
90
|
+
var _a = freb(fleb, 2);
|
|
91
|
+
var fl = _a.b;
|
|
92
|
+
var revfl = _a.r;
|
|
93
|
+
fl[28] = 258, revfl[258] = 28;
|
|
94
|
+
var _b = freb(fdeb, 0);
|
|
95
|
+
var fd = _b.b;
|
|
96
|
+
var revfd = _b.r;
|
|
97
|
+
var rev = new u16(32768);
|
|
98
|
+
for (i = 0; i < 32768; ++i) {
|
|
99
|
+
x = (i & 43690) >> 1 | (i & 21845) << 1;
|
|
100
|
+
x = (x & 52428) >> 2 | (x & 13107) << 2;
|
|
101
|
+
x = (x & 61680) >> 4 | (x & 3855) << 4;
|
|
102
|
+
rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
|
|
103
|
+
}
|
|
104
|
+
var x;
|
|
105
|
+
var i;
|
|
106
|
+
var hMap = (function(cd, mb, r) {
|
|
107
|
+
var s = cd.length;
|
|
108
|
+
var i = 0;
|
|
109
|
+
var l = new u16(mb);
|
|
110
|
+
for (; i < s; ++i) {
|
|
111
|
+
if (cd[i])
|
|
112
|
+
++l[cd[i] - 1];
|
|
113
|
+
}
|
|
114
|
+
var le = new u16(mb);
|
|
115
|
+
for (i = 1; i < mb; ++i) {
|
|
116
|
+
le[i] = le[i - 1] + l[i - 1] << 1;
|
|
117
|
+
}
|
|
118
|
+
var co;
|
|
119
|
+
if (r) {
|
|
120
|
+
co = new u16(1 << mb);
|
|
121
|
+
var rvb = 15 - mb;
|
|
122
|
+
for (i = 0; i < s; ++i) {
|
|
123
|
+
if (cd[i]) {
|
|
124
|
+
var sv = i << 4 | cd[i];
|
|
125
|
+
var r_1 = mb - cd[i];
|
|
126
|
+
var v = le[cd[i] - 1]++ << r_1;
|
|
127
|
+
for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
|
|
128
|
+
co[rev[v] >> rvb] = sv;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
co = new u16(s);
|
|
134
|
+
for (i = 0; i < s; ++i) {
|
|
135
|
+
if (cd[i]) {
|
|
136
|
+
co[i] = rev[le[cd[i] - 1]++] >> 15 - cd[i];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return co;
|
|
141
|
+
});
|
|
142
|
+
var flt = new u8(288);
|
|
143
|
+
for (i = 0; i < 144; ++i)
|
|
144
|
+
flt[i] = 8;
|
|
145
|
+
var i;
|
|
146
|
+
for (i = 144; i < 256; ++i)
|
|
147
|
+
flt[i] = 9;
|
|
148
|
+
var i;
|
|
149
|
+
for (i = 256; i < 280; ++i)
|
|
150
|
+
flt[i] = 7;
|
|
151
|
+
var i;
|
|
152
|
+
for (i = 280; i < 288; ++i)
|
|
153
|
+
flt[i] = 8;
|
|
154
|
+
var i;
|
|
155
|
+
var fdt = new u8(32);
|
|
156
|
+
for (i = 0; i < 32; ++i)
|
|
157
|
+
fdt[i] = 5;
|
|
158
|
+
var i;
|
|
159
|
+
var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
|
|
160
|
+
var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
|
|
161
|
+
var max = function(a) {
|
|
162
|
+
var m = a[0];
|
|
163
|
+
for (var i = 1; i < a.length; ++i) {
|
|
164
|
+
if (a[i] > m)
|
|
165
|
+
m = a[i];
|
|
166
|
+
}
|
|
167
|
+
return m;
|
|
168
|
+
};
|
|
169
|
+
var bits = function(d, p, m) {
|
|
170
|
+
var o = p / 8 | 0;
|
|
171
|
+
return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
|
|
172
|
+
};
|
|
173
|
+
var bits16 = function(d, p) {
|
|
174
|
+
var o = p / 8 | 0;
|
|
175
|
+
return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
|
|
176
|
+
};
|
|
177
|
+
var shft = function(p) {
|
|
178
|
+
return (p + 7) / 8 | 0;
|
|
179
|
+
};
|
|
180
|
+
var slc = function(v, s, e) {
|
|
181
|
+
if (s == null || s < 0)
|
|
182
|
+
s = 0;
|
|
183
|
+
if (e == null || e > v.length)
|
|
184
|
+
e = v.length;
|
|
185
|
+
return new u8(v.subarray(s, e));
|
|
186
|
+
};
|
|
187
|
+
var ec = [
|
|
188
|
+
"unexpected EOF",
|
|
189
|
+
"invalid block type",
|
|
190
|
+
"invalid length/literal",
|
|
191
|
+
"invalid distance",
|
|
192
|
+
"stream finished",
|
|
193
|
+
"no stream handler",
|
|
194
|
+
,
|
|
195
|
+
"no callback",
|
|
196
|
+
"invalid UTF-8 data",
|
|
197
|
+
"extra field too long",
|
|
198
|
+
"date not in range 1980-2099",
|
|
199
|
+
"filename too long",
|
|
200
|
+
"stream finishing",
|
|
201
|
+
"invalid zip data"
|
|
202
|
+
// determined by unknown compression method
|
|
203
|
+
];
|
|
204
|
+
var err = function(ind, msg, nt) {
|
|
205
|
+
var e = new Error(msg || ec[ind]);
|
|
206
|
+
e.code = ind;
|
|
207
|
+
if (Error.captureStackTrace)
|
|
208
|
+
Error.captureStackTrace(e, err);
|
|
209
|
+
if (!nt)
|
|
210
|
+
throw e;
|
|
211
|
+
return e;
|
|
212
|
+
};
|
|
213
|
+
var inflt = function(dat, st, buf, dict) {
|
|
214
|
+
var sl = dat.length, dl = dict ? dict.length : 0;
|
|
215
|
+
if (!sl || st.f && !st.l)
|
|
216
|
+
return buf || new u8(0);
|
|
217
|
+
var noBuf = !buf;
|
|
218
|
+
var resize = noBuf || st.i != 2;
|
|
219
|
+
var noSt = st.i;
|
|
220
|
+
if (noBuf)
|
|
221
|
+
buf = new u8(sl * 3);
|
|
222
|
+
var cbuf = function(l2) {
|
|
223
|
+
var bl = buf.length;
|
|
224
|
+
if (l2 > bl) {
|
|
225
|
+
var nbuf = new u8(Math.max(bl * 2, l2));
|
|
226
|
+
nbuf.set(buf);
|
|
227
|
+
buf = nbuf;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
|
|
231
|
+
var tbts = sl * 8;
|
|
232
|
+
do {
|
|
233
|
+
if (!lm) {
|
|
234
|
+
final = bits(dat, pos, 1);
|
|
235
|
+
var type = bits(dat, pos + 1, 3);
|
|
236
|
+
pos += 3;
|
|
237
|
+
if (!type) {
|
|
238
|
+
var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
|
|
239
|
+
if (t > sl) {
|
|
240
|
+
if (noSt)
|
|
241
|
+
err(0);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
if (resize)
|
|
245
|
+
cbuf(bt + l);
|
|
246
|
+
buf.set(dat.subarray(s, t), bt);
|
|
247
|
+
st.b = bt += l, st.p = pos = t * 8, st.f = final;
|
|
248
|
+
continue;
|
|
249
|
+
} else if (type == 1)
|
|
250
|
+
lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
|
|
251
|
+
else if (type == 2) {
|
|
252
|
+
var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
|
|
253
|
+
var tl = hLit + bits(dat, pos + 5, 31) + 1;
|
|
254
|
+
pos += 14;
|
|
255
|
+
var ldt = new u8(tl);
|
|
256
|
+
var clt = new u8(19);
|
|
257
|
+
for (var i = 0; i < hcLen; ++i) {
|
|
258
|
+
clt[clim[i]] = bits(dat, pos + i * 3, 7);
|
|
259
|
+
}
|
|
260
|
+
pos += hcLen * 3;
|
|
261
|
+
var clb = max(clt), clbmsk = (1 << clb) - 1;
|
|
262
|
+
var clm = hMap(clt, clb, 1);
|
|
263
|
+
for (var i = 0; i < tl; ) {
|
|
264
|
+
var r = clm[bits(dat, pos, clbmsk)];
|
|
265
|
+
pos += r & 15;
|
|
266
|
+
var s = r >> 4;
|
|
267
|
+
if (s < 16) {
|
|
268
|
+
ldt[i++] = s;
|
|
269
|
+
} else {
|
|
270
|
+
var c = 0, n = 0;
|
|
271
|
+
if (s == 16)
|
|
272
|
+
n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
|
|
273
|
+
else if (s == 17)
|
|
274
|
+
n = 3 + bits(dat, pos, 7), pos += 3;
|
|
275
|
+
else if (s == 18)
|
|
276
|
+
n = 11 + bits(dat, pos, 127), pos += 7;
|
|
277
|
+
while (n--)
|
|
278
|
+
ldt[i++] = c;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
|
|
282
|
+
lbt = max(lt);
|
|
283
|
+
dbt = max(dt);
|
|
284
|
+
lm = hMap(lt, lbt, 1);
|
|
285
|
+
dm = hMap(dt, dbt, 1);
|
|
286
|
+
} else
|
|
287
|
+
err(1);
|
|
288
|
+
if (pos > tbts) {
|
|
289
|
+
if (noSt)
|
|
290
|
+
err(0);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (resize)
|
|
295
|
+
cbuf(bt + 131072);
|
|
296
|
+
var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
|
|
297
|
+
var lpos = pos;
|
|
298
|
+
for (; ; lpos = pos) {
|
|
299
|
+
var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
|
|
300
|
+
pos += c & 15;
|
|
301
|
+
if (pos > tbts) {
|
|
302
|
+
if (noSt)
|
|
303
|
+
err(0);
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
if (!c)
|
|
307
|
+
err(2);
|
|
308
|
+
if (sym < 256)
|
|
309
|
+
buf[bt++] = sym;
|
|
310
|
+
else if (sym == 256) {
|
|
311
|
+
lpos = pos, lm = null;
|
|
312
|
+
break;
|
|
313
|
+
} else {
|
|
314
|
+
var add = sym - 254;
|
|
315
|
+
if (sym > 264) {
|
|
316
|
+
var i = sym - 257, b = fleb[i];
|
|
317
|
+
add = bits(dat, pos, (1 << b) - 1) + fl[i];
|
|
318
|
+
pos += b;
|
|
319
|
+
}
|
|
320
|
+
var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
|
|
321
|
+
if (!d)
|
|
322
|
+
err(3);
|
|
323
|
+
pos += d & 15;
|
|
324
|
+
var dt = fd[dsym];
|
|
325
|
+
if (dsym > 3) {
|
|
326
|
+
var b = fdeb[dsym];
|
|
327
|
+
dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
|
|
328
|
+
}
|
|
329
|
+
if (pos > tbts) {
|
|
330
|
+
if (noSt)
|
|
331
|
+
err(0);
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
if (resize)
|
|
335
|
+
cbuf(bt + 131072);
|
|
336
|
+
var end = bt + add;
|
|
337
|
+
if (bt < dt) {
|
|
338
|
+
var shift = dl - dt, dend = Math.min(dt, end);
|
|
339
|
+
if (shift + bt < 0)
|
|
340
|
+
err(3);
|
|
341
|
+
for (; bt < dend; ++bt)
|
|
342
|
+
buf[bt] = dict[shift + bt];
|
|
343
|
+
}
|
|
344
|
+
for (; bt < end; ++bt)
|
|
345
|
+
buf[bt] = buf[bt - dt];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
st.l = lm, st.p = lpos, st.b = bt, st.f = final;
|
|
349
|
+
if (lm)
|
|
350
|
+
final = 1, st.m = lbt, st.d = dm, st.n = dbt;
|
|
351
|
+
} while (!final);
|
|
352
|
+
return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
|
|
353
|
+
};
|
|
354
|
+
var et = /* @__PURE__ */ new u8(0);
|
|
355
|
+
var b2 = function(d, b) {
|
|
356
|
+
return d[b] | d[b + 1] << 8;
|
|
357
|
+
};
|
|
358
|
+
var b4 = function(d, b) {
|
|
359
|
+
return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0;
|
|
360
|
+
};
|
|
361
|
+
var b8 = function(d, b) {
|
|
362
|
+
return b4(d, b) + b4(d, b + 4) * 4294967296;
|
|
363
|
+
};
|
|
364
|
+
function inflateSync(data, opts) {
|
|
365
|
+
return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
|
|
366
|
+
}
|
|
367
|
+
var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
|
|
368
|
+
var tds = 0;
|
|
369
|
+
try {
|
|
370
|
+
td.decode(et, { stream: true });
|
|
371
|
+
tds = 1;
|
|
372
|
+
} catch (e) {
|
|
373
|
+
}
|
|
374
|
+
var dutf8 = function(d) {
|
|
375
|
+
for (var r = "", i = 0; ; ) {
|
|
376
|
+
var c = d[i++];
|
|
377
|
+
var eb = (c > 127) + (c > 223) + (c > 239);
|
|
378
|
+
if (i + eb > d.length)
|
|
379
|
+
return { s: r, r: slc(d, i - 1) };
|
|
380
|
+
if (!eb)
|
|
381
|
+
r += String.fromCharCode(c);
|
|
382
|
+
else if (eb == 3) {
|
|
383
|
+
c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | d[i++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
|
|
384
|
+
} else if (eb & 1)
|
|
385
|
+
r += String.fromCharCode((c & 31) << 6 | d[i++] & 63);
|
|
386
|
+
else
|
|
387
|
+
r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | d[i++] & 63);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
function strFromU8(dat, latin1) {
|
|
391
|
+
if (latin1) {
|
|
392
|
+
var r = "";
|
|
393
|
+
for (var i = 0; i < dat.length; i += 16384)
|
|
394
|
+
r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));
|
|
395
|
+
return r;
|
|
396
|
+
} else if (td) {
|
|
397
|
+
return td.decode(dat);
|
|
398
|
+
} else {
|
|
399
|
+
var _a2 = dutf8(dat), s = _a2.s, r = _a2.r;
|
|
400
|
+
if (r.length)
|
|
401
|
+
err(8);
|
|
402
|
+
return s;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
var slzh = function(d, b) {
|
|
406
|
+
return b + 30 + b2(d, b + 26) + b2(d, b + 28);
|
|
407
|
+
};
|
|
408
|
+
var zh = function(d, b, z) {
|
|
409
|
+
var fnl = b2(d, b + 28), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl, bs = b4(d, b + 20);
|
|
410
|
+
var _a2 = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a2[0], su = _a2[1], off = _a2[2];
|
|
411
|
+
return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off];
|
|
412
|
+
};
|
|
413
|
+
var z64e = function(d, b) {
|
|
414
|
+
for (; b2(d, b) != 1; b += 4 + b2(d, b + 2))
|
|
415
|
+
;
|
|
416
|
+
return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)];
|
|
417
|
+
};
|
|
418
|
+
function unzipSync(data, opts) {
|
|
419
|
+
var files = {};
|
|
420
|
+
var e = data.length - 22;
|
|
421
|
+
for (; b4(data, e) != 101010256; --e) {
|
|
422
|
+
if (!e || data.length - e > 65558)
|
|
423
|
+
err(13);
|
|
424
|
+
}
|
|
425
|
+
;
|
|
426
|
+
var c = b2(data, e + 8);
|
|
427
|
+
if (!c)
|
|
428
|
+
return {};
|
|
429
|
+
var o = b4(data, e + 16);
|
|
430
|
+
var z = o == 4294967295 || c == 65535;
|
|
431
|
+
if (z) {
|
|
432
|
+
var ze = b4(data, e - 12);
|
|
433
|
+
z = b4(data, ze) == 101075792;
|
|
434
|
+
if (z) {
|
|
435
|
+
c = b4(data, ze + 32);
|
|
436
|
+
o = b4(data, ze + 48);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
var fltr = opts && opts.filter;
|
|
440
|
+
for (var i = 0; i < c; ++i) {
|
|
441
|
+
var _a2 = zh(data, o, z), c_2 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off);
|
|
442
|
+
o = no;
|
|
443
|
+
if (!fltr || fltr({
|
|
444
|
+
name: fn,
|
|
445
|
+
size: sc,
|
|
446
|
+
originalSize: su,
|
|
447
|
+
compression: c_2
|
|
448
|
+
})) {
|
|
449
|
+
if (!c_2)
|
|
450
|
+
files[fn] = slc(data, b, b + sc);
|
|
451
|
+
else if (c_2 == 8)
|
|
452
|
+
files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
|
|
453
|
+
else
|
|
454
|
+
err(14, "unknown compression type " + c_2);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return files;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ../../external/egs-core/packages/loaders/splat-loader/utils.ts
|
|
461
|
+
var DEPTH_INFINITY = 31743;
|
|
462
|
+
var buckets = new Uint32Array(65536);
|
|
463
|
+
function sortSplats(counts, sorting, order) {
|
|
464
|
+
buckets.fill(0);
|
|
465
|
+
for (let i = 0; i < counts; i++) {
|
|
466
|
+
buckets[sorting[i]]++;
|
|
467
|
+
}
|
|
468
|
+
let activeSplats = 0;
|
|
469
|
+
for (let i = DEPTH_INFINITY - 1; i >= 0; i--) {
|
|
470
|
+
const v = buckets[i];
|
|
471
|
+
buckets[i] = activeSplats;
|
|
472
|
+
activeSplats += v;
|
|
473
|
+
}
|
|
474
|
+
for (let i = 0; i < counts; i++) {
|
|
475
|
+
const v = sorting[i];
|
|
476
|
+
if (v < DEPTH_INFINITY) {
|
|
477
|
+
order[buckets[v]++] = i;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return activeSplats;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// ../../external/egs-core/packages/egs-lib/src/env.ts
|
|
484
|
+
var isDebugEnable;
|
|
485
|
+
try {
|
|
486
|
+
if (isDebugEnable == null && (CONFIG.IS_DEV || CONFIG.IS_TESTING || CONFIG.IS_DEV_OR_TESTING)) {
|
|
487
|
+
isDebugEnable = true;
|
|
488
|
+
}
|
|
489
|
+
} catch (e) {
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
if (isDebugEnable == null && true) {
|
|
493
|
+
isDebugEnable = true;
|
|
494
|
+
}
|
|
495
|
+
} catch (e) {
|
|
496
|
+
}
|
|
497
|
+
try {
|
|
498
|
+
if (isDebugEnable == null) {
|
|
499
|
+
const urlParam = new URLSearchParams(location.search);
|
|
500
|
+
if (urlParam.has("__enable_debug__")) {
|
|
501
|
+
isDebugEnable = true;
|
|
502
|
+
} else if (urlParam.has("__disable_debug__")) {
|
|
503
|
+
isDebugEnable = false;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
} catch (e) {
|
|
507
|
+
}
|
|
508
|
+
if (isDebugEnable == null) {
|
|
509
|
+
isDebugEnable = false;
|
|
510
|
+
}
|
|
511
|
+
var ENV = {
|
|
512
|
+
isDebugEnable
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// ../../external/egs-core/packages/egs-lib/src/logger.ts
|
|
516
|
+
var _Logger = class _Logger {
|
|
517
|
+
constructor() {
|
|
518
|
+
this.exceptionCount = 0;
|
|
519
|
+
}
|
|
520
|
+
info(...param) {
|
|
521
|
+
if (!ENV.isDebugEnable) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
console.log("EGS:", ...param);
|
|
525
|
+
}
|
|
526
|
+
warn(...param) {
|
|
527
|
+
if (!ENV.isDebugEnable) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
console.warn("EGS:", ...param);
|
|
531
|
+
}
|
|
532
|
+
error(content, type = "Unreachable" /* Unreachable */) {
|
|
533
|
+
if (!ENV.isDebugEnable && this.exceptionCount >= _Logger.MAX_EXCEPTION_SIZE) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const error = typeof content === "string" ? new Error(`EGS Exception: <${type}> ${content}`) : content;
|
|
537
|
+
console.error(error);
|
|
538
|
+
}
|
|
539
|
+
// logic error
|
|
540
|
+
unreachable(content) {
|
|
541
|
+
this.error(content, "Unreachable" /* Unreachable */);
|
|
542
|
+
}
|
|
543
|
+
// platform issue
|
|
544
|
+
unsupported(content) {
|
|
545
|
+
this.error(content, "Unsupported" /* Unsupported */);
|
|
546
|
+
}
|
|
547
|
+
// user input invalid
|
|
548
|
+
invalidInput(content) {
|
|
549
|
+
this.error(content, "InvalidInput" /* InvalidInput */);
|
|
550
|
+
}
|
|
551
|
+
// webgl error
|
|
552
|
+
webglError(content) {
|
|
553
|
+
this.error(content, "WebglError" /* WebglError */);
|
|
554
|
+
}
|
|
555
|
+
webGpuError(content) {
|
|
556
|
+
this.error(content, "WebGpuError" /* WebGpuError */);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
_Logger.MAX_EXCEPTION_SIZE = 1024;
|
|
560
|
+
var Logger = _Logger;
|
|
561
|
+
var logger = new Logger();
|
|
562
|
+
|
|
563
|
+
// ../../external/egs-core/packages/egs-lib/src/promise.ts
|
|
564
|
+
function deferred() {
|
|
565
|
+
let resolve = () => {
|
|
566
|
+
};
|
|
567
|
+
let reject = () => {
|
|
568
|
+
};
|
|
569
|
+
const promise = new Promise(function(resolveInner, rejectInner) {
|
|
570
|
+
resolve = resolveInner;
|
|
571
|
+
reject = rejectInner;
|
|
572
|
+
});
|
|
573
|
+
return {
|
|
574
|
+
promise,
|
|
575
|
+
resolve,
|
|
576
|
+
reject
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// ../../external/egs-core/packages/egs-lib/src/worker.ts
|
|
581
|
+
var WorkerFlags = {
|
|
582
|
+
BUSY: 1,
|
|
583
|
+
ALIVE: 2,
|
|
584
|
+
PERMANENT: 4,
|
|
585
|
+
KEEP: 1 | 4
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// ../../external/egs-core/packages/loaders/splat-loader/splat/SplatData.ts
|
|
589
|
+
var SplatData = class {
|
|
590
|
+
constructor(maxShDegree = 3, maxTextureSize = 16384, blockCounts = 1) {
|
|
591
|
+
this.totalBlockCounts = 0;
|
|
592
|
+
this.totalBlockShDegree = 3;
|
|
593
|
+
this.blockOffsets = [];
|
|
594
|
+
this.blockExecs = [];
|
|
595
|
+
this.currentBlockIndex = 0;
|
|
596
|
+
this.blockCounts = blockCounts;
|
|
597
|
+
this.maxShDegree = maxShDegree;
|
|
598
|
+
this.maxTextureSize = maxTextureSize;
|
|
599
|
+
}
|
|
600
|
+
initBlock(counts, shDegree) {
|
|
601
|
+
this.blockOffsets.push(this.totalBlockCounts);
|
|
602
|
+
this.totalBlockCounts += counts;
|
|
603
|
+
this.totalBlockShDegree = Math.min(shDegree, this.totalBlockShDegree);
|
|
604
|
+
const { promise, resolve } = deferred();
|
|
605
|
+
this.blockExecs.push(resolve);
|
|
606
|
+
if (this.blockOffsets.length === this.blockCounts) {
|
|
607
|
+
this.init(this.totalBlockCounts, this.totalBlockShDegree);
|
|
608
|
+
this.blockExecs[this.currentBlockIndex](this.blockOffsets[0]);
|
|
609
|
+
}
|
|
610
|
+
return promise;
|
|
611
|
+
}
|
|
612
|
+
finishBlock() {
|
|
613
|
+
this.currentBlockIndex++;
|
|
614
|
+
this.blockExecs[this.currentBlockIndex]?.(this.blockOffsets[this.currentBlockIndex]);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// ../../external/egs-core/packages/loaders/splat-loader/splat/utils.ts
|
|
619
|
+
var SH_MAPS = {
|
|
620
|
+
0: 0,
|
|
621
|
+
1: 9,
|
|
622
|
+
2: 24,
|
|
623
|
+
3: 45
|
|
624
|
+
};
|
|
625
|
+
function computeTextureSize(counts, maxTextureSize) {
|
|
626
|
+
if (counts === 0) {
|
|
627
|
+
return { w: 0, h: 0, d: 0 };
|
|
628
|
+
}
|
|
629
|
+
const width = Math.min(Math.ceil(Math.sqrt(counts) / 2) * 2, maxTextureSize);
|
|
630
|
+
const height = Math.min(Math.ceil(counts / width), maxTextureSize);
|
|
631
|
+
const depth = Math.ceil(counts / (width * height));
|
|
632
|
+
return { w: width, h: height, d: depth };
|
|
633
|
+
}
|
|
634
|
+
function clamp(v, min, max2) {
|
|
635
|
+
return Math.min(Math.max(v, min), max2);
|
|
636
|
+
}
|
|
637
|
+
var f32buffer = new Float32Array(1);
|
|
638
|
+
var u32buffer = new Uint32Array(f32buffer.buffer);
|
|
639
|
+
function toHalf(f) {
|
|
640
|
+
f32buffer[0] = f;
|
|
641
|
+
const bits2 = u32buffer[0];
|
|
642
|
+
const sign = bits2 >> 31 & 1;
|
|
643
|
+
const exp = bits2 >> 23 & 255;
|
|
644
|
+
const frac = bits2 & 8388607;
|
|
645
|
+
const halfSign = sign << 15;
|
|
646
|
+
if (exp === 255) {
|
|
647
|
+
if (frac !== 0) {
|
|
648
|
+
return halfSign | 32767;
|
|
649
|
+
}
|
|
650
|
+
return halfSign | 31744;
|
|
651
|
+
}
|
|
652
|
+
const newExp = exp - 127 + 15;
|
|
653
|
+
if (newExp >= 31) {
|
|
654
|
+
return halfSign | 31744;
|
|
655
|
+
}
|
|
656
|
+
if (newExp <= 0) {
|
|
657
|
+
if (newExp < -10) {
|
|
658
|
+
return halfSign;
|
|
659
|
+
}
|
|
660
|
+
const subFrac = (frac | 8388608) >> 1 - newExp + 13;
|
|
661
|
+
return halfSign | subFrac;
|
|
662
|
+
}
|
|
663
|
+
const halfFrac = frac >> 13;
|
|
664
|
+
return halfSign | newExp << 10 | halfFrac;
|
|
665
|
+
}
|
|
666
|
+
function fromHalf(h) {
|
|
667
|
+
const sign = h >> 15 & 1;
|
|
668
|
+
const exp = h >> 10 & 31;
|
|
669
|
+
const frac = h & 1023;
|
|
670
|
+
let f32bits;
|
|
671
|
+
if (exp === 0) {
|
|
672
|
+
if (frac === 0) {
|
|
673
|
+
f32bits = sign << 31;
|
|
674
|
+
} else {
|
|
675
|
+
let mant = frac;
|
|
676
|
+
let e = -14;
|
|
677
|
+
while ((mant & 1024) === 0) {
|
|
678
|
+
mant <<= 1;
|
|
679
|
+
e--;
|
|
680
|
+
}
|
|
681
|
+
mant &= 1023;
|
|
682
|
+
const newExp = e + 127;
|
|
683
|
+
const newFrac = mant << 13;
|
|
684
|
+
f32bits = sign << 31 | newExp << 23 | newFrac;
|
|
685
|
+
}
|
|
686
|
+
} else if (exp === 31) {
|
|
687
|
+
if (frac === 0) {
|
|
688
|
+
f32bits = sign << 31 | 2139095040;
|
|
689
|
+
} else {
|
|
690
|
+
f32bits = sign << 31 | 2143289344;
|
|
691
|
+
}
|
|
692
|
+
} else {
|
|
693
|
+
const newExp = exp - 15 + 127;
|
|
694
|
+
const newFrac = frac << 13;
|
|
695
|
+
f32bits = sign << 31 | newExp << 23 | newFrac;
|
|
696
|
+
}
|
|
697
|
+
u32buffer[0] = f32bits;
|
|
698
|
+
return f32buffer[0];
|
|
699
|
+
}
|
|
700
|
+
var Vector3 = class {
|
|
701
|
+
constructor(x, y, z) {
|
|
702
|
+
this.x = x;
|
|
703
|
+
this.y = y;
|
|
704
|
+
this.z = z;
|
|
705
|
+
}
|
|
706
|
+
set(x, y, z) {
|
|
707
|
+
this.x = x;
|
|
708
|
+
this.y = y;
|
|
709
|
+
this.z = z;
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
length() {
|
|
713
|
+
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
714
|
+
}
|
|
715
|
+
divideScalar(scalar) {
|
|
716
|
+
const invLength = 1 / scalar;
|
|
717
|
+
this.x *= invLength;
|
|
718
|
+
this.y *= invLength;
|
|
719
|
+
this.z *= invLength;
|
|
720
|
+
return this;
|
|
721
|
+
}
|
|
722
|
+
normalize() {
|
|
723
|
+
return this.divideScalar(this.length() || 1);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
var Quaternion = class {
|
|
727
|
+
constructor(x, y, z, w) {
|
|
728
|
+
this.x = x;
|
|
729
|
+
this.y = y;
|
|
730
|
+
this.z = z;
|
|
731
|
+
this.w = w;
|
|
732
|
+
}
|
|
733
|
+
set(x, y, z, w) {
|
|
734
|
+
this.x = x;
|
|
735
|
+
this.y = y;
|
|
736
|
+
this.z = z;
|
|
737
|
+
this.w = w;
|
|
738
|
+
return this;
|
|
739
|
+
}
|
|
740
|
+
normalize() {
|
|
741
|
+
const length = Math.sqrt(
|
|
742
|
+
this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w
|
|
743
|
+
);
|
|
744
|
+
if (length === 0) {
|
|
745
|
+
return this;
|
|
746
|
+
}
|
|
747
|
+
const invLength = 1 / length;
|
|
748
|
+
this.x *= invLength;
|
|
749
|
+
this.y *= invLength;
|
|
750
|
+
this.z *= invLength;
|
|
751
|
+
this.w *= invLength;
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
var tempArr = new Array(4);
|
|
756
|
+
var tempVec = new Vector3(0, 0, 0);
|
|
757
|
+
var tempQuat = new Quaternion(0, 0, 0, 1);
|
|
758
|
+
function encodeQuatOct(x, y, z, w) {
|
|
759
|
+
const q = tempQuat.set(x, y, z, w).normalize();
|
|
760
|
+
if (q.w < 0) {
|
|
761
|
+
q.set(-q.x, -q.y, -q.z, -q.w);
|
|
762
|
+
}
|
|
763
|
+
const theta = 2 * Math.acos(q.w);
|
|
764
|
+
const xyz_norm = Math.sqrt(
|
|
765
|
+
q.x * q.x + q.y * q.y + q.z * q.z
|
|
766
|
+
);
|
|
767
|
+
const axis = xyz_norm < 1e-6 ? tempVec.set(1, 0, 0) : tempVec.set(q.x, q.y, q.z).divideScalar(xyz_norm);
|
|
768
|
+
const sum = Math.abs(axis.x) + Math.abs(axis.y) + Math.abs(axis.z);
|
|
769
|
+
let p_x = axis.x / sum;
|
|
770
|
+
let p_y = axis.y / sum;
|
|
771
|
+
if (axis.z < 0) {
|
|
772
|
+
const tmp = p_x;
|
|
773
|
+
p_x = (1 - Math.abs(p_y)) * (p_x >= 0 ? 1 : -1);
|
|
774
|
+
p_y = (1 - Math.abs(tmp)) * (p_y >= 0 ? 1 : -1);
|
|
775
|
+
}
|
|
776
|
+
tempArr[0] = p_x;
|
|
777
|
+
tempArr[1] = p_y;
|
|
778
|
+
tempArr[2] = theta / Math.PI;
|
|
779
|
+
return tempArr;
|
|
780
|
+
}
|
|
781
|
+
function decodeQuatOct(u, v, angle) {
|
|
782
|
+
let f_x = u;
|
|
783
|
+
let f_y = v;
|
|
784
|
+
const f_z = 1 - (Math.abs(f_x) + Math.abs(f_y));
|
|
785
|
+
const t = Math.max(-f_z, 0);
|
|
786
|
+
f_x += f_x >= 0 ? -t : t;
|
|
787
|
+
f_y += f_y >= 0 ? -t : t;
|
|
788
|
+
const axis = tempVec.set(f_x, f_y, f_z).normalize();
|
|
789
|
+
const theta = angle * Math.PI;
|
|
790
|
+
const halfTheta = theta * 0.5;
|
|
791
|
+
const s = Math.sin(halfTheta);
|
|
792
|
+
tempArr[0] = axis.x * s;
|
|
793
|
+
tempArr[1] = axis.y * s;
|
|
794
|
+
tempArr[2] = axis.z * s;
|
|
795
|
+
tempArr[3] = Math.cos(halfTheta);
|
|
796
|
+
return tempArr;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// ../../external/egs-core/packages/loaders/splat-loader/splat/RawSplatData.ts
|
|
800
|
+
var tempQuat2 = new Quaternion(0, 0, 0, 1);
|
|
801
|
+
var RawSplatData = class extends SplatData {
|
|
802
|
+
init(counts, shDegree) {
|
|
803
|
+
this.counts = counts;
|
|
804
|
+
this.shDegree = Math.min(shDegree, this.maxShDegree);
|
|
805
|
+
const shCounts = this.shCounts = SH_MAPS[shDegree];
|
|
806
|
+
this.table = new Array(14 + shCounts).fill(0).map(() => new Float32Array(counts));
|
|
807
|
+
}
|
|
808
|
+
set(i, single) {
|
|
809
|
+
const { table } = this;
|
|
810
|
+
table[0 /* x */][i] = single.x;
|
|
811
|
+
table[1 /* y */][i] = single.y;
|
|
812
|
+
table[2 /* z */][i] = single.z;
|
|
813
|
+
table[3 /* sx */][i] = single.sx;
|
|
814
|
+
table[4 /* sy */][i] = single.sy;
|
|
815
|
+
table[5 /* sz */][i] = single.sz;
|
|
816
|
+
tempQuat2.set(single.qx, single.qy, single.qz, single.qw).normalize();
|
|
817
|
+
table[6 /* qx */][i] = tempQuat2.x;
|
|
818
|
+
table[7 /* qy */][i] = tempQuat2.y;
|
|
819
|
+
table[8 /* qz */][i] = tempQuat2.z;
|
|
820
|
+
table[9 /* qw */][i] = tempQuat2.w;
|
|
821
|
+
table[10 /* r */][i] = single.r;
|
|
822
|
+
table[11 /* g */][i] = single.g;
|
|
823
|
+
table[12 /* b */][i] = single.b;
|
|
824
|
+
table[13 /* a */][i] = single.a;
|
|
825
|
+
}
|
|
826
|
+
setCenter(i, x, y, z) {
|
|
827
|
+
const { table } = this;
|
|
828
|
+
table[0 /* x */][i] = x;
|
|
829
|
+
table[1 /* y */][i] = y;
|
|
830
|
+
table[2 /* z */][i] = z;
|
|
831
|
+
}
|
|
832
|
+
setScale(i, sx, sy, sz) {
|
|
833
|
+
const { table } = this;
|
|
834
|
+
table[3 /* sx */][i] = sx;
|
|
835
|
+
table[4 /* sy */][i] = sy;
|
|
836
|
+
table[5 /* sz */][i] = sz;
|
|
837
|
+
}
|
|
838
|
+
setQuat(i, qx, qy, qz, qw) {
|
|
839
|
+
const { table } = this;
|
|
840
|
+
tempQuat2.set(qx, qy, qz, qw).normalize();
|
|
841
|
+
table[6 /* qx */][i] = tempQuat2.x;
|
|
842
|
+
table[7 /* qy */][i] = tempQuat2.y;
|
|
843
|
+
table[8 /* qz */][i] = tempQuat2.z;
|
|
844
|
+
table[9 /* qw */][i] = tempQuat2.w;
|
|
845
|
+
}
|
|
846
|
+
setColor(i, r, g, b) {
|
|
847
|
+
const { table } = this;
|
|
848
|
+
table[10 /* r */][i] = r;
|
|
849
|
+
table[11 /* g */][i] = g;
|
|
850
|
+
table[12 /* b */][i] = b;
|
|
851
|
+
}
|
|
852
|
+
setAlpha(i, a) {
|
|
853
|
+
const { table } = this;
|
|
854
|
+
table[13 /* a */][i] = a;
|
|
855
|
+
}
|
|
856
|
+
setShN(i, shN) {
|
|
857
|
+
const { table, shCounts } = this;
|
|
858
|
+
const offset = 13 /* a */ + 1;
|
|
859
|
+
for (let j = 0; j < shCounts; j++) {
|
|
860
|
+
table[offset + j][i] = shN[j];
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
get(i, single) {
|
|
864
|
+
const { table } = this;
|
|
865
|
+
single.x = table[0 /* x */][i];
|
|
866
|
+
single.y = table[1 /* y */][i];
|
|
867
|
+
single.z = table[2 /* z */][i];
|
|
868
|
+
single.sx = table[3 /* sx */][i];
|
|
869
|
+
single.sy = table[4 /* sy */][i];
|
|
870
|
+
single.sz = table[5 /* sz */][i];
|
|
871
|
+
single.qx = table[6 /* qx */][i];
|
|
872
|
+
single.qy = table[7 /* qy */][i];
|
|
873
|
+
single.qz = table[8 /* qz */][i];
|
|
874
|
+
single.qw = table[9 /* qw */][i];
|
|
875
|
+
single.r = table[10 /* r */][i];
|
|
876
|
+
single.g = table[11 /* g */][i];
|
|
877
|
+
single.b = table[12 /* b */][i];
|
|
878
|
+
single.a = table[13 /* a */][i];
|
|
879
|
+
}
|
|
880
|
+
getCenter(i, single) {
|
|
881
|
+
const { table } = this;
|
|
882
|
+
single.x = table[0 /* x */][i];
|
|
883
|
+
single.y = table[1 /* y */][i];
|
|
884
|
+
single.z = table[2 /* z */][i];
|
|
885
|
+
}
|
|
886
|
+
getScale(i, single) {
|
|
887
|
+
const { table } = this;
|
|
888
|
+
single.sx = table[3 /* sx */][i];
|
|
889
|
+
single.sy = table[4 /* sy */][i];
|
|
890
|
+
single.sz = table[5 /* sz */][i];
|
|
891
|
+
}
|
|
892
|
+
getQuat(i, single) {
|
|
893
|
+
const { table } = this;
|
|
894
|
+
single.qx = table[6 /* qx */][i];
|
|
895
|
+
single.qy = table[7 /* qy */][i];
|
|
896
|
+
single.qz = table[8 /* qz */][i];
|
|
897
|
+
single.qw = table[9 /* qw */][i];
|
|
898
|
+
}
|
|
899
|
+
getColor(i, single) {
|
|
900
|
+
const { table } = this;
|
|
901
|
+
single.r = table[10 /* r */][i];
|
|
902
|
+
single.g = table[11 /* g */][i];
|
|
903
|
+
single.b = table[12 /* b */][i];
|
|
904
|
+
}
|
|
905
|
+
getAlpha(i, single) {
|
|
906
|
+
const { table } = this;
|
|
907
|
+
single.a = table[13 /* a */][i];
|
|
908
|
+
}
|
|
909
|
+
getShN(i, shN) {
|
|
910
|
+
const { shCounts, table } = this;
|
|
911
|
+
const offset = 13 /* a */ + 1;
|
|
912
|
+
for (let j = 0; j < shCounts; j++) {
|
|
913
|
+
shN[j] = table[offset + j][i];
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
fillCenters(centers) {
|
|
917
|
+
const { counts, table } = this;
|
|
918
|
+
const xBuffer = table[0 /* x */];
|
|
919
|
+
const yBuffer = table[1 /* y */];
|
|
920
|
+
const zBuffer = table[2 /* z */];
|
|
921
|
+
for (let i = 0; i < counts; i++) {
|
|
922
|
+
const i3 = i * 3;
|
|
923
|
+
centers[i3 + 0] = xBuffer[i];
|
|
924
|
+
centers[i3 + 1] = yBuffer[i];
|
|
925
|
+
centers[i3 + 2] = zBuffer[i];
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
serialize() {
|
|
929
|
+
return {
|
|
930
|
+
counts: this.counts,
|
|
931
|
+
shDegree: this.shDegree,
|
|
932
|
+
samplers: this.table.map((buffer) => ({
|
|
933
|
+
width: this.counts,
|
|
934
|
+
height: 1,
|
|
935
|
+
depth: 1,
|
|
936
|
+
format: 1 /* RGBA_UINT */,
|
|
937
|
+
source: new Uint8Array(buffer.buffer)
|
|
938
|
+
}))
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
deserialize(data) {
|
|
942
|
+
const { counts, shDegree, samplers } = data;
|
|
943
|
+
this.counts = counts;
|
|
944
|
+
this.shDegree = shDegree;
|
|
945
|
+
this.shCounts = SH_MAPS[shDegree];
|
|
946
|
+
this.table = samplers.map((sampler) => new Float32Array(sampler.source.buffer));
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
// ../../external/egs-core/packages/loaders/splat-loader/splat/CompressedSplatData.ts
|
|
951
|
+
function encode111011s(a, b, c) {
|
|
952
|
+
return clamp((a * 0.5 + 0.5) * 2047 | 0, 0, 2047) << 21 | clamp((b * 0.5 + 0.5) * 1023 | 0, 0, 1023) << 11 | clamp((c * 0.5 + 0.5) * 2047 | 0, 0, 2047);
|
|
953
|
+
}
|
|
954
|
+
function decode111011s(decode, out, offset) {
|
|
955
|
+
out[offset + 0] = (decode >>> 21 & 2047) / 2047 * 2 - 1;
|
|
956
|
+
out[offset + 1] = (decode >>> 11 & 1023) / 1023 * 2 - 1;
|
|
957
|
+
out[offset + 2] = (decode & 2047) / 2047 * 2 - 1;
|
|
958
|
+
}
|
|
959
|
+
var CompressedSplatData = class extends SplatData {
|
|
960
|
+
init(counts, shDegree) {
|
|
961
|
+
this.counts = counts;
|
|
962
|
+
this.shDegree = Math.min(shDegree, this.maxShDegree);
|
|
963
|
+
const { w: width, h: height, d: depth } = computeTextureSize(counts, this.maxTextureSize);
|
|
964
|
+
const pixelCounts = width * height * depth;
|
|
965
|
+
const splat1Sampler = this.splat1Sampler = {
|
|
966
|
+
width,
|
|
967
|
+
height,
|
|
968
|
+
depth,
|
|
969
|
+
format: 1 /* RGBA_UINT */,
|
|
970
|
+
source: new Uint8Array(16 * pixelCounts)
|
|
971
|
+
};
|
|
972
|
+
this.splat1Float32Buffer = new Float32Array(splat1Sampler.source.buffer);
|
|
973
|
+
this.splat1Uint16Buffer = new Uint16Array(splat1Sampler.source.buffer);
|
|
974
|
+
const splat2Sampler = this.splat2Sampler = {
|
|
975
|
+
width,
|
|
976
|
+
height,
|
|
977
|
+
depth,
|
|
978
|
+
format: 1 /* RGBA_UINT */,
|
|
979
|
+
source: new Uint8Array(16 * pixelCounts)
|
|
980
|
+
};
|
|
981
|
+
this.splat2Uint16Buffer = new Uint16Array(splat2Sampler.source.buffer);
|
|
982
|
+
this.splat2Uint32Buffer = new Uint32Array(splat2Sampler.source.buffer);
|
|
983
|
+
const sh1Sampler = this.sh1Sampler = {
|
|
984
|
+
width,
|
|
985
|
+
height,
|
|
986
|
+
depth,
|
|
987
|
+
format: 1 /* RGBA_UINT */,
|
|
988
|
+
source: new Uint8Array((shDegree >= 1 ? 16 : 0) * pixelCounts)
|
|
989
|
+
};
|
|
990
|
+
this.sh1Uint32Buffer = new Uint32Array(sh1Sampler.source.buffer);
|
|
991
|
+
const sh2Sampler = this.sh2Sampler = {
|
|
992
|
+
width,
|
|
993
|
+
height,
|
|
994
|
+
depth,
|
|
995
|
+
format: 1 /* RGBA_UINT */,
|
|
996
|
+
source: new Uint8Array((shDegree >= 2 ? 16 : 0) * pixelCounts)
|
|
997
|
+
};
|
|
998
|
+
this.sh2Uint32Buffer = new Uint32Array(sh2Sampler.source.buffer);
|
|
999
|
+
const sh3Sampler = this.sh3Sampler = {
|
|
1000
|
+
width,
|
|
1001
|
+
height,
|
|
1002
|
+
depth,
|
|
1003
|
+
format: 1 /* RGBA_UINT */,
|
|
1004
|
+
source: new Uint8Array((shDegree >= 3 ? 16 : 0) * pixelCounts)
|
|
1005
|
+
};
|
|
1006
|
+
this.sh3Uint32Buffer = new Uint32Array(sh3Sampler.source.buffer);
|
|
1007
|
+
const sh4Sampler = this.sh4Sampler = {
|
|
1008
|
+
width,
|
|
1009
|
+
height,
|
|
1010
|
+
depth,
|
|
1011
|
+
format: 1 /* RGBA_UINT */,
|
|
1012
|
+
source: new Uint8Array((shDegree >= 3 ? 16 : 0) * pixelCounts)
|
|
1013
|
+
};
|
|
1014
|
+
this.sh4Uint32Buffer = new Uint32Array(sh4Sampler.source.buffer);
|
|
1015
|
+
}
|
|
1016
|
+
set(i, single) {
|
|
1017
|
+
const { splat1Float32Buffer, splat1Uint16Buffer, splat2Uint16Buffer, splat2Uint32Buffer } = this;
|
|
1018
|
+
const i4 = i * 4;
|
|
1019
|
+
const i8 = i * 8;
|
|
1020
|
+
splat1Float32Buffer[i4 + 0] = single.x;
|
|
1021
|
+
splat1Float32Buffer[i4 + 1] = single.y;
|
|
1022
|
+
splat1Float32Buffer[i4 + 2] = single.z;
|
|
1023
|
+
splat1Uint16Buffer[i8 + 6] = toHalf(single.a);
|
|
1024
|
+
splat2Uint16Buffer[i8 + 0] = toHalf(single.r);
|
|
1025
|
+
splat2Uint16Buffer[i8 + 1] = toHalf(single.g);
|
|
1026
|
+
splat2Uint16Buffer[i8 + 2] = toHalf(single.b);
|
|
1027
|
+
splat2Uint16Buffer[i8 + 3] = toHalf(Math.log(single.sx));
|
|
1028
|
+
splat2Uint16Buffer[i8 + 4] = toHalf(Math.log(single.sy));
|
|
1029
|
+
splat2Uint16Buffer[i8 + 5] = toHalf(Math.log(single.sz));
|
|
1030
|
+
const oct = encodeQuatOct(single.qx, single.qy, single.qz, single.qw);
|
|
1031
|
+
const quantU = clamp((oct[0] * 0.5 + 0.5) * 1023 | 0, 0, 1023);
|
|
1032
|
+
const quantV = clamp((oct[1] * 0.5 + 0.5) * 1023 | 0, 0, 1023);
|
|
1033
|
+
const angleInt = clamp(oct[2] * 4095 | 0, 0, 4095);
|
|
1034
|
+
splat2Uint32Buffer[i4 + 3] = angleInt << 20 | quantV << 10 | quantU;
|
|
1035
|
+
}
|
|
1036
|
+
setCenter(i, x, y, z) {
|
|
1037
|
+
const { splat1Float32Buffer } = this;
|
|
1038
|
+
const i4 = i * 4;
|
|
1039
|
+
splat1Float32Buffer[i4 + 0] = x;
|
|
1040
|
+
splat1Float32Buffer[i4 + 1] = y;
|
|
1041
|
+
splat1Float32Buffer[i4 + 2] = z;
|
|
1042
|
+
}
|
|
1043
|
+
setScale(i, sx, sy, sz) {
|
|
1044
|
+
const { splat2Uint16Buffer } = this;
|
|
1045
|
+
const i8 = i * 8;
|
|
1046
|
+
splat2Uint16Buffer[i8 + 3] = toHalf(Math.log(sx));
|
|
1047
|
+
splat2Uint16Buffer[i8 + 4] = toHalf(Math.log(sy));
|
|
1048
|
+
splat2Uint16Buffer[i8 + 5] = toHalf(Math.log(sz));
|
|
1049
|
+
}
|
|
1050
|
+
setQuat(i, qx, qy, qz, qw) {
|
|
1051
|
+
const { splat2Uint32Buffer } = this;
|
|
1052
|
+
const i4 = i * 4;
|
|
1053
|
+
const oct = encodeQuatOct(qx, qy, qz, qw);
|
|
1054
|
+
const quantU = clamp((oct[0] * 0.5 + 0.5) * 1023 | 0, 0, 1023);
|
|
1055
|
+
const quantV = clamp((oct[1] * 0.5 + 0.5) * 1023 | 0, 0, 1023);
|
|
1056
|
+
const angleInt = clamp(oct[2] * 4095 | 0, 0, 4095);
|
|
1057
|
+
splat2Uint32Buffer[i4 + 3] = angleInt << 20 | quantV << 10 | quantU;
|
|
1058
|
+
}
|
|
1059
|
+
setColor(i, r, g, b) {
|
|
1060
|
+
const { splat2Uint16Buffer } = this;
|
|
1061
|
+
const i8 = i * 8;
|
|
1062
|
+
splat2Uint16Buffer[i8 + 0] = toHalf(r);
|
|
1063
|
+
splat2Uint16Buffer[i8 + 1] = toHalf(g);
|
|
1064
|
+
splat2Uint16Buffer[i8 + 2] = toHalf(b);
|
|
1065
|
+
}
|
|
1066
|
+
setAlpha(i, a) {
|
|
1067
|
+
const { splat1Uint16Buffer } = this;
|
|
1068
|
+
const i8 = i * 8;
|
|
1069
|
+
splat1Uint16Buffer[i8 + 6] = toHalf(a);
|
|
1070
|
+
}
|
|
1071
|
+
setShN(i, shN) {
|
|
1072
|
+
const { shDegree, sh1Uint32Buffer, sh2Uint32Buffer } = this;
|
|
1073
|
+
const o = i * 4;
|
|
1074
|
+
if (shDegree >= 1) {
|
|
1075
|
+
sh1Uint32Buffer[o + 0] = encode111011s(shN[0], shN[1], shN[2]);
|
|
1076
|
+
sh1Uint32Buffer[o + 1] = encode111011s(shN[3], shN[4], shN[5]);
|
|
1077
|
+
sh1Uint32Buffer[o + 2] = encode111011s(shN[6], shN[7], shN[8]);
|
|
1078
|
+
}
|
|
1079
|
+
if (shDegree >= 2) {
|
|
1080
|
+
sh1Uint32Buffer[o + 3] = encode111011s(shN[9], shN[10], shN[11]);
|
|
1081
|
+
sh2Uint32Buffer[o + 0] = encode111011s(shN[12], shN[13], shN[14]);
|
|
1082
|
+
sh2Uint32Buffer[o + 1] = encode111011s(shN[15], shN[16], shN[17]);
|
|
1083
|
+
sh2Uint32Buffer[o + 2] = encode111011s(shN[18], shN[19], shN[20]);
|
|
1084
|
+
sh2Uint32Buffer[o + 3] = encode111011s(shN[21], shN[22], shN[23]);
|
|
1085
|
+
}
|
|
1086
|
+
if (shDegree >= 3) {
|
|
1087
|
+
const { sh3Uint32Buffer, sh4Uint32Buffer } = this;
|
|
1088
|
+
sh3Uint32Buffer[o + 0] = encode111011s(shN[24], shN[25], shN[26]);
|
|
1089
|
+
sh3Uint32Buffer[o + 1] = encode111011s(shN[27], shN[28], shN[29]);
|
|
1090
|
+
sh3Uint32Buffer[o + 2] = encode111011s(shN[30], shN[31], shN[32]);
|
|
1091
|
+
sh3Uint32Buffer[o + 3] = encode111011s(shN[33], shN[34], shN[35]);
|
|
1092
|
+
sh4Uint32Buffer[o + 0] = encode111011s(shN[36], shN[37], shN[38]);
|
|
1093
|
+
sh4Uint32Buffer[o + 1] = encode111011s(shN[39], shN[40], shN[41]);
|
|
1094
|
+
sh4Uint32Buffer[o + 2] = encode111011s(shN[42], shN[43], shN[44]);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
get(i, single) {
|
|
1098
|
+
const { splat1Float32Buffer, splat1Uint16Buffer, splat2Uint16Buffer, splat2Uint32Buffer } = this;
|
|
1099
|
+
const i4 = i * 4;
|
|
1100
|
+
const i8 = i * 8;
|
|
1101
|
+
single.x = splat1Float32Buffer[i4 + 0];
|
|
1102
|
+
single.y = splat1Float32Buffer[i4 + 1];
|
|
1103
|
+
single.z = splat1Float32Buffer[i4 + 2];
|
|
1104
|
+
single.a = fromHalf(splat1Uint16Buffer[i8 + 6]);
|
|
1105
|
+
single.r = fromHalf(splat2Uint16Buffer[i8 + 0]);
|
|
1106
|
+
single.g = fromHalf(splat2Uint16Buffer[i8 + 1]);
|
|
1107
|
+
single.b = fromHalf(splat2Uint16Buffer[i8 + 2]);
|
|
1108
|
+
single.sx = Math.exp(fromHalf(splat2Uint16Buffer[i8 + 3]));
|
|
1109
|
+
single.sy = Math.exp(fromHalf(splat2Uint16Buffer[i8 + 4]));
|
|
1110
|
+
single.sz = Math.exp(fromHalf(splat2Uint16Buffer[i8 + 5]));
|
|
1111
|
+
const quatEncode = splat2Uint32Buffer[i4 + 3];
|
|
1112
|
+
const u = (quatEncode & 1023 / 1023) * 2 - 1;
|
|
1113
|
+
const v = (quatEncode >>> 10 & 1023 / 1023) * 2 - 1;
|
|
1114
|
+
const angle = quatEncode >>> 20 & 4095 / 4095;
|
|
1115
|
+
const quat = decodeQuatOct(u, v, angle);
|
|
1116
|
+
single.qx = quat[0];
|
|
1117
|
+
single.qy = quat[1];
|
|
1118
|
+
single.qz = quat[2];
|
|
1119
|
+
single.qw = quat[3];
|
|
1120
|
+
}
|
|
1121
|
+
getCenter(i, single) {
|
|
1122
|
+
const { splat1Float32Buffer } = this;
|
|
1123
|
+
const i4 = i * 4;
|
|
1124
|
+
single.x = splat1Float32Buffer[i4 + 0];
|
|
1125
|
+
single.y = splat1Float32Buffer[i4 + 1];
|
|
1126
|
+
single.z = splat1Float32Buffer[i4 + 2];
|
|
1127
|
+
}
|
|
1128
|
+
getScale(i, single) {
|
|
1129
|
+
const { splat2Uint16Buffer } = this;
|
|
1130
|
+
const i8 = i * 8;
|
|
1131
|
+
single.sx = Math.exp(fromHalf(splat2Uint16Buffer[i8 + 3]));
|
|
1132
|
+
single.sy = Math.exp(fromHalf(splat2Uint16Buffer[i8 + 4]));
|
|
1133
|
+
single.sz = Math.exp(fromHalf(splat2Uint16Buffer[i8 + 5]));
|
|
1134
|
+
}
|
|
1135
|
+
getQuat(i, single) {
|
|
1136
|
+
const { splat2Uint32Buffer } = this;
|
|
1137
|
+
const i4 = i * 4;
|
|
1138
|
+
const quatEncode = splat2Uint32Buffer[i4 + 3];
|
|
1139
|
+
const u = (quatEncode & 1023 / 1023) * 2 - 1;
|
|
1140
|
+
const v = (quatEncode >>> 10 & 1023 / 1023) * 2 - 1;
|
|
1141
|
+
const angle = quatEncode >>> 20 & 4095 / 4095;
|
|
1142
|
+
const quat = decodeQuatOct(u, v, angle);
|
|
1143
|
+
single.qx = quat[0];
|
|
1144
|
+
single.qy = quat[1];
|
|
1145
|
+
single.qz = quat[2];
|
|
1146
|
+
single.qw = quat[3];
|
|
1147
|
+
}
|
|
1148
|
+
getColor(i, single) {
|
|
1149
|
+
const { splat2Uint16Buffer } = this;
|
|
1150
|
+
const i8 = i * 8;
|
|
1151
|
+
single.r = fromHalf(splat2Uint16Buffer[i8 + 0]);
|
|
1152
|
+
single.g = fromHalf(splat2Uint16Buffer[i8 + 1]);
|
|
1153
|
+
single.b = fromHalf(splat2Uint16Buffer[i8 + 2]);
|
|
1154
|
+
}
|
|
1155
|
+
getAlpha(i, single) {
|
|
1156
|
+
const { splat1Uint16Buffer } = this;
|
|
1157
|
+
const i8 = i * 8;
|
|
1158
|
+
single.a = fromHalf(splat1Uint16Buffer[i8 + 6]);
|
|
1159
|
+
}
|
|
1160
|
+
getShN(i, shN) {
|
|
1161
|
+
const { shDegree, sh1Uint32Buffer, sh2Uint32Buffer } = this;
|
|
1162
|
+
const o = i * 4;
|
|
1163
|
+
if (shDegree >= 1) {
|
|
1164
|
+
decode111011s(sh1Uint32Buffer[o + 0], shN, 0);
|
|
1165
|
+
decode111011s(sh1Uint32Buffer[o + 1], shN, 3);
|
|
1166
|
+
decode111011s(sh1Uint32Buffer[o + 2], shN, 6);
|
|
1167
|
+
}
|
|
1168
|
+
if (shDegree >= 2) {
|
|
1169
|
+
decode111011s(sh1Uint32Buffer[o + 3], shN, 9);
|
|
1170
|
+
decode111011s(sh2Uint32Buffer[o + 0], shN, 12);
|
|
1171
|
+
decode111011s(sh2Uint32Buffer[o + 1], shN, 15);
|
|
1172
|
+
decode111011s(sh2Uint32Buffer[o + 2], shN, 18);
|
|
1173
|
+
decode111011s(sh2Uint32Buffer[o + 3], shN, 21);
|
|
1174
|
+
}
|
|
1175
|
+
if (shDegree >= 3) {
|
|
1176
|
+
const { sh3Uint32Buffer, sh4Uint32Buffer } = this;
|
|
1177
|
+
decode111011s(sh3Uint32Buffer[o + 0], shN, 24);
|
|
1178
|
+
decode111011s(sh3Uint32Buffer[o + 1], shN, 27);
|
|
1179
|
+
decode111011s(sh3Uint32Buffer[o + 2], shN, 30);
|
|
1180
|
+
decode111011s(sh3Uint32Buffer[o + 3], shN, 33);
|
|
1181
|
+
decode111011s(sh4Uint32Buffer[o + 0], shN, 36);
|
|
1182
|
+
decode111011s(sh4Uint32Buffer[o + 1], shN, 39);
|
|
1183
|
+
decode111011s(sh4Uint32Buffer[o + 2], shN, 42);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
fillCenters(centers) {
|
|
1187
|
+
const { counts, splat1Float32Buffer } = this;
|
|
1188
|
+
for (let i = 0; i < counts; i++) {
|
|
1189
|
+
const i3 = i * 3;
|
|
1190
|
+
const i4 = i * 4;
|
|
1191
|
+
centers[i3 + 0] = splat1Float32Buffer[i4 + 0];
|
|
1192
|
+
centers[i3 + 1] = splat1Float32Buffer[i4 + 1];
|
|
1193
|
+
centers[i3 + 2] = splat1Float32Buffer[i4 + 2];
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
serialize() {
|
|
1197
|
+
return {
|
|
1198
|
+
counts: this.counts,
|
|
1199
|
+
shDegree: this.shDegree,
|
|
1200
|
+
samplers: [
|
|
1201
|
+
this.splat1Sampler,
|
|
1202
|
+
this.splat2Sampler,
|
|
1203
|
+
this.sh1Sampler,
|
|
1204
|
+
this.sh2Sampler,
|
|
1205
|
+
this.sh3Sampler,
|
|
1206
|
+
this.sh4Sampler
|
|
1207
|
+
]
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
deserialize(data) {
|
|
1211
|
+
const { counts, shDegree, samplers } = data;
|
|
1212
|
+
this.counts = counts;
|
|
1213
|
+
this.shDegree = shDegree;
|
|
1214
|
+
const { w: width, h: height, d: depth } = computeTextureSize(counts, this.maxTextureSize);
|
|
1215
|
+
const pixelCounts = width * height * depth;
|
|
1216
|
+
const splat1Sampler = this.splat1Sampler = samplers[0] ?? {
|
|
1217
|
+
width,
|
|
1218
|
+
height,
|
|
1219
|
+
depth,
|
|
1220
|
+
format: 1 /* RGBA_UINT */,
|
|
1221
|
+
source: new Uint8Array(16 * pixelCounts)
|
|
1222
|
+
};
|
|
1223
|
+
this.splat1Float32Buffer = new Float32Array(splat1Sampler.source.buffer);
|
|
1224
|
+
this.splat1Uint16Buffer = new Uint16Array(splat1Sampler.source.buffer);
|
|
1225
|
+
const splat2Sampler = this.splat2Sampler = samplers[1] ?? {
|
|
1226
|
+
width,
|
|
1227
|
+
height,
|
|
1228
|
+
depth,
|
|
1229
|
+
format: 1 /* RGBA_UINT */,
|
|
1230
|
+
source: new Uint8Array(16 * pixelCounts)
|
|
1231
|
+
};
|
|
1232
|
+
this.splat2Uint16Buffer = new Uint16Array(splat2Sampler.source.buffer);
|
|
1233
|
+
this.splat2Uint32Buffer = new Uint32Array(splat2Sampler.source.buffer);
|
|
1234
|
+
const sh1Sampler = this.sh1Sampler = samplers[2] ?? {
|
|
1235
|
+
width,
|
|
1236
|
+
height,
|
|
1237
|
+
depth,
|
|
1238
|
+
format: 1 /* RGBA_UINT */,
|
|
1239
|
+
source: new Uint8Array((shDegree >= 1 ? 16 : 0) * pixelCounts)
|
|
1240
|
+
};
|
|
1241
|
+
this.sh1Uint32Buffer = new Uint32Array(sh1Sampler.source.buffer);
|
|
1242
|
+
const sh2Sampler = this.sh2Sampler = samplers[3] ?? {
|
|
1243
|
+
width,
|
|
1244
|
+
height,
|
|
1245
|
+
depth,
|
|
1246
|
+
format: 1 /* RGBA_UINT */,
|
|
1247
|
+
source: new Uint8Array((shDegree >= 2 ? 16 : 0) * pixelCounts)
|
|
1248
|
+
};
|
|
1249
|
+
this.sh2Uint32Buffer = new Uint32Array(sh2Sampler.source.buffer);
|
|
1250
|
+
const sh3Sampler = this.sh3Sampler = samplers[4] ?? {
|
|
1251
|
+
width,
|
|
1252
|
+
height,
|
|
1253
|
+
depth,
|
|
1254
|
+
format: 1 /* RGBA_UINT */,
|
|
1255
|
+
source: new Uint8Array((shDegree >= 3 ? 16 : 0) * pixelCounts)
|
|
1256
|
+
};
|
|
1257
|
+
this.sh3Uint32Buffer = new Uint32Array(sh3Sampler.source.buffer);
|
|
1258
|
+
const sh4Sampler = this.sh4Sampler = samplers[5] ?? {
|
|
1259
|
+
width,
|
|
1260
|
+
height,
|
|
1261
|
+
depth,
|
|
1262
|
+
format: 1 /* RGBA_UINT */,
|
|
1263
|
+
source: new Uint8Array((shDegree >= 3 ? 16 : 0) * pixelCounts)
|
|
1264
|
+
};
|
|
1265
|
+
this.sh4Uint32Buffer = new Uint32Array(sh4Sampler.source.buffer);
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
// ../../external/egs-core/packages/loaders/splat-loader/splat/SuperCompressedSplatData.ts
|
|
1270
|
+
function packSint5x9ToUint32x2(data, out, offset) {
|
|
1271
|
+
const q0 = (data[0] * 16 + 16.5 | 0) & 31;
|
|
1272
|
+
const q1 = (data[1] * 16 + 16.5 | 0) & 31;
|
|
1273
|
+
const q2 = (data[2] * 16 + 16.5 | 0) & 31;
|
|
1274
|
+
const q3 = (data[3] * 16 + 16.5 | 0) & 31;
|
|
1275
|
+
const q4 = (data[4] * 16 + 16.5 | 0) & 31;
|
|
1276
|
+
const q5 = (data[5] * 16 + 16.5 | 0) & 31;
|
|
1277
|
+
const q6 = (data[6] * 16 + 16.5 | 0) & 31;
|
|
1278
|
+
const q7 = (data[7] * 16 + 16.5 | 0) & 31;
|
|
1279
|
+
const q8 = (data[8] * 16 + 16.5 | 0) & 31;
|
|
1280
|
+
let low = 0;
|
|
1281
|
+
let high = 0;
|
|
1282
|
+
low |= q0 << 0;
|
|
1283
|
+
low |= q1 << 5;
|
|
1284
|
+
low |= q2 << 10;
|
|
1285
|
+
low |= q3 << 15;
|
|
1286
|
+
low |= q4 << 20;
|
|
1287
|
+
low |= q5 << 25;
|
|
1288
|
+
low |= (q6 & 3) << 30;
|
|
1289
|
+
high |= q6 >>> 2;
|
|
1290
|
+
high |= q7 << 3;
|
|
1291
|
+
high |= q8 << 8;
|
|
1292
|
+
out[offset] = low;
|
|
1293
|
+
out[offset + 1] = high;
|
|
1294
|
+
}
|
|
1295
|
+
function unpackSint5x9FromUint32x2(low, high, out, offset) {
|
|
1296
|
+
out[offset + 0] = ((low >>> 0 & 31) - 16) * 0.0625;
|
|
1297
|
+
out[offset + 1] = ((low >>> 5 & 31) - 16) * 0.0625;
|
|
1298
|
+
out[offset + 2] = ((low >>> 10 & 31) - 16) * 0.0625;
|
|
1299
|
+
out[offset + 3] = ((low >>> 15 & 31) - 16) * 0.0625;
|
|
1300
|
+
out[offset + 4] = ((low >>> 20 & 31) - 16) * 0.0625;
|
|
1301
|
+
out[offset + 5] = ((low >>> 25 & 31) - 16) * 0.0625;
|
|
1302
|
+
const lowBits = low >>> 30 & 3;
|
|
1303
|
+
const highBits = (high & 7) << 2;
|
|
1304
|
+
out[offset + 6] = ((lowBits | highBits) - 16) * 0.0625;
|
|
1305
|
+
out[offset + 7] = ((high >>> 3 & 31) - 16) * 0.0625;
|
|
1306
|
+
out[offset + 8] = ((high >>> 8 & 31) - 16) * 0.0625;
|
|
1307
|
+
}
|
|
1308
|
+
function packSint4ToUint8(v0, v1) {
|
|
1309
|
+
const l = (v0 * 8 + 8.5 | 0) & 15;
|
|
1310
|
+
const h = (v1 * 8 + 8.5 | 0) & 15;
|
|
1311
|
+
return h << 4 | l;
|
|
1312
|
+
}
|
|
1313
|
+
function unpackUint8ToSint4x2(value, out, offset) {
|
|
1314
|
+
out[offset] = (value & 15) * 0.125 - 1;
|
|
1315
|
+
out[offset + 1] = (value >> 4 & 15) * 0.125 - 1;
|
|
1316
|
+
}
|
|
1317
|
+
function toUnsignedChar(v) {
|
|
1318
|
+
return clamp(v * 128 + 128.5 | 0, 0, 255);
|
|
1319
|
+
}
|
|
1320
|
+
function fromUnsignedChar(v) {
|
|
1321
|
+
return (v - 128) / 128;
|
|
1322
|
+
}
|
|
1323
|
+
function toUnsignedCharV2(v) {
|
|
1324
|
+
return clamp(v * 255 + 0.5 | 0, 0, 255);
|
|
1325
|
+
}
|
|
1326
|
+
var LN_SCALE_MIN = -12;
|
|
1327
|
+
var LN_SCALE_MAX = 9;
|
|
1328
|
+
var LN_SCALE = 254 / (LN_SCALE_MAX - LN_SCALE_MIN);
|
|
1329
|
+
var LN_SCALE_INV = 1 / LN_SCALE;
|
|
1330
|
+
var SuperCompressedSplatData = class extends SplatData {
|
|
1331
|
+
init(counts, shDegree) {
|
|
1332
|
+
this.counts = counts;
|
|
1333
|
+
this.shDegree = Math.min(shDegree, this.maxShDegree);
|
|
1334
|
+
const { w: width, h: height, d: depth } = computeTextureSize(counts, this.maxTextureSize);
|
|
1335
|
+
const pixelCounts = width * height * depth;
|
|
1336
|
+
const splatSampler = this.splatSampler = {
|
|
1337
|
+
width,
|
|
1338
|
+
height,
|
|
1339
|
+
depth,
|
|
1340
|
+
format: 1 /* RGBA_UINT */,
|
|
1341
|
+
source: new Uint8Array(16 * pixelCounts)
|
|
1342
|
+
};
|
|
1343
|
+
this.splatUint8Buffer = splatSampler.source;
|
|
1344
|
+
this.splatUint16Buffer = new Uint16Array(splatSampler.source.buffer);
|
|
1345
|
+
const sh1Sampler = this.sh1Sampler = {
|
|
1346
|
+
width,
|
|
1347
|
+
height,
|
|
1348
|
+
depth,
|
|
1349
|
+
format: shDegree === 1 ? 0 /* RG_UINT */ : 1 /* RGBA_UINT */,
|
|
1350
|
+
source: new Uint8Array((shDegree >= 1 ? shDegree === 1 ? 8 : 16 : 0) * pixelCounts)
|
|
1351
|
+
};
|
|
1352
|
+
this.sh1Uint8Buffer = sh1Sampler.source;
|
|
1353
|
+
this.sh1Uint32Buffer = new Uint32Array(sh1Sampler.source.buffer);
|
|
1354
|
+
const sh2Sampler = this.sh2Sampler = {
|
|
1355
|
+
width,
|
|
1356
|
+
height,
|
|
1357
|
+
depth,
|
|
1358
|
+
format: 1 /* RGBA_UINT */,
|
|
1359
|
+
source: new Uint8Array((shDegree >= 3 ? 16 : 0) * pixelCounts)
|
|
1360
|
+
};
|
|
1361
|
+
this.sh2Uint8Buffer = sh2Sampler.source;
|
|
1362
|
+
}
|
|
1363
|
+
set(i, single) {
|
|
1364
|
+
const { splatUint16Buffer, splatUint8Buffer } = this;
|
|
1365
|
+
const i8 = i * 8;
|
|
1366
|
+
const i16 = i * 16;
|
|
1367
|
+
splatUint16Buffer[i8 + 0] = toHalf(single.x);
|
|
1368
|
+
splatUint16Buffer[i8 + 1] = toHalf(single.y);
|
|
1369
|
+
splatUint16Buffer[i8 + 2] = toHalf(single.z);
|
|
1370
|
+
splatUint8Buffer[i16 + 6] = clamp((Math.log(single.sx) - LN_SCALE_MIN) * LN_SCALE + 1.5 | 0, 0, 255);
|
|
1371
|
+
splatUint8Buffer[i16 + 7] = clamp((Math.log(single.sy) - LN_SCALE_MIN) * LN_SCALE + 1.5 | 0, 0, 255);
|
|
1372
|
+
splatUint8Buffer[i16 + 8] = clamp((Math.log(single.sz) - LN_SCALE_MIN) * LN_SCALE + 1.5 | 0, 0, 255);
|
|
1373
|
+
const oct = encodeQuatOct(single.qx, single.qy, single.qz, single.qw);
|
|
1374
|
+
splatUint8Buffer[i16 + 9] = toUnsignedChar(oct[0]);
|
|
1375
|
+
splatUint8Buffer[i16 + 10] = toUnsignedChar(oct[1]);
|
|
1376
|
+
splatUint8Buffer[i16 + 11] = toUnsignedCharV2(oct[2]);
|
|
1377
|
+
splatUint8Buffer[i16 + 12] = toUnsignedCharV2(single.r);
|
|
1378
|
+
splatUint8Buffer[i16 + 13] = toUnsignedCharV2(single.g);
|
|
1379
|
+
splatUint8Buffer[i16 + 14] = toUnsignedCharV2(single.b);
|
|
1380
|
+
splatUint8Buffer[i16 + 15] = toUnsignedCharV2(single.a);
|
|
1381
|
+
}
|
|
1382
|
+
setCenter(i, x, y, z) {
|
|
1383
|
+
const { splatUint16Buffer } = this;
|
|
1384
|
+
const offset = i * 8;
|
|
1385
|
+
splatUint16Buffer[offset + 0] = toHalf(x);
|
|
1386
|
+
splatUint16Buffer[offset + 1] = toHalf(y);
|
|
1387
|
+
splatUint16Buffer[offset + 2] = toHalf(z);
|
|
1388
|
+
}
|
|
1389
|
+
setScale(i, sx, sy, sz) {
|
|
1390
|
+
const { splatUint8Buffer } = this;
|
|
1391
|
+
const offset = i * 16;
|
|
1392
|
+
splatUint8Buffer[offset + 6] = clamp((Math.log(sx) - LN_SCALE_MIN) * LN_SCALE + 1.5 | 0, 0, 255);
|
|
1393
|
+
splatUint8Buffer[offset + 7] = clamp((Math.log(sy) - LN_SCALE_MIN) * LN_SCALE + 1.5 | 0, 0, 255);
|
|
1394
|
+
splatUint8Buffer[offset + 8] = clamp((Math.log(sz) - LN_SCALE_MIN) * LN_SCALE + 1.5 | 0, 0, 255);
|
|
1395
|
+
}
|
|
1396
|
+
setQuat(i, qx, qy, qz, qw) {
|
|
1397
|
+
const { splatUint8Buffer } = this;
|
|
1398
|
+
const offset = i * 16;
|
|
1399
|
+
const oct = encodeQuatOct(qx, qy, qz, qw);
|
|
1400
|
+
splatUint8Buffer[offset + 9] = toUnsignedChar(oct[0]);
|
|
1401
|
+
splatUint8Buffer[offset + 10] = toUnsignedChar(oct[1]);
|
|
1402
|
+
splatUint8Buffer[offset + 11] = toUnsignedCharV2(oct[2]);
|
|
1403
|
+
}
|
|
1404
|
+
setColor(i, r, g, b) {
|
|
1405
|
+
const { splatUint8Buffer } = this;
|
|
1406
|
+
const offset = i * 16;
|
|
1407
|
+
splatUint8Buffer[offset + 12] = toUnsignedCharV2(r);
|
|
1408
|
+
splatUint8Buffer[offset + 13] = toUnsignedCharV2(g);
|
|
1409
|
+
splatUint8Buffer[offset + 14] = toUnsignedCharV2(b);
|
|
1410
|
+
}
|
|
1411
|
+
setAlpha(i, a) {
|
|
1412
|
+
const { splatUint8Buffer } = this;
|
|
1413
|
+
const offset = i * 16;
|
|
1414
|
+
splatUint8Buffer[offset + 15] = toUnsignedCharV2(a);
|
|
1415
|
+
}
|
|
1416
|
+
setShN(i, shN) {
|
|
1417
|
+
const { shDegree, sh1Uint32Buffer, sh1Uint8Buffer, sh2Uint8Buffer } = this;
|
|
1418
|
+
if (shDegree >= 1) {
|
|
1419
|
+
const offset = (shDegree === 1 ? 2 : 4) * i;
|
|
1420
|
+
packSint5x9ToUint32x2(shN, sh1Uint32Buffer, offset);
|
|
1421
|
+
}
|
|
1422
|
+
if (shDegree >= 2) {
|
|
1423
|
+
const offset = 16 * i + 8;
|
|
1424
|
+
sh1Uint8Buffer[offset + 0] = packSint4ToUint8(shN[9], shN[10]);
|
|
1425
|
+
sh1Uint8Buffer[offset + 1] = packSint4ToUint8(shN[11], shN[12]);
|
|
1426
|
+
sh1Uint8Buffer[offset + 2] = packSint4ToUint8(shN[13], shN[14]);
|
|
1427
|
+
sh1Uint8Buffer[offset + 3] = packSint4ToUint8(shN[15], shN[16]);
|
|
1428
|
+
sh1Uint8Buffer[offset + 4] = packSint4ToUint8(shN[17], shN[18]);
|
|
1429
|
+
sh1Uint8Buffer[offset + 5] = packSint4ToUint8(shN[19], shN[20]);
|
|
1430
|
+
sh1Uint8Buffer[offset + 6] = packSint4ToUint8(shN[21], shN[22]);
|
|
1431
|
+
sh1Uint8Buffer[offset + 7] = packSint4ToUint8(shN[23], 0);
|
|
1432
|
+
}
|
|
1433
|
+
if (shDegree >= 3) {
|
|
1434
|
+
const offset = 16 * i;
|
|
1435
|
+
sh2Uint8Buffer[offset + 0] = packSint4ToUint8(shN[24], shN[25]);
|
|
1436
|
+
sh2Uint8Buffer[offset + 1] = packSint4ToUint8(shN[26], shN[27]);
|
|
1437
|
+
sh2Uint8Buffer[offset + 2] = packSint4ToUint8(shN[28], shN[29]);
|
|
1438
|
+
sh2Uint8Buffer[offset + 3] = packSint4ToUint8(shN[30], shN[31]);
|
|
1439
|
+
sh2Uint8Buffer[offset + 4] = packSint4ToUint8(shN[32], shN[33]);
|
|
1440
|
+
sh2Uint8Buffer[offset + 5] = packSint4ToUint8(shN[34], shN[35]);
|
|
1441
|
+
sh2Uint8Buffer[offset + 6] = packSint4ToUint8(shN[36], shN[37]);
|
|
1442
|
+
sh2Uint8Buffer[offset + 7] = packSint4ToUint8(shN[38], shN[39]);
|
|
1443
|
+
sh2Uint8Buffer[offset + 8] = packSint4ToUint8(shN[40], shN[41]);
|
|
1444
|
+
sh2Uint8Buffer[offset + 9] = packSint4ToUint8(shN[42], shN[43]);
|
|
1445
|
+
sh2Uint8Buffer[offset + 10] = packSint4ToUint8(shN[44], 0);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
get(i, single) {
|
|
1449
|
+
const { splatUint16Buffer, splatUint8Buffer } = this;
|
|
1450
|
+
const i8 = i * 8;
|
|
1451
|
+
const i16 = i * 16;
|
|
1452
|
+
single.x = fromHalf(splatUint16Buffer[i8 + 0]);
|
|
1453
|
+
single.y = fromHalf(splatUint16Buffer[i8 + 1]);
|
|
1454
|
+
single.z = fromHalf(splatUint16Buffer[i8 + 2]);
|
|
1455
|
+
const uScaleX = splatUint8Buffer[i16 + 6];
|
|
1456
|
+
const uScaleY = splatUint8Buffer[i16 + 7];
|
|
1457
|
+
const uScaleZ = splatUint8Buffer[i16 + 8];
|
|
1458
|
+
single.sx = Math.exp(LN_SCALE_MIN + (uScaleX - 1) * LN_SCALE_INV);
|
|
1459
|
+
single.sy = Math.exp(LN_SCALE_MIN + (uScaleY - 1) * LN_SCALE_INV);
|
|
1460
|
+
single.sz = Math.exp(LN_SCALE_MIN + (uScaleZ - 1) * LN_SCALE_INV);
|
|
1461
|
+
const u = fromUnsignedChar(splatUint8Buffer[i16 + 9]);
|
|
1462
|
+
const v = fromUnsignedChar(splatUint8Buffer[i16 + 10]);
|
|
1463
|
+
const angle = splatUint8Buffer[i16 + 11] / 255;
|
|
1464
|
+
const quat = decodeQuatOct(u, v, angle);
|
|
1465
|
+
single.qx = quat[0];
|
|
1466
|
+
single.qy = quat[1];
|
|
1467
|
+
single.qz = quat[2];
|
|
1468
|
+
single.qw = quat[3];
|
|
1469
|
+
single.r = splatUint8Buffer[i16 + 12] / 255;
|
|
1470
|
+
single.g = splatUint8Buffer[i16 + 13] / 255;
|
|
1471
|
+
single.b = splatUint8Buffer[i16 + 14] / 255;
|
|
1472
|
+
single.a = splatUint8Buffer[i16 + 15] / 255;
|
|
1473
|
+
}
|
|
1474
|
+
getCenter(i, single) {
|
|
1475
|
+
const { splatUint16Buffer } = this;
|
|
1476
|
+
const i8 = i * 8;
|
|
1477
|
+
single.x = fromHalf(splatUint16Buffer[i8 + 0]);
|
|
1478
|
+
single.y = fromHalf(splatUint16Buffer[i8 + 1]);
|
|
1479
|
+
single.z = fromHalf(splatUint16Buffer[i8 + 2]);
|
|
1480
|
+
}
|
|
1481
|
+
getScale(i, single) {
|
|
1482
|
+
const { splatUint8Buffer } = this;
|
|
1483
|
+
const i16 = i * 16;
|
|
1484
|
+
const uScaleX = splatUint8Buffer[i16 + 6];
|
|
1485
|
+
const uScaleY = splatUint8Buffer[i16 + 7];
|
|
1486
|
+
const uScaleZ = splatUint8Buffer[i16 + 8];
|
|
1487
|
+
single.sx = Math.exp(LN_SCALE_MIN + (uScaleX - 1) * LN_SCALE_INV);
|
|
1488
|
+
single.sy = Math.exp(LN_SCALE_MIN + (uScaleY - 1) * LN_SCALE_INV);
|
|
1489
|
+
single.sz = Math.exp(LN_SCALE_MIN + (uScaleZ - 1) * LN_SCALE_INV);
|
|
1490
|
+
}
|
|
1491
|
+
getQuat(i, single) {
|
|
1492
|
+
const { splatUint8Buffer } = this;
|
|
1493
|
+
const i16 = i * 16;
|
|
1494
|
+
const u = fromUnsignedChar(splatUint8Buffer[i16 + 9]);
|
|
1495
|
+
const v = fromUnsignedChar(splatUint8Buffer[i16 + 10]);
|
|
1496
|
+
const angle = splatUint8Buffer[i16 + 11] / 255;
|
|
1497
|
+
const quat = decodeQuatOct(u, v, angle);
|
|
1498
|
+
single.qx = quat[0];
|
|
1499
|
+
single.qy = quat[1];
|
|
1500
|
+
single.qz = quat[2];
|
|
1501
|
+
single.qw = quat[3];
|
|
1502
|
+
}
|
|
1503
|
+
getColor(i, single) {
|
|
1504
|
+
const { splatUint8Buffer } = this;
|
|
1505
|
+
const i16 = i * 16;
|
|
1506
|
+
single.r = splatUint8Buffer[i16 + 12] / 255;
|
|
1507
|
+
single.g = splatUint8Buffer[i16 + 13] / 255;
|
|
1508
|
+
single.b = splatUint8Buffer[i16 + 14] / 255;
|
|
1509
|
+
}
|
|
1510
|
+
getAlpha(i, single) {
|
|
1511
|
+
const { splatUint8Buffer } = this;
|
|
1512
|
+
const i16 = i * 16;
|
|
1513
|
+
single.a = splatUint8Buffer[i16 + 15] / 255;
|
|
1514
|
+
}
|
|
1515
|
+
getShN(i, shN) {
|
|
1516
|
+
const { shDegree, sh1Uint32Buffer, sh1Uint8Buffer, sh2Uint8Buffer } = this;
|
|
1517
|
+
if (shDegree >= 1) {
|
|
1518
|
+
const offset = (shDegree === 1 ? 2 : 4) * i;
|
|
1519
|
+
const low = sh1Uint32Buffer[offset];
|
|
1520
|
+
const high = sh1Uint32Buffer[offset + 1];
|
|
1521
|
+
unpackSint5x9FromUint32x2(low, high, shN, 0);
|
|
1522
|
+
}
|
|
1523
|
+
if (shDegree >= 2) {
|
|
1524
|
+
const offset = 16 * i + 8;
|
|
1525
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 0], shN, 9);
|
|
1526
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 1], shN, 11);
|
|
1527
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 2], shN, 13);
|
|
1528
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 3], shN, 15);
|
|
1529
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 5], shN, 17);
|
|
1530
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 6], shN, 19);
|
|
1531
|
+
unpackUint8ToSint4x2(sh1Uint8Buffer[offset + 7], shN, 21);
|
|
1532
|
+
shN[23] = (sh2Uint8Buffer[offset + 8] & 15) * 0.125 - 1;
|
|
1533
|
+
}
|
|
1534
|
+
if (shDegree >= 3) {
|
|
1535
|
+
const offset = 16 * i;
|
|
1536
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 0], shN, 24);
|
|
1537
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 1], shN, 26);
|
|
1538
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 2], shN, 28);
|
|
1539
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 3], shN, 30);
|
|
1540
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 4], shN, 32);
|
|
1541
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 5], shN, 34);
|
|
1542
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 6], shN, 36);
|
|
1543
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 7], shN, 38);
|
|
1544
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 8], shN, 40);
|
|
1545
|
+
unpackUint8ToSint4x2(sh2Uint8Buffer[offset + 9], shN, 42);
|
|
1546
|
+
shN[44] = (sh2Uint8Buffer[offset + 10] & 15) * 0.125 - 1;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
fillCenters(centers) {
|
|
1550
|
+
const { counts, splatUint16Buffer } = this;
|
|
1551
|
+
for (let i = 0; i < counts; i++) {
|
|
1552
|
+
const i3 = i * 3;
|
|
1553
|
+
const i8 = i * 8;
|
|
1554
|
+
centers[i3 + 0] = fromHalf(splatUint16Buffer[i8 + 0]);
|
|
1555
|
+
centers[i3 + 1] = fromHalf(splatUint16Buffer[i8 + 1]);
|
|
1556
|
+
centers[i3 + 2] = fromHalf(splatUint16Buffer[i8 + 2]);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
serialize() {
|
|
1560
|
+
return {
|
|
1561
|
+
counts: this.counts,
|
|
1562
|
+
shDegree: this.shDegree,
|
|
1563
|
+
samplers: [this.splatSampler, this.sh1Sampler, this.sh2Sampler]
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
deserialize(data) {
|
|
1567
|
+
const { counts, shDegree, samplers } = data;
|
|
1568
|
+
this.counts = counts;
|
|
1569
|
+
this.shDegree = shDegree;
|
|
1570
|
+
const { w: width, h: height, d: depth } = computeTextureSize(counts, this.maxTextureSize);
|
|
1571
|
+
const pixelCounts = width * height * depth;
|
|
1572
|
+
const splatSampler = this.splatSampler = samplers[0] ?? {
|
|
1573
|
+
width,
|
|
1574
|
+
height,
|
|
1575
|
+
depth,
|
|
1576
|
+
format: 1 /* RGBA_UINT */,
|
|
1577
|
+
source: new Uint8Array(16 * pixelCounts)
|
|
1578
|
+
};
|
|
1579
|
+
this.splatUint8Buffer = new Uint8Array(splatSampler.source.buffer);
|
|
1580
|
+
this.splatUint16Buffer = new Uint16Array(splatSampler.source.buffer);
|
|
1581
|
+
const sh1Sampler = this.sh1Sampler = samplers[1] ?? {
|
|
1582
|
+
width,
|
|
1583
|
+
height,
|
|
1584
|
+
depth,
|
|
1585
|
+
format: shDegree === 1 ? 0 /* RG_UINT */ : 1 /* RGBA_UINT */,
|
|
1586
|
+
source: new Uint8Array((shDegree >= 1 ? shDegree === 1 ? 8 : 16 : 0) * pixelCounts)
|
|
1587
|
+
};
|
|
1588
|
+
this.sh1Uint8Buffer = sh1Sampler.source;
|
|
1589
|
+
this.sh1Uint32Buffer = new Uint32Array(sh1Sampler.source.buffer);
|
|
1590
|
+
const sh2Sampler = this.sh2Sampler = samplers[2] ?? {
|
|
1591
|
+
width,
|
|
1592
|
+
height,
|
|
1593
|
+
depth,
|
|
1594
|
+
format: 1 /* RGBA_UINT */,
|
|
1595
|
+
source: new Uint8Array((shDegree >= 3 ? 16 : 0) * pixelCounts)
|
|
1596
|
+
};
|
|
1597
|
+
this.sh2Uint8Buffer = sh2Sampler.source;
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
// ../../external/egs-core/packages/loaders/splat-loader/splat/SogSplatData.ts
|
|
1602
|
+
var SogSplatData = class extends SplatData {
|
|
1603
|
+
constructor() {
|
|
1604
|
+
super(...arguments);
|
|
1605
|
+
this.counts = 0;
|
|
1606
|
+
this.shDegree = 0;
|
|
1607
|
+
}
|
|
1608
|
+
init(_counts, _shDegree) {
|
|
1609
|
+
throw new Error("Method not implemented.");
|
|
1610
|
+
}
|
|
1611
|
+
load(meta, meansL, meansU, quats, scales, colors, shNLabels, shNCentroids) {
|
|
1612
|
+
this.meta = meta;
|
|
1613
|
+
this.meansL = meansL;
|
|
1614
|
+
this.meansU = meansU;
|
|
1615
|
+
this.quats = quats;
|
|
1616
|
+
this.scales = scales;
|
|
1617
|
+
this.colors = colors;
|
|
1618
|
+
this.shNLabels = shNLabels;
|
|
1619
|
+
this.shNCentroids = shNCentroids;
|
|
1620
|
+
}
|
|
1621
|
+
set(_i, _single) {
|
|
1622
|
+
throw new Error("Method not implemented.");
|
|
1623
|
+
}
|
|
1624
|
+
setCenter(_i, _x, _y, _z) {
|
|
1625
|
+
throw new Error("Method not implemented.");
|
|
1626
|
+
}
|
|
1627
|
+
setScale(_i, _sx, _sy, _sz) {
|
|
1628
|
+
throw new Error("Method not implemented.");
|
|
1629
|
+
}
|
|
1630
|
+
setQuat(_i, _qx, _qy, _qz, _qw) {
|
|
1631
|
+
throw new Error("Method not implemented.");
|
|
1632
|
+
}
|
|
1633
|
+
setColor(_i, _r, _g, _b2) {
|
|
1634
|
+
throw new Error("Method not implemented.");
|
|
1635
|
+
}
|
|
1636
|
+
setAlpha(_i, _a2) {
|
|
1637
|
+
throw new Error("Method not implemented.");
|
|
1638
|
+
}
|
|
1639
|
+
setShN(_i, _shN) {
|
|
1640
|
+
throw new Error("Method not implemented.");
|
|
1641
|
+
}
|
|
1642
|
+
get(_i, _single) {
|
|
1643
|
+
throw new Error("Method not implemented.");
|
|
1644
|
+
}
|
|
1645
|
+
getCenter(_i, _single) {
|
|
1646
|
+
throw new Error("Method not implemented.");
|
|
1647
|
+
}
|
|
1648
|
+
getScale(_i, _single) {
|
|
1649
|
+
throw new Error("Method not implemented.");
|
|
1650
|
+
}
|
|
1651
|
+
getQuat(_i, _single) {
|
|
1652
|
+
throw new Error("Method not implemented.");
|
|
1653
|
+
}
|
|
1654
|
+
getColor(_i, _single) {
|
|
1655
|
+
throw new Error("Method not implemented.");
|
|
1656
|
+
}
|
|
1657
|
+
getAlpha(_i, _single) {
|
|
1658
|
+
throw new Error("Method not implemented.");
|
|
1659
|
+
}
|
|
1660
|
+
getShN(_i, _shN) {
|
|
1661
|
+
throw new Error("Method not implemented.");
|
|
1662
|
+
}
|
|
1663
|
+
fillCenters(_centers) {
|
|
1664
|
+
throw new Error("Method not implemented.");
|
|
1665
|
+
}
|
|
1666
|
+
serialize() {
|
|
1667
|
+
return {
|
|
1668
|
+
counts: this.meta.counts,
|
|
1669
|
+
shDegree: this.meta.shDegree,
|
|
1670
|
+
samplers: [
|
|
1671
|
+
this.meansL,
|
|
1672
|
+
this.meansU,
|
|
1673
|
+
this.quats,
|
|
1674
|
+
this.scales,
|
|
1675
|
+
this.colors,
|
|
1676
|
+
this.shNLabels,
|
|
1677
|
+
this.shNCentroids
|
|
1678
|
+
].filter((v) => !!v).map((v) => ({
|
|
1679
|
+
width: 1,
|
|
1680
|
+
height: 1,
|
|
1681
|
+
depth: 1,
|
|
1682
|
+
format: 1 /* RGBA_UINT */,
|
|
1683
|
+
source: v
|
|
1684
|
+
})),
|
|
1685
|
+
extras: [this.meta]
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
deserialize(data) {
|
|
1689
|
+
const { samplers, extras = [] } = data;
|
|
1690
|
+
this.meta = extras[0];
|
|
1691
|
+
this.meansL = samplers[0].source;
|
|
1692
|
+
this.meansU = samplers[1].source;
|
|
1693
|
+
this.quats = samplers[2].source;
|
|
1694
|
+
this.scales = samplers[3].source;
|
|
1695
|
+
this.colors = samplers[4].source;
|
|
1696
|
+
if (samplers[5]) {
|
|
1697
|
+
this.shNLabels = samplers[5].source;
|
|
1698
|
+
}
|
|
1699
|
+
if (samplers[6]) {
|
|
1700
|
+
this.shNCentroids = samplers[6].source;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
|
|
1705
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/utils.ts
|
|
1706
|
+
var SH_C0 = 0.28209479177387814;
|
|
1707
|
+
var SH_MAPS2 = {
|
|
1708
|
+
0: 0,
|
|
1709
|
+
1: 9,
|
|
1710
|
+
2: 24,
|
|
1711
|
+
3: 45
|
|
1712
|
+
};
|
|
1713
|
+
var NUM_F_REST_TO_SH_DEGREE = {
|
|
1714
|
+
0: 0,
|
|
1715
|
+
9: 1,
|
|
1716
|
+
24: 2,
|
|
1717
|
+
45: 3
|
|
1718
|
+
};
|
|
1719
|
+
var BufferReader = class {
|
|
1720
|
+
constructor(buffer = new Uint8Array()) {
|
|
1721
|
+
this.head = 0;
|
|
1722
|
+
this.tail = 0;
|
|
1723
|
+
this.buffer = buffer;
|
|
1724
|
+
this.view = new DataView(this.buffer.buffer);
|
|
1725
|
+
}
|
|
1726
|
+
get remaining() {
|
|
1727
|
+
return this.tail - this.head;
|
|
1728
|
+
}
|
|
1729
|
+
grow(required) {
|
|
1730
|
+
const newCap = Math.max(required, this.buffer.length * 2);
|
|
1731
|
+
const next = new Uint8Array(newCap);
|
|
1732
|
+
next.set(this.buffer.subarray(this.head, this.tail), 0);
|
|
1733
|
+
this.tail -= this.head;
|
|
1734
|
+
this.head = 0;
|
|
1735
|
+
this.buffer = next;
|
|
1736
|
+
this.view = new DataView(next.buffer);
|
|
1737
|
+
}
|
|
1738
|
+
compact() {
|
|
1739
|
+
if (this.head === 0) {
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
this.buffer.copyWithin(0, this.head, this.tail);
|
|
1743
|
+
this.tail -= this.head;
|
|
1744
|
+
this.head = 0;
|
|
1745
|
+
}
|
|
1746
|
+
write(chunk) {
|
|
1747
|
+
const remaining = this.tail - this.head;
|
|
1748
|
+
const required = remaining + chunk.length;
|
|
1749
|
+
if (this.buffer.length < required) {
|
|
1750
|
+
this.grow(required);
|
|
1751
|
+
} else if (this.head > 0 && this.buffer.length - this.tail < chunk.length) {
|
|
1752
|
+
this.compact();
|
|
1753
|
+
}
|
|
1754
|
+
this.buffer.set(chunk, this.tail);
|
|
1755
|
+
this.tail += chunk.length;
|
|
1756
|
+
}
|
|
1757
|
+
read(counts) {
|
|
1758
|
+
const head = this.head;
|
|
1759
|
+
const tail = this.head = head + counts;
|
|
1760
|
+
return this.buffer.subarray(head, tail);
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
var StreamChunkDecoder = class {
|
|
1764
|
+
constructor(reader) {
|
|
1765
|
+
this.currentIndex = 0;
|
|
1766
|
+
this.reader = reader;
|
|
1767
|
+
}
|
|
1768
|
+
setDecoders(decoders) {
|
|
1769
|
+
this.decoders = decoders;
|
|
1770
|
+
this.decodedTotals = new Uint32Array(decoders.length);
|
|
1771
|
+
const [totals, itemSize] = decoders[this.currentIndex].init();
|
|
1772
|
+
this.currentTotals = totals;
|
|
1773
|
+
this.currentItemSize = itemSize;
|
|
1774
|
+
}
|
|
1775
|
+
flush() {
|
|
1776
|
+
const { reader, decoders, decodedTotals, currentIndex, currentTotals, currentItemSize } = this;
|
|
1777
|
+
const stage = decoders[currentIndex];
|
|
1778
|
+
const decoded = decodedTotals[currentIndex];
|
|
1779
|
+
const counts = Math.min(currentTotals - decoded, reader.remaining / currentItemSize | 0);
|
|
1780
|
+
const buf = reader.read(counts * currentItemSize);
|
|
1781
|
+
stage.decode(decoded, counts, buf);
|
|
1782
|
+
decodedTotals[currentIndex] += counts;
|
|
1783
|
+
if (decodedTotals[currentIndex] === currentTotals) {
|
|
1784
|
+
this.currentIndex++;
|
|
1785
|
+
if (this.currentIndex < decoders.length) {
|
|
1786
|
+
const [totals, itemSize] = decoders[this.currentIndex].init();
|
|
1787
|
+
this.currentTotals = totals;
|
|
1788
|
+
this.currentItemSize = itemSize;
|
|
1789
|
+
this.flush();
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
};
|
|
1794
|
+
var f32buffer2 = new Float32Array(1);
|
|
1795
|
+
var u32buffer2 = new Uint32Array(f32buffer2.buffer);
|
|
1796
|
+
function fromHalf2(h) {
|
|
1797
|
+
const sign = h >> 15 & 1;
|
|
1798
|
+
const exp = h >> 10 & 31;
|
|
1799
|
+
const frac = h & 1023;
|
|
1800
|
+
let f32bits;
|
|
1801
|
+
if (exp === 0) {
|
|
1802
|
+
if (frac === 0) {
|
|
1803
|
+
f32bits = sign << 31;
|
|
1804
|
+
} else {
|
|
1805
|
+
let mant = frac;
|
|
1806
|
+
let e = -14;
|
|
1807
|
+
while ((mant & 1024) === 0) {
|
|
1808
|
+
mant <<= 1;
|
|
1809
|
+
e--;
|
|
1810
|
+
}
|
|
1811
|
+
mant &= 1023;
|
|
1812
|
+
const newExp = e + 127;
|
|
1813
|
+
const newFrac = mant << 13;
|
|
1814
|
+
f32bits = sign << 31 | newExp << 23 | newFrac;
|
|
1815
|
+
}
|
|
1816
|
+
} else if (exp === 31) {
|
|
1817
|
+
if (frac === 0) {
|
|
1818
|
+
f32bits = sign << 31 | 2139095040;
|
|
1819
|
+
} else {
|
|
1820
|
+
f32bits = sign << 31 | 2143289344;
|
|
1821
|
+
}
|
|
1822
|
+
} else {
|
|
1823
|
+
const newExp = exp - 15 + 127;
|
|
1824
|
+
const newFrac = frac << 13;
|
|
1825
|
+
f32bits = sign << 31 | newExp << 23 | newFrac;
|
|
1826
|
+
}
|
|
1827
|
+
u32buffer2[0] = f32bits;
|
|
1828
|
+
return f32buffer2[0];
|
|
1829
|
+
}
|
|
1830
|
+
function clamp2(v, min, max2) {
|
|
1831
|
+
return Math.min(Math.max(v, min), max2);
|
|
1832
|
+
}
|
|
1833
|
+
function isUrl(str) {
|
|
1834
|
+
let url;
|
|
1835
|
+
try {
|
|
1836
|
+
url = new URL(str);
|
|
1837
|
+
} catch {
|
|
1838
|
+
return false;
|
|
1839
|
+
}
|
|
1840
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
1841
|
+
}
|
|
1842
|
+
var canvas;
|
|
1843
|
+
var context;
|
|
1844
|
+
async function decodeImage(fileBytes) {
|
|
1845
|
+
if (!context) {
|
|
1846
|
+
canvas = new OffscreenCanvas(1, 1);
|
|
1847
|
+
context = canvas.getContext("2d", { willReadFrequently: true }) ?? void 0;
|
|
1848
|
+
}
|
|
1849
|
+
if (!context) {
|
|
1850
|
+
throw new Error("Failed to create context");
|
|
1851
|
+
}
|
|
1852
|
+
const imageBlob = new Blob([fileBytes]);
|
|
1853
|
+
const bitmap = await createImageBitmap(imageBlob, {
|
|
1854
|
+
premultiplyAlpha: "none"
|
|
1855
|
+
});
|
|
1856
|
+
const { width, height } = bitmap;
|
|
1857
|
+
canvas.width = width;
|
|
1858
|
+
canvas.height = height;
|
|
1859
|
+
context.drawImage(bitmap, 0, 0, width, height);
|
|
1860
|
+
const data = context.getImageData(0, 0, width, height);
|
|
1861
|
+
return {
|
|
1862
|
+
data: new Uint8Array(data.data.buffer, data.data.byteOffset, data.data.length),
|
|
1863
|
+
width,
|
|
1864
|
+
height
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
function extractFromRootDir(entries) {
|
|
1868
|
+
let dir = "";
|
|
1869
|
+
for (const path in entries) {
|
|
1870
|
+
if (path.endsWith("/")) {
|
|
1871
|
+
dir = path;
|
|
1872
|
+
break;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
const result = {};
|
|
1876
|
+
for (const path in entries) {
|
|
1877
|
+
result[path.replace(dir, "")] = entries[path];
|
|
1878
|
+
}
|
|
1879
|
+
return result;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/ksplat.ts
|
|
1883
|
+
var KSPLAT_COMPRESSION = {
|
|
1884
|
+
0: {
|
|
1885
|
+
bytesPerCenter: 12,
|
|
1886
|
+
bytesPerScale: 12,
|
|
1887
|
+
bytesPerRotation: 16,
|
|
1888
|
+
bytesPerColor: 4,
|
|
1889
|
+
bytesPerSphericalHarmonicsComponent: 4,
|
|
1890
|
+
scaleOffsetBytes: 12,
|
|
1891
|
+
rotationOffsetBytes: 24,
|
|
1892
|
+
colorOffsetBytes: 40,
|
|
1893
|
+
sphericalHarmonicsOffsetBytes: 44,
|
|
1894
|
+
scaleRange: 1
|
|
1895
|
+
},
|
|
1896
|
+
1: {
|
|
1897
|
+
bytesPerCenter: 6,
|
|
1898
|
+
bytesPerScale: 6,
|
|
1899
|
+
bytesPerRotation: 8,
|
|
1900
|
+
bytesPerColor: 4,
|
|
1901
|
+
bytesPerSphericalHarmonicsComponent: 2,
|
|
1902
|
+
scaleOffsetBytes: 6,
|
|
1903
|
+
rotationOffsetBytes: 12,
|
|
1904
|
+
colorOffsetBytes: 20,
|
|
1905
|
+
sphericalHarmonicsOffsetBytes: 24,
|
|
1906
|
+
scaleRange: 32767
|
|
1907
|
+
},
|
|
1908
|
+
2: {
|
|
1909
|
+
bytesPerCenter: 6,
|
|
1910
|
+
bytesPerScale: 6,
|
|
1911
|
+
bytesPerRotation: 8,
|
|
1912
|
+
bytesPerColor: 4,
|
|
1913
|
+
bytesPerSphericalHarmonicsComponent: 1,
|
|
1914
|
+
scaleOffsetBytes: 6,
|
|
1915
|
+
rotationOffsetBytes: 12,
|
|
1916
|
+
colorOffsetBytes: 20,
|
|
1917
|
+
sphericalHarmonicsOffsetBytes: 24,
|
|
1918
|
+
scaleRange: 32767
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
var SHIndex = [
|
|
1922
|
+
0,
|
|
1923
|
+
3,
|
|
1924
|
+
6,
|
|
1925
|
+
1,
|
|
1926
|
+
4,
|
|
1927
|
+
7,
|
|
1928
|
+
2,
|
|
1929
|
+
5,
|
|
1930
|
+
8,
|
|
1931
|
+
// sh1
|
|
1932
|
+
9,
|
|
1933
|
+
14,
|
|
1934
|
+
19,
|
|
1935
|
+
10,
|
|
1936
|
+
15,
|
|
1937
|
+
20,
|
|
1938
|
+
11,
|
|
1939
|
+
16,
|
|
1940
|
+
21,
|
|
1941
|
+
12,
|
|
1942
|
+
17,
|
|
1943
|
+
22,
|
|
1944
|
+
13,
|
|
1945
|
+
18,
|
|
1946
|
+
23,
|
|
1947
|
+
// sh2
|
|
1948
|
+
24,
|
|
1949
|
+
31,
|
|
1950
|
+
38,
|
|
1951
|
+
25,
|
|
1952
|
+
32,
|
|
1953
|
+
39,
|
|
1954
|
+
26,
|
|
1955
|
+
33,
|
|
1956
|
+
40,
|
|
1957
|
+
27,
|
|
1958
|
+
34,
|
|
1959
|
+
41,
|
|
1960
|
+
28,
|
|
1961
|
+
35,
|
|
1962
|
+
42,
|
|
1963
|
+
29,
|
|
1964
|
+
36,
|
|
1965
|
+
43,
|
|
1966
|
+
30,
|
|
1967
|
+
37,
|
|
1968
|
+
44
|
|
1969
|
+
// sh3
|
|
1970
|
+
];
|
|
1971
|
+
var HEADER_BYTES = 4096;
|
|
1972
|
+
var SECTION_BYTES = 1024;
|
|
1973
|
+
var KsplatFile = class {
|
|
1974
|
+
constructor() {
|
|
1975
|
+
this.counts = 0;
|
|
1976
|
+
this.shDegree = 0;
|
|
1977
|
+
}
|
|
1978
|
+
load(buffer) {
|
|
1979
|
+
this.buffer = buffer;
|
|
1980
|
+
const header = new DataView(buffer.buffer, 0, HEADER_BYTES);
|
|
1981
|
+
const versionMajor = header.getUint8(0);
|
|
1982
|
+
const versionMinor = header.getUint8(1);
|
|
1983
|
+
if (versionMajor !== 0 || versionMinor < 1) {
|
|
1984
|
+
throw new Error(`Unsupported .ksplat version: ${versionMajor}.${versionMinor}`);
|
|
1985
|
+
}
|
|
1986
|
+
const maxSectionCount = header.getUint32(4, true);
|
|
1987
|
+
const sectionCount = header.getUint32(8, true);
|
|
1988
|
+
const maxSplatCount = header.getUint32(12, true);
|
|
1989
|
+
const splatCount = header.getUint32(16, true);
|
|
1990
|
+
const compressionLevel = header.getUint16(20, true);
|
|
1991
|
+
if (compressionLevel < 0 || compressionLevel > 2) {
|
|
1992
|
+
throw new Error(`Invalid .ksplat compression level: ${compressionLevel}`);
|
|
1993
|
+
}
|
|
1994
|
+
const sceneCenterX = header.getFloat32(24, true);
|
|
1995
|
+
const sceneCenterY = header.getFloat32(28, true);
|
|
1996
|
+
const sceneCenterZ = header.getFloat32(32, true);
|
|
1997
|
+
const minSH = header.getFloat32(36, true) || -1.5;
|
|
1998
|
+
const maxSH = header.getFloat32(40, true) || 1.5;
|
|
1999
|
+
let maxSHDegree = 0;
|
|
2000
|
+
const sections = [];
|
|
2001
|
+
for (let i = 0; i < maxSectionCount; i++) {
|
|
2002
|
+
const section = new DataView(buffer.buffer, HEADER_BYTES + i * SECTION_BYTES, SECTION_BYTES);
|
|
2003
|
+
const sectionSplatCount = section.getUint32(0, true);
|
|
2004
|
+
const sectionMaxSplatCount = section.getUint32(4, true);
|
|
2005
|
+
const bucketSize = section.getUint32(8, true);
|
|
2006
|
+
const bucketCount = section.getUint32(12, true);
|
|
2007
|
+
const bucketBlockSize = section.getFloat32(16, true);
|
|
2008
|
+
const bucketStorageSizeBytes = section.getUint16(20, true);
|
|
2009
|
+
const compressionScaleRange = section.getUint32(24, true);
|
|
2010
|
+
const fullBucketCount = section.getUint32(32, true);
|
|
2011
|
+
const partiallyFilledBucketCount = section.getUint32(36, true);
|
|
2012
|
+
const shDegree = section.getUint16(40, true);
|
|
2013
|
+
maxSHDegree = Math.max(maxSHDegree, shDegree);
|
|
2014
|
+
sections.push({
|
|
2015
|
+
sectionSplatCount,
|
|
2016
|
+
sectionMaxSplatCount,
|
|
2017
|
+
bucketSize,
|
|
2018
|
+
bucketCount,
|
|
2019
|
+
bucketBlockSize,
|
|
2020
|
+
bucketStorageSizeBytes,
|
|
2021
|
+
compressionScaleRange: compressionScaleRange || KSPLAT_COMPRESSION[compressionLevel].scaleRange,
|
|
2022
|
+
fullBucketCount,
|
|
2023
|
+
partiallyFilledBucketCount,
|
|
2024
|
+
shDegree
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
this.header = {
|
|
2028
|
+
versionMajor,
|
|
2029
|
+
versionMinor,
|
|
2030
|
+
maxSectionCount,
|
|
2031
|
+
sectionCount,
|
|
2032
|
+
maxSplatCount,
|
|
2033
|
+
splatCount,
|
|
2034
|
+
compressionLevel,
|
|
2035
|
+
sceneCenter: [sceneCenterX, sceneCenterY, sceneCenterZ],
|
|
2036
|
+
shRange: [minSH, maxSH]
|
|
2037
|
+
};
|
|
2038
|
+
this.sections = sections;
|
|
2039
|
+
this.counts = splatCount;
|
|
2040
|
+
this.shDegree = maxSHDegree;
|
|
2041
|
+
}
|
|
2042
|
+
async read(stream, contentLength, data) {
|
|
2043
|
+
let BlockOffset = 0;
|
|
2044
|
+
{
|
|
2045
|
+
const buffer2 = new Uint8Array(contentLength);
|
|
2046
|
+
const reader = stream.getReader();
|
|
2047
|
+
let offset = 0;
|
|
2048
|
+
while (true) {
|
|
2049
|
+
const { done, value } = await reader.read();
|
|
2050
|
+
if (done) {
|
|
2051
|
+
break;
|
|
2052
|
+
}
|
|
2053
|
+
buffer2.set(value, offset);
|
|
2054
|
+
offset += value.length;
|
|
2055
|
+
}
|
|
2056
|
+
this.load(buffer2);
|
|
2057
|
+
BlockOffset = await data.initBlock(this.counts, this.shDegree);
|
|
2058
|
+
}
|
|
2059
|
+
const setFn = data.set.bind(data);
|
|
2060
|
+
const setShFn = data.setShN.bind(data);
|
|
2061
|
+
const { buffer, header, sections, shDegree: maxSHDegree } = this;
|
|
2062
|
+
const { maxSectionCount, compressionLevel, shRange: [minSH, maxSH] } = header;
|
|
2063
|
+
const isHighQualitySplatData = compressionLevel === 0;
|
|
2064
|
+
const single = {
|
|
2065
|
+
x: 0,
|
|
2066
|
+
y: 0,
|
|
2067
|
+
z: 0,
|
|
2068
|
+
sx: 0,
|
|
2069
|
+
sy: 0,
|
|
2070
|
+
sz: 0,
|
|
2071
|
+
qx: 0,
|
|
2072
|
+
qy: 0,
|
|
2073
|
+
qz: 0,
|
|
2074
|
+
qw: 0,
|
|
2075
|
+
r: 0,
|
|
2076
|
+
g: 0,
|
|
2077
|
+
b: 0,
|
|
2078
|
+
a: 0,
|
|
2079
|
+
shN: []
|
|
2080
|
+
};
|
|
2081
|
+
const maxSHSize = SH_MAPS2[maxSHDegree];
|
|
2082
|
+
const shData = new Array(maxSHSize);
|
|
2083
|
+
let sectionBase = HEADER_BYTES + maxSectionCount * SECTION_BYTES;
|
|
2084
|
+
for (let i = 0; i < maxSectionCount; i++) {
|
|
2085
|
+
const {
|
|
2086
|
+
sectionSplatCount,
|
|
2087
|
+
sectionMaxSplatCount,
|
|
2088
|
+
bucketSize,
|
|
2089
|
+
bucketCount,
|
|
2090
|
+
bucketBlockSize,
|
|
2091
|
+
bucketStorageSizeBytes,
|
|
2092
|
+
fullBucketCount,
|
|
2093
|
+
partiallyFilledBucketCount,
|
|
2094
|
+
compressionScaleRange,
|
|
2095
|
+
shDegree
|
|
2096
|
+
} = sections[i];
|
|
2097
|
+
const fullBucketSplats = fullBucketCount * bucketSize;
|
|
2098
|
+
const bucketsMetaDataSizeBytes = partiallyFilledBucketCount * 4;
|
|
2099
|
+
const bucketsStorageSizeBytes = bucketStorageSizeBytes * bucketCount + bucketsMetaDataSizeBytes;
|
|
2100
|
+
const shComponents = SH_MAPS2[shDegree];
|
|
2101
|
+
const {
|
|
2102
|
+
bytesPerCenter,
|
|
2103
|
+
bytesPerScale,
|
|
2104
|
+
bytesPerRotation,
|
|
2105
|
+
bytesPerColor,
|
|
2106
|
+
bytesPerSphericalHarmonicsComponent,
|
|
2107
|
+
scaleOffsetBytes,
|
|
2108
|
+
rotationOffsetBytes,
|
|
2109
|
+
colorOffsetBytes,
|
|
2110
|
+
sphericalHarmonicsOffsetBytes
|
|
2111
|
+
} = KSPLAT_COMPRESSION[compressionLevel];
|
|
2112
|
+
const bytesPerSplat = bytesPerCenter + bytesPerScale + bytesPerRotation + bytesPerColor + shComponents * bytesPerSphericalHarmonicsComponent;
|
|
2113
|
+
const splatDataStorageSizeBytes = bytesPerSplat * sectionMaxSplatCount;
|
|
2114
|
+
const storageSizeBytes = splatDataStorageSizeBytes + bucketsStorageSizeBytes;
|
|
2115
|
+
const compressionScaleFactor = bucketBlockSize / 2 / compressionScaleRange;
|
|
2116
|
+
const bucketsBase = sectionBase + bucketsMetaDataSizeBytes;
|
|
2117
|
+
const dataBase = sectionBase + bucketsStorageSizeBytes;
|
|
2118
|
+
const data2 = new DataView(buffer.buffer, dataBase, splatDataStorageSizeBytes);
|
|
2119
|
+
const bucketArray = new Float32Array(buffer.buffer, bucketsBase, bucketCount * 3);
|
|
2120
|
+
const partiallyFilledBucketLengths = new Uint32Array(buffer.buffer, sectionBase, partiallyFilledBucketCount);
|
|
2121
|
+
let partialBucketIndex = fullBucketCount;
|
|
2122
|
+
let partialBucketBase = fullBucketSplats;
|
|
2123
|
+
for (let j = 0; j < sectionSplatCount; j++) {
|
|
2124
|
+
const splatOffset = j * bytesPerSplat;
|
|
2125
|
+
let bucketIndex;
|
|
2126
|
+
if (j < fullBucketSplats) {
|
|
2127
|
+
bucketIndex = Math.floor(j / bucketSize);
|
|
2128
|
+
} else {
|
|
2129
|
+
const bucketLength = partiallyFilledBucketLengths[partialBucketIndex - fullBucketCount];
|
|
2130
|
+
if (j >= partialBucketBase + bucketLength) {
|
|
2131
|
+
partialBucketIndex += 1;
|
|
2132
|
+
partialBucketBase += bucketLength;
|
|
2133
|
+
}
|
|
2134
|
+
bucketIndex = partialBucketIndex;
|
|
2135
|
+
}
|
|
2136
|
+
if (isHighQualitySplatData) {
|
|
2137
|
+
single.x = data2.getFloat32(splatOffset + 0, true);
|
|
2138
|
+
single.y = data2.getFloat32(splatOffset + 4, true);
|
|
2139
|
+
single.z = data2.getFloat32(splatOffset + 8, true);
|
|
2140
|
+
single.sx = data2.getFloat32(splatOffset + scaleOffsetBytes + 0, true);
|
|
2141
|
+
single.sy = data2.getFloat32(splatOffset + scaleOffsetBytes + 4, true);
|
|
2142
|
+
single.sz = data2.getFloat32(splatOffset + scaleOffsetBytes + 8, true);
|
|
2143
|
+
single.qw = data2.getFloat32(splatOffset + rotationOffsetBytes + 0, true);
|
|
2144
|
+
single.qx = data2.getFloat32(splatOffset + rotationOffsetBytes + 4, true);
|
|
2145
|
+
single.qy = data2.getFloat32(splatOffset + rotationOffsetBytes + 8, true);
|
|
2146
|
+
single.qz = data2.getFloat32(splatOffset + rotationOffsetBytes + 12, true);
|
|
2147
|
+
} else {
|
|
2148
|
+
single.x = (data2.getUint16(splatOffset + 0, true) - compressionScaleRange) * compressionScaleFactor + bucketArray[3 * bucketIndex + 0];
|
|
2149
|
+
single.y = (data2.getUint16(splatOffset + 2, true) - compressionScaleRange) * compressionScaleFactor + bucketArray[3 * bucketIndex + 1];
|
|
2150
|
+
single.z = (data2.getUint16(splatOffset + 4, true) - compressionScaleRange) * compressionScaleFactor + bucketArray[3 * bucketIndex + 2];
|
|
2151
|
+
single.sx = fromHalf2(data2.getUint16(splatOffset + scaleOffsetBytes + 0, true));
|
|
2152
|
+
single.sy = fromHalf2(data2.getUint16(splatOffset + scaleOffsetBytes + 2, true));
|
|
2153
|
+
single.sz = fromHalf2(data2.getUint16(splatOffset + scaleOffsetBytes + 4, true));
|
|
2154
|
+
single.qw = fromHalf2(data2.getUint16(splatOffset + rotationOffsetBytes + 0, true));
|
|
2155
|
+
single.qx = fromHalf2(data2.getUint16(splatOffset + rotationOffsetBytes + 2, true));
|
|
2156
|
+
single.qy = fromHalf2(data2.getUint16(splatOffset + rotationOffsetBytes + 4, true));
|
|
2157
|
+
single.qz = fromHalf2(data2.getUint16(splatOffset + rotationOffsetBytes + 6, true));
|
|
2158
|
+
}
|
|
2159
|
+
single.r = data2.getUint8(splatOffset + colorOffsetBytes + 0) / 255;
|
|
2160
|
+
single.g = data2.getUint8(splatOffset + colorOffsetBytes + 1) / 255;
|
|
2161
|
+
single.b = data2.getUint8(splatOffset + colorOffsetBytes + 2) / 255;
|
|
2162
|
+
single.a = data2.getUint8(splatOffset + colorOffsetBytes + 3) / 255;
|
|
2163
|
+
setFn(j + BlockOffset, single);
|
|
2164
|
+
const shOffsetBytes = splatOffset + sphericalHarmonicsOffsetBytes;
|
|
2165
|
+
for (let k = 0; k < shComponents; k++) {
|
|
2166
|
+
shData[k] = compressionLevel === 0 ? data2.getFloat32(shOffsetBytes + SHIndex[k] * 4, true) : compressionLevel === 1 ? fromHalf2(data2.getUint16(shOffsetBytes + SHIndex[k] * 2, true)) : minSH + data2.getUint8(shOffsetBytes + SHIndex[k]) / 255 * (maxSH - minSH);
|
|
2167
|
+
}
|
|
2168
|
+
for (let k = maxSHSize - 1; k >= shComponents; k--) {
|
|
2169
|
+
shData[k] = 0;
|
|
2170
|
+
}
|
|
2171
|
+
setShFn(j + BlockOffset, shData);
|
|
2172
|
+
}
|
|
2173
|
+
sectionBase += storageSizeBytes;
|
|
2174
|
+
}
|
|
2175
|
+
data.finishBlock();
|
|
2176
|
+
}
|
|
2177
|
+
async write(_stream, _data) {
|
|
2178
|
+
throw new Error("Method not implemented.");
|
|
2179
|
+
}
|
|
2180
|
+
};
|
|
2181
|
+
|
|
2182
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/ply.ts
|
|
2183
|
+
var F_REST_REGEX = /^f_rest_([0-9]{1,2})$/;
|
|
2184
|
+
function createEmptyBlock(properties, shDegree) {
|
|
2185
|
+
const result = {
|
|
2186
|
+
f_rest: new Array(SH_MAPS2[shDegree])
|
|
2187
|
+
};
|
|
2188
|
+
for (const name of Object.keys(properties)) {
|
|
2189
|
+
if (F_REST_REGEX.test(name)) {
|
|
2190
|
+
continue;
|
|
2191
|
+
}
|
|
2192
|
+
result[name] = 0;
|
|
2193
|
+
}
|
|
2194
|
+
return result;
|
|
2195
|
+
}
|
|
2196
|
+
var FIELD_BYTES = {
|
|
2197
|
+
char: 1,
|
|
2198
|
+
uchar: 1,
|
|
2199
|
+
short: 2,
|
|
2200
|
+
ushort: 2,
|
|
2201
|
+
int: 4,
|
|
2202
|
+
uint: 4,
|
|
2203
|
+
float: 4,
|
|
2204
|
+
double: 8
|
|
2205
|
+
};
|
|
2206
|
+
function createParseFn(properties, littleEndian, shDegree) {
|
|
2207
|
+
function createPropertyParse(type) {
|
|
2208
|
+
switch (type) {
|
|
2209
|
+
case "char":
|
|
2210
|
+
return "data.getInt8(offset)";
|
|
2211
|
+
case "uchar":
|
|
2212
|
+
return "data.getUint8(offset)";
|
|
2213
|
+
case "short":
|
|
2214
|
+
return `data.getInt16(offset, ${littleEndian})`;
|
|
2215
|
+
case "ushort":
|
|
2216
|
+
return `data.getUint16(offset, ${littleEndian})`;
|
|
2217
|
+
case "int":
|
|
2218
|
+
return `data.getInt32(offset, ${littleEndian})`;
|
|
2219
|
+
case "uint":
|
|
2220
|
+
return `data.getUint32(offset, ${littleEndian})`;
|
|
2221
|
+
case "float":
|
|
2222
|
+
return `data.getFloat32(offset, ${littleEndian})`;
|
|
2223
|
+
case "double":
|
|
2224
|
+
return `data.getFloat64(offset, ${littleEndian})`;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
let itemSize = 0;
|
|
2228
|
+
const parserSrc = [];
|
|
2229
|
+
const shLen = SH_MAPS2[shDegree] / 3;
|
|
2230
|
+
for (const [propertyName, propertyType] of Object.entries(properties)) {
|
|
2231
|
+
const fRestMatch = propertyName.match(F_REST_REGEX);
|
|
2232
|
+
if (fRestMatch) {
|
|
2233
|
+
let fRestIndex = parseInt(fRestMatch[1], 10);
|
|
2234
|
+
fRestIndex = fRestIndex % shLen * 3 + Math.floor(fRestIndex / shLen);
|
|
2235
|
+
parserSrc.push(`item.f_rest[${fRestIndex}] = ${createPropertyParse(propertyType)};`);
|
|
2236
|
+
} else {
|
|
2237
|
+
parserSrc.push(`item.${propertyName} = ${createPropertyParse(propertyType)};`);
|
|
2238
|
+
}
|
|
2239
|
+
parserSrc.push(`offset += ${FIELD_BYTES[propertyType]};`);
|
|
2240
|
+
itemSize += FIELD_BYTES[propertyType];
|
|
2241
|
+
}
|
|
2242
|
+
return [itemSize, new Function("data", "offset", "item", parserSrc.join("\n"))];
|
|
2243
|
+
}
|
|
2244
|
+
var HeaderTerminator = "end_header\n";
|
|
2245
|
+
var PlyFile = class {
|
|
2246
|
+
constructor() {
|
|
2247
|
+
this.littleEndian = true;
|
|
2248
|
+
this.comments = [];
|
|
2249
|
+
this.elements = {};
|
|
2250
|
+
this.isSuperSplatCompressed = false;
|
|
2251
|
+
this.counts = 0;
|
|
2252
|
+
this.shDegree = 0;
|
|
2253
|
+
}
|
|
2254
|
+
initHeader(header) {
|
|
2255
|
+
let curElement;
|
|
2256
|
+
const lines = header.trim().split("\n").map((v) => v.trim()).filter((v) => !!v);
|
|
2257
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2258
|
+
const line = lines[i];
|
|
2259
|
+
if (i === 0) {
|
|
2260
|
+
if (line !== "ply") {
|
|
2261
|
+
throw new Error("Invalid PLY header");
|
|
2262
|
+
}
|
|
2263
|
+
continue;
|
|
2264
|
+
}
|
|
2265
|
+
const fields = line.split(" ");
|
|
2266
|
+
switch (fields[0]) {
|
|
2267
|
+
case "format":
|
|
2268
|
+
if (fields[1] === "binary_little_endian") {
|
|
2269
|
+
this.littleEndian = true;
|
|
2270
|
+
} else if (fields[1] === "binary_big_endian") {
|
|
2271
|
+
this.littleEndian = false;
|
|
2272
|
+
} else {
|
|
2273
|
+
throw new Error(`Unsupported PLY format: ${fields[1]}`);
|
|
2274
|
+
}
|
|
2275
|
+
if (fields[2] !== "1.0") {
|
|
2276
|
+
throw new Error(`Unsupported PLY version: ${fields[2]}`);
|
|
2277
|
+
}
|
|
2278
|
+
break;
|
|
2279
|
+
case "comment":
|
|
2280
|
+
this.comments.push(line.slice("comment ".length));
|
|
2281
|
+
break;
|
|
2282
|
+
case "element": {
|
|
2283
|
+
const name = fields[1];
|
|
2284
|
+
curElement = this.elements[name] = {
|
|
2285
|
+
name,
|
|
2286
|
+
count: parseInt(fields[2], 10),
|
|
2287
|
+
properties: {}
|
|
2288
|
+
};
|
|
2289
|
+
break;
|
|
2290
|
+
}
|
|
2291
|
+
case "property":
|
|
2292
|
+
if (!curElement) {
|
|
2293
|
+
throw new Error("Property must be inside an element");
|
|
2294
|
+
}
|
|
2295
|
+
if (!FIELD_BYTES[fields[1]]) {
|
|
2296
|
+
throw new Error(`Unsupported property type '${fields[1]}'`);
|
|
2297
|
+
}
|
|
2298
|
+
curElement.properties[fields[2]] = fields[1];
|
|
2299
|
+
break;
|
|
2300
|
+
case "end_header":
|
|
2301
|
+
break;
|
|
2302
|
+
default:
|
|
2303
|
+
console.warn(`Skipping unsupported PLY keyword: ${fields[0]}`);
|
|
2304
|
+
break;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
const { elements } = this;
|
|
2308
|
+
const isSuperSplatCompressed = this.isSuperSplatCompressed = !!elements.chunk;
|
|
2309
|
+
this.counts = elements.vertex?.count ?? 0;
|
|
2310
|
+
const shElement = isSuperSplatCompressed ? elements.sh : elements.vertex;
|
|
2311
|
+
if (shElement) {
|
|
2312
|
+
const { properties } = shElement;
|
|
2313
|
+
let num_f_rest = 0;
|
|
2314
|
+
while (properties[`f_rest_${num_f_rest}`]) {
|
|
2315
|
+
num_f_rest += 1;
|
|
2316
|
+
}
|
|
2317
|
+
const shDegree = NUM_F_REST_TO_SH_DEGREE[num_f_rest];
|
|
2318
|
+
if (shDegree === void 0) {
|
|
2319
|
+
throw new Error(`Unsupported number of SH coefficients: ${num_f_rest}`);
|
|
2320
|
+
}
|
|
2321
|
+
this.shDegree = shDegree;
|
|
2322
|
+
}
|
|
2323
|
+
for (const name in elements) {
|
|
2324
|
+
const { properties } = elements[name];
|
|
2325
|
+
if (isSuperSplatCompressed) {
|
|
2326
|
+
if (name === "chunk") {
|
|
2327
|
+
const {
|
|
2328
|
+
min_x,
|
|
2329
|
+
min_y,
|
|
2330
|
+
min_z,
|
|
2331
|
+
max_x,
|
|
2332
|
+
max_y,
|
|
2333
|
+
max_z,
|
|
2334
|
+
min_scale_x,
|
|
2335
|
+
min_scale_y,
|
|
2336
|
+
min_scale_z,
|
|
2337
|
+
max_scale_x,
|
|
2338
|
+
max_scale_y,
|
|
2339
|
+
max_scale_z,
|
|
2340
|
+
min_r,
|
|
2341
|
+
min_g,
|
|
2342
|
+
min_b,
|
|
2343
|
+
max_r,
|
|
2344
|
+
max_g,
|
|
2345
|
+
max_b
|
|
2346
|
+
} = properties;
|
|
2347
|
+
if (!min_x || !min_y || !min_z || !max_x || !max_y || !max_z || !min_scale_x || !min_scale_y || !min_scale_z || !max_scale_x || !max_scale_y || !max_scale_z || !min_r || !min_g || !min_b || !max_r || !max_g || !max_b) {
|
|
2348
|
+
throw new Error("Missing Compressed PLY chunk properties");
|
|
2349
|
+
}
|
|
2350
|
+
} else if (name === "vertex") {
|
|
2351
|
+
const { packed_position, packed_rotation, packed_scale, packed_color } = properties;
|
|
2352
|
+
if (!packed_position || !packed_rotation || !packed_scale || !packed_color) {
|
|
2353
|
+
throw new Error("Missing Compressed PLY vertex properties");
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
} else {
|
|
2357
|
+
if (name === "vertex") {
|
|
2358
|
+
const {
|
|
2359
|
+
x,
|
|
2360
|
+
y,
|
|
2361
|
+
z,
|
|
2362
|
+
scale_0,
|
|
2363
|
+
scale_1,
|
|
2364
|
+
scale_2,
|
|
2365
|
+
rot_0,
|
|
2366
|
+
rot_1,
|
|
2367
|
+
rot_2,
|
|
2368
|
+
rot_3,
|
|
2369
|
+
f_dc_0,
|
|
2370
|
+
f_dc_1,
|
|
2371
|
+
f_dc_2,
|
|
2372
|
+
opacity
|
|
2373
|
+
} = properties;
|
|
2374
|
+
if (!x || !y || !z || !scale_0 || !scale_1 || !scale_2 || !rot_0 || !rot_1 || !rot_2 || !rot_3 || !f_dc_0 || !f_dc_1 || !f_dc_2 || !opacity) {
|
|
2375
|
+
throw new Error("Missing PLY vertex properties");
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
async read(stream, _contentLength, data) {
|
|
2382
|
+
const setFn = data.set.bind(data);
|
|
2383
|
+
const setShFn = data.setShN.bind(data);
|
|
2384
|
+
let headerParsed = false;
|
|
2385
|
+
let header = "";
|
|
2386
|
+
const reader = new BufferReader();
|
|
2387
|
+
const decoder = new StreamChunkDecoder(reader);
|
|
2388
|
+
let BlockOffset = 0;
|
|
2389
|
+
const chunks = [];
|
|
2390
|
+
const single = {
|
|
2391
|
+
x: 0,
|
|
2392
|
+
y: 0,
|
|
2393
|
+
z: 0,
|
|
2394
|
+
sx: 0,
|
|
2395
|
+
sy: 0,
|
|
2396
|
+
sz: 0,
|
|
2397
|
+
qx: 0,
|
|
2398
|
+
qy: 0,
|
|
2399
|
+
qz: 0,
|
|
2400
|
+
qw: 0,
|
|
2401
|
+
r: 0,
|
|
2402
|
+
g: 0,
|
|
2403
|
+
b: 0,
|
|
2404
|
+
a: 0,
|
|
2405
|
+
shN: []
|
|
2406
|
+
};
|
|
2407
|
+
const initDecoder = () => {
|
|
2408
|
+
const { elements, littleEndian, isSuperSplatCompressed, shDegree } = this;
|
|
2409
|
+
const chunkDecoders = [];
|
|
2410
|
+
for (const name in elements) {
|
|
2411
|
+
const { count, properties } = elements[name];
|
|
2412
|
+
const block = createEmptyBlock(properties, shDegree);
|
|
2413
|
+
const [itemSize, parseFn] = createParseFn(properties, littleEndian, shDegree);
|
|
2414
|
+
let fn = () => {
|
|
2415
|
+
};
|
|
2416
|
+
if (isSuperSplatCompressed) {
|
|
2417
|
+
if (name === "chunk") {
|
|
2418
|
+
fn = (i, item) => {
|
|
2419
|
+
chunks[i - BlockOffset] = { ...item };
|
|
2420
|
+
};
|
|
2421
|
+
} else if (name === "sh") {
|
|
2422
|
+
fn = (i, item) => {
|
|
2423
|
+
setShFn(i, item.f_rest.map((v) => v * 8 / 255 - 4));
|
|
2424
|
+
};
|
|
2425
|
+
} else if (name === "vertex") {
|
|
2426
|
+
fn = (i, item) => {
|
|
2427
|
+
const chunk = chunks[i - BlockOffset >>> 8];
|
|
2428
|
+
if (!chunk) {
|
|
2429
|
+
throw new Error("Missing PLY chunk");
|
|
2430
|
+
}
|
|
2431
|
+
const {
|
|
2432
|
+
min_x,
|
|
2433
|
+
min_y,
|
|
2434
|
+
min_z,
|
|
2435
|
+
max_x,
|
|
2436
|
+
max_y,
|
|
2437
|
+
max_z,
|
|
2438
|
+
min_scale_x,
|
|
2439
|
+
min_scale_y,
|
|
2440
|
+
min_scale_z,
|
|
2441
|
+
max_scale_x,
|
|
2442
|
+
max_scale_y,
|
|
2443
|
+
max_scale_z,
|
|
2444
|
+
min_r,
|
|
2445
|
+
min_g,
|
|
2446
|
+
min_b,
|
|
2447
|
+
max_r,
|
|
2448
|
+
max_g,
|
|
2449
|
+
max_b
|
|
2450
|
+
} = chunk;
|
|
2451
|
+
const { packed_position, packed_rotation, packed_scale, packed_color } = item;
|
|
2452
|
+
single.x = (packed_position >>> 21 & 2047) / 2047 * (max_x - min_x) + min_x;
|
|
2453
|
+
single.y = (packed_position >>> 11 & 1023) / 1023 * (max_y - min_y) + min_y;
|
|
2454
|
+
single.z = (packed_position & 2047) / 2047 * (max_z - min_z) + min_z;
|
|
2455
|
+
const r0 = ((packed_rotation >>> 20 & 1023) / 1023 - 0.5) * Math.SQRT2;
|
|
2456
|
+
const r1 = ((packed_rotation >>> 10 & 1023) / 1023 - 0.5) * Math.SQRT2;
|
|
2457
|
+
const r2 = ((packed_rotation & 1023) / 1023 - 0.5) * Math.SQRT2;
|
|
2458
|
+
const rr = Math.sqrt(Math.max(0, 1 - r0 * r0 - r1 * r1 - r2 * r2));
|
|
2459
|
+
const rOrder = packed_rotation >>> 30;
|
|
2460
|
+
single.qx = rOrder === 0 ? r0 : rOrder === 1 ? rr : r1;
|
|
2461
|
+
single.qy = rOrder <= 1 ? r1 : rOrder === 2 ? rr : r2;
|
|
2462
|
+
single.qz = rOrder <= 2 ? r2 : rr;
|
|
2463
|
+
single.qw = rOrder === 0 ? rr : r0;
|
|
2464
|
+
single.sx = Math.exp((packed_scale >>> 21 & 2047) / 2047 * (max_scale_x - min_scale_x) + min_scale_x);
|
|
2465
|
+
single.sy = Math.exp((packed_scale >>> 11 & 1023) / 1023 * (max_scale_y - min_scale_y) + min_scale_y);
|
|
2466
|
+
single.sz = Math.exp((packed_scale & 2047) / 2047 * (max_scale_z - min_scale_z) + min_scale_z);
|
|
2467
|
+
single.r = (packed_color >>> 24 & 255) / 255 * (max_r - min_r) + min_r;
|
|
2468
|
+
single.g = (packed_color >>> 16 & 255) / 255 * (max_g - min_g) + min_g;
|
|
2469
|
+
single.b = (packed_color >>> 8 & 255) / 255 * (max_b - min_b) + min_b;
|
|
2470
|
+
single.a = (packed_color & 255) / 255;
|
|
2471
|
+
setFn(i, single);
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
} else if (name === "vertex") {
|
|
2475
|
+
fn = (i, item) => {
|
|
2476
|
+
single.x = item.x;
|
|
2477
|
+
single.y = item.y;
|
|
2478
|
+
single.z = item.z;
|
|
2479
|
+
single.sx = Math.exp(item.scale_0);
|
|
2480
|
+
single.sy = Math.exp(item.scale_1);
|
|
2481
|
+
single.sz = Math.exp(item.scale_2);
|
|
2482
|
+
single.qx = item.rot_1;
|
|
2483
|
+
single.qy = item.rot_2;
|
|
2484
|
+
single.qz = item.rot_3;
|
|
2485
|
+
single.qw = item.rot_0;
|
|
2486
|
+
single.r = item.f_dc_0 * SH_C0 + 0.5;
|
|
2487
|
+
single.g = item.f_dc_1 * SH_C0 + 0.5;
|
|
2488
|
+
single.b = item.f_dc_2 * SH_C0 + 0.5;
|
|
2489
|
+
single.a = 1 / (1 + Math.exp(-item.opacity));
|
|
2490
|
+
setFn(i, single);
|
|
2491
|
+
setShFn(i, item.f_rest);
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
chunkDecoders.push({
|
|
2495
|
+
init: () => [count, itemSize],
|
|
2496
|
+
decode: (offset, counts, buffer) => {
|
|
2497
|
+
offset += BlockOffset;
|
|
2498
|
+
const dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
2499
|
+
for (let i = 0; i < counts; i++) {
|
|
2500
|
+
parseFn(dataview, i * itemSize, block);
|
|
2501
|
+
fn(offset + i, block);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
decoder.setDecoders(chunkDecoders);
|
|
2507
|
+
};
|
|
2508
|
+
const textDecoder = new TextDecoder();
|
|
2509
|
+
const source = stream.getReader();
|
|
2510
|
+
while (true) {
|
|
2511
|
+
const { done, value } = await source.read();
|
|
2512
|
+
if (done) {
|
|
2513
|
+
break;
|
|
2514
|
+
}
|
|
2515
|
+
reader.write(value);
|
|
2516
|
+
if (!headerParsed) {
|
|
2517
|
+
const HeaderReadBlockSize = 4096;
|
|
2518
|
+
const counts = Math.ceil(reader.remaining / HeaderReadBlockSize);
|
|
2519
|
+
for (let i = 0; i < counts; i++) {
|
|
2520
|
+
const chunk = reader.read(HeaderReadBlockSize);
|
|
2521
|
+
header += textDecoder.decode(chunk, { stream: true });
|
|
2522
|
+
const idx = header.indexOf(HeaderTerminator);
|
|
2523
|
+
if (idx >= 0) {
|
|
2524
|
+
header = header.slice(0, idx + HeaderTerminator.length);
|
|
2525
|
+
reader.head -= HeaderReadBlockSize - new TextEncoder().encode(header).length % HeaderReadBlockSize;
|
|
2526
|
+
this.initHeader(header);
|
|
2527
|
+
initDecoder();
|
|
2528
|
+
BlockOffset = await data.initBlock(this.counts, this.shDegree);
|
|
2529
|
+
headerParsed = true;
|
|
2530
|
+
break;
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
if (!headerParsed) {
|
|
2534
|
+
continue;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
decoder.flush();
|
|
2538
|
+
}
|
|
2539
|
+
data.finishBlock();
|
|
2540
|
+
}
|
|
2541
|
+
async write(stream, data) {
|
|
2542
|
+
const writer2 = stream.getWriter();
|
|
2543
|
+
const counts = data.counts;
|
|
2544
|
+
const shDegree = data.shDegree;
|
|
2545
|
+
const shCounts = SH_MAPS2[shDegree];
|
|
2546
|
+
const shCoeffs = shCounts / 3;
|
|
2547
|
+
const header = [
|
|
2548
|
+
"ply",
|
|
2549
|
+
"format binary_little_endian 1.0",
|
|
2550
|
+
`comment Generated by EGS`,
|
|
2551
|
+
`element vertex ${counts}`,
|
|
2552
|
+
"property float x",
|
|
2553
|
+
"property float y",
|
|
2554
|
+
"property float z",
|
|
2555
|
+
"property float scale_0",
|
|
2556
|
+
"property float scale_1",
|
|
2557
|
+
"property float scale_2",
|
|
2558
|
+
"property float rot_1",
|
|
2559
|
+
"property float rot_2",
|
|
2560
|
+
"property float rot_3",
|
|
2561
|
+
"property float rot_0",
|
|
2562
|
+
"property float f_dc_0",
|
|
2563
|
+
"property float f_dc_1",
|
|
2564
|
+
"property float f_dc_2",
|
|
2565
|
+
"property float opacity",
|
|
2566
|
+
new Array(shCounts).fill(0).map((_, i) => `property float f_rest_${i}`),
|
|
2567
|
+
"end_header",
|
|
2568
|
+
""
|
|
2569
|
+
].flat().join("\n");
|
|
2570
|
+
writer2.write(new TextEncoder().encode(header));
|
|
2571
|
+
const ItemSize2 = 14 + shCounts;
|
|
2572
|
+
const chunkSize = 1024;
|
|
2573
|
+
const chunkCounts = Math.ceil(counts / chunkSize);
|
|
2574
|
+
const single = {
|
|
2575
|
+
x: 0,
|
|
2576
|
+
y: 0,
|
|
2577
|
+
z: 0,
|
|
2578
|
+
sx: 0,
|
|
2579
|
+
sy: 0,
|
|
2580
|
+
sz: 0,
|
|
2581
|
+
qx: 0,
|
|
2582
|
+
qy: 0,
|
|
2583
|
+
qz: 0,
|
|
2584
|
+
qw: 0,
|
|
2585
|
+
r: 0,
|
|
2586
|
+
g: 0,
|
|
2587
|
+
b: 0,
|
|
2588
|
+
a: 0,
|
|
2589
|
+
shN: new Array(shCounts)
|
|
2590
|
+
};
|
|
2591
|
+
const shN = single.shN;
|
|
2592
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
2593
|
+
if (writer2.desiredSize <= 0) {
|
|
2594
|
+
await writer2.ready;
|
|
2595
|
+
}
|
|
2596
|
+
const currentChunkSize = Math.min(chunkSize, counts - i * chunkSize);
|
|
2597
|
+
const chunk = new Float32Array(currentChunkSize * ItemSize2);
|
|
2598
|
+
const offset = i * chunkSize;
|
|
2599
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
2600
|
+
data.get(offset + j, single);
|
|
2601
|
+
data.getShN(offset + j, shN);
|
|
2602
|
+
const o = j * ItemSize2;
|
|
2603
|
+
chunk[o + 0] = single.x;
|
|
2604
|
+
chunk[o + 1] = single.y;
|
|
2605
|
+
chunk[o + 2] = single.z;
|
|
2606
|
+
chunk[o + 3] = Math.log(single.sx);
|
|
2607
|
+
chunk[o + 4] = Math.log(single.sy);
|
|
2608
|
+
chunk[o + 5] = Math.log(single.sz);
|
|
2609
|
+
chunk[o + 6] = single.qx;
|
|
2610
|
+
chunk[o + 7] = single.qy;
|
|
2611
|
+
chunk[o + 8] = single.qz;
|
|
2612
|
+
chunk[o + 9] = single.qw;
|
|
2613
|
+
chunk[o + 10] = (single.r - 0.5) / SH_C0;
|
|
2614
|
+
chunk[o + 11] = (single.g - 0.5) / SH_C0;
|
|
2615
|
+
chunk[o + 12] = (single.b - 0.5) / SH_C0;
|
|
2616
|
+
chunk[o + 13] = single.a === 0 ? -100 : -Math.log(1 / single.a - 1);
|
|
2617
|
+
for (let k = 0; k < shCounts; k++) {
|
|
2618
|
+
chunk[o + 14 + k] = shN[k % shCoeffs * 3 + (k / shCoeffs | 0)];
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
writer2.write(new Uint8Array(chunk.buffer));
|
|
2622
|
+
await Promise.resolve();
|
|
2623
|
+
}
|
|
2624
|
+
await writer2.close();
|
|
2625
|
+
}
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/sog.ts
|
|
2629
|
+
var ZIP_MAGIC = 67324752;
|
|
2630
|
+
var PERM_TABLE = [
|
|
2631
|
+
// original quat idx ---> actual storage idx
|
|
2632
|
+
[0, 1, 2, 3],
|
|
2633
|
+
[3, 1, 2, 0],
|
|
2634
|
+
[1, 3, 2, 0],
|
|
2635
|
+
[1, 2, 3, 0]
|
|
2636
|
+
];
|
|
2637
|
+
var TEMP_ROT = new Float32Array(4);
|
|
2638
|
+
var SogFile = class {
|
|
2639
|
+
constructor() {
|
|
2640
|
+
this.counts = 0;
|
|
2641
|
+
this.shDegree = 0;
|
|
2642
|
+
/**
|
|
2643
|
+
* @internal
|
|
2644
|
+
*/
|
|
2645
|
+
this.refs = {};
|
|
2646
|
+
}
|
|
2647
|
+
async load(stream, contentLength) {
|
|
2648
|
+
const buffer = new Uint8Array(contentLength);
|
|
2649
|
+
const reader = stream.getReader();
|
|
2650
|
+
let offset = 0;
|
|
2651
|
+
while (true) {
|
|
2652
|
+
const { done, value } = await reader.read();
|
|
2653
|
+
if (done) {
|
|
2654
|
+
break;
|
|
2655
|
+
}
|
|
2656
|
+
buffer.set(value, offset);
|
|
2657
|
+
offset += value.length;
|
|
2658
|
+
}
|
|
2659
|
+
let metaBuffer = buffer;
|
|
2660
|
+
const view = new DataView(buffer.buffer);
|
|
2661
|
+
if (view.getUint32(0, true) === ZIP_MAGIC) {
|
|
2662
|
+
this.refs = extractFromRootDir(unzipSync(buffer));
|
|
2663
|
+
metaBuffer = this.refs["meta.json"];
|
|
2664
|
+
if (!metaBuffer) {
|
|
2665
|
+
throw new Error("SOG meta.json not found in the zip archive.");
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
this.meta = JSON.parse(new TextDecoder().decode(metaBuffer));
|
|
2669
|
+
if (this.meta.version === void 0) {
|
|
2670
|
+
const { means, quats, shN } = this.meta;
|
|
2671
|
+
if (quats.encoding !== "quaternion_packed") {
|
|
2672
|
+
throw new Error("Unsupported quaternion encoding");
|
|
2673
|
+
}
|
|
2674
|
+
this.counts = means.shape[0];
|
|
2675
|
+
this.shDegree = shN ? NUM_F_REST_TO_SH_DEGREE[shN.shape[1]] : 0;
|
|
2676
|
+
this.version = 1;
|
|
2677
|
+
} else {
|
|
2678
|
+
const { version, count, shN } = this.meta;
|
|
2679
|
+
if (version !== 2) {
|
|
2680
|
+
throw new Error(`Unsupported SOGS version: ${version}`);
|
|
2681
|
+
}
|
|
2682
|
+
this.counts = count;
|
|
2683
|
+
this.shDegree = shN?.bands ?? 0;
|
|
2684
|
+
this.version = version;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
parse_v1(data, offset) {
|
|
2688
|
+
const setFn = data.set.bind(data);
|
|
2689
|
+
const setShFn = data.setShN.bind(data);
|
|
2690
|
+
const { meta, counts, shDegree, cached } = this;
|
|
2691
|
+
const [mean0, mean1, scale0, quat0, color0, centroids, labels] = cached.map((v) => v.data);
|
|
2692
|
+
const {
|
|
2693
|
+
means: { mins: [centerMinX, centerMinY, centerMinZ], maxs: [centerMaxX, centerMaxY, centerMaxZ] },
|
|
2694
|
+
scales: { mins: [scaleMinX, scaleMinY, scaleMinZ], maxs: [scaleMaxX, scaleMaxY, scaleMaxZ] },
|
|
2695
|
+
sh0: { mins: [colorMinR, colorMinG, colorMinB, colorMinA], maxs: [colorMaxR, colorMaxG, colorMaxB, colorMaxA] },
|
|
2696
|
+
shN
|
|
2697
|
+
} = meta;
|
|
2698
|
+
const rangeX = (centerMaxX - centerMinX) / 65535;
|
|
2699
|
+
const rangeY = (centerMaxY - centerMinY) / 65535;
|
|
2700
|
+
const rangeZ = (centerMaxZ - centerMinZ) / 65535;
|
|
2701
|
+
const SX_LUT = new Float32Array(256);
|
|
2702
|
+
const SY_LUT = new Float32Array(256);
|
|
2703
|
+
const SZ_LUT = new Float32Array(256);
|
|
2704
|
+
const scaleRangeX = (scaleMaxX - scaleMinX) / 255;
|
|
2705
|
+
const scaleRangeY = (scaleMaxY - scaleMinY) / 255;
|
|
2706
|
+
const scaleRangeZ = (scaleMaxZ - scaleMinZ) / 255;
|
|
2707
|
+
for (let i = 0; i < 256; i++) {
|
|
2708
|
+
SX_LUT[i] = Math.exp(scaleMinX + scaleRangeX * i);
|
|
2709
|
+
SY_LUT[i] = Math.exp(scaleMinY + scaleRangeY * i);
|
|
2710
|
+
SZ_LUT[i] = Math.exp(scaleMinZ + scaleRangeZ * i);
|
|
2711
|
+
}
|
|
2712
|
+
const A_LUT = new Float32Array(256);
|
|
2713
|
+
const colorRangeR = (colorMaxR - colorMinR) / 255;
|
|
2714
|
+
const colorRangeG = (colorMaxG - colorMinG) / 255;
|
|
2715
|
+
const colorRangeB = (colorMaxB - colorMinB) / 255;
|
|
2716
|
+
const colorRangeA = (colorMaxA - colorMinA) / 255;
|
|
2717
|
+
for (let i = 0; i < 256; i++) {
|
|
2718
|
+
A_LUT[i] = 1 / (1 + Math.exp(-(colorMinA + colorRangeA * i)));
|
|
2719
|
+
}
|
|
2720
|
+
const single = {
|
|
2721
|
+
x: 0,
|
|
2722
|
+
y: 0,
|
|
2723
|
+
z: 0,
|
|
2724
|
+
sx: 0,
|
|
2725
|
+
sy: 0,
|
|
2726
|
+
sz: 0,
|
|
2727
|
+
qx: 0,
|
|
2728
|
+
qy: 0,
|
|
2729
|
+
qz: 0,
|
|
2730
|
+
qw: 0,
|
|
2731
|
+
r: 0,
|
|
2732
|
+
g: 0,
|
|
2733
|
+
b: 0,
|
|
2734
|
+
a: 0,
|
|
2735
|
+
shN: []
|
|
2736
|
+
};
|
|
2737
|
+
for (let i = 0; i < counts; i++) {
|
|
2738
|
+
const i4 = i * 4;
|
|
2739
|
+
const x = centerMinX + rangeX * (mean0[i4 + 0] + (mean1[i4 + 0] << 8));
|
|
2740
|
+
const y = centerMinY + rangeY * (mean0[i4 + 1] + (mean1[i4 + 1] << 8));
|
|
2741
|
+
const z = centerMinZ + rangeZ * (mean0[i4 + 2] + (mean1[i4 + 2] << 8));
|
|
2742
|
+
single.x = Math.sign(x) * (Math.exp(Math.abs(x)) - 1);
|
|
2743
|
+
single.y = Math.sign(y) * (Math.exp(Math.abs(y)) - 1);
|
|
2744
|
+
single.z = Math.sign(z) * (Math.exp(Math.abs(z)) - 1);
|
|
2745
|
+
single.sx = SX_LUT[scale0[i4 + 0]];
|
|
2746
|
+
single.sy = SY_LUT[scale0[i4 + 1]];
|
|
2747
|
+
single.sz = SZ_LUT[scale0[i4 + 2]];
|
|
2748
|
+
TEMP_ROT[0] = (quat0[i4 + 0] / 255 - 0.5) * Math.SQRT2;
|
|
2749
|
+
TEMP_ROT[1] = (quat0[i4 + 1] / 255 - 0.5) * Math.SQRT2;
|
|
2750
|
+
TEMP_ROT[2] = (quat0[i4 + 2] / 255 - 0.5) * Math.SQRT2;
|
|
2751
|
+
TEMP_ROT[3] = Math.sqrt(Math.max(0, 1 - TEMP_ROT[0] * TEMP_ROT[0] - TEMP_ROT[1] * TEMP_ROT[1] - TEMP_ROT[2] * TEMP_ROT[2]));
|
|
2752
|
+
const PERM = PERM_TABLE[quat0[i4 + 3] - 252];
|
|
2753
|
+
single.qx = TEMP_ROT[PERM[0]];
|
|
2754
|
+
single.qy = TEMP_ROT[PERM[1]];
|
|
2755
|
+
single.qz = TEMP_ROT[PERM[2]];
|
|
2756
|
+
single.qw = TEMP_ROT[PERM[3]];
|
|
2757
|
+
single.r = SH_C0 * (colorMinR + colorRangeR * color0[i4 + 0]) + 0.5;
|
|
2758
|
+
single.g = SH_C0 * (colorMinG + colorRangeG * color0[i4 + 1]) + 0.5;
|
|
2759
|
+
single.b = SH_C0 * (colorMinB + colorRangeB * color0[i4 + 2]) + 0.5;
|
|
2760
|
+
single.a = A_LUT[color0[i4 + 3]];
|
|
2761
|
+
setFn(offset + i, single);
|
|
2762
|
+
}
|
|
2763
|
+
if (shN) {
|
|
2764
|
+
const centroidTexWidth = cached[5].width;
|
|
2765
|
+
const { mins: min, maxs: max2 } = shN;
|
|
2766
|
+
const range = (max2 - min) / 255;
|
|
2767
|
+
const shCounts = SH_MAPS2[shDegree];
|
|
2768
|
+
const sh = new Array(shCounts);
|
|
2769
|
+
const shCoeffs = shCounts / 3;
|
|
2770
|
+
for (let i = 0; i < counts; i++) {
|
|
2771
|
+
const i4 = i * 4;
|
|
2772
|
+
const label = labels[i4] + (labels[i4 + 1] << 8);
|
|
2773
|
+
const o = ((label >>> 6) * centroidTexWidth + (label & 63) * 15) * 4;
|
|
2774
|
+
for (let j = 0; j < shCoeffs; j++) {
|
|
2775
|
+
sh[j * 3 + 0] = min + range * centroids[o + j * 4 + 0];
|
|
2776
|
+
sh[j * 3 + 1] = min + range * centroids[o + j * 4 + 1];
|
|
2777
|
+
sh[j * 3 + 2] = min + range * centroids[o + j * 4 + 2];
|
|
2778
|
+
}
|
|
2779
|
+
setShFn(offset + i, sh);
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
parse_v2(data, offset) {
|
|
2784
|
+
const setFn = data.set.bind(data);
|
|
2785
|
+
const setShFn = data.setShN.bind(data);
|
|
2786
|
+
const { meta, counts, shDegree, cached } = this;
|
|
2787
|
+
const { means, scales, sh0, shN } = meta;
|
|
2788
|
+
const {
|
|
2789
|
+
mins: [centerMinX, centerMinY, centerMinZ],
|
|
2790
|
+
maxs: [centerMaxX, centerMaxY, centerMaxZ]
|
|
2791
|
+
} = means;
|
|
2792
|
+
const { codebook: scaleCodebook } = scales;
|
|
2793
|
+
const { codebook: sh0Codebook } = sh0;
|
|
2794
|
+
const [mean0, mean1, scale0, quat0, color0, centroids, labels] = cached.map((img) => img.data);
|
|
2795
|
+
const rangeX = (centerMaxX - centerMinX) / 65535;
|
|
2796
|
+
const rangeY = (centerMaxY - centerMinY) / 65535;
|
|
2797
|
+
const rangeZ = (centerMaxZ - centerMinZ) / 65535;
|
|
2798
|
+
const SCALE_LUT = scaleCodebook.map((v) => Math.exp(v));
|
|
2799
|
+
const single = {
|
|
2800
|
+
x: 0,
|
|
2801
|
+
y: 0,
|
|
2802
|
+
z: 0,
|
|
2803
|
+
sx: 0,
|
|
2804
|
+
sy: 0,
|
|
2805
|
+
sz: 0,
|
|
2806
|
+
qx: 0,
|
|
2807
|
+
qy: 0,
|
|
2808
|
+
qz: 0,
|
|
2809
|
+
qw: 0,
|
|
2810
|
+
r: 0,
|
|
2811
|
+
g: 0,
|
|
2812
|
+
b: 0,
|
|
2813
|
+
a: 0,
|
|
2814
|
+
shN: []
|
|
2815
|
+
};
|
|
2816
|
+
for (let i = 0; i < counts; i++) {
|
|
2817
|
+
const i4 = i * 4;
|
|
2818
|
+
const x = centerMinX + rangeX * (mean0[i4 + 0] + (mean1[i4 + 0] << 8));
|
|
2819
|
+
const y = centerMinY + rangeY * (mean0[i4 + 1] + (mean1[i4 + 1] << 8));
|
|
2820
|
+
const z = centerMinZ + rangeZ * (mean0[i4 + 2] + (mean1[i4 + 2] << 8));
|
|
2821
|
+
single.x = Math.sign(x) * (Math.exp(Math.abs(x)) - 1);
|
|
2822
|
+
single.y = Math.sign(y) * (Math.exp(Math.abs(y)) - 1);
|
|
2823
|
+
single.z = Math.sign(z) * (Math.exp(Math.abs(z)) - 1);
|
|
2824
|
+
single.sx = SCALE_LUT[scale0[i4 + 0]];
|
|
2825
|
+
single.sy = SCALE_LUT[scale0[i4 + 1]];
|
|
2826
|
+
single.sz = SCALE_LUT[scale0[i4 + 2]];
|
|
2827
|
+
TEMP_ROT[0] = (quat0[i4 + 0] / 255 - 0.5) * Math.SQRT2;
|
|
2828
|
+
TEMP_ROT[1] = (quat0[i4 + 1] / 255 - 0.5) * Math.SQRT2;
|
|
2829
|
+
TEMP_ROT[2] = (quat0[i4 + 2] / 255 - 0.5) * Math.SQRT2;
|
|
2830
|
+
TEMP_ROT[3] = Math.sqrt(Math.max(0, 1 - TEMP_ROT[0] * TEMP_ROT[0] - TEMP_ROT[1] * TEMP_ROT[1] - TEMP_ROT[2] * TEMP_ROT[2]));
|
|
2831
|
+
const PERM = PERM_TABLE[quat0[i4 + 3] - 252];
|
|
2832
|
+
single.qx = TEMP_ROT[PERM[0]];
|
|
2833
|
+
single.qy = TEMP_ROT[PERM[1]];
|
|
2834
|
+
single.qz = TEMP_ROT[PERM[2]];
|
|
2835
|
+
single.qw = TEMP_ROT[PERM[3]];
|
|
2836
|
+
single.r = SH_C0 * sh0Codebook[color0[i4 + 0]] + 0.5;
|
|
2837
|
+
single.g = SH_C0 * sh0Codebook[color0[i4 + 1]] + 0.5;
|
|
2838
|
+
single.b = SH_C0 * sh0Codebook[color0[i4 + 2]] + 0.5;
|
|
2839
|
+
single.a = color0[i4 + 3] / 255;
|
|
2840
|
+
setFn(offset + i, single);
|
|
2841
|
+
}
|
|
2842
|
+
if (shN) {
|
|
2843
|
+
const { codebook } = shN;
|
|
2844
|
+
const shCounts = SH_MAPS2[shDegree];
|
|
2845
|
+
const shCoeffs = shCounts / 3;
|
|
2846
|
+
const offsetItemSize = shCoeffs * 4;
|
|
2847
|
+
const sh = new Array(shCounts);
|
|
2848
|
+
for (let i = 0; i < counts; i++) {
|
|
2849
|
+
const i4 = i * 4;
|
|
2850
|
+
const o = (labels[i4 + 0] + (labels[i4 + 1] << 8)) * offsetItemSize;
|
|
2851
|
+
for (let j = 0; j < shCoeffs; j++) {
|
|
2852
|
+
sh[j * 3] = codebook[centroids[o + j * 4 + 0]];
|
|
2853
|
+
sh[j * 3 + 1] = codebook[centroids[o + j * 4 + 1]];
|
|
2854
|
+
sh[j * 3 + 2] = codebook[centroids[o + j * 4 + 2]];
|
|
2855
|
+
}
|
|
2856
|
+
setShFn(offset + i, sh);
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
async loadTexture(path) {
|
|
2861
|
+
let buffer = this.refs[path];
|
|
2862
|
+
if (!buffer && isUrl(path)) {
|
|
2863
|
+
buffer = await fetch(path).then((res) => res.arrayBuffer()).then((buf) => new Uint8Array(buf));
|
|
2864
|
+
}
|
|
2865
|
+
if (!buffer) {
|
|
2866
|
+
throw new Error(`Cannot load texture: ${path}`);
|
|
2867
|
+
}
|
|
2868
|
+
return decodeImage(buffer.buffer);
|
|
2869
|
+
}
|
|
2870
|
+
async read(stream, contentLength, data) {
|
|
2871
|
+
await this.load(stream, contentLength);
|
|
2872
|
+
const BlockOffset = await data.initBlock(this.counts, this.shDegree);
|
|
2873
|
+
const { means, scales, quats, sh0, shN } = this.meta;
|
|
2874
|
+
this.cached = await Promise.all([
|
|
2875
|
+
means.files[0],
|
|
2876
|
+
means.files[1],
|
|
2877
|
+
scales.files[0],
|
|
2878
|
+
quats.files[0],
|
|
2879
|
+
sh0.files[0],
|
|
2880
|
+
shN?.files[0],
|
|
2881
|
+
shN?.files[1]
|
|
2882
|
+
].filter((path) => !!path).map((path) => this.loadTexture(path)));
|
|
2883
|
+
if (this.version === 1) {
|
|
2884
|
+
this.parse_v1(data, BlockOffset);
|
|
2885
|
+
} else if (this.version === 2) {
|
|
2886
|
+
this.parse_v2(data, BlockOffset);
|
|
2887
|
+
} else {
|
|
2888
|
+
throw new Error(`Unsupported SOG version: ${this.version}`);
|
|
2889
|
+
}
|
|
2890
|
+
data.finishBlock();
|
|
2891
|
+
}
|
|
2892
|
+
async write(_stream, _data) {
|
|
2893
|
+
throw new Error("Method not implemented.");
|
|
2894
|
+
}
|
|
2895
|
+
};
|
|
2896
|
+
|
|
2897
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/splat.ts
|
|
2898
|
+
var ItemSize = 32;
|
|
2899
|
+
var SplatFile = class {
|
|
2900
|
+
async read(stream, contentLength, data) {
|
|
2901
|
+
const setFn = data.set.bind(data);
|
|
2902
|
+
const counts = Math.floor(contentLength / ItemSize);
|
|
2903
|
+
const BlockOffset = await data.initBlock(counts, 0);
|
|
2904
|
+
const reader = new BufferReader();
|
|
2905
|
+
const decoder = new StreamChunkDecoder(reader);
|
|
2906
|
+
const single = {
|
|
2907
|
+
x: 0,
|
|
2908
|
+
y: 0,
|
|
2909
|
+
z: 0,
|
|
2910
|
+
sx: 0,
|
|
2911
|
+
sy: 0,
|
|
2912
|
+
sz: 0,
|
|
2913
|
+
qx: 0,
|
|
2914
|
+
qy: 0,
|
|
2915
|
+
qz: 0,
|
|
2916
|
+
qw: 0,
|
|
2917
|
+
r: 0,
|
|
2918
|
+
g: 0,
|
|
2919
|
+
b: 0,
|
|
2920
|
+
a: 0,
|
|
2921
|
+
shN: []
|
|
2922
|
+
};
|
|
2923
|
+
decoder.setDecoders([
|
|
2924
|
+
{
|
|
2925
|
+
init: () => [counts, ItemSize],
|
|
2926
|
+
decode: (offset, counts2, buffer) => {
|
|
2927
|
+
offset += BlockOffset;
|
|
2928
|
+
const f32Array = new Float32Array(buffer.buffer);
|
|
2929
|
+
let o = 0;
|
|
2930
|
+
for (let i = 0; i < counts2; i++) {
|
|
2931
|
+
o = i * 8;
|
|
2932
|
+
single.x = f32Array[o];
|
|
2933
|
+
single.y = f32Array[o + 1];
|
|
2934
|
+
single.z = f32Array[o + 2];
|
|
2935
|
+
single.sx = f32Array[o + 3];
|
|
2936
|
+
single.sy = f32Array[o + 4];
|
|
2937
|
+
single.sz = f32Array[o + 5];
|
|
2938
|
+
o = i * 32;
|
|
2939
|
+
single.r = buffer[o + 24] / 255;
|
|
2940
|
+
single.g = buffer[o + 25] / 255;
|
|
2941
|
+
single.b = buffer[o + 26] / 255;
|
|
2942
|
+
single.a = buffer[o + 27] / 255;
|
|
2943
|
+
single.qw = (buffer[o + 28] - 128) / 128;
|
|
2944
|
+
single.qx = (buffer[o + 29] - 128) / 128;
|
|
2945
|
+
single.qy = (buffer[o + 30] - 128) / 128;
|
|
2946
|
+
single.qz = (buffer[o + 31] - 128) / 128;
|
|
2947
|
+
setFn(offset + i, single);
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
]);
|
|
2952
|
+
const source = stream.getReader();
|
|
2953
|
+
while (true) {
|
|
2954
|
+
const { done, value } = await source.read();
|
|
2955
|
+
if (done) {
|
|
2956
|
+
break;
|
|
2957
|
+
}
|
|
2958
|
+
reader.write(value);
|
|
2959
|
+
decoder.flush();
|
|
2960
|
+
}
|
|
2961
|
+
data.finishBlock();
|
|
2962
|
+
}
|
|
2963
|
+
async write(stream, data) {
|
|
2964
|
+
const writer2 = stream.getWriter();
|
|
2965
|
+
const chunkSize = 2048;
|
|
2966
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
2967
|
+
const single = {
|
|
2968
|
+
x: 0,
|
|
2969
|
+
y: 0,
|
|
2970
|
+
z: 0,
|
|
2971
|
+
sx: 0,
|
|
2972
|
+
sy: 0,
|
|
2973
|
+
sz: 0,
|
|
2974
|
+
qx: 0,
|
|
2975
|
+
qy: 0,
|
|
2976
|
+
qz: 0,
|
|
2977
|
+
qw: 0,
|
|
2978
|
+
r: 0,
|
|
2979
|
+
g: 0,
|
|
2980
|
+
b: 0,
|
|
2981
|
+
a: 0,
|
|
2982
|
+
shN: []
|
|
2983
|
+
};
|
|
2984
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
2985
|
+
if (writer2.desiredSize <= 0) {
|
|
2986
|
+
await writer2.ready;
|
|
2987
|
+
}
|
|
2988
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
2989
|
+
const chunk = new Uint8Array(currentChunkSize * ItemSize);
|
|
2990
|
+
const dataView = new DataView(chunk.buffer);
|
|
2991
|
+
const offset = i * chunkSize;
|
|
2992
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
2993
|
+
data.get(offset + j, single);
|
|
2994
|
+
const o = j * ItemSize;
|
|
2995
|
+
dataView.setFloat32(o, single.x, true);
|
|
2996
|
+
dataView.setFloat32(o + 4, single.y, true);
|
|
2997
|
+
dataView.setFloat32(o + 8, single.z, true);
|
|
2998
|
+
dataView.setFloat32(o + 12, single.sx, true);
|
|
2999
|
+
dataView.setFloat32(o + 16, single.sy, true);
|
|
3000
|
+
dataView.setFloat32(o + 20, single.sz, true);
|
|
3001
|
+
dataView.setUint8(o + 24, clamp2(Math.round(single.r * 255), 0, 255));
|
|
3002
|
+
dataView.setUint8(o + 25, clamp2(Math.round(single.g * 255), 0, 255));
|
|
3003
|
+
dataView.setUint8(o + 26, clamp2(Math.round(single.b * 255), 0, 255));
|
|
3004
|
+
dataView.setUint8(o + 27, clamp2(Math.round(single.a * 255), 0, 255));
|
|
3005
|
+
dataView.setUint8(o + 28, clamp2(Math.round(single.qw * 128 + 128), 0, 255));
|
|
3006
|
+
dataView.setUint8(o + 29, clamp2(Math.round(single.qx * 128 + 128), 0, 255));
|
|
3007
|
+
dataView.setUint8(o + 30, clamp2(Math.round(single.qy * 128 + 128), 0, 255));
|
|
3008
|
+
dataView.setUint8(o + 31, clamp2(Math.round(single.qz * 128 + 128), 0, 255));
|
|
3009
|
+
}
|
|
3010
|
+
writer2.write(chunk);
|
|
3011
|
+
await Promise.resolve();
|
|
3012
|
+
}
|
|
3013
|
+
await writer2.close();
|
|
3014
|
+
}
|
|
3015
|
+
};
|
|
3016
|
+
|
|
3017
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/spz.ts
|
|
3018
|
+
var SPZ_MAGIC = 1347635022;
|
|
3019
|
+
var SPZ_VERSION = 3;
|
|
3020
|
+
var FLAG_ANTIALIASED = 1;
|
|
3021
|
+
var COLOR_SCALE = SH_C0 / 0.15;
|
|
3022
|
+
var rotation = new Array(4);
|
|
3023
|
+
var SH_SCALE1 = 1 << 3;
|
|
3024
|
+
var SH_SCALE2 = 1 << 4;
|
|
3025
|
+
var SpzFile = class {
|
|
3026
|
+
async read(stream, _contentLength, data) {
|
|
3027
|
+
const setCenter = data.setCenter.bind(data);
|
|
3028
|
+
const setAlpha = data.setAlpha.bind(data);
|
|
3029
|
+
const setColor = data.setColor.bind(data);
|
|
3030
|
+
const setScale = data.setScale.bind(data);
|
|
3031
|
+
const setQuat = data.setQuat.bind(data);
|
|
3032
|
+
const setShN = data.setShN.bind(data);
|
|
3033
|
+
const SCALE_LUT = new Float32Array(256);
|
|
3034
|
+
for (let i = 0; i < 256; i++) {
|
|
3035
|
+
SCALE_LUT[i] = Math.exp(i / 16 - 10);
|
|
3036
|
+
}
|
|
3037
|
+
const COLOR_LUT = new Float32Array(256);
|
|
3038
|
+
for (let i = 0; i < 256; i++) {
|
|
3039
|
+
COLOR_LUT[i] = (i / 255 - 0.5) * COLOR_SCALE + 0.5;
|
|
3040
|
+
}
|
|
3041
|
+
let version = SPZ_VERSION;
|
|
3042
|
+
let counts = 0;
|
|
3043
|
+
let shDegree = 0;
|
|
3044
|
+
let fractionalBits = 12;
|
|
3045
|
+
let flags = FLAG_ANTIALIASED;
|
|
3046
|
+
let reserved = 0;
|
|
3047
|
+
let isF16 = false;
|
|
3048
|
+
let useSmallestThreeQuat = true;
|
|
3049
|
+
let fraction = 1;
|
|
3050
|
+
let fractionInv = 1;
|
|
3051
|
+
let shCounts = 0;
|
|
3052
|
+
let BlockOffset = 0;
|
|
3053
|
+
const shN = [];
|
|
3054
|
+
const reader = new BufferReader();
|
|
3055
|
+
const decoder = new StreamChunkDecoder(reader);
|
|
3056
|
+
decoder.setDecoders([
|
|
3057
|
+
{
|
|
3058
|
+
init: () => [1, 16],
|
|
3059
|
+
decode: async (_offset, _counts, buf) => {
|
|
3060
|
+
const header = new DataView(buf.buffer);
|
|
3061
|
+
if (header.getUint32(0, true) !== SPZ_MAGIC) {
|
|
3062
|
+
throw new Error("Invalid SPZ file");
|
|
3063
|
+
}
|
|
3064
|
+
version = header.getUint32(4, true);
|
|
3065
|
+
if (version < 1 || version > 3) {
|
|
3066
|
+
throw new Error(`Unsupported SPZ version: ${version}`);
|
|
3067
|
+
}
|
|
3068
|
+
counts = header.getUint32(8, true);
|
|
3069
|
+
shDegree = header.getUint8(12);
|
|
3070
|
+
fractionalBits = header.getUint8(13);
|
|
3071
|
+
flags = header.getUint8(14);
|
|
3072
|
+
reserved = header.getUint8(15);
|
|
3073
|
+
isF16 = version < 2;
|
|
3074
|
+
useSmallestThreeQuat = version >= 3;
|
|
3075
|
+
fraction = 1 << fractionalBits;
|
|
3076
|
+
fractionInv = 1 / fraction;
|
|
3077
|
+
shCounts = SH_MAPS2[shDegree];
|
|
3078
|
+
BlockOffset = await data.initBlock(counts, shDegree);
|
|
3079
|
+
if (flags || reserved) {
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
},
|
|
3083
|
+
{
|
|
3084
|
+
init: () => [counts, isF16 ? 6 : 9],
|
|
3085
|
+
decode: (offset, counts2, buf) => {
|
|
3086
|
+
offset += BlockOffset;
|
|
3087
|
+
let x, y, z;
|
|
3088
|
+
for (let i = 0; i < counts2; i++) {
|
|
3089
|
+
if (isF16) {
|
|
3090
|
+
const o = i * 6;
|
|
3091
|
+
x = fromHalf2(buf[o + 1] << 8 | buf[o]);
|
|
3092
|
+
y = fromHalf2(buf[o + 3] << 8 | buf[o + 2]);
|
|
3093
|
+
z = fromHalf2(buf[o + 5] << 8 | buf[o + 4]);
|
|
3094
|
+
} else {
|
|
3095
|
+
const o = i * 9;
|
|
3096
|
+
x = ((buf[o + 2] << 24 | buf[o + 1] << 16 | buf[o] << 8) >> 8) * fractionInv;
|
|
3097
|
+
y = ((buf[o + 5] << 24 | buf[o + 4] << 16 | buf[o + 3] << 8) >> 8) * fractionInv;
|
|
3098
|
+
z = ((buf[o + 8] << 24 | buf[o + 7] << 16 | buf[o + 6] << 8) >> 8) * fractionInv;
|
|
3099
|
+
}
|
|
3100
|
+
setCenter(offset + i, x, y, z);
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
},
|
|
3104
|
+
{
|
|
3105
|
+
init: () => [counts, 1],
|
|
3106
|
+
decode: (offset, counts2, buf) => {
|
|
3107
|
+
offset += BlockOffset;
|
|
3108
|
+
for (let i = 0; i < counts2; i++) {
|
|
3109
|
+
setAlpha(offset + i, buf[i] / 255);
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
},
|
|
3113
|
+
{
|
|
3114
|
+
init: () => [counts, 3],
|
|
3115
|
+
decode: (offset, counts2, buf) => {
|
|
3116
|
+
offset += BlockOffset;
|
|
3117
|
+
for (let i = 0; i < counts2; i++) {
|
|
3118
|
+
const o = i * 3;
|
|
3119
|
+
setColor(offset + i, COLOR_LUT[buf[o]], COLOR_LUT[buf[o + 1]], COLOR_LUT[buf[o + 2]]);
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
},
|
|
3123
|
+
{
|
|
3124
|
+
init: () => [counts, 3],
|
|
3125
|
+
decode: (offset, counts2, buf) => {
|
|
3126
|
+
offset += BlockOffset;
|
|
3127
|
+
for (let i = 0; i < counts2; i++) {
|
|
3128
|
+
const o = i * 3;
|
|
3129
|
+
setScale(offset + i, SCALE_LUT[buf[o]], SCALE_LUT[buf[o + 1]], SCALE_LUT[buf[o + 2]]);
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
},
|
|
3133
|
+
{
|
|
3134
|
+
init: () => [counts, useSmallestThreeQuat ? 4 : 3],
|
|
3135
|
+
decode: (offset, counts2, buf) => {
|
|
3136
|
+
offset += BlockOffset;
|
|
3137
|
+
let qx, qy, qz, qw;
|
|
3138
|
+
for (let i = 0; i < counts2; i++) {
|
|
3139
|
+
if (!useSmallestThreeQuat) {
|
|
3140
|
+
const o = i * 3;
|
|
3141
|
+
qx = buf[o] / 127.5 - 1;
|
|
3142
|
+
qy = buf[o + 1] / 127.5 - 1;
|
|
3143
|
+
qz = buf[o + 2] / 127.5 - 1;
|
|
3144
|
+
qw = Math.sqrt(Math.max(0, 1 - qx * qx - qy * qy - qz * qz));
|
|
3145
|
+
} else {
|
|
3146
|
+
const o = i * 4;
|
|
3147
|
+
const packed = buf[o] | buf[o + 1] << 8 | buf[o + 2] << 16 | buf[o + 3] << 24;
|
|
3148
|
+
const largest = packed >>> 30;
|
|
3149
|
+
let temp = packed;
|
|
3150
|
+
let sum = 0;
|
|
3151
|
+
for (let j = 3; j >= 0; j--) {
|
|
3152
|
+
if (j === largest) {
|
|
3153
|
+
continue;
|
|
3154
|
+
}
|
|
3155
|
+
const mag = temp & 511;
|
|
3156
|
+
const sign = temp >>> 9 & 1;
|
|
3157
|
+
temp >>>= 10;
|
|
3158
|
+
const v = Math.SQRT1_2 * (mag / 511) * (sign ? -1 : 1);
|
|
3159
|
+
rotation[j] = v;
|
|
3160
|
+
sum += v * v;
|
|
3161
|
+
}
|
|
3162
|
+
rotation[largest] = Math.sqrt(1 - sum);
|
|
3163
|
+
qx = rotation[0];
|
|
3164
|
+
qy = rotation[1];
|
|
3165
|
+
qz = rotation[2];
|
|
3166
|
+
qw = rotation[3];
|
|
3167
|
+
}
|
|
3168
|
+
setQuat(offset + i, qx, qy, qz, qw);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
},
|
|
3172
|
+
{
|
|
3173
|
+
init: () => [counts, shCounts],
|
|
3174
|
+
decode: (offset, counts2, buf) => {
|
|
3175
|
+
offset += BlockOffset;
|
|
3176
|
+
for (let i = 0; i < counts2; i++) {
|
|
3177
|
+
const o = i * shCounts;
|
|
3178
|
+
for (let j = 0; j < shCounts; j++) {
|
|
3179
|
+
shN[j] = (buf[o + j] - 128) / 128;
|
|
3180
|
+
}
|
|
3181
|
+
setShN(offset + i, shN);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
]);
|
|
3186
|
+
const source = stream.pipeThrough(new self.DecompressionStream("gzip")).getReader();
|
|
3187
|
+
while (true) {
|
|
3188
|
+
const { done, value } = await source.read();
|
|
3189
|
+
if (done) {
|
|
3190
|
+
break;
|
|
3191
|
+
}
|
|
3192
|
+
reader.write(value);
|
|
3193
|
+
decoder.flush();
|
|
3194
|
+
}
|
|
3195
|
+
data.finishBlock();
|
|
3196
|
+
}
|
|
3197
|
+
async write(writeStream, data) {
|
|
3198
|
+
const compressStream = new self.CompressionStream("gzip");
|
|
3199
|
+
const pipePromise = compressStream.readable.pipeTo(writeStream);
|
|
3200
|
+
const writer2 = compressStream.writable.getWriter();
|
|
3201
|
+
const version = SPZ_VERSION;
|
|
3202
|
+
const counts = data.counts;
|
|
3203
|
+
const shDegree = data.shDegree;
|
|
3204
|
+
const fractionalBits = 12;
|
|
3205
|
+
const flags = FLAG_ANTIALIASED;
|
|
3206
|
+
const reserved = 0;
|
|
3207
|
+
const fraction = 1 << fractionalBits;
|
|
3208
|
+
const shCounts = SH_MAPS2[shDegree];
|
|
3209
|
+
{
|
|
3210
|
+
const buffer = new Uint8Array(16);
|
|
3211
|
+
const header = new DataView(buffer.buffer);
|
|
3212
|
+
header.setUint32(0, SPZ_MAGIC, true);
|
|
3213
|
+
header.setUint32(4, version, true);
|
|
3214
|
+
header.setUint32(8, counts, true);
|
|
3215
|
+
header.setUint8(12, shDegree);
|
|
3216
|
+
header.setUint8(13, fractionalBits);
|
|
3217
|
+
header.setUint8(14, flags);
|
|
3218
|
+
header.setUint8(15, reserved);
|
|
3219
|
+
writer2.write(buffer);
|
|
3220
|
+
}
|
|
3221
|
+
const single = {
|
|
3222
|
+
x: 0,
|
|
3223
|
+
y: 0,
|
|
3224
|
+
z: 0,
|
|
3225
|
+
sx: 0,
|
|
3226
|
+
sy: 0,
|
|
3227
|
+
sz: 0,
|
|
3228
|
+
qx: 0,
|
|
3229
|
+
qy: 0,
|
|
3230
|
+
qz: 0,
|
|
3231
|
+
qw: 0,
|
|
3232
|
+
r: 0,
|
|
3233
|
+
g: 0,
|
|
3234
|
+
b: 0,
|
|
3235
|
+
a: 0,
|
|
3236
|
+
shN: new Array(shCounts)
|
|
3237
|
+
};
|
|
3238
|
+
{
|
|
3239
|
+
const ItemSize2 = 9;
|
|
3240
|
+
const chunkSize = 4096;
|
|
3241
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
3242
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
3243
|
+
if (writer2.desiredSize <= 0) {
|
|
3244
|
+
await writer2.ready;
|
|
3245
|
+
}
|
|
3246
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
3247
|
+
const chunk = new Uint8Array(currentChunkSize * ItemSize2);
|
|
3248
|
+
const offset = i * chunkSize;
|
|
3249
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
3250
|
+
data.getCenter(offset + j, single);
|
|
3251
|
+
const o = j * ItemSize2;
|
|
3252
|
+
const ix = clamp2(single.x * fraction, -8388607, 8388607);
|
|
3253
|
+
chunk[o + 0] = ix & 255;
|
|
3254
|
+
chunk[o + 1] = ix >> 8 & 255;
|
|
3255
|
+
chunk[o + 2] = ix >> 16 & 255;
|
|
3256
|
+
const iy = clamp2(single.y * fraction, -8388607, 8388607);
|
|
3257
|
+
chunk[o + 3] = iy & 255;
|
|
3258
|
+
chunk[o + 4] = iy >> 8 & 255;
|
|
3259
|
+
chunk[o + 5] = iy >> 16 & 255;
|
|
3260
|
+
const iz = clamp2(single.z * fraction, -8388607, 8388607);
|
|
3261
|
+
chunk[o + 6] = iz & 255;
|
|
3262
|
+
chunk[o + 7] = iz >> 8 & 255;
|
|
3263
|
+
chunk[o + 8] = iz >> 16 & 255;
|
|
3264
|
+
}
|
|
3265
|
+
writer2.write(chunk);
|
|
3266
|
+
await Promise.resolve();
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
{
|
|
3270
|
+
const chunkSize = 65536;
|
|
3271
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
3272
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
3273
|
+
if (writer2.desiredSize <= 0) {
|
|
3274
|
+
await writer2.ready;
|
|
3275
|
+
}
|
|
3276
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
3277
|
+
const chunk = new Uint8Array(currentChunkSize);
|
|
3278
|
+
const offset = i * chunkSize;
|
|
3279
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
3280
|
+
data.getAlpha(offset + j, single);
|
|
3281
|
+
chunk[j] = clamp2(Math.round(single.a * 255), 0, 255);
|
|
3282
|
+
}
|
|
3283
|
+
writer2.write(chunk);
|
|
3284
|
+
await Promise.resolve();
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
{
|
|
3288
|
+
const ItemSize2 = 3;
|
|
3289
|
+
const chunkSize = 16384;
|
|
3290
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
3291
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
3292
|
+
if (writer2.desiredSize <= 0) {
|
|
3293
|
+
await writer2.ready;
|
|
3294
|
+
}
|
|
3295
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
3296
|
+
const chunk = new Uint8Array(currentChunkSize * ItemSize2);
|
|
3297
|
+
const offset = i * chunkSize;
|
|
3298
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
3299
|
+
data.getColor(offset + j, single);
|
|
3300
|
+
const o = j * ItemSize2;
|
|
3301
|
+
chunk[o + 0] = clamp2(Math.round(((single.r - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
3302
|
+
chunk[o + 1] = clamp2(Math.round(((single.g - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
3303
|
+
chunk[o + 2] = clamp2(Math.round(((single.b - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
3304
|
+
}
|
|
3305
|
+
writer2.write(chunk);
|
|
3306
|
+
await Promise.resolve();
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
{
|
|
3310
|
+
const ItemSize2 = 3;
|
|
3311
|
+
const chunkSize = 16384;
|
|
3312
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
3313
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
3314
|
+
if (writer2.desiredSize <= 0) {
|
|
3315
|
+
await writer2.ready;
|
|
3316
|
+
}
|
|
3317
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
3318
|
+
const chunk = new Uint8Array(currentChunkSize * ItemSize2);
|
|
3319
|
+
const offset = i * chunkSize;
|
|
3320
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
3321
|
+
data.getScale(offset + j, single);
|
|
3322
|
+
const o = j * ItemSize2;
|
|
3323
|
+
chunk[o + 0] = clamp2(Math.round((Math.log(single.sx) + 10) * 16), 0, 255);
|
|
3324
|
+
chunk[o + 1] = clamp2(Math.round((Math.log(single.sy) + 10) * 16), 0, 255);
|
|
3325
|
+
chunk[o + 2] = clamp2(Math.round((Math.log(single.sz) + 10) * 16), 0, 255);
|
|
3326
|
+
}
|
|
3327
|
+
writer2.write(chunk);
|
|
3328
|
+
await Promise.resolve();
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
{
|
|
3332
|
+
const ItemSize2 = 4;
|
|
3333
|
+
const chunkSize = 16384;
|
|
3334
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
3335
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
3336
|
+
if (writer2.desiredSize <= 0) {
|
|
3337
|
+
await writer2.ready;
|
|
3338
|
+
}
|
|
3339
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
3340
|
+
const chunk = new Uint8Array(currentChunkSize * ItemSize2);
|
|
3341
|
+
const offset = i * chunkSize;
|
|
3342
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
3343
|
+
data.getQuat(offset + j, single);
|
|
3344
|
+
const o = j * ItemSize2;
|
|
3345
|
+
rotation[0] = single.qx;
|
|
3346
|
+
rotation[1] = single.qy;
|
|
3347
|
+
rotation[2] = single.qz;
|
|
3348
|
+
rotation[3] = single.qw;
|
|
3349
|
+
let iLargest = 0;
|
|
3350
|
+
for (let i2 = 1; i2 < 4; ++i2) {
|
|
3351
|
+
if (Math.abs(rotation[i2]) > Math.abs(rotation[iLargest])) {
|
|
3352
|
+
iLargest = i2;
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
const negate = rotation[iLargest] < 0 ? 1 : 0;
|
|
3356
|
+
let comp = iLargest;
|
|
3357
|
+
for (let i2 = 0; i2 < 4; ++i2) {
|
|
3358
|
+
if (i2 !== iLargest) {
|
|
3359
|
+
const negbit = (rotation[i2] < 0 ? 1 : 0) ^ negate;
|
|
3360
|
+
const mag = Math.floor(((1 << 9) - 1) * (Math.abs(rotation[i2]) / Math.SQRT1_2) + 0.5);
|
|
3361
|
+
comp = comp << 10 | negbit << 9 | mag;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
chunk[o + 0] = comp & 255;
|
|
3365
|
+
chunk[o + 1] = comp >> 8 & 255;
|
|
3366
|
+
chunk[o + 2] = comp >> 16 & 255;
|
|
3367
|
+
chunk[o + 3] = comp >> 24 & 255;
|
|
3368
|
+
}
|
|
3369
|
+
writer2.write(chunk);
|
|
3370
|
+
await Promise.resolve();
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
if (shDegree > 0) {
|
|
3374
|
+
const shN = single.shN;
|
|
3375
|
+
const ItemSize2 = shCounts;
|
|
3376
|
+
const chunkSize = 1024;
|
|
3377
|
+
const chunkCounts = Math.ceil(data.counts / chunkSize);
|
|
3378
|
+
for (let i = 0; i < chunkCounts; i++) {
|
|
3379
|
+
if (writer2.desiredSize <= 0) {
|
|
3380
|
+
await writer2.ready;
|
|
3381
|
+
}
|
|
3382
|
+
const currentChunkSize = Math.min(chunkSize, data.counts - i * chunkSize);
|
|
3383
|
+
const chunk = new Uint8Array(currentChunkSize * ItemSize2);
|
|
3384
|
+
const offset = i * chunkSize;
|
|
3385
|
+
for (let j = 0; j < currentChunkSize; j++) {
|
|
3386
|
+
data.getShN(offset + j, shN);
|
|
3387
|
+
const o = j * ItemSize2;
|
|
3388
|
+
for (let k = 0; k < ItemSize2; k++) {
|
|
3389
|
+
if (k < 9) {
|
|
3390
|
+
chunk[o + k] = clamp2(Math.floor((Math.round(shN[k] * 128) + 128 + SH_SCALE1 / 2) / SH_SCALE1) * SH_SCALE1, 0, 255);
|
|
3391
|
+
continue;
|
|
3392
|
+
}
|
|
3393
|
+
chunk[o + k] = clamp2(Math.floor((Math.round(shN[k] * 128) + 128 + SH_SCALE2 / 2) / SH_SCALE2) * SH_SCALE2, 0, 255);
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
writer2.write(chunk);
|
|
3397
|
+
await Promise.resolve();
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
await writer2.close();
|
|
3401
|
+
await pipePromise;
|
|
3402
|
+
}
|
|
3403
|
+
};
|
|
3404
|
+
|
|
3405
|
+
// ../../external/egs-core/packages/loaders/splat-loader/file/lcc.ts
|
|
3406
|
+
var ZIP_MAGIC2 = 67324752;
|
|
3407
|
+
var SQRT_2 = 1.414213562373095;
|
|
3408
|
+
var SQRT_2_INV = 0.7071067811865475;
|
|
3409
|
+
function decodeRotation(v) {
|
|
3410
|
+
const d0 = (v & 1023) / 1023;
|
|
3411
|
+
const d1 = (v >> 10 & 1023) / 1023;
|
|
3412
|
+
const d2 = (v >> 20 & 1023) / 1023;
|
|
3413
|
+
const d3 = v >> 30 & 3;
|
|
3414
|
+
const qx = d0 * SQRT_2 - SQRT_2_INV;
|
|
3415
|
+
const qy = d1 * SQRT_2 - SQRT_2_INV;
|
|
3416
|
+
const qz = d2 * SQRT_2 - SQRT_2_INV;
|
|
3417
|
+
let sum = qx * qx + qy * qy + qz * qz;
|
|
3418
|
+
sum = Math.min(1, sum);
|
|
3419
|
+
const qw = Math.sqrt(1 - sum);
|
|
3420
|
+
if (d3 === 0) {
|
|
3421
|
+
return [qw, qx, qy, qz];
|
|
3422
|
+
} else if (d3 === 1) {
|
|
3423
|
+
return [qx, qw, qy, qz];
|
|
3424
|
+
} else if (d3 === 2) {
|
|
3425
|
+
return [qx, qy, qw, qz];
|
|
3426
|
+
}
|
|
3427
|
+
return [qx, qy, qz, qw];
|
|
3428
|
+
}
|
|
3429
|
+
function DecodePacked_11_10_11(enc) {
|
|
3430
|
+
return [
|
|
3431
|
+
(enc & 2047) / 2047,
|
|
3432
|
+
(enc >> 11 & 1023) / 1023,
|
|
3433
|
+
(enc >> 21 & 2047) / 2047
|
|
3434
|
+
];
|
|
3435
|
+
}
|
|
3436
|
+
function mix(min, max2, s) {
|
|
3437
|
+
return (1 - s) * min + s * max2;
|
|
3438
|
+
}
|
|
3439
|
+
var LccFile = class {
|
|
3440
|
+
constructor() {
|
|
3441
|
+
this.counts = 0;
|
|
3442
|
+
this.shDegree = 0;
|
|
3443
|
+
this.refs = {};
|
|
3444
|
+
}
|
|
3445
|
+
load(buffer) {
|
|
3446
|
+
const view = new DataView(buffer.buffer);
|
|
3447
|
+
if (view.getUint32(0, true) !== ZIP_MAGIC2) {
|
|
3448
|
+
throw new Error("LCC file is not a valid zip archive.");
|
|
3449
|
+
}
|
|
3450
|
+
this.refs = extractFromRootDir(unzipSync(buffer));
|
|
3451
|
+
if (!["meta.lcc", "index.bin", "data.bin"].every((name) => !!this.refs[name])) {
|
|
3452
|
+
throw new Error("LCC file is missing required files.");
|
|
3453
|
+
}
|
|
3454
|
+
this.meta = JSON.parse(new TextDecoder().decode(this.refs["meta.lcc"]));
|
|
3455
|
+
this.counts = this.meta.splats[0];
|
|
3456
|
+
this.shDegree = !!this.refs["shcoef.bin"] ? 3 : 0;
|
|
3457
|
+
}
|
|
3458
|
+
async read(stream, contentLength, data) {
|
|
3459
|
+
let BlockOffset = 0;
|
|
3460
|
+
{
|
|
3461
|
+
const buffer = new Uint8Array(contentLength);
|
|
3462
|
+
const reader = stream.getReader();
|
|
3463
|
+
let offset = 0;
|
|
3464
|
+
while (true) {
|
|
3465
|
+
const { done, value } = await reader.read();
|
|
3466
|
+
if (done) {
|
|
3467
|
+
break;
|
|
3468
|
+
}
|
|
3469
|
+
buffer.set(value, offset);
|
|
3470
|
+
offset += value.length;
|
|
3471
|
+
}
|
|
3472
|
+
this.load(buffer);
|
|
3473
|
+
BlockOffset = await data.initBlock(this.counts, this.shDegree);
|
|
3474
|
+
}
|
|
3475
|
+
const setFn = data.set.bind(data);
|
|
3476
|
+
const setShFn = data.setShN.bind(data);
|
|
3477
|
+
const { meta, refs } = this;
|
|
3478
|
+
const infos = [];
|
|
3479
|
+
{
|
|
3480
|
+
const index2 = new DataView(refs["index.bin"].buffer);
|
|
3481
|
+
const infoCounts = Math.floor(index2.byteLength / (4 + 16 * meta.totalLevel));
|
|
3482
|
+
let offset = 0;
|
|
3483
|
+
for (let i = 0; i < infoCounts; i++) {
|
|
3484
|
+
const x = index2.getInt16(offset, true);
|
|
3485
|
+
offset += 2;
|
|
3486
|
+
const y = index2.getInt16(offset, true);
|
|
3487
|
+
offset += 2;
|
|
3488
|
+
const lods = [];
|
|
3489
|
+
for (let j = 0; j < meta.totalLevel; j++) {
|
|
3490
|
+
const points = index2.getInt32(offset, true);
|
|
3491
|
+
offset += 4;
|
|
3492
|
+
const ldOffset = Number(index2.getBigInt64(offset, true));
|
|
3493
|
+
offset += 8;
|
|
3494
|
+
const size = index2.getInt32(offset, true);
|
|
3495
|
+
offset += 4;
|
|
3496
|
+
lods.push({ points, offset: ldOffset, size });
|
|
3497
|
+
}
|
|
3498
|
+
infos.push({ x, y, lods });
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
const attributes = meta.attributes.reduce((p, c) => {
|
|
3502
|
+
p[c.name] = c;
|
|
3503
|
+
return p;
|
|
3504
|
+
}, {});
|
|
3505
|
+
const { scale: { min: scaleMin, max: scaleMax }, shcoef: { min: shMin, max: shMax } } = attributes;
|
|
3506
|
+
const single = {
|
|
3507
|
+
x: 0,
|
|
3508
|
+
y: 0,
|
|
3509
|
+
z: 0,
|
|
3510
|
+
sx: 0,
|
|
3511
|
+
sy: 0,
|
|
3512
|
+
sz: 0,
|
|
3513
|
+
qx: 0,
|
|
3514
|
+
qy: 0,
|
|
3515
|
+
qz: 0,
|
|
3516
|
+
qw: 0,
|
|
3517
|
+
r: 0,
|
|
3518
|
+
g: 0,
|
|
3519
|
+
b: 0,
|
|
3520
|
+
a: 0,
|
|
3521
|
+
shN: []
|
|
3522
|
+
};
|
|
3523
|
+
const shData = new Array(45);
|
|
3524
|
+
let index = BlockOffset;
|
|
3525
|
+
for (let i = 0; i < infos.length; i++) {
|
|
3526
|
+
const info = infos[i];
|
|
3527
|
+
const { points, offset, size } = info.lods[0];
|
|
3528
|
+
const dataview = new DataView(refs["data.bin"].buffer, offset, size);
|
|
3529
|
+
const shN = refs["shcoef.bin"] ? new DataView(refs["shcoef.bin"].buffer, offset * 2, size * 2) : void 0;
|
|
3530
|
+
for (let j = 0; j < points; j++) {
|
|
3531
|
+
const off = j * 32;
|
|
3532
|
+
single.x = dataview.getFloat32(off + 0, true);
|
|
3533
|
+
single.y = dataview.getFloat32(off + 4, true);
|
|
3534
|
+
single.z = dataview.getFloat32(off + 8, true);
|
|
3535
|
+
single.r = dataview.getUint8(off + 12) / 255;
|
|
3536
|
+
single.g = dataview.getUint8(off + 13) / 255;
|
|
3537
|
+
single.b = dataview.getUint8(off + 14) / 255;
|
|
3538
|
+
single.a = dataview.getUint8(off + 15) / 255;
|
|
3539
|
+
single.sx = mix(scaleMin[0], scaleMax[0], dataview.getUint16(off + 16, true) / 65535);
|
|
3540
|
+
single.sy = mix(scaleMin[1], scaleMax[1], dataview.getUint16(off + 18, true) / 65535);
|
|
3541
|
+
single.sz = mix(scaleMin[2], scaleMax[2], dataview.getUint16(off + 20, true) / 65535);
|
|
3542
|
+
const quat = decodeRotation(dataview.getUint32(off + 22, true));
|
|
3543
|
+
single.qx = quat[0];
|
|
3544
|
+
single.qy = quat[1];
|
|
3545
|
+
single.qz = quat[2];
|
|
3546
|
+
single.qw = quat[3];
|
|
3547
|
+
setFn(index, single);
|
|
3548
|
+
if (shN) {
|
|
3549
|
+
const shOff = off * 2;
|
|
3550
|
+
for (let k = 0; k < 15; k++) {
|
|
3551
|
+
const v = DecodePacked_11_10_11(shN.getUint32(shOff + k * 4, true));
|
|
3552
|
+
shData[k * 3] = mix(shMin[0], shMax[0], v[0]);
|
|
3553
|
+
shData[k * 3 + 1] = mix(shMin[1], shMax[1], v[1]);
|
|
3554
|
+
shData[k * 3 + 2] = mix(shMin[2], shMax[2], v[2]);
|
|
3555
|
+
}
|
|
3556
|
+
setShFn(index, shData);
|
|
3557
|
+
}
|
|
3558
|
+
index++;
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
data.finishBlock();
|
|
3562
|
+
}
|
|
3563
|
+
async write(_stream, _data) {
|
|
3564
|
+
throw new Error("Method not implemented.");
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
|
|
3568
|
+
// ../../external/egs-core/packages/loaders/splat-loader/worker.ts
|
|
3569
|
+
var writer;
|
|
3570
|
+
self.onmessage = async (event) => {
|
|
3571
|
+
try {
|
|
3572
|
+
const message = event.data;
|
|
3573
|
+
switch (message.taskType) {
|
|
3574
|
+
case "ParseSplat" /* ParseSplat */: {
|
|
3575
|
+
const { type, packType, stream, contentLength, extras: { maxShDegree, maxTextureSize } } = event.data.payload;
|
|
3576
|
+
let splatData;
|
|
3577
|
+
switch (packType) {
|
|
3578
|
+
case 0 /* Raw */: {
|
|
3579
|
+
splatData = new RawSplatData(maxShDegree, maxTextureSize);
|
|
3580
|
+
break;
|
|
3581
|
+
}
|
|
3582
|
+
case 1 /* Compressed */: {
|
|
3583
|
+
splatData = new CompressedSplatData(maxShDegree, maxTextureSize);
|
|
3584
|
+
break;
|
|
3585
|
+
}
|
|
3586
|
+
case 2 /* SuperCompressed */: {
|
|
3587
|
+
splatData = new SuperCompressedSplatData(maxShDegree, maxTextureSize);
|
|
3588
|
+
break;
|
|
3589
|
+
}
|
|
3590
|
+
case 3 /* Sog */: {
|
|
3591
|
+
splatData = new SogSplatData(maxShDegree, maxTextureSize);
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
let file;
|
|
3595
|
+
switch (type) {
|
|
3596
|
+
case 0 /* PLY */: {
|
|
3597
|
+
file = new PlyFile();
|
|
3598
|
+
break;
|
|
3599
|
+
}
|
|
3600
|
+
case 1 /* SPZ */: {
|
|
3601
|
+
file = new SpzFile();
|
|
3602
|
+
break;
|
|
3603
|
+
}
|
|
3604
|
+
case 3 /* KSPLAT */: {
|
|
3605
|
+
file = new KsplatFile();
|
|
3606
|
+
break;
|
|
3607
|
+
}
|
|
3608
|
+
case 2 /* SPLAT */: {
|
|
3609
|
+
file = new SplatFile();
|
|
3610
|
+
break;
|
|
3611
|
+
}
|
|
3612
|
+
case 4 /* SOG */: {
|
|
3613
|
+
file = new SogFile();
|
|
3614
|
+
break;
|
|
3615
|
+
}
|
|
3616
|
+
case 5 /* LCC */: {
|
|
3617
|
+
file = new LccFile();
|
|
3618
|
+
break;
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
let reader = stream;
|
|
3622
|
+
if (!reader) {
|
|
3623
|
+
const stream2 = new TransformStream();
|
|
3624
|
+
writer = stream2.writable.getWriter();
|
|
3625
|
+
reader = stream2.readable;
|
|
3626
|
+
}
|
|
3627
|
+
if (packType === 3 /* Sog */) {
|
|
3628
|
+
await file.load(reader, contentLength);
|
|
3629
|
+
const { meta, refs } = file;
|
|
3630
|
+
let splatMeta;
|
|
3631
|
+
if (meta.version === void 0) {
|
|
3632
|
+
const m = meta;
|
|
3633
|
+
splatMeta = {
|
|
3634
|
+
version: 1,
|
|
3635
|
+
counts: m.means.shape[0],
|
|
3636
|
+
shDegree: NUM_F_REST_TO_SH_DEGREE[m.shN?.shape?.[1] ?? 0],
|
|
3637
|
+
means: {
|
|
3638
|
+
mins: [m.means.mins[0], m.means.mins[1], m.means.mins[2]],
|
|
3639
|
+
maxs: [m.means.maxs[0], m.means.maxs[1], m.means.maxs[2]]
|
|
3640
|
+
},
|
|
3641
|
+
scales: {
|
|
3642
|
+
mins: [m.scales.mins[0], m.scales.mins[1], m.scales.mins[2]],
|
|
3643
|
+
maxs: [m.scales.maxs[0], m.scales.maxs[1], m.scales.maxs[2]]
|
|
3644
|
+
},
|
|
3645
|
+
sh0: {
|
|
3646
|
+
mins: [m.sh0.mins[0], m.sh0.mins[1], m.sh0.mins[2], m.sh0.mins[3]],
|
|
3647
|
+
maxs: [m.sh0.maxs[0], m.sh0.maxs[1], m.sh0.maxs[2], m.sh0.maxs[3]]
|
|
3648
|
+
},
|
|
3649
|
+
shN: m.shN ? {
|
|
3650
|
+
mins: m.shN.mins,
|
|
3651
|
+
maxs: m.shN.maxs
|
|
3652
|
+
} : void 0
|
|
3653
|
+
};
|
|
3654
|
+
} else {
|
|
3655
|
+
const m = meta;
|
|
3656
|
+
splatMeta = {
|
|
3657
|
+
version: 2,
|
|
3658
|
+
counts: m.count,
|
|
3659
|
+
shDegree: m.shN?.bands ?? 0,
|
|
3660
|
+
means: {
|
|
3661
|
+
mins: [m.means.mins[0], m.means.mins[1], m.means.mins[2]],
|
|
3662
|
+
maxs: [m.means.maxs[0], m.means.maxs[1], m.means.maxs[2]]
|
|
3663
|
+
},
|
|
3664
|
+
scales: {
|
|
3665
|
+
codebook: m.scales.codebook
|
|
3666
|
+
},
|
|
3667
|
+
sh0: {
|
|
3668
|
+
codebook: m.sh0.codebook
|
|
3669
|
+
},
|
|
3670
|
+
shN: m.shN ? {
|
|
3671
|
+
codebook: m.shN.codebook
|
|
3672
|
+
} : void 0
|
|
3673
|
+
};
|
|
3674
|
+
}
|
|
3675
|
+
splatData.load(
|
|
3676
|
+
splatMeta,
|
|
3677
|
+
refs[meta.means.files[0]],
|
|
3678
|
+
refs[meta.means.files[1]],
|
|
3679
|
+
refs[meta.scales.files[0]],
|
|
3680
|
+
refs[meta.quats.files[0]],
|
|
3681
|
+
refs[meta.sh0.files[0]],
|
|
3682
|
+
...meta.shN ? [
|
|
3683
|
+
refs[meta.shN.files[0]],
|
|
3684
|
+
refs[meta.shN.files[1]]
|
|
3685
|
+
] : []
|
|
3686
|
+
);
|
|
3687
|
+
} else {
|
|
3688
|
+
await file.read(reader, contentLength, splatData);
|
|
3689
|
+
}
|
|
3690
|
+
writer = void 0;
|
|
3691
|
+
const splats = splatData.serialize();
|
|
3692
|
+
const payload = { status: 0 /* Success */, payload: splats };
|
|
3693
|
+
postMessage(
|
|
3694
|
+
payload,
|
|
3695
|
+
splats.samplers.map((v) => v.source.buffer)
|
|
3696
|
+
);
|
|
3697
|
+
return;
|
|
3698
|
+
}
|
|
3699
|
+
case "PostStreamChunk" /* PostStreamChunk */: {
|
|
3700
|
+
const { chunk } = event.data.payload;
|
|
3701
|
+
if (!writer) {
|
|
3702
|
+
return;
|
|
3703
|
+
}
|
|
3704
|
+
if (chunk) {
|
|
3705
|
+
writer.write(chunk);
|
|
3706
|
+
} else {
|
|
3707
|
+
writer.close();
|
|
3708
|
+
}
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3711
|
+
case "SortSplats" /* SortSplats */: {
|
|
3712
|
+
const { splatCounts, sorting, ordering } = event.data.payload;
|
|
3713
|
+
const activeSplats = sortSplats(splatCounts, sorting, ordering);
|
|
3714
|
+
const payload = { status: 0 /* Success */, payload: { activeSplats, sorting, ordering } };
|
|
3715
|
+
postMessage(payload, [sorting.buffer, ordering.buffer]);
|
|
3716
|
+
return;
|
|
3717
|
+
}
|
|
3718
|
+
default: {
|
|
3719
|
+
const check = message.taskType;
|
|
3720
|
+
throw new Error(`Unsupported task type: ${check}.`);
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
} catch (e) {
|
|
3724
|
+
console.error(e);
|
|
3725
|
+
postMessage({ status: 1 /* Fail */, payload: e.toString() });
|
|
3726
|
+
}
|
|
3727
|
+
};
|
|
3728
|
+
//# sourceMappingURL=splat-worker.js.map
|