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: 0 additions & 1 deletion examples/interactivity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ <h2>Food scans by <a href="https://x.com/tipatat" target="_blank">Tipatat</a></h
if (food) food.opacity = 1 - easeInOutSine(fadeOutTime / TRANSITION_LENGTH);
} else {
// Fade out finished
if (food) food.dispose();
fadeOutTime = null;
// Fade in next food
fadeInTime = 0;
Expand Down
28 changes: 26 additions & 2 deletions src/PackedSplats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import {
DynoProgram,
DynoProgramTemplate,
DynoSampler2D,
type DynoType,
DynoUniform,
DynoVec2,
DynoVec4,
Expand Down Expand Up @@ -241,12 +243,32 @@ export class PackedSplats {
dispose() {
if (this.target) {
this.target.dispose();
this.target.texture.source.data = null;
this.target = null;
}
if (this.source) {
this.source.dispose();
this.source.source.data = null;
this.source = null;
}

this.packedArray = null;

for (const key in this.extra) {
const dyno = this.extra[key] as DynoUniform<
DynoType,
string,
THREE.Texture
>;
if (dyno instanceof DynoUniform) {
const texture = dyno.value;
if (texture?.isTexture) {
texture.dispose();
texture.source.data = null;
}
}
}
this.extra = {};
}

// Ensures that this.packedArray can fit numSplats Gsplats. If it's too small,
Expand Down Expand Up @@ -432,7 +454,9 @@ export class PackedSplats {
if (this.target && (maxSplats ?? 1) <= this.maxSplats) {
return false;
}
this.dispose();
if (this.target) {
this.target.dispose();
}

const textureSize = getTextureSize(maxSplats ?? 1);
const { width, height, depth } = textureSize;
Expand Down Expand Up @@ -687,7 +711,7 @@ export class PackedSplats {
static programTemplate: DynoProgramTemplate | null = null;

// Cache for GsplatGenerator programs
static generatorProgram = new Map<GsplatGenerator, DynoProgram>();
static generatorProgram = new WeakMap<GsplatGenerator, DynoProgram>();

// Static full-screen quad for pseudo-compute shader rendering
static fullScreenQuad = new FullScreenQuad(
Expand Down
2 changes: 1 addition & 1 deletion src/dyno/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DynoProgramTemplate {
}
}

const programMaterial = new Map<DynoProgram, THREE.RawShaderMaterial>();
const programMaterial = new WeakMap<DynoProgram, THREE.RawShaderMaterial>();

function getMaterial(program: DynoProgram): THREE.RawShaderMaterial {
let material = programMaterial.get(program);
Expand Down