Texture.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  8. this.uuid = THREE.Math.generateUUID();
  9. this.name = '';
  10. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  11. this.mipmaps = [];
  12. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  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.DEFAULT_IMAGE = undefined;
  30. THREE.Texture.DEFAULT_MAPPING = new THREE.UVMapping();
  31. THREE.Texture.prototype = {
  32. constructor: THREE.Texture,
  33. get needsUpdate () {
  34. return this._needsUpdate;
  35. },
  36. set needsUpdate ( value ) {
  37. if ( value === true ) this.update();
  38. this._needsUpdate = value;
  39. },
  40. clone: function ( texture ) {
  41. if ( texture === undefined ) texture = new THREE.Texture();
  42. texture.image = this.image;
  43. texture.mipmaps = this.mipmaps.slice( 0 );
  44. texture.mapping = this.mapping;
  45. texture.wrapS = this.wrapS;
  46. texture.wrapT = this.wrapT;
  47. texture.magFilter = this.magFilter;
  48. texture.minFilter = this.minFilter;
  49. texture.anisotropy = this.anisotropy;
  50. texture.format = this.format;
  51. texture.type = this.type;
  52. texture.offset.copy( this.offset );
  53. texture.repeat.copy( this.repeat );
  54. texture.generateMipmaps = this.generateMipmaps;
  55. texture.premultiplyAlpha = this.premultiplyAlpha;
  56. texture.flipY = this.flipY;
  57. texture.unpackAlignment = this.unpackAlignment;
  58. return texture;
  59. },
  60. update: function () {
  61. this.dispatchEvent( { type: 'update' } );
  62. },
  63. dispose: function () {
  64. this.dispatchEvent( { type: 'dispose' } );
  65. }
  66. };
  67. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  68. THREE.TextureIdCount = 0;