From 1c8eb8534e85d5c42693c114116dd320c053615e Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sat, 22 Nov 2025 10:03:51 +0100 Subject: [PATCH] Feature: spotlight from main window --- party-cathedral/src/core/init.js | 11 ---- party-cathedral/src/scene/root.js | 8 +++ .../src/scene/rose-window-light.js | 66 +++++++++++++++++++ 3 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 party-cathedral/src/scene/rose-window-light.js diff --git a/party-cathedral/src/core/init.js b/party-cathedral/src/core/init.js index d8a626d..805ece1 100644 --- a/party-cathedral/src/core/init.js +++ b/party-cathedral/src/core/init.js @@ -33,17 +33,6 @@ export function init() { // 6. Initialize all visual effects via the manager state.effectsManager = new EffectsManager(state.scene); - - // --- 8. Debug Visualization Helpers --- - // Visual aids for the light source positions - if (state.debugLight && THREE.PointLightHelper) { - const screenHelper = new THREE.PointLightHelper(state.screenLight, 0.1, 0xff0000); // Red for screen - state.scene.add(screenHelper); - - // Lamp Helper will now work since lampLight is added to the scene - const lampHelperPoint = new THREE.PointLightHelper(state.lampLightPoint, 0.1, 0x00ff00); // Green for lamp - state.scene.add(lampHelperPoint); - } // 9. Event Listeners window.addEventListener('resize', onWindowResize, false); diff --git a/party-cathedral/src/scene/root.js b/party-cathedral/src/scene/root.js index feeaead..7bfa700 100644 --- a/party-cathedral/src/scene/root.js +++ b/party-cathedral/src/scene/root.js @@ -12,6 +12,7 @@ import { PartyGuests } from './party-guests.js'; import { StageTorches } from './stage-torches.js'; import { Dancers } from './dancers.js'; import { MusicVisualizer } from './music-visualizer.js'; +import { RoseWindowLight } from './rose-window-light.js'; // Scene Features ^^^ // --- Scene Modeling Function --- @@ -42,5 +43,12 @@ export function createSceneObjects() { // Add a HemisphereLight for more natural, general illumination in a large space. const hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.2); + // Visual aids for the light source positions + if (state.debugLight && THREE.HemisphereLightHelper) { + // Lamp Helper will now work since lampLight is added to the scene + const hemisphereLightHelper = new THREE.HemisphereLightHelper(hemisphereLight, 0.1, 0x00ff00); // Green for lamp + state.scene.add(hemisphereLightHelper); + } + state.scene.add(hemisphereLight); } diff --git a/party-cathedral/src/scene/rose-window-light.js b/party-cathedral/src/scene/rose-window-light.js new file mode 100644 index 0000000..e7f21e4 --- /dev/null +++ b/party-cathedral/src/scene/rose-window-light.js @@ -0,0 +1,66 @@ +import * as THREE from 'three'; +import { state } from '../state.js'; +import { SceneFeature } from './SceneFeature.js'; +import sceneFeatureManager from './SceneFeatureManager.js'; + +export class RoseWindowLight extends SceneFeature { + constructor() { + super(); + this.spotlight = null; + this.helper = null; + sceneFeatureManager.register(this); + } + + init() { + // --- Dimensions for positioning --- + const length = 40; + const naveHeight = 15; + const stageDepth = 5; + + // --- Create the spotlight --- + this.spotlight = new THREE.SpotLight(0xffffff, 100.0); // White light, high intensity + this.spotlight.position.set(0, naveHeight, -length / 2 + 10); // Position it at the rose window + this.spotlight.angle = Math.PI / 9; // A reasonably focused beam + this.spotlight.penumbra = 0.3; // Soft edges + this.spotlight.decay = 0.9; + this.spotlight.distance = 30; + + this.spotlight.castShadow = false; + this.spotlight.shadow.mapSize.width = 1024; + this.spotlight.shadow.mapSize.height = 1024; + this.spotlight.shadow.camera.near = 1; + this.spotlight.shadow.camera.far = 30; + this.spotlight.shadow.focus = 1; + + // --- Create a target for the spotlight to aim at --- + const targetObject = new THREE.Object3D(); + targetObject.position.set(0, 0, -length / 2 + stageDepth); // Aim at the center of the stage + state.scene.add(targetObject); + this.spotlight.target = targetObject; + + state.scene.add(this.spotlight); + + // --- Add a debug helper --- + if (state.debugLight) { + this.helper = new THREE.SpotLightHelper(this.spotlight); + state.scene.add(this.helper); + } + } + + update(deltaTime) { + if (!this.spotlight) return; + + // Make the light pulse with the music + if (state.music) { + const baseIntensity = 4.0; + this.spotlight.intensity = baseIntensity + state.music.beatIntensity * 1.0; + } + + // Update the helper if it exists + if (this.helper) { + this.helper.update(); + } + } +} + +new RoseWindowLight(); \ No newline at end of file