Browse Source

DataTextureLoader: Refactor parsing.

Mugen87 5 năm trước cách đây
mục cha
commit
364ab4698e

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 624 - 627
examples/js/loaders/EXRLoader.js


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

@@ -79,7 +79,7 @@ THREE.HDRCubeTextureLoader.prototype = Object.assign( Object.create( THREE.Loade
 
 					loaded ++;
 
-					var texData = scope.hdrLoader._parser( buffer );
+					var texData = scope.hdrLoader.parse( buffer );
 
 					if ( ! texData ) return;
 

+ 335 - 338
examples/js/loaders/RGBELoader.js

@@ -7,523 +7,520 @@
 
 THREE.RGBELoader = function ( manager ) {
 
-	this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
+	THREE.DataTextureLoader.call( this, manager );
+
 	this.type = THREE.UnsignedByteType;
 
 };
 
-// extend THREE.DataTextureLoader
-THREE.RGBELoader.prototype = Object.create( THREE.DataTextureLoader.prototype );
+THREE.RGBELoader.prototype = Object.assign( Object.create( THREE.DataTextureLoader.prototype ), {
 
-// adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
-THREE.RGBELoader.prototype._parser = function ( buffer ) {
+	constructor: THREE.RGBELoader,
 
-	var
-		/* return codes for rgbe routines */
-		//RGBE_RETURN_SUCCESS = 0,
-		RGBE_RETURN_FAILURE = - 1,
+	// adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
 
-		/* default error routine.  change this to change error handling */
-		rgbe_read_error = 1,
-		rgbe_write_error = 2,
-		rgbe_format_error = 3,
-		rgbe_memory_error = 4,
-		rgbe_error = function ( rgbe_error_code, msg ) {
+	parse: function ( buffer ) {
 
-			switch ( rgbe_error_code ) {
+		var
+			/* return codes for rgbe routines */
+			//RGBE_RETURN_SUCCESS = 0,
+			RGBE_RETURN_FAILURE = - 1,
 
-				case rgbe_read_error: console.error( "THREE.RGBELoader Read Error: " + ( msg || '' ) );
-					break;
-				case rgbe_write_error: console.error( "THREE.RGBELoader Write Error: " + ( msg || '' ) );
-					break;
-				case rgbe_format_error: console.error( "THREE.RGBELoader Bad File Format: " + ( msg || '' ) );
-					break;
-				default:
-				case rgbe_memory_error: console.error( "THREE.RGBELoader: Error: " + ( msg || '' ) );
+			/* default error routine.  change this to change error handling */
+			rgbe_read_error = 1,
+			rgbe_write_error = 2,
+			rgbe_format_error = 3,
+			rgbe_memory_error = 4,
+			rgbe_error = function ( rgbe_error_code, msg ) {
 
-			}
-			return RGBE_RETURN_FAILURE;
+				switch ( rgbe_error_code ) {
 
-		},
+					case rgbe_read_error: console.error( "THREE.RGBELoader Read Error: " + ( msg || '' ) );
+						break;
+					case rgbe_write_error: console.error( "THREE.RGBELoader Write Error: " + ( msg || '' ) );
+						break;
+					case rgbe_format_error: console.error( "THREE.RGBELoader Bad File Format: " + ( msg || '' ) );
+						break;
+					default:
+					case rgbe_memory_error: console.error( "THREE.RGBELoader: Error: " + ( msg || '' ) );
 
-		/* offsets to red, green, and blue components in a data (float) pixel */
-		//RGBE_DATA_RED = 0,
-		//RGBE_DATA_GREEN = 1,
-		//RGBE_DATA_BLUE = 2,
+				}
+				return RGBE_RETURN_FAILURE;
 
-		/* number of floats per pixel, use 4 since stored in rgba image format */
-		//RGBE_DATA_SIZE = 4,
+			},
 
-		/* flags indicating which fields in an rgbe_header_info are valid */
-		RGBE_VALID_PROGRAMTYPE = 1,
-		RGBE_VALID_FORMAT = 2,
-		RGBE_VALID_DIMENSIONS = 4,
+			/* offsets to red, green, and blue components in a data (float) pixel */
+			//RGBE_DATA_RED = 0,
+			//RGBE_DATA_GREEN = 1,
+			//RGBE_DATA_BLUE = 2,
 
-		NEWLINE = "\n",
+			/* number of floats per pixel, use 4 since stored in rgba image format */
+			//RGBE_DATA_SIZE = 4,
 
-		fgets = function ( buffer, lineLimit, consume ) {
+			/* flags indicating which fields in an rgbe_header_info are valid */
+			RGBE_VALID_PROGRAMTYPE = 1,
+			RGBE_VALID_FORMAT = 2,
+			RGBE_VALID_DIMENSIONS = 4,
 
-			lineLimit = ! lineLimit ? 1024 : lineLimit;
-			var p = buffer.pos,
-				i = - 1, len = 0, s = '', chunkSize = 128,
-				chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) )
-			;
-			while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
+			NEWLINE = "\n",
 
-				s += chunk; len += chunk.length;
-				p += chunkSize;
-				chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
+			fgets = function ( buffer, lineLimit, consume ) {
 
-			}
+				lineLimit = ! lineLimit ? 1024 : lineLimit;
+				var p = buffer.pos,
+					i = - 1, len = 0, s = '', chunkSize = 128,
+					chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) )
+				;
+				while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
 
-			if ( - 1 < i ) {
+					s += chunk; len += chunk.length;
+					p += chunkSize;
+					chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
 
-				/*for (i=l-1; i>=0; i--) {
-					byteCode = m.charCodeAt(i);
-					if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
-					else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
-					if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
-				}*/
-				if ( false !== consume ) buffer.pos += len + i + 1;
-				return s + chunk.slice( 0, i );
+				}
 
-			}
-			return false;
+				if ( - 1 < i ) {
 
-		},
+					/*for (i=l-1; i>=0; i--) {
+						byteCode = m.charCodeAt(i);
+						if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
+						else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
+						if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
+					}*/
+					if ( false !== consume ) buffer.pos += len + i + 1;
+					return s + chunk.slice( 0, i );
 
-		/* minimal header reading.  modify if you want to parse more information */
-		RGBE_ReadHeader = function ( buffer ) {
+				}
+				return false;
 
-			var line, match,
+			},
 
-				// regexes to parse header info fields
-				magic_token_re = /^#\?(\S+)$/,
-				gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
-				exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
-				format_re = /^\s*FORMAT=(\S+)\s*$/,
-				dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
+			/* minimal header reading.  modify if you want to parse more information */
+			RGBE_ReadHeader = function ( buffer ) {
 
-				// RGBE format header struct
-				header = {
+				var line, match,
 
-					valid: 0, /* indicate which fields are valid */
+					// regexes to parse header info fields
+					magic_token_re = /^#\?(\S+)$/,
+					gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
+					exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
+					format_re = /^\s*FORMAT=(\S+)\s*$/,
+					dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
 
-					string: '', /* the actual header string */
+					// RGBE format header struct
+					header = {
 
-					comments: '', /* comments found in header */
+						valid: 0, /* indicate which fields are valid */
 
-					programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
+						string: '', /* the actual header string */
 
-					format: '', /* RGBE format, default 32-bit_rle_rgbe */
+						comments: '', /* comments found in header */
 
-					gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
+						programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
 
-					exposure: 1.0, /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
+						format: '', /* RGBE format, default 32-bit_rle_rgbe */
 
-					width: 0, height: 0 /* image dimensions, width/height */
+						gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
 
-				};
+						exposure: 1.0, /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
 
-			if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {
+						width: 0, height: 0 /* image dimensions, width/height */
 
-				return rgbe_error( rgbe_read_error, "no header found" );
+					};
 
-			}
-			/* if you want to require the magic token then uncomment the next line */
-			if ( ! ( match = line.match( magic_token_re ) ) ) {
+				if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {
 
-				return rgbe_error( rgbe_format_error, "bad initial token" );
+					return rgbe_error( rgbe_read_error, "no header found" );
 
-			}
-			header.valid |= RGBE_VALID_PROGRAMTYPE;
-			header.programtype = match[ 1 ];
-			header.string += line + "\n";
-
-			while ( true ) {
-
-				line = fgets( buffer );
-				if ( false === line ) break;
-				header.string += line + "\n";
-
-				if ( '#' === line.charAt( 0 ) ) {
+				}
+				/* if you want to require the magic token then uncomment the next line */
+				if ( ! ( match = line.match( magic_token_re ) ) ) {
 
-					header.comments += line + "\n";
-					continue; // comment line
+					return rgbe_error( rgbe_format_error, "bad initial token" );
 
 				}
+				header.valid |= RGBE_VALID_PROGRAMTYPE;
+				header.programtype = match[ 1 ];
+				header.string += line + "\n";
 
-				if ( match = line.match( gamma_re ) ) {
+				while ( true ) {
 
-					header.gamma = parseFloat( match[ 1 ], 10 );
+					line = fgets( buffer );
+					if ( false === line ) break;
+					header.string += line + "\n";
 
-				}
-				if ( match = line.match( exposure_re ) ) {
+					if ( '#' === line.charAt( 0 ) ) {
 
-					header.exposure = parseFloat( match[ 1 ], 10 );
+						header.comments += line + "\n";
+						continue; // comment line
 
-				}
-				if ( match = line.match( format_re ) ) {
+					}
 
-					header.valid |= RGBE_VALID_FORMAT;
-					header.format = match[ 1 ];//'32-bit_rle_rgbe';
+					if ( match = line.match( gamma_re ) ) {
 
-				}
-				if ( match = line.match( dimensions_re ) ) {
+						header.gamma = parseFloat( match[ 1 ], 10 );
 
-					header.valid |= RGBE_VALID_DIMENSIONS;
-					header.height = parseInt( match[ 1 ], 10 );
-					header.width = parseInt( match[ 2 ], 10 );
+					}
+					if ( match = line.match( exposure_re ) ) {
 
-				}
+						header.exposure = parseFloat( match[ 1 ], 10 );
 
-				if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
+					}
+					if ( match = line.match( format_re ) ) {
 
-			}
+						header.valid |= RGBE_VALID_FORMAT;
+						header.format = match[ 1 ];//'32-bit_rle_rgbe';
 
-			if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
+					}
+					if ( match = line.match( dimensions_re ) ) {
 
-				return rgbe_error( rgbe_format_error, "missing format specifier" );
+						header.valid |= RGBE_VALID_DIMENSIONS;
+						header.height = parseInt( match[ 1 ], 10 );
+						header.width = parseInt( match[ 2 ], 10 );
 
-			}
-			if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
+					}
 
-				return rgbe_error( rgbe_format_error, "missing image size specifier" );
+					if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
 
-			}
+				}
 
-			return header;
+				if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
 
-		},
+					return rgbe_error( rgbe_format_error, "missing format specifier" );
 
-		RGBE_ReadPixels_RLE = function ( buffer, w, h ) {
+				}
+				if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
 
-			var data_rgba, offset, pos, count, byteValue,
-				scanline_buffer, ptr, ptr_end, i, l, off, isEncodedRun,
-				scanline_width = w, num_scanlines = h, rgbeStart
-			;
+					return rgbe_error( rgbe_format_error, "missing image size specifier" );
 
-			if (
-				// run length encoding is not allowed so read flat
-				( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
-				// this file is not run length encoded
-				( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
-			) {
+				}
 
-				// return the flat buffer
-				return new Uint8Array( buffer );
+				return header;
 
-			}
+			},
 
-			if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
+			RGBE_ReadPixels_RLE = function ( buffer, w, h ) {
 
-				return rgbe_error( rgbe_format_error, "wrong scanline width" );
+				var data_rgba, offset, pos, count, byteValue,
+					scanline_buffer, ptr, ptr_end, i, l, off, isEncodedRun,
+					scanline_width = w, num_scanlines = h, rgbeStart
+				;
 
-			}
+				if (
+					// run length encoding is not allowed so read flat
+					( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
+					// this file is not run length encoded
+					( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
+				) {
 
-			data_rgba = new Uint8Array( 4 * w * h );
+					// return the flat buffer
+					return new Uint8Array( buffer );
 
-			if ( ! data_rgba || ! data_rgba.length ) {
+				}
 
-				return rgbe_error( rgbe_memory_error, "unable to allocate buffer space" );
+				if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
 
-			}
+					return rgbe_error( rgbe_format_error, "wrong scanline width" );
 
-			offset = 0; pos = 0; ptr_end = 4 * scanline_width;
-			rgbeStart = new Uint8Array( 4 );
-			scanline_buffer = new Uint8Array( ptr_end );
+				}
 
-			// read in each successive scanline
-			while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
+				data_rgba = new Uint8Array( 4 * w * h );
 
-				if ( pos + 4 > buffer.byteLength ) {
+				if ( ! data_rgba || ! data_rgba.length ) {
 
-					return rgbe_error( rgbe_read_error );
+					return rgbe_error( rgbe_memory_error, "unable to allocate buffer space" );
 
 				}
 
-				rgbeStart[ 0 ] = buffer[ pos ++ ];
-				rgbeStart[ 1 ] = buffer[ pos ++ ];
-				rgbeStart[ 2 ] = buffer[ pos ++ ];
-				rgbeStart[ 3 ] = buffer[ pos ++ ];
+				offset = 0; pos = 0; ptr_end = 4 * scanline_width;
+				rgbeStart = new Uint8Array( 4 );
+				scanline_buffer = new Uint8Array( ptr_end );
 
-				if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
+				// read in each successive scanline
+				while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
 
-					return rgbe_error( rgbe_format_error, "bad rgbe scanline format" );
+					if ( pos + 4 > buffer.byteLength ) {
 
-				}
+						return rgbe_error( rgbe_read_error );
 
-				// read each of the four channels for the scanline into the buffer
-				// first red, then green, then blue, then exponent
-				ptr = 0;
-				while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
+					}
 
-					count = buffer[ pos ++ ];
-					isEncodedRun = count > 128;
-					if ( isEncodedRun ) count -= 128;
+					rgbeStart[ 0 ] = buffer[ pos ++ ];
+					rgbeStart[ 1 ] = buffer[ pos ++ ];
+					rgbeStart[ 2 ] = buffer[ pos ++ ];
+					rgbeStart[ 3 ] = buffer[ pos ++ ];
 
-					if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
+					if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
 
-						return rgbe_error( rgbe_format_error, "bad scanline data" );
+						return rgbe_error( rgbe_format_error, "bad rgbe scanline format" );
 
 					}
 
-					if ( isEncodedRun ) {
+					// read each of the four channels for the scanline into the buffer
+					// first red, then green, then blue, then exponent
+					ptr = 0;
+					while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
+
+						count = buffer[ pos ++ ];
+						isEncodedRun = count > 128;
+						if ( isEncodedRun ) count -= 128;
 
-						// a (encoded) run of the same value
-						byteValue = buffer[ pos ++ ];
-						for ( i = 0; i < count; i ++ ) {
+						if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
 
-							scanline_buffer[ ptr ++ ] = byteValue;
+							return rgbe_error( rgbe_format_error, "bad scanline data" );
 
 						}
-						//ptr += count;
 
-					} else {
+						if ( isEncodedRun ) {
+
+							// a (encoded) run of the same value
+							byteValue = buffer[ pos ++ ];
+							for ( i = 0; i < count; i ++ ) {
 
-						// a literal-run
-						scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
-						ptr += count; pos += count;
+								scanline_buffer[ ptr ++ ] = byteValue;
+
+							}
+							//ptr += count;
+
+						} else {
+
+							// a literal-run
+							scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
+							ptr += count; pos += count;
+
+						}
 
 					}
 
-				}
 
+					// now convert data from buffer into rgba
+					// first red, then green, then blue, then exponent (alpha)
+					l = scanline_width; //scanline_buffer.byteLength;
+					for ( i = 0; i < l; i ++ ) {
 
-				// now convert data from buffer into rgba
-				// first red, then green, then blue, then exponent (alpha)
-				l = scanline_width; //scanline_buffer.byteLength;
-				for ( i = 0; i < l; i ++ ) {
+						off = 0;
+						data_rgba[ offset ] = scanline_buffer[ i + off ];
+						off += scanline_width; //1;
+						data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
+						off += scanline_width; //1;
+						data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
+						off += scanline_width; //1;
+						data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
+						offset += 4;
 
-					off = 0;
-					data_rgba[ offset ] = scanline_buffer[ i + off ];
-					off += scanline_width; //1;
-					data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
-					off += scanline_width; //1;
-					data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
-					off += scanline_width; //1;
-					data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
-					offset += 4;
+					}
+
+					num_scanlines --;
 
 				}
 
-				num_scanlines --;
+				return data_rgba;
 
-			}
+			};
 
-			return data_rgba;
+		var RGBEByteToRGBFloat = function ( sourceArray, sourceOffset, destArray, destOffset ) {
 
-		};
+			var e = sourceArray[ sourceOffset + 3 ];
+			var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
 
-	var RGBEByteToRGBFloat = function ( sourceArray, sourceOffset, destArray, destOffset ) {
+			destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale;
+			destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale;
+			destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale;
 
-		var e = sourceArray[ sourceOffset + 3 ];
-		var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
+		};
 
-		destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale;
-		destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale;
-		destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale;
+		var RGBEByteToRGBHalf = ( function () {
 
-	};
+			// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
 
-	var RGBEByteToRGBHalf = ( function () {
+			var floatView = new Float32Array( 1 );
+			var int32View = new Int32Array( floatView.buffer );
 
-		// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
+			/* This method is faster than the OpenEXR implementation (very often
+			 * used, eg. in Ogre), with the additional benefit of rounding, inspired
+			 * by James Tursa?s half-precision code. */
+			function toHalf( val ) {
 
-		var floatView = new Float32Array( 1 );
-		var int32View = new Int32Array( floatView.buffer );
+				floatView[ 0 ] = val;
+				var x = int32View[ 0 ];
 
-		/* This method is faster than the OpenEXR implementation (very often
-		 * used, eg. in Ogre), with the additional benefit of rounding, inspired
-		 * by James Tursa?s half-precision code. */
-		function toHalf( val ) {
+				var bits = ( x >> 16 ) & 0x8000; /* Get the sign */
+				var m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
+				var e = ( x >> 23 ) & 0xff; /* Using int is faster here */
 
-			floatView[ 0 ] = val;
-			var x = int32View[ 0 ];
+				/* If zero, or denormal, or exponent underflows too much for a denormal
+				 * half, return signed zero. */
+				if ( e < 103 ) return bits;
 
-			var bits = ( x >> 16 ) & 0x8000; /* Get the sign */
-			var m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
-			var e = ( x >> 23 ) & 0xff; /* Using int is faster here */
+				/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
+				if ( e > 142 ) {
 
-			/* If zero, or denormal, or exponent underflows too much for a denormal
-			 * half, return signed zero. */
-			if ( e < 103 ) return bits;
+					bits |= 0x7c00;
+					/* If exponent was 0xff and one mantissa bit was set, it means NaN,
+							 * not Inf, so make sure we set one mantissa bit too. */
+					bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
+					return bits;
 
-			/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
-			if ( e > 142 ) {
+				}
 
-				bits |= 0x7c00;
-				/* If exponent was 0xff and one mantissa bit was set, it means NaN,
-						 * not Inf, so make sure we set one mantissa bit too. */
-				bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
-				return bits;
+				/* If exponent underflows but not too much, return a denormal */
+				if ( e < 113 ) {
 
-			}
+					m |= 0x0800;
+					/* Extra rounding may overflow and set mantissa to 0 and exponent
+					 * to 1, which is OK. */
+					bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
+					return bits;
 
-			/* If exponent underflows but not too much, return a denormal */
-			if ( e < 113 ) {
+				}
 
-				m |= 0x0800;
-				/* Extra rounding may overflow and set mantissa to 0 and exponent
-				 * to 1, which is OK. */
-				bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
+				bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
+				/* Extra rounding. An overflow will set mantissa to 0 and increment
+				 * the exponent, which is OK. */
+				bits += m & 1;
 				return bits;
 
 			}
 
-			bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
-			/* Extra rounding. An overflow will set mantissa to 0 and increment
-			 * the exponent, which is OK. */
-			bits += m & 1;
-			return bits;
+			return function ( sourceArray, sourceOffset, destArray, destOffset ) {
 
-		}
+				var e = sourceArray[ sourceOffset + 3 ];
+				var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
 
-		return function ( sourceArray, sourceOffset, destArray, destOffset ) {
+				destArray[ destOffset + 0 ] = toHalf( sourceArray[ sourceOffset + 0 ] * scale );
+				destArray[ destOffset + 1 ] = toHalf( sourceArray[ sourceOffset + 1 ] * scale );
+				destArray[ destOffset + 2 ] = toHalf( sourceArray[ sourceOffset + 2 ] * scale );
 
-			var e = sourceArray[ sourceOffset + 3 ];
-			var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
+			};
 
-			destArray[ destOffset + 0 ] = toHalf( sourceArray[ sourceOffset + 0 ] * scale );
-			destArray[ destOffset + 1 ] = toHalf( sourceArray[ sourceOffset + 1 ] * scale );
-			destArray[ destOffset + 2 ] = toHalf( sourceArray[ sourceOffset + 2 ] * scale );
+		} )();
 
-		};
+		var byteArray = new Uint8Array( buffer );
+		byteArray.pos = 0;
+		var rgbe_header_info = RGBE_ReadHeader( byteArray );
 
-	} )();
+		if ( RGBE_RETURN_FAILURE !== rgbe_header_info ) {
 
-	var byteArray = new Uint8Array( buffer );
-	byteArray.pos = 0;
-	var rgbe_header_info = RGBE_ReadHeader( byteArray );
+			var w = rgbe_header_info.width,
+				h = rgbe_header_info.height,
+				image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );
 
-	if ( RGBE_RETURN_FAILURE !== rgbe_header_info ) {
+			if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {
 
-		var w = rgbe_header_info.width,
-			h = rgbe_header_info.height,
-			image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );
+				switch ( this.type ) {
 
-		if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {
+					case THREE.UnsignedByteType:
 
-			switch ( this.type ) {
+						var data = image_rgba_data;
+						var format = THREE.RGBEFormat; // handled as THREE.RGBAFormat in shaders
+						var type = THREE.UnsignedByteType;
+						break;
 
-				case THREE.UnsignedByteType:
+					case THREE.FloatType:
 
-					var data = image_rgba_data;
-					var format = THREE.RGBEFormat; // handled as THREE.RGBAFormat in shaders
-					var type = THREE.UnsignedByteType;
-					break;
+						var numElements = ( image_rgba_data.length / 4 ) * 3;
+						var floatArray = new Float32Array( numElements );
 
-				case THREE.FloatType:
+						for ( var j = 0; j < numElements; j ++ ) {
 
-					var numElements = ( image_rgba_data.length / 4 ) * 3;
-					var floatArray = new Float32Array( numElements );
+							RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 3 );
 
-					for ( var j = 0; j < numElements; j ++ ) {
+						}
 
-						RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 3 );
+						var data = floatArray;
+						var format = THREE.RGBFormat;
+						var type = THREE.FloatType;
+						break;
 
-					}
+					case THREE.HalfFloatType:
 
-					var data = floatArray;
-					var format = THREE.RGBFormat;
-					var type = THREE.FloatType;
-					break;
+						var numElements = ( image_rgba_data.length / 4 ) * 3;
+						var halfArray = new Uint16Array( numElements );
 
-				case THREE.HalfFloatType:
+						for ( var j = 0; j < numElements; j ++ ) {
 
-					var numElements = ( image_rgba_data.length / 4 ) * 3;
-					var halfArray = new Uint16Array( numElements );
+							RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 3 );
 
-					for ( var j = 0; j < numElements; j ++ ) {
+						}
 
-						RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 3 );
+						var data = halfArray;
+						var format = THREE.RGBFormat;
+						var type = THREE.HalfFloatType;
+						break;
 
-					}
+					default:
 
-					var data = halfArray;
-					var format = THREE.RGBFormat;
-					var type = THREE.HalfFloatType;
-					break;
+						console.error( 'THREE.RGBELoader: unsupported type: ', this.type );
+						break;
 
-				default:
+				}
 
-					console.error( 'THREE.RGBELoader: unsupported type: ', this.type );
-					break;
+				return {
+					width: w, height: h,
+					data: data,
+					header: rgbe_header_info.string,
+					gamma: rgbe_header_info.gamma,
+					exposure: rgbe_header_info.exposure,
+					format: format,
+					type: type
+				};
 
 			}
 
-			return {
-				width: w, height: h,
-				data: data,
-				header: rgbe_header_info.string,
-				gamma: rgbe_header_info.gamma,
-				exposure: rgbe_header_info.exposure,
-				format: format,
-				type: type
-			};
-
 		}
 
-	}
-
-	return null;
-
-};
-
-THREE.RGBELoader.prototype.setDataType = function ( value ) {
+		return null;
 
-	this.type = value;
-	return this;
+	},
 
-};
+	setDataType: function ( value ) {
 
-THREE.RGBELoader.prototype.setType = function ( value ) {
+		this.type = value;
+		return this;
 
-	console.warn( 'THREE.RGBELoader: .setType() has been renamed to .setDataType().' );
+	},
 
-	return this.setDataType( value );
+	load: function ( url, onLoad, onProgress, onError ) {
 
-};
+		function onLoadCallback( texture, texData ) {
 
-THREE.RGBELoader.prototype.load = function ( url, onLoad, onProgress, onError ) {
+			switch ( texture.type ) {
 
-	function onLoadCallback( texture, texData ) {
+				case THREE.UnsignedByteType:
 
-		switch ( texture.type ) {
+					texture.encoding = THREE.RGBEEncoding;
+					texture.minFilter = THREE.NearestFilter;
+					texture.magFilter = THREE.NearestFilter;
+					texture.generateMipmaps = false;
+					texture.flipY = true;
+					break;
 
-			case THREE.UnsignedByteType:
+				case THREE.FloatType:
 
-				texture.encoding = THREE.RGBEEncoding;
-				texture.minFilter = THREE.NearestFilter;
-				texture.magFilter = THREE.NearestFilter;
-				texture.generateMipmaps = false;
-				texture.flipY = true;
-				break;
+					texture.encoding = THREE.LinearEncoding;
+					texture.minFilter = THREE.LinearFilter;
+					texture.magFilter = THREE.LinearFilter;
+					texture.generateMipmaps = false;
+					texture.flipY = true;
+					break;
 
-			case THREE.FloatType:
+				case THREE.HalfFloatType:
 
-				texture.encoding = THREE.LinearEncoding;
-				texture.minFilter = THREE.LinearFilter;
-				texture.magFilter = THREE.LinearFilter;
-				texture.generateMipmaps = false;
-				texture.flipY = true;
-				break;
+					texture.encoding = THREE.LinearEncoding;
+					texture.minFilter = THREE.LinearFilter;
+					texture.magFilter = THREE.LinearFilter;
+					texture.generateMipmaps = false;
+					texture.flipY = true;
+					break;
 
-			case THREE.HalfFloatType:
+			}
 
-				texture.encoding = THREE.LinearEncoding;
-				texture.minFilter = THREE.LinearFilter;
-				texture.magFilter = THREE.LinearFilter;
-				texture.generateMipmaps = false;
-				texture.flipY = true;
-				break;
+			if ( onLoad ) onLoad( texture, texData );
 
 		}
 
-		if ( onLoad ) onLoad( texture, texData );
+		return THREE.DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
 
 	}
 
-	return THREE.DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
-
-};
+} );

+ 1 - 1
examples/jsm/loaders/EXRLoader.d.ts

@@ -18,6 +18,6 @@ export class EXRLoader extends DataTextureLoader {
   constructor(manager?: LoadingManager);
   type: TextureDataType;
 
-  _parser(buffer: ArrayBuffer) : EXR;
+  parse(buffer: ArrayBuffer) : EXR;
   setDataType(type: TextureDataType): this;
 }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 624 - 628
examples/jsm/loaders/EXRLoader.js


+ 1 - 1
examples/jsm/loaders/HDRCubeTextureLoader.js

@@ -96,7 +96,7 @@ HDRCubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 					loaded ++;
 
-					var texData = scope.hdrLoader._parser( buffer );
+					var texData = scope.hdrLoader.parse( buffer );
 
 					if ( ! texData ) return;
 

+ 1 - 1
examples/jsm/loaders/RGBELoader.d.ts

@@ -20,6 +20,6 @@ export class RGBELoader extends DataTextureLoader {
   constructor(manager?: LoadingManager);
   type: TextureDataType;
 
-  _parser(buffer: ArrayBuffer): RGBE;
+  parse(buffer: ArrayBuffer): RGBE;
   setDataType(type: TextureDataType): this;
 }

+ 335 - 339
examples/jsm/loaders/RGBELoader.js

@@ -4,7 +4,6 @@
 
 import {
 	DataTextureLoader,
-	DefaultLoadingManager,
 	FloatType,
 	HalfFloatType,
 	LinearEncoding,
@@ -21,525 +20,522 @@ import {
 
 var RGBELoader = function ( manager ) {
 
-	this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
+	DataTextureLoader.call( this, manager );
+
 	this.type = UnsignedByteType;
 
 };
 
-// extend DataTextureLoader
-RGBELoader.prototype = Object.create( DataTextureLoader.prototype );
+RGBELoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype ), {
 
-// adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
-RGBELoader.prototype._parser = function ( buffer ) {
+	constructor: RGBELoader,
 
-	var
-		/* return codes for rgbe routines */
-		//RGBE_RETURN_SUCCESS = 0,
-		RGBE_RETURN_FAILURE = - 1,
+	// adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
 
-		/* default error routine.  change this to change error handling */
-		rgbe_read_error = 1,
-		rgbe_write_error = 2,
-		rgbe_format_error = 3,
-		rgbe_memory_error = 4,
-		rgbe_error = function ( rgbe_error_code, msg ) {
+	parse: function ( buffer ) {
 
-			switch ( rgbe_error_code ) {
+		var
+			/* return codes for rgbe routines */
+			//RGBE_RETURN_SUCCESS = 0,
+			RGBE_RETURN_FAILURE = - 1,
 
-				case rgbe_read_error: console.error( "RGBELoader Read Error: " + ( msg || '' ) );
-					break;
-				case rgbe_write_error: console.error( "RGBELoader Write Error: " + ( msg || '' ) );
-					break;
-				case rgbe_format_error: console.error( "RGBELoader Bad File Format: " + ( msg || '' ) );
-					break;
-				default:
-				case rgbe_memory_error: console.error( "RGBELoader: Error: " + ( msg || '' ) );
+			/* default error routine.  change this to change error handling */
+			rgbe_read_error = 1,
+			rgbe_write_error = 2,
+			rgbe_format_error = 3,
+			rgbe_memory_error = 4,
+			rgbe_error = function ( rgbe_error_code, msg ) {
 
-			}
-			return RGBE_RETURN_FAILURE;
+				switch ( rgbe_error_code ) {
 
-		},
+					case rgbe_read_error: console.error( "RGBELoader Read Error: " + ( msg || '' ) );
+						break;
+					case rgbe_write_error: console.error( "RGBELoader Write Error: " + ( msg || '' ) );
+						break;
+					case rgbe_format_error: console.error( "RGBELoader Bad File Format: " + ( msg || '' ) );
+						break;
+					default:
+					case rgbe_memory_error: console.error( "RGBELoader: Error: " + ( msg || '' ) );
 
-		/* offsets to red, green, and blue components in a data (float) pixel */
-		//RGBE_DATA_RED = 0,
-		//RGBE_DATA_GREEN = 1,
-		//RGBE_DATA_BLUE = 2,
+				}
+				return RGBE_RETURN_FAILURE;
 
-		/* number of floats per pixel, use 4 since stored in rgba image format */
-		//RGBE_DATA_SIZE = 4,
+			},
 
-		/* flags indicating which fields in an rgbe_header_info are valid */
-		RGBE_VALID_PROGRAMTYPE = 1,
-		RGBE_VALID_FORMAT = 2,
-		RGBE_VALID_DIMENSIONS = 4,
+			/* offsets to red, green, and blue components in a data (float) pixel */
+			//RGBE_DATA_RED = 0,
+			//RGBE_DATA_GREEN = 1,
+			//RGBE_DATA_BLUE = 2,
 
-		NEWLINE = "\n",
+			/* number of floats per pixel, use 4 since stored in rgba image format */
+			//RGBE_DATA_SIZE = 4,
 
-		fgets = function ( buffer, lineLimit, consume ) {
+			/* flags indicating which fields in an rgbe_header_info are valid */
+			RGBE_VALID_PROGRAMTYPE = 1,
+			RGBE_VALID_FORMAT = 2,
+			RGBE_VALID_DIMENSIONS = 4,
 
-			lineLimit = ! lineLimit ? 1024 : lineLimit;
-			var p = buffer.pos,
-				i = - 1, len = 0, s = '', chunkSize = 128,
-				chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) )
-			;
-			while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
+			NEWLINE = "\n",
 
-				s += chunk; len += chunk.length;
-				p += chunkSize;
-				chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
+			fgets = function ( buffer, lineLimit, consume ) {
 
-			}
+				lineLimit = ! lineLimit ? 1024 : lineLimit;
+				var p = buffer.pos,
+					i = - 1, len = 0, s = '', chunkSize = 128,
+					chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) )
+				;
+				while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
 
-			if ( - 1 < i ) {
+					s += chunk; len += chunk.length;
+					p += chunkSize;
+					chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
 
-				/*for (i=l-1; i>=0; i--) {
-					byteCode = m.charCodeAt(i);
-					if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
-					else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
-					if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
-				}*/
-				if ( false !== consume ) buffer.pos += len + i + 1;
-				return s + chunk.slice( 0, i );
+				}
 
-			}
-			return false;
+				if ( - 1 < i ) {
 
-		},
+					/*for (i=l-1; i>=0; i--) {
+						byteCode = m.charCodeAt(i);
+						if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
+						else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
+						if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
+					}*/
+					if ( false !== consume ) buffer.pos += len + i + 1;
+					return s + chunk.slice( 0, i );
 
-		/* minimal header reading.  modify if you want to parse more information */
-		RGBE_ReadHeader = function ( buffer ) {
+				}
+				return false;
 
-			var line, match,
+			},
 
-				// regexes to parse header info fields
-				magic_token_re = /^#\?(\S+)$/,
-				gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
-				exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
-				format_re = /^\s*FORMAT=(\S+)\s*$/,
-				dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
+			/* minimal header reading.  modify if you want to parse more information */
+			RGBE_ReadHeader = function ( buffer ) {
 
-				// RGBE format header struct
-				header = {
+				var line, match,
 
-					valid: 0, /* indicate which fields are valid */
+					// regexes to parse header info fields
+					magic_token_re = /^#\?(\S+)$/,
+					gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
+					exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
+					format_re = /^\s*FORMAT=(\S+)\s*$/,
+					dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
 
-					string: '', /* the actual header string */
+					// RGBE format header struct
+					header = {
 
-					comments: '', /* comments found in header */
+						valid: 0, /* indicate which fields are valid */
 
-					programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
+						string: '', /* the actual header string */
 
-					format: '', /* RGBE format, default 32-bit_rle_rgbe */
+						comments: '', /* comments found in header */
 
-					gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
+						programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
 
-					exposure: 1.0, /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
+						format: '', /* RGBE format, default 32-bit_rle_rgbe */
 
-					width: 0, height: 0 /* image dimensions, width/height */
+						gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
 
-				};
+						exposure: 1.0, /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
 
-			if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {
+						width: 0, height: 0 /* image dimensions, width/height */
 
-				return rgbe_error( rgbe_read_error, "no header found" );
+					};
 
-			}
-			/* if you want to require the magic token then uncomment the next line */
-			if ( ! ( match = line.match( magic_token_re ) ) ) {
+				if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {
 
-				return rgbe_error( rgbe_format_error, "bad initial token" );
+					return rgbe_error( rgbe_read_error, "no header found" );
 
-			}
-			header.valid |= RGBE_VALID_PROGRAMTYPE;
-			header.programtype = match[ 1 ];
-			header.string += line + "\n";
-
-			while ( true ) {
-
-				line = fgets( buffer );
-				if ( false === line ) break;
-				header.string += line + "\n";
-
-				if ( '#' === line.charAt( 0 ) ) {
+				}
+				/* if you want to require the magic token then uncomment the next line */
+				if ( ! ( match = line.match( magic_token_re ) ) ) {
 
-					header.comments += line + "\n";
-					continue; // comment line
+					return rgbe_error( rgbe_format_error, "bad initial token" );
 
 				}
+				header.valid |= RGBE_VALID_PROGRAMTYPE;
+				header.programtype = match[ 1 ];
+				header.string += line + "\n";
 
-				if ( match = line.match( gamma_re ) ) {
+				while ( true ) {
 
-					header.gamma = parseFloat( match[ 1 ], 10 );
+					line = fgets( buffer );
+					if ( false === line ) break;
+					header.string += line + "\n";
 
-				}
-				if ( match = line.match( exposure_re ) ) {
+					if ( '#' === line.charAt( 0 ) ) {
 
-					header.exposure = parseFloat( match[ 1 ], 10 );
+						header.comments += line + "\n";
+						continue; // comment line
 
-				}
-				if ( match = line.match( format_re ) ) {
+					}
 
-					header.valid |= RGBE_VALID_FORMAT;
-					header.format = match[ 1 ];//'32-bit_rle_rgbe';
+					if ( match = line.match( gamma_re ) ) {
 
-				}
-				if ( match = line.match( dimensions_re ) ) {
+						header.gamma = parseFloat( match[ 1 ], 10 );
 
-					header.valid |= RGBE_VALID_DIMENSIONS;
-					header.height = parseInt( match[ 1 ], 10 );
-					header.width = parseInt( match[ 2 ], 10 );
+					}
+					if ( match = line.match( exposure_re ) ) {
 
-				}
+						header.exposure = parseFloat( match[ 1 ], 10 );
 
-				if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
+					}
+					if ( match = line.match( format_re ) ) {
 
-			}
+						header.valid |= RGBE_VALID_FORMAT;
+						header.format = match[ 1 ];//'32-bit_rle_rgbe';
 
-			if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
+					}
+					if ( match = line.match( dimensions_re ) ) {
 
-				return rgbe_error( rgbe_format_error, "missing format specifier" );
+						header.valid |= RGBE_VALID_DIMENSIONS;
+						header.height = parseInt( match[ 1 ], 10 );
+						header.width = parseInt( match[ 2 ], 10 );
 
-			}
-			if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
+					}
 
-				return rgbe_error( rgbe_format_error, "missing image size specifier" );
+					if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
 
-			}
+				}
 
-			return header;
+				if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
 
-		},
+					return rgbe_error( rgbe_format_error, "missing format specifier" );
 
-		RGBE_ReadPixels_RLE = function ( buffer, w, h ) {
+				}
+				if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
 
-			var data_rgba, offset, pos, count, byteValue,
-				scanline_buffer, ptr, ptr_end, i, l, off, isEncodedRun,
-				scanline_width = w, num_scanlines = h, rgbeStart
-			;
+					return rgbe_error( rgbe_format_error, "missing image size specifier" );
 
-			if (
-				// run length encoding is not allowed so read flat
-				( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
-				// this file is not run length encoded
-				( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
-			) {
+				}
 
-				// return the flat buffer
-				return new Uint8Array( buffer );
+				return header;
 
-			}
+			},
 
-			if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
+			RGBE_ReadPixels_RLE = function ( buffer, w, h ) {
 
-				return rgbe_error( rgbe_format_error, "wrong scanline width" );
+				var data_rgba, offset, pos, count, byteValue,
+					scanline_buffer, ptr, ptr_end, i, l, off, isEncodedRun,
+					scanline_width = w, num_scanlines = h, rgbeStart
+				;
 
-			}
+				if (
+					// run length encoding is not allowed so read flat
+					( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
+					// this file is not run length encoded
+					( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
+				) {
 
-			data_rgba = new Uint8Array( 4 * w * h );
+					// return the flat buffer
+					return new Uint8Array( buffer );
 
-			if ( ! data_rgba || ! data_rgba.length ) {
+				}
 
-				return rgbe_error( rgbe_memory_error, "unable to allocate buffer space" );
+				if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
 
-			}
+					return rgbe_error( rgbe_format_error, "wrong scanline width" );
 
-			offset = 0; pos = 0; ptr_end = 4 * scanline_width;
-			rgbeStart = new Uint8Array( 4 );
-			scanline_buffer = new Uint8Array( ptr_end );
+				}
 
-			// read in each successive scanline
-			while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
+				data_rgba = new Uint8Array( 4 * w * h );
 
-				if ( pos + 4 > buffer.byteLength ) {
+				if ( ! data_rgba || ! data_rgba.length ) {
 
-					return rgbe_error( rgbe_read_error );
+					return rgbe_error( rgbe_memory_error, "unable to allocate buffer space" );
 
 				}
 
-				rgbeStart[ 0 ] = buffer[ pos ++ ];
-				rgbeStart[ 1 ] = buffer[ pos ++ ];
-				rgbeStart[ 2 ] = buffer[ pos ++ ];
-				rgbeStart[ 3 ] = buffer[ pos ++ ];
+				offset = 0; pos = 0; ptr_end = 4 * scanline_width;
+				rgbeStart = new Uint8Array( 4 );
+				scanline_buffer = new Uint8Array( ptr_end );
 
-				if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
+				// read in each successive scanline
+				while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
 
-					return rgbe_error( rgbe_format_error, "bad rgbe scanline format" );
+					if ( pos + 4 > buffer.byteLength ) {
 
-				}
+						return rgbe_error( rgbe_read_error );
 
-				// read each of the four channels for the scanline into the buffer
-				// first red, then green, then blue, then exponent
-				ptr = 0;
-				while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
+					}
 
-					count = buffer[ pos ++ ];
-					isEncodedRun = count > 128;
-					if ( isEncodedRun ) count -= 128;
+					rgbeStart[ 0 ] = buffer[ pos ++ ];
+					rgbeStart[ 1 ] = buffer[ pos ++ ];
+					rgbeStart[ 2 ] = buffer[ pos ++ ];
+					rgbeStart[ 3 ] = buffer[ pos ++ ];
 
-					if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
+					if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
 
-						return rgbe_error( rgbe_format_error, "bad scanline data" );
+						return rgbe_error( rgbe_format_error, "bad rgbe scanline format" );
 
 					}
 
-					if ( isEncodedRun ) {
+					// read each of the four channels for the scanline into the buffer
+					// first red, then green, then blue, then exponent
+					ptr = 0;
+					while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
+
+						count = buffer[ pos ++ ];
+						isEncodedRun = count > 128;
+						if ( isEncodedRun ) count -= 128;
 
-						// a (encoded) run of the same value
-						byteValue = buffer[ pos ++ ];
-						for ( i = 0; i < count; i ++ ) {
+						if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
 
-							scanline_buffer[ ptr ++ ] = byteValue;
+							return rgbe_error( rgbe_format_error, "bad scanline data" );
 
 						}
-						//ptr += count;
 
-					} else {
+						if ( isEncodedRun ) {
+
+							// a (encoded) run of the same value
+							byteValue = buffer[ pos ++ ];
+							for ( i = 0; i < count; i ++ ) {
 
-						// a literal-run
-						scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
-						ptr += count; pos += count;
+								scanline_buffer[ ptr ++ ] = byteValue;
+
+							}
+							//ptr += count;
+
+						} else {
+
+							// a literal-run
+							scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
+							ptr += count; pos += count;
+
+						}
 
 					}
 
-				}
 
+					// now convert data from buffer into rgba
+					// first red, then green, then blue, then exponent (alpha)
+					l = scanline_width; //scanline_buffer.byteLength;
+					for ( i = 0; i < l; i ++ ) {
 
-				// now convert data from buffer into rgba
-				// first red, then green, then blue, then exponent (alpha)
-				l = scanline_width; //scanline_buffer.byteLength;
-				for ( i = 0; i < l; i ++ ) {
+						off = 0;
+						data_rgba[ offset ] = scanline_buffer[ i + off ];
+						off += scanline_width; //1;
+						data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
+						off += scanline_width; //1;
+						data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
+						off += scanline_width; //1;
+						data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
+						offset += 4;
 
-					off = 0;
-					data_rgba[ offset ] = scanline_buffer[ i + off ];
-					off += scanline_width; //1;
-					data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
-					off += scanline_width; //1;
-					data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
-					off += scanline_width; //1;
-					data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
-					offset += 4;
+					}
+
+					num_scanlines --;
 
 				}
 
-				num_scanlines --;
+				return data_rgba;
 
-			}
+			};
 
-			return data_rgba;
+		var RGBEByteToRGBFloat = function ( sourceArray, sourceOffset, destArray, destOffset ) {
 
-		};
+			var e = sourceArray[ sourceOffset + 3 ];
+			var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
 
-	var RGBEByteToRGBFloat = function ( sourceArray, sourceOffset, destArray, destOffset ) {
+			destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale;
+			destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale;
+			destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale;
 
-		var e = sourceArray[ sourceOffset + 3 ];
-		var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
+		};
 
-		destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale;
-		destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale;
-		destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale;
+		var RGBEByteToRGBHalf = ( function () {
 
-	};
+			// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
 
-	var RGBEByteToRGBHalf = ( function () {
+			var floatView = new Float32Array( 1 );
+			var int32View = new Int32Array( floatView.buffer );
 
-		// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
+			/* This method is faster than the OpenEXR implementation (very often
+			 * used, eg. in Ogre), with the additional benefit of rounding, inspired
+			 * by James Tursa?s half-precision code. */
+			function toHalf( val ) {
 
-		var floatView = new Float32Array( 1 );
-		var int32View = new Int32Array( floatView.buffer );
+				floatView[ 0 ] = val;
+				var x = int32View[ 0 ];
 
-		/* This method is faster than the OpenEXR implementation (very often
-		 * used, eg. in Ogre), with the additional benefit of rounding, inspired
-		 * by James Tursa?s half-precision code. */
-		function toHalf( val ) {
+				var bits = ( x >> 16 ) & 0x8000; /* Get the sign */
+				var m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
+				var e = ( x >> 23 ) & 0xff; /* Using int is faster here */
 
-			floatView[ 0 ] = val;
-			var x = int32View[ 0 ];
+				/* If zero, or denormal, or exponent underflows too much for a denormal
+				 * half, return signed zero. */
+				if ( e < 103 ) return bits;
 
-			var bits = ( x >> 16 ) & 0x8000; /* Get the sign */
-			var m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
-			var e = ( x >> 23 ) & 0xff; /* Using int is faster here */
+				/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
+				if ( e > 142 ) {
 
-			/* If zero, or denormal, or exponent underflows too much for a denormal
-			 * half, return signed zero. */
-			if ( e < 103 ) return bits;
+					bits |= 0x7c00;
+					/* If exponent was 0xff and one mantissa bit was set, it means NaN,
+							 * not Inf, so make sure we set one mantissa bit too. */
+					bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
+					return bits;
 
-			/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
-			if ( e > 142 ) {
+				}
 
-				bits |= 0x7c00;
-				/* If exponent was 0xff and one mantissa bit was set, it means NaN,
-						 * not Inf, so make sure we set one mantissa bit too. */
-				bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
-				return bits;
+				/* If exponent underflows but not too much, return a denormal */
+				if ( e < 113 ) {
 
-			}
+					m |= 0x0800;
+					/* Extra rounding may overflow and set mantissa to 0 and exponent
+					 * to 1, which is OK. */
+					bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
+					return bits;
 
-			/* If exponent underflows but not too much, return a denormal */
-			if ( e < 113 ) {
+				}
 
-				m |= 0x0800;
-				/* Extra rounding may overflow and set mantissa to 0 and exponent
-				 * to 1, which is OK. */
-				bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
+				bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
+				/* Extra rounding. An overflow will set mantissa to 0 and increment
+				 * the exponent, which is OK. */
+				bits += m & 1;
 				return bits;
 
 			}
 
-			bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
-			/* Extra rounding. An overflow will set mantissa to 0 and increment
-			 * the exponent, which is OK. */
-			bits += m & 1;
-			return bits;
+			return function ( sourceArray, sourceOffset, destArray, destOffset ) {
 
-		}
+				var e = sourceArray[ sourceOffset + 3 ];
+				var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
 
-		return function ( sourceArray, sourceOffset, destArray, destOffset ) {
+				destArray[ destOffset + 0 ] = toHalf( sourceArray[ sourceOffset + 0 ] * scale );
+				destArray[ destOffset + 1 ] = toHalf( sourceArray[ sourceOffset + 1 ] * scale );
+				destArray[ destOffset + 2 ] = toHalf( sourceArray[ sourceOffset + 2 ] * scale );
 
-			var e = sourceArray[ sourceOffset + 3 ];
-			var scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
+			};
 
-			destArray[ destOffset + 0 ] = toHalf( sourceArray[ sourceOffset + 0 ] * scale );
-			destArray[ destOffset + 1 ] = toHalf( sourceArray[ sourceOffset + 1 ] * scale );
-			destArray[ destOffset + 2 ] = toHalf( sourceArray[ sourceOffset + 2 ] * scale );
+		} )();
 
-		};
+		var byteArray = new Uint8Array( buffer );
+		byteArray.pos = 0;
+		var rgbe_header_info = RGBE_ReadHeader( byteArray );
 
-	} )();
+		if ( RGBE_RETURN_FAILURE !== rgbe_header_info ) {
 
-	var byteArray = new Uint8Array( buffer );
-	byteArray.pos = 0;
-	var rgbe_header_info = RGBE_ReadHeader( byteArray );
+			var w = rgbe_header_info.width,
+				h = rgbe_header_info.height,
+				image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );
 
-	if ( RGBE_RETURN_FAILURE !== rgbe_header_info ) {
+			if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {
 
-		var w = rgbe_header_info.width,
-			h = rgbe_header_info.height,
-			image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );
+				switch ( this.type ) {
 
-		if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {
+					case UnsignedByteType:
 
-			switch ( this.type ) {
+						var data = image_rgba_data;
+						var format = RGBEFormat; // handled as THREE.RGBAFormat in shaders
+						var type = UnsignedByteType;
+						break;
 
-				case UnsignedByteType:
+					case FloatType:
 
-					var data = image_rgba_data;
-					var format = RGBEFormat; // handled as THREE.RGBAFormat in shaders
-					var type = UnsignedByteType;
-					break;
+						var numElements = ( image_rgba_data.length / 4 ) * 3;
+						var floatArray = new Float32Array( numElements );
 
-				case FloatType:
+						for ( var j = 0; j < numElements; j ++ ) {
 
-					var numElements = ( image_rgba_data.length / 4 ) * 3;
-					var floatArray = new Float32Array( numElements );
+							RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 3 );
 
-					for ( var j = 0; j < numElements; j ++ ) {
+						}
 
-						RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 3 );
+						var data = floatArray;
+						var format = RGBFormat;
+						var type = FloatType;
+						break;
 
-					}
+					case HalfFloatType:
 
-					var data = floatArray;
-					var format = RGBFormat;
-					var type = FloatType;
-					break;
+						var numElements = ( image_rgba_data.length / 4 ) * 3;
+						var halfArray = new Uint16Array( numElements );
 
-				case HalfFloatType:
+						for ( var j = 0; j < numElements; j ++ ) {
 
-					var numElements = ( image_rgba_data.length / 4 ) * 3;
-					var halfArray = new Uint16Array( numElements );
+							RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 3 );
 
-					for ( var j = 0; j < numElements; j ++ ) {
+						}
 
-						RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 3 );
+						var data = halfArray;
+						var format = RGBFormat;
+						var type = HalfFloatType;
+						break;
 
-					}
+					default:
 
-					var data = halfArray;
-					var format = RGBFormat;
-					var type = HalfFloatType;
-					break;
+						console.error( 'THREE.RGBELoader: unsupported type: ', this.type );
+						break;
 
-				default:
+				}
 
-					console.error( 'THREE.RGBELoader: unsupported type: ', this.type );
-					break;
+				return {
+					width: w, height: h,
+					data: data,
+					header: rgbe_header_info.string,
+					gamma: rgbe_header_info.gamma,
+					exposure: rgbe_header_info.exposure,
+					format: format,
+					type: type
+				};
 
 			}
 
-			return {
-				width: w, height: h,
-				data: data,
-				header: rgbe_header_info.string,
-				gamma: rgbe_header_info.gamma,
-				exposure: rgbe_header_info.exposure,
-				format: format,
-				type: type
-			};
-
 		}
 
-	}
-
-	return null;
-
-};
-
-RGBELoader.prototype.setDataType = function ( value ) {
+		return null;
 
-	this.type = value;
-	return this;
+	},
 
-};
+	setDataType: function ( value ) {
 
-RGBELoader.prototype.setType = function ( value ) {
+		this.type = value;
+		return this;
 
-	console.warn( 'THREE.RGBELoader: .setType() has been renamed to .setDataType().' );
+	},
 
-	return this.setDataType( value );
+	load: function ( url, onLoad, onProgress, onError ) {
 
-};
+		function onLoadCallback( texture, texData ) {
 
-RGBELoader.prototype.load = function ( url, onLoad, onProgress, onError ) {
+			switch ( texture.type ) {
 
-	function onLoadCallback( texture, texData ) {
+				case UnsignedByteType:
 
-		switch ( texture.type ) {
+					texture.encoding = RGBEEncoding;
+					texture.minFilter = NearestFilter;
+					texture.magFilter = NearestFilter;
+					texture.generateMipmaps = false;
+					texture.flipY = true;
+					break;
 
-			case UnsignedByteType:
+				case FloatType:
 
-				texture.encoding = RGBEEncoding;
-				texture.minFilter = NearestFilter;
-				texture.magFilter = NearestFilter;
-				texture.generateMipmaps = false;
-				texture.flipY = true;
-				break;
+					texture.encoding = LinearEncoding;
+					texture.minFilter = LinearFilter;
+					texture.magFilter = LinearFilter;
+					texture.generateMipmaps = false;
+					texture.flipY = true;
+					break;
 
-			case FloatType:
+				case HalfFloatType:
 
-				texture.encoding = LinearEncoding;
-				texture.minFilter = LinearFilter;
-				texture.magFilter = LinearFilter;
-				texture.generateMipmaps = false;
-				texture.flipY = true;
-				break;
+					texture.encoding = LinearEncoding;
+					texture.minFilter = LinearFilter;
+					texture.magFilter = LinearFilter;
+					texture.generateMipmaps = false;
+					texture.flipY = true;
+					break;
 
-			case HalfFloatType:
+			}
 
-				texture.encoding = LinearEncoding;
-				texture.minFilter = LinearFilter;
-				texture.magFilter = LinearFilter;
-				texture.generateMipmaps = false;
-				texture.flipY = true;
-				break;
+			if ( onLoad ) onLoad( texture, texData );
 
 		}
 
-		if ( onLoad ) onLoad( texture, texData );
+		return DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
 
 	}
 
-	return DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
-
-};
+} );
 
 export { RGBELoader };

+ 2 - 0
src/loaders/CompressedTextureLoader.js

@@ -7,6 +7,8 @@ import { Loader } from './Loader.js';
  * @author mrdoob / http://mrdoob.com/
  *
  * Abstract Base class to block based textures loader (dds, pvr, ...)
+ *
+ * Sub classes have to implement the parse() method which will be used in load().
  */
 
 function CompressedTextureLoader( manager ) {

+ 3 - 4
src/loaders/DataTextureLoader.js

@@ -7,15 +7,14 @@ import { Loader } from './Loader.js';
  * @author Nikos M. / https://github.com/foo123/
  *
  * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
+ *
+ * Sub classes have to implement the parse() method which will be used in load().
  */
 
 function DataTextureLoader( manager ) {
 
 	Loader.call( this, manager );
 
-	// override in sub classes
-	this._parser = null;
-
 }
 
 DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
@@ -33,7 +32,7 @@ DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 		loader.setPath( this.path );
 		loader.load( url, function ( buffer ) {
 
-			var texData = scope._parser( buffer );
+			var texData = scope.parse( buffer );
 
 			if ( ! texData ) return;
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác