瀏覽代碼

Fixed ImageLoader breakage. See #3442.

Mr.doob 12 年之前
父節點
當前提交
23a2faace6
共有 4 個文件被更改,包括 16 次插入41 次删除
  1. 2 5
      examples/canvas_geometry_earth.html
  2. 4 12
      examples/js/loaders/MTLLoader.js
  3. 3 12
      src/extras/ImageUtils.js
  4. 7 12
      src/loaders/LoadingManager.js

+ 2 - 5
examples/canvas_geometry_earth.html

@@ -66,16 +66,13 @@
 
 				var earthTexture = new THREE.Texture();
 				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;
 
 				} );
 
-				loader.load( 'textures/land_ocean_ice_cloud_2048.jpg' );
-
 				var geometry = new THREE.SphereGeometry( 200, 20, 20 );
 				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 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;
-			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;

+ 3 - 12
src/extras/ImageUtils.js

@@ -13,25 +13,16 @@ THREE.ImageUtils = {
 		var texture = new THREE.Texture( image, mapping );
 
 		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;
 
 			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;
 
 		return texture;

+ 7 - 12
src/loaders/LoadingManager.js

@@ -8,7 +8,6 @@ THREE.LoadingManager = function () {
 
 	var list = [], cache = {};
 
-	var isLoading = false;
 	var loaded = 0, total = 0;
 
 	var crossOrigin = null;
@@ -92,14 +91,15 @@ THREE.LoadingManager = function () {
 
 		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
 		} );
 
-		if ( isLoading === false ) {
-
-			isLoading = true;
-			load();
-
-		}
+		load();
 
 	};