Browse Source

added multiple renderers examples

Fordy 10 years ago
parent
commit
cd88296bcd

+ 1 - 4
examples/index.html

@@ -313,12 +313,9 @@
 				"webgl_multiple_canvases_complex",
 				"webgl_multiple_canvases_grid",
 				"webgl_multiple_elements",
-				"webgl_multiple_renderers",
+				"webgl_multiple_renderers_cube",
 				"webgl_multiple_renderers_horse",
 				"webgl_multiple_renderers_cubemap",
-				"webgl_multiple_renderers_buffergeometry_custom_attributes_particles",
-				"webgl_multiple_renderers_buffergeometry_instancing_dynamic",
-				"webgl_multiple_renderers_sprites",
 				"webgl_multiple_views",
 				"webgl_nearestneighbour",
 				"webgl_octree",

+ 93 - 0
examples/webgl_multiple_renderers_cube.html

@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <title>three.js webgl - geometry - cube</title>
+        <meta charset="utf-8">
+        <style>
+            body {
+                margin: 0px;
+                background-color: #000000;
+                overflow: hidden;
+            }
+        </style>
+    </head>
+    <body>
+
+        <script src="../build/three.min.js"></script>
+
+        <script>
+
+            var camera, camera2, scene, renderer;
+            var mesh, texture;
+
+            init();
+            animate();
+
+            function init() {
+
+                renderer = new THREE.WebGLRenderer();
+                renderer.setPixelRatio( window.devicePixelRatio );
+                renderer.setSize( window.innerWidth / 2, window.innerHeight );
+                document.body.appendChild( renderer.domElement );
+
+                renderer2 = new THREE.WebGLRenderer();
+                renderer2.setPixelRatio( window.devicePixelRatio );
+                renderer2.setSize( window.innerWidth / 2, window.innerHeight );
+                document.body.appendChild( renderer2.domElement );
+
+                //
+
+                camera = new THREE.PerspectiveCamera( 70, (window.innerWidth / 2) / window.innerHeight, 1, 1000 );
+                camera.position.z = 400;
+
+                camera2 = new THREE.PerspectiveCamera( 100, (window.innerWidth / 2) / window.innerHeight, 1, 1000 );
+                camera2.position.z = 400;
+
+                scene = new THREE.Scene();
+
+                var geometry = new THREE.BoxGeometry( 200, 200, 200 );
+
+                texture = THREE.ImageUtils.loadTexture( 'textures/crate.gif' );
+                texture.anisotropy = renderer.getMaxAnisotropy();
+
+                var material = new THREE.MeshBasicMaterial( { map: texture } );
+
+                mesh = new THREE.Mesh( geometry, material );
+                scene.add( mesh );
+
+                //
+
+                window.addEventListener( 'resize', onWindowResize, false );
+
+            }
+
+            function onWindowResize() {
+
+                camera.aspect = (window.innerWidth / 2) / window.innerHeight;
+                camera.updateProjectionMatrix();
+
+                renderer.setSize( window.innerWidth / 2, window.innerHeight );
+                renderer2.setSize( window.innerWidth / 2, window.innerHeight );
+
+            }
+
+            var i = 0;
+            function animate() {
+
+                requestAnimationFrame( animate );
+
+                mesh.rotation.x += 0.005;
+                mesh.rotation.y += 0.01;
+
+                i += 1;
+                mesh.material.color.setHex(0xffff00 + Math.sin(i / 100) * 128 + 128);
+
+                renderer.render( scene, camera );
+                renderer2.render( scene, camera2 );
+
+            }
+
+        </script>
+
+    </body>
+</html>

+ 245 - 0
examples/webgl_multiple_renderers_cubemap.html

@@ -0,0 +1,245 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webgl - materials - dynamic cube reflection</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<style>
+			body {
+				background-color: #000000;
+				margin: 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="info"><a href="http://threejs.org" target="_blank">three.js webgl</a> - materials - dynamic cube reflection<br/>Photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank">J&oacute;n Ragnarsson</a>.</div>
+
+		<script src="../build/three.min.js"></script>
+
+		<script>
+
+			var camera, cubeCamera, scene, renderer, renderer2, renderer3;
+			var cube, sphere, torus;
+
+			var fov = 70,
+			isUserInteracting = false,
+			onMouseDownMouseX = 0, onMouseDownMouseY = 0,
+			lon = 0, onMouseDownLon = 0,
+			lat = 0, onMouseDownLat = 0,
+			phi = 0, theta = 0;
+
+			var texture = THREE.ImageUtils.loadTexture( 'textures/2294472375_24a3b8ef46_o.jpg', THREE.UVMapping, function () {
+
+				init();
+				animate();
+
+			} );
+
+			function init() {
+
+				camera = new THREE.PerspectiveCamera( fov, (window.innerWidth / 2) / window.innerHeight, 1, 1000 );
+
+				scene = new THREE.Scene();
+
+				var mesh = new THREE.Mesh( new THREE.SphereGeometry( 500, 60, 40 ), new THREE.MeshBasicMaterial( { map: texture } ) );
+				mesh.scale.x = -1;
+				scene.add( mesh );
+
+				renderer = new THREE.WebGLRenderer( { antialias: true } );
+				renderer.setPixelRatio( window.devicePixelRatio );
+				renderer.setSize( window.innerWidth / 3, window.innerHeight );
+
+				renderer2 = new THREE.WebGLRenderer( { antialias: true } );
+				renderer2.setPixelRatio( window.devicePixelRatio );
+				renderer2.setSize( window.innerWidth / 3, window.innerHeight );
+
+				renderer3 = new THREE.WebGLRenderer( { antialias: true } );
+				renderer3.setPixelRatio( window.devicePixelRatio );
+				renderer3.setSize( window.innerWidth / 3, window.innerHeight );
+
+				cubeCamera = new THREE.CubeCamera( 1, 1000, 256 );
+				cubeCamera.renderTarget.minFilter = THREE.LinearMipMapLinearFilter;
+				scene.add( cubeCamera );
+
+				document.body.appendChild( renderer.domElement );
+				document.body.appendChild( renderer2.domElement );
+				document.body.appendChild( renderer3.domElement );
+
+				//
+
+				var material = new THREE.MeshBasicMaterial( { envMap: cubeCamera.renderTarget } );
+
+				sphere = new THREE.Mesh( new THREE.SphereGeometry( 20, 30, 15 ), material );
+				scene.add( sphere );
+
+				cube = new THREE.Mesh( new THREE.BoxGeometry( 20, 20, 20 ), material );
+				scene.add( cube );
+
+				torus = new THREE.Mesh( new THREE.TorusKnotGeometry( 20, 5, 100, 25 ), material );
+				scene.add( torus );
+
+				//
+
+				document.addEventListener( 'mousedown', onDocumentMouseDown, false );
+				document.addEventListener( 'mousewheel', onDocumentMouseWheel, false );
+				document.addEventListener( 'DOMMouseScroll', onDocumentMouseWheel, false);
+				window.addEventListener( 'resize', onWindowResized, false );
+
+				onWindowResized( null );
+
+			}
+
+			function onWindowResized( event ) {
+
+				renderer.setSize( window.innerWidth / 3, window.innerHeight );
+				camera.projectionMatrix.makePerspective( fov, (window.innerWidth / 3) / window.innerHeight, 1, 1100 );
+			}
+
+			function onDocumentMouseDown( event ) {
+
+				event.preventDefault();
+
+				onPointerDownPointerX = event.clientX;
+				onPointerDownPointerY = event.clientY;
+
+				onPointerDownLon = lon;
+				onPointerDownLat = lat;
+
+				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.addEventListener( 'mouseup', onDocumentMouseUp, false );
+
+			}
+
+			function onDocumentMouseMove( event ) {
+
+				lon = ( event.clientX - onPointerDownPointerX ) * 0.1 + onPointerDownLon;
+				lat = ( event.clientY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
+
+			}
+
+			function onDocumentMouseUp( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+
+			}
+
+			function onDocumentMouseWheel( event ) {
+
+				// WebKit
+
+				if ( event.wheelDeltaY ) {
+
+					fov -= event.wheelDeltaY * 0.05;
+
+				// Opera / Explorer 9
+
+				} else if ( event.wheelDelta ) {
+
+					fov -= event.wheelDelta * 0.05;
+
+				// Firefox
+
+				} else if ( event.detail ) {
+
+					fov += event.detail * 1.0;
+
+				}
+
+				camera.projectionMatrix.makePerspective( fov, window.innerWidth / window.innerHeight, 1, 1100 );
+
+			}
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+				render();
+
+			}
+
+			function render() {
+
+				var time = Date.now();
+
+				lon += .15;
+
+				lat = Math.max( - 85, Math.min( 85, lat ) );
+				phi = THREE.Math.degToRad( 90 - lat );
+				theta = THREE.Math.degToRad( lon );
+
+				sphere.position.x = Math.sin( time * 0.001 ) * 30;
+				sphere.position.y = Math.sin( time * 0.0011 ) * 30;
+				sphere.position.z = Math.sin( time * 0.0012 ) * 30;
+
+				sphere.rotation.x += 0.02;
+				sphere.rotation.y += 0.03;
+
+				cube.position.x = Math.sin( time * 0.001 + 2 ) * 30;
+				cube.position.y = Math.sin( time * 0.0011 + 2 ) * 30;
+				cube.position.z = Math.sin( time * 0.0012 + 2 ) * 30;
+
+				cube.rotation.x += 0.02;
+				cube.rotation.y += 0.03;
+
+				torus.position.x = Math.sin( time * 0.001 + 4 ) * 30;
+				torus.position.y = Math.sin( time * 0.0011 + 4 ) * 30;
+				torus.position.z = Math.sin( time * 0.0012 + 4 ) * 30;
+
+				torus.rotation.x += 0.02;
+				torus.rotation.y += 0.03;
+
+				camera.position.x = 100 * Math.sin( phi ) * Math.cos( theta );
+				camera.position.y = 100 * Math.cos( phi );
+				camera.position.z = 100 * Math.sin( phi ) * Math.sin( theta );
+
+				camera.lookAt( scene.position );
+
+				sphere.visible = false; // *cough*
+
+				cubeCamera.updateCubeMap( renderer, scene );
+				cubeCamera.updateCubeMap( renderer2, scene );
+				cubeCamera.updateCubeMap( renderer3, scene );
+
+				sphere.visible = true; // *cough*
+
+				renderer.render( scene, camera );
+
+				camera.position.z = 100 * Math.sin( phi ) * Math.cos( theta );
+				camera.position.x = 100 * Math.cos( phi );
+				camera.position.y = 100 * Math.sin( phi ) * Math.sin( theta );
+
+				camera.lookAt( scene.position );
+
+				renderer2.render( scene, camera );
+
+				camera.position.y = 100 * Math.sin( phi ) * Math.cos( theta );
+				camera.position.z = 100 * Math.cos( phi );
+				camera.position.x = 100 * Math.sin( phi ) * Math.sin( theta );
+
+				camera.lookAt( scene.position );
+
+				renderer3.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 160 - 0
examples/webgl_multiple_renderers_horse.html

@@ -0,0 +1,160 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webgl - morph targets - horse</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<style>
+			body {
+				font-family: Monospace;
+				background-color: #f0f0f0;
+				margin: 0px;
+				overflow: hidden;
+			}
+		</style>
+	</head>
+	<body>
+
+		<script src="../build/three.min.js"></script>
+
+		<script src="js/libs/stats.min.js"></script>
+
+		<script>
+
+			var container, stats;
+			var camera, scene, projector, renderer, renderer2;
+			var mesh, animation;
+
+			init();
+			animate();
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				var info = document.createElement( 'div' );
+				info.style.position = 'absolute';
+				info.style.top = '10px';
+				info.style.width = '100%';
+				info.style.textAlign = 'center';
+				info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js</a> webgl - morph targets - horse. model by <a href="http://mirada.com/">mirada</a> from <a href="http://ro.me">rome</a>';
+				container.appendChild( info );
+
+				//
+
+				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / 2 / window.innerHeight, 1, 10000 );
+				camera.position.y = 300;
+				camera.target = new THREE.Vector3( 0, 150, 0 );
+
+				scene = new THREE.Scene();
+
+				//
+
+				var light = new THREE.DirectionalLight( 0xefefff, 2 );
+				light.position.set( 1, 1, 1 ).normalize();
+				scene.add( light );
+
+				var light = new THREE.DirectionalLight( 0xffefef, 2 );
+				light.position.set( -1, -1, -1 ).normalize();
+				scene.add( light );
+
+				var loader = new THREE.JSONLoader( true );
+				loader.load( "models/animated/horse.js", function( geometry ) {
+
+					mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x606060, morphTargets: true } ) );
+					mesh.scale.set( 1.5, 1.5, 1.5 );
+					scene.add( mesh );
+
+					animation = new THREE.MorphAnimation( mesh );
+					animation.play();
+
+				} );
+
+				//
+
+				renderer = new THREE.WebGLRenderer();
+				renderer.setClearColor( 0xf0f0f0 );
+				renderer.setPixelRatio( window.devicePixelRatio );
+				renderer.setSize( window.innerWidth / 2, window.innerHeight );
+				container.appendChild(renderer.domElement);
+
+				renderer2 = new THREE.WebGLRenderer();
+				renderer2.setClearColor( 0xf0f0f0 );
+				renderer2.setPixelRatio( window.devicePixelRatio );
+				renderer2.setSize( window.innerWidth / 2, window.innerHeight );
+				container.appendChild(renderer2.domElement);
+
+				//
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				container.appendChild( stats.domElement );
+
+				//
+
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				camera.aspect = window.innerWidth / 2 / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth / 2, window.innerHeight );
+				renderer2.setSize( window.innerWidth / 2, window.innerHeight );
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			var radius = 600;
+			var theta = 0;
+
+			var prevTime = Date.now();
+
+			function render() {
+
+				theta += 0.1;
+
+				camera.position.x = radius * Math.sin( THREE.Math.degToRad( theta ) );
+				camera.position.z = radius * Math.cos( THREE.Math.degToRad( theta ) );
+
+				camera.lookAt( camera.target );
+
+				if ( animation ) {
+
+					var time = Date.now();
+
+					animation.update( time - prevTime );
+
+					prevTime = time;
+
+				}
+
+				renderer.render( scene, camera );
+
+				camera.position.x = -radius * Math.sin( THREE.Math.degToRad( theta ) );
+				camera.position.z = -radius * Math.cos( THREE.Math.degToRad( theta ) );
+
+				camera.lookAt( camera.target );
+
+				renderer2.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>