Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions src/pcsogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ export async function unpackPcSogs(
}

if (json.shN) {
extra.sh1 = new Uint32Array(numSplats * 2);
extra.sh2 = new Uint32Array(numSplats * 4);
extra.sh3 = new Uint32Array(numSplats * 4);
const useSH3 = json.shN.shape[1] >= 48 - 3;
const useSH2 = json.shN.shape[1] >= 27 - 3;
const useSH1 = json.shN.shape[1] >= 12 - 3;

if (useSH1) extra.sh1 = new Uint32Array(numSplats * 2);
if (useSH2) extra.sh2 = new Uint32Array(numSplats * 4);
if (useSH3) extra.sh3 = new Uint32Array(numSplats * 4);

const sh1 = new Float32Array(9);
const sh2 = new Float32Array(15);
const sh3 = new Float32Array(21);
Expand All @@ -116,32 +121,40 @@ export async function unpackPcSogs(
const offset = row * centroids.width + col;

for (let d = 0; d < 3; ++d) {
for (let k = 0; k < 3; ++k) {
sh1[k * 3 + d] =
json.shN.mins +
((json.shN.maxs - json.shN.mins) *
centroids.rgba[(offset + k) * 4 + d]) /
255;
if (useSH1) {
for (let k = 0; k < 3; ++k) {
sh1[k * 3 + d] =
json.shN.mins +
((json.shN.maxs - json.shN.mins) *
centroids.rgba[(offset + k) * 4 + d]) /
255;
}
}
for (let k = 0; k < 5; ++k) {
sh2[k * 3 + d] =
json.shN.mins +
((json.shN.maxs - json.shN.mins) *
centroids.rgba[(offset + 3 + k) * 4 + d]) /
255;

if (useSH2) {
for (let k = 0; k < 5; ++k) {
sh2[k * 3 + d] =
json.shN.mins +
((json.shN.maxs - json.shN.mins) *
centroids.rgba[(offset + 3 + k) * 4 + d]) /
255;
}
}
for (let k = 0; k < 7; ++k) {
sh3[k * 3 + d] =
json.shN.mins +
((json.shN.maxs - json.shN.mins) *
centroids.rgba[(offset + 8 + k) * 4 + d]) /
255;

if (useSH3) {
for (let k = 0; k < 7; ++k) {
sh3[k * 3 + d] =
json.shN.mins +
((json.shN.maxs - json.shN.mins) *
centroids.rgba[(offset + 8 + k) * 4 + d]) /
255;
}
}
}

encodeSh1Rgb(extra.sh1 as Uint32Array, i, sh1);
encodeSh2Rgb(extra.sh2 as Uint32Array, i, sh2);
encodeSh3Rgb(extra.sh3 as Uint32Array, i, sh3);
if (useSH1) encodeSh1Rgb(extra.sh1 as Uint32Array, i, sh1);
if (useSH2) encodeSh2Rgb(extra.sh2 as Uint32Array, i, sh2);
if (useSH3) encodeSh3Rgb(extra.sh3 as Uint32Array, i, sh3);
}
}

Expand Down