Skip to content

Commit

Permalink
BufferGeometryLoader/ObjectLoader: Avoid unnecessary object allocations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Apr 4, 2017
1 parent 50b433e commit 43d6053
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
23 changes: 11 additions & 12 deletions src/loaders/BufferGeometryLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ Object.assign( BufferGeometryLoader.prototype, {

var index = json.data.index;

var TYPED_ARRAYS = {
'Int8Array': Int8Array,
'Uint8Array': Uint8Array,
'Uint8ClampedArray': Uint8ClampedArray,
'Int16Array': Int16Array,
'Uint16Array': Uint16Array,
'Int32Array': Int32Array,
'Uint32Array': Uint32Array,
'Float32Array': Float32Array,
'Float64Array': Float64Array
};

if ( index !== undefined ) {

var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
Expand Down Expand Up @@ -103,5 +91,16 @@ Object.assign( BufferGeometryLoader.prototype, {

} );

var TYPED_ARRAYS = {
Int8Array: Int8Array,
Uint8Array: Uint8Array,
Uint8ClampedArray: Uint8ClampedArray,
Int16Array: Int16Array,
Uint16Array: Uint16Array,
Int32Array: Int32Array,
Uint32Array: Uint32Array,
Float32Array: Float32Array,
Float64Array: Float64Array
};

export { BufferGeometryLoader };
62 changes: 31 additions & 31 deletions src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,32 +436,6 @@ Object.assign( ObjectLoader.prototype, {

parseTextures: function ( json, images ) {

var TextureMapping = {
UVMapping: UVMapping,
CubeReflectionMapping: CubeReflectionMapping,
CubeRefractionMapping: CubeRefractionMapping,
EquirectangularReflectionMapping: EquirectangularReflectionMapping,
EquirectangularRefractionMapping: EquirectangularRefractionMapping,
SphericalReflectionMapping: SphericalReflectionMapping,
CubeUVReflectionMapping: CubeUVReflectionMapping,
CubeUVRefractionMapping: CubeUVRefractionMapping
};

var TextureWrapping = {
RepeatWrapping: RepeatWrapping,
ClampToEdgeWrapping: ClampToEdgeWrapping,
MirroredRepeatWrapping: MirroredRepeatWrapping
};

var TextureFilter = {
NearestFilter: NearestFilter,
NearestMipMapNearestFilter: NearestMipMapNearestFilter,
NearestMipMapLinearFilter: NearestMipMapLinearFilter,
LinearFilter: LinearFilter,
LinearMipMapNearestFilter: LinearMipMapNearestFilter,
LinearMipMapLinearFilter: LinearMipMapLinearFilter
};

function parseConstant( value, type ) {

if ( typeof( value ) === 'number' ) return value;
Expand Down Expand Up @@ -499,19 +473,19 @@ Object.assign( ObjectLoader.prototype, {

if ( data.name !== undefined ) texture.name = data.name;

if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TextureMapping );
if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );

if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
if ( data.wrap !== undefined ) {

texture.wrapS = parseConstant( data.wrap[ 0 ], TextureWrapping );
texture.wrapT = parseConstant( data.wrap[ 1 ], TextureWrapping );
texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );

}

if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TextureFilter );
if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TextureFilter );
if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;

if ( data.flipY !== undefined ) texture.flipY = data.flipY;
Expand Down Expand Up @@ -807,5 +781,31 @@ Object.assign( ObjectLoader.prototype, {

} );

var TEXTURE_MAPPING = {
UVMapping: UVMapping,
CubeReflectionMapping: CubeReflectionMapping,
CubeRefractionMapping: CubeRefractionMapping,
EquirectangularReflectionMapping: EquirectangularReflectionMapping,
EquirectangularRefractionMapping: EquirectangularRefractionMapping,
SphericalReflectionMapping: SphericalReflectionMapping,
CubeUVReflectionMapping: CubeUVReflectionMapping,
CubeUVRefractionMapping: CubeUVRefractionMapping
};

var TEXTURE_WRAPPING = {
RepeatWrapping: RepeatWrapping,
ClampToEdgeWrapping: ClampToEdgeWrapping,
MirroredRepeatWrapping: MirroredRepeatWrapping
};

var TEXTURE_FILTER = {
NearestFilter: NearestFilter,
NearestMipMapNearestFilter: NearestMipMapNearestFilter,
NearestMipMapLinearFilter: NearestMipMapLinearFilter,
LinearFilter: LinearFilter,
LinearMipMapNearestFilter: LinearMipMapNearestFilter,
LinearMipMapLinearFilter: LinearMipMapLinearFilter
};


export { ObjectLoader };

0 comments on commit 43d6053

Please sign in to comment.