Skip to content

Instantly share code, notes, and snippets.

@gilbox
Last active October 18, 2015 19:16
Show Gist options
  • Save gilbox/b39b31f536b45700b903 to your computer and use it in GitHub Desktop.
Save gilbox/b39b31f536b45700b903 to your computer and use it in GitHub Desktop.
three.js spinning cube
const renderer = new THREE.WebGLRenderer( {canvas: document.getElementById('canvas')} );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.autoClear = false;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
function render() {
requestAnimationFrame( render );
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render( scene, camera );
}
render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment