Feature: more colored light balls

This commit is contained in:
Dejvino 2025-11-21 22:16:30 +01:00
parent a4e48d1d5a
commit 2811fdbbd8

View File

@ -3,58 +3,70 @@ import { state } from '../state.js';
import { SceneFeature } from './SceneFeature.js'; import { SceneFeature } from './SceneFeature.js';
import sceneFeatureManager from './SceneFeatureManager.js'; import sceneFeatureManager from './SceneFeatureManager.js';
// --- Dimensions from room-walls.js for positioning ---
const naveWidth = 12;
const naveHeight = 15;
const length = 40;
export class LightBall extends SceneFeature { export class LightBall extends SceneFeature {
constructor() { constructor() {
super(); super();
this.ball = null; this.lightBalls = [];
this.light = null;
sceneFeatureManager.register(this); sceneFeatureManager.register(this);
} }
init() { init() {
// --- Dimensions from room-walls.js for positioning ---
const naveWidth = 12;
const naveHeight = 15;
const length = 40;
// --- Ball Properties --- // --- Ball Properties ---
const ballRadius = 1.0; const ballRadius = 0.4;
const ballColor = 0xffffff; // White light const lightIntensity = 5.0;
const lightIntensity = 6.0; const lightColors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0x558800]; // Red, Green, Blue, Yellow
// --- Create the Ball --- lightColors.forEach(color => {
const ballGeometry = new THREE.SphereGeometry(ballRadius, 32, 32); // --- Create the Ball ---
const ballMaterial = new THREE.MeshBasicMaterial({ color: ballColor, emissive: ballColor, emissiveIntensity: 1.0 }); const ballGeometry = new THREE.SphereGeometry(ballRadius, 32, 32);
this.ball = new THREE.Mesh(ballGeometry, ballMaterial); const ballMaterial = new THREE.MeshBasicMaterial({ color: color, emissive: color, emissiveIntensity: 1.0 });
this.ball.castShadow = false; const ball = new THREE.Mesh(ballGeometry, ballMaterial);
this.ball.receiveShadow = false; ball.castShadow = false;
ball.receiveShadow = false;
// --- Create the Light --- // --- Create the Light ---
this.light = new THREE.PointLight(ballColor, lightIntensity, length / 2); // Adjust range to cathedral size const light = new THREE.PointLight(color, lightIntensity, length / 1.5);
this.light.castShadow = true; light.castShadow = true;
this.light.shadow.mapSize.width = 512; light.shadow.mapSize.width = 512;
this.light.shadow.mapSize.height = 512; light.shadow.mapSize.height = 512;
this.light.shadow.camera.near = 0.1; light.shadow.camera.near = 0.1;
this.light.shadow.camera.far = length / 2; light.shadow.camera.far = length / 2;
// --- Initial Position --- // --- Initial Position ---
this.ball.position.set(0, naveHeight * 0.7, 0); // Near the ceiling ball.position.set(
this.light.position.copy(this.ball.position); (Math.random() - 0.5) * naveWidth,
naveHeight * 0.6 + Math.random() * 4,
(Math.random() - 0.5) * length * 0.8
);
light.position.copy(ball.position);
state.scene.add(this.ball); state.scene.add(ball);
state.scene.add(this.light); state.scene.add(light);
this.lightBalls.push({
mesh: ball,
light: light,
driftSpeed: 0.2 + Math.random() * 0.2,
driftAmplitude: 4.0 + Math.random() * 4.0,
offset: Math.random() * Math.PI * 6,
});
});
} }
update(deltaTime) { update(deltaTime) {
// --- Animate the Ball ---
const time = state.clock.getElapsedTime(); const time = state.clock.getElapsedTime();
const driftSpeed = 0.5; this.lightBalls.forEach(lb => {
const driftAmplitude = 10.0; const { mesh, light, driftSpeed, offset } = lb;
mesh.position.x = Math.sin(time * driftSpeed + offset) * naveWidth/2 * 0.8;
this.ball.position.x = Math.sin(time * driftSpeed) * driftAmplitude; mesh.position.y = 10 + Math.cos(time * driftSpeed * 1.3 + offset) * naveHeight/2 * 0.6;
this.ball.position.y = 10 + Math.cos(time * driftSpeed * 1.3) * driftAmplitude * 0.5; // bobbing mesh.position.z = Math.cos(time * driftSpeed * 0.7 + offset) * length/2 * 0.8;
this.ball.position.z = Math.cos(time * driftSpeed * 0.7) * driftAmplitude; light.position.copy(mesh.position);
this.light.position.copy(this.ball.position); });
} }
} }