misc_exporter_gltf.html 17.5 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 13
			<button id="export_scene">Export Scene1</button>
			<button id="export_scenes">Export Scene1 and 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
		<script type="module">
			import {
				AmbientLight,
				AxesHelper,
				BoxBufferGeometry,
				BufferAttribute,
				BufferGeometry,
				CircleBufferGeometry,
				CylinderBufferGeometry,
				DirectionalLight,
				DoubleSide,
				GridHelper,
				Group,
				IcosahedronBufferGeometry,
				LatheBufferGeometry,
				Line,
				LineBasicMaterial,
				LineLoop,
				Mesh,
				MeshBasicMaterial,
				MeshLambertMaterial,
				MeshStandardMaterial,
				OctahedronBufferGeometry,
				OrthographicCamera,
				PerspectiveCamera,
				Points,
				PointsMaterial,
				RepeatWrapping,
				RingBufferGeometry,
				Scene,
				SphereBufferGeometry,
				TetrahedronBufferGeometry,
				TextureLoader,
				TorusKnotBufferGeometry,
				TriangleStripDrawMode,
				Vector2,
				VertexColors,
				WebGLRenderer
			} from "../build/three.module.js";

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

70
			function exportGLTF( input ) {
F
Fernando Serrano 已提交
71

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

74
				var options = {
L
Lewy Blue 已提交
75 76 77 78 79 80
					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
81
				};
L
Lewy Blue 已提交
82
				gltfExporter.parse( input, function ( result ) {
F
Fernando Serrano 已提交
83

84 85 86 87 88 89 90 91 92 93 94
					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 已提交
95

96
				}, options );
F
Fernando Serrano 已提交
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
			}

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

			} );

118 119 120 121 122 123
			document.getElementById( 'export_obj' ).addEventListener( 'click', function () {

				exportGLTF( waltHead );

			} );

124 125 126 127
			document.getElementById( 'export_objects' ).addEventListener( 'click', function () {

				exportGLTF( [ sphere, gridHelper ] );

128
			} );
F
Fernando Serrano 已提交
129

130 131 132 133 134 135 136
			document.getElementById( 'export_scene_object' ).addEventListener( 'click', function () {

				exportGLTF( [ scene1, gridHelper ] );

			} );


137 138 139
			var link = document.createElement( 'a' );
			link.style.display = 'none';
			document.body.appendChild( link ); // Firefox workaround, see #6594
F
Fernando Serrano 已提交
140

141
			function save( blob, filename ) {
F
Fernando Serrano 已提交
142

143
				link.href = URL.createObjectURL( blob );
144
				link.download = filename;
145
				link.click();
F
Fernando Serrano 已提交
146

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

149 150 151
			}

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

153
				save( new Blob( [ text ], { type: 'text/plain' } ), filename );
154 155 156 157 158 159 160

			}


			function saveArrayBuffer( buffer, filename ) {

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

162
			}
F
Fernando Serrano 已提交
163

164
			var container;
F
Fernando Serrano 已提交
165

166
			var camera, object, scene1, scene2, renderer;
167
			var gridHelper, sphere, waltHead;
F
Fernando Serrano 已提交
168 169 170 171 172 173 174 175 176

			init();
			animate();

			function init() {

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

M
Mugen87 已提交
177
				scene1 = new Scene();
178
				scene1.name = 'Scene1';
F
Fernando Serrano 已提交
179

180 181 182
				// ---------------------------------------------------------------------
				// Perspective Camera
				// ---------------------------------------------------------------------
M
Mugen87 已提交
183
				camera = new PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
L
Lewy Blue 已提交
184
				camera.position.set( 600, 400, 0 );
185 186 187

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

189 190 191
				// ---------------------------------------------------------------------
				// Ambient light
				// ---------------------------------------------------------------------
M
Mugen87 已提交
192
				var light = new AmbientLight( 0xffffff, 0.2 );
193 194
				light.name = 'AmbientLight';
				scene1.add( light );
F
Fernando Serrano 已提交
195

196 197 198
				// ---------------------------------------------------------------------
				// DirectLight
				// ---------------------------------------------------------------------
M
Mugen87 已提交
199 200
				light = new DirectionalLight( 0xffffff, 1 );
				light.target.position.set( 0, 0, - 1 );
201
				light.add( light.target );
M
Mugen87 已提交
202
				light.lookAt( - 1, - 1, 0 );
203
				light.name = 'DirectionalLight';
F
Fernando Serrano 已提交
204
				scene1.add( light );
F
Fernando Serrano 已提交
205

206 207 208
				// ---------------------------------------------------------------------
				// Grid
				// ---------------------------------------------------------------------
M
Mugen87 已提交
209
				gridHelper = new GridHelper( 2000, 20 );
L
Lewy Blue 已提交
210
				gridHelper.position.y = - 50;
211 212
				gridHelper.name = "Grid";
				scene1.add( gridHelper );
F
Fernando Serrano 已提交
213

214
				// ---------------------------------------------------------------------
W
WestLangley 已提交
215
				// Axes
216
				// ---------------------------------------------------------------------
M
Mugen87 已提交
217
				var axes = new AxesHelper( 500 );
W
WestLangley 已提交
218 219
				axes.name = "AxesHelper";
				scene1.add( axes );
F
Fernando Serrano 已提交
220 221 222 223 224

				// ---------------------------------------------------------------------
				// Simple geometry with basic material
				// ---------------------------------------------------------------------
				// Icosahedron
M
Mugen87 已提交
225 226 227
				var mapGrid = new TextureLoader().load( 'textures/UV_Grid_Sm.jpg' );
				mapGrid.wrapS = mapGrid.wrapT = RepeatWrapping;
				var material = new MeshBasicMaterial( {
228 229
					color: 0xffffff,
					map: mapGrid
230
				} );
F
Fernando Serrano 已提交
231

M
Mugen87 已提交
232
				object = new Mesh( new IcosahedronBufferGeometry( 75, 0 ), material );
L
Lewy Blue 已提交
233
				object.position.set( - 200, 0, 200 );
234 235
				object.name = 'Icosahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
236

F
Fernando Serrano 已提交
237
				// Octahedron
M
Mugen87 已提交
238
				material = new MeshBasicMaterial( {
F
Fernando Serrano 已提交
239 240 241
					color: 0x0000ff,
					wireframe: true
				} );
M
Mugen87 已提交
242
				object = new Mesh( new OctahedronBufferGeometry( 75, 1 ), material );
F
Fernando Serrano 已提交
243
				object.position.set( 0, 0, 200 );
244 245
				object.name = 'Octahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
246

F
Fernando Serrano 已提交
247
				// Tetrahedron
M
Mugen87 已提交
248
				material = new MeshBasicMaterial( {
249 250 251
					color: 0xff0000,
					transparent: true,
					opacity: 0.5
F
Fernando Serrano 已提交
252 253
				} );

M
Mugen87 已提交
254
				object = new Mesh( new TetrahedronBufferGeometry( 75, 0 ), material );
F
Fernando Serrano 已提交
255
				object.position.set( 200, 0, 200 );
256 257
				object.name = 'Tetrahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
258

F
Fernando Serrano 已提交
259 260 261
				// ---------------------------------------------------------------------
				// Buffered geometry primitives
				// ---------------------------------------------------------------------
F
Fernando Serrano 已提交
262
				// Sphere
M
Mugen87 已提交
263
				material = new MeshStandardMaterial( {
F
Fernando Serrano 已提交
264
					color: 0xffff00,
F
Fernando Serrano 已提交
265
					metalness: 0.5,
F
Fernando Serrano 已提交
266 267
					roughness: 1.0,
					flatShading: true
F
Fernando Serrano 已提交
268
				} );
M
Mugen87 已提交
269
				sphere = new Mesh( new SphereBufferGeometry( 70, 10, 10 ), material );
270 271 272
				sphere.position.set( 0, 0, 0 );
				sphere.name = "Sphere";
				scene1.add( sphere );
273

F
Fernando Serrano 已提交
274
				// Cylinder
M
Mugen87 已提交
275
				material = new MeshStandardMaterial( {
F
Fernando Serrano 已提交
276 277 278
					color: 0xff00ff,
					flatShading: true
				} );
M
Mugen87 已提交
279
				object = new Mesh( new CylinderBufferGeometry( 10, 80, 100 ), material );
F
Fernando Serrano 已提交
280 281
				object.position.set( 200, 0, 0 );
				object.name = "Cylinder";
282
				scene1.add( object );
F
Fernando Serrano 已提交
283

F
Fernando Serrano 已提交
284
				// TorusKnot
M
Mugen87 已提交
285
				material = new MeshStandardMaterial( {
286 287
					color: 0xff0000,
					roughness: 1
F
Fernando Serrano 已提交
288
				} );
M
Mugen87 已提交
289
				object = new Mesh( new TorusKnotBufferGeometry( 50, 15, 40, 10 ), material );
L
Lewy Blue 已提交
290
				object.position.set( - 200, 0, 0 );
F
Fernando Serrano 已提交
291
				object.name = "Cylinder";
292
				scene1.add( object );
F
Fernando Serrano 已提交
293

F
Fernando Serrano 已提交
294

F
Fernando Serrano 已提交
295 296 297
				// ---------------------------------------------------------------------
				// Hierarchy
				// ---------------------------------------------------------------------
M
Mugen87 已提交
298 299
				var mapWood = new TextureLoader().load( 'textures/hardwood2_diffuse.jpg' );
				material = new MeshStandardMaterial( { map: mapWood, side: DoubleSide } );
F
Fernando Serrano 已提交
300

M
Mugen87 已提交
301
				object = new Mesh( new BoxBufferGeometry( 40, 100, 100 ), material );
L
Lewy Blue 已提交
302
				object.position.set( - 200, 0, 400 );
F
Fernando Serrano 已提交
303
				object.name = "Cube";
304
				scene1.add( object );
F
Fernando Serrano 已提交
305

M
Mugen87 已提交
306
				var object2 = new Mesh( new BoxBufferGeometry( 40, 40, 40, 2, 2, 2 ), material );
F
Fernando Serrano 已提交
307
				object2.position.set( 0, 0, 50 );
F
Fernando Serrano 已提交
308
				object2.rotation.set( 0, 45, 0 );
F
Fernando Serrano 已提交
309
				object2.name = "SubCube";
F
Fernando Serrano 已提交
310
				object.add( object2 );
311

F
Fernando Serrano 已提交
312 313 314 315

				// ---------------------------------------------------------------------
				// Groups
				// ---------------------------------------------------------------------
M
Mugen87 已提交
316
				var group1 = new Group();
F
Fernando Serrano 已提交
317
				group1.name = "Group";
318
				scene1.add( group1 );
F
Fernando Serrano 已提交
319

M
Mugen87 已提交
320
				var group2 = new Group();
F
Fernando Serrano 已提交
321
				group2.name = "subGroup";
L
Lewy Blue 已提交
322
				group2.position.set( 0, 50, 0 );
F
Fernando Serrano 已提交
323
				group1.add( group2 );
324

M
Mugen87 已提交
325
				object2 = new Mesh( new BoxBufferGeometry( 30, 30, 30 ), material );
326
				object2.name = "Cube in group";
F
Fernando Serrano 已提交
327
				object2.position.set( 0, 0, 400 );
328 329
				group2.add( object2 );

F
Fernando Serrano 已提交
330
				// ---------------------------------------------------------------------
331
				// Triangle Strip
F
Fernando Serrano 已提交
332
				// ---------------------------------------------------------------------
M
Mugen87 已提交
333
				var geometry = new BufferGeometry();
L
Lewy Blue 已提交
334
				var positions = new Float32Array( [
F
Fernando Serrano 已提交
335 336 337 338 339 340
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 80, 0,
					80, 0, 80,
					80, 80, 80,
L
Lewy Blue 已提交
341
				] );
F
Fernando Serrano 已提交
342

L
Lewy Blue 已提交
343
				var colors = new Float32Array( [
F
Fernando Serrano 已提交
344 345 346 347 348 349
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
350
				] );
351

M
Mugen87 已提交
352 353 354
				geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
				geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
				object = new Mesh( geometry, new MeshBasicMaterial( { side: DoubleSide, vertexColors: VertexColors } ) );
L
Lewy Blue 已提交
355
				object.position.set( 140, - 40, - 250 );
M
Mugen87 已提交
356
				object.setDrawMode( TriangleStripDrawMode );
F
Fernando Serrano 已提交
357
				object.name = 'Custom buffered';
L
Lewy Blue 已提交
358
				object.userData = { data: 'customdata', list: [ 1, 2, 3, 4 ] };
359

F
Fernando Serrano 已提交
360
				scene1.add( object );
361 362


F
Fernando Serrano 已提交
363
				// ---------------------------------------------------------------------
364
				// Line Strip
F
Fernando Serrano 已提交
365
				// ---------------------------------------------------------------------
M
Mugen87 已提交
366
				var geometry = new BufferGeometry();
367 368 369
				var numPoints = 100;
				var positions = new Float32Array( numPoints * 3 );

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

372 373 374
					positions[ i * 3 ] = i;
					positions[ i * 3 + 1 ] = Math.sin( i / 2 ) * 20;
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
375

376 377
				}

M
Mugen87 已提交
378 379
				geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
				object = new Line( geometry, new LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
380
				object.position.set( - 50, 0, - 200 );
F
Fernando Serrano 已提交
381
				scene1.add( object );
382 383


F
Fernando Serrano 已提交
384
				// ---------------------------------------------------------------------
385
				// Line Loop
F
Fernando Serrano 已提交
386
				// ---------------------------------------------------------------------
M
Mugen87 已提交
387
				var geometry = new BufferGeometry();
388
				var numPoints = 5;
F
Fernando Serrano 已提交
389
				var radius = 70;
390 391
				var positions = new Float32Array( numPoints * 3 );

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

394
					var s = i * Math.PI * 2 / numPoints;
L
Lewy Blue 已提交
395 396
					positions[ i * 3 ] = radius * Math.sin( s );
					positions[ i * 3 + 1 ] = radius * Math.cos( s );
397
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
398

399 400
				}

M
Mugen87 已提交
401 402
				geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
				object = new LineLoop( geometry, new LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
403
				object.position.set( 0, 0, - 200 );
404

F
Fernando Serrano 已提交
405
				scene1.add( object );
406

407 408 409
				// ---------------------------------------------------------------------
				// Buffer geometry truncated (DrawRange)
				// ---------------------------------------------------------------------
M
Mugen87 已提交
410
				var geometry = new BufferGeometry();
411 412 413 414 415 416
				var numElements = 6;
				var outOfRange = 3;

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

L
Lewy Blue 已提交
417
				positions.set( [
418 419 420 421 422 423
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 0, 0,
					0, 80, 0,
					80, 80, 0
L
Lewy Blue 已提交
424
				] );
425

L
Lewy Blue 已提交
426
				colors.set( [
427 428 429 430 431 432
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
433
				] );
434

M
Mugen87 已提交
435 436
				geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
				geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
437 438
				geometry.setDrawRange( 0, numElements );

M
Mugen87 已提交
439
				object = new Mesh( geometry, new MeshBasicMaterial( { side: DoubleSide, vertexColors: VertexColors } ) );
440
				object.name = 'Custom buffered truncated';
L
Lewy Blue 已提交
441
				object.position.set( 340, - 40, - 200 );
442 443 444

				scene1.add( object );

F
Fernando Serrano 已提交
445
				// ---------------------------------------------------------------------
F
Fernando Serrano 已提交
446
				// Points
F
Fernando Serrano 已提交
447
				// ---------------------------------------------------------------------
448 449
				var numPoints = 100;
				var pointsArray = new Float32Array( numPoints * 3 );
L
Lewy Blue 已提交
450 451 452
				for ( var i = 0; i < numPoints; i ++ ) {

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

F
Fernando Serrano 已提交
456 457
				}

M
Mugen87 已提交
458 459
				var pointsGeo = new BufferGeometry();
				pointsGeo.addAttribute( 'position', new BufferAttribute( pointsArray, 3 ) );
F
Fernando Serrano 已提交
460

M
Mugen87 已提交
461 462
				var pointsMaterial = new PointsMaterial( { color: 0xffff00, size: 5 } );
				var points = new Points( pointsGeo, pointsMaterial );
F
Fernando Serrano 已提交
463
				points.name = "Points";
L
Lewy Blue 已提交
464
				points.position.set( - 200, 0, - 200 );
465
				scene1.add( points );
F
Fernando Serrano 已提交
466

467 468 469
				// ---------------------------------------------------------------------
				// Ortho camera
				// ---------------------------------------------------------------------
M
Mugen87 已提交
470
				var cameraOrtho = new OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 0.1, 10 );
471
				scene1.add( cameraOrtho );
F
Fernando Serrano 已提交
472
				cameraOrtho.name = 'OrthographicCamera';
F
Fernando Serrano 已提交
473

M
Mugen87 已提交
474
				material = new MeshLambertMaterial( {
475
					color: 0xffff00,
M
Mugen87 已提交
476
					side: DoubleSide
477 478
				} );

M
Mugen87 已提交
479
				object = new Mesh( new CircleBufferGeometry( 50, 20, 0, Math.PI * 2 ), material );
L
Lewy Blue 已提交
480
				object.position.set( 200, 0, - 400 );
481
				scene1.add( object );
F
Fernando Serrano 已提交
482

M
Mugen87 已提交
483
				object = new Mesh( new RingBufferGeometry( 10, 50, 20, 5, 0, Math.PI * 2 ), material );
L
Lewy Blue 已提交
484
				object.position.set( 0, 0, - 400 );
485
				scene1.add( object );
F
Fernando Serrano 已提交
486

M
Mugen87 已提交
487
				object = new Mesh( new CylinderBufferGeometry( 25, 75, 100, 40, 5 ), material );
L
Lewy Blue 已提交
488
				object.position.set( - 200, 0, - 400 );
489
				scene1.add( object );
490

F
Fernando Serrano 已提交
491 492 493 494 495
				//
				var points = [];

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

M
Mugen87 已提交
496
					points.push( new Vector2( Math.sin( i * 0.2 ) * Math.sin( i * 0.1 ) * 15 + 50, ( i - 5 ) * 2 ) );
F
Fernando Serrano 已提交
497 498 499

				}

M
Mugen87 已提交
500
				object = new Mesh( new LatheBufferGeometry( points, 20 ), material );
501
				object.position.set( 200, 0, 400 );
502
				scene1.add( object );
F
Fernando Serrano 已提交
503

504 505 506
				// ---------------------------------------------------------------------
				// Big red box hidden just for testing `onlyVisible` option
				// ---------------------------------------------------------------------
M
Mugen87 已提交
507
				material = new MeshBasicMaterial( {
508 509
					color: 0xff0000
				} );
M
Mugen87 已提交
510
				object = new Mesh( new BoxBufferGeometry( 200, 200, 200 ), material );
511 512 513 514
				object.position.set( 0, 0, 0 );
				object.name = "CubeHidden";
				object.visible = false;
				scene1.add( object );
F
Fernando Serrano 已提交
515

516 517 518
				// ---------------------------------------------------------------------
				//
				//
M
Mugen87 已提交
519
				var loader = new OBJLoader();
520 521 522 523
				loader.load( 'models/obj/walt/WaltHead.obj', function ( obj ) {

					waltHead = obj;
					waltHead.scale.multiplyScalar( 1.5 );
L
Lewy Blue 已提交
524
					waltHead.position.set( 400, 0, 0 );
525 526 527
					scene1.add( waltHead );

				} );
M
Mugen87 已提交
528 529


F
Fernando Serrano 已提交
530 531 532
				// ---------------------------------------------------------------------
				// 2nd Scene
				// ---------------------------------------------------------------------
M
Mugen87 已提交
533 534
				scene2 = new Scene();
				object = new Mesh( new BoxBufferGeometry( 100, 100, 100 ), material );
535 536 537
				object.position.set( 0, 0, 0 );
				object.name = "Cube2ndScene";
				scene2.name = 'Scene2';
L
Lewy Blue 已提交
538
				scene2.add( object );
539

F
Fernando Serrano 已提交
540 541
				//

M
Mugen87 已提交
542
				renderer = new WebGLRenderer( { antialias: true } );
F
Fernando Serrano 已提交
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
				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 已提交
575
				var timer = Date.now() * 0.0001;
F
Fernando Serrano 已提交
576

F
Fernando Serrano 已提交
577 578
				camera.position.x = Math.cos( timer ) * 800;
				camera.position.z = Math.sin( timer ) * 800;
F
Fernando Serrano 已提交
579

580 581
				camera.lookAt( scene1.position );
				renderer.render( scene1, camera );
F
Fernando Serrano 已提交
582 583 584 585 586 587 588

			}

		</script>

	</body>
</html>