From a434c91b551c0c561281d95318046c2c8c34fbb2 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 18 May 2026 16:07:39 +0200 Subject: [PATCH] Refactor material texture cache management to use generic material logic and improve cleanup --- src/runtime-three/runtime-host.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/runtime-three/runtime-host.ts b/src/runtime-three/runtime-host.ts index ad87a5f6..57c5bc7e 100644 --- a/src/runtime-three/runtime-host.ts +++ b/src/runtime-three/runtime-host.ts @@ -1494,11 +1494,7 @@ export class RuntimeHost { this.renderer.autoClear = true; } - for (const cachedTexture of this.materialTextureCache.values()) { - disposeStarterMaterialTextureSet(cachedTexture.textureSet); - } - - this.materialTextureCache.clear(); + this.clearMaterialTextureCache(); this.environmentBlendCache?.dispose(); this.shaderSkyEnvironmentBlendCache?.dispose(); this.shaderSkyEnvironmentCache?.dispose(); @@ -5248,10 +5244,18 @@ export class RuntimeHost { } } + private clearMaterialTextureCache() { + for (const cachedTexture of this.materialTextureCache.values()) { + disposeMaterialTextureSet(cachedTexture.textureSet); + } + + this.materialTextureCache.clear(); + } + private getOrCreateTextureSet( material: NonNullable ) { - const signature = createStarterMaterialSignature(material); + const signature = createMaterialSignature(material, this.loadedImageAssets); const cachedTexture = this.materialTextureCache.get(material.id); if (cachedTexture !== undefined && cachedTexture.signature === signature) { @@ -5259,13 +5263,15 @@ export class RuntimeHost { } if (cachedTexture !== undefined) { - disposeStarterMaterialTextureSet(cachedTexture.textureSet); + disposeMaterialTextureSet(cachedTexture.textureSet); } - const textureSet = createStarterMaterialTextureSet( + const textureSet = createMaterialTextureSet( material, - this.materialTextureLoader + this.materialTextureLoader, + this.loadedImageAssets ); + this.materialTextureCache.set(material.id, { signature, textureSet