-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (38 loc) · 1.78 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
import * as THREE from './libs/three/three.module.js';
import { OrbitControls } from './libs/three/jsm/OrbitControls.js';
class App{
constructor(){
const container = document.createElement( 'div' );
document.body.appendChild( container );
this.camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 100 );
this.camera.position.set( 0, 0, 4 );
this.scene = new THREE.Scene();
this.scene.background = new THREE.Color( 0xaaaaaa );
const ambient = new THREE.HemisphereLight(0xffffff, 0xbbbbff, 0.3);
this.scene.add(ambient);
const light = new THREE.DirectionalLight();
light.position.set( 0.2, 1, 1);
this.scene.add(light);
this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true } );
this.renderer.setPixelRatio( window.devicePixelRatio );
this.renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( this.renderer.domElement );
const geometry = new THREE.BoxBufferGeometry();
const material = new THREE.MeshStandardMaterial( { color: 0xFF0000 });
this.mesh = new THREE.Mesh( geometry, material );
this.scene.add(this.mesh);
const controls = new OrbitControls( this.camera, this.renderer.domElement );
this.renderer.setAnimationLoop(this.render.bind(this));
window.addEventListener('resize', this.resize.bind(this) );
}
resize(){
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize( window.innerWidth, window.innerHeight );
}
render( ) {
this.mesh.rotateY( 0.01 );
this.renderer.render( this.scene, this.camera );
}
}
export { App };