Skip to content

Commit

Permalink
Updated examples builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Dec 21, 2021
1 parent 6cd5321 commit e44441a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 104 deletions.
31 changes: 16 additions & 15 deletions examples/js/controls/ArcballControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/js/controls/TransformControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
83 changes: 3 additions & 80 deletions examples/js/loaders/EXRLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down Expand Up @@ -1980,7 +1947,6 @@
// half
switch ( outputType ) {

case THREE.UnsignedByteType:
case THREE.FloatType:
EXRDecoder.getter = parseFloat16;
EXRDecoder.inputSize = INT16_SIZE;
Expand All @@ -1998,7 +1964,6 @@
// float
switch ( outputType ) {

case THREE.UnsignedByteType:
case THREE.FloatType:
EXRDecoder.getter = parseFloat32;
EXRDecoder.inputSize = FLOAT32_SIZE;
Expand Down Expand Up @@ -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

Expand All @@ -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 {

Expand Down Expand Up @@ -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 {
Expand All @@ -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 );
Expand Down
11 changes: 9 additions & 2 deletions examples/js/loaders/NRRDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,22 @@
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 ) {

for ( i = 0; i <= 2; i ++ ) {

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 ];

}

}

Expand Down
60 changes: 55 additions & 5 deletions examples/js/loaders/RGBMLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -32,7 +54,7 @@

}

texture.encoding = THREE.RGBM7Encoding;
texture.type = this.type;
texture.format = THREE.RGBAFormat;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
Expand All @@ -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
};

}
Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/VRMLLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e44441a

Please sign in to comment.