README.md 3.2 KB
Newer Older
M
testing  
Mr.doob 已提交
1 2 3
three.js
========

M
Mr.doob 已提交
4
[![NPM package][npm]][npm-url]
5
[![Build Size][build-size]][build-size-url]
M
Mr.doob 已提交
6 7 8 9
[![Build Status][build-status]][build-status-url]
[![Dependencies][dependencies]][dependencies-url]
[![Dev Dependencies][dev-dependencies]][dev-dependencies-url]
[![Language Grade][lgtm]][lgtm-url]
B
Brian Sipple 已提交
10

M
Mr.doob 已提交
11
#### JavaScript 3D library ####
M
Mr.doob 已提交
12

P
Paul Masson 已提交
13
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.
14

15 16 17
[Examples](http://threejs.org/examples/) —
[Documentation](http://threejs.org/docs/) —
[Wiki](https://github.com/mrdoob/three.js/wiki) —
M
Michael Herzog 已提交
18
[Migrating](https://github.com/mrdoob/three.js/wiki/Migration-Guide) —
M
Mr.doob 已提交
19
[Questions](http://stackoverflow.com/questions/tagged/three.js) —
20 21 22
[Forum](https://discourse.threejs.org/) —
[Gitter](https://gitter.im/mrdoob/three.js) —
[Slack](https://threejs-slack.herokuapp.com/)
M
Mr.doob 已提交
23

M
Mr.doob 已提交
24
### Usage ###
M
Mr.doob 已提交
25

M
Michael Herzog 已提交
26
Download 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),
L
leewz 已提交
27
Alternatively see [how to build the library yourself](https://github.com/mrdoob/three.js/wiki/Build-instructions).
M
Mr.doob 已提交
28

M
Mr.doob 已提交
29
```html
30
<script src="js/three.min.js"></script>
M
Mr.doob 已提交
31
```
M
Mr.doob 已提交
32

M
Michael Herzog 已提交
33
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.
M
Mr.doob 已提交
34

M
Mr.doob 已提交
35
```javascript
M
Mr.doob 已提交
36
var camera, scene, renderer;
M
Mr.doob 已提交
37
var geometry, material, mesh;
38

M
Mr.doob 已提交
39 40
init();
animate();
M
Mr.doob 已提交
41

M
Mr.doob 已提交
42
function init() {
M
Mr.doob 已提交
43

M
Mr.doob 已提交
44 45
	camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
	camera.position.z = 1;
46

M
Mr.doob 已提交
47
	scene = new THREE.Scene();
48

M
Mr.doob 已提交
49 50
	geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
	material = new THREE.MeshNormalMaterial();
M
Mr.doob 已提交
51

M
Mr.doob 已提交
52 53
	mesh = new THREE.Mesh( geometry, material );
	scene.add( mesh );
M
Mr.doob 已提交
54

M
Mr.doob 已提交
55
	renderer = new THREE.WebGLRenderer( { antialias: true } );
M
Mr.doob 已提交
56 57
	renderer.setSize( window.innerWidth, window.innerHeight );
	document.body.appendChild( renderer.domElement );
58

M
Mr.doob 已提交
59
}
M
Mr.doob 已提交
60

M
Mr.doob 已提交
61
function animate() {
M
Mr.doob 已提交
62

M
Mr.doob 已提交
63
	requestAnimationFrame( animate );
M
Mr.doob 已提交
64

M
Mr.doob 已提交
65 66
	mesh.rotation.x += 0.01;
	mesh.rotation.y += 0.02;
M
Mr.doob 已提交
67

M
Mr.doob 已提交
68
	renderer.render( scene, camera );
69

M
Mr.doob 已提交
70
}
M
Mr.doob 已提交
71
```
M
Mr.doob 已提交
72

M
Mr.doob 已提交
73
If everything went well you should see [this](https://jsfiddle.net/f2Lommf5/).
74

M
Mr.doob 已提交
75
### Change log ###
76

Y
Yaroslav Khudchenko 已提交
77
[Releases](https://github.com/mrdoob/three.js/releases)
B
Brian Sipple 已提交
78 79


M
Mr.doob 已提交
80 81
[npm]: https://img.shields.io/npm/v/three.svg
[npm-url]: https://www.npmjs.com/package/three
82 83
[build-size]: https://badgen.net/bundlephobia/minzip/three
[build-size-url]: https://bundlephobia.com/result?p=three
M
Mr.doob 已提交
84 85 86 87 88 89 90 91
[build-status]: https://travis-ci.org/mrdoob/three.js.svg?branch=dev
[build-status-url]: https://travis-ci.org/mrdoob/three.js
[dependencies]: https://img.shields.io/david/mrdoob/three.js.svg
[dependencies-url]: https://david-dm.org/mrdoob/three.js
[dev-dependencies]: https://img.shields.io/david/dev/mrdoob/three.js.svg
[dev-dependencies-url]: https://david-dm.org/mrdoob/three.js#info=devDependencies
[lgtm]: https://img.shields.io/lgtm/grade/javascript/g/mrdoob/three.js.svg?label=code%20quality
[lgtm-url]: https://lgtm.com/projects/g/mrdoob/three.js/