From 2509678105cf5f346601d016c6b18659096a0f48 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 14 Apr 2026 03:02:44 +0200 Subject: [PATCH] Add checks to prevent redundant updates in light and sound settings --- src/runtime-three/runtime-host.ts | 62 +++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/runtime-three/runtime-host.ts b/src/runtime-three/runtime-host.ts index 94da8822..d696da3c 100644 --- a/src/runtime-three/runtime-host.ts +++ b/src/runtime-three/runtime-host.ts @@ -1184,6 +1184,13 @@ export class RuntimeHost { return; } + if ( + this.runtimeScene.world.ambientLight.intensity === intensity && + this.currentWorld.ambientLight.intensity === intensity + ) { + return; + } + this.runtimeScene.world.ambientLight.intensity = intensity; this.currentWorld.ambientLight.intensity = intensity; this.applyDayNightLighting(); @@ -1197,6 +1204,13 @@ export class RuntimeHost { return; } + if ( + this.runtimeScene.world.ambientLight.colorHex === colorHex && + this.currentWorld.ambientLight.colorHex === colorHex + ) { + return; + } + this.runtimeScene.world.ambientLight.colorHex = colorHex; this.currentWorld.ambientLight.colorHex = colorHex; this.applyDayNightLighting(); @@ -1210,6 +1224,13 @@ export class RuntimeHost { return; } + if ( + this.runtimeScene.world.sunLight.intensity === intensity && + this.currentWorld.sunLight.intensity === intensity + ) { + return; + } + this.runtimeScene.world.sunLight.intensity = intensity; this.currentWorld.sunLight.intensity = intensity; this.applyDayNightLighting(); @@ -1223,6 +1244,13 @@ export class RuntimeHost { return; } + if ( + this.runtimeScene.world.sunLight.colorHex === colorHex && + this.currentWorld.sunLight.colorHex === colorHex + ) { + return; + } + this.runtimeScene.world.sunLight.colorHex = colorHex; this.currentWorld.sunLight.colorHex = colorHex; this.applyDayNightLighting(); @@ -1255,6 +1283,8 @@ export class RuntimeHost { clipName: string | null, loop: boolean | undefined ) { + let stateChanged = true; + if (this.runtimeScene !== null) { const modelInstance = this.runtimeScene.modelInstances.find( @@ -1262,12 +1292,24 @@ export class RuntimeHost { ) ?? null; if (modelInstance !== null) { - modelInstance.animationClipName = clipName ?? undefined; - modelInstance.animationAutoplay = clipName !== null; - modelInstance.animationLoop = clipName === null ? undefined : loop; + const nextClipName = clipName ?? undefined; + const nextAutoplay = clipName !== null; + const nextLoop = clipName === null ? undefined : loop; + + stateChanged = + modelInstance.animationClipName !== nextClipName || + modelInstance.animationAutoplay !== nextAutoplay || + modelInstance.animationLoop !== nextLoop; + modelInstance.animationClipName = nextClipName; + modelInstance.animationAutoplay = nextAutoplay; + modelInstance.animationLoop = nextLoop; } } + if (!stateChanged) { + return; + } + if (!this.animationMixers.has(target.modelInstanceId)) { return; } @@ -1285,6 +1327,8 @@ export class RuntimeHost { playing: boolean, link: InteractionLink | null = null ) { + let stateChanged = true; + if (this.runtimeScene !== null) { const soundEmitter = this.runtimeScene.entities.soundEmitters.find( @@ -1292,10 +1336,15 @@ export class RuntimeHost { ) ?? null; if (soundEmitter !== null) { + stateChanged = soundEmitter.autoplay !== playing; soundEmitter.autoplay = playing; } } + if (!stateChanged) { + return; + } + if (!this.audioSystem.hasSoundEmitter(target.entityId)) { return; } @@ -1311,6 +1360,8 @@ export class RuntimeHost { target: SoundEmitterControlTargetRef, volume: number ) { + let stateChanged = true; + if (this.runtimeScene !== null) { const soundEmitter = this.runtimeScene.entities.soundEmitters.find( @@ -1318,10 +1369,15 @@ export class RuntimeHost { ) ?? null; if (soundEmitter !== null) { + stateChanged = soundEmitter.volume !== volume; soundEmitter.volume = volume; } } + if (!stateChanged) { + return; + } + this.audioSystem.setSoundEmitterVolume(target.entityId, volume); }