Explorar el Código

Explicitly set the SVG MIME type (to fix loading SVGs as textures)

Kevan Stannard hace 8 años
padre
commit
18d14c261f
Se han modificado 2 ficheros con 7 adiciones y 5 borrados
  1. 0 5
      src/loaders/FileLoader.js
  2. 7 0
      src/loaders/ImageLoader.js

+ 0 - 5
src/loaders/FileLoader.js

@@ -184,11 +184,6 @@ Object.assign( FileLoader.prototype, {
 			if ( this.responseType !== undefined ) request.responseType = this.responseType;
 			if ( this.responseType !== undefined ) request.responseType = this.responseType;
 			if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
 			if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
 
 
-			// Setting 'text/plain' as the MIME type for SVG files will cause a
-			// problem when the ImageLoader tries to use it as the src of an image,
-			// so explicitly set the SVG MIME type.
-			if ( /\.svg$/.test( url ) ) this.mimeType = 'image/svg+xml';
-
 			if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
 			if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
 
 
 			request.send( null );
 			request.send( null );

+ 7 - 0
src/loaders/ImageLoader.js

@@ -48,6 +48,13 @@ Object.assign( ImageLoader.prototype, {
 			loader.setPath( this.path );
 			loader.setPath( this.path );
 			loader.setResponseType( 'blob' );
 			loader.setResponseType( 'blob' );
 			loader.setWithCredentials( this.withCredentials );
 			loader.setWithCredentials( this.withCredentials );
+
+			// By default the FileLoader requests files to be loaded with a MIME
+			// type of `text/plain`. Using `URL.createObjectURL()` with SVGs that
+			// have a MIME type of `text/plain` results in an error, so explicitly
+			// set the SVG MIME type.
+			if ( /\.svg$/.test( url ) ) loader.setMimeType( 'image/svg+xml' );
+
 			loader.load( url, function ( blob ) {
 			loader.load( url, function ( blob ) {
 
 
 				image.src = URL.createObjectURL( blob );
 				image.src = URL.createObjectURL( blob );