webgl_geometry_colors_blender.html 3.7 KB
Newer Older
M
Mr.doob 已提交
1
<!DOCTYPE html>
2 3
<html lang="en">
	<head>
4
		<title>three.js webgl - io blender - vertex colors</title>
5
		<meta charset="utf-8">
6 7
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
8 9 10 11 12 13 14 15
			body {
				color: #eee;
				font-family:Monospace;
				font-size:13px;
				text-align:center;

				background-color: #000;
				margin: 0px;
16
				padding: 0px;
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
				overflow: hidden;
			}

			#info {
				position: absolute;
				top: 0px; width: 100%;
				padding: 5px;
			}

			a {
				color: #0080ff;
			}

		</style>
	</head>
	<body>

34
		<div id="container"></div>
M
Mr.doob 已提交
35
		<div id="info"><a href="http://threejs.org" target="_blank">three.js</a> webgl - io blender - vertex colors</div>
36

37
		<script src="../build/three.min.js"></script>
38

M
Mr.doob 已提交
39
		<script src="js/Detector.js"></script>
40
		<script src="js/libs/stats.min.js"></script>
41

M
Mr.doob 已提交
42
		<script>
43

M
Mr.doob 已提交
44
			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
45 46 47 48 49 50 51 52 53 54 55 56

			var container, stats;

			var camera, scene, renderer;

			var mesh, mesh2, mesh3, light;

			var mouseX = 0, mouseY = 0;

			var windowHalfX = window.innerWidth / 2;
			var windowHalfY = window.innerHeight / 2;

57 58
			init();
			animate();
59 60 61 62 63

			function init() {

				container = document.getElementById( 'container' );

64
				camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
65
				camera.position.z = 1800;
66 67

				scene = new THREE.Scene();
68

69
				light = new THREE.DirectionalLight( 0xffffff );
70
				light.position.set( 0, 0, 1 ).normalize();
71
				scene.add( light );
72

73
				var loader = new THREE.JSONLoader();
74 75 76

				loader.load( "obj/cubecolors/cubecolors.js", createScene1 );
				loader.load( "obj/cubecolors/cube_fvc.js", createScene2 );
77

78
				renderer = new THREE.WebGLRenderer( { antialias: true } );
79
				renderer.setPixelRatio( window.devicePixelRatio );
80 81 82 83 84 85 86 87 88 89
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				stats = new Stats();
				stats.domElement.style.position = 'absolute';
				stats.domElement.style.top = '0px';
				container.appendChild( stats.domElement );

				document.addEventListener( 'mousemove', onDocumentMouseMove, false );

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
				//

				window.addEventListener( 'resize', onWindowResize, false );

			}

			function onWindowResize() {

				windowHalfX = window.innerWidth / 2;
				windowHalfY = window.innerHeight / 2;

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

106 107
			}

108
			function createScene1( geometry, materials ) {
109

110
				materials[ 0 ].shading = THREE.FlatShading;
111

M
Mugen87 已提交
112
				mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
113 114
				mesh.position.x = 400;
				mesh.scale.x = mesh.scale.y = mesh.scale.z = 250;
115
				scene.add( mesh );
116 117 118

			}

119
			function createScene2( geometry, materials ) {
120

121
				materials[ 0 ].shading = THREE.FlatShading;
122

M
Mugen87 已提交
123
				mesh2 = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
124 125
				mesh2.position.x = - 400;
				mesh2.scale.x = mesh2.scale.y = mesh2.scale.z = 250;
126
				scene.add( mesh2 );
127

128
			}
129

130 131 132 133 134 135 136
			function onDocumentMouseMove( event ) {

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

			}

137 138 139 140 141 142 143 144 145 146 147 148
			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {
149 150 151 152

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

153 154
				camera.lookAt( scene.position );

155
				if ( mesh ) {
156

157 158
					mesh.rotation.x += 0.01;
					mesh.rotation.y += 0.01;
159
				}
160

161
				if ( mesh2 ) {
162

163 164
					mesh2.rotation.x += 0.01;
					mesh2.rotation.y += 0.01;
165

166
				}
167

168 169 170 171 172 173 174 175
				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>