Переглянути джерело

Fixed ImageLoader breakage. See #3442.

Mr.doob 12 роки тому
батько
коміт
23a2faace6

+ 2 - 5
examples/canvas_geometry_earth.html

@@ -66,16 +66,13 @@
 
 
 				var earthTexture = new THREE.Texture();
 				var earthTexture = new THREE.Texture();
 				var loader = new THREE.ImageLoader();
 				var loader = new THREE.ImageLoader();
+				loader.load( 'textures/land_ocean_ice_cloud_2048.jpg', function ( image ) {
 
 
-				loader.addEventListener( 'load', function ( event ) {
-
-					earthTexture.image = event.content;
+					earthTexture.image = image;
 					earthTexture.needsUpdate = true;
 					earthTexture.needsUpdate = true;
 
 
 				} );
 				} );
 
 
-				loader.load( 'textures/land_ocean_ice_cloud_2048.jpg' );
-
 				var geometry = new THREE.SphereGeometry( 200, 20, 20 );
 				var geometry = new THREE.SphereGeometry( 200, 20, 20 );
 				var material = new THREE.MeshBasicMaterial( { map: earthTexture, overdraw: true } );
 				var material = new THREE.MeshBasicMaterial( { map: earthTexture, overdraw: true } );
 
 

+ 4 - 12
examples/js/loaders/MTLLoader.js

@@ -418,24 +418,16 @@ THREE.MTLLoader.loadTexture = function ( url, mapping, onLoad, onError ) {
 		var texture = new THREE.Texture( image, mapping );
 		var texture = new THREE.Texture( image, mapping );
 
 
 		var loader = new THREE.ImageLoader();
 		var loader = new THREE.ImageLoader();
+		loader.crossOrigin = this.crossOrigin;
+		loader.load( url, function ( image ) {
 
 
-		loader.addEventListener( 'load', function ( event ) {
-
-			texture.image = THREE.MTLLoader.ensurePowerOfTwo_( event.content );
+			texture.image = THREE.MTLLoader.ensurePowerOfTwo_( image );
 			texture.needsUpdate = true;
 			texture.needsUpdate = true;
-			if ( onLoad ) onLoad( texture );
-
-		} );
 
 
-		loader.addEventListener( 'error', function ( event ) {
-
-			if ( onError ) onError( event.message );
+			if ( onLoad ) onLoad( texture );
 
 
 		} );
 		} );
 
 
-		loader.crossOrigin = this.crossOrigin;
-		loader.load( url, image );
-
 	}
 	}
 
 
 	return texture;
 	return texture;

+ 3 - 12
src/extras/ImageUtils.js

@@ -13,25 +13,16 @@ THREE.ImageUtils = {
 		var texture = new THREE.Texture( image, mapping );
 		var texture = new THREE.Texture( image, mapping );
 
 
 		var loader = new THREE.ImageLoader();
 		var loader = new THREE.ImageLoader();
+		loader.crossOrigin = this.crossOrigin;
+		loader.load( url, function ( image ) {
 
 
-		loader.addEventListener( 'load', function ( event ) {
-
-			texture.image = event.content;
+			texture.image = image;
 			texture.needsUpdate = true;
 			texture.needsUpdate = true;
 
 
 			if ( onLoad ) onLoad( texture );
 			if ( onLoad ) onLoad( texture );
 
 
 		} );
 		} );
 
 
-		loader.addEventListener( 'error', function ( event ) {
-
-			if ( onError ) onError( event.message );
-
-		} );
-
-		loader.crossOrigin = this.crossOrigin;
-		loader.load( url, image );
-
 		texture.sourceFile = url;
 		texture.sourceFile = url;
 
 
 		return texture;
 		return texture;

+ 7 - 12
src/loaders/LoadingManager.js

@@ -8,7 +8,6 @@ THREE.LoadingManager = function () {
 
 
 	var list = [], cache = {};
 	var list = [], cache = {};
 
 
-	var isLoading = false;
 	var loaded = 0, total = 0;
 	var loaded = 0, total = 0;
 
 
 	var crossOrigin = null;
 	var crossOrigin = null;
@@ -92,14 +91,15 @@ THREE.LoadingManager = function () {
 
 
 		scope.dispatchEvent( { type: 'load', item: item, loaded: loaded, total: total } );
 		scope.dispatchEvent( { type: 'load', item: item, loaded: loaded, total: total } );
 
 
-		if ( loaded === total ) {
+		if ( list.length > 0 ) {
 
 
-			isLoading = false;
-			scope.dispatchEvent( { type: 'complete' } );
+			load();
 
 
-		} else {
+		}
 
 
-			load();
+		if ( loaded === total ) {
+
+			scope.dispatchEvent( { type: 'complete' } );
 
 
 		}
 		}
 
 
@@ -117,12 +117,7 @@ THREE.LoadingManager = function () {
 			onError: onError
 			onError: onError
 		} );
 		} );
 
 
-		if ( isLoading === false ) {
-
-			isLoading = true;
-			load();
-
-		}
+		load();
 
 
 	};
 	};