webgl_performance_doublesided.html 4.4 KB
Newer Older
M
Mr.doob 已提交
1
<!DOCTYPE html>
2 3 4 5 6 7 8 9 10 11 12 13 14
<html lang="en">
	<head>
		<title>three.js webgl - performance</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:#fff;
				padding:0;
				margin:0;
				font-weight: bold;
				overflow:hidden;
			}
15 16 17 18 19

			#stats { position: absolute; top:0; left: 0 }
			#stats #fps { background: transparent !important }
			#stats #fps #fpsText { color: #eee !important }
			#stats #fps #fpsGraph { display: none }
20 21 22 23
		</style>
	</head>
	<body>

24
		<script src="../build/three.min.js"></script>
25

26
		<script src="js/Detector.js"></script>
27
		<script src="js/libs/stats.min.js"></script>
28 29 30

		<script>

31 32
			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

33 34 35 36
			var container, stats;

			var camera, scene, renderer;

37
			var mesh, geometry;
38 39 40

			var mouseX = 0, mouseY = 0;

41 42 43 44 45
			var SCREEN_WIDTH = window.innerWidth,
				SCREEN_HEIGHT = window.innerHeight;

			var windowHalfX = SCREEN_WIDTH / 2;
			var windowHalfY = SCREEN_HEIGHT / 2;
46 47 48 49 50 51 52 53 54 55

			init();
			animate();


			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

56
				camera = new THREE.PerspectiveCamera( 50, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 20000 );
57 58 59 60
				camera.position.z = 3200;

				scene = new THREE.Scene();

61
				var light = new THREE.PointLight( 0x0011ff, 1, 5500 );
62 63 64
				light.position.set( 4000, 0, 0 );
				scene.add( light );

65
				var light = new THREE.PointLight( 0xff1100, 1, 5500 );
66 67 68
				light.position.set( -4000, 0, 0 );
				scene.add( light );

69 70 71
				var light = new THREE.PointLight( 0xffaa00, 2, 3000 );
				light.position.set( 0, 0, 0 );
				scene.add( light );
72

73 74 75 76 77 78 79
				var path = "textures/cube/SwedishRoyalCastle/";
				var format = '.jpg';
				var urls = [
						path + 'px' + format, path + 'nx' + format,
						path + 'py' + format, path + 'ny' + format,
						path + 'pz' + format, path + 'nz' + format
					];
80

81 82
				var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
				reflectionCube.format = THREE.RGBFormat;
83

W
WestLangley 已提交
84
				var material = new THREE.MeshPhongMaterial( { specular: 0x101010, shininess: 100, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1, side: THREE.DoubleSide } );
85 86
				material.wrapAround = true;
				material.wrapRGB.set( 0.5, 0.5, 0.5 );
87 88 89 90 91 92 93 94 95 96 97

				var geometry = new THREE.SphereGeometry( 1, 32, 16, 0, Math.PI );

				for ( var i = 0; i < 5000; i ++ ) {

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

					mesh.position.x = Math.random() * 10000 - 5000;
					mesh.position.y = Math.random() * 10000 - 5000;
					mesh.position.z = Math.random() * 10000 - 5000;

98 99
					mesh.rotation.x = Math.random() * 2 * Math.PI;
					mesh.rotation.y = Math.random() * 2 * Math.PI;
100 101 102 103 104 105 106 107 108
					mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;

					mesh.matrixAutoUpdate = false;
					mesh.updateMatrix();

					scene.add( mesh );

				}

109
				renderer = new THREE.WebGLRenderer( { antialias: true } );
M
Mr.doob 已提交
110
				renderer.setClearColor( 0x050505 );
111
				renderer.setPixelRatio( window.devicePixelRatio );
112
				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
113 114 115 116 117 118 119 120 121

				renderer.gammaInput = true;
				renderer.gammaOutput = true;

				container.appendChild( renderer.domElement );

				stats = new Stats();
				container.appendChild( stats.domElement );

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
				window.addEventListener( 'resize', onWindowResize, false );

			}

			//

			function onWindowResize( event ) {

				SCREEN_WIDTH = window.innerWidth;
				SCREEN_HEIGHT = window.innerHeight;

				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );

				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
				camera.updateProjectionMatrix();

				windowHalfX = SCREEN_WIDTH / 2;
				windowHalfY = SCREEN_HEIGHT / 2;

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
			}

			function onDocumentMouseMove(event) {

				mouseX = ( event.clientX - windowHalfX ) * 10;
				mouseY = ( event.clientY - windowHalfY ) * 10;

			}

			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {

				camera.position.x += ( mouseX - camera.position.x ) * .05;
				camera.position.y += ( - mouseY - camera.position.y ) * .05;

				camera.lookAt( scene.position );

				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>