@manycore/aholo-splat-transform 1.2.7 → 1.2.9
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/CHANGELOG.md +120 -106
- package/COPYRIGHT.md +17 -0
- package/README.md +39 -39
- package/THIRD_PARTY_LICENSES.txt +1373 -0
- package/bin/cli.js +125 -118
- package/dist/SplatData.d.ts +67 -67
- package/dist/SplatData.js +167 -156
- package/dist/constant.d.ts +3 -3
- package/dist/constant.js +13 -13
- package/dist/file/IFile.d.ts +5 -5
- package/dist/file/IFile.js +1 -1
- package/dist/file/esz.d.ts +11 -0
- package/dist/file/esz.js +337 -0
- package/dist/file/index.d.ts +8 -7
- package/dist/file/index.js +7 -6
- package/dist/file/ksplat.d.ts +12 -12
- package/dist/file/ksplat.js +293 -232
- package/dist/file/lcc.d.ts +11 -11
- package/dist/file/lcc.js +161 -157
- package/dist/file/ply.d.ts +13 -13
- package/dist/file/ply.js +439 -388
- package/dist/file/sog.d.ts +80 -80
- package/dist/file/sog.js +525 -504
- package/dist/file/splat.d.ts +6 -6
- package/dist/file/splat.js +119 -99
- package/dist/file/spz.d.ts +11 -8
- package/dist/file/spz.js +597 -400
- package/dist/file/voxel.d.ts +43 -37
- package/dist/file/voxel.js +411 -280
- package/dist/index.d.ts +33 -33
- package/dist/index.js +54 -54
- package/dist/native/index.d.ts +54 -54
- package/dist/native/index.js +122 -128
- package/dist/native/utils.d.ts +1 -0
- package/dist/native/utils.js +54 -0
- package/dist/tasks/AutoChunkLodTask.d.ts +13 -13
- package/dist/tasks/AutoChunkLodTask.js +117 -117
- package/dist/tasks/AutoLodTask.d.ts +10 -10
- package/dist/tasks/AutoLodTask.js +20 -20
- package/dist/tasks/BaseTask.d.ts +15 -15
- package/dist/tasks/BaseTask.js +5 -5
- package/dist/tasks/FlexLodTask.d.ts +12 -12
- package/dist/tasks/FlexLodTask.js +54 -44
- package/dist/tasks/ModifyTask.d.ts +9 -9
- package/dist/tasks/ModifyTask.js +166 -156
- package/dist/tasks/ReadTask.d.ts +9 -9
- package/dist/tasks/ReadTask.js +29 -29
- package/dist/tasks/SkeletonLodTask.d.ts +10 -10
- package/dist/tasks/SkeletonLodTask.js +176 -156
- package/dist/tasks/VoxelTask.d.ts +35 -30
- package/dist/tasks/VoxelTask.js +40 -37
- package/dist/tasks/WriteTask.d.ts +12 -11
- package/dist/tasks/WriteTask.js +70 -70
- package/dist/utils/BufferReader.d.ts +12 -12
- package/dist/utils/BufferReader.js +45 -47
- package/dist/utils/Logger.d.ts +11 -11
- package/dist/utils/Logger.js +40 -38
- package/dist/utils/StreamChunkDecoder.d.ts +16 -16
- package/dist/utils/StreamChunkDecoder.js +31 -36
- package/dist/utils/index.d.ts +27 -27
- package/dist/utils/index.js +101 -101
- package/dist/utils/k-means.d.ts +4 -4
- package/dist/utils/k-means.js +340 -350
- package/dist/utils/math.d.ts +46 -46
- package/dist/utils/math.js +350 -351
- package/dist/utils/quantize-1d.d.ts +4 -4
- package/dist/utils/quantize-1d.js +164 -164
- package/dist/utils/sh-rotate.d.ts +2 -2
- package/dist/utils/sh-rotate.js +236 -175
- package/dist/utils/splat.d.ts +21 -20
- package/dist/utils/splat.js +397 -378
- package/dist/utils/voxel/binary.d.ts +8 -0
- package/dist/utils/voxel/binary.js +176 -0
- package/dist/utils/voxel/common.d.ts +178 -162
- package/dist/utils/voxel/common.js +1752 -1700
- package/dist/utils/voxel/coplanar-merge.d.ts +63 -63
- package/dist/utils/voxel/coplanar-merge.js +818 -819
- package/dist/utils/voxel/filter-cluster.d.ts +20 -0
- package/dist/utils/voxel/filter-cluster.js +628 -0
- package/dist/utils/voxel/gpu-dilation.d.ts +2 -2
- package/dist/utils/voxel/gpu-dilation.js +677 -665
- package/dist/utils/voxel/marching-cubes.d.ts +42 -42
- package/dist/utils/voxel/marching-cubes.js +1645 -1657
- package/dist/utils/voxel/mesh.d.ts +3 -3
- package/dist/utils/voxel/mesh.js +130 -130
- package/dist/utils/voxel/nav.d.ts +29 -29
- package/dist/utils/voxel/nav.js +1068 -1043
- package/dist/utils/voxel/postprocess.d.ts +23 -23
- package/dist/utils/voxel/postprocess.js +408 -375
- package/dist/utils/voxel/voxel-faces.d.ts +18 -18
- package/dist/utils/voxel/voxel-faces.js +662 -663
- package/dist/utils/voxel/voxelize.d.ts +34 -33
- package/dist/utils/voxel/voxelize.js +1208 -1193
- package/dist/utils/webgpu.d.ts +8 -8
- package/dist/utils/webgpu.js +122 -122
- package/package.json +37 -30
- package/dist/native/cpp/bin/linux/binding.node +0 -0
- package/dist/native/cpp/bin/windows/binding.node +0 -0
package/dist/file/esz.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { unzipSync, zipSync } from 'fflate';
|
|
2
|
+
import { ColIdx } from '../SplatData.js';
|
|
3
|
+
import { clamp, extractFromRootDir, isUrl, logger, mortonSort } from '../utils/index.js';
|
|
4
|
+
import { decodeWebP, encodeWebP, WebPLosslessProfile } from '../native/index.js';
|
|
5
|
+
import { SH_C0, SH_MAPS } from '../constant.js';
|
|
6
|
+
const TEMP_ROT = new Array(4);
|
|
7
|
+
const PERM_TABLE = [
|
|
8
|
+
// original quat idx ---> actual storage idx
|
|
9
|
+
[0, 1, 2, 3],
|
|
10
|
+
[3, 1, 2, 0],
|
|
11
|
+
[1, 3, 2, 0],
|
|
12
|
+
[1, 2, 3, 0],
|
|
13
|
+
];
|
|
14
|
+
const COLOR_SCALE = SH_C0 / 0.15;
|
|
15
|
+
const SH_SCALE1 = 1 << 3;
|
|
16
|
+
const SH_SCALE2 = 1 << 4;
|
|
17
|
+
function logTransform(value) {
|
|
18
|
+
return Math.sign(value) * Math.log(Math.abs(value) + 1);
|
|
19
|
+
}
|
|
20
|
+
export class EszFile {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.counts = 0;
|
|
23
|
+
this.shDegree = 0;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
this.refs = {};
|
|
28
|
+
}
|
|
29
|
+
async load(stream, contentLength) {
|
|
30
|
+
const buffer = new Uint8Array(contentLength);
|
|
31
|
+
const reader = stream.getReader();
|
|
32
|
+
let offset = 0;
|
|
33
|
+
while (true) {
|
|
34
|
+
const { done, value } = await reader.read();
|
|
35
|
+
if (done) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
buffer.set(value, offset);
|
|
39
|
+
offset += value.length;
|
|
40
|
+
}
|
|
41
|
+
this.refs = extractFromRootDir(unzipSync(buffer));
|
|
42
|
+
const metaBuffer = this.refs['meta.json'];
|
|
43
|
+
if (!metaBuffer) {
|
|
44
|
+
throw new Error('SOG meta.json not found in the zip archive.');
|
|
45
|
+
}
|
|
46
|
+
const meta = (this.meta = JSON.parse(new TextDecoder().decode(metaBuffer)));
|
|
47
|
+
this.version = meta.version;
|
|
48
|
+
this.counts = meta.counts;
|
|
49
|
+
this.shDegree = meta.shDegree;
|
|
50
|
+
}
|
|
51
|
+
async loadTexture(path) {
|
|
52
|
+
let buffer = this.refs[path];
|
|
53
|
+
if (!buffer) {
|
|
54
|
+
if (isUrl(path)) {
|
|
55
|
+
buffer = await fetch(path)
|
|
56
|
+
.then(res => res.arrayBuffer())
|
|
57
|
+
.then(buf => new Uint8Array(buf));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!buffer) {
|
|
61
|
+
throw new Error(`Cannot load texture: ${path}`);
|
|
62
|
+
}
|
|
63
|
+
const { data, width, height } = decodeWebP(buffer);
|
|
64
|
+
return {
|
|
65
|
+
data: new Uint8Array(data),
|
|
66
|
+
width,
|
|
67
|
+
height,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async read(stream, contentLength, data) {
|
|
71
|
+
await this.load(stream, contentLength);
|
|
72
|
+
const offset = await data.initBlock(this.counts, this.shDegree);
|
|
73
|
+
const { resources } = this.meta;
|
|
74
|
+
this.cached = await Promise.all([resources.means_l, resources.means_u, resources.scales, resources.quats, resources.sh0, resources.shN]
|
|
75
|
+
.filter(path => !!path)
|
|
76
|
+
.map(path => this.loadTexture(path)));
|
|
77
|
+
const setFn = data.set.bind(data);
|
|
78
|
+
const setShFn = data.setShN.bind(data);
|
|
79
|
+
const SCALE_LUT = new Float32Array(256);
|
|
80
|
+
for (let i = 0; i < 256; i++) {
|
|
81
|
+
SCALE_LUT[i] = Math.exp(i / 16 - 10);
|
|
82
|
+
}
|
|
83
|
+
const COLOR_LUT = new Float32Array(256);
|
|
84
|
+
for (let i = 0; i < 256; i++) {
|
|
85
|
+
COLOR_LUT[i] = (i / 255 - 0.5) * COLOR_SCALE + 0.5;
|
|
86
|
+
}
|
|
87
|
+
const { meta: { box }, counts, shDegree, cached, } = this;
|
|
88
|
+
const [means_l, means_u, scales, quats, color, shN] = cached.map(v => v.data);
|
|
89
|
+
const { min: [centerMinX, centerMinY, centerMinZ], max: [centerMaxX, centerMaxY, centerMaxZ], } = box;
|
|
90
|
+
const rangeX = (centerMaxX - centerMinX) / 65535;
|
|
91
|
+
const rangeY = (centerMaxY - centerMinY) / 65535;
|
|
92
|
+
const rangeZ = (centerMaxZ - centerMinZ) / 65535;
|
|
93
|
+
const single = {
|
|
94
|
+
x: 0,
|
|
95
|
+
y: 0,
|
|
96
|
+
z: 0,
|
|
97
|
+
sx: 0,
|
|
98
|
+
sy: 0,
|
|
99
|
+
sz: 0,
|
|
100
|
+
qx: 0,
|
|
101
|
+
qy: 0,
|
|
102
|
+
qz: 0,
|
|
103
|
+
qw: 0,
|
|
104
|
+
r: 0,
|
|
105
|
+
g: 0,
|
|
106
|
+
b: 0,
|
|
107
|
+
a: 0,
|
|
108
|
+
shN: [],
|
|
109
|
+
};
|
|
110
|
+
for (let i = 0; i < counts; i++) {
|
|
111
|
+
const i4 = i * 4;
|
|
112
|
+
const x = centerMinX + rangeX * (means_l[i4 + 0] + (means_u[i4 + 0] << 8));
|
|
113
|
+
const y = centerMinY + rangeY * (means_l[i4 + 1] + (means_u[i4 + 1] << 8));
|
|
114
|
+
const z = centerMinZ + rangeZ * (means_l[i4 + 2] + (means_u[i4 + 2] << 8));
|
|
115
|
+
single.x = Math.sign(x) * (Math.exp(Math.abs(x)) - 1);
|
|
116
|
+
single.y = Math.sign(y) * (Math.exp(Math.abs(y)) - 1);
|
|
117
|
+
single.z = Math.sign(z) * (Math.exp(Math.abs(z)) - 1);
|
|
118
|
+
single.sx = SCALE_LUT[scales[i4 + 0]];
|
|
119
|
+
single.sy = SCALE_LUT[scales[i4 + 1]];
|
|
120
|
+
single.sz = SCALE_LUT[scales[i4 + 2]];
|
|
121
|
+
TEMP_ROT[0] = (quats[i4 + 0] / 255 - 0.5) * Math.SQRT2;
|
|
122
|
+
TEMP_ROT[1] = (quats[i4 + 1] / 255 - 0.5) * Math.SQRT2;
|
|
123
|
+
TEMP_ROT[2] = (quats[i4 + 2] / 255 - 0.5) * Math.SQRT2;
|
|
124
|
+
TEMP_ROT[3] = Math.sqrt(Math.max(0, 1.0 - TEMP_ROT[0] * TEMP_ROT[0] - TEMP_ROT[1] * TEMP_ROT[1] - TEMP_ROT[2] * TEMP_ROT[2]));
|
|
125
|
+
const PERM = PERM_TABLE[quats[i4 + 3] - 252];
|
|
126
|
+
single.qx = TEMP_ROT[PERM[0]];
|
|
127
|
+
single.qy = TEMP_ROT[PERM[1]];
|
|
128
|
+
single.qz = TEMP_ROT[PERM[2]];
|
|
129
|
+
single.qw = TEMP_ROT[PERM[3]];
|
|
130
|
+
single.r = COLOR_LUT[color[i4 + 0]];
|
|
131
|
+
single.g = COLOR_LUT[color[i4 + 1]];
|
|
132
|
+
single.b = COLOR_LUT[color[i4 + 2]];
|
|
133
|
+
single.a = color[i4 + 3] / 255;
|
|
134
|
+
setFn(offset + i, single);
|
|
135
|
+
}
|
|
136
|
+
if (shN) {
|
|
137
|
+
const shCounts = SH_MAPS[shDegree];
|
|
138
|
+
const shCoeffs = shCounts / 3;
|
|
139
|
+
const sh = new Array(shCounts);
|
|
140
|
+
for (let i = 0; i < counts; i++) {
|
|
141
|
+
const o = i * shCounts;
|
|
142
|
+
for (let j = 0; j < shCoeffs; j++) {
|
|
143
|
+
sh[o + j * 3 + 0] = (shN[(i * shCoeffs + j) * 4 + 0] - 128) / 128;
|
|
144
|
+
sh[o + j * 3 + 1] = (shN[(i * shCoeffs + j) * 4 + 1] - 128) / 128;
|
|
145
|
+
sh[o + j * 3 + 2] = (shN[(i * shCoeffs + j) * 4 + 2] - 128) / 128;
|
|
146
|
+
}
|
|
147
|
+
setShFn(offset + i, sh);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
data.finishBlock();
|
|
151
|
+
}
|
|
152
|
+
async write(stream, data, indices = mortonSort(data)) {
|
|
153
|
+
const { counts, shDegree, shCounts, table } = data;
|
|
154
|
+
const width = Math.ceil(Math.sqrt(counts) / 4) * 4;
|
|
155
|
+
const height = Math.ceil(counts / width / 4) * 4;
|
|
156
|
+
const webPProfile = new WebPLosslessProfile();
|
|
157
|
+
const output = {};
|
|
158
|
+
const meta = {
|
|
159
|
+
version: 1,
|
|
160
|
+
counts,
|
|
161
|
+
shDegree,
|
|
162
|
+
box: {
|
|
163
|
+
min: [Infinity, Infinity, Infinity],
|
|
164
|
+
max: [-Infinity, -Infinity, -Infinity],
|
|
165
|
+
},
|
|
166
|
+
resources: {
|
|
167
|
+
means_l: 'means_l.webp',
|
|
168
|
+
means_u: 'means_u.webp',
|
|
169
|
+
scales: 'scales.webp',
|
|
170
|
+
quats: 'quats.webp',
|
|
171
|
+
sh0: 'sh0.webp',
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const xCol = table[ColIdx.x];
|
|
175
|
+
const yCol = table[ColIdx.y];
|
|
176
|
+
const zCol = table[ColIdx.z];
|
|
177
|
+
// calculate minmax & transform
|
|
178
|
+
let minX = Infinity;
|
|
179
|
+
let minY = Infinity;
|
|
180
|
+
let minZ = Infinity;
|
|
181
|
+
let maxX = -Infinity;
|
|
182
|
+
let maxY = -Infinity;
|
|
183
|
+
let maxZ = -Infinity;
|
|
184
|
+
for (let i = 0; i < counts; i++) {
|
|
185
|
+
const idx = indices[i];
|
|
186
|
+
const x = xCol[idx];
|
|
187
|
+
const y = yCol[idx];
|
|
188
|
+
const z = zCol[idx];
|
|
189
|
+
if (x < minX) {
|
|
190
|
+
minX = x;
|
|
191
|
+
}
|
|
192
|
+
if (x > maxX) {
|
|
193
|
+
maxX = x;
|
|
194
|
+
}
|
|
195
|
+
if (y < minY) {
|
|
196
|
+
minY = y;
|
|
197
|
+
}
|
|
198
|
+
if (y > maxY) {
|
|
199
|
+
maxY = y;
|
|
200
|
+
}
|
|
201
|
+
if (z < minZ) {
|
|
202
|
+
minZ = z;
|
|
203
|
+
}
|
|
204
|
+
if (z > maxZ) {
|
|
205
|
+
maxZ = z;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
meta.box.min = [minX, minY, minZ];
|
|
209
|
+
meta.box.max = [maxX, maxY, maxZ];
|
|
210
|
+
{
|
|
211
|
+
logger.time('ESZ encoding means');
|
|
212
|
+
minX = logTransform(minX);
|
|
213
|
+
minY = logTransform(minY);
|
|
214
|
+
minZ = logTransform(minZ);
|
|
215
|
+
maxX = logTransform(maxX);
|
|
216
|
+
maxY = logTransform(maxY);
|
|
217
|
+
maxZ = logTransform(maxZ);
|
|
218
|
+
const scaleX = 65535 / Math.max(maxX - minX, 1e-9);
|
|
219
|
+
const scaleY = 65535 / Math.max(maxY - minY, 1e-9);
|
|
220
|
+
const scaleZ = 65535 / Math.max(maxZ - minZ, 1e-9);
|
|
221
|
+
const meansL = new Uint8Array(width * height * 4).fill(0xff);
|
|
222
|
+
const meansU = new Uint8Array(width * height * 4).fill(0xff);
|
|
223
|
+
for (let i = 0; i < indices.length; i++) {
|
|
224
|
+
const idx = indices[i];
|
|
225
|
+
const x = (logTransform(xCol[idx]) - minX) * scaleX;
|
|
226
|
+
const y = (logTransform(yCol[idx]) - minY) * scaleY;
|
|
227
|
+
const z = (logTransform(zCol[idx]) - minZ) * scaleZ;
|
|
228
|
+
meansL[i * 4 + 0] = x & 0xff;
|
|
229
|
+
meansL[i * 4 + 1] = y & 0xff;
|
|
230
|
+
meansL[i * 4 + 2] = z & 0xff;
|
|
231
|
+
meansU[i * 4 + 0] = (x >> 8) & 0xff;
|
|
232
|
+
meansU[i * 4 + 1] = (y >> 8) & 0xff;
|
|
233
|
+
meansU[i * 4 + 2] = (z >> 8) & 0xff;
|
|
234
|
+
}
|
|
235
|
+
output['means_l.webp'] = encodeWebP(meansL, width, height, webPProfile);
|
|
236
|
+
output['means_u.webp'] = encodeWebP(meansU, width, height, webPProfile);
|
|
237
|
+
logger.timeEnd('ESZ encoding means');
|
|
238
|
+
}
|
|
239
|
+
{
|
|
240
|
+
logger.time('ESZ encoding scales');
|
|
241
|
+
const sxCol = table[ColIdx.sx];
|
|
242
|
+
const syCol = table[ColIdx.sy];
|
|
243
|
+
const szCol = table[ColIdx.sz];
|
|
244
|
+
const scales = new Uint8Array(width * height * 4).fill(0xff);
|
|
245
|
+
for (let i = 0; i < counts; i++) {
|
|
246
|
+
const idx = indices[i];
|
|
247
|
+
scales[i * 4 + 0] = clamp(Math.round((Math.log(sxCol[idx]) + 10) * 16), 0, 255);
|
|
248
|
+
scales[i * 4 + 1] = clamp(Math.round((Math.log(syCol[idx]) + 10) * 16), 0, 255);
|
|
249
|
+
scales[i * 4 + 2] = clamp(Math.round((Math.log(szCol[idx]) + 10) * 16), 0, 255);
|
|
250
|
+
}
|
|
251
|
+
output['scales.webp'] = encodeWebP(scales, width, height, webPProfile);
|
|
252
|
+
logger.timeEnd('ESZ encoding scales');
|
|
253
|
+
}
|
|
254
|
+
{
|
|
255
|
+
logger.time('ESZ encoding quats');
|
|
256
|
+
const qxCol = table[ColIdx.qx];
|
|
257
|
+
const qyCol = table[ColIdx.qy];
|
|
258
|
+
const qzCol = table[ColIdx.qz];
|
|
259
|
+
const qwCol = table[ColIdx.qw];
|
|
260
|
+
const quats = new Uint8Array(width * height * 4);
|
|
261
|
+
for (let i = 0; i < counts; i++) {
|
|
262
|
+
const idx = indices[i];
|
|
263
|
+
TEMP_ROT[0] = qwCol[idx];
|
|
264
|
+
TEMP_ROT[1] = qxCol[idx];
|
|
265
|
+
TEMP_ROT[2] = qyCol[idx];
|
|
266
|
+
TEMP_ROT[3] = qzCol[idx];
|
|
267
|
+
const l = Math.sqrt(TEMP_ROT[0] * TEMP_ROT[0] +
|
|
268
|
+
TEMP_ROT[1] * TEMP_ROT[1] +
|
|
269
|
+
TEMP_ROT[2] * TEMP_ROT[2] +
|
|
270
|
+
TEMP_ROT[3] * TEMP_ROT[3]);
|
|
271
|
+
TEMP_ROT.forEach((v, j) => {
|
|
272
|
+
TEMP_ROT[j] = v / l;
|
|
273
|
+
});
|
|
274
|
+
const maxComp = TEMP_ROT.reduce((v, _, i) => (Math.abs(TEMP_ROT[i]) > Math.abs(TEMP_ROT[v]) ? i : v), 0);
|
|
275
|
+
if (TEMP_ROT[maxComp] < 0) {
|
|
276
|
+
TEMP_ROT.forEach((_, j) => {
|
|
277
|
+
TEMP_ROT[j] *= -1;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
TEMP_ROT.forEach((_, j) => (TEMP_ROT[j] *= Math.SQRT2));
|
|
281
|
+
const PERM = [
|
|
282
|
+
[1, 2, 3],
|
|
283
|
+
[0, 2, 3],
|
|
284
|
+
[0, 1, 3],
|
|
285
|
+
[0, 1, 2],
|
|
286
|
+
][maxComp];
|
|
287
|
+
quats[i * 4] = (TEMP_ROT[PERM[0]] * 0.5 + 0.5) * 255;
|
|
288
|
+
quats[i * 4 + 1] = (TEMP_ROT[PERM[1]] * 0.5 + 0.5) * 255;
|
|
289
|
+
quats[i * 4 + 2] = (TEMP_ROT[PERM[2]] * 0.5 + 0.5) * 255;
|
|
290
|
+
quats[i * 4 + 3] = 252 + maxComp;
|
|
291
|
+
}
|
|
292
|
+
output['quats.webp'] = encodeWebP(quats, width, height, webPProfile);
|
|
293
|
+
logger.timeEnd('ESZ encoding quats');
|
|
294
|
+
}
|
|
295
|
+
{
|
|
296
|
+
logger.time('ESZ encoding sh0');
|
|
297
|
+
const rCol = table[ColIdx.r];
|
|
298
|
+
const gCol = table[ColIdx.g];
|
|
299
|
+
const bCol = table[ColIdx.b];
|
|
300
|
+
const aCol = table[ColIdx.a];
|
|
301
|
+
const sh0 = new Uint8Array(width * height * 4).fill(0xff);
|
|
302
|
+
for (let i = 0; i < counts; i++) {
|
|
303
|
+
const idx = indices[i];
|
|
304
|
+
sh0[i * 4 + 0] = clamp(Math.round(((rCol[idx] - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
305
|
+
sh0[i * 4 + 1] = clamp(Math.round(((gCol[idx] - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
306
|
+
sh0[i * 4 + 2] = clamp(Math.round(((bCol[idx] - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
307
|
+
sh0[i * 4 + 3] = clamp(Math.round(aCol[idx] * 255), 0, 255);
|
|
308
|
+
}
|
|
309
|
+
output['sh0.webp'] = encodeWebP(sh0, width, height, webPProfile);
|
|
310
|
+
logger.timeEnd('ESZ encoding sh0');
|
|
311
|
+
}
|
|
312
|
+
if (shDegree > 0) {
|
|
313
|
+
logger.time('ESZ encoding shN');
|
|
314
|
+
const shCoeffs = shCounts / 3;
|
|
315
|
+
const pixels = counts * shCoeffs;
|
|
316
|
+
const shNWidth = Math.ceil(Math.sqrt(pixels) / 4) * 4;
|
|
317
|
+
const shNHeight = Math.ceil(pixels / shNWidth / 4) * 4;
|
|
318
|
+
const shN = new Uint8Array(shNWidth * shNHeight * 4).fill(0xff);
|
|
319
|
+
for (let i = 0; i < counts; i++) {
|
|
320
|
+
const idx = indices[i];
|
|
321
|
+
const o = i * shCoeffs;
|
|
322
|
+
for (let j = 0; j < shCoeffs; j++) {
|
|
323
|
+
const scale = j < 3 ? SH_SCALE1 : SH_SCALE2;
|
|
324
|
+
shN[(o + j) * 4 + 0] = clamp(Math.floor((Math.round(table[ColIdx.shOffset + (j * 3 + 0)][idx] * 128) + 128 + scale / 2) / scale) * scale, 0, 255);
|
|
325
|
+
shN[(o + j) * 4 + 1] = clamp(Math.floor((Math.round(table[ColIdx.shOffset + (j * 3 + 1)][idx] * 128) + 128 + scale / 2) / scale) * scale, 0, 255);
|
|
326
|
+
shN[(o + j) * 4 + 2] = clamp(Math.floor((Math.round(table[ColIdx.shOffset + (j * 3 + 2)][idx] * 128) + 128 + scale / 2) / scale) * scale, 0, 255);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
output['shN.webp'] = encodeWebP(shN, shNWidth, shNHeight, webPProfile);
|
|
330
|
+
meta.resources.shN = 'shN.webp';
|
|
331
|
+
logger.timeEnd('ESZ encoding shN');
|
|
332
|
+
}
|
|
333
|
+
output['meta.json'] = Buffer.from(JSON.stringify(meta), 'utf-8');
|
|
334
|
+
const result = zipSync(output);
|
|
335
|
+
await stream.getWriter().write(result);
|
|
336
|
+
}
|
|
337
|
+
}
|
package/dist/file/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { IFile } from './IFile.js';
|
|
2
|
-
export { KsplatFile } from './ksplat.js';
|
|
3
|
-
export { PlyFile } from './ply.js';
|
|
4
|
-
export { SogFile } from './sog.js';
|
|
5
|
-
export { SplatFile } from './splat.js';
|
|
6
|
-
export { SpzFile } from './spz.js';
|
|
7
|
-
export { LccFile } from './lcc.js';
|
|
1
|
+
export type { IFile } from './IFile.js';
|
|
2
|
+
export { KsplatFile } from './ksplat.js';
|
|
3
|
+
export { PlyFile } from './ply.js';
|
|
4
|
+
export { SogFile } from './sog.js';
|
|
5
|
+
export { SplatFile } from './splat.js';
|
|
6
|
+
export { SpzFile } from './spz.js';
|
|
7
|
+
export { LccFile } from './lcc.js';
|
|
8
|
+
export { EszFile } from './esz.js';
|
package/dist/file/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { KsplatFile } from './ksplat.js';
|
|
2
|
-
export { PlyFile } from './ply.js';
|
|
3
|
-
export { SogFile } from './sog.js';
|
|
4
|
-
export { SplatFile } from './splat.js';
|
|
5
|
-
export { SpzFile } from './spz.js';
|
|
6
|
-
export { LccFile } from './lcc.js';
|
|
1
|
+
export { KsplatFile } from './ksplat.js';
|
|
2
|
+
export { PlyFile } from './ply.js';
|
|
3
|
+
export { SogFile } from './sog.js';
|
|
4
|
+
export { SplatFile } from './splat.js';
|
|
5
|
+
export { SpzFile } from './spz.js';
|
|
6
|
+
export { LccFile } from './lcc.js';
|
|
7
|
+
export { EszFile } from './esz.js';
|
package/dist/file/ksplat.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { SplatData } from '../SplatData.js';
|
|
2
|
-
import { IFile } from './IFile.js';
|
|
3
|
-
export declare class KsplatFile implements IFile {
|
|
4
|
-
private counts;
|
|
5
|
-
private shDegree;
|
|
6
|
-
private header;
|
|
7
|
-
private sections;
|
|
8
|
-
private buffer;
|
|
9
|
-
private load;
|
|
10
|
-
read(stream: ReadableStream<Uint8Array>, contentLength: number, data: SplatData): Promise<void>;
|
|
11
|
-
write(_stream: WritableStream<Uint8Array>, _data: SplatData): Promise<void>;
|
|
12
|
-
}
|
|
1
|
+
import type { SplatData } from '../SplatData.js';
|
|
2
|
+
import type { IFile } from './IFile.js';
|
|
3
|
+
export declare class KsplatFile implements IFile {
|
|
4
|
+
private counts;
|
|
5
|
+
private shDegree;
|
|
6
|
+
private header;
|
|
7
|
+
private sections;
|
|
8
|
+
private buffer;
|
|
9
|
+
private load;
|
|
10
|
+
read(stream: ReadableStream<Uint8Array>, contentLength: number, data: SplatData): Promise<void>;
|
|
11
|
+
write(_stream: WritableStream<Uint8Array>, _data: SplatData): Promise<void>;
|
|
12
|
+
}
|