Browse Source

Revert to FileLoader-based ImageLoader. See #10439.

Mr.doob 8 years ago
parent
commit
e7f7d330b9
2 changed files with 44 additions and 51 deletions
  1. 40 38
      src/loaders/ImageLoader.js
  2. 4 13
      src/loaders/TextureLoader.js

+ 40 - 38
src/loaders/ImageLoader.js

@@ -1,10 +1,11 @@
-import { FileLoader } from './FileLoader';
-import { DefaultLoadingManager } from './LoadingManager';
-
 /**
  * @author mrdoob / http://mrdoob.com/
  */
 
+import { Cache } from './Cache';
+import { DefaultLoadingManager } from './LoadingManager';
+
+
 function ImageLoader( manager ) {
 
 	this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
@@ -15,56 +16,64 @@ Object.assign( ImageLoader.prototype, {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
+		if ( url === undefined ) url = '';
+
+		if ( this.path !== undefined ) url = this.path + url;
+
 		var scope = this;
 
-		var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
-		image.onload = function () {
+		var cached = Cache.get( url );
 
-			image.onload = null;
+		if ( cached !== undefined ) {
 
-			URL.revokeObjectURL( image.src );
+			scope.manager.itemStart( url );
 
-			if ( onLoad ) onLoad( image );
+			setTimeout( function () {
 
-			scope.manager.itemEnd( url );
+				if ( onLoad ) onLoad( cached );
+
+				scope.manager.itemEnd( url );
+
+			}, 0 );
+
+			return cached;
 
-		};
-		image.onerror = onError;
+		}
+
+		var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
 
-		if ( url.indexOf( 'data:' ) === 0 ) {
+		image.addEventListener( 'load', function () {
 
-			image.src = url;
+			THREE.Cache.add( url, this );
 
-		} else if ( this.crossOrigin !== undefined ) {
+			if ( onLoad ) onLoad( this );
 
-			// crossOrigin doesn't work with URL.createObjectURL()?
+			scope.manager.itemEnd( url );
 
-			image.crossOrigin = this.crossOrigin;
-			image.src = url;
+		}, false );
 
-		} else {
+		/*
+		image.addEventListener( 'progress', function ( event ) {
 
-			var loader = new FileLoader();
-			loader.setPath( this.path );
-			loader.setResponseType( 'blob' );
-			loader.setWithCredentials( this.withCredentials );
+			if ( onProgress ) onProgress( event );
 
-			// 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' );
+		}, false );
+		*/
 
-			loader.load( url, function ( blob ) {
+		image.addEventListener( 'error', function ( event ) {
 
-				image.src = URL.createObjectURL( blob );
+			if ( onError ) onError( event );
 
-			}, onProgress, onError );
+			scope.manager.itemError( url );
 
-		}
+		}, false );
+
+		if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
 
 		scope.manager.itemStart( url );
 
+		image.src = url;
+
 		return image;
 
 	},
@@ -76,13 +85,6 @@ Object.assign( ImageLoader.prototype, {
 
 	},
 
-	setWithCredentials: function ( value ) {
-
-		this.withCredentials = value;
-		return this;
-
-	},
-
 	setPath: function ( value ) {
 
 		this.path = value;

+ 4 - 13
src/loaders/TextureLoader.js

@@ -1,11 +1,12 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
 import { RGBAFormat, RGBFormat } from '../constants';
 import { ImageLoader } from './ImageLoader';
 import { Texture } from '../textures/Texture';
 import { DefaultLoadingManager } from './LoadingManager';
 
-/**
- * @author mrdoob / http://mrdoob.com/
- */
 
 function TextureLoader( manager ) {
 
@@ -21,7 +22,6 @@ Object.assign( TextureLoader.prototype, {
 
 		var loader = new ImageLoader( this.manager );
 		loader.setCrossOrigin( this.crossOrigin );
-		loader.setWithCredentials( this.withCredentials );
 		loader.setPath( this.path );
 		loader.load( url, function ( image ) {
 
@@ -51,13 +51,6 @@ Object.assign( TextureLoader.prototype, {
 
 	},
 
-	setWithCredentials: function ( value ) {
-
-		this.withCredentials = value;
-		return this;
-
-	},
-
 	setPath: function ( value ) {
 
 		this.path = value;
@@ -65,8 +58,6 @@ Object.assign( TextureLoader.prototype, {
 
 	}
 
-
-
 } );