diff --git a/examples/js/loaders/MTLLoader.js b/examples/js/loaders/MTLLoader.js index 97d7f13907a66c073bd5571eb0c7fe914bcca741..53027a48df58cb148f058049c1c1b842719b2586 100644 --- a/examples/js/loaders/MTLLoader.js +++ b/examples/js/loaders/MTLLoader.js @@ -401,7 +401,7 @@ THREE.MTLLoader.MaterialCreator.prototype = { THREE.MTLLoader.loadTexture = function ( url, mapping, onLoad, onError ) { - var isCompressed = url.toLowerCase().endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( url ); if ( isCompressed ) { diff --git a/examples/js/loaders/OBJLoader.js b/examples/js/loaders/OBJLoader.js index 536a1e5b25a847b42968f99e92b487b1de931e9a..a28f6ec51edbba38ebf8c9735da19bdb0cfaa78a 100644 --- a/examples/js/loaders/OBJLoader.js +++ b/examples/js/loaders/OBJLoader.js @@ -382,7 +382,7 @@ THREE.OBJLoader.prototype = { } - } else if ( line.startsWith( "o " ) ) { + } else if ( /^o /.test( line ) ) { // object @@ -390,23 +390,23 @@ THREE.OBJLoader.prototype = { object.name = line.substring( 2 ).trim(); group.add( object ); - } else if ( line.startsWith( "g " ) ) { + } else if ( /^g /.test( line ) ) { // group meshN( line.substring( 2 ).trim(), undefined ); - } else if ( line.startsWith( "usemtl " ) ) { + } else if ( /^usemtl /.test( line ) ) { // material meshN( undefined, line.substring( 7 ).trim() ); - } else if ( line.startsWith( "mtllib ") ) { + } else if ( /^mtllib /.test( line ) ) { // mtl file - } else if ( line.startsWith( "s ") ) { + } else if ( /^s /.test( line ) ) { // smooth shading diff --git a/examples/js/loaders/OBJMTLLoader.js b/examples/js/loaders/OBJMTLLoader.js index 1d6bffdb109647d147aa4618ef1281aed1f65aac..f30864dd30352697944103f42a484ca14121705a 100644 --- a/examples/js/loaders/OBJMTLLoader.js +++ b/examples/js/loaders/OBJMTLLoader.js @@ -518,7 +518,7 @@ THREE.OBJMTLLoader.prototype = { } - } else if ( line.startsWith( "o " ) ) { + } else if ( /^o /.test( line ) ) { // object @@ -526,19 +526,19 @@ THREE.OBJMTLLoader.prototype = { object.name = line.substring( 2 ).trim(); group.add( object ); - } else if ( line.startsWith( "g " ) ) { + } else if ( /^g /.test( line ) ) { // group meshN( line.substring( 2 ).trim(), undefined ); - } else if ( line.startsWith( "usemtl " ) ) { + } else if ( /^usemtl /.test( line ) ) { // material meshN( undefined, line.substring( 7 ).trim() ); - } else if ( line.startsWith( "mtllib ") ) { + } else if ( /^mtllib /.test( line ) ) { // mtl file @@ -550,7 +550,7 @@ THREE.OBJMTLLoader.prototype = { } - } else if ( line.startsWith( "s ") ) { + } else if ( /^s /.test( line ) ) { // Smooth shading diff --git a/src/Three.js b/src/Three.js index cf7a515e8f3c8c2ec64ad6ba31fec5dd6b731195..6714339fdd34e5a703ebcc119d5aae02b00db7b1 100644 --- a/src/Three.js +++ b/src/Three.js @@ -18,27 +18,6 @@ self.console = self.console || { self.Int32Array = self.Int32Array || Array; self.Float32Array = self.Float32Array || Array; -// Shims for "startsWith", "endsWith", and "trim" for browsers where this is not yet implemented -// not sure we should have this, or at least not have it here - -// http://stackoverflow.com/questions/646628/javascript-startswith -// http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript -// http://wiki.ecmascript.org/doku.php?id=harmony%3astring_extras - -String.prototype.startsWith = String.prototype.startsWith || function ( str ) { - - return this.slice( 0, str.length ) === str; - -}; - -String.prototype.endsWith = String.prototype.endsWith || function ( str ) { - - var t = String( str ); - var index = this.lastIndexOf( t ); - return ( -1 < index && index ) === (this.length - t.length); - -}; - String.prototype.trim = String.prototype.trim || function () { return this.replace( /^\s+|\s+$/g, '' ); diff --git a/src/loaders/Loader.js b/src/loaders/Loader.js index 5e7334127c317d552c0c9b804dd0dfeed872b404..dd22b0715a3b758c048a65b98a9407c09533d6d2 100644 --- a/src/loaders/Loader.js +++ b/src/loaders/Loader.js @@ -145,7 +145,7 @@ THREE.Loader.prototype = { function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) { - var isCompressed = sourceFile.toLowerCase().endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( sourceFile ); var fullPath = texturePath + "/" + sourceFile; if ( isCompressed ) { diff --git a/src/loaders/SceneLoader.js b/src/loaders/SceneLoader.js index a6243f800f4b5ab0a4aeba785083e830a2afb40b..3179aee550ca9abbac4ea01cc7248d0e555d2b89 100644 --- a/src/loaders/SceneLoader.js +++ b/src/loaders/SceneLoader.js @@ -903,7 +903,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) { } - var isCompressed = url_array[ 0 ].endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( url_array[ 0 ] ); if ( isCompressed ) { @@ -917,7 +917,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) { } else { - var isCompressed = textureJSON.url.toLowerCase().endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( textureJSON.url ); var fullUrl = get_url( textureJSON.url, data.urlBaseType ); var textureCallback = generateTextureCallback( 1 );