three.js

0.184.0 · active · verified Sun Apr 19

three.js is a powerful, lightweight, cross-browser JavaScript library for creating and displaying animated 3D graphics in a web browser using WebGL, WebGPU, and other renderers. It abstracts away the complexities of low-level graphics APIs, providing a high-level scene graph, cameras, lights, materials, and geometries. The library is actively maintained with frequent minor releases (currently at 0.184.0), typically on a monthly cadence, focusing on performance, new features, and the removal of deprecated APIs. Its key differentiators include a vast ecosystem of examples, extensive documentation, and a strong community, making it a go-to choice for interactive 3D web experiences, virtual reality, and augmented reality applications.

Common errors

Warnings

Install

Imports

Quickstart

This code initializes a basic 3D scene with a rotating cube, a perspective camera, and a WebGL renderer, animating it in the browser.

import * as THREE from 'three';

const width = window.innerWidth, height = window.innerHeight;

// init

const camera = new THREE.PerspectiveCamera( 70, width / height, 0.01, 10 );
camera.position.z = 1;

const scene = new THREE.Scene();

const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshNormalMaterial();

const mesh = new THREE.Mesh( geometry, material );
sce.add( mesh );

const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( width, height );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

// animation

function animate( time ) {
	mesh.rotation.x = time / 2000;
	mesh.rotation.y = time / 1000;

	renderer.render( scene, camera );
}

view raw JSON →