babylon.baseTexture.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. }
  31. BaseTexture.prototype.toString = function () {
  32. return this.name;
  33. };
  34. Object.defineProperty(BaseTexture.prototype, "onDispose", {
  35. set: function (callback) {
  36. if (this._onDisposeObserver) {
  37. this.onDisposeObservable.remove(this._onDisposeObserver);
  38. }
  39. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  40. },
  41. enumerable: true,
  42. configurable: true
  43. });
  44. BaseTexture.prototype.getScene = function () {
  45. return this._scene;
  46. };
  47. BaseTexture.prototype.getTextureMatrix = function () {
  48. return null;
  49. };
  50. BaseTexture.prototype.getReflectionTextureMatrix = function () {
  51. return null;
  52. };
  53. BaseTexture.prototype.getInternalTexture = function () {
  54. return this._texture;
  55. };
  56. BaseTexture.prototype.isReady = function () {
  57. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  58. return true;
  59. }
  60. if (this._texture) {
  61. return this._texture.isReady;
  62. }
  63. return false;
  64. };
  65. BaseTexture.prototype.getSize = function () {
  66. if (this._texture._width) {
  67. return new BABYLON.Size(this._texture._width, this._texture._height);
  68. }
  69. if (this._texture._size) {
  70. return new BABYLON.Size(this._texture._size, this._texture._size);
  71. }
  72. return BABYLON.Size.Zero();
  73. };
  74. BaseTexture.prototype.getBaseSize = function () {
  75. if (!this.isReady() || !this._texture)
  76. return BABYLON.Size.Zero();
  77. if (this._texture._size) {
  78. return new BABYLON.Size(this._texture._size, this._texture._size);
  79. }
  80. return new BABYLON.Size(this._texture._baseWidth, this._texture._baseHeight);
  81. };
  82. BaseTexture.prototype.scale = function (ratio) {
  83. };
  84. Object.defineProperty(BaseTexture.prototype, "canRescale", {
  85. get: function () {
  86. return false;
  87. },
  88. enumerable: true,
  89. configurable: true
  90. });
  91. BaseTexture.prototype._removeFromCache = function (url, noMipmap) {
  92. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  93. for (var index = 0; index < texturesCache.length; index++) {
  94. var texturesCacheEntry = texturesCache[index];
  95. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  96. texturesCache.splice(index, 1);
  97. return;
  98. }
  99. }
  100. };
  101. BaseTexture.prototype._getFromCache = function (url, noMipmap, sampling) {
  102. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  103. for (var index = 0; index < texturesCache.length; index++) {
  104. var texturesCacheEntry = texturesCache[index];
  105. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  106. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  107. texturesCacheEntry.references++;
  108. return texturesCacheEntry;
  109. }
  110. }
  111. }
  112. return null;
  113. };
  114. BaseTexture.prototype.delayLoad = function () {
  115. };
  116. BaseTexture.prototype.clone = function () {
  117. return null;
  118. };
  119. BaseTexture.prototype.releaseInternalTexture = function () {
  120. if (this._texture) {
  121. this._scene.getEngine().releaseInternalTexture(this._texture);
  122. delete this._texture;
  123. }
  124. };
  125. BaseTexture.prototype.dispose = function () {
  126. // Animations
  127. this.getScene().stopAnimation(this);
  128. // Remove from scene
  129. var index = this._scene.textures.indexOf(this);
  130. if (index >= 0) {
  131. this._scene.textures.splice(index, 1);
  132. }
  133. if (this._texture === undefined) {
  134. return;
  135. }
  136. // Release
  137. this.releaseInternalTexture();
  138. // Callback
  139. this.onDisposeObservable.notifyObservers(this);
  140. this.onDisposeObservable.clear();
  141. };
  142. BaseTexture.prototype.serialize = function () {
  143. if (!this.name) {
  144. return null;
  145. }
  146. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  147. // Animations
  148. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  149. return serializationObject;
  150. };
  151. __decorate([
  152. BABYLON.serialize()
  153. ], BaseTexture.prototype, "name", void 0);
  154. __decorate([
  155. BABYLON.serialize()
  156. ], BaseTexture.prototype, "hasAlpha", void 0);
  157. __decorate([
  158. BABYLON.serialize()
  159. ], BaseTexture.prototype, "getAlphaFromRGB", void 0);
  160. __decorate([
  161. BABYLON.serialize()
  162. ], BaseTexture.prototype, "level", void 0);
  163. __decorate([
  164. BABYLON.serialize()
  165. ], BaseTexture.prototype, "coordinatesIndex", void 0);
  166. __decorate([
  167. BABYLON.serialize()
  168. ], BaseTexture.prototype, "coordinatesMode", void 0);
  169. __decorate([
  170. BABYLON.serialize()
  171. ], BaseTexture.prototype, "wrapU", void 0);
  172. __decorate([
  173. BABYLON.serialize()
  174. ], BaseTexture.prototype, "wrapV", void 0);
  175. __decorate([
  176. BABYLON.serialize()
  177. ], BaseTexture.prototype, "anisotropicFilteringLevel", void 0);
  178. __decorate([
  179. BABYLON.serialize()
  180. ], BaseTexture.prototype, "isCube", void 0);
  181. __decorate([
  182. BABYLON.serialize()
  183. ], BaseTexture.prototype, "isRenderTarget", void 0);
  184. return BaseTexture;
  185. })();
  186. BABYLON.BaseTexture = BaseTexture;
  187. })(BABYLON || (BABYLON = {}));