Skip to content

Commit 2ab4d8e

Browse files
authored
Merge pull request #20581 from Mugen87/dev51
Examples: Clean up.
2 parents e630876 + aa5c581 commit 2ab4d8e

File tree

2 files changed

+5
-102
lines changed

2 files changed

+5
-102
lines changed

examples/js/loaders/EXRLoader.js

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
12311231

12321232
for ( var i = 0; i < 64; ++ i ) {
12331233

1234-
dst[ idx + i ] = encodeFloat16( toLinear( src[ i ] ) );
1234+
dst[ idx + i ] = THREE.DataUtils.toHalfFloat( toLinear( src[ i ] ) );
12351235

12361236
}
12371237

@@ -1816,7 +1816,7 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
18161816

18171817
function decodeFloat32( dataView, offset ) {
18181818

1819-
return encodeFloat16( parseFloat32( dataView, offset ) );
1819+
return THREE.DataUtils.toHalfFloat( parseFloat32( dataView, offset ) );
18201820

18211821
}
18221822

@@ -1838,55 +1838,6 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
18381838

18391839
}
18401840

1841-
// http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
1842-
function encodeFloat16( val ) {
1843-
1844-
/* This method is faster than the OpenEXR implementation (very often
1845-
* used, eg. in Ogre), with the additional benefit of rounding, inspired
1846-
* by James Tursa?s half-precision code.
1847-
*/
1848-
1849-
tmpDataView.setFloat32( 0, val );
1850-
var x = tmpDataView.getInt32( 0 );
1851-
1852-
var bits = ( x >> 16 ) & 0x8000; /* Get the sign */
1853-
var m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
1854-
var e = ( x >> 23 ) & 0xff; /* Using int is faster here */
1855-
1856-
/* If zero, or denormal, or exponent underflows too much for a denormal
1857-
* half, return signed zero. */
1858-
if ( e < 103 ) return bits;
1859-
1860-
/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
1861-
if ( e > 142 ) {
1862-
1863-
bits |= 0x7c00;
1864-
/* If exponent was 0xff and one mantissa bit was set, it means NaN,
1865-
* not Inf, so make sure we set one mantissa bit too. */
1866-
bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
1867-
return bits;
1868-
1869-
}
1870-
1871-
/* If exponent underflows but not too much, return a denormal */
1872-
if ( e < 113 ) {
1873-
1874-
m |= 0x0800;
1875-
/* Extra rounding may overflow and set mantissa to 0 and exponent
1876-
* to 1, which is OK. */
1877-
bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
1878-
return bits;
1879-
1880-
}
1881-
1882-
bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
1883-
/* Extra rounding. An overflow will set mantissa to 0 and increment
1884-
* the exponent, which is OK. */
1885-
bits += m & 1;
1886-
return bits;
1887-
1888-
}
1889-
18901841
function parseUint16( dataView, offset ) {
18911842

18921843
var Uint16 = dataView.getUint16( offset.value, true );

examples/jsm/loaders/EXRLoader.js

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DataTextureLoader,
3+
DataUtils,
34
FloatType,
45
HalfFloatType,
56
LinearEncoding,
@@ -1246,7 +1247,7 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
12461247

12471248
for ( var i = 0; i < 64; ++ i ) {
12481249

1249-
dst[ idx + i ] = encodeFloat16( toLinear( src[ i ] ) );
1250+
dst[ idx + i ] = DataUtils.toHalfFloat( toLinear( src[ i ] ) );
12501251

12511252
}
12521253

@@ -1831,7 +1832,7 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
18311832

18321833
function decodeFloat32( dataView, offset ) {
18331834

1834-
return encodeFloat16( parseFloat32( dataView, offset ) );
1835+
return DataUtils.toHalfFloat( parseFloat32( dataView, offset ) );
18351836

18361837
}
18371838

@@ -1853,55 +1854,6 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
18531854

18541855
}
18551856

1856-
// http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
1857-
function encodeFloat16( val ) {
1858-
1859-
/* This method is faster than the OpenEXR implementation (very often
1860-
* used, eg. in Ogre), with the additional benefit of rounding, inspired
1861-
* by James Tursa?s half-precision code.
1862-
*/
1863-
1864-
tmpDataView.setFloat32( 0, val );
1865-
var x = tmpDataView.getInt32( 0 );
1866-
1867-
var bits = ( x >> 16 ) & 0x8000; /* Get the sign */
1868-
var m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
1869-
var e = ( x >> 23 ) & 0xff; /* Using int is faster here */
1870-
1871-
/* If zero, or denormal, or exponent underflows too much for a denormal
1872-
* half, return signed zero. */
1873-
if ( e < 103 ) return bits;
1874-
1875-
/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
1876-
if ( e > 142 ) {
1877-
1878-
bits |= 0x7c00;
1879-
/* If exponent was 0xff and one mantissa bit was set, it means NaN,
1880-
* not Inf, so make sure we set one mantissa bit too. */
1881-
bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
1882-
return bits;
1883-
1884-
}
1885-
1886-
/* If exponent underflows but not too much, return a denormal */
1887-
if ( e < 113 ) {
1888-
1889-
m |= 0x0800;
1890-
/* Extra rounding may overflow and set mantissa to 0 and exponent
1891-
* to 1, which is OK. */
1892-
bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
1893-
return bits;
1894-
1895-
}
1896-
1897-
bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
1898-
/* Extra rounding. An overflow will set mantissa to 0 and increment
1899-
* the exponent, which is OK. */
1900-
bits += m & 1;
1901-
return bits;
1902-
1903-
}
1904-
19051857
function parseUint16( dataView, offset ) {
19061858

19071859
var Uint16 = dataView.getUint16( offset.value, true );

0 commit comments

Comments
 (0)