babylon.cubeTexture.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var __extends = (this && 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. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var CubeTexture = (function (_super) {
  9. __extends(CubeTexture, _super);
  10. function CubeTexture(rootUrl, scene, extensions, noMipmap) {
  11. _super.call(this, scene);
  12. this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
  13. this.name = rootUrl;
  14. this.url = rootUrl;
  15. this._noMipmap = noMipmap;
  16. this.hasAlpha = false;
  17. if (!rootUrl) {
  18. return;
  19. }
  20. this._texture = this._getFromCache(rootUrl, noMipmap);
  21. if (!extensions) {
  22. extensions = ["_px.jpg", "_py.jpg", "_pz.jpg", "_nx.jpg", "_ny.jpg", "_nz.jpg"];
  23. }
  24. this._extensions = extensions;
  25. if (!this._texture) {
  26. if (!scene.useDelayedTextureLoading) {
  27. this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, extensions, noMipmap);
  28. }
  29. else {
  30. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  31. }
  32. }
  33. this.isCube = true;
  34. this._textureMatrix = BABYLON.Matrix.Identity();
  35. }
  36. CubeTexture.prototype.clone = function () {
  37. var newTexture = new CubeTexture(this.url, this.getScene(), this._extensions, this._noMipmap);
  38. // Base texture
  39. newTexture.level = this.level;
  40. newTexture.wrapU = this.wrapU;
  41. newTexture.wrapV = this.wrapV;
  42. newTexture.coordinatesIndex = this.coordinatesIndex;
  43. newTexture.coordinatesMode = this.coordinatesMode;
  44. return newTexture;
  45. };
  46. // Methods
  47. CubeTexture.prototype.delayLoad = function () {
  48. if (this.delayLoadState !== BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  49. return;
  50. }
  51. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  52. this._texture = this._getFromCache(this.url, this._noMipmap);
  53. if (!this._texture) {
  54. this._texture = this.getScene().getEngine().createCubeTexture(this.url, this.getScene(), this._extensions);
  55. }
  56. };
  57. CubeTexture.prototype.getReflectionTextureMatrix = function () {
  58. return this._textureMatrix;
  59. };
  60. CubeTexture.ParseCubeTexture = function (parsedTexture, scene, rootUrl) {
  61. var texture = null;
  62. if ((parsedTexture.name || parsedTexture.extensions) && !parsedTexture.isRenderTarget) {
  63. texture = new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.extensions);
  64. texture.name = parsedTexture.name;
  65. texture.hasAlpha = parsedTexture.hasAlpha;
  66. texture.level = parsedTexture.level;
  67. texture.coordinatesMode = parsedTexture.coordinatesMode;
  68. }
  69. return texture;
  70. };
  71. CubeTexture.prototype.serialize = function () {
  72. if (!this.name) {
  73. return null;
  74. }
  75. var serializationObject = {};
  76. serializationObject.name = this.name;
  77. serializationObject.hasAlpha = this.hasAlpha;
  78. serializationObject.isCube = true;
  79. serializationObject.level = this.level;
  80. serializationObject.coordinatesMode = this.coordinatesMode;
  81. return serializationObject;
  82. };
  83. return CubeTexture;
  84. })(BABYLON.BaseTexture);
  85. BABYLON.CubeTexture = CubeTexture;
  86. })(BABYLON || (BABYLON = {}));