BinaryTextureLoader.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. THREE.BinaryTextureLoader.prototype = {
  12. constructor: THREE.BinaryTextureLoader,
  13. load: function ( url, onLoad, onProgress, onError ) {
  14. var scope = this;
  15. var texture = new THREE.DataTexture();
  16. var loader = new THREE.XHRLoader( this.manager );
  17. loader.setCrossOrigin( this.crossOrigin );
  18. loader.setResponseType( 'arraybuffer' );
  19. loader.load( url, function ( buffer ) {
  20. var texData = scope._parser( buffer );
  21. if ( ! texData ) return;
  22. if ( undefined !== texData.image ) {
  23. texture.image = texData.image;
  24. } else if ( undefined !== texData.data ) {
  25. texture.image.width = texData.width;
  26. texture.image.height = texData.height;
  27. texture.image.data = texData.data;
  28. }
  29. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  30. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  31. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  32. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  33. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  34. if ( undefined !== texData.format ) {
  35. texture.format = texData.format;
  36. }
  37. if ( undefined !== texData.type ) {
  38. texture.type = texData.type;
  39. }
  40. if ( undefined !== texData.mipmaps ) {
  41. texture.mipmaps = texData.mipmaps;
  42. }
  43. if ( 1 === texData.mipmapCount ) {
  44. texture.minFilter = THREE.LinearFilter;
  45. }
  46. texture.needsUpdate = true;
  47. if ( onLoad ) onLoad( texture, texData );
  48. }, onProgress, onError );
  49. return texture;
  50. },
  51. setCrossOrigin: function ( value ) {
  52. this.crossOrigin = value;
  53. }
  54. };
粤ICP备19079148号