Skip to content

Instantly share code, notes, and snippets.

@arisetyo
Created November 9, 2012 05:32
Show Gist options
  • Save arisetyo/4043918 to your computer and use it in GitHub Desktop.
Save arisetyo/4043918 to your computer and use it in GitHub Desktop.
Basic Three.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hello-three-js</title>
</head>
<body>
<script type='text/javascript' src='three.min.js'></script>
<script type='text/javascript'>
var camera, scene, renderer;
var geometry, material, mesh;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
scene = new THREE.Scene();
geometry = new THREE.CubeGeometry( 200, 200, 200 );
material = new THREE.MeshBasicMaterial( { color: 0xCC6600, wireframe: true } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
// note: three.js includes requestAnimationFrame shim
requestAnimationFrame( animate );
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render( scene, camera );
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment