日期:2014-05-17  浏览次数:20711 次

HTML5实现的多边形球体自转效果源码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			body {
				background-color: #ffffff;
				margin: 0;
				overflow: hidden;
			}
		</style>
	</head>
	<body>
		<script src="http://mrdoob.github.com/three.js/build/three.min.js"></script>
		<script>

			// workaround for chrome bug: http://code.google.com/p/chromium/issues/detail?id=35980#c12
			if ( window.innerWidth === 0 ) { window.innerWidth = parent.innerWidth; window.innerHeight = parent.innerHeight; }
							
			var camera, scene, renderer;
			var geometry, material, mesh;

			init();
			animate();

			function init() {
				
				camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000 );
				camera.position.z = 500;

				scene = new THREE.Scene();

				geometry = new THREE.IcosahedronGeometry( 200, 1 );
				material = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, wireframeLinewidth: 2 } );

				mesh = new THREE.Mesh( geometry, material );
				scene.add( mesh );

				renderer = new THREE.CanvasRenderer();
				renderer.setSize( window.innerWidth, window.innerHeight );

				document.body.appendChild( renderer.domElement );

			}

			function animate() {

				requestAnimationFrame( animate );

				mesh.rotation.x = Date.now() * 0.0005;
				mesh.rotation.y = Date.now() * 0.001;

				renderer.render( scene, camera );

			}

		</script>
	</body>
</html>