Initial commit
This commit is contained in:
57
js/scene.js
Normal file
57
js/scene.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import * as THREE from 'three';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
||||
import { setupLights, setupRoomLights } from './lights.js';
|
||||
import { camera } from './camera.js';
|
||||
|
||||
const canvas = document.getElementById('scene');
|
||||
|
||||
export const scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x222222);
|
||||
|
||||
export const renderer = new THREE.WebGLRenderer({
|
||||
canvas,
|
||||
antialias: true
|
||||
});
|
||||
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
renderer.setPixelRatio(window.devicePixelRatio);
|
||||
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 0.3;
|
||||
|
||||
// Свет
|
||||
setupLights(scene);
|
||||
|
||||
// ===== ROOM =====
|
||||
export let room = null; // Экспортируем для вращения
|
||||
const loader = new GLTFLoader();
|
||||
loader.load(
|
||||
'models/room.glb',
|
||||
(gltf) => {
|
||||
room = gltf.scene;
|
||||
|
||||
// Центрируем модель
|
||||
const box = new THREE.Box3().setFromObject(room);
|
||||
const center = box.getCenter(new THREE.Vector3());
|
||||
room.position.sub(center);
|
||||
|
||||
// Масштаб 1:1 так как модель уже в метрах
|
||||
room.scale.set(1, 1, 1);
|
||||
|
||||
// Инициализируем свет комнаты
|
||||
setupRoomLights(room);
|
||||
|
||||
scene.add(room);
|
||||
},
|
||||
undefined,
|
||||
(error) => {
|
||||
console.error('GLB LOAD ERROR', error);
|
||||
}
|
||||
);
|
||||
|
||||
// Resize
|
||||
window.addEventListener('resize', () => {
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
camera.aspect = window.innerWidth / window.innerHeight;
|
||||
camera.updateProjectionMatrix();
|
||||
});
|
||||
Reference in New Issue
Block a user