JavaScript API for rendering interactive 2D and 3D graphics
inside an HTML <canvas> element.
3D Javascript Library
Renderers: WebGL, <canvas>, <svg>, CSS3D / DOM, and more
Scenes, Cameras, Geometry, 3D Model Loaders, Lights, Materials,
Shaders, Particles, Animation, Math Utilities
<!DOCTYPE html>
<html>
<head>
<title>Basic Three.js App</title>
<style>
html, body { margin: 0; padding: 0; overflow: hidden; }
</style>
</head>
<body>
<script src="js/three.min.js"></script>
<script>
// Javascript will go here.
</script>
</body>
</html>
var scene = new THREE.Scene();
var aspect = window.innerWidth / window.innerHeight;
var camera = new THREE.PerspectiveCamera( 75, aspect, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshNormalMaterial();
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
var render = function () {
requestAnimationFrame( render );
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render( scene, camera );
};
render();
var group = new THREE.Group();
scene.add( group );
group.add( mesh1 );
group.add( mesh2 );
mesh2.visible = false;
group.remove( mesh2 );
group.children // mesh1
group.parent // scene
mesh.position.x = 0mesh.position.x = -100mesh.scale.set(2,2,2)mesh.rotation.y = Math.PI / 4mesh.rotation.y = Math.PI * 5 / 4

mesh.rotation.y = THREE.Math.degToRad(45);
mesh.position.x = Math.cos( time );
mesh.position.y = Math.sin( time );cam = new THREE.PerspectiveCamera( fov, aspect, near, far )cam = new THREE.PerspectiveCamera( fov, aspect, near, far )cam = new THREE.PerspectiveCamera( fov, aspect, near, far )camera.fov = 15camera.fov = 60camera.far = 1000camera.far = 3000camera = new THREE.OrthographicCamera( left, right, top, bottom, near, far );/three.js/examples/js/controls/OrbitControls.js
<script src="path/to/OrbitControls.js"></script>controls = new THREE.OrbitControls( camera ); function render() { requestAnimationFrame( render ); controls.update(); renderer.render( scene, camera ); }
controls.enablePan = false;
controls.enableZoom = false;
controls.enableRotate = false;
controls.minDistance
controls.maxDistance
controls.minPolarAngle
controls.maxPolarAngle
var geo = new THREE.BoxGeometry( width, height, depth );var geo = new THREE.SphereGeometry( 60, 24, 16 );var geo = new THREE.CylinderGeometry( ... );var geo = new THREE.TorusGeometry( ... );
var material = new THREE.MeshBasicMaterial({ ... });var material = new THREE.MeshLambertMaterial({ ... });var material = new THREE.MeshPhongMaterial({ ... });var material = new THREE.MeshNormalMaterial({ ... });var material = new THREE.MeshNormalMaterial({ ... });shading: THREE.SmoothShadingshading: THREE.FlatShadingshading: THREE.FlatShading // face normalsshading: THREE.FlatShading // face normalsshading: THREE.SmoothShading // vertex normalscolor: 0xaaaaaacolor: 0x3794cfshininess: 40shininess: 80wireframe: truetransparent: true, opacity: 0.5var loader = new THREE.TextureLoader();
var texture = loader.load("color-map.jpg");map: texturenormalMap: texturespecularMap: texturemap: colorMap, specularMap: specMap, normalMap: normalMapvar material = new THREE.MeshPhongMaterial({
color: 0xaaaaaa,
specular: 0x333333,
shininess: 15,
map: colorMap,
specularMap: specMap,
normalMap: normalMap
});
light = new THREE.DirectionalLight( 0xdddddd, 0.8 );light.position.set( -80, 80, 80 );light.position.x = 80;light.target.position = 160;light.position.x = -80;light = new THREE.DirectionalLight( 0xdddddd, 0.8 );light = new THREE.DirectionalLight( 0xb4e7f2, 0.8 );light = new THREE.DirectionalLight( 0xb4e7f2, 0.2 );light = new THREE.DirectionalLight( 0xb4e7f2, 1.5 );light = new THREE.DirectionalLight( 0xb4e7f2, 0.8 );light = new THREE.PointLight( 0xb4e7f2, 0.8 );light = new THREE.PointLight( 0xb4e7f2, 0.8 );light = new THREE.SpotLight( 0xb4e7f2, 0.8 );light.angle = Math.PI / 9;light.angle = Math.PI / 5;light.penumbra = 0.4;light.penumbra = 0;light.penumbra = 0.8;light = new THREE.AmbientLight( 0x444444 );light = new THREE.AmbientLight( 0x000000 );light = new THREE.AmbientLight( 0x444444 );OBJ to JSON converter python tool
/three.js/utils/converters/obj/convert_obj_three.py

python convert_obj_three.py -i teapot.obj -o teapot.jsvar loader = new THREE.JSONLoader();
loader.load("teapot.js", function( geometry, materials ) {
material = new THREE.MultiMaterial( materials );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
});
// normalized device coordinates
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster = new THREE.Raycaster();
var vector = new THREE.Vector3( mouse.x, mouse.y, 1 ).unproject( camera );
raycaster.set( camera.position, vector.sub( camera.position ).normalize() );
var intersects = raycaster.intersectObjects( scene.children );
INTERSECTED = intersects[ 0 ].object;
/