misc_exporter_gltf.html 17.3 KB
Newer Older
F
Fernando Serrano 已提交
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
F
Fernando Serrano 已提交
4
		<title>three.js webgl - gltf exporter</title>
F
Fernando Serrano 已提交
5 6 7 8 9 10 11 12 13
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #000;
				margin: 0px;
				overflow: hidden;
			}
14
			#info {
15
				color: #ccc;
16 17 18 19 20
				text-align: center;
				position: absolute;
				top: 0px; width: 100%;
				padding: 5px;
			}
F
Fernando Serrano 已提交
21 22 23
		</style>
	</head>
	<body>
24
		<div id="info">
25
			GLTF Exporter<br/>
26 27 28
			<button id="export_scene">Export Scene1</button>
			<button id="export_scenes">Export Scene1 and Scene 2</button>
			<button id="export_object">Export Sphere</button>
29
			<button id="export_obj">Export WaltHead</button>
30 31
			<button id="export_objects">Export Sphere and Grid</button>
			<button id="export_scene_object">Export Scene1 and Sphere</button>
32
			<br/>
33 34
			<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>
35
			<label><input id="option_drawrange" name="visible" type="checkbox" checked="checked"/>Truncate drawRange</label>
36
			<label><input id="option_binary" name="visible" type="checkbox">Binary (<code>.glb</code>)</label>
37
			<label><input id="option_forceindices" name="visible" type="checkbox">Force indices</label>
38
			<label><input id="option_forcepot" name="visible" type="checkbox">Force POT textures</label>
39
		</div>
F
Fernando Serrano 已提交
40 41 42

		<script src="../build/three.js"></script>

M
Mr.doob 已提交
43
		<script src="js/WebGL.js"></script>
44
		<script src="js/loaders/OBJLoader.js"></script>
F
Fernando Serrano 已提交
45 46 47 48
		<script src="js/exporters/GLTFExporter.js"></script>

		<script>

49
			function exportGLTF( input ) {
F
Fernando Serrano 已提交
50

51
				var gltfExporter = new THREE.GLTFExporter();
F
Fernando Serrano 已提交
52

53
				var options = {
L
Lewy Blue 已提交
54 55 56 57 58 59
					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
60
				};
L
Lewy Blue 已提交
61
				gltfExporter.parse( input, function ( result ) {
F
Fernando Serrano 已提交
62

63 64 65 66 67 68 69 70 71 72 73
					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 已提交
74

75
				}, options );
F
Fernando Serrano 已提交
76

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
			}

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

			} );

97 98 99 100 101 102
			document.getElementById( 'export_obj' ).addEventListener( 'click', function () {

				exportGLTF( waltHead );

			} );

103 104 105 106
			document.getElementById( 'export_objects' ).addEventListener( 'click', function () {

				exportGLTF( [ sphere, gridHelper ] );

107
			} );
F
Fernando Serrano 已提交
108

109 110 111 112 113 114 115
			document.getElementById( 'export_scene_object' ).addEventListener( 'click', function () {

				exportGLTF( [ scene1, gridHelper ] );

			} );


116 117 118
			var link = document.createElement( 'a' );
			link.style.display = 'none';
			document.body.appendChild( link ); // Firefox workaround, see #6594
F
Fernando Serrano 已提交
119

120
			function save( blob, filename ) {
F
Fernando Serrano 已提交
121

122
				link.href = URL.createObjectURL( blob );
123
				link.download = filename;
124
				link.click();
F
Fernando Serrano 已提交
125

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

128 129 130
			}

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

132
				save( new Blob( [ text ], { type: 'text/plain' } ), filename );
133 134 135 136 137 138 139

			}


			function saveArrayBuffer( buffer, filename ) {

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

141
			}
F
Fernando Serrano 已提交
142

M
Mr.doob 已提交
143 144 145 146 147
			if ( WEBGL.isWebGLAvailable() === false ) {

				document.body.appendChild( WEBGL.getWebGLErrorMessage() );

			}
F
Fernando Serrano 已提交
148

149
			var container;
F
Fernando Serrano 已提交
150

151
			var camera, object, scene1, scene2, renderer;
152
			var gridHelper, sphere, waltHead;
F
Fernando Serrano 已提交
153 154 155 156 157 158 159 160 161

			init();
			animate();

			function init() {

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

162 163
				scene1 = new THREE.Scene();
				scene1.name = 'Scene1';
F
Fernando Serrano 已提交
164

165 166 167 168
				// ---------------------------------------------------------------------
				// Perspective Camera
				// ---------------------------------------------------------------------
				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
L
Lewy Blue 已提交
169
				camera.position.set( 600, 400, 0 );
170 171 172

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

174 175 176
				// ---------------------------------------------------------------------
				// Ambient light
				// ---------------------------------------------------------------------
177 178 179
				var light = new THREE.AmbientLight( 0xffffff, 0.2 );
				light.name = 'AmbientLight';
				scene1.add( light );
F
Fernando Serrano 已提交
180

181 182 183
				// ---------------------------------------------------------------------
				// DirectLight
				// ---------------------------------------------------------------------
184
				light = new THREE.DirectionalLight( 0xffffff, 1 );
F
Fernando Serrano 已提交
185
				light.position.set( 1, 1, 0 );
186
				light.name = 'DirectionalLight';
F
Fernando Serrano 已提交
187
				scene1.add( light );
F
Fernando Serrano 已提交
188

189 190 191
				// ---------------------------------------------------------------------
				// Grid
				// ---------------------------------------------------------------------
192
				gridHelper = new THREE.GridHelper( 2000, 20 );
L
Lewy Blue 已提交
193
				gridHelper.position.y = - 50;
194 195
				gridHelper.name = "Grid";
				scene1.add( gridHelper );
F
Fernando Serrano 已提交
196

197
				// ---------------------------------------------------------------------
W
WestLangley 已提交
198
				// Axes
199
				// ---------------------------------------------------------------------
W
WestLangley 已提交
200 201 202
				var axes = new THREE.AxesHelper( 500 );
				axes.name = "AxesHelper";
				scene1.add( axes );
F
Fernando Serrano 已提交
203 204 205 206 207

				// ---------------------------------------------------------------------
				// Simple geometry with basic material
				// ---------------------------------------------------------------------
				// Icosahedron
208 209
				var mapGrid = new THREE.TextureLoader().load( 'textures/UV_Grid_Sm.jpg' );
				mapGrid.wrapS = mapGrid.wrapT = THREE.RepeatWrapping;
210
				var material = new THREE.MeshBasicMaterial( {
211 212
					color: 0xffffff,
					map: mapGrid
213
				} );
F
Fernando Serrano 已提交
214

215
				object = new THREE.Mesh( new THREE.IcosahedronGeometry( 75, 0 ), material );
L
Lewy Blue 已提交
216
				object.position.set( - 200, 0, 200 );
217 218
				object.name = 'Icosahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
219

F
Fernando Serrano 已提交
220 221 222 223 224
				// Octahedron
				material = new THREE.MeshBasicMaterial( {
					color: 0x0000ff,
					wireframe: true
				} );
225
				object = new THREE.Mesh( new THREE.OctahedronGeometry( 75, 1 ), material );
F
Fernando Serrano 已提交
226
				object.position.set( 0, 0, 200 );
227 228
				object.name = 'Octahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
229

F
Fernando Serrano 已提交
230 231
				// Tetrahedron
				material = new THREE.MeshBasicMaterial( {
232 233 234
					color: 0xff0000,
					transparent: true,
					opacity: 0.5
F
Fernando Serrano 已提交
235 236
				} );

F
Fernando Serrano 已提交
237 238
				object = new THREE.Mesh( new THREE.TetrahedronGeometry( 75, 0 ), material );
				object.position.set( 200, 0, 200 );
239 240
				object.name = 'Tetrahedron';
				scene1.add( object );
F
Fernando Serrano 已提交
241

F
Fernando Serrano 已提交
242 243 244
				// ---------------------------------------------------------------------
				// Buffered geometry primitives
				// ---------------------------------------------------------------------
F
Fernando Serrano 已提交
245 246
				// Sphere
				material = new THREE.MeshStandardMaterial( {
F
Fernando Serrano 已提交
247
					color: 0xffff00,
F
Fernando Serrano 已提交
248
					metalness: 0.5,
F
Fernando Serrano 已提交
249 250
					roughness: 1.0,
					flatShading: true
F
Fernando Serrano 已提交
251
				} );
252 253 254 255
				sphere = new THREE.Mesh( new THREE.SphereBufferGeometry( 70, 10, 10 ), material );
				sphere.position.set( 0, 0, 0 );
				sphere.name = "Sphere";
				scene1.add( sphere );
256

F
Fernando Serrano 已提交
257
				// Cylinder
F
Fernando Serrano 已提交
258 259 260 261
				material = new THREE.MeshStandardMaterial( {
					color: 0xff00ff,
					flatShading: true
				} );
F
Fernando Serrano 已提交
262 263 264
				object = new THREE.Mesh( new THREE.CylinderBufferGeometry( 10, 80, 100 ), material );
				object.position.set( 200, 0, 0 );
				object.name = "Cylinder";
265
				scene1.add( object );
F
Fernando Serrano 已提交
266

F
Fernando Serrano 已提交
267
				// TorusKnot
F
Fernando Serrano 已提交
268
				material = new THREE.MeshStandardMaterial( {
269 270
					color: 0xff0000,
					roughness: 1
F
Fernando Serrano 已提交
271
				} );
272
				object = new THREE.Mesh( new THREE.TorusKnotGeometry( 50, 15, 40, 10 ), material );
L
Lewy Blue 已提交
273
				object.position.set( - 200, 0, 0 );
F
Fernando Serrano 已提交
274
				object.name = "Cylinder";
275
				scene1.add( object );
F
Fernando Serrano 已提交
276

F
Fernando Serrano 已提交
277

F
Fernando Serrano 已提交
278 279 280 281 282
				// ---------------------------------------------------------------------
				// Hierarchy
				// ---------------------------------------------------------------------
				var mapWood = new THREE.TextureLoader().load( 'textures/hardwood2_diffuse.jpg' );
				material = new THREE.MeshStandardMaterial( { map: mapWood, side: THREE.DoubleSide } );
F
Fernando Serrano 已提交
283

F
Fernando Serrano 已提交
284
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 40, 100, 100 ), material );
L
Lewy Blue 已提交
285
				object.position.set( - 200, 0, 400 );
F
Fernando Serrano 已提交
286
				object.name = "Cube";
287
				scene1.add( object );
F
Fernando Serrano 已提交
288

M
Mugen87 已提交
289
				var object2 = new THREE.Mesh( new THREE.BoxBufferGeometry( 40, 40, 40, 2, 2, 2 ), material );
F
Fernando Serrano 已提交
290
				object2.position.set( 0, 0, 50 );
F
Fernando Serrano 已提交
291
				object2.rotation.set( 0, 45, 0 );
F
Fernando Serrano 已提交
292
				object2.name = "SubCube";
F
Fernando Serrano 已提交
293
				object.add( object2 );
294

F
Fernando Serrano 已提交
295 296 297 298

				// ---------------------------------------------------------------------
				// Groups
				// ---------------------------------------------------------------------
F
Fernando Serrano 已提交
299
				var group1 = new THREE.Group();
F
Fernando Serrano 已提交
300
				group1.name = "Group";
301
				scene1.add( group1 );
F
Fernando Serrano 已提交
302

F
Fernando Serrano 已提交
303
				var group2 = new THREE.Group();
F
Fernando Serrano 已提交
304
				group2.name = "subGroup";
L
Lewy Blue 已提交
305
				group2.position.set( 0, 50, 0 );
F
Fernando Serrano 已提交
306
				group1.add( group2 );
307

M
Mugen87 已提交
308
				object2 = new THREE.Mesh( new THREE.BoxBufferGeometry( 30, 30, 30 ), material );
309
				object2.name = "Cube in group";
F
Fernando Serrano 已提交
310
				object2.position.set( 0, 0, 400 );
311 312
				group2.add( object2 );

F
Fernando Serrano 已提交
313
				// ---------------------------------------------------------------------
314
				// Triangle Strip
F
Fernando Serrano 已提交
315
				// ---------------------------------------------------------------------
316
				var geometry = new THREE.BufferGeometry();
L
Lewy Blue 已提交
317
				var positions = new Float32Array( [
F
Fernando Serrano 已提交
318 319 320 321 322 323
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 80, 0,
					80, 0, 80,
					80, 80, 80,
L
Lewy Blue 已提交
324
				] );
F
Fernando Serrano 已提交
325

L
Lewy Blue 已提交
326
				var colors = new Float32Array( [
F
Fernando Serrano 已提交
327 328 329 330 331 332
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
333
				] );
334 335

				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
F
Fernando Serrano 已提交
336
				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
337
				object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide, vertexColors: THREE.VertexColors } ) );
L
Lewy Blue 已提交
338
				object.position.set( 140, - 40, - 250 );
339
				object.setDrawMode( THREE.TriangleStripDrawMode );
F
Fernando Serrano 已提交
340
				object.name = 'Custom buffered';
L
Lewy Blue 已提交
341
				object.userData = { data: 'customdata', list: [ 1, 2, 3, 4 ] };
342

F
Fernando Serrano 已提交
343
				scene1.add( object );
344 345


F
Fernando Serrano 已提交
346
				// ---------------------------------------------------------------------
347
				// Line Strip
F
Fernando Serrano 已提交
348
				// ---------------------------------------------------------------------
349 350 351 352
				var geometry = new THREE.BufferGeometry();
				var numPoints = 100;
				var positions = new Float32Array( numPoints * 3 );

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

355 356 357
					positions[ i * 3 ] = i;
					positions[ i * 3 + 1 ] = Math.sin( i / 2 ) * 20;
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
358

359 360 361 362
				}

				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				object = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
363
				object.position.set( - 50, 0, - 200 );
F
Fernando Serrano 已提交
364
				scene1.add( object );
365 366


F
Fernando Serrano 已提交
367
				// ---------------------------------------------------------------------
368
				// Line Loop
F
Fernando Serrano 已提交
369
				// ---------------------------------------------------------------------
370 371
				var geometry = new THREE.BufferGeometry();
				var numPoints = 5;
F
Fernando Serrano 已提交
372
				var radius = 70;
373 374
				var positions = new Float32Array( numPoints * 3 );

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

377
					var s = i * Math.PI * 2 / numPoints;
L
Lewy Blue 已提交
378 379
					positions[ i * 3 ] = radius * Math.sin( s );
					positions[ i * 3 + 1 ] = radius * Math.cos( s );
380
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
381

382 383 384 385
				}

				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				object = new THREE.LineLoop( geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
386
				object.position.set( 0, 0, - 200 );
387

F
Fernando Serrano 已提交
388
				scene1.add( object );
389

390 391 392 393 394 395 396 397 398 399
				// ---------------------------------------------------------------------
				// Buffer geometry truncated (DrawRange)
				// ---------------------------------------------------------------------
				var geometry = new THREE.BufferGeometry();
				var numElements = 6;
				var outOfRange = 3;

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

L
Lewy Blue 已提交
400
				positions.set( [
401 402 403 404 405 406
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 0, 0,
					0, 80, 0,
					80, 80, 0
L
Lewy Blue 已提交
407
				] );
408

L
Lewy Blue 已提交
409
				colors.set( [
410 411 412 413 414 415
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
416
				] );
417 418 419 420 421 422 423

				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
				geometry.setDrawRange( 0, numElements );

				object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide, vertexColors: THREE.VertexColors } ) );
				object.name = 'Custom buffered truncated';
L
Lewy Blue 已提交
424
				object.position.set( 340, - 40, - 200 );
425 426 427

				scene1.add( object );

F
Fernando Serrano 已提交
428
				// ---------------------------------------------------------------------
F
Fernando Serrano 已提交
429
				// Points
F
Fernando Serrano 已提交
430
				// ---------------------------------------------------------------------
431 432
				var numPoints = 100;
				var pointsArray = new Float32Array( numPoints * 3 );
L
Lewy Blue 已提交
433 434 435
				for ( var i = 0; i < numPoints; i ++ ) {

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

F
Fernando Serrano 已提交
439 440
				}

F
Fernando Serrano 已提交
441
				var pointsGeo = new THREE.BufferGeometry();
F
Fernando Serrano 已提交
442
				pointsGeo.addAttribute( 'position', new THREE.BufferAttribute( pointsArray, 3 ) );
F
Fernando Serrano 已提交
443

F
Fernando Serrano 已提交
444
				var pointsMaterial = new THREE.PointsMaterial( { color: 0xffff00, size: 5 } );
F
Fernando Serrano 已提交
445 446
				var points = new THREE.Points( pointsGeo, pointsMaterial );
				points.name = "Points";
L
Lewy Blue 已提交
447
				points.position.set( - 200, 0, - 200 );
448
				scene1.add( points );
F
Fernando Serrano 已提交
449

450 451 452
				// ---------------------------------------------------------------------
				// Ortho camera
				// ---------------------------------------------------------------------
453
				var cameraOrtho = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 0.1, 10 );
454
				scene1.add( cameraOrtho );
F
Fernando Serrano 已提交
455
				cameraOrtho.name = 'OrthographicCamera';
F
Fernando Serrano 已提交
456

457
				material = new THREE.MeshLambertMaterial( {
458 459 460 461
					color: 0xffff00,
					side: THREE.DoubleSide
				} );

F
Fernando Serrano 已提交
462
				object = new THREE.Mesh( new THREE.CircleGeometry( 50, 20, 0, Math.PI * 2 ), material );
L
Lewy Blue 已提交
463
				object.position.set( 200, 0, - 400 );
464
				scene1.add( object );
F
Fernando Serrano 已提交
465 466

				object = new THREE.Mesh( new THREE.RingGeometry( 10, 50, 20, 5, 0, Math.PI * 2 ), material );
L
Lewy Blue 已提交
467
				object.position.set( 0, 0, - 400 );
468
				scene1.add( object );
F
Fernando Serrano 已提交
469 470

				object = new THREE.Mesh( new THREE.CylinderGeometry( 25, 75, 100, 40, 5 ), material );
L
Lewy Blue 已提交
471
				object.position.set( - 200, 0, - 400 );
472
				scene1.add( object );
473

F
Fernando Serrano 已提交
474 475 476 477 478 479 480 481 482 483
				//
				var points = [];

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

					points.push( new THREE.Vector2( Math.sin( i * 0.2 ) * Math.sin( i * 0.1 ) * 15 + 50, ( i - 5 ) * 2 ) );

				}

				object = new THREE.Mesh( new THREE.LatheGeometry( points, 20 ), material );
484
				object.position.set( 200, 0, 400 );
485
				scene1.add( object );
F
Fernando Serrano 已提交
486

487 488 489 490 491 492 493 494 495 496 497
				// ---------------------------------------------------------------------
				// Big red box hidden just for testing `onlyVisible` option
				// ---------------------------------------------------------------------
				material = new THREE.MeshBasicMaterial( {
					color: 0xff0000
				} );
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 200, 200, 200 ), material );
				object.position.set( 0, 0, 0 );
				object.name = "CubeHidden";
				object.visible = false;
				scene1.add( object );
F
Fernando Serrano 已提交
498

499 500 501 502 503 504 505 506
				// ---------------------------------------------------------------------
				//
				//
				var loader = new THREE.OBJLoader();
				loader.load( 'models/obj/walt/WaltHead.obj', function ( obj ) {

					waltHead = obj;
					waltHead.scale.multiplyScalar( 1.5 );
L
Lewy Blue 已提交
507
					waltHead.position.set( 400, 0, 0 );
508 509 510
					scene1.add( waltHead );

				} );
M
Mugen87 已提交
511 512


F
Fernando Serrano 已提交
513 514 515
				// ---------------------------------------------------------------------
				// 2nd Scene
				// ---------------------------------------------------------------------
516
				scene2 = new THREE.Scene();
517 518 519 520
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 100, 100, 100 ), material );
				object.position.set( 0, 0, 0 );
				object.name = "Cube2ndScene";
				scene2.name = 'Scene2';
L
Lewy Blue 已提交
521
				scene2.add( object );
522

F
Fernando Serrano 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
				//

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				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 已提交
558
				var timer = Date.now() * 0.0001;
F
Fernando Serrano 已提交
559

F
Fernando Serrano 已提交
560 561
				camera.position.x = Math.cos( timer ) * 800;
				camera.position.z = Math.sin( timer ) * 800;
F
Fernando Serrano 已提交
562

563 564
				camera.lookAt( scene1.position );
				renderer.render( scene1, camera );
F
Fernando Serrano 已提交
565 566 567 568 569 570 571

			}

		</script>

	</body>
</html>