Feature: Music playback
This commit is contained in:
@@ -4,54 +4,33 @@ import { onResizePostprocessing } from './postprocessing.js';
|
||||
import { updateScreenEffect } from '../scene/magic-mirror.js'
|
||||
import sceneFeatureManager from '../scene/SceneFeatureManager.js';
|
||||
|
||||
function updateScreenLight() {
|
||||
if (state.isVideoLoaded && state.screenLight.intensity > 0) {
|
||||
const pulseTarget = state.originalScreenIntensity + (Math.random() - 0.5) * state.screenIntensityPulse;
|
||||
state.screenLight.intensity = THREE.MathUtils.lerp(state.screenLight.intensity, pulseTarget, 0.1);
|
||||
|
||||
const lightTime = Date.now() * 0.0001;
|
||||
const radius = 0.01;
|
||||
const centerX = 0;
|
||||
const centerY = 1.5;
|
||||
|
||||
state.screenLight.position.x = centerX + Math.cos(lightTime) * radius;
|
||||
state.screenLight.position.y = centerY + Math.sin(lightTime * 1.5) * radius * 0.5; // Slightly different freq for Y
|
||||
}
|
||||
}
|
||||
|
||||
function updateShaderTime() {
|
||||
if (state.tvScreen && state.tvScreen.material.uniforms && state.tvScreen.material.uniforms.u_time) {
|
||||
state.tvScreen.material.uniforms.u_time.value = state.clock.getElapsedTime();
|
||||
}
|
||||
}
|
||||
|
||||
function updateVideo() {
|
||||
if (state.videoTexture) {
|
||||
state.videoTexture.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --- Animation Loop ---
|
||||
let lastTime = -1;
|
||||
export function animate() {
|
||||
requestAnimationFrame(animate);
|
||||
|
||||
let deltaTime = 0;
|
||||
if (lastTime !== -1) {
|
||||
if (lastTime === -1) {
|
||||
lastTime = state.clock.getElapsedTime();
|
||||
deltaTime = 1;
|
||||
} else {
|
||||
const newTime = state.clock.getElapsedTime();
|
||||
deltaTime = newTime - lastTime;
|
||||
lastTime = newTime;
|
||||
} else {
|
||||
lastTime = state.clock.getElapsedTime();
|
||||
}
|
||||
|
||||
sceneFeatureManager.update(deltaTime);
|
||||
state.effectsManager.update();
|
||||
updateScreenLight();
|
||||
updateVideo();
|
||||
updateShaderTime();
|
||||
updateScreenEffect();
|
||||
if (deltaTime > 0) {
|
||||
sceneFeatureManager.update(deltaTime);
|
||||
state.effectsManager.update(deltaTime);
|
||||
updateShaderTime();
|
||||
updateScreenEffect();
|
||||
}
|
||||
|
||||
// RENDER!
|
||||
if (state.composer) {
|
||||
|
||||
Reference in New Issue
Block a user