TextureLoader.js 1.1 KB

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