babylon.texture.js 8.4 KB

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