Browse Source

Starting the *Loader change. First ImageLoader and testing.

Mr.doob 13 years ago
parent
commit
136999875f
4 changed files with 40 additions and 18 deletions
  1. 16 2
      examples/canvas_geometry_earth.html
  2. 1 1
      src/core/EventTarget.js
  3. 17 14
      src/loaders/ImageLoader.js
  4. 6 1
      utils/build.py

+ 16 - 2
examples/canvas_geometry_earth.html

@@ -60,11 +60,25 @@
 				camera.position.z = 500;
 				camera.position.z = 500;
 				scene.add( camera );
 				scene.add( camera );
 
 
-				mesh = new THREE.Mesh( new THREE.PlaneGeometry( 300, 300, 3, 3 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/shadow.png' ), overdraw: true } ) );
+				// THREE.ImageUtils.loadTexture( 'textures/shadow.png' )
+				var shadowTexture = new THREE.Texture();
+				
+				var loader = new THREE.ImageLoader();
+				loader.addEventListener( 'complete', function ( event ) { shadowTexture.image = event.image } );
+				loader.load( 'textures/shadow.png' );
+
+				mesh = new THREE.Mesh( new THREE.PlaneGeometry( 300, 300, 3, 3 ), new THREE.MeshBasicMaterial( { map: shadowTexture, overdraw: true } ) );
 				mesh.position.y = - 250;
 				mesh.position.y = - 250;
 				scene.add( mesh );
 				scene.add( mesh );
 
 
-				mesh = new THREE.Mesh( new THREE.SphereGeometry( 200, 20, 20 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/land_ocean_ice_cloud_2048.jpg' ), overdraw: true } ) );
+				// THREE.ImageUtils.loadTexture( 'textures/land_ocean_ice_cloud_2048.jpg' )
+				var earthTexture = new THREE.Texture();
+				
+				var loader = new THREE.ImageLoader();
+				loader.addEventListener( 'complete', function ( event ) { earthTexture.image = event.image } );
+				loader.load( 'textures/land_ocean_ice_cloud_2048.jpg' );
+
+				mesh = new THREE.Mesh( new THREE.SphereGeometry( 200, 20, 20 ), new THREE.MeshBasicMaterial( { map: earthTexture, overdraw: true } ) );
 				scene.add( mesh );
 				scene.add( mesh );
 
 
 				renderer = new THREE.CanvasRenderer();
 				renderer = new THREE.CanvasRenderer();

+ 1 - 1
src/extras/core/EventTarget.js → src/core/EventTarget.js

@@ -8,7 +8,7 @@ THREE.EventTarget = function () {
 
 
 	this.addEventListener = function ( type, listener ) {
 	this.addEventListener = function ( type, listener ) {
 
 
-		if ( listeners[ type ] == undefined ) {
+		if ( listeners[ type ] === undefined ) {
 
 
 			listeners[ type ] = [];
 			listeners[ type ] = [];
 
 

+ 17 - 14
src/loaders/ImageLoader.js

@@ -2,27 +2,30 @@
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
-THREE.ImageLoader = function () {};
+THREE.ImageLoader = function () {
 
 
-THREE.ImageLoader.prototype = new THREE.Loader();
-THREE.ImageLoader.prototype.constructor = THREE.ImageLoader;
+	THREE.EventTarget.call( this );
 
 
-THREE.ImageLoader.prototype.load = function ( url, callback ) {
+	var _this = this;
 
 
-	var that = this;
-	var image = new Image();
+	this.crossOrigin = 'anonymous';
 
 
-	image.onload = function () {
+	this.load = function ( url ) {
 
 
-		callback( image );
+		var image = new Image();
+		image.addEventListener( 'load', function () {
 
 
-		that.onLoadComplete();
+			_this.dispatchEvent( { type: 'complete', image: image } );
 
 
-	};
-
-	image.crossOrigin = this.crossOrigin;
-	image.src = path;
+		}, false );
+		image.addEventListener( 'error', function () {
+		
+			_this.dispatchEvent( { type: 'error', image: image } ); 
+		
+		}, false );
+		image.crossOrigin = this.crossOrigin;
+		image.src = url;
 
 
-	that.onLoadStart();
+	};
 
 
 };
 };

+ 6 - 1
utils/build.py

@@ -18,6 +18,7 @@ COMMON_FILES = [
 'core/Vector2.js',
 'core/Vector2.js',
 'core/Vector3.js',
 'core/Vector3.js',
 'core/Vector4.js',
 'core/Vector4.js',
+'core/EventTarget.js',
 'core/Frustum.js',
 'core/Frustum.js',
 'core/Ray.js',
 'core/Ray.js',
 'core/Rectangle.js',
 'core/Rectangle.js',
@@ -43,6 +44,7 @@ COMMON_FILES = [
 'lights/SpotLight.js',
 'lights/SpotLight.js',
 'loaders/Loader.js',
 'loaders/Loader.js',
 'loaders/BinaryLoader.js',
 'loaders/BinaryLoader.js',
+'loaders/ImageLoader.js',
 'loaders/JSONLoader.js',
 'loaders/JSONLoader.js',
 'loaders/SceneLoader.js',
 'loaders/SceneLoader.js',
 'materials/Material.js',
 'materials/Material.js',
@@ -95,7 +97,6 @@ EXTRAS_FILES = [
 'extras/core/BufferGeometry.js',
 'extras/core/BufferGeometry.js',
 'extras/core/Curve.js',
 'extras/core/Curve.js',
 'extras/core/CurvePath.js',
 'extras/core/CurvePath.js',
-'extras/core/EventTarget.js',
 'extras/core/Gyroscope.js',
 'extras/core/Gyroscope.js',
 'extras/core/Path.js',
 'extras/core/Path.js',
 'extras/core/Shape.js',
 'extras/core/Shape.js',
@@ -146,6 +147,7 @@ CANVAS_FILES = [
 'core/Vector2.js',
 'core/Vector2.js',
 'core/Vector3.js',
 'core/Vector3.js',
 'core/Vector4.js',
 'core/Vector4.js',
+'core/EventTarget.js',
 'core/Frustum.js',
 'core/Frustum.js',
 'core/Ray.js',
 'core/Ray.js',
 'core/Rectangle.js',
 'core/Rectangle.js',
@@ -169,6 +171,7 @@ CANVAS_FILES = [
 'lights/PointLight.js',
 'lights/PointLight.js',
 'loaders/Loader.js',
 'loaders/Loader.js',
 'loaders/BinaryLoader.js',
 'loaders/BinaryLoader.js',
+'loaders/ImageLoader.js',
 'loaders/JSONLoader.js',
 'loaders/JSONLoader.js',
 'loaders/SceneLoader.js',
 'loaders/SceneLoader.js',
 'materials/Material.js',
 'materials/Material.js',
@@ -204,6 +207,7 @@ WEBGL_FILES = [
 'core/Vector2.js',
 'core/Vector2.js',
 'core/Vector3.js',
 'core/Vector3.js',
 'core/Vector4.js',
 'core/Vector4.js',
+'core/EventTarget.js',
 'core/Frustum.js',
 'core/Frustum.js',
 'core/Ray.js',
 'core/Ray.js',
 'core/Rectangle.js',
 'core/Rectangle.js',
@@ -229,6 +233,7 @@ WEBGL_FILES = [
 'lights/SpotLight.js',
 'lights/SpotLight.js',
 'loaders/Loader.js',
 'loaders/Loader.js',
 'loaders/BinaryLoader.js',
 'loaders/BinaryLoader.js',
+'loaders/ImageLoader.js',
 'loaders/JSONLoader.js',
 'loaders/JSONLoader.js',
 'loaders/SceneLoader.js',
 'loaders/SceneLoader.js',
 'materials/Material.js',
 'materials/Material.js',