Skip to content

Commit 86070cb

Browse files
authored
Fix SH bug on SOG import (#7972)
1 parent c156676 commit 86070cb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/scene/gsplat/gsplat-sogs-data.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GSplatSogsIterator {
4040
const lerp = (a, b, t) => a * (1 - t) + b * t;
4141

4242
// extract means for centers
43-
const { meta } = data;
43+
const { meta, shBands } = data;
4444
const { means, scales, sh0, shN } = meta;
4545
const means_l_data = p && data.means_l._levels[0];
4646
const means_u_data = p && data.means_u._levels[0];
@@ -52,6 +52,8 @@ class GSplatSogsIterator {
5252

5353
const norm = 2.0 / Math.sqrt(2.0);
5454

55+
const coeffs = { 1: 3, 2: 8, 3: 15 }[shBands] ?? 0;
56+
5557
this.read = (i) => {
5658
if (p) {
5759
const nx = lerp(means.mins[0], means.maxs[0], ((means_u_data[i * 4 + 0] << 8) + means_l_data[i * 4 + 0]) / 65535);
@@ -121,18 +123,18 @@ class GSplatSogsIterator {
121123

122124
if (sh) {
123125
const n = sh_labels_data[i * 4 + 0] + (sh_labels_data[i * 4 + 1] << 8);
124-
const u = (n % 64) * 15;
126+
const u = (n % 64) * coeffs;
125127
const v = Math.floor(n / 64);
126128

127129
if (meta.version === 2) {
128130
for (let j = 0; j < 3; ++j) {
129-
for (let k = 0; k < 15; ++k) {
131+
for (let k = 0; k < coeffs; ++k) {
130132
sh[j * 15 + k] = shN.codebook[sh_centroids_data[((u + k) * 4 + j) + (v * data.sh_centroids.width * 4)]];
131133
}
132134
}
133135
} else {
134136
for (let j = 0; j < 3; ++j) {
135-
for (let k = 0; k < 15; ++k) {
137+
for (let k = 0; k < coeffs; ++k) {
136138
sh[j * 15 + k] = lerp(shN.mins, shN.maxs, sh_centroids_data[((u + k) * 4 + j) + (v * data.sh_centroids.width * 4)] / 255);
137139
}
138140
}

0 commit comments

Comments
 (0)