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

B
Brian Sipple 已提交
4 5 6 7
[![Latest NPM release][npm-badge]][npm-badge-url]
[![License][license-badge]][license-badge-url]
[![Dependencies][dependencies-badge]][dependencies-badge-url]
[![Dev Dependencies][devDependencies-badge]][devDependencies-badge-url]
M
Mugen87 已提交
8
[![Build Status](https://travis-ci.org/mrdoob/three.js.svg?branch=dev)](https://travis-ci.org/mrdoob/three.js)
B
Brian Sipple 已提交
9

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

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

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

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

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

M
Michael Herzog 已提交
32
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 已提交
33

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

M
r59  
Mr.doob 已提交
76
[releases](https://github.com/mrdoob/three.js/releases)
B
Brian Sipple 已提交
77 78 79 80 81 82 83 84 85 86


[npm-badge]: https://img.shields.io/npm/v/three.svg
[npm-badge-url]: https://www.npmjs.com/package/three
[license-badge]: https://img.shields.io/npm/l/three.svg
[license-badge-url]: ./LICENSE
[dependencies-badge]: https://img.shields.io/david/mrdoob/three.js.svg
[dependencies-badge-url]: https://david-dm.org/mrdoob/three.js
[devDependencies-badge]: https://img.shields.io/david/dev/mrdoob/three.js.svg
[devDependencies-badge-url]: https://david-dm.org/mrdoob/three.js#info=devDependencies