ソースを参照

Merge pull request #10363 from kevanstannard/fix-svg-file-loading

Fix Loading an SVG with TextureLoader
Mr.doob 8 年 前
コミット
5ad36da0e4
1 ファイル変更7 行追加0 行削除
  1. 7 0
      src/loaders/ImageLoader.js

+ 7 - 0
src/loaders/ImageLoader.js

@@ -48,6 +48,13 @@ Object.assign( ImageLoader.prototype, {
 			loader.setPath( this.path );
 			loader.setResponseType( 'blob' );
 			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 ) {
 
 				image.src = URL.createObjectURL( blob );