Three.js

JavaScript 3D Library.

README

three.js


JavaScript 3D library


The aim of the project is to create an easy to use, lightweight, cross-browser, general purpose 3D library. The current builds only include a WebGL renderer but WebGPU (experimental), SVG and CSS3D renderers are also available in the examples.

ExamplesDocsManualWikiMigratingQuestionsForumDiscord

Usage


This code creates a scene, a camera, and a geometric cube, and it adds the cube to the scene. It then creates a WebGL renderer for the scene and camera, and it adds that viewport to the document.body element. Finally, it animates the cube within the scene for the camera.

  1. ``` js
  2. import * as THREE from 'three';

  3. // init

  4. const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
  5. camera.position.z = 1;

  6. const scene = new THREE.Scene();

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

  9. const mesh = new THREE.Mesh( geometry, material );
  10. scene.add( mesh );

  11. const renderer = new THREE.WebGLRenderer( { antialias: true } );
  12. renderer.setSize( window.innerWidth, window.innerHeight );
  13. renderer.setAnimationLoop( animation );
  14. document.body.appendChild( renderer.domElement );

  15. // animation

  16. function animation( time ) {

  17. mesh.rotation.x = time / 2000;
  18. mesh.rotation.y = time / 1000;

  19. renderer.render( scene, camera );

  20. }
  21. ```

If everything went well, you should see this.

Cloning this repository


Cloning the repo with all its history results in a ~2 GB download. If you don't need the whole history you can use the depth parameter to significantly reduce download size.

  1. ```sh
  2. git clone --depth=1 https://github.com/mrdoob/three.js.git
  3. ```

Change log



[npm]: https://img.shields.io/npm/v/three
[npm-url]: https://www.npmjs.com/package/three
[build-size]: https://badgen.net/bundlephobia/minzip/three
[build-size-url]: https://bundlephobia.com/result?p=three
[npm-downloads]: https://img.shields.io/npm/dw/three
[npmtrends-url]: https://www.npmtrends.com/three
[deepscan]: https://deepscan.io/api/teams/16600/projects/19901/branches/525701/badge/grade.svg
[deepscan-url]: https://deepscan.io/dashboard#view=project&tid=16600&pid=19901&bid=525701
[discord]: https://img.shields.io/discord/685241246557667386
[discord-url]: https://discord.gg/56GBJwAnUS