|
@@ -7,6 +7,7 @@ import { BaseTexture } from "../../Materials/Textures/baseTexture";
|
|
import { Texture } from "../../Materials/Textures/texture";
|
|
import { Texture } from "../../Materials/Textures/texture";
|
|
import { Constants } from "../../Engines/constants";
|
|
import { Constants } from "../../Engines/constants";
|
|
import { _TypeStore } from '../../Misc/typeStore';
|
|
import { _TypeStore } from '../../Misc/typeStore';
|
|
|
|
+import { ThinEngine } from '../../Engines/thinEngine';
|
|
|
|
|
|
import "../../Engines/Extensions/engine.cubeTexture";
|
|
import "../../Engines/Extensions/engine.cubeTexture";
|
|
import { StringTools } from '../../Misc/stringTools';
|
|
import { StringTools } from '../../Misc/stringTools';
|
|
@@ -102,6 +103,7 @@ export class CubeTexture extends BaseTexture {
|
|
|
|
|
|
private _format: number;
|
|
private _format: number;
|
|
private _createPolynomials: boolean;
|
|
private _createPolynomials: boolean;
|
|
|
|
+ private _engine: ThinEngine;
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _prefiltered: boolean = false;
|
|
public _prefiltered: boolean = false;
|
|
@@ -158,11 +160,19 @@ export class CubeTexture extends BaseTexture {
|
|
* @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
|
|
* @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
|
|
* @return the cube texture
|
|
* @return the cube texture
|
|
*/
|
|
*/
|
|
- constructor(rootUrl: string, scene: Scene, extensions: Nullable<string[]> = null, noMipmap: boolean = false, files: Nullable<string[]> = null,
|
|
|
|
|
|
+ constructor(rootUrl: string, sceneOrEngine: Scene | ThinEngine, extensions: Nullable<string[]> = null, noMipmap: boolean = false, files: Nullable<string[]> = null,
|
|
onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null, format: number = Constants.TEXTUREFORMAT_RGBA, prefiltered = false,
|
|
onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null, format: number = Constants.TEXTUREFORMAT_RGBA, prefiltered = false,
|
|
forcedExtension: any = null, createPolynomials: boolean = false,
|
|
forcedExtension: any = null, createPolynomials: boolean = false,
|
|
lodScale: number = 0.8, lodOffset: number = 0) {
|
|
lodScale: number = 0.8, lodOffset: number = 0) {
|
|
- super(scene);
|
|
|
|
|
|
+ super(null);
|
|
|
|
+ if (CubeTexture._isScene(sceneOrEngine)) {
|
|
|
|
+ this._setScene(sceneOrEngine);
|
|
|
|
+ this._engine = sceneOrEngine.getEngine();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this._setScene(null);
|
|
|
|
+ this._engine = sceneOrEngine;
|
|
|
|
+ }
|
|
|
|
|
|
this.name = rootUrl;
|
|
this.name = rootUrl;
|
|
this.url = rootUrl;
|
|
this.url = rootUrl;
|
|
@@ -227,12 +237,13 @@ export class CubeTexture extends BaseTexture {
|
|
};
|
|
};
|
|
|
|
|
|
if (!this._texture) {
|
|
if (!this._texture) {
|
|
- if (!scene.useDelayedTextureLoading) {
|
|
|
|
|
|
+ const scene = this.getScene();
|
|
|
|
+ if (!scene?.useDelayedTextureLoading) {
|
|
if (prefiltered) {
|
|
if (prefiltered) {
|
|
- this._texture = scene.getEngine().createPrefilteredCubeTexture(rootUrl, scene, lodScale, lodOffset, onLoad, onError, format, forcedExtension, this._createPolynomials);
|
|
|
|
|
|
+ this._texture = this._engine.createPrefilteredCubeTexture(rootUrl, scene, lodScale, lodOffset, onLoad, onError, format, forcedExtension, this._createPolynomials);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError, this._format, forcedExtension, false, lodScale, lodOffset);
|
|
|
|
|
|
+ this._texture = this._engine.createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError, this._format, forcedExtension, false, lodScale, lodOffset);
|
|
}
|
|
}
|
|
this._texture?.onLoadedObservable.add(() => this.onLoadObservable.notifyObservers(this));
|
|
this._texture?.onLoadedObservable.add(() => this.onLoadObservable.notifyObservers(this));
|
|
|
|
|
|
@@ -273,7 +284,7 @@ export class CubeTexture extends BaseTexture {
|
|
public updateURL(url: string, forcedExtension?: string, onLoad?: () => void, prefiltered: boolean = false): void {
|
|
public updateURL(url: string, forcedExtension?: string, onLoad?: () => void, prefiltered: boolean = false): void {
|
|
if (this.url) {
|
|
if (this.url) {
|
|
this.releaseInternalTexture();
|
|
this.releaseInternalTexture();
|
|
- this.getScene()!.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
|
|
|
|
|
|
+ this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
|
|
}
|
|
}
|
|
|
|
|
|
if (!this.name || StringTools.StartsWith(this.name, "data:")) {
|
|
if (!this.name || StringTools.StartsWith(this.name, "data:")) {
|
|
@@ -304,20 +315,16 @@ export class CubeTexture extends BaseTexture {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- let scene = this.getScene();
|
|
|
|
-
|
|
|
|
- if (!scene) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;
|
|
this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;
|
|
this._texture = this._getFromCache(this.url, this._noMipmap);
|
|
this._texture = this._getFromCache(this.url, this._noMipmap);
|
|
|
|
|
|
if (!this._texture) {
|
|
if (!this._texture) {
|
|
|
|
+ const scene = this.getScene();
|
|
if (this._prefiltered) {
|
|
if (this._prefiltered) {
|
|
- this._texture = scene.getEngine().createPrefilteredCubeTexture(this.url, scene, 0.8, 0, this._delayedOnLoad, undefined, this._format, undefined, this._createPolynomials);
|
|
|
|
|
|
+ this._texture = this._engine.createPrefilteredCubeTexture(this.url, scene, 0.8, 0, this._delayedOnLoad, undefined, this._format, undefined, this._createPolynomials);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- this._texture = scene.getEngine().createCubeTexture(this.url, scene, this._files, this._noMipmap, this._delayedOnLoad, null, this._format, forcedExtension);
|
|
|
|
|
|
+ this._texture = this._engine.createCubeTexture(this.url, scene, this._files, this._noMipmap, this._delayedOnLoad, null, this._format, forcedExtension);
|
|
}
|
|
}
|
|
|
|
|
|
this._texture?.onLoadedObservable.add(() => this.onLoadObservable.notifyObservers(this));
|
|
this._texture?.onLoadedObservable.add(() => this.onLoadObservable.notifyObservers(this));
|
|
@@ -342,7 +349,7 @@ export class CubeTexture extends BaseTexture {
|
|
}
|
|
}
|
|
|
|
|
|
if (value.isIdentity() !== this._textureMatrix.isIdentity()) {
|
|
if (value.isIdentity() !== this._textureMatrix.isIdentity()) {
|
|
- this.getScene()!.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);
|
|
|
|
|
|
+ this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);
|
|
}
|
|
}
|
|
|
|
|
|
this._textureMatrix = value;
|
|
this._textureMatrix = value;
|
|
@@ -391,15 +398,10 @@ export class CubeTexture extends BaseTexture {
|
|
* @returns a new cube texture
|
|
* @returns a new cube texture
|
|
*/
|
|
*/
|
|
public clone(): CubeTexture {
|
|
public clone(): CubeTexture {
|
|
- let scene = this.getScene();
|
|
|
|
let uniqueId = 0;
|
|
let uniqueId = 0;
|
|
|
|
|
|
let newCubeTexture = SerializationHelper.Clone(() => {
|
|
let newCubeTexture = SerializationHelper.Clone(() => {
|
|
-
|
|
|
|
- if (!scene) {
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
- const cubeTexture = new CubeTexture(this.url, scene, this._extensions, this._noMipmap, this._files);
|
|
|
|
|
|
+ const cubeTexture = new CubeTexture(this.url, this.getScene() || this._engine, this._extensions, this._noMipmap, this._files);
|
|
uniqueId = cubeTexture.uniqueId;
|
|
uniqueId = cubeTexture.uniqueId;
|
|
|
|
|
|
return cubeTexture;
|
|
return cubeTexture;
|
|
@@ -409,6 +411,10 @@ export class CubeTexture extends BaseTexture {
|
|
|
|
|
|
return newCubeTexture;
|
|
return newCubeTexture;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static _isScene(sceneOrEngine: Scene | ThinEngine): sceneOrEngine is Scene {
|
|
|
|
+ return sceneOrEngine.getClassName() === "Scene";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
Texture._CubeTextureParser = CubeTexture.Parse;
|
|
Texture._CubeTextureParser = CubeTexture.Parse;
|