Skip to content

Instantly share code, notes, and snippets.

@anthonybrown
Created June 8, 2012 01:36
Show Gist options
  • Save anthonybrown/2892884 to your computer and use it in GitHub Desktop.
Save anthonybrown/2892884 to your computer and use it in GitHub Desktop.
HTML5 Canvas WebGL Plane with Three.js (simplified)
<script src="http://www.html5canvastutorials.com/libraries/Three.js"></script>
<script>
// RequestAnimationFrame shim
window.requestAnimFrame = ( function( callback ) {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function ( callback ) {
window.setTimeout( callback, 1000 / 60 );
};
})();
// scene
var scene = new THREE.Scene();
// camera
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0, - 450, 400 );
camera.rotation.x = 45 * ( Math.PI / 180 );
scene.add( camera );
// plane
var geometry = new THREE.PlaneGeometry( 300, 300 );
var material = new THREE.MeshBasicMaterial( { color: 0x0000ff } );
var mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
// renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
animate();
function animate() {
requestAnimFrame( animate );
render();
}
function render() {
plane.rotation.z = Date.now() / 1000;
renderer.render( scene, camera );
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment