@manycore/aholo-splat-transform 1.2.7-alpha.0 → 1.2.8
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 +11 -0
- package/COPYRIGHT.md +17 -0
- package/README.md +9 -3
- package/THIRD_PARTY_LICENSES.txt +1373 -0
- package/bin/cli.js +3 -3
- package/dist/SplatData.js +6 -12
- package/dist/file/esz.d.ts +11 -0
- package/dist/file/esz.js +322 -0
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.js +1 -0
- package/dist/file/ksplat.js +4 -5
- package/dist/file/lcc.js +5 -4
- package/dist/file/ply.js +8 -6
- package/dist/file/sog.js +8 -18
- package/dist/file/spz.d.ts +4 -1
- package/dist/file/spz.js +358 -175
- package/dist/native/cpp/bin/linux/binding.node +0 -0
- package/dist/native/cpp/bin/windows/binding.node +0 -0
- package/dist/native/index.js +4 -3
- package/dist/tasks/ReadTask.d.ts +1 -0
- package/dist/tasks/ReadTask.js +2 -2
- package/dist/tasks/WriteTask.d.ts +1 -0
- package/dist/tasks/WriteTask.js +6 -6
- package/dist/utils/BufferReader.js +2 -4
- package/dist/utils/Logger.js +4 -2
- package/dist/utils/StreamChunkDecoder.js +1 -6
- package/dist/utils/k-means.js +0 -9
- package/dist/utils/math.js +7 -12
- package/dist/utils/splat.d.ts +3 -2
- package/dist/utils/splat.js +12 -3
- package/dist/utils/voxel/common.js +10 -28
- package/dist/utils/voxel/gpu-dilation.js +3 -12
- package/package.json +13 -6
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
3
|
import { program } from 'commander';
|
|
4
4
|
import packageJson from '../package.json' with { type: 'json' };
|
|
5
5
|
import { runner } from '../dist/index.js';
|
|
@@ -8,10 +8,10 @@ const ExtraText = `
|
|
|
8
8
|
Transform Gaussian splats file
|
|
9
9
|
===================================
|
|
10
10
|
SUPPORTED INPUTS
|
|
11
|
-
.ply .compressed.ply .sog meta.json .ksplat .splat .spz .lcc
|
|
11
|
+
.ply .compressed.ply .sog meta.json .ksplat .splat .spz .lcc .esz
|
|
12
12
|
|
|
13
13
|
SUPPORTED OUTPUTS
|
|
14
|
-
.ply .spz .uspz .splat .sog
|
|
14
|
+
.ply .spz .uspz .splat .sog .esz
|
|
15
15
|
`;
|
|
16
16
|
|
|
17
17
|
program
|
package/dist/SplatData.js
CHANGED
|
@@ -2,22 +2,16 @@ import { Quaternion, deferred } from './utils/index.js';
|
|
|
2
2
|
import { SH_MAPS } from './constant.js';
|
|
3
3
|
const tempQuat = new Quaternion(0, 0, 0, 1);
|
|
4
4
|
export class SplatData {
|
|
5
|
-
counts;
|
|
6
|
-
shDegree;
|
|
7
|
-
shCounts;
|
|
8
|
-
maxShDegree;
|
|
9
|
-
table;
|
|
10
5
|
constructor(blockCounts = 1, maxShDegree = 3) {
|
|
6
|
+
this.blockOffsets = [];
|
|
7
|
+
this.blockContentCounts = [];
|
|
8
|
+
this.totalBlockCounts = 0;
|
|
9
|
+
this.totalBlockShDegree = 3;
|
|
10
|
+
this.blockExecs = [];
|
|
11
|
+
this.currentBlockIndex = 0;
|
|
11
12
|
this.blockCounts = blockCounts;
|
|
12
13
|
this.maxShDegree = maxShDegree;
|
|
13
14
|
}
|
|
14
|
-
blockOffsets = [];
|
|
15
|
-
blockContentCounts = [];
|
|
16
|
-
blockCounts;
|
|
17
|
-
totalBlockCounts = 0;
|
|
18
|
-
totalBlockShDegree = 3;
|
|
19
|
-
blockExecs = [];
|
|
20
|
-
currentBlockIndex = 0;
|
|
21
15
|
initBlock(counts, shDegree) {
|
|
22
16
|
this.blockContentCounts.push(counts);
|
|
23
17
|
this.blockOffsets.push(this.totalBlockCounts);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SplatData } from '../SplatData.js';
|
|
2
|
+
import { IFile } from './IFile.js';
|
|
3
|
+
export declare class EszFile implements IFile {
|
|
4
|
+
private counts;
|
|
5
|
+
private shDegree;
|
|
6
|
+
private cached;
|
|
7
|
+
load(stream: ReadableStream<Uint8Array>, contentLength: number): Promise<void>;
|
|
8
|
+
private loadTexture;
|
|
9
|
+
read(stream: ReadableStream<Uint8Array>, contentLength: number, data: SplatData): Promise<void>;
|
|
10
|
+
write(stream: WritableStream<Uint8Array>, data: SplatData, indices?: Uint32Array): Promise<void>;
|
|
11
|
+
}
|
package/dist/file/esz.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { unzipSync, zipSync } from 'fflate';
|
|
2
|
+
import { clamp, extractFromRootDir, isUrl, logger, mortonSort } from '../utils/index.js';
|
|
3
|
+
import { decodeWebP, encodeWebP, WebPLosslessProfile } from '../native/index.js';
|
|
4
|
+
import { SH_C0, SH_MAPS } from '../constant.js';
|
|
5
|
+
const TEMP_ROT = new Array(4);
|
|
6
|
+
const PERM_TABLE = [
|
|
7
|
+
[0, 1, 2, 3],
|
|
8
|
+
[3, 1, 2, 0],
|
|
9
|
+
[1, 3, 2, 0],
|
|
10
|
+
[1, 2, 3, 0],
|
|
11
|
+
];
|
|
12
|
+
const COLOR_SCALE = SH_C0 / 0.15;
|
|
13
|
+
const SH_SCALE1 = 1 << 3;
|
|
14
|
+
const SH_SCALE2 = 1 << 4;
|
|
15
|
+
function logTransform(value) {
|
|
16
|
+
return Math.sign(value) * Math.log(Math.abs(value) + 1);
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
export class EszFile {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.counts = 0;
|
|
22
|
+
this.shDegree = 0;
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
this.refs = {};
|
|
27
|
+
}
|
|
28
|
+
async load(stream, contentLength) {
|
|
29
|
+
const buffer = new Uint8Array(contentLength);
|
|
30
|
+
const reader = stream.getReader();
|
|
31
|
+
let offset = 0;
|
|
32
|
+
while (true) {
|
|
33
|
+
const { done, value } = await reader.read();
|
|
34
|
+
if (done) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
buffer.set(value, offset);
|
|
38
|
+
offset += value.length;
|
|
39
|
+
}
|
|
40
|
+
this.refs = extractFromRootDir(unzipSync(buffer));
|
|
41
|
+
const metaBuffer = this.refs['meta.json'];
|
|
42
|
+
if (!metaBuffer) {
|
|
43
|
+
throw new Error('SOG meta.json not found in the zip archive.');
|
|
44
|
+
}
|
|
45
|
+
const meta = this.meta = JSON.parse(new TextDecoder().decode(metaBuffer));
|
|
46
|
+
this.version = meta.version;
|
|
47
|
+
this.counts = meta.counts;
|
|
48
|
+
this.shDegree = meta.shDegree;
|
|
49
|
+
}
|
|
50
|
+
async loadTexture(path) {
|
|
51
|
+
let buffer = this.refs[path];
|
|
52
|
+
if (!buffer) {
|
|
53
|
+
if (isUrl(path)) {
|
|
54
|
+
buffer = await fetch(path)
|
|
55
|
+
.then(res => res.arrayBuffer())
|
|
56
|
+
.then(buf => new Uint8Array(buf));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!buffer) {
|
|
60
|
+
throw new Error(`Cannot load texture: ${path}`);
|
|
61
|
+
}
|
|
62
|
+
const { data, width, height } = decodeWebP(buffer);
|
|
63
|
+
return {
|
|
64
|
+
data: new Uint8Array(data),
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async read(stream, contentLength, data) {
|
|
70
|
+
await this.load(stream, contentLength);
|
|
71
|
+
const offset = await data.initBlock(this.counts, this.shDegree);
|
|
72
|
+
const { resources } = this.meta;
|
|
73
|
+
this.cached = await Promise.all([
|
|
74
|
+
resources.means_l, resources.means_u,
|
|
75
|
+
resources.scales, resources.quats,
|
|
76
|
+
resources.sh0, resources.shN,
|
|
77
|
+
].filter(path => !!path).map(path => this.loadTexture(path)));
|
|
78
|
+
const setFn = data.set.bind(data);
|
|
79
|
+
const setShFn = data.setShN.bind(data);
|
|
80
|
+
const SCALE_LUT = new Float32Array(256);
|
|
81
|
+
for (let i = 0; i < 256; i++) {
|
|
82
|
+
SCALE_LUT[i] = Math.exp(i / 16 - 10);
|
|
83
|
+
}
|
|
84
|
+
const COLOR_LUT = new Float32Array(256);
|
|
85
|
+
for (let i = 0; i < 256; i++) {
|
|
86
|
+
COLOR_LUT[i] = (i / 255 - 0.5) * COLOR_SCALE + 0.5;
|
|
87
|
+
}
|
|
88
|
+
const { meta: { box }, counts, shDegree, cached } = this;
|
|
89
|
+
const [means_l, means_u, scales, quats, color, shN] = cached.map(v => v.data);
|
|
90
|
+
const { min: [centerMinX, centerMinY, centerMinZ], max: [centerMaxX, centerMaxY, centerMaxZ] } = box;
|
|
91
|
+
const rangeX = (centerMaxX - centerMinX) / 65535;
|
|
92
|
+
const rangeY = (centerMaxY - centerMinY) / 65535;
|
|
93
|
+
const rangeZ = (centerMaxZ - centerMinZ) / 65535;
|
|
94
|
+
const single = {
|
|
95
|
+
x: 0, y: 0, z: 0,
|
|
96
|
+
sx: 0, sy: 0, sz: 0,
|
|
97
|
+
qx: 0, qy: 0, qz: 0, qw: 0,
|
|
98
|
+
r: 0, g: 0, b: 0, a: 0,
|
|
99
|
+
shN: [],
|
|
100
|
+
};
|
|
101
|
+
for (let i = 0; i < counts; i++) {
|
|
102
|
+
const i4 = i * 4;
|
|
103
|
+
const x = centerMinX + rangeX * (means_l[i4 + 0] + (means_u[i4 + 0] << 8));
|
|
104
|
+
const y = centerMinY + rangeY * (means_l[i4 + 1] + (means_u[i4 + 1] << 8));
|
|
105
|
+
const z = centerMinZ + rangeZ * (means_l[i4 + 2] + (means_u[i4 + 2] << 8));
|
|
106
|
+
single.x = Math.sign(x) * (Math.exp(Math.abs(x)) - 1);
|
|
107
|
+
single.y = Math.sign(y) * (Math.exp(Math.abs(y)) - 1);
|
|
108
|
+
single.z = Math.sign(z) * (Math.exp(Math.abs(z)) - 1);
|
|
109
|
+
single.sx = SCALE_LUT[scales[i4 + 0]];
|
|
110
|
+
single.sy = SCALE_LUT[scales[i4 + 1]];
|
|
111
|
+
single.sz = SCALE_LUT[scales[i4 + 2]];
|
|
112
|
+
TEMP_ROT[0] = (quats[i4 + 0] / 255 - 0.5) * Math.SQRT2;
|
|
113
|
+
TEMP_ROT[1] = (quats[i4 + 1] / 255 - 0.5) * Math.SQRT2;
|
|
114
|
+
TEMP_ROT[2] = (quats[i4 + 2] / 255 - 0.5) * Math.SQRT2;
|
|
115
|
+
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]));
|
|
116
|
+
const PERM = PERM_TABLE[quats[i4 + 3] - 252];
|
|
117
|
+
single.qx = TEMP_ROT[PERM[0]];
|
|
118
|
+
single.qy = TEMP_ROT[PERM[1]];
|
|
119
|
+
single.qz = TEMP_ROT[PERM[2]];
|
|
120
|
+
single.qw = TEMP_ROT[PERM[3]];
|
|
121
|
+
single.r = COLOR_LUT[color[i4 + 0]];
|
|
122
|
+
single.g = COLOR_LUT[color[i4 + 1]];
|
|
123
|
+
single.b = COLOR_LUT[color[i4 + 2]];
|
|
124
|
+
single.a = color[i4 + 3] / 255;
|
|
125
|
+
setFn(offset + i, single);
|
|
126
|
+
}
|
|
127
|
+
if (shN) {
|
|
128
|
+
const shCounts = SH_MAPS[shDegree];
|
|
129
|
+
const shCoeffs = shCounts / 3;
|
|
130
|
+
const sh = new Array(shCounts);
|
|
131
|
+
for (let i = 0; i < counts; i++) {
|
|
132
|
+
const o = i * shCounts;
|
|
133
|
+
for (let j = 0; j < shCoeffs; j++) {
|
|
134
|
+
sh[o + j * 3 + 0] = (shN[(i * shCoeffs + j) * 4 + 0] - 128) / 128;
|
|
135
|
+
sh[o + j * 3 + 1] = (shN[(i * shCoeffs + j) * 4 + 1] - 128) / 128;
|
|
136
|
+
sh[o + j * 3 + 2] = (shN[(i * shCoeffs + j) * 4 + 2] - 128) / 128;
|
|
137
|
+
}
|
|
138
|
+
setShFn(offset + i, sh);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
data.finishBlock();
|
|
142
|
+
}
|
|
143
|
+
async write(stream, data, indices = mortonSort(data)) {
|
|
144
|
+
const { counts, shDegree, shCounts, table } = data;
|
|
145
|
+
const width = Math.ceil(Math.sqrt(counts) / 4) * 4;
|
|
146
|
+
const height = Math.ceil(counts / width / 4) * 4;
|
|
147
|
+
const webPProfile = new WebPLosslessProfile();
|
|
148
|
+
const output = {};
|
|
149
|
+
const meta = {
|
|
150
|
+
version: 1,
|
|
151
|
+
counts,
|
|
152
|
+
shDegree,
|
|
153
|
+
box: {
|
|
154
|
+
min: [Infinity, Infinity, Infinity],
|
|
155
|
+
max: [-Infinity, -Infinity, -Infinity],
|
|
156
|
+
},
|
|
157
|
+
resources: {
|
|
158
|
+
means_l: 'means_l.webp', means_u: 'means_u.webp',
|
|
159
|
+
scales: 'scales.webp', quats: 'quats.webp', sh0: 'sh0.webp',
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
const xCol = table[0 /* ColIdx.x */];
|
|
163
|
+
const yCol = table[1 /* ColIdx.y */];
|
|
164
|
+
const zCol = table[2 /* ColIdx.z */];
|
|
165
|
+
// calculate minmax & transform
|
|
166
|
+
let minX = Infinity;
|
|
167
|
+
let minY = Infinity;
|
|
168
|
+
let minZ = Infinity;
|
|
169
|
+
let maxX = -Infinity;
|
|
170
|
+
let maxY = -Infinity;
|
|
171
|
+
let maxZ = -Infinity;
|
|
172
|
+
for (let i = 0; i < counts; i++) {
|
|
173
|
+
const idx = indices[i];
|
|
174
|
+
const x = xCol[idx];
|
|
175
|
+
const y = yCol[idx];
|
|
176
|
+
const z = zCol[idx];
|
|
177
|
+
if (x < minX) {
|
|
178
|
+
minX = x;
|
|
179
|
+
}
|
|
180
|
+
if (x > maxX) {
|
|
181
|
+
maxX = x;
|
|
182
|
+
}
|
|
183
|
+
if (y < minY) {
|
|
184
|
+
minY = y;
|
|
185
|
+
}
|
|
186
|
+
if (y > maxY) {
|
|
187
|
+
maxY = y;
|
|
188
|
+
}
|
|
189
|
+
if (z < minZ) {
|
|
190
|
+
minZ = z;
|
|
191
|
+
}
|
|
192
|
+
if (z > maxZ) {
|
|
193
|
+
maxZ = z;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
meta.box.min = [minX, minY, minZ];
|
|
197
|
+
meta.box.max = [maxX, maxY, maxZ];
|
|
198
|
+
{
|
|
199
|
+
logger.time('ESZ encoding means');
|
|
200
|
+
minX = logTransform(minX);
|
|
201
|
+
minY = logTransform(minY);
|
|
202
|
+
minZ = logTransform(minZ);
|
|
203
|
+
maxX = logTransform(maxX);
|
|
204
|
+
maxY = logTransform(maxY);
|
|
205
|
+
maxZ = logTransform(maxZ);
|
|
206
|
+
const scaleX = 65535 / Math.max(maxX - minX, 1e-9);
|
|
207
|
+
const scaleY = 65535 / Math.max(maxY - minY, 1e-9);
|
|
208
|
+
const scaleZ = 65535 / Math.max(maxZ - minZ, 1e-9);
|
|
209
|
+
const meansL = new Uint8Array(width * height * 4).fill(0xff);
|
|
210
|
+
const meansU = new Uint8Array(width * height * 4).fill(0xff);
|
|
211
|
+
for (let i = 0; i < indices.length; i++) {
|
|
212
|
+
const idx = indices[i];
|
|
213
|
+
const x = (logTransform(xCol[idx]) - minX) * scaleX;
|
|
214
|
+
const y = (logTransform(yCol[idx]) - minY) * scaleY;
|
|
215
|
+
const z = (logTransform(zCol[idx]) - minZ) * scaleZ;
|
|
216
|
+
meansL[i * 4 + 0] = x & 0xff;
|
|
217
|
+
meansL[i * 4 + 1] = y & 0xff;
|
|
218
|
+
meansL[i * 4 + 2] = z & 0xff;
|
|
219
|
+
meansU[i * 4 + 0] = (x >> 8) & 0xff;
|
|
220
|
+
meansU[i * 4 + 1] = (y >> 8) & 0xff;
|
|
221
|
+
meansU[i * 4 + 2] = (z >> 8) & 0xff;
|
|
222
|
+
}
|
|
223
|
+
output['means_l.webp'] = encodeWebP(meansL, width, height, webPProfile);
|
|
224
|
+
output['means_u.webp'] = encodeWebP(meansU, width, height, webPProfile);
|
|
225
|
+
logger.timeEnd('ESZ encoding means');
|
|
226
|
+
}
|
|
227
|
+
{
|
|
228
|
+
logger.time('ESZ encoding scales');
|
|
229
|
+
const sxCol = table[3 /* ColIdx.sx */];
|
|
230
|
+
const syCol = table[4 /* ColIdx.sy */];
|
|
231
|
+
const szCol = table[5 /* ColIdx.sz */];
|
|
232
|
+
const scales = new Uint8Array(width * height * 4).fill(0xff);
|
|
233
|
+
for (let i = 0; i < counts; i++) {
|
|
234
|
+
const idx = indices[i];
|
|
235
|
+
scales[i * 4 + 0] = clamp(Math.round((Math.log(sxCol[idx]) + 10) * 16), 0, 255);
|
|
236
|
+
scales[i * 4 + 1] = clamp(Math.round((Math.log(syCol[idx]) + 10) * 16), 0, 255);
|
|
237
|
+
scales[i * 4 + 2] = clamp(Math.round((Math.log(szCol[idx]) + 10) * 16), 0, 255);
|
|
238
|
+
}
|
|
239
|
+
output['scales.webp'] = encodeWebP(scales, width, height, webPProfile);
|
|
240
|
+
logger.timeEnd('ESZ encoding scales');
|
|
241
|
+
}
|
|
242
|
+
{
|
|
243
|
+
logger.time('ESZ encoding quats');
|
|
244
|
+
const qxCol = table[6 /* ColIdx.qx */];
|
|
245
|
+
const qyCol = table[7 /* ColIdx.qy */];
|
|
246
|
+
const qzCol = table[8 /* ColIdx.qz */];
|
|
247
|
+
const qwCol = table[9 /* ColIdx.qw */];
|
|
248
|
+
const quats = new Uint8Array(width * height * 4);
|
|
249
|
+
for (let i = 0; i < counts; i++) {
|
|
250
|
+
const idx = indices[i];
|
|
251
|
+
TEMP_ROT[0] = qwCol[idx];
|
|
252
|
+
TEMP_ROT[1] = qxCol[idx];
|
|
253
|
+
TEMP_ROT[2] = qyCol[idx];
|
|
254
|
+
TEMP_ROT[3] = qzCol[idx];
|
|
255
|
+
const l = Math.sqrt(TEMP_ROT[0] * TEMP_ROT[0] + TEMP_ROT[1] * TEMP_ROT[1] + TEMP_ROT[2] * TEMP_ROT[2] + TEMP_ROT[3] * TEMP_ROT[3]);
|
|
256
|
+
TEMP_ROT.forEach((v, j) => {
|
|
257
|
+
TEMP_ROT[j] = v / l;
|
|
258
|
+
});
|
|
259
|
+
const maxComp = TEMP_ROT.reduce((v, _, i) => (Math.abs(TEMP_ROT[i]) > Math.abs(TEMP_ROT[v]) ? i : v), 0);
|
|
260
|
+
if (TEMP_ROT[maxComp] < 0) {
|
|
261
|
+
TEMP_ROT.forEach((_, j) => {
|
|
262
|
+
TEMP_ROT[j] *= -1;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
TEMP_ROT.forEach((_, j) => TEMP_ROT[j] *= Math.SQRT2);
|
|
266
|
+
const PERM = [
|
|
267
|
+
[1, 2, 3],
|
|
268
|
+
[0, 2, 3],
|
|
269
|
+
[0, 1, 3],
|
|
270
|
+
[0, 1, 2]
|
|
271
|
+
][maxComp];
|
|
272
|
+
quats[i * 4] = (TEMP_ROT[PERM[0]] * 0.5 + 0.5) * 255;
|
|
273
|
+
quats[i * 4 + 1] = (TEMP_ROT[PERM[1]] * 0.5 + 0.5) * 255;
|
|
274
|
+
quats[i * 4 + 2] = (TEMP_ROT[PERM[2]] * 0.5 + 0.5) * 255;
|
|
275
|
+
quats[i * 4 + 3] = 252 + maxComp;
|
|
276
|
+
}
|
|
277
|
+
output['quats.webp'] = encodeWebP(quats, width, height, webPProfile);
|
|
278
|
+
logger.timeEnd('ESZ encoding quats');
|
|
279
|
+
}
|
|
280
|
+
{
|
|
281
|
+
logger.time('ESZ encoding sh0');
|
|
282
|
+
const rCol = table[10 /* ColIdx.r */];
|
|
283
|
+
const gCol = table[11 /* ColIdx.g */];
|
|
284
|
+
const bCol = table[12 /* ColIdx.b */];
|
|
285
|
+
const aCol = table[13 /* ColIdx.a */];
|
|
286
|
+
const sh0 = new Uint8Array(width * height * 4).fill(0xff);
|
|
287
|
+
for (let i = 0; i < counts; i++) {
|
|
288
|
+
const idx = indices[i];
|
|
289
|
+
sh0[i * 4 + 0] = clamp(Math.round(((rCol[idx] - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
290
|
+
sh0[i * 4 + 1] = clamp(Math.round(((gCol[idx] - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
291
|
+
sh0[i * 4 + 2] = clamp(Math.round(((bCol[idx] - 0.5) / COLOR_SCALE + 0.5) * 255), 0, 255);
|
|
292
|
+
sh0[i * 4 + 3] = clamp(Math.round(aCol[idx] * 255), 0, 255);
|
|
293
|
+
}
|
|
294
|
+
output['sh0.webp'] = encodeWebP(sh0, width, height, webPProfile);
|
|
295
|
+
logger.timeEnd('ESZ encoding sh0');
|
|
296
|
+
}
|
|
297
|
+
if (shDegree > 0) {
|
|
298
|
+
logger.time('ESZ encoding shN');
|
|
299
|
+
const shCoeffs = shCounts / 3;
|
|
300
|
+
const pixels = counts * shCoeffs;
|
|
301
|
+
const shNWidth = Math.ceil(Math.sqrt(pixels) / 4) * 4;
|
|
302
|
+
const shNHeight = Math.ceil(pixels / shNWidth / 4) * 4;
|
|
303
|
+
const shN = new Uint8Array(shNWidth * shNHeight * 4).fill(0xff);
|
|
304
|
+
for (let i = 0; i < counts; i++) {
|
|
305
|
+
const idx = indices[i];
|
|
306
|
+
const o = i * shCoeffs;
|
|
307
|
+
for (let j = 0; j < shCoeffs; j++) {
|
|
308
|
+
const scale = j < 3 ? SH_SCALE1 : SH_SCALE2;
|
|
309
|
+
shN[(o + j) * 4 + 0] = clamp(Math.floor((Math.round(table[14 /* ColIdx.shOffset */ + (j * 3 + 0)][idx] * 128) + 128 + scale / 2) / scale) * scale, 0, 255);
|
|
310
|
+
shN[(o + j) * 4 + 1] = clamp(Math.floor((Math.round(table[14 /* ColIdx.shOffset */ + (j * 3 + 1)][idx] * 128) + 128 + scale / 2) / scale) * scale, 0, 255);
|
|
311
|
+
shN[(o + j) * 4 + 2] = clamp(Math.floor((Math.round(table[14 /* ColIdx.shOffset */ + (j * 3 + 2)][idx] * 128) + 128 + scale / 2) / scale) * scale, 0, 255);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
output['shN.webp'] = encodeWebP(shN, shNWidth, shNHeight, webPProfile);
|
|
315
|
+
meta.resources.shN = 'shN.webp';
|
|
316
|
+
logger.timeEnd('ESZ encoding shN');
|
|
317
|
+
}
|
|
318
|
+
output['meta.json'] = Buffer.from(JSON.stringify(meta), 'utf-8');
|
|
319
|
+
const result = zipSync(output);
|
|
320
|
+
await stream.getWriter().write(result);
|
|
321
|
+
}
|
|
322
|
+
}
|
package/dist/file/index.d.ts
CHANGED
package/dist/file/index.js
CHANGED
package/dist/file/ksplat.js
CHANGED
|
@@ -46,11 +46,10 @@ const SHIndex = [
|
|
|
46
46
|
const HEADER_BYTES = 4096;
|
|
47
47
|
const SECTION_BYTES = 1024;
|
|
48
48
|
export class KsplatFile {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
buffer;
|
|
49
|
+
constructor() {
|
|
50
|
+
this.counts = 0;
|
|
51
|
+
this.shDegree = 0;
|
|
52
|
+
}
|
|
54
53
|
load(buffer) {
|
|
55
54
|
this.buffer = buffer;
|
|
56
55
|
const header = new DataView(buffer.buffer, 0, HEADER_BYTES);
|
package/dist/file/lcc.js
CHANGED
|
@@ -39,10 +39,11 @@ function mix(min, max, s) {
|
|
|
39
39
|
}
|
|
40
40
|
;
|
|
41
41
|
export class LccFile {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
constructor() {
|
|
43
|
+
this.counts = 0;
|
|
44
|
+
this.shDegree = 0;
|
|
45
|
+
this.refs = {};
|
|
46
|
+
}
|
|
46
47
|
load(buffer) {
|
|
47
48
|
const view = new DataView(buffer.buffer);
|
|
48
49
|
if (view.getUint32(0, true) !== ZIP_MAGIC) {
|
package/dist/file/ply.js
CHANGED
|
@@ -64,12 +64,14 @@ function createParseFn(properties, littleEndian, shDegree) {
|
|
|
64
64
|
}
|
|
65
65
|
const HeaderTerminator = 'end_header\n';
|
|
66
66
|
export class PlyFile {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
constructor() {
|
|
68
|
+
this.littleEndian = true;
|
|
69
|
+
this.comments = [];
|
|
70
|
+
this.elements = {};
|
|
71
|
+
this.isSuperSplatCompressed = false;
|
|
72
|
+
this.counts = 0;
|
|
73
|
+
this.shDegree = 0;
|
|
74
|
+
}
|
|
73
75
|
initHeader(header) {
|
|
74
76
|
let curElement;
|
|
75
77
|
const lines = header.trim().split('\n').map(v => v.trim()).filter(v => !!v);
|
package/dist/file/sog.js
CHANGED
|
@@ -37,24 +37,14 @@ function buildSHTableMap(shCoeffs) {
|
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
export class SogFile {
|
|
40
|
-
iterations;
|
|
41
|
-
counts = 0;
|
|
42
|
-
shDegree = 0;
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
version;
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
meta;
|
|
51
|
-
/**
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
refs = {};
|
|
55
|
-
cached;
|
|
56
40
|
constructor(iterations = 10) {
|
|
57
41
|
this.iterations = iterations;
|
|
42
|
+
this.counts = 0;
|
|
43
|
+
this.shDegree = 0;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
this.refs = {};
|
|
58
48
|
}
|
|
59
49
|
async load(stream, contentLength) {
|
|
60
50
|
const buffer = new Uint8Array(contentLength);
|
|
@@ -405,12 +395,12 @@ export class SogFile {
|
|
|
405
395
|
const maxComp = q.reduce((v, _, i) => (Math.abs(q[i]) > Math.abs(q[v]) ? i : v), 0);
|
|
406
396
|
// invert if max component is negative
|
|
407
397
|
if (q[maxComp] < 0) {
|
|
408
|
-
q.forEach((
|
|
398
|
+
q.forEach((_, j) => {
|
|
409
399
|
q[j] *= -1;
|
|
410
400
|
});
|
|
411
401
|
}
|
|
412
402
|
// scale by sqrt(2) to fit in [-1, 1] range
|
|
413
|
-
q.forEach((
|
|
403
|
+
q.forEach((_, j) => q[j] *= Math.SQRT2);
|
|
414
404
|
const idx = [
|
|
415
405
|
[1, 2, 3],
|
|
416
406
|
[0, 2, 3],
|
package/dist/file/spz.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { SplatData } from '../SplatData.js';
|
|
|
2
2
|
import { IFile } from './IFile.js';
|
|
3
3
|
export declare class SpzFile implements IFile {
|
|
4
4
|
readonly compressLevel: number;
|
|
5
|
-
|
|
5
|
+
readonly spzVersion: number;
|
|
6
|
+
constructor(compressLevel: number, spzVersion?: number);
|
|
6
7
|
read(stream: ReadableStream<Uint8Array>, _contentLength: number, data: SplatData): Promise<void>;
|
|
7
8
|
write(writeStream: WritableStream<Uint8Array>, data: SplatData, indices?: Uint32Array): Promise<void>;
|
|
9
|
+
private writeV3;
|
|
10
|
+
private writeV4;
|
|
8
11
|
}
|