babylon.cubeTexture.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, files) {
  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 && !files) {
  18. return;
  19. }
  20. this._texture = this._getFromCache(rootUrl, noMipmap);
  21. if (!files) {
  22. if (!extensions) {
  23. extensions = ["_px.jpg", "_py.jpg", "_pz.jpg", "_nx.jpg", "_ny.jpg", "_nz.jpg"];
  24. }
  25. files = [];
  26. for (var index = 0; index < extensions.length; index++) {
  27. files.push(rootUrl + extensions[index]);
  28. }
  29. this._extensions = extensions;
  30. }
  31. this._files = files;
  32. if (!this._texture) {
  33. if (!scene.useDelayedTextureLoading) {
  34. this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap);
  35. }
  36. else {
  37. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  38. }
  39. }
  40. this.isCube = true;
  41. this._textureMatrix = BABYLON.Matrix.Identity();
  42. }
  43. CubeTexture.CreateFromImages = function (files, scene, noMipmap) {
  44. return new CubeTexture("", scene, null, noMipmap, files);
  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._files, this._noMipmap);
  55. }
  56. };
  57. CubeTexture.prototype.getReflectionTextureMatrix = function () {
  58. return this._textureMatrix;
  59. };
  60. CubeTexture.Parse = function (parsedTexture, scene, rootUrl) {
  61. var texture = BABYLON.SerializationHelper.Parse(function () {
  62. return new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.extensions);
  63. }, parsedTexture, scene);
  64. // Animations
  65. if (parsedTexture.animations) {
  66. for (var animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {
  67. var parsedAnimation = parsedTexture.animations[animationIndex];
  68. texture.animations.push(BABYLON.Animation.Parse(parsedAnimation));
  69. }
  70. }
  71. return texture;
  72. };
  73. CubeTexture.prototype.clone = function () {
  74. var _this = this;
  75. return BABYLON.SerializationHelper.Clone(function () {
  76. return new CubeTexture(_this.url, _this.getScene(), _this._extensions, _this._noMipmap, _this._files);
  77. }, this);
  78. };
  79. return CubeTexture;
  80. }(BABYLON.BaseTexture));
  81. BABYLON.CubeTexture = CubeTexture;
  82. })(BABYLON || (BABYLON = {}));