Browse Source

Added webgl_panorama_cube example.

Mr.doob 9 years ago
parent
commit
ed9412dc7d

+ 1 - 0
examples/files.js

@@ -173,6 +173,7 @@ var files = {
 		"webgl_objects_update",
 		"webgl_octree",
 		"webgl_octree_raycasting",
+		"webgl_panorama_cube",
 		"webgl_panorama_dualfisheye",
 		"webgl_panorama_equirectangular",
 		"webgl_performance",

BIN
examples/textures/cube/sun_temple_stripe.jpg


+ 146 - 0
examples/webgl_panorama_cube.html

@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webvr - panorama</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
+		<style>
+			html, body {
+				background-color: #000;
+				margin: 0px;
+				padding: 0px;
+				overflow: hidden;
+			}
+			#info {
+				position: absolute;
+				top: 0px; width: 100%;
+				color: #ffffff;
+				padding: 5px;
+				font-family:Monospace;
+				font-size:13px;
+				font-weight: bold;
+				text-align:center;
+			}
+
+			a {
+				color: #ffffff;
+			}
+		</style>
+
+	</head>
+	<body>
+		<div id="container"></div>
+		<div id="info">
+			<a href="http://threejs.org" target="_blank">three.js webgl</a> - cube panorama demo.
+		</div>
+
+		<script src="../build/three.js"></script>
+		<script src="js/controls/OrbitControls.js"></script>
+
+		<script>
+
+		var camera;
+		var effect, controls;
+		var renderer;
+		var scene;
+
+		init();
+		animate();
+
+		function init() {
+
+			var container = document.getElementById( 'container' );
+
+			renderer = new THREE.WebGLRenderer();
+			renderer.setPixelRatio( window.devicePixelRatio );
+			renderer.setSize( window.innerWidth, window.innerHeight );
+			container.appendChild( renderer.domElement );
+
+			scene = new THREE.Scene();
+
+			camera = new THREE.PerspectiveCamera( 90, window.innerWidth / window.innerHeight, 0.1, 100 );
+			camera.position.z = 0.01;
+
+			controls = new THREE.OrbitControls( camera );
+			controls.enableZoom = false;
+			controls.enablePan = false;
+
+			var textures = getTexturesFromAtlasFile( "textures/cube/sun_temple_stripe.jpg", 6 );
+
+			var materials = [];
+
+			for ( var i = 0; i < 6; i ++ ) {
+
+				materials.push( new THREE.MeshBasicMaterial( { map: textures[ i ] } ) );
+
+			}
+
+			var skyBox = new THREE.Mesh( new THREE.CubeGeometry( 1, 1, 1 ), new THREE.MeshFaceMaterial( materials ) );
+			skyBox.applyMatrix( new THREE.Matrix4().makeScale( 1, 1, - 1 ) );
+			scene.add( skyBox );
+
+			window.addEventListener( 'resize', onWindowResize, false );
+
+		}
+
+		function getTexturesFromAtlasFile( atlasImgUrl, tilesNum ) {
+
+			var textures = [];
+
+			for ( var i = 0; i < tilesNum; i ++ ) {
+
+				textures[ i ] = new THREE.Texture();
+
+			}
+
+			var imageObj = new Image();
+
+			imageObj.onload = function() {
+
+				var canvas, context;
+				var tileWidth = imageObj.height;
+
+				for ( var i = 0; i < textures.length; i ++ ) {
+
+					canvas = document.createElement( 'canvas' );
+					context = canvas.getContext( '2d' );
+					canvas.height = tileWidth;
+					canvas.width = tileWidth;
+					context.drawImage( imageObj, tileWidth * i, 0, tileWidth, tileWidth, 0, 0, tileWidth, tileWidth );
+					textures[ i ].image = canvas
+					textures[ i ].needsUpdate = true;
+
+				}
+
+			};
+
+			imageObj.src = atlasImgUrl;
+
+			return textures;
+
+		}
+
+		function onWindowResize() {
+
+			camera.aspect = window.innerWidth / window.innerHeight;
+			camera.updateProjectionMatrix();
+
+			renderer.setSize( window.innerWidth, window.innerHeight );
+
+		}
+
+		function animate() {
+
+			controls.update();
+
+			// camera.rotation.y = - performance.now() / 10000;
+
+			renderer.render( scene, camera );
+
+			requestAnimationFrame( animate );
+
+		}
+
+		</script>
+	</body>
+</html>

+ 0 - 1
examples/webvr_panorama.html

@@ -16,7 +16,6 @@
 	</head>
 	<body>
 		<script src="../build/three.js"></script>
-		<script src="js/controls/OrbitControls.js"></script>
 
 		<script src="js/WebVR.js"></script>
 		<script src="js/controls/VRControls.js"></script>