Texture.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. * @author szimek / https://github.com/szimek/
  5. */
  6. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  7. THREE.TextureLibrary.push( this );
  8. this.id = THREE.TextureIdCount ++;
  9. this.name = '';
  10. this.image = image;
  11. this.mipmaps = [];
  12. this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
  13. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  14. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  15. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  16. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  17. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  18. this.format = format !== undefined ? format : THREE.RGBAFormat;
  19. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  20. this.offset = new THREE.Vector2( 0, 0 );
  21. this.repeat = new THREE.Vector2( 1, 1 );
  22. this.generateMipmaps = true;
  23. this.premultiplyAlpha = false;
  24. this.flipY = true;
  25. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  26. this.needsUpdate = false;
  27. this.onUpdate = null;
  28. };
  29. THREE.Texture.prototype = {
  30. constructor: THREE.Texture,
  31. clone: function ( texture ) {
  32. if ( texture === undefined ) texture = new THREE.Texture();
  33. texture.image = this.image;
  34. texture.mipmaps = this.mipmaps.slice(0);
  35. texture.mapping = this.mapping;
  36. texture.wrapS = this.wrapS;
  37. texture.wrapT = this.wrapT;
  38. texture.magFilter = this.magFilter;
  39. texture.minFilter = this.minFilter;
  40. texture.anisotropy = this.anisotropy;
  41. texture.format = this.format;
  42. texture.type = this.type;
  43. texture.offset.copy( this.offset );
  44. texture.repeat.copy( this.repeat );
  45. texture.generateMipmaps = this.generateMipmaps;
  46. texture.premultiplyAlpha = this.premultiplyAlpha;
  47. texture.flipY = this.flipY;
  48. texture.unpackAlignment = this.unpackAlignment;
  49. return texture;
  50. },
  51. deallocate: function () {
  52. var index = THREE.TextureLibrary.indexOf( this );
  53. if ( index !== -1 ) THREE.TextureLibrary.splice( index, 1 );
  54. }
  55. };
  56. THREE.TextureIdCount = 0;
  57. THREE.TextureLibrary = [];
粤ICP备19079148号