Refactoring: Centralize TV screen material creation

This commit is contained in:
Dejvino 2025-11-17 13:31:53 +01:00
parent c1383e0845
commit 272c4267a3
2 changed files with 31 additions and 17 deletions

View File

@ -1,5 +1,6 @@
import * as THREE from 'three';
import { state } from '../state.js';
import { turnTvScreenOff, turnTvScreenOn } from '../scene/tv-set.js';
// --- Play video by index ---
export function playVideoByIndex(index) {
@ -15,13 +16,7 @@ export function playVideoByIndex(index) {
if (index < 0 || index >= state.videoUrls.length) {
console.info('End of playlist reached. Reload tapes to start again.');
state.screenLight.intensity = 0.0;
state.tvScreen.material.dispose();
state.tvScreen.material = new THREE.MeshPhongMaterial({
color: 0x0a0a0a, // Deep black
shininess: 5,
specular: 0x111111
});
state.tvScreen.material.needsUpdate = true;
turnTvScreenOff();
state.isVideoLoaded = false;
state.lastUpdateTime = -1; // force VCR to redraw
return;
@ -44,9 +39,7 @@ export function playVideoByIndex(index) {
state.videoTexture.needsUpdate = true;
// 2. Apply the video texture to the screen mesh
state.tvScreen.material.dispose();
state.tvScreen.material = new THREE.MeshBasicMaterial({ map: state.videoTexture });
state.tvScreen.material.needsUpdate = true;
turnTvScreenOn();
// 3. Start playback
state.videoElement.play().then(() => {

View File

@ -136,12 +136,7 @@ export function createTvSet(x, z, rotY) {
// Position the curved screen
state.tvScreen.position.set(0.0, 1.5, -2.1);
state.tvScreen.material = new THREE.MeshPhongMaterial({
color: 0x0a0a0a, // Deep black
shininess: 5,
specular: 0x111111
});
state.tvScreen.material.needsUpdate = true;
turnTvScreenOff();
tvGroup.add(state.tvScreen);
tvGroup.position.set(x, 0, z);
@ -165,3 +160,29 @@ export function createTvSet(x, z, rotY) {
state.scene.add(tvGroup);
}
export function turnTvScreenOff() {
if (state.tvScreen.material) {
state.tvScreen.material.dispose();
}
state.tvScreen.material = new THREE.MeshPhongMaterial({
color: 0x203530,
shininess: 45,
specular: 0x111111,
});
state.tvScreen.material.needsUpdate = true;
}
export function turnTvScreenOn() {
if (state.tvScreen.material) {
state.tvScreen.material.dispose();
}
state.tvScreen.material = new THREE.MeshBasicMaterial({
color: 0xffffff,
map: state.videoTexture,
fog: false,
lightMapIntensity: 0,
reflectivity: 0
});
state.tvScreen.material.needsUpdate = true;
}