babylon.baseTexture.js 6.8 KB

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