Refactor: SceneFeature+Manager

This commit is contained in:
Dejvino 2025-11-21 19:39:37 +01:00
parent 1d4e428bf9
commit bc961119b6
5 changed files with 66 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import * as THREE from 'three';
import { state } from '../state.js';
import { updateScreenEffect } from '../scene/magic-mirror.js'
import sceneFeatureManager from '../scene/SceneFeatureManager.js';
function updateCamera() {
const globalTime = Date.now() * 0.0001;
@ -69,6 +70,8 @@ function updateVideo() {
export function animate() {
requestAnimationFrame(animate);
const deltaTime = 1;
sceneFeatureManager.update(deltaTime);
state.effectsManager.update();
updateCamera();
updateScreenLight();

View File

@ -0,0 +1,6 @@
// SceneFeature.js
export class SceneFeature {
init() {}
update(deltaTime) {}
}

View File

@ -0,0 +1,31 @@
// SceneFeatureManager.js
class SceneFeatureManager {
constructor() {
if (SceneFeatureManager.instance) {
return SceneFeatureManager.instance;
}
this.features = [];
SceneFeatureManager.instance = this;
}
register(feature) {
this.features.push(feature);
}
init() {
for (const feature of this.features) {
feature.init();
}
}
update(deltaTime) {
for (const feature of this.features) {
feature.update(deltaTime);
}
}
}
const sceneFeatureManager = new SceneFeatureManager();
export default sceneFeatureManager;

View File

@ -1,10 +1,16 @@
import * as THREE from 'three';
import { state } from '../state.js';
import wallTextureUrl from '/textures/stone_wall.png';
import sceneFeatureManager from './SceneFeatureManager.js';
import { SceneFeature } from './SceneFeature.js';
const length = 40;
export function createRoomWalls() {
// --- Cathedral Dimensions ---
const length = 40;
export class RoomWalls extends SceneFeature {
constructor() {
super();
sceneFeatureManager.register(this);
}
init() {
const naveWidth = 12;
const aisleWidth = 6;
const totalWidth = naveWidth + 2 * aisleWidth;
@ -80,7 +86,7 @@ export function createRoomWalls() {
for (let i = 0; i <= numPillars; i++) {
const z = -length / 2 + pillarSpacing * (i + 0.5);
// Add wall sections between pillars
if (i < numPillars) {
if (i <= numPillars) {
createMesh(arcadeWallGeo, arcadeWallMat, new THREE.Vector3(-naveWidth / 2, pillarHeight + arcadeWallHeight / 2, z));
createMesh(arcadeWallGeo, arcadeWallMat, new THREE.Vector3(naveWidth / 2, pillarHeight + arcadeWallHeight / 2, z));
}
@ -88,9 +94,9 @@ export function createRoomWalls() {
const pillarZ = -length / 2 + pillarSpacing * (i + 1) - pillarSize / 2;
// Left side pillars
createMesh(pillarGeo, wallMaterial, new THREE.Vector3(-naveWidth / 2 - pillarSize, pillarHeight / 2, pillarZ));
// Right side pillars
// Right side pillars
createMesh(pillarGeo, wallMaterial, new THREE.Vector3(naveWidth / 2 + pillarSize, pillarHeight / 2, pillarZ));
}
}
// 5. Clerestory (Upper Nave Walls)
const clerestoryHeight = naveHeight - aisleHeight;
@ -98,8 +104,8 @@ export function createRoomWalls() {
const clerestoryMat = wallMaterial.clone();
clerestoryMat.map = wallTexture.clone();
clerestoryMat.map.repeat.set(length / 4, clerestoryHeight / 4);
// Left and Right Clerestory walls
createMesh(clerestoryGeo, clerestoryMat, new THREE.Vector3(-naveWidth / 2, aisleHeight + clerestoryHeight / 2, 0), new THREE.Euler(0, -Math.PI/2, 0));
// Left and Right Clerestory walls
createMesh(clerestoryGeo, clerestoryMat, new THREE.Vector3(-naveWidth / 2, aisleHeight + clerestoryHeight / 2, 0), new THREE.Euler(0, - Math.PI / 2, 0));
createMesh(clerestoryGeo, clerestoryMat, new THREE.Vector3(naveWidth / 2, aisleHeight + clerestoryHeight / 2, 0), new THREE.Euler(0, Math.PI/2, 0));
// Upper part of the back wall (for the nave)
@ -138,5 +144,11 @@ export function createRoomWalls() {
gableMat.map.repeat.set(naveWidth / 8, roofPeakHeight / 8);
createMesh(gableGeo, gableMat, new THREE.Vector3(0, 0, -length / 2));
// Note: crawlSurfaces and landingSurfaces might need to be updated if spiders/rats are used.
// Note: crawlSurfaces and landingSurfaces might need to be updated if spiders/rats are used.
}
update(deltaTime) {
// Add any per-frame update logic here, if needed
}
}
new RoomWalls();

View File

@ -1,10 +1,13 @@
import * as THREE from 'three';
import { state } from '../state.js';
import { createRoomWalls } from './room-walls.js';
import floorTextureUrl from '/textures/stone_floor.png';
import sceneFeatureManager from './SceneFeatureManager.js';
import { RoomWalls } from './room-walls.js';
// --- Scene Modeling Function ---
export function createSceneObjects() {
sceneFeatureManager.init();
// --- Materials (MeshPhongMaterial) ---
// --- 1. Floor --- (Resized to match the new cathedral dimensions)
@ -22,13 +25,12 @@ export function createSceneObjects() {
floor.receiveShadow = true;
state.scene.add(floor);
createRoomWalls(); // This will need to be updated to create cathedral walls.
// 3. Lighting (Minimal and focused)
const ambientLight = new THREE.AmbientLight(0x606060, 1.5); // Increased ambient light for a larger space
state.scene.add(ambientLight);
// Add a HemisphereLight for more natural, general illumination in a large space.
const hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.7);
state.scene.add(hemisphereLight);
}