babylon.cubeTexture.ts 1.8 KB

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