123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- module BABYLON {
- export class CubeTexture extends BaseTexture {
- public url: string;
- public coordinatesMode = Texture.CUBIC_MODE;
- private _noMipmap: boolean;
- private _files: string[];
- private _extensions: string[];
- private _textureMatrix: Matrix;
- private _format: number;
- public static CreateFromImages(files: string[], scene: Scene, noMipmap?: boolean) {
- return new CubeTexture("", scene, null, noMipmap, files);
- }
- constructor(rootUrl: string, scene: Scene, extensions?: string[], noMipmap?: boolean, files?: string[], onLoad: () => void = null, onError: () => void = null, format: number = Engine.TEXTUREFORMAT_RGBA) {
- super(scene);
- this.name = rootUrl;
- this.url = rootUrl;
- this._noMipmap = noMipmap;
- this.hasAlpha = false;
- this._format = format;
- if (!rootUrl && !files) {
- return;
- }
- this._texture = this._getFromCache(rootUrl, noMipmap);
- if (!files) {
- if (!extensions) {
- extensions = ["_px.jpg", "_py.jpg", "_pz.jpg", "_nx.jpg", "_ny.jpg", "_nz.jpg"];
- }
- files = [];
- for (var index = 0; index < extensions.length; index++) {
- files.push(rootUrl + extensions[index]);
- }
- this._extensions = extensions;
- }
- this._files = files;
- if (!this._texture) {
- if (!scene.useDelayedTextureLoading) {
- this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError, this._format);
- } else {
- this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
- }
- } else if (onLoad) {
- if (this._texture.isReady) {
- Tools.SetImmediate(() => onLoad());
- } else {
- this._texture.onLoadedCallbacks.push(onLoad);
- }
- }
- this.isCube = true;
- this._textureMatrix = Matrix.Identity();
- }
- // Methods
- public delayLoad(): void {
- if (this.delayLoadState !== Engine.DELAYLOADSTATE_NOTLOADED) {
- return;
- }
- this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
- this._texture = this._getFromCache(this.url, this._noMipmap);
- if (!this._texture) {
- this._texture = this.getScene().getEngine().createCubeTexture(this.url, this.getScene(), this._files, this._noMipmap, this._format);
- }
- }
- public getReflectionTextureMatrix(): Matrix {
- return this._textureMatrix;
- }
- public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): CubeTexture {
- var texture = SerializationHelper.Parse(() => {
- return new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.extensions);
- }, parsedTexture, scene);
- // Animations
- if (parsedTexture.animations) {
- for (var animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {
- var parsedAnimation = parsedTexture.animations[animationIndex];
- texture.animations.push(Animation.Parse(parsedAnimation));
- }
- }
- return texture;
- }
- public clone(): CubeTexture {
- return SerializationHelper.Clone(() => {
- return new CubeTexture(this.url, this.getScene(), this._extensions, this._noMipmap, this._files);
- }, this);
- }
- }
- }
|