babylon.texture.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var Texture = (function (_super) {
  10. __extends(Texture, _super);
  11. function Texture(url, scene, noMipmap, invertY) {
  12. _super.call(this, scene);
  13. this.uOffset = 0;
  14. this.vOffset = 0;
  15. this.uScale = 1.0;
  16. this.vScale = 1.0;
  17. this.uAng = 0;
  18. this.vAng = 0;
  19. this.wAng = 0;
  20. this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  21. this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  22. this.coordinatesIndex = 0;
  23. this.coordinatesMode = BABYLON.Texture.EXPLICIT_MODE;
  24. this.anisotropicFilteringLevel = 4;
  25. this.animations = new Array();
  26. this.isRenderTarget = false;
  27. this.name = url;
  28. this.url = url;
  29. this._noMipmap = noMipmap;
  30. this._invertY = invertY;
  31. if (!url) {
  32. return;
  33. }
  34. this._texture = this._getFromCache(url, noMipmap);
  35. if (!this._texture) {
  36. if (!scene.useDelayedTextureLoading) {
  37. this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene);
  38. } else {
  39. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  40. }
  41. }
  42. }
  43. Texture.prototype.delayLoad = function () {
  44. if (this.delayLoadState != BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  45. return;
  46. }
  47. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  48. this._texture = this._getFromCache(this.url, this._noMipmap);
  49. if (!this._texture) {
  50. this._texture = this.getScene().getEngine().createTexture(this.url, this._noMipmap, this._invertY, this.getScene());
  51. }
  52. };
  53. Texture.prototype._prepareRowForTextureGeneration = function (x, y, z, t) {
  54. x -= this.uOffset + 0.5;
  55. y -= this.vOffset + 0.5;
  56. z -= 0.5;
  57. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix, t);
  58. t.x *= this.uScale;
  59. t.y *= this.vScale;
  60. t.x += 0.5;
  61. t.y += 0.5;
  62. t.z += 0.5;
  63. };
  64. Texture.prototype._computeTextureMatrix = function () {
  65. if (this.uOffset === this._cachedUOffset && this.vOffset === this._cachedVOffset && this.uScale === this._cachedUScale && this.vScale === this._cachedVScale && this.uAng === this._cachedUAng && this.vAng === this._cachedVAng && this.wAng === this._cachedWAng) {
  66. return this._cachedTextureMatrix;
  67. }
  68. this._cachedUOffset = this.uOffset;
  69. this._cachedVOffset = this.vOffset;
  70. this._cachedUScale = this.uScale;
  71. this._cachedVScale = this.vScale;
  72. this._cachedUAng = this.uAng;
  73. this._cachedVAng = this.vAng;
  74. this._cachedWAng = this.wAng;
  75. if (!this._cachedTextureMatrix) {
  76. this._cachedTextureMatrix = BABYLON.Matrix.Zero();
  77. this._rowGenerationMatrix = new BABYLON.Matrix();
  78. this._t0 = BABYLON.Vector3.Zero();
  79. this._t1 = BABYLON.Vector3.Zero();
  80. this._t2 = BABYLON.Vector3.Zero();
  81. }
  82. BABYLON.Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix);
  83. this._prepareRowForTextureGeneration(0, 0, 0, this._t0);
  84. this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1);
  85. this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2);
  86. this._t1.subtractInPlace(this._t0);
  87. this._t2.subtractInPlace(this._t0);
  88. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  89. this._cachedTextureMatrix.m[0] = this._t1.x;
  90. this._cachedTextureMatrix.m[1] = this._t1.y;
  91. this._cachedTextureMatrix.m[2] = this._t1.z;
  92. this._cachedTextureMatrix.m[4] = this._t2.x;
  93. this._cachedTextureMatrix.m[5] = this._t2.y;
  94. this._cachedTextureMatrix.m[6] = this._t2.z;
  95. this._cachedTextureMatrix.m[8] = this._t0.x;
  96. this._cachedTextureMatrix.m[9] = this._t0.y;
  97. this._cachedTextureMatrix.m[10] = this._t0.z;
  98. return this._cachedTextureMatrix;
  99. };
  100. Texture.prototype._computeReflectionTextureMatrix = function () {
  101. if (this.uOffset === this._cachedUOffset && this.vOffset === this._cachedVOffset && this.uScale === this._cachedUScale && this.vScale === this._cachedVScale && this.coordinatesMode === this._cachedCoordinatesMode) {
  102. return this._cachedTextureMatrix;
  103. }
  104. if (!this._cachedTextureMatrix) {
  105. this._cachedTextureMatrix = BABYLON.Matrix.Zero();
  106. this._projectionModeMatrix = BABYLON.Matrix.Zero();
  107. }
  108. switch (this.coordinatesMode) {
  109. case BABYLON.Texture.SPHERICAL_MODE:
  110. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  111. this._cachedTextureMatrix[0] = -0.5 * this.uScale;
  112. this._cachedTextureMatrix[5] = -0.5 * this.vScale;
  113. this._cachedTextureMatrix[12] = 0.5 + this.uOffset;
  114. this._cachedTextureMatrix[13] = 0.5 + this.vOffset;
  115. break;
  116. case BABYLON.Texture.PLANAR_MODE:
  117. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  118. this._cachedTextureMatrix[0] = this.uScale;
  119. this._cachedTextureMatrix[5] = this.vScale;
  120. this._cachedTextureMatrix[12] = this.uOffset;
  121. this._cachedTextureMatrix[13] = this.vOffset;
  122. break;
  123. case BABYLON.Texture.PROJECTION_MODE:
  124. BABYLON.Matrix.IdentityToRef(this._projectionModeMatrix);
  125. this._projectionModeMatrix.m[0] = 0.5;
  126. this._projectionModeMatrix.m[5] = -0.5;
  127. this._projectionModeMatrix.m[10] = 0.0;
  128. this._projectionModeMatrix.m[12] = 0.5;
  129. this._projectionModeMatrix.m[13] = 0.5;
  130. this._projectionModeMatrix.m[14] = 1.0;
  131. this._projectionModeMatrix.m[15] = 1.0;
  132. this.getScene().getProjectionMatrix().multiplyToRef(this._projectionModeMatrix, this._cachedTextureMatrix);
  133. break;
  134. default:
  135. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  136. break;
  137. }
  138. return this._cachedTextureMatrix;
  139. };
  140. Texture.prototype.clone = function () {
  141. var newTexture = new BABYLON.Texture(this._texture.url, this.getScene(), this._noMipmap, this._invertY);
  142. // Base texture
  143. newTexture.hasAlpha = this.hasAlpha;
  144. newTexture.level = this.level;
  145. // Texture
  146. newTexture.uOffset = this.uOffset;
  147. newTexture.vOffset = this.vOffset;
  148. newTexture.uScale = this.uScale;
  149. newTexture.vScale = this.vScale;
  150. newTexture.uAng = this.uAng;
  151. newTexture.vAng = this.vAng;
  152. newTexture.wAng = this.wAng;
  153. newTexture.wrapU = this.wrapU;
  154. newTexture.wrapV = this.wrapV;
  155. newTexture.coordinatesIndex = this.coordinatesIndex;
  156. newTexture.coordinatesMode = this.coordinatesMode;
  157. return newTexture;
  158. };
  159. Texture.NEAREST_SAMPLINGMODE = 1;
  160. Texture.BILINEAR_SAMPLINGMODE = 2;
  161. Texture.TRILINEAR_SAMPLINGMODE = 3;
  162. Texture.EXPLICIT_MODE = 0;
  163. Texture.SPHERICAL_MODE = 1;
  164. Texture.PLANAR_MODE = 2;
  165. Texture.CUBIC_MODE = 3;
  166. Texture.PROJECTION_MODE = 4;
  167. Texture.SKYBOX_MODE = 5;
  168. Texture.CLAMP_ADDRESSMODE = 0;
  169. Texture.WRAP_ADDRESSMODE = 1;
  170. Texture.MIRROR_ADDRESSMODE = 2;
  171. return Texture;
  172. })(BABYLON.BaseTexture);
  173. BABYLON.Texture = Texture;
  174. })(BABYLON || (BABYLON = {}));
  175. //# sourceMappingURL=babylon.texture.js.map