-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (37 loc) · 1.37 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import './style.css'
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
let camera, scene, renderer, controls;
// Inicializar la cámara
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.25, 1000);
camera.position.set(30.5, 10.5, 10.0);
// Inicializar la escena
scene = new THREE.Scene();
// Cargar el mapa de entorno
const rgbeLoader = new RGBELoader();
rgbeLoader.load('/royal_esplanade_4k.hdr', function (texture) {
texture.mapping = THREE.EquirectangularReflectionMapping;
scene.background = texture;
scene.environment = texture;
} );
// Cargar el modelo GLTF
const gltfLoader = new GLTFLoader();
gltfLoader.load('/DamagedHelmet.glb', function (gltf) {
gltf.scene.scale.set(10.0, 10.0, 10.0);
scene.add(gltf.scene);
});
// Inicializar el renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Inicializar los controles OrbitControls
controls = new OrbitControls(camera, renderer.domElement);
// Función de animación
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
// Iniciar la animación
animate();