From bc961119b6066083748427577304bc1d8547381e Mon Sep 17 00:00:00 2001 From: Dejvino Date: Fri, 21 Nov 2025 19:39:37 +0100 Subject: [PATCH] Refactor: SceneFeature+Manager --- party-cathedral/src/core/animate.js | 3 ++ party-cathedral/src/scene/SceneFeature.js | 6 ++++ .../src/scene/SceneFeatureManager.js | 31 +++++++++++++++++++ party-cathedral/src/scene/room-walls.js | 30 ++++++++++++------ party-cathedral/src/scene/root.js | 8 +++-- 5 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 party-cathedral/src/scene/SceneFeature.js create mode 100644 party-cathedral/src/scene/SceneFeatureManager.js diff --git a/party-cathedral/src/core/animate.js b/party-cathedral/src/core/animate.js index 8b8ce16..f08300d 100644 --- a/party-cathedral/src/core/animate.js +++ b/party-cathedral/src/core/animate.js @@ -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(); diff --git a/party-cathedral/src/scene/SceneFeature.js b/party-cathedral/src/scene/SceneFeature.js new file mode 100644 index 0000000..5a2fc3e --- /dev/null +++ b/party-cathedral/src/scene/SceneFeature.js @@ -0,0 +1,6 @@ +// SceneFeature.js + +export class SceneFeature { + init() {} + update(deltaTime) {} +} \ No newline at end of file diff --git a/party-cathedral/src/scene/SceneFeatureManager.js b/party-cathedral/src/scene/SceneFeatureManager.js new file mode 100644 index 0000000..6704d10 --- /dev/null +++ b/party-cathedral/src/scene/SceneFeatureManager.js @@ -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; \ No newline at end of file diff --git a/party-cathedral/src/scene/room-walls.js b/party-cathedral/src/scene/room-walls.js index abe2d0d..6d79b6e 100644 --- a/party-cathedral/src/scene/room-walls.js +++ b/party-cathedral/src/scene/room-walls.js @@ -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(); diff --git a/party-cathedral/src/scene/root.js b/party-cathedral/src/scene/root.js index 241d102..d9863ed 100644 --- a/party-cathedral/src/scene/root.js +++ b/party-cathedral/src/scene/root.js @@ -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); }