瀏覽代碼

Examples: More clean up. (#25183)

Michael Herzog 2 年之前
父節點
當前提交
c3bc5c8a9a

+ 1 - 0
examples/jsm/helpers/OctreeHelper.js

@@ -67,6 +67,7 @@ class OctreeHelper extends LineSegments {
 		this.material.dispose();
 
 	}
+
 }
 
 export { OctreeHelper };

+ 1 - 1
examples/jsm/interactive/HTMLMesh.js

@@ -36,7 +36,7 @@ class HTMLMesh extends Mesh {
 			material.dispose();
 
 			material.map.dispose();
-			
+
 			canvases.delete( dom );
 
 			this.removeEventListener( 'mousedown', onEvent );

+ 1 - 1
examples/jsm/interactive/InteractiveGroup.js

@@ -28,7 +28,7 @@ class InteractiveGroup extends Group {
 			event.stopPropagation();
 
 			const rect = renderer.domElement.getBoundingClientRect();
-			
+
 			_pointer.x = ( event.clientX - rect.left ) / rect.width * 2 - 1;
 			_pointer.y = - ( event.clientY - rect.top ) / rect.height * 2 + 1;
 

+ 2 - 2
examples/jsm/loaders/GLTFLoader.js

@@ -584,7 +584,7 @@ class GLTFLightsExtension {
 
 	}
 
-	getDependency( type, index ) {	
+	getDependency( type, index ) {
 
 		if ( type !== 'light' ) return;
 
@@ -2264,7 +2264,7 @@ class GLTFParser {
 
 		// Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
 		// expensive work of uploading a texture to the GPU off the main thread.
-		
+
 		let isSafari = false;
 		let isFirefox = false;
 		let firefoxVersion = - 1;

+ 1 - 2
examples/jsm/webxr/VRButton.js

@@ -174,8 +174,6 @@ class VRButton {
 
 	}
 
-	static xrSessionIsGranted = false;
-
 	static registerSessionGrantedListener() {
 
 		if ( 'xr' in navigator ) {
@@ -196,6 +194,7 @@ class VRButton {
 
 }
 
+VRButton.xrSessionIsGranted = false;
 VRButton.registerSessionGrantedListener();
 
 export { VRButton };

+ 1 - 1
examples/physics_ammo_instancing.html

@@ -138,7 +138,7 @@
 				controls.update();
 
 				animate();
-				
+			
 				setInterval( () => {
 
 					let index = Math.floor( Math.random() * boxes.count );

+ 2 - 2
examples/webgl_buffergeometry_compression.html

@@ -100,7 +100,7 @@
 				controls.enableZoom = false;
 
 				//
-				
+			
 				scene.add( new THREE.AmbientLight( 0xffffff, 0.1 ) );
 
 				lights[ 0 ] = new THREE.DirectionalLight( 0xffffff, 0.7 );
@@ -143,7 +143,7 @@
 						case 'Icosahedron':
 							return new THREE.IcosahedronGeometry( radius, data.detail );
 						case 'Cylinder':
-							return new THREE.CylinderGeometry( radius / 1.5 , radius / 1.5, radius, data.detail * 6 );
+							return new THREE.CylinderGeometry( radius / 1.5, radius / 1.5, radius, data.detail * 6 );
 						case 'Teapot':
 							return new TeapotGeometry( radius / 1.5, data.detail * 3, true, true, true, true, true );
 						case 'TorusKnot':

+ 3 - 3
examples/webgl_loader_svg.html

@@ -121,9 +121,9 @@
 					'Styles in svg tag': 'models/svg/tests/styles.svg',
 					'Round join': 'models/svg/tests/roundJoinPrecisionIssue.svg',
 					'Ellipse Transformations': 'models/svg/tests/ellipseTransform.svg',
-					"singlePointTest": 'models/svg/singlePointTest.svg',
-					"singlePointTest2": 'models/svg/singlePointTest2.svg',
-					"singlePointTest3": 'models/svg/singlePointTest3.svg',
+					'singlePointTest': 'models/svg/singlePointTest.svg',
+					'singlePointTest2': 'models/svg/singlePointTest2.svg',
+					'singlePointTest3': 'models/svg/singlePointTest3.svg',
 
 				} ).name( 'SVG File' ).onChange( update );
 

+ 4 - 2
examples/webgl_loader_usdz.html

@@ -40,7 +40,7 @@
 			import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
 			import { USDZLoader } from 'three/addons/loaders/USDZLoader.js';
 
-			let camera, controls, scene, renderer;
+			let camera, scene, renderer;
 
 			init();
 			animate();
@@ -69,7 +69,9 @@
 				renderer.outputEncoding = THREE.sRGBEncoding;
 				document.body.appendChild( renderer.domElement );
 
-				controls = new OrbitControls( camera, renderer.domElement );
+				const controls = new OrbitControls( camera, renderer.domElement );
+				controls.minDistance = 1;
+				controls.maxDistance = 8;
 
 				const loader = new USDZLoader();
 				loader.load( 'models/usdz/saeukkang.usdz', function ( usd ) {

+ 1 - 1
examples/webgl_materials_lightmap.html

@@ -31,7 +31,7 @@
 
 			import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
 
-			import { MeshBasicNodeMaterial, vec4, color, positionLocal, mix, max, pow } from 'three/nodes';
+			import { MeshBasicNodeMaterial, vec4, color, positionLocal, mix } from 'three/nodes';
 			import { nodeFrame } from 'three/addons/renderers/webgl/nodes/WebGLNodes.js';
 
 			let container, stats;

+ 35 - 35
examples/webgl_postprocessing_pixel.html

@@ -182,18 +182,18 @@
 
 			const rendererSize = renderer.getSize( new THREE.Vector2() );
 			const aspectRatio = rendererSize.x / rendererSize.y;
-			if ( params["pixelAlignedPanning"] ) {
+			if ( params[ 'pixelAlignedPanning' ] ) {
 
-				pixelAlignFrustum( camera, aspectRatio, Math.floor( rendererSize.x / params[ "pixelSize" ] ), 
-									Math.floor( rendererSize.y / params[ "pixelSize" ] ) );
+				pixelAlignFrustum( camera, aspectRatio, Math.floor( rendererSize.x / params[ 'pixelSize' ] ),
+					Math.floor( rendererSize.y / params[ 'pixelSize' ] ) );
 
 			} else if ( camera.left != - aspectRatio || camera.top != 1.0 ) {
 
 				// Reset the Camera Frustum if it has been modified
-				camera.left   = - aspectRatio;
-				camera.right  =   aspectRatio;
-				camera.top    =   1.0        ;
-				camera.bottom = - 1.0        ;
+				camera.left = - aspectRatio;
+				camera.right = aspectRatio;
+				camera.top = 1.0;
+				camera.bottom = - 1.0;
 				camera.updateProjectionMatrix();
 
 			}
@@ -241,34 +241,34 @@
 
 		function pixelAlignFrustum( camera, aspectRatio, pixelsPerScreenWidth, pixelsPerScreenHeight ) {
 
-				// 0. Get Pixel Grid Units
-				let worldScreenWidth  = ( ( camera.right - camera.left ) / camera.zoom );
-				let worldScreenHeight = ( ( camera.top - camera.bottom ) / camera.zoom );
-				let pixelWidth  = worldScreenWidth  / pixelsPerScreenWidth;
-				let pixelHeight = worldScreenHeight / pixelsPerScreenHeight;
-
-				// 1. Project the current camera position along its local rotation bases
-				let camPos      = new THREE.Vector3   ();   camera.getWorldPosition  ( camPos );
-				let camRot      = new THREE.Quaternion();   camera.getWorldQuaternion( camRot );
-				let camRight    = new THREE.Vector3( 1.0, 0.0, 0.0 ) .applyQuaternion( camRot );
-				let camUp       = new THREE.Vector3( 0.0, 1.0, 0.0 ) .applyQuaternion( camRot );
-				let camPosRight = camPos.dot( camRight );
-				let camPosUp    = camPos.dot( camUp );
-
-				// 2. Find how far along its position is along these bases in pixel units
-				let camPosRightPx = camPosRight / pixelWidth;
-				let camPosUpPx    = camPosUp    / pixelHeight;
-
-				// 3. Find the fractional pixel units and convert to world units
-				let fractX = camPosRightPx - Math.round( camPosRightPx );
-				let fractY = camPosUpPx    - Math.round(    camPosUpPx );
-
-				// 4. Add fractional world units to the left/right top/bottom to align with the pixel grid
-				camera.left   = - aspectRatio - ( fractX * pixelWidth  );
-				camera.right  =   aspectRatio - ( fractX * pixelWidth  );
-				camera.top    =   1.0         - ( fractY * pixelHeight );
-				camera.bottom = - 1.0         - ( fractY * pixelHeight );
-				camera.updateProjectionMatrix();
+			// 0. Get Pixel Grid Units
+			const worldScreenWidth = ( ( camera.right - camera.left ) / camera.zoom );
+			const worldScreenHeight = ( ( camera.top - camera.bottom ) / camera.zoom );
+			const pixelWidth = worldScreenWidth / pixelsPerScreenWidth;
+			const pixelHeight = worldScreenHeight / pixelsPerScreenHeight;
+
+			// 1. Project the current camera position along its local rotation bases
+			const camPos = new THREE.Vector3(); camera.getWorldPosition( camPos );
+			const camRot = new THREE.Quaternion(); camera.getWorldQuaternion( camRot );
+			const camRight = new THREE.Vector3( 1.0, 0.0, 0.0 ).applyQuaternion( camRot );
+			const camUp = new THREE.Vector3( 0.0, 1.0, 0.0 ).applyQuaternion( camRot );
+			const camPosRight = camPos.dot( camRight );
+			const camPosUp = camPos.dot( camUp );
+
+			// 2. Find how far along its position is along these bases in pixel units
+			const camPosRightPx = camPosRight / pixelWidth;
+			const camPosUpPx = camPosUp / pixelHeight;
+
+			// 3. Find the fractional pixel units and convert to world units
+			const fractX = camPosRightPx - Math.round( camPosRightPx );
+			const fractY = camPosUpPx - Math.round( camPosUpPx );
+
+			// 4. Add fractional world units to the left/right top/bottom to align with the pixel grid
+			camera.left = - aspectRatio - ( fractX * pixelWidth );
+			camera.right = aspectRatio - ( fractX * pixelWidth );
+			camera.top = 1.0 - ( fractY * pixelHeight );
+			camera.bottom = - 1.0 - ( fractY * pixelHeight );
+			camera.updateProjectionMatrix();
 
 		}
 		

+ 18 - 16
examples/webxr_ar_plane_detection.html

@@ -61,7 +61,7 @@
 				//
 
 				document.body.appendChild( ARButton.createButton( renderer, {
-					requiredFeatures: ['plane-detection']
+					requiredFeatures: [ 'plane-detection' ]
 				} ) );
 
 				//
@@ -74,26 +74,26 @@
 
 				} );
 
-				renderer.xr.addEventListener( 'planeadded', function (e) {
-				
-					console.log( "plane added", e.data )
-				
+				renderer.xr.addEventListener( 'planeadded', function ( e ) {
+			
+					console.log( 'plane added', e.data );
+			
 				} );
 
-				renderer.xr.addEventListener( 'planeremoved', function (e) {
-				
-					console.log( "plane removed", e.data )
-				
+				renderer.xr.addEventListener( 'planeremoved', function ( e ) {
+			
+					console.log( 'plane removed', e.data );
+			
 				} );
 
-				renderer.xr.addEventListener( 'planechanged', function (e) {
-				
-					console.log( "plane changed", e.data)
-				
+				renderer.xr.addEventListener( 'planechanged', function ( e ) {
+			
+					console.log( 'plane changed', e.data );
+			
 				} );
 
-				renderer.xr.addEventListener( 'planesdetected', function (e) {
-					
+				renderer.xr.addEventListener( 'planesdetected', function ( e ) {
+			
 					const detectedPlanes = e.data;
 					const referenceSpace = renderer.xr.getReferenceSpace();
 
@@ -102,7 +102,7 @@
 					detectedPlanes.forEach( plane => {
 
 						if ( planesAdded.has( plane ) ) return;
-						
+			
 						planesAdded.add( plane );
 						const frame = renderer.xr.getFrame();
 						const planePose = frame.getPose( plane.planeSpace, referenceSpace );
@@ -134,7 +134,9 @@
 						scene.add( boxMesh );
 
 					} );
+			
 				} );
+
 			}
 
 			function onWindowResize() {