TextureLoader.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. import { RGBAFormat, RGBFormat } from '../constants.js';
  5. import { ImageLoader } from './ImageLoader.js';
  6. import { Texture } from '../textures/Texture.js';
  7. import { Loader } from './Loader.js';
  8. function TextureLoader( manager ) {
  9. Loader.call( this, manager );
  10. }
  11. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  12. constructor: TextureLoader,
  13. load: function ( url, onLoad, onProgress, onError ) {
  14. const texture = new Texture();
  15. const loader = new ImageLoader( this.manager );
  16. loader.setCrossOrigin( this.crossOrigin );
  17. loader.setPath( this.path );
  18. loader.load( url, function ( image ) {
  19. texture.image = image;
  20. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21. const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  22. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  23. texture.needsUpdate = true;
  24. if ( onLoad !== undefined ) {
  25. onLoad( texture );
  26. }
  27. }, onProgress, onError );
  28. return texture;
  29. }
  30. } );
  31. export { TextureLoader };