babylon.baseTexture.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var BaseTexture = (function () {
  4. function BaseTexture(scene) {
  5. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  6. this.hasAlpha = false;
  7. this.getAlphaFromRGB = false;
  8. this.level = 1;
  9. this.isCube = false;
  10. this.isRenderTarget = false;
  11. this.animations = new Array();
  12. this.coordinatesIndex = 0;
  13. this.coordinatesMode = BABYLON.Texture.EXPLICIT_MODE;
  14. this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  15. this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  16. this.anisotropicFilteringLevel = 4;
  17. this._scene = scene;
  18. this._scene.textures.push(this);
  19. }
  20. BaseTexture.prototype.getScene = function () {
  21. return this._scene;
  22. };
  23. BaseTexture.prototype.getTextureMatrix = function () {
  24. return null;
  25. };
  26. BaseTexture.prototype.getReflectionTextureMatrix = function () {
  27. return null;
  28. };
  29. BaseTexture.prototype.getInternalTexture = function () {
  30. return this._texture;
  31. };
  32. BaseTexture.prototype.isReady = function () {
  33. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  34. return true;
  35. }
  36. if (this._texture) {
  37. return this._texture.isReady;
  38. }
  39. return false;
  40. };
  41. BaseTexture.prototype.getSize = function () {
  42. if (this._texture._width) {
  43. return { width: this._texture._width, height: this._texture._height };
  44. }
  45. if (this._texture._size) {
  46. return { width: this._texture._size, height: this._texture._size };
  47. }
  48. return { width: 0, height: 0 };
  49. };
  50. BaseTexture.prototype.getBaseSize = function () {
  51. if (!this.isReady())
  52. return { width: 0, height: 0 };
  53. if (this._texture._size) {
  54. return { width: this._texture._size, height: this._texture._size };
  55. }
  56. return { width: this._texture._baseWidth, height: this._texture._baseHeight };
  57. };
  58. BaseTexture.prototype.scale = function (ratio) {
  59. };
  60. Object.defineProperty(BaseTexture.prototype, "canRescale", {
  61. get: function () {
  62. return false;
  63. },
  64. enumerable: true,
  65. configurable: true
  66. });
  67. BaseTexture.prototype._removeFromCache = function (url, noMipmap) {
  68. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  69. for (var index = 0; index < texturesCache.length; index++) {
  70. var texturesCacheEntry = texturesCache[index];
  71. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  72. texturesCache.splice(index, 1);
  73. return;
  74. }
  75. }
  76. };
  77. BaseTexture.prototype._getFromCache = function (url, noMipmap, sampling) {
  78. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  79. for (var index = 0; index < texturesCache.length; index++) {
  80. var texturesCacheEntry = texturesCache[index];
  81. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  82. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  83. texturesCacheEntry.references++;
  84. return texturesCacheEntry;
  85. }
  86. }
  87. }
  88. return null;
  89. };
  90. BaseTexture.prototype.delayLoad = function () {
  91. };
  92. BaseTexture.prototype.clone = function () {
  93. return null;
  94. };
  95. BaseTexture.prototype.releaseInternalTexture = function () {
  96. if (this._texture) {
  97. this._scene.getEngine().releaseInternalTexture(this._texture);
  98. delete this._texture;
  99. }
  100. };
  101. BaseTexture.prototype.dispose = function () {
  102. // Animations
  103. this.getScene().stopAnimation(this);
  104. // Remove from scene
  105. var index = this._scene.textures.indexOf(this);
  106. if (index >= 0) {
  107. this._scene.textures.splice(index, 1);
  108. }
  109. if (this._texture === undefined) {
  110. return;
  111. }
  112. // Release
  113. this.releaseInternalTexture();
  114. // Callback
  115. if (this.onDispose) {
  116. this.onDispose();
  117. }
  118. };
  119. BaseTexture.prototype.serialize = function () {
  120. var serializationObject = {};
  121. if (!this.name) {
  122. return null;
  123. }
  124. serializationObject.name = this.name;
  125. serializationObject.hasAlpha = this.hasAlpha;
  126. serializationObject.level = this.level;
  127. serializationObject.coordinatesIndex = this.coordinatesIndex;
  128. serializationObject.coordinatesMode = this.coordinatesMode;
  129. serializationObject.wrapU = this.wrapU;
  130. serializationObject.wrapV = this.wrapV;
  131. // Animations
  132. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  133. return serializationObject;
  134. };
  135. return BaseTexture;
  136. }());
  137. BABYLON.BaseTexture = BaseTexture;
  138. })(BABYLON || (BABYLON = {}));