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

M
Mr.doob 已提交
4
#### JavaScript 3D library ####
M
Mr.doob 已提交
5

M
Mr.doob 已提交
6
The aim of the project is to create a lightweight 3D library with a very low level of complexity — in other words, for dummies. The library provides <canvas>, <svg>, CSS3D and WebGL renderers.
7

M
Mr.doob 已提交
8
[Examples](http://threejs.org/examples/)[Documentation](http://threejs.org/docs/)[Migrating](https://github.com/mrdoob/three.js/wiki/Migration)[Help](http://stackoverflow.com/questions/tagged/three.js)
M
Mr.doob 已提交
9

M
Mr.doob 已提交
10

M
Mr.doob 已提交
11
### Usage ###
M
Mr.doob 已提交
12

13 14
Download the [minified library](http://threejs.org/build/three.min.js) and include it in your html.
Alternatively see [how to build the library yourself](https://github.com/mrdoob/three.js/wiki/build.py,-or-how-to-generate-a-compressed-Three.js-file).
M
Mr.doob 已提交
15

M
Mr.doob 已提交
16
```html
17
<script src="js/three.min.js"></script>
M
Mr.doob 已提交
18
```
M
Mr.doob 已提交
19

S
sole 已提交
20
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 已提交
21

M
Mr.doob 已提交
22 23 24
```javascript
var scene, camera, renderer;
var geometry, material, mesh;
25

M
Mr.doob 已提交
26 27
init();
animate();
M
Mr.doob 已提交
28

M
Mr.doob 已提交
29
function init() {
M
Mr.doob 已提交
30

M
Mr.doob 已提交
31
	scene = new THREE.Scene();
32

M
Mr.doob 已提交
33 34
	camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
	camera.position.z = 1000;
35

M
Mr.doob 已提交
36 37
	geometry = new THREE.BoxGeometry( 200, 200, 200 );
	material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
M
Mr.doob 已提交
38

M
Mr.doob 已提交
39 40
	mesh = new THREE.Mesh( geometry, material );
	scene.add( mesh );
M
Mr.doob 已提交
41

M
Mr.doob 已提交
42 43
	renderer = new THREE.WebGLRenderer();
	renderer.setSize( window.innerWidth, window.innerHeight );
M
Mr.doob 已提交
44

M
Mr.doob 已提交
45
	document.body.appendChild( renderer.domElement );
46

M
Mr.doob 已提交
47
}
M
Mr.doob 已提交
48

M
Mr.doob 已提交
49
function animate() {
M
Mr.doob 已提交
50

M
Mr.doob 已提交
51
	requestAnimationFrame( animate );
M
Mr.doob 已提交
52

M
Mr.doob 已提交
53 54
	mesh.rotation.x += 0.01;
	mesh.rotation.y += 0.02;
M
Mr.doob 已提交
55

M
Mr.doob 已提交
56
	renderer.render( scene, camera );
57

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

M
Mr.doob 已提交
61
If everything went well you should see [this](http://jsfiddle.net/hfj7gm6t/).
62

M
Mr.doob 已提交
63
### Change log ###
64

M
r59  
Mr.doob 已提交
65
[releases](https://github.com/mrdoob/three.js/releases)