webgl_geometry_colors_blender.html 3.5 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>
35
		<div id="info"><a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - io blender - vertex colors</div>
36

W
WestLangley 已提交
37
		<script src="../build/three.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

L
Lewy Blue 已提交
75 76
				loader.load( "models/json/cubecolors/cubecolors.json", createScene1 );
				loader.load( "models/json/cubecolors/cube_fvc.json", createScene2 );
77

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

				stats = new Stats();
M
Mr.doob 已提交
84
				container.appendChild( stats.dom );
85 86 87

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

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
				//

				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 );

104 105
			}

106
			function createScene1( geometry, materials ) {
107

108
				mesh = new THREE.Mesh( geometry, materials );
109 110
				mesh.position.x = 400;
				mesh.scale.x = mesh.scale.y = mesh.scale.z = 250;
111
				scene.add( mesh );
112 113 114

			}

115
			function createScene2( geometry, materials ) {
116

117
				mesh2 = new THREE.Mesh( geometry, materials );
118 119
				mesh2.position.x = - 400;
				mesh2.scale.x = mesh2.scale.y = mesh2.scale.z = 250;
120
				scene.add( mesh2 );
121

122
			}
123

124 125 126 127 128 129 130
			function onDocumentMouseMove( event ) {

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

			}

131 132 133 134 135 136 137 138 139 140 141 142
			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {
143 144 145 146

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

147 148
				camera.lookAt( scene.position );

149
				if ( mesh ) {
150

151 152
					mesh.rotation.x += 0.01;
					mesh.rotation.y += 0.01;
153
				}
154

155
				if ( mesh2 ) {
156

157 158
					mesh2.rotation.x += 0.01;
					mesh2.rotation.y += 0.01;
159

160
				}
161

162 163 164 165 166 167 168 169
				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>