Browse Source

TextureLoader correctly passes onError, onProgress

Nick Yahnke 11 years ago
parent
commit
33fac5733c
2 changed files with 158 additions and 1 deletions
  1. 157 0
      examples/webgl_loader_callbacks.html
  2. 1 1
      src/loaders/TextureLoader.js

+ 157 - 0
examples/webgl_loader_callbacks.html

@@ -0,0 +1,157 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<title>three.js webgl - loader callbacks</title>
+		<style>
+
+			body {
+				margin: 0;
+				font-family: Arial;
+				overflow: hidden;
+			}
+
+			a {
+				color: #ffffff;
+			}
+
+			#info {
+				position: absolute;
+				top: 0px;
+				width: 100%;
+				color: #ffffff;
+				padding: 5px;
+				font-family: Monospace;
+				font-size: 13px;
+				font-weight: bold;
+				text-align: center;
+				z-index: 1;
+			}
+
+			#menu {
+				position: absolute;
+				bottom: 20px;
+				width: 100%;
+				text-align: center;
+				padding: 0;
+				margin: 0;
+			}
+
+			button {
+				color: rgb(255,255,255);
+				background: transparent;
+				border: 0px;
+				padding: 5px 10px;
+				cursor: pointer;
+			}
+			button:hover {
+				background-color: rgba(0,255,255,0.5);
+			}
+			button:active {
+				color: #000000;
+				background-color: rgba(0,255,255,1);
+			}
+
+			.bond {
+				width: 5px;
+				height: 10px;
+				background: #eee;
+				display: block;
+			}
+		</style>
+	</head>
+	<body>
+		<script src="../build/three.js"></script>
+		<script src="js/controls/TrackballControls.js"></script>
+
+		<div id="container"></div>
+		<div id="info"><a href="http://threejs.org" target="_blank">three.js webgl</a> - molecules</div>
+
+		<script>
+			var camera, scene, renderer;
+			var controls;
+
+			init();
+			animate();
+
+			function init() {
+
+				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 5000 );
+				camera.position.z = 3;
+
+				scene = new THREE.Scene();
+
+				var light = new THREE.HemisphereLight( 0xffffff, 0x000000 );
+				light.position.set( 1, 1, 1 );
+				scene.add( light );
+
+				//
+
+				renderer = new THREE.WebGLRenderer( { antialias: true } );
+				renderer.setClearColor( 0x050505 );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+				document.getElementById( 'container' ).appendChild( renderer.domElement );
+
+				//
+
+				controls = new THREE.TrackballControls( camera, renderer.domElement );
+				controls.rotateSpeed = 0.5;
+				controls.addEventListener( 'change', render );
+
+
+				window.addEventListener( 'resize', onWindowResize, false );
+
+				var textureLoader = new THREE.TextureLoader()
+				textureLoader.load('textures/crate.gif', function(texture) {
+					console.log('texture loaded')
+					var material = new THREE.SpriteMaterial({ map: texture, color: 0xffffff, useScreenCoordinates: false})
+					var sp = new THREE.Sprite(material);
+					scene.add(sp)
+
+				}, function(progress) {
+					console.log('do we have progress?')
+				})
+				textureLoader.load('textures/404-texture-doesnt-exist.bmp', function(texture) {
+
+				},function () {
+					//progress callback
+				}, function (error) {
+					console.log('error caught - image not loaded')
+					console.log(error)
+				})
+
+			}
+
+			//
+
+			function onWindowResize() {
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				render();
+
+			}
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+				controls.update();
+
+				render();
+
+			}
+
+			function render() {
+
+				renderer.render( scene, camera );
+
+			}
+
+    </script>
+  </body>
+
+</html>

+ 1 - 1
src/loaders/TextureLoader.js

@@ -29,7 +29,7 @@ THREE.TextureLoader.prototype = {
 
 			}
 
-		} );
+		}, onProgress, onError );
 
 	},