babylon.cubeTexture.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. module BABYLON {
  2. export class CubeTexture extends BaseTexture {
  3. public url: string;
  4. public coordinatesMode = Texture.CUBIC_MODE;
  5. private _noMipmap: boolean;
  6. private _extensions: string[];
  7. private _textureMatrix: Matrix;
  8. constructor(rootUrl: string, scene: Scene, extensions?: string[], noMipmap?: boolean) {
  9. super(scene);
  10. this.name = rootUrl;
  11. this.url = rootUrl;
  12. this._noMipmap = noMipmap;
  13. this.hasAlpha = false;
  14. this._texture = this._getFromCache(rootUrl, noMipmap);
  15. if (!extensions) {
  16. extensions = ["_px.jpg", "_py.jpg", "_pz.jpg", "_nx.jpg", "_ny.jpg", "_nz.jpg"];
  17. }
  18. this._extensions = extensions;
  19. if (!this._texture) {
  20. if (!scene.useDelayedTextureLoading) {
  21. this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, extensions, noMipmap);
  22. } else {
  23. this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
  24. }
  25. }
  26. this.isCube = true;
  27. this._textureMatrix = Matrix.Identity();
  28. }
  29. public clone(): CubeTexture {
  30. var newTexture = new CubeTexture(this.url, this.getScene(), this._extensions, this._noMipmap);
  31. // Base texture
  32. newTexture.level = this.level;
  33. newTexture.wrapU = this.wrapU;
  34. newTexture.wrapV = this.wrapV;
  35. newTexture.coordinatesIndex = this.coordinatesIndex;
  36. newTexture.coordinatesMode = this.coordinatesMode;
  37. return newTexture;
  38. }
  39. // Methods
  40. public delayLoad(): void {
  41. if (this.delayLoadState !== Engine.DELAYLOADSTATE_NOTLOADED) {
  42. return;
  43. }
  44. this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
  45. this._texture = this._getFromCache(this.url, this._noMipmap);
  46. if (!this._texture) {
  47. this._texture = this.getScene().getEngine().createCubeTexture(this.url, this.getScene(), this._extensions);
  48. }
  49. }
  50. public getReflectionTextureMatrix(): Matrix {
  51. return this._textureMatrix;
  52. }
  53. }
  54. }