Files
Room-3D/js/lights.js
2026-01-08 16:37:17 +03:00

60 lines
1.6 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.3);
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, 80, Math.PI/4, 0.5, 1);
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);
// === ВИЗУАЛЬНАЯ ТОЧКА ИСТОЧНИКА (сфера) ===
const bulb = new THREE.Mesh(
new THREE.SphereGeometry(0.02, 12, 12),
new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0xffffff,
emissiveIntensity: 2
})
);
bulb.position.set(0, 0, 0);
spotObject.add(bulb);
console.log(`Спот корректно создан: ${spotName}`);
});
}