README.md 2.8 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
[![NPM Downloads][npm-downloads]][npmtrends-url]
M
Mr.doob 已提交
7 8
[![Dev Dependencies][dev-dependencies]][dev-dependencies-url]
[![Language Grade][lgtm]][lgtm-url]
B
Brian Sipple 已提交
9

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

P
Paul Masson 已提交
12
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.
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
[Forum](https://discourse.threejs.org/) —
M
Marco Fugaro 已提交
20 21
[Slack](https://join.slack.com/t/threejs/shared_invite/enQtMzYxMzczODM2OTgxLTQ1YmY4YTQxOTFjNDAzYmQ4NjU2YzRhNzliY2RiNDEyYjU2MjhhODgyYWQ5Y2MyZTU3MWNkOGVmOGRhOTQzYTk) —
[Discord](https://discordapp.com/invite/HF4UdyF)
M
Mr.doob 已提交
22

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

H
Hongarc 已提交
25
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 已提交
26

M
Mr.doob 已提交
27
```javascript
M
Mr.doob 已提交
28 29
import * as THREE from 'js/three.module.js';

M
Mr.doob 已提交
30
var camera, scene, renderer;
M
Mr.doob 已提交
31
var geometry, material, mesh;
32

M
Mr.doob 已提交
33 34
init();
animate();
M
Mr.doob 已提交
35

M
Mr.doob 已提交
36
function init() {
M
Mr.doob 已提交
37

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

M
Mr.doob 已提交
41
	scene = new THREE.Scene();
42

M
Mr.doob 已提交
43 44
	geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
	material = new THREE.MeshNormalMaterial();
M
Mr.doob 已提交
45

M
Mr.doob 已提交
46 47
	mesh = new THREE.Mesh( geometry, material );
	scene.add( mesh );
M
Mr.doob 已提交
48

M
Mr.doob 已提交
49
	renderer = new THREE.WebGLRenderer( { antialias: true } );
M
Mr.doob 已提交
50 51
	renderer.setSize( window.innerWidth, window.innerHeight );
	document.body.appendChild( renderer.domElement );
52

M
Mr.doob 已提交
53
}
M
Mr.doob 已提交
54

M
Mr.doob 已提交
55
function animate() {
M
Mr.doob 已提交
56

M
Mr.doob 已提交
57
	requestAnimationFrame( animate );
M
Mr.doob 已提交
58

M
Mr.doob 已提交
59 60
	mesh.rotation.x += 0.01;
	mesh.rotation.y += 0.02;
M
Mr.doob 已提交
61

M
Mr.doob 已提交
62
	renderer.render( scene, camera );
63

M
Mr.doob 已提交
64
}
M
Mr.doob 已提交
65
```
M
Mr.doob 已提交
66

S
Scott Bedard 已提交
67
If everything went well you should see [this](https://jsfiddle.net/972m5cdx/).
68

M
Mr.doob 已提交
69
### Change log ###
70

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


M
Mr.doob 已提交
74
[npm]: https://img.shields.io/npm/v/three
M
Mr.doob 已提交
75
[npm-url]: https://www.npmjs.com/package/three
76 77
[build-size]: https://badgen.net/bundlephobia/minzip/three
[build-size-url]: https://bundlephobia.com/result?p=three
M
Mr.doob 已提交
78 79 80
[npm-downloads]: https://img.shields.io/npm/dw/three
[npmtrends-url]: https://www.npmtrends.com/three
[dev-dependencies]: https://img.shields.io/david/dev/mrdoob/three.js
M
Mr.doob 已提交
81
[dev-dependencies-url]: https://david-dm.org/mrdoob/three.js#info=devDependencies
M
Mr.doob 已提交
82
[lgtm]: https://img.shields.io/lgtm/alerts/github/mrdoob/three.js
M
Mr.doob 已提交
83
[lgtm-url]: https://lgtm.com/projects/g/mrdoob/three.js/