diff --git a/party-stage/src/scene/stage-torches.js b/party-stage/src/scene/stage-torches.js index 2c6a9aa..8cc5b5d 100644 --- a/party-stage/src/scene/stage-torches.js +++ b/party-stage/src/scene/stage-torches.js @@ -104,23 +104,17 @@ export class StageTorches extends SceneFeature { } update(deltaTime) { - const enabled = state.config.torchesEnabled && !state.blackoutMode; + const configEnabled = state.config.torchesEnabled; this.torches.forEach(torch => { - if (torch.group.visible !== enabled) torch.group.visible = enabled; + if (torch.group.visible !== configEnabled) torch.group.visible = configEnabled; }); - if (!enabled) return; + if (!configEnabled) return; - if (!state.partyStarted && state.music.isLoudEnough) { - this.torches.forEach(torch => { - if (torch.light.visible) torch.light.visible = false; - if (torch.particles.visible) torch.particles.visible = false; - }); - return; - } + const fireActive = !state.blackoutMode && !(!state.partyStarted && state.music.isLoudEnough); this.torches.forEach(torch => { - if (!torch.light.visible) torch.light.visible = true; + if (torch.light.visible !== fireActive) torch.light.visible = fireActive; if (!torch.particles.visible) torch.particles.visible = true; let measurePulse = 0; @@ -134,26 +128,35 @@ export class StageTorches extends SceneFeature { // --- Animate Particles --- const positions = torch.particles.geometry.attributes.position.array; let averageY = 0; + let activeParticleCount = 0; for (let i = 0; i < torch.particleData.length; i++) { const data = torch.particleData[i]; data.life -= deltaTime; const yVelocity = data.velocity.y; if (data.life <= 0 || positions[i * 3 + 1] < 0) { - // Reset particle - positions[i * 3] = (Math.random() - 0.5) * 0.2; - positions[i * 3 + 1] = 1; - positions[i * 3 + 2] = (Math.random() - 0.5) * 0.2; - data.life = Math.random() * 1.0; - data.velocity.y = Math.random() * 1.2 + measurePulse; + if (fireActive) { + // Reset particle + positions[i * 3] = (Math.random() - 0.5) * 0.2; + positions[i * 3 + 1] = 1; + positions[i * 3 + 2] = (Math.random() - 0.5) * 0.2; + data.life = Math.random() * 1.0; + data.velocity.y = Math.random() * 1.2 + measurePulse; + } else { + // Stop producing: move out of view + positions[i * 3 + 1] = -100; + } } else { // Update position positions[i * 3] += data.velocity.x * deltaTime; positions[i * 3 + 1] += yVelocity * deltaTime; positions[i * 3 + 2] += data.velocity.z * deltaTime; } - averageY += positions[i * 3 + 1]; + if (positions[i * 3 + 1] > -50) { + averageY += positions[i * 3 + 1]; + activeParticleCount++; + } } - averageY = averageY / positions.length; + averageY = activeParticleCount > 0 ? averageY / activeParticleCount : 0; torch.particles.geometry.attributes.position.needsUpdate = true; // --- Flicker Light ---