Three.js, a Javascript 3D Engine

Three.js by MrDoob (AKA Ricardo Cabello) is a Javascript rendering engine and library that allows you to work in 3D. It can render to the typical 2D <canvas>, the new WebGL 3D <canvas>, and <svg>. You will need a modern, webGL capable browser to view these demos and use this library.



WebGL (Context 3D)


Canvas (Context 2D)


Usage


Download the minified library and include it in your html.


<script src="js/Three.js"></script>

This code creates a camera, then creates a scene, adds a cube on it, creates a <canvas> renderer and adds its viewport in the document.body element.


<script>

var camera, scene, renderer,
geometry, material, mesh;

init();
animate();

function init() {

camera = new THREE.Camera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;

scene = new THREE.Scene();

geometry = new THREE.Cube( 200, 200, 200 );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );

mesh = new THREE.Mesh( geometry, material );
scene.addObject( mesh );

renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );

document.body.appendChild( renderer.domElement );

}

function animate() {

// Include examples/js/RequestAnimationFrame.js for cross-browser compatibility.
requestAnimationFrame( animate );
render();

}

function render() {

mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;

renderer.render( scene, camera );

}

</script>

Check out the source repo on Github : https://github.com/mrdoob/three.js/