Browse Source

JSM: Update modules.

Mugen87 6 years ago
parent
commit
dea46d7e87
2 changed files with 60 additions and 8 deletions
  1. 58 8
      examples/jsm/loaders/EXRLoader.js
  2. 2 0
      examples/jsm/loaders/GLTFLoader.js

+ 58 - 8
examples/jsm/loaders/EXRLoader.js

@@ -12,6 +12,7 @@ import {
 	DataTextureLoader,
 	DefaultLoadingManager,
 	FloatType,
+	HalfFloatType,
 	RGBAFormat,
 	RGBFormat
 } from "../../../build/three.module.js";
@@ -84,11 +85,19 @@ import {
 var EXRLoader = function ( manager ) {
 
 	this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
+	this.type = FloatType;
 
 };
 
 EXRLoader.prototype = Object.create( DataTextureLoader.prototype );
 
+EXRLoader.prototype.setType = function ( value ) {
+
+	this.type = value;
+	return this;
+
+};
+
 EXRLoader.prototype._parser = function ( buffer ) {
 
 	const USHORT_RANGE = ( 1 << 16 );
@@ -1087,7 +1096,24 @@ EXRLoader.prototype._parser = function ( buffer ) {
 	var height = EXRHeader.dataWindow.yMax - EXRHeader.dataWindow.yMin + 1;
 	var numChannels = EXRHeader.channels.length;
 
-	var byteArray = new Float32Array( width * height * numChannels );
+	switch ( this.type ) {
+
+		case FloatType:
+
+			var byteArray = new Float32Array( width * height * numChannels );
+			break;
+
+		case HalfFloatType:
+
+			var byteArray = new Uint16Array( width * height * numChannels );
+			break;
+
+		default:
+
+			console.error( 'THREE.EXRLoader: unsupported type: ', this.type );
+			break;
+
+	}
 
 	var channelOffsets = {
 		R: 0,
@@ -1107,12 +1133,23 @@ EXRLoader.prototype._parser = function ( buffer ) {
 
 				var cOff = channelOffsets[ EXRHeader.channels[ channelID ].name ];
 
-				if ( EXRHeader.channels[ channelID ].pixelType === 1 ) {
+				if ( EXRHeader.channels[ channelID ].pixelType === 1 ) { // half
 
-					// HALF
 					for ( var x = 0; x < width; x ++ ) {
 
-						var val = parseFloat16( bufferDataView, offset );
+						switch ( this.type ) {
+
+							case FloatType:
+
+								var val = parseFloat16( bufferDataView, offset );
+								break;
+
+							case HalfFloatType:
+
+								var val = parseUint16( bufferDataView, offset );
+								break;
+
+						}
 
 						byteArray[ ( ( ( height - y_scanline ) * ( width * numChannels ) ) + ( x * numChannels ) ) + cOff ] = val;
 
@@ -1147,12 +1184,25 @@ EXRLoader.prototype._parser = function ( buffer ) {
 
 					var cOff = channelOffsets[ EXRHeader.channels[ channelID ].name ];
 
-					if ( EXRHeader.channels[ channelID ].pixelType === 1 ) {
+					if ( EXRHeader.channels[ channelID ].pixelType === 1 ) { // half
 
-						// HALF
 						for ( var x = 0; x < width; x ++ ) {
 
-							var val = decodeFloat16( tmpBuffer[ ( channelID * ( scanlineBlockSize * width ) ) + ( line_y * width ) + x ] );
+							var idx = ( channelID * ( scanlineBlockSize * width ) ) + ( line_y * width ) + x;
+
+							switch ( this.type ) {
+
+								case FloatType:
+
+									var val = decodeFloat16( tmpBuffer[ idx ] );
+									break;
+
+								case HalfFloatType:
+
+									var val = tmpBuffer[ idx ];
+									break;
+
+							}
 
 							var true_y = line_y + ( scanlineBlockIdx * scanlineBlockSize );
 
@@ -1184,7 +1234,7 @@ EXRLoader.prototype._parser = function ( buffer ) {
 		height: height,
 		data: byteArray,
 		format: EXRHeader.channels.length == 4 ? RGBAFormat : RGBFormat,
-		type: FloatType
+		type: this.type
 	};
 
 };

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

@@ -1644,6 +1644,8 @@ var GLTFLoader = ( function () {
 
 			addUnknownExtensionsToUserData( extensions, result, json );
 
+			assignExtrasToUserData( result, json );
+
 			onLoad( result );
 
 		} ).catch( onError );