-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
79 lines (57 loc) · 2.04 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { OrbitControls } from 'https://threejs.org/examples/jsm/controls/OrbitControls.js';
let container;
let camera;
let renderer;
let scene;
let controls;
function init() {
container = document.querySelector('.scene');
//careating scene
scene = new THREE.Scene();
//setting up renderer
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(container.clientWidth, container.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
//setting up camera
const fov = 45;
const aspect = container.clientWidth / container.clientHeight;
const near = 0.1;
const far = 500
camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
//setting up controls
controls = new OrbitControls(camera, renderer.domElement);
controls.listenToKeyEvents(window);
controls.maxPolarAngle = Math.PI / 2;
controls.minDistance = 5;
controls.maxDistance = 5;
camera.position.set(3.0679134273082003, 1.9584414998616988, 3.4281794139399286);
//setting up lights
const dirLight1 = new THREE.DirectionalLight(0x002288, 30);
dirLight1.position.set(1, 1, 2);
scene.add(dirLight1);
const dirLight2 = new THREE.DirectionalLight(0xb81024, 30);
dirLight2.position.set(- 1, - 1, 2);
scene.add(dirLight2)
const ambientLight = new THREE.AmbientLight(0x404040, 10);
scene.add(ambientLight);
window.addEventListener('resize', onWindowResize);
//loading our model using gltf loader
let loader = new THREE.GLTFLoader();
loader.load('./3d_model/scene.gltf', function (gltf) {
scene.add(gltf.scene);
})
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
//animate function is used to render our object
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
init();
animate();