UNPKG

3.07 kBMarkdownView Raw
1three.js
2========
3
4[![Latest NPM release][npm-badge]][npm-badge-url]
5[![License][license-badge]][license-badge-url]
6[![Dependencies][dependencies-badge]][dependencies-badge-url]
7[![Dev Dependencies][devDependencies-badge]][devDependencies-badge-url]
8[![Build Status](https://travis-ci.org/mrdoob/three.js.svg?branch=dev)](https://travis-ci.org/mrdoob/three.js)
9
10#### JavaScript 3D library ####
11
12The aim of the project is to create an easy to use, lightweight, 3D library. The library provides <canvas>, <svg>, CSS3D and WebGL renderers.
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[Gitter](https://gitter.im/mrdoob/three.js) —
21[Slack](https://threejs-slack.herokuapp.com/)
22
23### Usage ###
24
25Download the [minified library](http://threejs.org/build/three.min.js) and include it in your HTML, or install and import it as a [module](http://threejs.org/docs/#manual/introduction/Import-via-modules),
26Alternatively see [how to build the library yourself](https://github.com/mrdoob/three.js/wiki/Build-instructions).
27
28```html
29<script src="js/three.min.js"></script>
30```
31
32This 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.
33
34```javascript
35var camera, scene, renderer;
36var geometry, material, mesh;
37
38init();
39animate();
40
41function init() {
42
43 camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
44 camera.position.z = 1;
45
46 scene = new THREE.Scene();
47
48 geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
49 material = new THREE.MeshNormalMaterial();
50
51 mesh = new THREE.Mesh( geometry, material );
52 scene.add( mesh );
53
54 renderer = new THREE.WebGLRenderer( { antialias: true } );
55 renderer.setSize( window.innerWidth, window.innerHeight );
56 document.body.appendChild( renderer.domElement );
57
58}
59
60function animate() {
61
62 requestAnimationFrame( animate );
63
64 mesh.rotation.x += 0.01;
65 mesh.rotation.y += 0.02;
66
67 renderer.render( scene, camera );
68
69}
70```
71
72If everything went well you should see [this](https://jsfiddle.net/f2Lommf5/).
73
74### Change log ###
75
76[releases](https://github.com/mrdoob/three.js/releases)
77
78
79[npm-badge]: https://img.shields.io/npm/v/three.svg
80[npm-badge-url]: https://www.npmjs.com/package/three
81[license-badge]: https://img.shields.io/npm/l/three.svg
82[license-badge-url]: ./LICENSE
83[dependencies-badge]: https://img.shields.io/david/mrdoob/three.js.svg
84[dependencies-badge-url]: https://david-dm.org/mrdoob/three.js
85[devDependencies-badge]: https://img.shields.io/david/dev/mrdoob/three.js.svg
86[devDependencies-badge-url]: https://david-dm.org/mrdoob/three.js#info=devDependencies