1 | three.js
|
2 | ========
|
3 |
|
4 | [![NPM Package][npm]][npm-url]
|
5 | [![Build Size][build-size]][build-size-url]
|
6 | [![NPM Downloads][npm-downloads]][npmtrends-url]
|
7 | [![Dev Dependencies][dev-dependencies]][dev-dependencies-url]
|
8 | [![Language Grade][lgtm]][lgtm-url]
|
9 |
|
10 | #### JavaScript 3D library ####
|
11 |
|
12 | The aim of the project is to create an easy to use, lightweight, 3D library with a default WebGL renderer. The library also provides Canvas 2D, SVG and CSS3D renderers in the examples.
|
13 |
|
14 | [Examples](http://threejs.org/examples/) —
|
15 | [Documentation](http://threejs.org/docs/) —
|
16 | [Wiki](https://github.com/mrdoob/three.js/wiki) —
|
17 | [Migrating](https://github.com/mrdoob/three.js/wiki/Migration-Guide) —
|
18 | [Questions](http://stackoverflow.com/questions/tagged/three.js) —
|
19 | [Forum](https://discourse.threejs.org/) —
|
20 | [Slack](https://join.slack.com/t/threejs/shared_invite/enQtMzYxMzczODM2OTgxLTQ1YmY4YTQxOTFjNDAzYmQ4NjU2YzRhNzliY2RiNDEyYjU2MjhhODgyYWQ5Y2MyZTU3MWNkOGVmOGRhOTQzYTk) —
|
21 | [Discord](https://discordapp.com/invite/HF4UdyF)
|
22 |
|
23 | ### Usage ###
|
24 |
|
25 | 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.
|
26 |
|
27 | ```javascript
|
28 | import * as THREE from 'js/three.module.js';
|
29 |
|
30 | var camera, scene, renderer;
|
31 | var geometry, material, mesh;
|
32 |
|
33 | init();
|
34 | animate();
|
35 |
|
36 | function init() {
|
37 |
|
38 | camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
|
39 | camera.position.z = 1;
|
40 |
|
41 | scene = new THREE.Scene();
|
42 |
|
43 | geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
|
44 | material = new THREE.MeshNormalMaterial();
|
45 |
|
46 | mesh = new THREE.Mesh( geometry, material );
|
47 | scene.add( mesh );
|
48 |
|
49 | renderer = new THREE.WebGLRenderer( { antialias: true } );
|
50 | renderer.setSize( window.innerWidth, window.innerHeight );
|
51 | document.body.appendChild( renderer.domElement );
|
52 |
|
53 | }
|
54 |
|
55 | function animate() {
|
56 |
|
57 | requestAnimationFrame( animate );
|
58 |
|
59 | mesh.rotation.x += 0.01;
|
60 | mesh.rotation.y += 0.02;
|
61 |
|
62 | renderer.render( scene, camera );
|
63 |
|
64 | }
|
65 | ```
|
66 |
|
67 | If everything went well, you should see [this](https://jsfiddle.net/8kubjpL5/).
|
68 |
|
69 | ### Cloning this repository ###
|
70 |
|
71 | Cloning the repo with all its history results in a ~2GB download. If you don't need the whole history you can use the `depth` parameter to significantly reduce download size.
|
72 |
|
73 | ```sh
|
74 | git clone --depth=1 https://github.com/mrdoob/three.js.git
|
75 | ```
|
76 |
|
77 | ### Change log ###
|
78 |
|
79 | [Releases](https://github.com/mrdoob/three.js/releases)
|
80 |
|
81 |
|
82 | [npm]: https://img.shields.io/npm/v/three
|
83 | [npm-url]: https://www.npmjs.com/package/three
|
84 | [build-size]: https://badgen.net/bundlephobia/minzip/three
|
85 | [build-size-url]: https://bundlephobia.com/result?p=three
|
86 | [npm-downloads]: https://img.shields.io/npm/dw/three
|
87 | [npmtrends-url]: https://www.npmtrends.com/three
|
88 | [dev-dependencies]: https://img.shields.io/david/dev/mrdoob/three.js
|
89 | [dev-dependencies-url]: https://david-dm.org/mrdoob/three.js#info=devDependencies
|
90 | [lgtm]: https://img.shields.io/lgtm/alerts/github/mrdoob/three.js
|
91 | [lgtm-url]: https://lgtm.com/projects/g/mrdoob/three.js/
|