2
0
Mr.doob 3 жил өмнө
parent
commit
e44441a558

+ 16 - 15
examples/js/controls/ArcballControls.js

@@ -2272,19 +2272,6 @@
 
 			};
 
-			this.setTarget = ( 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.target, this._tbRadius );
-				this.camera.lookAt( this.target );
-
-			};
-
 			this.zRotate = ( point, angle ) => {
 
 				this._rotationMatrix.makeRotationAxis( this._rotationAxis, angle );
@@ -2566,7 +2553,20 @@
 
 			this.update = () => {
 
-				const EPS = 0.000001; //check min/max parameters
+				const EPS = 0.000001;
+
+				if ( this.target.equals( this._currentTarget ) === false ) {
+
+					this._gizmos.position.copy( this.target ); //for correct radius calculation
+
+
+					this._tbRadius = this.calculateTbRadius( this.camera );
+					this.makeGizmos( this.target, this._tbRadius );
+
+					this._currentTarget.copy( this.target );
+
+				} //check min/max parameters
+
 
 				if ( this.camera.isOrthographicCamera ) {
 
@@ -2671,7 +2671,8 @@
 			this.camera = null;
 			this.domElement = domElement;
 			this.scene = scene;
-			this.target = new THREE.Vector3( 0, 0, 0 );
+			this.target = new THREE.Vector3();
+			this._currentTarget = new THREE.Vector3();
 			this.radiusFactor = 0.67;
 			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)

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

@@ -655,7 +655,7 @@
 			this.domElement.setPointerCapture( event.pointerId );
 
 		}
-		
+
 		this.domElement.addEventListener( 'pointermove', this._onPointerMove );
 		this.pointerHover( this._getPointer( event ) );
 		this.pointerDown( this._getPointer( event ) );

+ 3 - 80
examples/js/loaders/EXRLoader.js

@@ -106,39 +106,6 @@
 			const LOSSY_DCT = 1;
 			const RLE = 2;
 			const logBase = Math.pow( 2.7182818, 2.2 );
-			var tmpDataView = new DataView( new ArrayBuffer( 8 ) );
-
-			function frexp( value ) {
-
-				if ( value === 0 ) return [ value, 0 ];
-				tmpDataView.setFloat64( 0, value );
-				var bits = tmpDataView.getUint32( 0 ) >>> 20 & 0x7FF;
-
-				if ( bits === 0 ) {
-
-					// denormal
-					tmpDataView.setFloat64( 0, value * Math.pow( 2, 64 ) ); // exp + 64
-
-					bits = ( tmpDataView.getUint32( 0 ) >>> 20 & 0x7FF ) - 64;
-
-				}
-
-				var exponent = bits - 1022;
-				var mantissa = ldexp( value, - exponent );
-				return [ mantissa, exponent ];
-
-			}
-
-			function ldexp( mantissa, exponent ) {
-
-				var steps = Math.min( 3, Math.ceil( Math.abs( exponent ) / 1023 ) );
-				var result = mantissa;
-
-				for ( var i = 0; i < steps; i ++ ) result *= Math.pow( 2, Math.floor( ( exponent + i ) / steps ) );
-
-				return result;
-
-			}
 
 			function reverseLutFromBitmap( bitmap, lut ) {
 
@@ -1980,7 +1947,6 @@
 					// half
 					switch ( outputType ) {
 
-						case THREE.UnsignedByteType:
 						case THREE.FloatType:
 							EXRDecoder.getter = parseFloat16;
 							EXRDecoder.inputSize = INT16_SIZE;
@@ -1998,7 +1964,6 @@
 					// float
 					switch ( outputType ) {
 
-						case THREE.UnsignedByteType:
 						case THREE.FloatType:
 							EXRDecoder.getter = parseFloat32;
 							EXRDecoder.inputSize = FLOAT32_SIZE;
@@ -2028,7 +1993,6 @@
 
 				switch ( outputType ) {
 
-					case THREE.UnsignedByteType:
 					case THREE.FloatType:
 						EXRDecoder.byteArray = new Float32Array( size ); // Fill initially with 1s for the alpha value if the texture is not RGBA, RGB values will be overwritten
 
@@ -2052,7 +2016,7 @@
 				if ( EXRDecoder.outputChannels == 4 ) {
 
 					EXRDecoder.format = THREE.RGBAFormat;
-					EXRDecoder.encoding = outputType == THREE.UnsignedByteType ? THREE.RGBEEncoding : THREE.LinearEncoding;
+					EXRDecoder.encoding = THREE.LinearEncoding;
 
 				} else {
 
@@ -2118,47 +2082,6 @@
 
 				}
 
-			} // convert to RGBE if user specifies Uint8 output on a RGB input texture
-
-
-			if ( EXRDecoder.encoding == THREE.RGBEEncoding ) {
-
-				let v, i;
-				const size = EXRDecoder.byteArray.length;
-				const RGBEArray = new Uint8Array( size );
-
-				for ( let h = 0; h < EXRDecoder.height; ++ h ) {
-
-					for ( let w = 0; w < EXRDecoder.width; ++ w ) {
-
-						i = h * EXRDecoder.width * 4 + w * 4;
-						const red = EXRDecoder.byteArray[ i ];
-						const green = EXRDecoder.byteArray[ i + 1 ];
-						const blue = EXRDecoder.byteArray[ i + 2 ];
-						v = red > green ? red : green;
-						v = blue > v ? blue : v;
-
-						if ( v < 1e-32 ) {
-
-							RGBEArray[ i ] = RGBEArray[ i + 1 ] = RGBEArray[ i + 2 ] = RGBEArray[ i + 3 ] = 0;
-
-						} else {
-
-							const res = frexp( v );
-							v = res[ 0 ] * 256 / v;
-							RGBEArray[ i ] = red * v;
-							RGBEArray[ i + 1 ] = green * v;
-							RGBEArray[ i + 2 ] = blue * v;
-							RGBEArray[ i + 3 ] = res[ 1 ] + 128;
-
-						}
-
-					}
-
-				}
-
-				EXRDecoder.byteArray = RGBEArray;
-
 			}
 
 			return {
@@ -2185,8 +2108,8 @@
 			function onLoadCallback( texture, texData ) {
 
 				texture.encoding = texData.encoding;
-				texture.minFilter = texture.encoding == THREE.RGBEEncoding ? THREE.NearestFilter : THREE.LinearFilter;
-				texture.magFilter = texture.encoding == THREE.RGBEEncoding ? THREE.NearestFilter : THREE.LinearFilter;
+				texture.minFilter = THREE.LinearFilter;
+				texture.magFilter = THREE.LinearFilter;
 				texture.generateMipmaps = false;
 				texture.flipY = false;
 				if ( onLoad ) onLoad( texture, texData );

+ 9 - 2
examples/js/loaders/NRRDLoader.js

@@ -207,7 +207,10 @@
 				if ( ! headerObject.vectors ) {
 
 					//if no space direction is set, let's use the identity
-					headerObject.vectors = [ new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ) ]; //apply spacing if defined
+					headerObject.vectors = [];
+					headerObject.vectors.push( [ 1, 0, 0 ] );
+					headerObject.vectors.push( [ 0, 1, 0 ] );
+					headerObject.vectors.push( [ 0, 0, 1 ] ); //apply spacing if defined
 
 					if ( headerObject.spacings ) {
 
@@ -215,7 +218,11 @@
 
 							if ( ! isNaN( headerObject.spacings[ i ] ) ) {
 
-								headerObject.vectors[ i ].multiplyScalar( headerObject.spacings[ i ] );
+								for ( let j = 0; j <= 2; j ++ ) {
+
+									headerObject.vectors[ i ][ j ] *= headerObject.spacings[ i ];
+
+								}
 
 							}
 

+ 55 - 5
examples/js/loaders/RGBMLoader.js

@@ -2,6 +2,28 @@
 
 	class RGBMLoader extends THREE.DataTextureLoader {
 
+		constructor( manager ) {
+
+			super( manager );
+			this.type = THREE.HalfFloatType;
+			this.maxRange = 7; // more information about this property at https://iwasbeingirony.blogspot.com/2010/06/difference-between-rgbm-and-rgbd.html
+
+		}
+
+		setDataType( value ) {
+
+			this.type = value;
+			return this;
+
+		}
+
+		setMaxRange( value ) {
+
+			this.maxRange = value;
+			return this;
+
+		}
+
 		loadCubemap( urls, onLoad, onProgress, onError ) {
 
 			const texture = new THREE.CubeTexture();
@@ -32,7 +54,7 @@
 
 			}
 
-			texture.encoding = THREE.RGBM7Encoding;
+			texture.type = this.type;
 			texture.format = THREE.RGBAFormat;
 			texture.minFilter = THREE.LinearFilter;
 			texture.generateMipmaps = false;
@@ -44,14 +66,42 @@
 
 			const img = UPNG.decode( buffer );
 			const rgba = UPNG.toRGBA8( img )[ 0 ];
+			const data = new Uint8Array( rgba );
+			const size = img.width * img.height * 4;
+			const output = this.type === THREE.HalfFloatType ? new Uint16Array( size ) : new Float32Array( size ); // decode RGBM
+
+			for ( let i = 0; i < data.length; i += 4 ) {
+
+				const r = data[ i + 0 ] / 255;
+				const g = data[ i + 1 ] / 255;
+				const b = data[ i + 2 ] / 255;
+				const a = data[ i + 3 ] / 255;
+
+				if ( this.type === THREE.HalfFloatType ) {
+
+					output[ i + 0 ] = THREE.DataUtils.toHalfFloat( Math.min( r * a * this.maxRange, 65504 ) );
+					output[ i + 1 ] = THREE.DataUtils.toHalfFloat( Math.min( g * a * this.maxRange, 65504 ) );
+					output[ i + 2 ] = THREE.DataUtils.toHalfFloat( Math.min( b * a * this.maxRange, 65504 ) );
+					output[ i + 3 ] = THREE.DataUtils.toHalfFloat( 1 );
+
+				} else {
+
+					output[ i + 0 ] = r * a * this.maxRange;
+					output[ i + 1 ] = g * a * this.maxRange;
+					output[ i + 2 ] = b * a * this.maxRange;
+					output[ i + 3 ] = 1;
+
+				}
+
+			}
+
 			return {
 				width: img.width,
 				height: img.height,
-				data: new Uint8Array( rgba ),
+				data: output,
 				format: THREE.RGBAFormat,
-				type: THREE.UnsignedByteType,
-				flipY: true,
-				encoding: THREE.RGBM7Encoding
+				type: this.type,
+				flipY: true
 			};
 
 		}

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

@@ -139,7 +139,7 @@
 
 				const StringLiteral = createToken( {
 					name: 'StringLiteral',
-					pattern: /"(:?[^\\"\n\r]|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/
+					pattern: /"(?:[^\\"\n\r]|\\[bfnrtv"\\/]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])*"/
 				} );
 				const HexLiteral = createToken( {
 					name: 'HexLiteral',