ThreeJS 시리즈 자습서 - Lesson4

2191 단어 WebGLthree.js
효과:
 
코드:
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<title>Three.js tutorial - Lesson 04</title>
		<style>body{background:#000000;overflow:hidden;}</style>
		<script src="js/r69/three.js"></script> 
        <script src="js/r69/Detector.js"></script> 
        <script src="js/r69/CanvasRenderer.js"></script> 
        <script src="js/r69/Projector.js"></script>
	</head>
	<body>
		<script>
			var scene,camera,mesh,renderer;
			
			if(Detector.webgl){
				renderer = new THREE.WebGLRenderer({antialias:true});
			}else{
				renderer = new THREE.CanvasRenderer();
			}
			renderer.setSize(window.innerWidth, window.innerHeight);
			renderer.setClearColor(0x000000, 1);
			document.body.appendChild(renderer.domElement);
			
			scene = new THREE.Scene();
			
			camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 1, 1000);
			camera.position.set(0, 0, 10);
			camera.lookAt(scene.position);	//         
			//scene.add(camera);
			
			var boxGeometry = new THREE.BoxGeometry(2.0, 2.0, 2.0);
			
			var texture = new THREE.ImageUtils.loadTexture("images/NeHe.jpg");	//        
			var boxMaterial = new THREE.MeshBasicMaterial({map:texture});		//         
			
			var mesh = new THREE.Mesh(boxGeometry, boxMaterial);
			mesh.position.set(0, 0, 4);
			scene.add(mesh);
			
			var xRotation = 0;
			var yRotation = 0;
			var zRotation = 0;
			function render(){
				xRotation += 0.03;
				yRotation += 0.02;
				zRotation += 0.04;
				mesh.rotation.set(xRotation, yRotation, zRotation);
				
				renderer.render(scene, camera);
				
				requestAnimationFrame(render);
			}
			render();
		</script>
	</body>
</html>

부주: 현재 필자가 사용하는three.js 버전 r69

좋은 웹페이지 즐겨찾기