复制代码代码如下: !DOCTYPE html html head title threeJSDemo /title meta charset="utf-8" style body { margin:0px; background-color:#B0B0B0; overload:hidden; } /style /head body script src="Three.js" /script script var camera,scene,renderer; var mesh; init(); animate();
function init(){ scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(70,window.innerWidth / window.innerHeight,1,1000); camera.position.z = 400; scene.add(camera); geometry = new THREE.CubeGeometry(200,200,200); material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } ); mesh = new THREE.Mesh(geometry,material); scene.add(mesh); renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth,window.innerHeight); document.body.appendChild(renderer.domElement); } function animate() { requestAnimationFrame( animate ); mesh.rotation.x += 0.05; mesh.rotation.y += 0.05; renderer.render( scene, camera ); } /script /body /html