Переглянути джерело

Examples: Clean up. (#21947)

* Examples: Clean up.

* Examples: More clean up.

* Examples: More clean up.
Michael Herzog 4 роки тому
батько
коміт
dcc318f2c7

+ 1 - 1
examples/webgl2_multiple_rendertargets.html

@@ -213,7 +213,7 @@
 				controls.enableZoom = false;
 				controls.screenSpacePanning = true;
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl2_rendertarget_texture2darray.html

@@ -179,7 +179,7 @@
 				stats = new Stats();
 				container.appendChild( stats.dom );
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 				const gui = new GUI();
 

+ 1 - 1
examples/webgl_loader_gltf_compressed.html

@@ -87,7 +87,7 @@
 				controls.target.set( 10, 90, - 16 );
 				controls.update();
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl_loader_pdb.html

@@ -156,7 +156,7 @@
 
 					const url = 'models/pdb/' + MOLECULES[ m ];
 
-					button.addEventListener( 'click', generateButtonCallback( url ), false );
+					button.addEventListener( 'click', generateButtonCallback( url ) );
 
 				}
 

+ 1 - 1
examples/webgl_mirror.html

@@ -160,7 +160,7 @@
 				blueLight.position.set( 0, 50, 550 );
 				scene.add( blueLight );
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl_mirror_nodes.html

@@ -84,7 +84,7 @@
 				const container = document.getElementById( 'container' );
 				container.appendChild( renderer.domElement );
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl_modifier_curve.html

@@ -154,7 +154,7 @@
 				stats = new Stats();
 				document.body.appendChild( stats.dom );
 
-				window.addEventListener( "resize", onWindowResize, false );
+				window.addEventListener( "resize", onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl_modifier_curve_instanced.html

@@ -184,7 +184,7 @@
 				stats = new Stats();
 				document.body.appendChild( stats.dom );
 
-				window.addEventListener( "resize", onWindowResize, false );
+				window.addEventListener( "resize", onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl_portal.html

@@ -161,7 +161,7 @@
 				blueLight.position.set( 0, 50, 550 );
 				scene.add( blueLight );
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 			}
 

+ 1 - 1
examples/webgl_postprocessing_ssr.html

@@ -160,7 +160,7 @@
 			stats = new Stats();
 			container.appendChild( stats.dom );
 
-			window.addEventListener( 'resize', onWindowResize, false );
+			window.addEventListener( 'resize', onWindowResize );
 
 			// composer
 

+ 104 - 94
examples/webgl_postprocessing_ssrr.html

@@ -17,7 +17,7 @@
 		SSRrPass demo by <a href="https://github.com/gonnavis" target="_blank">Vis</a>.<br />
 		click object to toggle transparent<br/>
 	</div>
-	
+
 	<script type="module">
 		import * as THREE from '../build/three.module.js';
 
@@ -47,131 +47,131 @@
 		const mouseDown = new THREE.Vector2();
 		const mouse = new THREE.Vector2();
 
-		const container = document.querySelector('#container');
+		const container = document.querySelector( '#container' );
 
 		// Configure and create Draco decoder.
 		const dracoLoader = new DRACOLoader();
-		dracoLoader.setDecoderPath('js/libs/draco/');
-		dracoLoader.setDecoderConfig({ type: 'js' });
+		dracoLoader.setDecoderPath( 'js/libs/draco/' );
+		dracoLoader.setDecoderConfig( { type: 'js' } );
 
 		init();
 		animate();
 
 		function init() {
 
-			camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 15);
-			camera.position.set(0.13271600513224902, 0.3489546826045913, 0.43921296427927076);
+			camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 15 );
+			camera.position.set( 0.13271600513224902, 0.3489546826045913, 0.43921296427927076 );
 
 			scene = new THREE.Scene();
-			scene.background = new THREE.Color(0x443333);
-			scene.fog = new THREE.Fog(0x443333, 1, 4);
+			scene.background = new THREE.Color( 0x443333 );
+			scene.fog = new THREE.Fog( 0x443333, 1, 4 );
 
 			// Ground
-			let map=new THREE.TextureLoader().load('./textures/uv_grid_opengl.jpg')
+			const map = new THREE.TextureLoader().load( './textures/uv_grid_opengl.jpg' );
 			map.wrapS = THREE.RepeatWrapping;
 			map.wrapT = THREE.RepeatWrapping;
-			map.repeat.set(20,20)
+			map.repeat.set( 20, 20 );
 			const plane = new THREE.Mesh(
-				new THREE.PlaneGeometry(8, 8),
-				new THREE.MeshPhongMaterial({ 
-					color: 0x999999, 
+				new THREE.PlaneGeometry( 8, 8 ),
+				new THREE.MeshPhongMaterial( {
+					color: 0x999999,
 					specular: 0x101010,
 					map,
-				})
+				} )
 			);
 			plane.rotation.x = - Math.PI / 2;
 			plane.position.y = - 0.0001;
 			// plane.receiveShadow = true;
-			scene.add(plane);
-			plane.name='plane'
+			scene.add( plane );
+			plane.name = 'plane';
 
 			// Lights
-			const hemiLight = new THREE.HemisphereLight(0x443333, 0x111122);
-			hemiLight.name='hemiLight'
-			scene.add(hemiLight);
+			const hemiLight = new THREE.HemisphereLight( 0x443333, 0x111122 );
+			hemiLight.name = 'hemiLight';
+			scene.add( hemiLight );
 
 			const spotLight = new THREE.SpotLight();
-			spotLight.name='spotLight'
+			spotLight.name = 'spotLight';
 			spotLight.angle = Math.PI / 16;
 			spotLight.penumbra = 0.5;
 			// spotLight.castShadow = true;
-			spotLight.position.set(- 1, 1, 1);
-			scene.add(spotLight);
+			spotLight.position.set( - 1, 1, 1 );
+			scene.add( spotLight );
 
-			dracoLoader.load('models/draco/bunny.drc', function (geometry) {
+			dracoLoader.load( 'models/draco/bunny.drc', function ( geometry ) {
 
 				geometry.computeVertexNormals();
 
-				const material = new THREE.MeshStandardMaterial({ color: 0x606060 });
-				const mesh = new THREE.Mesh(geometry, material);
+				const material = new THREE.MeshStandardMaterial( { color: 0x606060 } );
+				const mesh = new THREE.Mesh( geometry, material );
 				mesh.position.y = - 0.0365;
-				mesh.name='bunny'
-				scene.add(mesh);
-				objects.push(mesh);
-				selects.push(mesh);
+				mesh.name = 'bunny';
+				scene.add( mesh );
+				objects.push( mesh );
+				selects.push( mesh );
 
 				// Release decoder resources.
 				dracoLoader.dispose();
 
-			});
+			} );
 
 			let geometry, material, mesh;
 
-			geometry = new THREE.BoxBufferGeometry(.05, .05, .05);
-			material = new THREE.MeshStandardMaterial({ color: 'green' });
-			mesh = new THREE.Mesh(geometry, material);
-			mesh.position.set(- .12, .025, .015);
-			mesh.name='box'
-			scene.add(mesh);
+			geometry = new THREE.BoxBufferGeometry( .05, .05, .05 );
+			material = new THREE.MeshStandardMaterial( { color: 'green' } );
+			mesh = new THREE.Mesh( geometry, material );
+			mesh.position.set( - .12, .025, .015 );
+			mesh.name = 'box';
+			scene.add( mesh );
 			objects.push( mesh );
 			selects.push( mesh );
 
-			geometry = new THREE.IcosahedronBufferGeometry(.025, 4);
-			material = new THREE.MeshStandardMaterial({ color: 'cyan' });
-			mesh = new THREE.Mesh(geometry, material);
-			mesh.position.set(- .05, .025, .08);
-			mesh.name='sphere'
-			scene.add(mesh);
+			geometry = new THREE.IcosahedronBufferGeometry( .025, 4 );
+			material = new THREE.MeshStandardMaterial( { color: 'cyan' } );
+			mesh = new THREE.Mesh( geometry, material );
+			mesh.position.set( - .05, .025, .08 );
+			mesh.name = 'sphere';
+			scene.add( mesh );
 			objects.push( mesh );
 			// selects.push( mesh );
 
-			geometry = new THREE.ConeBufferGeometry(.025, .05, 64);
-			material = new THREE.MeshStandardMaterial({ color: 'yellow' });
-			mesh = new THREE.Mesh(geometry, material);
-			mesh.position.set(- .05, .025, - .055);
-			mesh.name='cone'
-			scene.add(mesh);
+			geometry = new THREE.ConeBufferGeometry( .025, .05, 64 );
+			material = new THREE.MeshStandardMaterial( { color: 'yellow' } );
+			mesh = new THREE.Mesh( geometry, material );
+			mesh.position.set( - .05, .025, - .055 );
+			mesh.name = 'cone';
+			scene.add( mesh );
 			objects.push( mesh );
 			// selects.push( mesh );
 
 			// renderer
-			renderer = new THREE.WebGLRenderer({ antialias: false });
-			renderer.setSize(window.innerWidth, window.innerHeight);
+			renderer = new THREE.WebGLRenderer( { antialias: false } );
+			renderer.setSize( window.innerWidth, window.innerHeight );
 			renderer.outputEncoding = THREE.sRGBEncoding;
-			renderer.autoClear=false
-			container.appendChild(renderer.domElement);
+			renderer.autoClear = false;
+			container.appendChild( renderer.domElement );
 
 			//
 
-			controls = new OrbitControls(camera, renderer.domElement);
+			controls = new OrbitControls( camera, renderer.domElement );
 			controls.enableDamping = true;
-			controls.target.set(0, 0.0635, 0);
+			controls.target.set( 0, 0.0635, 0 );
 			controls.update();
-			controls.enabled = !params.autoRotate;
+			controls.enabled = ! params.autoRotate;
 
 			// STATS
 
 			stats = new Stats();
-			container.appendChild(stats.dom);
+			container.appendChild( stats.dom );
 
-			window.addEventListener('resize', onWindowResize, false);
-			window.addEventListener( 'pointerdown', onPointerDown, false );
-			window.addEventListener( 'pointerup', onPointerUp, false );
+			window.addEventListener( 'resize', onWindowResize );
+			window.addEventListener( 'pointerdown', onPointerDown );
+			window.addEventListener( 'pointerup', onPointerUp );
 
 			// composer
 
-			composer = new EffectComposer(renderer);
-			ssrrPass = new SSRrPass({
+			composer = new EffectComposer( renderer );
+			ssrrPass = new SSRrPass( {
 				renderer,
 				scene,
 				camera,
@@ -179,28 +179,28 @@
 				height: innerHeight,
 				encoding: THREE.sRGBEncoding,
 				selects: selects
-			});
+			} );
 
-			composer.addPass(ssrrPass);
+			composer.addPass( ssrrPass );
 
 			// GUI
 
 			gui = new GUI();
-			gui.add(params, 'enableSSRr').name('Enable SSRr');
+			gui.add( params, 'enableSSRr' ).name( 'Enable SSRr' );
 			ssrrPass.ior = 1.1;
-			gui.add(ssrrPass, 'ior').name('IOR').min(1).max(1.5).step(.0001);
+			gui.add( ssrrPass, 'ior' ).name( 'IOR' ).min( 1 ).max( 1.5 ).step( .0001 );
 			gui.add( ssrrPass, 'fillHole' );
-			gui.add(params, 'autoRotate').onChange(() => {
+			gui.add( params, 'autoRotate' ).onChange( () => {
 
-				controls.enabled = !params.autoRotate;
+				controls.enabled = ! params.autoRotate;
 
-			});
+			} );
 
-			const folder = gui.addFolder('more settings');
+			const folder = gui.addFolder( 'more settings' );
 			folder.add( ssrrPass, 'specular' );
-			folder.add(ssrrPass.specularMaterial, 'metalness').min(0).max(1).step(.01);
-			folder.add(ssrrPass.specularMaterial, 'roughness').min(0).max(1).step(.01);
-			folder.add(ssrrPass, 'output', {
+			folder.add( ssrrPass.specularMaterial, 'metalness' ).min( 0 ).max( 1 ).step( .01 );
+			folder.add( ssrrPass.specularMaterial, 'roughness' ).min( 0 ).max( 1 ).step( .01 );
+			folder.add( ssrrPass, 'output', {
 				'Default': SSRrPass.OUTPUT.Default,
 				'SSRr Only': SSRrPass.OUTPUT.SSRr,
 				'Beauty': SSRrPass.OUTPUT.Beauty,
@@ -209,15 +209,15 @@
 				'NormalSelects': SSRrPass.OUTPUT.NormalSelects,
 				'Refractive': SSRrPass.OUTPUT.Refractive,
 				'Specular': SSRrPass.OUTPUT.Specular,
-			}).onChange(function (value) {
+			} ).onChange( function ( value ) {
 
-				ssrrPass.output = parseInt(value);
+				ssrrPass.output = parseInt( value );
 
-			});
+			} );
 			ssrrPass.surfDist = 0.0015;
 			folder.add( ssrrPass, 'surfDist' ).min( 0 ).max( .005 ).step( .0001 );
 			ssrrPass.maxDistance = 50;
-			folder.add( ssrrPass, 'maxDistance' ).min( 0 ).max( 100 ).step( .001 )
+			folder.add( ssrrPass, 'maxDistance' ).min( 0 ).max( 100 ).step( .001 );
 			folder.add( ssrrPass, 'infiniteThick' );
 			// folder.open()
 			// gui.close()
@@ -225,9 +225,12 @@
 		}
 
 		function onPointerDown( event ) {
+
 			mouseDown.x = ( event.clientX / window.innerWidth ) * 2 - 1;
 			mouseDown.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
+
 		}
+
 		function onPointerUp( event ) {
 
 			// calculate mouse position in normalized device coordinates
@@ -236,35 +239,42 @@
 			mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
 			mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
 
-			if(mouseDown.sub(mouse).length()>0) return
+			if ( mouseDown.sub( mouse ).length() > 0 ) return;
 
 
 			raycaster.setFromCamera( mouse, camera );
-			const intersect = raycaster.intersectObjects( objects )[0];
-			if(intersect){
-				let index=selects.indexOf(intersect.object)
-				if(index>=0){
-					selects.splice(index,1)
-				}else{
-					selects.push(intersect.object)
+			const intersect = raycaster.intersectObjects( objects )[ 0 ];
+
+			if ( intersect ) {
+
+				const index = selects.indexOf( intersect.object );
+				if ( index >= 0 ) {
+
+					selects.splice( index, 1 );
+
+				} else {
+
+					selects.push( intersect.object );
+
 				}
+
 			}
-		}
 
+		}
 
 		function onWindowResize() {
 
 			camera.aspect = window.innerWidth / window.innerHeight;
 			camera.updateProjectionMatrix();
 
-			renderer.setSize(window.innerWidth, window.innerHeight);
-			composer.setSize(window.innerWidth, window.innerHeight);
+			renderer.setSize( window.innerWidth, window.innerHeight );
+			composer.setSize( window.innerWidth, window.innerHeight );
 
 		}
 
 		function animate() {
 
-			requestAnimationFrame(animate);
+			requestAnimationFrame( animate );
 
 			stats.begin();
 			render();
@@ -274,14 +284,14 @@
 
 		function render() {
 
-			if (params.autoRotate) {
+			if ( params.autoRotate ) {
 
 				const timer = Date.now() * 0.0003;
 
-				camera.position.x = Math.sin(timer) * 0.5;
+				camera.position.x = Math.sin( timer ) * 0.5;
 				camera.position.y = 0.2135;
-				camera.position.z = Math.cos(timer) * 0.5;
-				camera.lookAt(0, 0.0635, 0);
+				camera.position.z = Math.cos( timer ) * 0.5;
+				camera.lookAt( 0, 0.0635, 0 );
 
 			} else {
 
@@ -289,13 +299,13 @@
 
 			}
 
-			if (params.enableSSRr) {
+			if ( params.enableSSRr ) {
 
 				composer.render();
 
 			} else {
 
-				renderer.render(scene, camera);
+				renderer.render( scene, camera );
 
 			}
 

+ 1 - 1
examples/webgpu_lights_custom.html

@@ -132,7 +132,7 @@
 
 				// events
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 				//
 

+ 2 - 2
examples/webgpu_rtt.html

@@ -80,8 +80,8 @@
 				textureRenderer = new WebGPUTextureRenderer( renderer );
 				textureRenderer.setSize( window.innerWidth * dpr, window.innerHeight * dpr );
 
-				window.addEventListener( 'mousemove', onWindowMouseMove, false );
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'mousemove', onWindowMouseMove );
+				window.addEventListener( 'resize', onWindowResize );
 
 				// FX
 

+ 1 - 1
examples/webxr_ar_lighting.html

@@ -148,7 +148,7 @@
 
 				//
 
-				window.addEventListener( 'resize', onWindowResize, false );
+				window.addEventListener( 'resize', onWindowResize );
 
 			}