BinaryTextureLoader.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @author Nikos M. / https://github.com/foo123/
  3. *
  4. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  5. */
  6. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  7. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8. // override in sub classes
  9. this._parser = null;
  10. };
  11. Object.assign( THREE.BinaryTextureLoader.prototype, {
  12. load: function ( url, onLoad, onProgress, onError ) {
  13. var scope = this;
  14. var texture = new THREE.DataTexture();
  15. var loader = new THREE.XHRLoader( this.manager );
  16. loader.setResponseType( 'arraybuffer' );
  17. loader.load( url, function ( buffer ) {
  18. var texData = scope._parser( buffer );
  19. if ( ! texData ) return;
  20. if ( undefined !== texData.image ) {
  21. texture.image = texData.image;
  22. } else if ( undefined !== texData.data ) {
  23. texture.image.width = texData.width;
  24. texture.image.height = texData.height;
  25. texture.image.data = texData.data;
  26. }
  27. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  28. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  29. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  30. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  31. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  32. if ( undefined !== texData.format ) {
  33. texture.format = texData.format;
  34. }
  35. if ( undefined !== texData.type ) {
  36. texture.type = texData.type;
  37. }
  38. if ( undefined !== texData.mipmaps ) {
  39. texture.mipmaps = texData.mipmaps;
  40. }
  41. if ( 1 === texData.mipmapCount ) {
  42. texture.minFilter = THREE.LinearFilter;
  43. }
  44. texture.needsUpdate = true;
  45. if ( onLoad ) onLoad( texture, texData );
  46. }, onProgress, onError );
  47. return texture;
  48. }
  49. } );
粤ICP备19079148号