threejs第一课 30行代码实现旋转的立方体

版权声明:本博客只做技术交流使用 https://blog.csdn.net/weixin_39452320/article/details/82662293

需要电子档书籍可以Q群:828202939   希望可以和大家一起学习、一起进步!!

所有的课程源代码在我上传的资源里面,本来想设置开源,好像不行!博客和专栏同步!

如有错别字或有理解不到位的地方,可以留言或者加微信15250969798,在下会及时修改!!!!!

花了大概2个月时间把webgl编程指南肯完了,有时候工作忙就没来得及更新博客!

接下的时间让我们重温threeTS的乐趣!

webgl要几百行代码实现的功能在three里面只需要短短的几十行就行了!

<html>
	<head>
		<title>第一个three场景</title>
		<style>
			body { margin: 0; }
			canvas { width: 100%; height: 100% }
		</style>
	</head>
	<body>
		<script src="../../../build/three.js"></script>
		<script>
			var scene = new THREE.Scene();
            scene.background=new THREE.Color(0xcfcfcf);
			var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
			var renderer = new THREE.WebGLRenderer();
			renderer.setSize( window.innerWidth, window.innerHeight );
            document.body.appendChild( renderer.domElement );
			var geometry = new THREE.BoxGeometry( 1, 1, 2 );//width, height, depth
			var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 ,wireframe:true} );//把wireframe设为false显示面
			var cube = new THREE.Mesh( geometry, material );
			scene.add( cube );
			camera.position.z = 5;
			var animate = function () {
				requestAnimationFrame( animate );
				cube.rotation.x += 0.01;
				cube.rotation.y += 0.01;
				renderer.render( scene, camera );
			};
			animate();
		</script>
	</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_39452320/article/details/82662293