Browse Source

Updated examples builds.

Mr.doob 3 years ago
parent
commit
0c5b9b7e4c

+ 10 - 10
examples/js/controls/ArcballControls.js

@@ -1707,8 +1707,8 @@
 				window.removeEventListener( 'pointermove', this.onPointerMove );
 				window.removeEventListener( 'pointerup', this.onPointerUp );
 				window.removeEventListener( 'resize', this.onWindowResize );
-				window.addEventListener( 'keydown', this.onKeyDown );
-				this.scene.remove( this._gizmos );
+				window.removeEventListener( 'keydown', this.onKeyDown );
+				if ( this.scene !== null ) this.scene.remove( this._gizmos );
 				this.disposeGrid();
 
 			};
@@ -1788,7 +1788,7 @@
 
 			this.setCamera = camera => {
 
-				camera.lookAt( this._tbCenter );
+				camera.lookAt( this.target );
 				camera.updateMatrix(); //setting state
 
 				if ( camera.type == 'PerspectiveCamera' ) {
@@ -1807,10 +1807,10 @@
 				this._zoom0 = camera.zoom;
 				this._zoomState = this._zoom0;
 				this._initialNear = camera.near;
-				this._nearPos0 = camera.position.distanceTo( this._tbCenter ) - camera.near;
+				this._nearPos0 = camera.position.distanceTo( this.target ) - camera.near;
 				this._nearPos = this._initialNear;
 				this._initialFar = camera.far;
-				this._farPos0 = camera.position.distanceTo( this._tbCenter ) - camera.far;
+				this._farPos0 = camera.position.distanceTo( this.target ) - camera.far;
 				this._farPos = this._initialFar;
 
 				this._up0.copy( camera.up );
@@ -1821,7 +1821,7 @@
 				this.camera.updateProjectionMatrix(); //making gizmos
 
 				this._tbRadius = this.calculateTbRadius( camera );
-				this.makeGizmos( this._tbCenter, this._tbRadius );
+				this.makeGizmos( this.target, this._tbRadius );
 
 			};
 
@@ -2283,14 +2283,14 @@
 
 			this.setTarget = ( x, y, z ) => {
 
-				this._tbCenter.set( x, y, z );
+				this.target.set( x, y, z );
 
 				this._gizmos.position.set( x, y, z ); //for correct radius calculation
 
 
 				this._tbRadius = this.calculateTbRadius( this.camera );
-				this.makeGizmos( this._tbCenter, this._tbRadius );
-				this.camera.lookAt( this._tbCenter );
+				this.makeGizmos( this.target, this._tbRadius );
+				this.camera.lookAt( this.target );
 
 			};
 
@@ -2680,6 +2680,7 @@
 			this.camera = null;
 			this.domElement = domElement;
 			this.scene = scene;
+			this.target = new THREE.Vector3( 0, 0, 0 );
 			this.mouseActions = [];
 			this._mouseOp = null; //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
 
@@ -2803,7 +2804,6 @@
 			this.minZoom = 0;
 			this.maxZoom = Infinity; //trackball parameters
 
-			this._tbCenter = new THREE.Vector3( 0, 0, 0 );
 			this._tbRadius = 1; //FSA
 
 			this._state = STATE.IDLE;

+ 1 - 1
examples/js/controls/OrbitControls.js

@@ -892,7 +892,7 @@
 
 			function onMouseWheel( event ) {
 
-				if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE && state !== STATE.ROTATE ) return;
+				if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE ) return;
 				event.preventDefault();
 				scope.dispatchEvent( _startEvent );
 				handleMouseWheel( event );

+ 1 - 1
examples/js/loaders/ColladaLoader.js

@@ -1422,7 +1422,6 @@
 
 				const effect = getEffect( data.url );
 				const technique = effect.profile.technique;
-				const extra = effect.profile.extra;
 				let material;
 
 				switch ( technique.type ) {
@@ -1598,6 +1597,7 @@
 								break;
 
 							default:
+								material.opacity = 1 - transparency.float;
 								console.warn( 'THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.', transparent.opaque );
 
 						}

+ 66 - 0
examples/js/loaders/GLTFLoader.js

@@ -23,6 +23,11 @@
 
 				return new GLTFTextureWebPExtension( parser );
 
+			} );
+			this.register( function ( parser ) {
+
+				return new GLTFMaterialsSheenExtension( parser );
+
 			} );
 			this.register( function ( parser ) {
 
@@ -336,6 +341,7 @@
 		KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
 		KHR_MATERIALS_IOR: 'KHR_materials_ior',
 		KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
+		KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
 		KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
 		KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
 		KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
@@ -588,6 +594,66 @@
 
 			}
 
+			return Promise.all( pending );
+
+		}
+
+	}
+	/**
+ * Sheen Materials Extension
+ *
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
+ */
+
+
+	class GLTFMaterialsSheenExtension {
+
+		constructor( parser ) {
+
+			this.parser = parser;
+			this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
+
+		}
+
+		getMaterialType( materialIndex ) {
+
+			const parser = this.parser;
+			const materialDef = parser.json.materials[ materialIndex ];
+			if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
+			return THREE.MeshPhysicalMaterial;
+
+		}
+
+		extendMaterialParams( materialIndex, materialParams ) {
+
+			const parser = this.parser;
+			const materialDef = parser.json.materials[ materialIndex ];
+
+			if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
+
+				return Promise.resolve();
+
+			}
+
+			const pending = [];
+			materialParams.sheenTint = new THREE.Color( 0, 0, 0 );
+			materialParams.sheenRoughness = 0;
+			materialParams.sheen = 1;
+			const extension = materialDef.extensions[ this.name ];
+
+			if ( extension.sheenColorFactor !== undefined ) {
+
+				materialParams.sheenTint.fromArray( extension.sheenColorFactor );
+
+			}
+
+			if ( extension.sheenRoughnessFactor !== undefined ) {
+
+				materialParams.sheenRoughness = extension.sheenRoughnessFactor;
+
+			} // TODO sheenColorTexture and sheenRoughnessTexture
+
+
 			return Promise.all( pending );
 
 		}