Files
Room-3D/js/lights.js
2026-01-08 19:59:09 +03:00

75 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import * as THREE from 'three';
/**
* Базовый свет сцены (Ambient + Directional)
*/
export function setupLights(scene) {
const ambient = new THREE.AmbientLight(0xffffff, 1.4);
scene.add(ambient);
const key = new THREE.DirectionalLight(0xffffff, 0.8);
key.position.set(5, 6, 4);
scene.add(key);
const fill = new THREE.DirectionalLight(0xffffff, 0.2);
fill.position.set(-5, 3, -4);
scene.add(fill);
}
/**
* Потолочные споты, привязанные к Spot_*
*/
export function setupRoomLights(room) {
const spotNames = [
'Spot_001','Spot_002','Spot_003','Spot_004',
'Spot_005','Spot_006','Spot_007','Spot_008'
];
spotNames.forEach((spotName) => {
const spotObject = room.getObjectByName(spotName);
if (!spotObject) {
console.warn(`Объект не найден: ${spotName}`);
return;
}
// === СПОТ-СВЕТ ===
const spotLight = new THREE.SpotLight(
0xffffff,
5, // intensity
80, // distance
Math.PI / 4, // angle
0.5, // penumbra
2 // decay (физически корректный)
);
spotObject.add(spotLight);
spotLight.position.set(0, 0, 0);
// === Target (локально по -Z) ===
spotObject.add(spotLight.target);
spotLight.target.position.set(0, 0, -1);
spotLight.target.updateMatrixWorld(true);
// === ВИЗУАЛЬНЫЙ СВЕТЯЩИЙСЯ КРУГ (LED-линза) ===
const bulb = new THREE.Mesh(
new THREE.CircleGeometry(0.01, 24),
new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0xffffff,
emissiveIntensity: 2.5,
roughness: 0.2,
metalness: 0.0,
side: THREE.DoubleSide
})
);
// CircleGeometry смотрит по +Z → поворачиваем вниз
bulb.rotation.x = -Math.PI;
bulb.position.set(0, 0, -0.005);
spotObject.add(bulb);
console.log(`Спот корректно создан: ${spotName}`);
});
}