ImageLoader.js 695 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.ImageLoader = function () {
  5. THREE.EventTarget.call( this );
  6. this.crossOrigin = null;
  7. };
  8. THREE.ImageLoader.prototype = {
  9. constructor: THREE.ImageLoader,
  10. load: function ( url, image ) {
  11. var scope = this;
  12. if ( image === undefined ) image = new Image();
  13. image.addEventListener( 'load', function () {
  14. scope.dispatchEvent( { type: 'load', content: image } );
  15. }, false );
  16. image.addEventListener( 'error', function () {
  17. scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } );
  18. }, false );
  19. if ( scope.crossOrigin ) image.crossOrigin = scope.crossOrigin;
  20. image.src = url;
  21. }
  22. }