-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathanimation.js
61 lines (46 loc) · 1.82 KB
/
animation.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
// animation.js
var camera;
var scene;
var renderer;
var mesh;
function init(img) {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000);
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 1, 1 ).normalize();
scene.add(light);
var geometry = new THREE.CubeGeometry( 1, 10, 10);
var material = new THREE.MeshPhongMaterial( { map: THREE.ImageUtils.loadTexture(img) } );
var sidesMaterial = new THREE.MeshPhongMaterial( { ambient: 0x050505, color: 0x222222, specular: 0x555555, shininess: 5 } );
var materials = [material, material, sidesMaterial, sidesMaterial, sidesMaterial, sidesMaterial];
var meshFaceMaterial = new THREE.MeshFaceMaterial( materials );
mesh = new THREE.Mesh(geometry, meshFaceMaterial );
mesh.position.z = -20;
scene.add( mesh );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
render();
}
function animate() {
// mesh.rotation.x += .04;
mesh.rotation.y += .02;
render();
requestAnimationFrame( animate );
}
function render() {
renderer.render( scene, camera );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
render();
}
module.exports = {
init: init,
animate: animate,
render: render,
onWindowResize: onWindowResize
}