misc_exporter_gltf.html 17.2 KB
Newer Older
F
Fernando Serrano 已提交
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
M
Mr.doob 已提交
4
		<title>three.js webgl - exporter - gltf</title>
F
Fernando Serrano 已提交
5 6
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
M
Mr.doob 已提交
7
		<link type="text/css" rel="stylesheet" href="main.css">
F
Fernando Serrano 已提交
8 9
	</head>
	<body>
10
		<div id="info">
M
Mr.doob 已提交
11
			<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - exporter - gltf<br/><br/>
12
			<button id="export_scene">Export Scene1</button>
M
Mr.doob 已提交
13
			<button id="export_scenes">Export Scene1 and THREE.Scene 2</button>
M
Mr.doob 已提交
14
			<button id="export_object">Export Sphere</button><br/>
15
			<button id="export_obj">Export WaltHead</button>
16 17
			<button id="export_objects">Export Sphere and Grid</button>
			<button id="export_scene_object">Export Scene1 and Sphere</button>
M
Mr.doob 已提交
18
			<br/><br/>
19 20
			<label><input id="option_trs" name="trs" type="checkbox"/>TRS</label>
			<label><input id="option_visible" name="visible" type="checkbox" checked="checked"/>Only Visible</label>
M
Mr.doob 已提交
21
			<label><input id="option_drawrange" name="visible" type="checkbox" checked="checked"/>Truncate drawRange</label><br/>
22
			<label><input id="option_binary" name="visible" type="checkbox">Binary (<code>.glb</code>)</label>
23
			<label><input id="option_forceindices" name="visible" type="checkbox">Force indices</label>
24
			<label><input id="option_forcepot" name="visible" type="checkbox">Force POT textures</label>
25
		</div>
F
Fernando Serrano 已提交
26

M
Mugen87 已提交
27
		<script type="module">
28

M
Mr.doob 已提交
29
			import * as THREE from '../build/three.module.js';
M
Mugen87 已提交
30 31 32

			import { OBJLoader } from './jsm/loaders/OBJLoader.js';
			import { GLTFExporter } from './jsm/exporters/GLTFExporter.js';
F
Fernando Serrano 已提交
33

34
			function exportGLTF( input ) {
F
Fernando Serrano 已提交
35

M
Mugen87 已提交
36
				var gltfExporter = new GLTFExporter();
F
Fernando Serrano 已提交
37

38
				var options = {
L
Lewy Blue 已提交
39 40 41 42 43 44
					trs: document.getElementById( 'option_trs' ).checked,
					onlyVisible: document.getElementById( 'option_visible' ).checked,
					truncateDrawRange: document.getElementById( 'option_drawrange' ).checked,
					binary: document.getElementById( 'option_binary' ).checked,
					forceIndices: document.getElementById( 'option_forceindices' ).checked,
					forcePowerOfTwoTextures: document.getElementById( 'option_forcepot' ).checked
45
				};
L
Lewy Blue 已提交
46
				gltfExporter.parse( input, function ( result ) {
F
Fernando Serrano 已提交
47

48 49 50 51 52 53 54 55 56 57 58
					if ( result instanceof ArrayBuffer ) {

						saveArrayBuffer( result, 'scene.glb' );

					} else {

						var output = JSON.stringify( result, null, 2 );
						console.log( output );
						saveString( output, 'scene.gltf' );

					}
F
Fernando Serrano 已提交
59

60
				}, options );
F
Fernando Serrano 已提交
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
			}

			document.getElementById( 'export_scene' ).addEventListener( 'click', function () {

				exportGLTF( scene1 );

			} );

			document.getElementById( 'export_scenes' ).addEventListener( 'click', function () {

				exportGLTF( [ scene1, scene2 ] );

			} );

			document.getElementById( 'export_object' ).addEventListener( 'click', function () {

				exportGLTF( sphere );

			} );

82 83 84 85 86 87
			document.getElementById( 'export_obj' ).addEventListener( 'click', function () {

				exportGLTF( waltHead );

			} );

88 89 90 91
			document.getElementById( 'export_objects' ).addEventListener( 'click', function () {

				exportGLTF( [ sphere, gridHelper ] );

92
			} );
F
Fernando Serrano 已提交
93

94 95 96 97 98 99 100
			document.getElementById( 'export_scene_object' ).addEventListener( 'click', function () {

				exportGLTF( [ scene1, gridHelper ] );

			} );


101 102 103
			var link = document.createElement( 'a' );
			link.style.display = 'none';
			document.body.appendChild( link ); // Firefox workaround, see #6594
F
Fernando Serrano 已提交
104

105
			function save( blob, filename ) {
F
Fernando Serrano 已提交
106

107
				link.href = URL.createObjectURL( blob );
108
				link.download = filename;
109
				link.click();
F
Fernando Serrano 已提交
110

111
				// URL.revokeObjectURL( url ); breaks Firefox...
F
Fernando Serrano 已提交
112

113 114 115
			}

			function saveString( text, filename ) {
F
Fernando Serrano 已提交
116

117
				save( new Blob( [ text ], { type: 'text/plain' } ), filename );
118 119 120 121 122 123 124

			}


			function saveArrayBuffer( buffer, filename ) {

				save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
F
Fernando Serrano 已提交
125

126
			}
F
Fernando Serrano 已提交
127

128
			var container;
F
Fernando Serrano 已提交
129

130
			var camera, object, scene1, scene2, renderer;
131
			var gridHelper, sphere, waltHead;
F
Fernando Serrano 已提交
132 133 134 135 136 137 138 139 140

			init();
			animate();

			function init() {

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

M
Mr.doob 已提交
141
				scene1 = new THREE.Scene();
142
				scene1.name = 'Scene1';
F
Fernando Serrano 已提交
143

144 145 146
				// ---------------------------------------------------------------------
				// Perspective Camera
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
147
				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
L
Lewy Blue 已提交
148
				camera.position.set( 600, 400, 0 );
149 150 151

				camera.name = "PerspectiveCamera";
				scene1.add( camera );
F
Fernando Serrano 已提交
152

153 154 155
				// ---------------------------------------------------------------------
				// Ambient light
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
156
				var light = new THREE.AmbientLight( 0xffffff, 0.2 );
157 158
				light.name = 'AmbientLight';
				scene1.add( light );
F
Fernando Serrano 已提交
159

160 161 162
				// ---------------------------------------------------------------------
				// DirectLight
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
163
				light = new THREE.DirectionalLight( 0xffffff, 1 );
M
Mugen87 已提交
164
				light.target.position.set( 0, 0, - 1 );
165
				light.add( light.target );
M
Mugen87 已提交
166
				light.lookAt( - 1, - 1, 0 );
167
				light.name = 'DirectionalLight';
F
Fernando Serrano 已提交
168
				scene1.add( light );
F
Fernando Serrano 已提交
169

170 171 172
				// ---------------------------------------------------------------------
				// Grid
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
173
				gridHelper = new THREE.GridHelper( 2000, 20 );
L
Lewy Blue 已提交
174
				gridHelper.position.y = - 50;
175 176
				gridHelper.name = "Grid";
				scene1.add( gridHelper );
F
Fernando Serrano 已提交
177

178
				// ---------------------------------------------------------------------
W
WestLangley 已提交
179
				// Axes
180
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
181
				var axes = new THREE.AxesHelper( 500 );
W
WestLangley 已提交
182 183
				axes.name = "AxesHelper";
				scene1.add( axes );
F
Fernando Serrano 已提交
184 185 186 187 188

				// ---------------------------------------------------------------------
				// Simple geometry with basic material
				// ---------------------------------------------------------------------
				// Icosahedron
M
Mr.doob 已提交
189 190 191
				var mapGrid = new THREE.TextureLoader().load( 'textures/UV_Grid_Sm.jpg' );
				mapGrid.wrapS = mapGrid.wrapT = THREE.RepeatWrapping;
				var material = new THREE.MeshBasicMaterial( {
192 193
					color: 0xffffff,
					map: mapGrid
194
				} );
F
Fernando Serrano 已提交
195

M
Mr.doob 已提交
196
				object = new THREE.Mesh( new THREE.IcosahedronBufferGeometry( 75, 0 ), material );
L
Lewy Blue 已提交
197
				object.position.set( - 200, 0, 200 );
198 199
				object.name = 'Icosahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
200

F
Fernando Serrano 已提交
201
				// Octahedron
M
Mr.doob 已提交
202
				material = new THREE.MeshBasicMaterial( {
F
Fernando Serrano 已提交
203 204 205
					color: 0x0000ff,
					wireframe: true
				} );
M
Mr.doob 已提交
206
				object = new THREE.Mesh( new THREE.OctahedronBufferGeometry( 75, 1 ), material );
F
Fernando Serrano 已提交
207
				object.position.set( 0, 0, 200 );
208 209
				object.name = 'Octahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
210

F
Fernando Serrano 已提交
211
				// Tetrahedron
M
Mr.doob 已提交
212
				material = new THREE.MeshBasicMaterial( {
213 214 215
					color: 0xff0000,
					transparent: true,
					opacity: 0.5
F
Fernando Serrano 已提交
216 217
				} );

M
Mr.doob 已提交
218
				object = new THREE.Mesh( new THREE.TetrahedronBufferGeometry( 75, 0 ), material );
F
Fernando Serrano 已提交
219
				object.position.set( 200, 0, 200 );
220 221
				object.name = 'Tetrahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
222

F
Fernando Serrano 已提交
223 224 225
				// ---------------------------------------------------------------------
				// Buffered geometry primitives
				// ---------------------------------------------------------------------
F
Fernando Serrano 已提交
226
				// Sphere
M
Mr.doob 已提交
227
				material = new THREE.MeshStandardMaterial( {
F
Fernando Serrano 已提交
228
					color: 0xffff00,
F
Fernando Serrano 已提交
229
					metalness: 0.5,
F
Fernando Serrano 已提交
230 231
					roughness: 1.0,
					flatShading: true
F
Fernando Serrano 已提交
232
				} );
M
Mr.doob 已提交
233
				sphere = new THREE.Mesh( new THREE.SphereBufferGeometry( 70, 10, 10 ), material );
234 235 236
				sphere.position.set( 0, 0, 0 );
				sphere.name = "Sphere";
				scene1.add( sphere );
237

F
Fernando Serrano 已提交
238
				// Cylinder
M
Mr.doob 已提交
239
				material = new THREE.MeshStandardMaterial( {
F
Fernando Serrano 已提交
240 241 242
					color: 0xff00ff,
					flatShading: true
				} );
M
Mr.doob 已提交
243
				object = new THREE.Mesh( new THREE.CylinderBufferGeometry( 10, 80, 100 ), material );
F
Fernando Serrano 已提交
244 245
				object.position.set( 200, 0, 0 );
				object.name = "Cylinder";
246
				scene1.add( object );
F
Fernando Serrano 已提交
247

F
Fernando Serrano 已提交
248
				// TorusKnot
M
Mr.doob 已提交
249
				material = new THREE.MeshStandardMaterial( {
250 251
					color: 0xff0000,
					roughness: 1
F
Fernando Serrano 已提交
252
				} );
M
Mr.doob 已提交
253
				object = new THREE.Mesh( new THREE.TorusKnotBufferGeometry( 50, 15, 40, 10 ), material );
L
Lewy Blue 已提交
254
				object.position.set( - 200, 0, 0 );
F
Fernando Serrano 已提交
255
				object.name = "Cylinder";
256
				scene1.add( object );
F
Fernando Serrano 已提交
257

F
Fernando Serrano 已提交
258

F
Fernando Serrano 已提交
259 260 261
				// ---------------------------------------------------------------------
				// Hierarchy
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
262 263
				var mapWood = new THREE.TextureLoader().load( 'textures/hardwood2_diffuse.jpg' );
				material = new THREE.MeshStandardMaterial( { map: mapWood, side: THREE.DoubleSide } );
F
Fernando Serrano 已提交
264

M
Mr.doob 已提交
265
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 40, 100, 100 ), material );
L
Lewy Blue 已提交
266
				object.position.set( - 200, 0, 400 );
F
Fernando Serrano 已提交
267
				object.name = "Cube";
268
				scene1.add( object );
F
Fernando Serrano 已提交
269

M
Mr.doob 已提交
270
				var object2 = new THREE.Mesh( new THREE.BoxBufferGeometry( 40, 40, 40, 2, 2, 2 ), material );
F
Fernando Serrano 已提交
271
				object2.position.set( 0, 0, 50 );
F
Fernando Serrano 已提交
272
				object2.rotation.set( 0, 45, 0 );
F
Fernando Serrano 已提交
273
				object2.name = "SubCube";
F
Fernando Serrano 已提交
274
				object.add( object2 );
275

F
Fernando Serrano 已提交
276 277 278 279

				// ---------------------------------------------------------------------
				// Groups
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
280
				var group1 = new THREE.Group();
F
Fernando Serrano 已提交
281
				group1.name = "Group";
282
				scene1.add( group1 );
F
Fernando Serrano 已提交
283

M
Mr.doob 已提交
284
				var group2 = new THREE.Group();
F
Fernando Serrano 已提交
285
				group2.name = "subGroup";
L
Lewy Blue 已提交
286
				group2.position.set( 0, 50, 0 );
F
Fernando Serrano 已提交
287
				group1.add( group2 );
288

M
Mr.doob 已提交
289
				object2 = new THREE.Mesh( new THREE.BoxBufferGeometry( 30, 30, 30 ), material );
290
				object2.name = "Cube in group";
F
Fernando Serrano 已提交
291
				object2.position.set( 0, 0, 400 );
292 293
				group2.add( object2 );

F
Fernando Serrano 已提交
294
				// ---------------------------------------------------------------------
295
				// Triangle Strip
F
Fernando Serrano 已提交
296
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
297
				var geometry = new THREE.BufferGeometry();
L
Lewy Blue 已提交
298
				var positions = new Float32Array( [
F
Fernando Serrano 已提交
299 300 301 302 303 304
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 80, 0,
					80, 0, 80,
					80, 80, 80,
L
Lewy Blue 已提交
305
				] );
F
Fernando Serrano 已提交
306

L
Lewy Blue 已提交
307
				var colors = new Float32Array( [
F
Fernando Serrano 已提交
308 309 310 311 312 313
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
314
				] );
315

M
Mr.doob 已提交
316 317 318
				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
				object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide, vertexColors: THREE.VertexColors } ) );
L
Lewy Blue 已提交
319
				object.position.set( 140, - 40, - 250 );
M
Mr.doob 已提交
320
				object.setDrawMode( THREE.TriangleStripDrawMode );
F
Fernando Serrano 已提交
321
				object.name = 'Custom buffered';
L
Lewy Blue 已提交
322
				object.userData = { data: 'customdata', list: [ 1, 2, 3, 4 ] };
323

F
Fernando Serrano 已提交
324
				scene1.add( object );
325 326


F
Fernando Serrano 已提交
327
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
328
				// THREE.Line Strip
F
Fernando Serrano 已提交
329
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
330
				var geometry = new THREE.BufferGeometry();
331 332 333
				var numPoints = 100;
				var positions = new Float32Array( numPoints * 3 );

L
Lewy Blue 已提交
334 335
				for ( var i = 0; i < numPoints; i ++ ) {

336 337 338
					positions[ i * 3 ] = i;
					positions[ i * 3 + 1 ] = Math.sin( i / 2 ) * 20;
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
339

340 341
				}

M
Mr.doob 已提交
342 343
				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				object = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
344
				object.position.set( - 50, 0, - 200 );
F
Fernando Serrano 已提交
345
				scene1.add( object );
346 347


F
Fernando Serrano 已提交
348
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
349
				// THREE.Line Loop
F
Fernando Serrano 已提交
350
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
351
				var geometry = new THREE.BufferGeometry();
352
				var numPoints = 5;
F
Fernando Serrano 已提交
353
				var radius = 70;
354 355
				var positions = new Float32Array( numPoints * 3 );

L
Lewy Blue 已提交
356 357
				for ( var i = 0; i < numPoints; i ++ ) {

358
					var s = i * Math.PI * 2 / numPoints;
L
Lewy Blue 已提交
359 360
					positions[ i * 3 ] = radius * Math.sin( s );
					positions[ i * 3 + 1 ] = radius * Math.cos( s );
361
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
362

363 364
				}

M
Mr.doob 已提交
365 366
				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				object = new THREE.LineLoop( geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
367
				object.position.set( 0, 0, - 200 );
368

F
Fernando Serrano 已提交
369
				scene1.add( object );
370

371 372 373
				// ---------------------------------------------------------------------
				// Buffer geometry truncated (DrawRange)
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
374
				var geometry = new THREE.BufferGeometry();
375 376 377 378 379 380
				var numElements = 6;
				var outOfRange = 3;

				var positions = new Float32Array( ( numElements + outOfRange ) * 3 );
				var colors = new Float32Array( ( numElements + outOfRange ) * 3 );

L
Lewy Blue 已提交
381
				positions.set( [
382 383 384 385 386 387
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 0, 0,
					0, 80, 0,
					80, 80, 0
L
Lewy Blue 已提交
388
				] );
389

L
Lewy Blue 已提交
390
				colors.set( [
391 392 393 394 395 396
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
397
				] );
398

M
Mr.doob 已提交
399 400
				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
401 402
				geometry.setDrawRange( 0, numElements );

M
Mr.doob 已提交
403
				object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide, vertexColors: THREE.VertexColors } ) );
404
				object.name = 'Custom buffered truncated';
L
Lewy Blue 已提交
405
				object.position.set( 340, - 40, - 200 );
406 407 408

				scene1.add( object );

F
Fernando Serrano 已提交
409
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
410
				// THREE.Points
F
Fernando Serrano 已提交
411
				// ---------------------------------------------------------------------
412 413
				var numPoints = 100;
				var pointsArray = new Float32Array( numPoints * 3 );
L
Lewy Blue 已提交
414 415 416
				for ( var i = 0; i < numPoints; i ++ ) {

					pointsArray[ 3 * i ] = - 50 + Math.random() * 100;
F
Fernando Serrano 已提交
417
					pointsArray[ 3 * i + 1 ] = Math.random() * 100;
L
Lewy Blue 已提交
418 419
					pointsArray[ 3 * i + 2 ] = - 50 + Math.random() * 100;

F
Fernando Serrano 已提交
420 421
				}

M
Mr.doob 已提交
422 423
				var pointsGeo = new THREE.BufferGeometry();
				pointsGeo.addAttribute( 'position', new THREE.BufferAttribute( pointsArray, 3 ) );
F
Fernando Serrano 已提交
424

M
Mr.doob 已提交
425 426
				var pointsMaterial = new THREE.PointsMaterial( { color: 0xffff00, size: 5 } );
				var points = new THREE.Points( pointsGeo, pointsMaterial );
F
Fernando Serrano 已提交
427
				points.name = "Points";
L
Lewy Blue 已提交
428
				points.position.set( - 200, 0, - 200 );
429
				scene1.add( points );
F
Fernando Serrano 已提交
430

431 432 433
				// ---------------------------------------------------------------------
				// Ortho camera
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
434
				var cameraOrtho = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 0.1, 10 );
435
				scene1.add( cameraOrtho );
F
Fernando Serrano 已提交
436
				cameraOrtho.name = 'OrthographicCamera';
F
Fernando Serrano 已提交
437

M
Mr.doob 已提交
438
				material = new THREE.MeshLambertMaterial( {
439
					color: 0xffff00,
M
Mr.doob 已提交
440
					side: THREE.DoubleSide
441 442
				} );

M
Mr.doob 已提交
443
				object = new THREE.Mesh( new THREE.CircleBufferGeometry( 50, 20, 0, Math.PI * 2 ), material );
L
Lewy Blue 已提交
444
				object.position.set( 200, 0, - 400 );
445
				scene1.add( object );
F
Fernando Serrano 已提交
446

M
Mr.doob 已提交
447
				object = new THREE.Mesh( new THREE.RingBufferGeometry( 10, 50, 20, 5, 0, Math.PI * 2 ), material );
L
Lewy Blue 已提交
448
				object.position.set( 0, 0, - 400 );
449
				scene1.add( object );
F
Fernando Serrano 已提交
450

M
Mr.doob 已提交
451
				object = new THREE.Mesh( new THREE.CylinderBufferGeometry( 25, 75, 100, 40, 5 ), material );
L
Lewy Blue 已提交
452
				object.position.set( - 200, 0, - 400 );
453
				scene1.add( object );
454

F
Fernando Serrano 已提交
455 456 457 458 459
				//
				var points = [];

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

M
Mr.doob 已提交
460
					points.push( new THREE.Vector2( Math.sin( i * 0.2 ) * Math.sin( i * 0.1 ) * 15 + 50, ( i - 5 ) * 2 ) );
F
Fernando Serrano 已提交
461 462 463

				}

M
Mr.doob 已提交
464
				object = new THREE.Mesh( new THREE.LatheBufferGeometry( points, 20 ), material );
465
				object.position.set( 200, 0, 400 );
466
				scene1.add( object );
F
Fernando Serrano 已提交
467

468 469 470
				// ---------------------------------------------------------------------
				// Big red box hidden just for testing `onlyVisible` option
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
471
				material = new THREE.MeshBasicMaterial( {
472 473
					color: 0xff0000
				} );
M
Mr.doob 已提交
474
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 200, 200, 200 ), material );
475 476 477 478
				object.position.set( 0, 0, 0 );
				object.name = "CubeHidden";
				object.visible = false;
				scene1.add( object );
F
Fernando Serrano 已提交
479

480 481 482
				// ---------------------------------------------------------------------
				//
				//
M
Mugen87 已提交
483
				var loader = new OBJLoader();
484 485 486 487
				loader.load( 'models/obj/walt/WaltHead.obj', function ( obj ) {

					waltHead = obj;
					waltHead.scale.multiplyScalar( 1.5 );
L
Lewy Blue 已提交
488
					waltHead.position.set( 400, 0, 0 );
489 490 491
					scene1.add( waltHead );

				} );
M
Mugen87 已提交
492 493


F
Fernando Serrano 已提交
494
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
495
				// 2nd THREE.Scene
F
Fernando Serrano 已提交
496
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
497 498
				scene2 = new THREE.Scene();
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 100, 100, 100 ), material );
499 500 501
				object.position.set( 0, 0, 0 );
				object.name = "Cube2ndScene";
				scene2.name = 'Scene2';
L
Lewy Blue 已提交
502
				scene2.add( object );
503

F
Fernando Serrano 已提交
504 505
				//

M
Mr.doob 已提交
506
				renderer = new THREE.WebGLRenderer( { antialias: true } );
F
Fernando Serrano 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );

				container.appendChild( renderer.domElement );

				//

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

			}

			function onWindowResize() {

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

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

			}

			//

			function animate() {

				requestAnimationFrame( animate );

				render();

			}

			function render() {

F
Fernando Serrano 已提交
539
				var timer = Date.now() * 0.0001;
F
Fernando Serrano 已提交
540

F
Fernando Serrano 已提交
541 542
				camera.position.x = Math.cos( timer ) * 800;
				camera.position.z = Math.sin( timer ) * 800;
F
Fernando Serrano 已提交
543

544 545
				camera.lookAt( scene1.position );
				renderer.render( scene1, camera );
F
Fernando Serrano 已提交
546 547 548 549 550 551 552

			}

		</script>

	</body>
</html>