Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/framework/parsers/sog-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class SogBundleParser {
data.sh0 = textures[meta.sh0.files[0]].resource;
data.sh_centroids = textures[meta.shN?.files[0]]?.resource;
data.sh_labels = textures[meta.shN?.files[1]]?.resource;
data.shBands = GSplatSogsData.calcBands(data.sh_centroids?.width);

if (!decompress) {
// no need to prepare gpu data if decompressing
Expand Down
1 change: 1 addition & 0 deletions src/framework/parsers/sogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class SogsParser {
data.sh0 = textures.sh0[0].resource;
data.sh_centroids = textures.shN?.[0]?.resource;
data.sh_labels = textures.shN?.[1]?.resource;
data.shBands = GSplatSogsData.calcBands(data.sh_centroids?.width);

const decompress = asset.data?.decompress;
const minimalMemory = asset.options?.minimalMemory ?? false;
Expand Down
21 changes: 9 additions & 12 deletions src/scene/gsplat/gsplat-sogs-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@ class GSplatSogsData {
destroyed = false;

/**
* Cached number of spherical harmonics bands.
* Number of spherical harmonics bands.
*
* @type {number}
* @private
*/
_shBands = 0;
shBands = 0;

_destroyGpuResources() {
this.means_l?.destroy();
Expand All @@ -237,6 +236,13 @@ class GSplatSogsData {
this.packedShN?.destroy();
}

// calculate the number of bands given the centroids texture width
static calcBands(centroidsWidth) {
// sh palette has 64 sh entries per row: 192 = 1 band (64*3), 512 = 2 bands (64*8), 960 = 3 bands (64*15)
const shBandsWidths = { 192: 1, 512: 2, 960: 3 };
return shBandsWidths[centroidsWidth] ?? 0;
}

destroy() {
// Remove devicerestored listener if it was registered
this.deviceRestoredEvent?.off();
Expand Down Expand Up @@ -293,10 +299,6 @@ class GSplatSogsData {
return true;
}

get shBands() {
return this._shBands;
}

async decompress() {
const members = [
'x', 'y', 'z',
Expand Down Expand Up @@ -543,11 +545,6 @@ class GSplatSogsData {

if (this.destroyed || !device || device._destroyed) return;

// Cache shBands from sh_centroids texture width before source textures may be destroyed
// sh palette has 64 sh entries per row: 192 = 1 band (64*3), 512 = 2 bands (64*8), 960 = 3 bands (64*15)
const shBandsWidths = { 192: 1, 512: 2, 960: 3 };
this._shBands = shBandsWidths[this.sh_centroids?.width] ?? 0;

// Include URL in texture name for debugging
const urlSuffix = this.url ? `_${this.url}` : '';

Expand Down