Sfoglia il codice sorgente

Merge pull request #16625 from WestLangley/dev_rgbe_loader

RGBELoader: Set encoding based on output type
Mr.doob 6 anni fa
parent
commit
a0e2a726e9
2 ha cambiato i file con 35 aggiunte e 25 eliminazioni
  1. 34 0
      examples/js/loaders/RGBELoader.js
  2. 1 25
      examples/webgl_loader_texture_hdr.html

+ 34 - 0
examples/js/loaders/RGBELoader.js

@@ -391,3 +391,37 @@ THREE.RGBELoader.prototype.setType = function ( value ) {
 	return this;
 
 };
+
+THREE.RGBELoader.prototype.load = function ( url, onLoad, onProgress, onError ) {
+
+	function onLoadCallback( texture, texData ) {
+
+		switch ( texture.type ) {
+
+			case THREE.UnsignedByteType:
+
+				texture.encoding = THREE.RGBEEncoding;
+				texture.minFilter = THREE.NearestFilter;
+				texture.magFilter = THREE.NearestFilter;
+				texture.generateMipmaps = false;
+				texture.flipY = true;
+				break;
+
+			case THREE.FloatType:
+
+				texture.encoding = THREE.LinearEncoding;
+				texture.minFilter = THREE.LinearFilter;
+				texture.magFilter = THREE.LinearFilter;
+				texture.generateMipmaps = false;
+				texture.flipY = true;
+				break;
+
+		}
+
+		if ( onLoad ) onLoad( texture, texData );
+
+	}
+
+	return THREE.DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
+
+};

+ 1 - 25
examples/webgl_loader_texture_hdr.html

@@ -54,34 +54,10 @@
 
 				camera = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 0, 1 );
 
-				var type = THREE.UnsignedByteType;
-				//var type = THREE.FloatType;
-
 				new THREE.RGBELoader()
-					.setType( type )
+					.setType( THREE.UnsignedByteType ) // alt: THREE.FloatType
 					.load( 'textures/memorial.hdr', function ( texture, textureData ) {
 
-						switch ( type ) {
-
-							case THREE.UnsignedByteType:
-
-								texture.encoding = THREE.RGBEEncoding;
-								texture.minFilter = THREE.NearestFilter;
-								texture.magFilter = THREE.NearestFilter;
-								break;
-
-							case THREE.FloatType:
-
-								texture.encoding = THREE.LinearEncoding;
-								texture.minFilter = THREE.LinearFilter;
-								texture.magFilter = THREE.LinearFilter;
-								break;
-
-						}
-
-						texture.generateMipmaps = false;
-						texture.flipY = true;
-
 						//console.log( textureData );
 						//console.log( texture );