Feature: door outside is glowing red

This commit is contained in:
Dejvino 2025-11-16 15:59:23 +01:00
parent 6d54f4b15a
commit 6e2a59ce77

View File

@ -2,6 +2,9 @@ import * as THREE from 'three';
import { state } from '../state.js';
let doorGroupPanel;
let outsideMaterial; // Declare outsideMaterial globally
let glowIntensity = 0.0;
let glowDirection = 1; // 1 for increasing, -1 for decreasing
const DOOR_STATES = {
RESTING: 'resting',
@ -36,7 +39,7 @@ export function createDoor(x, z, rotY) {
doorGroup.add(frameRight);
// Outside darkness
const outsideMaterial = new THREE.MeshBasicMaterial({ color: 0x150505, shininess: 50 });
outsideMaterial = new THREE.MeshPhongMaterial({ color: 0x150505, emissive: 0x000000, shininess: 50 });
const outside = new THREE.Mesh(new THREE.BoxGeometry(doorWidth, 2.2, 0.04), outsideMaterial);
outside.position.set(0, 0, 0);
doorGroup.add(outside);
@ -76,13 +79,13 @@ export function updateDoor() {
const nextState = Math.random();
if (nextState < 0.4) {
doorState = DOOR_STATES.RESTING;
stateTimer = 5 + Math.random() * 5;
stateTimer = 2 + Math.random() * 5;
} else if (nextState < 0.7) {
doorState = DOOR_STATES.OPENING;
stateTimer = 2 + Math.random() * 3; // Open for 2-5 seconds
stateTimer = 2 + Math.random() * 4;
} else {
doorState = DOOR_STATES.CLOSING;
stateTimer = 2 + Math.random() * 3; // Close for 2-5 seconds
stateTimer = 3 + Math.random() * 3;
}
}
@ -98,4 +101,20 @@ export function updateDoor() {
}
break;
}
// Outside material pulsating glow
if (outsideMaterial) {
const glowMin = 0.001;
const glowMax = 0.01;
const glowSpeed = 0.0001; // Speed of the pulsation
glowIntensity += glowDirection * glowSpeed;
if (glowIntensity >= glowMax) {
glowIntensity = glowMax;
glowDirection = -1;
} else if (glowIntensity <= glowMin) {
glowIntensity = glowMin;
glowDirection = 1;
}
outsideMaterial.emissive.setRGB(glowIntensity, 0, 0);
}
}