Texture.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.sourceFile = '';
  11. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12. this.mipmaps = [];
  13. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  14. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  15. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  16. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  17. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  18. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  19. this.format = format !== undefined ? format : THREE.RGBAFormat;
  20. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  21. this.offset = new THREE.Vector2( 0, 0 );
  22. this.repeat = new THREE.Vector2( 1, 1 );
  23. this.generateMipmaps = true;
  24. this.premultiplyAlpha = false;
  25. this.flipY = true;
  26. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  27. this._needsUpdate = false;
  28. this.onUpdate = null;
  29. };
  30. THREE.Texture.DEFAULT_IMAGE = undefined;
  31. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  32. THREE.Texture.prototype = {
  33. constructor: THREE.Texture,
  34. get needsUpdate () {
  35. return this._needsUpdate;
  36. },
  37. set needsUpdate ( value ) {
  38. if ( value === true ) this.update();
  39. this._needsUpdate = value;
  40. },
  41. clone: function ( texture ) {
  42. if ( texture === undefined ) texture = new THREE.Texture();
  43. texture.image = this.image;
  44. texture.mipmaps = this.mipmaps.slice( 0 );
  45. texture.mapping = this.mapping;
  46. texture.wrapS = this.wrapS;
  47. texture.wrapT = this.wrapT;
  48. texture.magFilter = this.magFilter;
  49. texture.minFilter = this.minFilter;
  50. texture.anisotropy = this.anisotropy;
  51. texture.format = this.format;
  52. texture.type = this.type;
  53. texture.offset.copy( this.offset );
  54. texture.repeat.copy( this.repeat );
  55. texture.generateMipmaps = this.generateMipmaps;
  56. texture.premultiplyAlpha = this.premultiplyAlpha;
  57. texture.flipY = this.flipY;
  58. texture.unpackAlignment = this.unpackAlignment;
  59. return texture;
  60. },
  61. update: function () {
  62. this.dispatchEvent( { type: 'update' } );
  63. },
  64. dispose: function () {
  65. this.dispatchEvent( { type: 'dispose' } );
  66. }
  67. };
  68. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  69. THREE.TextureIdCount = 0;