three.js : JavaScript 3D library:javascript
1.下載three.min.js:html
http://threejs.org/build/three.min.jsjava
2. 建立threejs_test.js:瀏覽器
var camera, scene, renderer; var geometry, material, mesh; function init() { camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 ); camera.position.z = 1; scene = new THREE.Scene(); geometry = new THREE.BoxGeometry( 0.5, 0.5, 0.5 ); material = new THREE.MeshNormalMaterial(); mesh = new THREE.Mesh( geometry, material ); scene.add( mesh ); renderer = new THREE.WebGLRenderer( { antialias: true } ); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); } function animate() { requestAnimationFrame( animate ); mesh.rotation.x += 0.01; mesh.rotation.y += 0.02; renderer.render( scene, camera ); }
3. 建立threejs_test.html文件app
<!DOCTYPE html> <html> <head> <script src="three.min.js"></script> <script src="threejs_test.js"></script> </head> <body> <script type='text/javascript'>init();</script> <script type='text/javascript'>animate();</script> </body> </html>
4. 瀏覽器上顯示:dom