CubeTextureLoader.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. import { ImageLoader } from './ImageLoader.js';
  5. import { CubeTexture } from '../textures/CubeTexture.js';
  6. import { DefaultLoadingManager } from './LoadingManager.js';
  7. function CubeTextureLoader( manager ) {
  8. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  9. }
  10. Object.assign( CubeTextureLoader.prototype, {
  11. crossOrigin: 'anonymous',
  12. load: function ( urls, onLoad, onProgress, onError ) {
  13. var texture = new CubeTexture();
  14. var loader = new ImageLoader( this.manager );
  15. loader.setCrossOrigin( this.crossOrigin );
  16. loader.setPath( this.path );
  17. var loaded = 0;
  18. function loadTexture( i ) {
  19. loader.load( urls[ i ], function ( image ) {
  20. texture.images[ i ] = image;
  21. loaded ++;
  22. if ( loaded === 6 ) {
  23. texture.needsUpdate = true;
  24. if ( onLoad ) onLoad( texture );
  25. }
  26. }, undefined, onError );
  27. }
  28. for ( var i = 0; i < urls.length; ++ i ) {
  29. loadTexture( i );
  30. }
  31. return texture;
  32. },
  33. setCrossOrigin: function ( value ) {
  34. this.crossOrigin = value;
  35. return this;
  36. },
  37. setPath: function ( value ) {
  38. this.path = value;
  39. return this;
  40. }
  41. } );
  42. export { CubeTextureLoader };