babylon.baseTexture.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var BaseTexture = (function () {
  10. function BaseTexture(scene) {
  11. this.hasAlpha = false;
  12. this.getAlphaFromRGB = false;
  13. this.level = 1;
  14. this.coordinatesIndex = 0;
  15. this.coordinatesMode = BABYLON.Texture.EXPLICIT_MODE;
  16. this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  17. this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  18. this.anisotropicFilteringLevel = 4;
  19. this.isCube = false;
  20. this.isRenderTarget = false;
  21. this.animations = new Array();
  22. /**
  23. * An event triggered when the texture is disposed.
  24. * @type {BABYLON.Observable}
  25. */
  26. this.onDisposeObservable = new BABYLON.Observable();
  27. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  28. this._scene = scene;
  29. this._scene.textures.push(this);
  30. this._uid = null;
  31. }
  32. Object.defineProperty(BaseTexture.prototype, "uid", {
  33. get: function () {
  34. if (!this._uid) {
  35. this._uid = BABYLON.Tools.RandomId();
  36. }
  37. return this._uid;
  38. },
  39. enumerable: true,
  40. configurable: true
  41. });
  42. BaseTexture.prototype.toString = function () {
  43. return this.name;
  44. };
  45. Object.defineProperty(BaseTexture.prototype, "onDispose", {
  46. set: function (callback) {
  47. if (this._onDisposeObserver) {
  48. this.onDisposeObservable.remove(this._onDisposeObserver);
  49. }
  50. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  51. },
  52. enumerable: true,
  53. configurable: true
  54. });
  55. BaseTexture.prototype.getScene = function () {
  56. return this._scene;
  57. };
  58. BaseTexture.prototype.getTextureMatrix = function () {
  59. return null;
  60. };
  61. BaseTexture.prototype.getReflectionTextureMatrix = function () {
  62. return null;
  63. };
  64. BaseTexture.prototype.getInternalTexture = function () {
  65. return this._texture;
  66. };
  67. BaseTexture.prototype.isReady = function () {
  68. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  69. return true;
  70. }
  71. if (this._texture) {
  72. return this._texture.isReady;
  73. }
  74. return false;
  75. };
  76. BaseTexture.prototype.getSize = function () {
  77. if (this._texture._width) {
  78. return new BABYLON.Size(this._texture._width, this._texture._height);
  79. }
  80. if (this._texture._size) {
  81. return new BABYLON.Size(this._texture._size, this._texture._size);
  82. }
  83. return BABYLON.Size.Zero();
  84. };
  85. BaseTexture.prototype.getBaseSize = function () {
  86. if (!this.isReady() || !this._texture)
  87. return BABYLON.Size.Zero();
  88. if (this._texture._size) {
  89. return new BABYLON.Size(this._texture._size, this._texture._size);
  90. }
  91. return new BABYLON.Size(this._texture._baseWidth, this._texture._baseHeight);
  92. };
  93. BaseTexture.prototype.scale = function (ratio) {
  94. };
  95. Object.defineProperty(BaseTexture.prototype, "canRescale", {
  96. get: function () {
  97. return false;
  98. },
  99. enumerable: true,
  100. configurable: true
  101. });
  102. BaseTexture.prototype._removeFromCache = function (url, noMipmap) {
  103. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  104. for (var index = 0; index < texturesCache.length; index++) {
  105. var texturesCacheEntry = texturesCache[index];
  106. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  107. texturesCache.splice(index, 1);
  108. return;
  109. }
  110. }
  111. };
  112. BaseTexture.prototype._getFromCache = function (url, noMipmap, sampling) {
  113. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  114. for (var index = 0; index < texturesCache.length; index++) {
  115. var texturesCacheEntry = texturesCache[index];
  116. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  117. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  118. texturesCacheEntry.references++;
  119. return texturesCacheEntry;
  120. }
  121. }
  122. }
  123. return null;
  124. };
  125. BaseTexture.prototype.delayLoad = function () {
  126. };
  127. BaseTexture.prototype.clone = function () {
  128. return null;
  129. };
  130. BaseTexture.prototype.releaseInternalTexture = function () {
  131. if (this._texture) {
  132. this._scene.getEngine().releaseInternalTexture(this._texture);
  133. delete this._texture;
  134. }
  135. };
  136. BaseTexture.prototype.dispose = function () {
  137. // Animations
  138. this.getScene().stopAnimation(this);
  139. // Remove from scene
  140. var index = this._scene.textures.indexOf(this);
  141. if (index >= 0) {
  142. this._scene.textures.splice(index, 1);
  143. }
  144. if (this._texture === undefined) {
  145. return;
  146. }
  147. // Release
  148. this.releaseInternalTexture();
  149. // Callback
  150. this.onDisposeObservable.notifyObservers(this);
  151. this.onDisposeObservable.clear();
  152. };
  153. BaseTexture.prototype.serialize = function () {
  154. if (!this.name) {
  155. return null;
  156. }
  157. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  158. // Animations
  159. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  160. return serializationObject;
  161. };
  162. __decorate([
  163. BABYLON.serialize()
  164. ], BaseTexture.prototype, "name", void 0);
  165. __decorate([
  166. BABYLON.serialize()
  167. ], BaseTexture.prototype, "hasAlpha", void 0);
  168. __decorate([
  169. BABYLON.serialize()
  170. ], BaseTexture.prototype, "getAlphaFromRGB", void 0);
  171. __decorate([
  172. BABYLON.serialize()
  173. ], BaseTexture.prototype, "level", void 0);
  174. __decorate([
  175. BABYLON.serialize()
  176. ], BaseTexture.prototype, "coordinatesIndex", void 0);
  177. __decorate([
  178. BABYLON.serialize()
  179. ], BaseTexture.prototype, "coordinatesMode", void 0);
  180. __decorate([
  181. BABYLON.serialize()
  182. ], BaseTexture.prototype, "wrapU", void 0);
  183. __decorate([
  184. BABYLON.serialize()
  185. ], BaseTexture.prototype, "wrapV", void 0);
  186. __decorate([
  187. BABYLON.serialize()
  188. ], BaseTexture.prototype, "anisotropicFilteringLevel", void 0);
  189. __decorate([
  190. BABYLON.serialize()
  191. ], BaseTexture.prototype, "isCube", void 0);
  192. __decorate([
  193. BABYLON.serialize()
  194. ], BaseTexture.prototype, "isRenderTarget", void 0);
  195. return BaseTexture;
  196. }());
  197. BABYLON.BaseTexture = BaseTexture;
  198. })(BABYLON || (BABYLON = {}));