misc_exporter_gltf.html 16.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
Mugen87 已提交
11
			<a href="https://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
			<label><input id="option_maxsize" name="maxSize" type="number" value="4096" min="2" max="8192" step="1"> Max texture size</label>
26
		</div>
F
Fernando Serrano 已提交
27

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

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

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

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

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

39
				var options = {
L
Lewy Blue 已提交
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,
45 46
					forcePowerOfTwoTextures: document.getElementById( 'option_forcepot' ).checked,
					maxTextureSize: Number( document.getElementById( 'option_maxsize' ).value ) || Infinity // To prevent NaN value
47
				};
L
Lewy Blue 已提交
48
				gltfExporter.parse( input, function ( result ) {
F
Fernando Serrano 已提交
49

50 51 52 53 54 55 56 57 58 59 60
					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 已提交
61

62
				}, options );
F
Fernando Serrano 已提交
63

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

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

			} );

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

				exportGLTF( waltHead );

			} );

90 91 92 93
			document.getElementById( 'export_objects' ).addEventListener( 'click', function () {

				exportGLTF( [ sphere, gridHelper ] );

94
			} );
F
Fernando Serrano 已提交
95

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

				exportGLTF( [ scene1, gridHelper ] );

			} );


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

107
			function save( blob, filename ) {
F
Fernando Serrano 已提交
108

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

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

115 116 117
			}

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

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

			}


			function saveArrayBuffer( buffer, filename ) {

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

128
			}
F
Fernando Serrano 已提交
129

130
			var container;
F
Fernando Serrano 已提交
131

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

			init();
			animate();

			function init() {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

F
Fernando Serrano 已提交
260

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

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

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

F
Fernando Serrano 已提交
278 279 280 281

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

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

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

F
Fernando Serrano 已提交
296
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
297
				// THREE.Line Strip
F
Fernando Serrano 已提交
298
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
299
				var geometry = new THREE.BufferGeometry();
300 301 302
				var numPoints = 100;
				var positions = new Float32Array( numPoints * 3 );

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

305 306 307
					positions[ i * 3 ] = i;
					positions[ i * 3 + 1 ] = Math.sin( i / 2 ) * 20;
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
308

309 310
				}

311
				geometry.setAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
M
Mr.doob 已提交
312
				object = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
313
				object.position.set( - 50, 0, - 200 );
F
Fernando Serrano 已提交
314
				scene1.add( object );
315 316


F
Fernando Serrano 已提交
317
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
318
				// THREE.Line Loop
F
Fernando Serrano 已提交
319
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
320
				var geometry = new THREE.BufferGeometry();
321
				var numPoints = 5;
F
Fernando Serrano 已提交
322
				var radius = 70;
323 324
				var positions = new Float32Array( numPoints * 3 );

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

327
					var s = i * Math.PI * 2 / numPoints;
L
Lewy Blue 已提交
328 329
					positions[ i * 3 ] = radius * Math.sin( s );
					positions[ i * 3 + 1 ] = radius * Math.cos( s );
330
					positions[ i * 3 + 2 ] = 0;
L
Lewy Blue 已提交
331

332 333
				}

334
				geometry.setAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
M
Mr.doob 已提交
335
				object = new THREE.LineLoop( geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
L
Lewy Blue 已提交
336
				object.position.set( 0, 0, - 200 );
337

F
Fernando Serrano 已提交
338
				scene1.add( object );
339

340 341 342
				// ---------------------------------------------------------------------
				// Buffer geometry truncated (DrawRange)
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
343
				var geometry = new THREE.BufferGeometry();
344 345 346 347 348 349
				var numElements = 6;
				var outOfRange = 3;

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

L
Lewy Blue 已提交
350
				positions.set( [
351 352 353 354 355 356
					0, 0, 0,
					0, 80, 0,
					80, 0, 0,
					80, 0, 0,
					0, 80, 0,
					80, 80, 0
L
Lewy Blue 已提交
357
				] );
358

L
Lewy Blue 已提交
359
				colors.set( [
360 361 362 363 364 365
					1, 0, 0,
					1, 0, 0,
					1, 1, 0,
					1, 1, 0,
					0, 0, 1,
					0, 0, 1,
L
Lewy Blue 已提交
366
				] );
367

368 369
				geometry.setAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
				geometry.setAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
370 371
				geometry.setDrawRange( 0, numElements );

M
Mr.doob 已提交
372
				object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide, vertexColors: THREE.VertexColors } ) );
373
				object.name = 'Custom buffered truncated';
M
Mugen87 已提交
374
				object.position.set( 140, - 40, - 200 );
375 376 377

				scene1.add( object );

F
Fernando Serrano 已提交
378
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
379
				// THREE.Points
F
Fernando Serrano 已提交
380
				// ---------------------------------------------------------------------
381 382
				var numPoints = 100;
				var pointsArray = new Float32Array( numPoints * 3 );
L
Lewy Blue 已提交
383 384 385
				for ( var i = 0; i < numPoints; i ++ ) {

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

F
Fernando Serrano 已提交
389 390
				}

M
Mr.doob 已提交
391
				var pointsGeo = new THREE.BufferGeometry();
392
				pointsGeo.setAttribute( 'position', new THREE.BufferAttribute( pointsArray, 3 ) );
F
Fernando Serrano 已提交
393

M
Mr.doob 已提交
394 395
				var pointsMaterial = new THREE.PointsMaterial( { color: 0xffff00, size: 5 } );
				var points = new THREE.Points( pointsGeo, pointsMaterial );
F
Fernando Serrano 已提交
396
				points.name = "Points";
L
Lewy Blue 已提交
397
				points.position.set( - 200, 0, - 200 );
398
				scene1.add( points );
F
Fernando Serrano 已提交
399

400 401 402
				// ---------------------------------------------------------------------
				// Ortho camera
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
403
				var cameraOrtho = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 0.1, 10 );
404
				scene1.add( cameraOrtho );
F
Fernando Serrano 已提交
405
				cameraOrtho.name = 'OrthographicCamera';
F
Fernando Serrano 已提交
406

M
Mr.doob 已提交
407
				material = new THREE.MeshLambertMaterial( {
408
					color: 0xffff00,
M
Mr.doob 已提交
409
					side: THREE.DoubleSide
410 411
				} );

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

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

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

F
Fernando Serrano 已提交
424 425 426 427 428
				//
				var points = [];

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

M
Mr.doob 已提交
429
					points.push( new THREE.Vector2( Math.sin( i * 0.2 ) * Math.sin( i * 0.1 ) * 15 + 50, ( i - 5 ) * 2 ) );
F
Fernando Serrano 已提交
430 431 432

				}

M
Mr.doob 已提交
433
				object = new THREE.Mesh( new THREE.LatheBufferGeometry( points, 20 ), material );
434
				object.position.set( 200, 0, 400 );
435
				scene1.add( object );
F
Fernando Serrano 已提交
436

437 438 439
				// ---------------------------------------------------------------------
				// Big red box hidden just for testing `onlyVisible` option
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
440
				material = new THREE.MeshBasicMaterial( {
441 442
					color: 0xff0000
				} );
M
Mr.doob 已提交
443
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 200, 200, 200 ), material );
444 445 446 447
				object.position.set( 0, 0, 0 );
				object.name = "CubeHidden";
				object.visible = false;
				scene1.add( object );
F
Fernando Serrano 已提交
448

449 450 451
				// ---------------------------------------------------------------------
				//
				//
M
Mugen87 已提交
452
				var loader = new OBJLoader();
453 454 455 456
				loader.load( 'models/obj/walt/WaltHead.obj', function ( obj ) {

					waltHead = obj;
					waltHead.scale.multiplyScalar( 1.5 );
L
Lewy Blue 已提交
457
					waltHead.position.set( 400, 0, 0 );
458 459 460
					scene1.add( waltHead );

				} );
M
Mugen87 已提交
461 462


F
Fernando Serrano 已提交
463
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
464
				// 2nd THREE.Scene
F
Fernando Serrano 已提交
465
				// ---------------------------------------------------------------------
M
Mr.doob 已提交
466 467
				scene2 = new THREE.Scene();
				object = new THREE.Mesh( new THREE.BoxBufferGeometry( 100, 100, 100 ), material );
468 469 470
				object.position.set( 0, 0, 0 );
				object.name = "Cube2ndScene";
				scene2.name = 'Scene2';
L
Lewy Blue 已提交
471
				scene2.add( object );
472

F
Fernando Serrano 已提交
473 474
				//

M
Mr.doob 已提交
475
				renderer = new THREE.WebGLRenderer( { antialias: true } );
F
Fernando Serrano 已提交
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
				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 已提交
508
				var timer = Date.now() * 0.0001;
F
Fernando Serrano 已提交
509

F
Fernando Serrano 已提交
510 511
				camera.position.x = Math.cos( timer ) * 800;
				camera.position.z = Math.sin( timer ) * 800;
F
Fernando Serrano 已提交
512

513 514
				camera.lookAt( scene1.position );
				renderer.render( scene1, camera );
F
Fernando Serrano 已提交
515 516 517 518 519 520 521

			}

		</script>

	</body>
</html>