-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (44 loc) · 1.58 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
// Variables
let container, camera, renderer, scene, house;
function init() {
container = document.querySelector('.scene');
//**********Create Scene*************//
// Camera
scene = new THREE.Scene();
const fov = 35;
const aspect = container.clientWidth / container.clientHeight;
const near = 0.1;
const far = 500;
camera = new THREE.PerspectiveCamera(fov,aspect,near,far);
camera.position.set(0, -5, 25);
const ambient = new THREE.AmbientLight(0x404040, 2);
scene.add(ambient);
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(10,10,10);
scene.add(light);
//Renderer
renderer = new THREE.WebGLRenderer({antialias:true, alpha:true});
renderer.setSize(container.clientWidth, container.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
// Load The Model
let loader = new THREE.GLTFLoader();
loader.load("scene.gltf", function(gltf){
scene.add(gltf.scene);
house = gltf.scene.children[0];
renderer.render(scene, camera);
});
}
function animate(){
requestAnimationFrame(animate);
house.rotation.z += 0.01;
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = container.clientWidth / container.clientHeight;
camera.updateProjectionMatrix();
renderer.setSize(container.clientWidth,container.clientHeight);
}
window.addEventListener('resize', onWindowResize);
init();
animate();