-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube.js
39 lines (39 loc) · 1.32 KB
/
cube.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
function cube()
{
var width = window.innerWidth *7/15;
var height = window.innerHeight *7/15;
var camera, scene, renderer;
var mesh;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, width / height, 1, 1000 );
camera.position.z = 400;
scene = new THREE.Scene();
var texture = new THREE.TextureLoader().load( 'marvel.jpg' );
var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
var material = new THREE.MeshBasicMaterial( { map: texture } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor(obj.color , 1.0);// Color of renderer
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( width, height );
document.body.appendChild( renderer.domElement );
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize( width , height );
}
function animate() {
requestAnimationFrame( animate );
renderer.setClearColor(obj.color,1.0);// Color of renderer
mesh.rotation.x += obj.Rotation_X;
mesh.rotation.y += obj.Rotation_Y;
mesh.rotation.z += obj.Rotation_Z;
renderer.render( scene, camera );
}
}