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

8
[Examples](http://threejs.org/)[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

J
Janas Page 已提交
20
This code creates a scene, a camera, and a geometric cube, and it adds the cube to the scene. It then creates a &lt;canvas&gt; 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
```html
<script>
M
Mr.doob 已提交
24

J
Janas Page 已提交
25
	var scene, camera, renderer;
M
Mr.doob 已提交
26
	var geometry, material, mesh;
27

M
Mr.doob 已提交
28 29
	init();
	animate();
M
Mr.doob 已提交
30

M
Mr.doob 已提交
31
	function init() {
M
Mr.doob 已提交
32

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

M
Mr.doob 已提交
38
		geometry = new THREE.BoxGeometry( 200, 200, 200 );
M
Mr.doob 已提交
39 40
		material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
		mesh = new THREE.Mesh( geometry, material );
J
Janas Page 已提交
41
		
M
Mr.doob 已提交
42
		scene.add( mesh );
M
Mr.doob 已提交
43

M
Mr.doob 已提交
44 45
		renderer = new THREE.CanvasRenderer();
		renderer.setSize( window.innerWidth, window.innerHeight );
M
Mr.doob 已提交
46

M
Mr.doob 已提交
47
		document.body.appendChild( renderer.domElement );
M
Mr.doob 已提交
48

M
Mr.doob 已提交
49
	}
50

M
Mr.doob 已提交
51
	function animate() {
M
Mr.doob 已提交
52

M
r47  
Mr.doob 已提交
53
		// note: three.js includes requestAnimationFrame shim
M
Mr.doob 已提交
54
		requestAnimationFrame( animate );
M
Mr.doob 已提交
55

M
Mr.doob 已提交
56 57
		mesh.rotation.x += 0.01;
		mesh.rotation.y += 0.02;
M
Mr.doob 已提交
58

M
Mr.doob 已提交
59
		renderer.render( scene, camera );
M
Mr.doob 已提交
60

M
Mr.doob 已提交
61
	}
62

M
Mr.doob 已提交
63 64
</script>
```
M
Mr.doob 已提交
65
If everything went well you should see [this](http://jsfiddle.net/Gy4w7/).
66

M
Mr.doob 已提交
67
### Change log ###
68

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