Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pendingData APIs publicly #12760

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/dev/core/src/Audio/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,11 +1163,11 @@ export class Sound {
soundUrl,
scene,
() => {
scene._removePendingData(newSound);
scene.removePendingData(newSound);
},
options
);
scene._addPendingData(newSound);
scene.addPendingData(newSound);
} else {
const setBufferAndRun = () => {
if (sourceSound._isReadyToPlay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ ThinEngine.prototype._partialLoadImg = function (
(<any>loadedImages)._internalCount++;

if (scene) {
scene._removePendingData(tokenPendingData);
scene.removePendingData(tokenPendingData);
}

if ((<any>loadedImages)._internalCount === 6 && onfinish) {
Expand All @@ -292,7 +292,7 @@ ThinEngine.prototype._partialLoadImg = function (

const onerror = (message?: string, exception?: any) => {
if (scene) {
scene._removePendingData(tokenPendingData);
scene.removePendingData(tokenPendingData);
}

if (onErrorCallBack) {
Expand All @@ -302,7 +302,7 @@ ThinEngine.prototype._partialLoadImg = function (

LoadImage(url, onload, onerror, scene ? scene.offlineProvider : null, mimeType);
if (scene) {
scene._addPendingData(tokenPendingData);
scene.addPendingData(tokenPendingData);
}
};

Expand Down
6 changes: 3 additions & 3 deletions packages/dev/core/src/Engines/Extensions/engine.rawTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,12 @@ ThinEngine.prototype.createRawCubeTextureFromUrl = function (
): InternalTexture {
const gl = this._gl;
const texture = this.createRawCubeTexture(null, size, format, type, !noMipmap, invertY, samplingMode, null);
scene?._addPendingData(texture);
scene?.addPendingData(texture);
texture.url = url;
this._internalTexturesCache.push(texture);

const onerror = (request?: IWebRequest, exception?: any) => {
scene?._removePendingData(texture);
scene?.removePendingData(texture);
if (onError && request) {
onError(request.status + " " + request.statusText, exception);
}
Expand Down Expand Up @@ -601,7 +601,7 @@ ThinEngine.prototype.createRawCubeTextureFromUrl = function (

texture.isReady = true;
// this.resetTextureCache();
scene?._removePendingData(texture);
scene?.removePendingData(texture);

texture.onLoadedObservable.notifyObservers(texture);
texture.onLoadedObservable.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ WebGPUEngine.prototype.createRawCubeTextureFromUrl = function (
invertY: boolean = false
): InternalTexture {
const texture = this.createRawCubeTexture(null, size, format, type, !noMipmap, invertY, samplingMode, null);
scene?._addPendingData(texture);
scene?.addPendingData(texture);
texture.url = url;

this._internalTexturesCache.push(texture);

const onerror = (request?: IWebRequest, exception?: any) => {
scene?._removePendingData(texture);
scene?.removePendingData(texture);
if (onError && request) {
onError(request.status + " " + request.statusText, exception);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ WebGPUEngine.prototype.createRawCubeTextureFromUrl = function (
}

texture.isReady = true;
scene?._removePendingData(texture);
scene?.removePendingData(texture);

if (onLoad) {
onLoad();
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,7 @@ export class NativeEngine extends Engine {
}

if (scene) {
scene._addPendingData(texture);
scene.addPendingData(texture);
}
texture.url = url;
texture.generateMipMaps = !noMipmap;
Expand All @@ -2295,7 +2295,7 @@ export class NativeEngine extends Engine {

const onInternalError = (message?: string, exception?: any) => {
if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

if (url === originalUrl) {
Expand Down Expand Up @@ -2324,7 +2324,7 @@ export class NativeEngine extends Engine {
const onload = (data: ArrayBufferView) => {
if (!texture._hardwareTexture) {
if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

return;
Expand All @@ -2349,7 +2349,7 @@ export class NativeEngine extends Engine {
this._setTextureSampling(underlyingResource, filter);

if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

texture.onLoadedObservable.notifyObservers(texture);
Expand Down
12 changes: 6 additions & 6 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ declare type WebGLRenderTargetWrapper = import("./WebGL/webGLRenderTargetWrapper
* @hidden
*/
export interface ISceneLike {
_addPendingData(data: any): void;
_removePendingData(data: any): void;
addPendingData(data: any): void;
removePendingData(data: any): void;
offlineProvider: IOfflineProvider;
}

Expand Down Expand Up @@ -3910,7 +3910,7 @@ export class ThinEngine {
}

if (scene) {
scene._addPendingData(texture);
scene.addPendingData(texture);
}
texture.url = url;
texture.generateMipMaps = !noMipmap;
Expand All @@ -3934,7 +3934,7 @@ export class ThinEngine {

const onInternalError = (message?: string, exception?: any) => {
if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

if (url === originalUrl) {
Expand Down Expand Up @@ -4702,7 +4702,7 @@ export class ThinEngine {

// this.resetTextureCache();
if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

texture.onLoadedObservable.notifyObservers(texture);
Expand Down Expand Up @@ -4739,7 +4739,7 @@ export class ThinEngine {
if (!texture._hardwareTexture) {
// this.resetTextureCache();
if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

return;
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ export class WebGPUEngine extends Engine {
}

if (scene) {
scene._removePendingData(texture);
scene.removePendingData(texture);
}

texture.isReady = true;
Expand Down
18 changes: 9 additions & 9 deletions packages/dev/core/src/Loading/sceneLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,10 @@ export class SceneLoader {
}

const loadingToken = {};
scene._addPendingData(loadingToken);
scene.addPendingData(loadingToken);

const disposeHandler = () => {
scene._removePendingData(loadingToken);
scene.removePendingData(loadingToken);
};

const errorHandler = (message?: string, exception?: any) => {
Expand Down Expand Up @@ -759,7 +759,7 @@ export class SceneLoader {
}
}

scene._removePendingData(loadingToken);
scene.removePendingData(loadingToken);
};

return SceneLoader._LoadData(
Expand Down Expand Up @@ -955,10 +955,10 @@ export class SceneLoader {
}

const loadingToken = {};
scene._addPendingData(loadingToken);
scene.addPendingData(loadingToken);

const disposeHandler = () => {
scene._removePendingData(loadingToken);
scene.removePendingData(loadingToken);
};

const errorHandler = (message?: string, exception?: any) => {
Expand Down Expand Up @@ -993,7 +993,7 @@ export class SceneLoader {
}
}

scene._removePendingData(loadingToken);
scene.removePendingData(loadingToken);
};

return SceneLoader._LoadData(
Expand Down Expand Up @@ -1092,10 +1092,10 @@ export class SceneLoader {
}

const loadingToken = {};
scene._addPendingData(loadingToken);
scene.addPendingData(loadingToken);

const disposeHandler = () => {
scene._removePendingData(loadingToken);
scene.removePendingData(loadingToken);
};

const errorHandler = (message?: string, exception?: any) => {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ export class SceneLoader {
}
}

scene._removePendingData(loadingToken);
scene.removePendingData(loadingToken);
};

return SceneLoader._LoadData(
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Materials/Textures/baseTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ export class BaseTexture extends ThinTexture implements IAnimatable {
}

// Remove from scene
this._scene._removePendingData(this);
this._scene.removePendingData(this);
const index = this._scene.textures.indexOf(this);

if (index >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Meshes/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ export class Geometry implements IGetSetVerticesData {
return;
}

scene._addPendingData(this);
scene.addPendingData(this);
scene._loadFile(
this.delayLoadingFile,
(data) => {
Expand All @@ -805,7 +805,7 @@ export class Geometry implements IGetSetVerticesData {
this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;
this._delayInfo = [];

scene._removePendingData(this);
scene.removePendingData(this);

const meshes = this._meshes;
const numOfMeshes = meshes.length;
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Meshes/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
}

private _queueLoad(scene: Scene): Mesh {
scene._addPendingData(this);
scene.addPendingData(this);

const getBinaryData = this.delayLoadingFile.indexOf(".babylonbinarymeshdata") !== -1;

Expand All @@ -2565,7 +2565,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
});

this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;
scene._removePendingData(this);
scene.removePendingData(this);
},
() => {},
scene.offlineProvider,
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/core/src/Particles/particleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ export class ParticleHelper {

const token = {};

scene!._addPendingData(token);
scene!.addPendingData(token);

return new Promise((resolve, reject) => {
if (gpu && !GPUParticleSystem.IsSupported) {
scene!._removePendingData(token);
scene!.removePendingData(token);
return reject("Particle system with GPU is not supported.");
}

Tools.LoadFile(
`${ParticleHelper.BaseAssetsUrl}/systems/${type}.json`,
(data) => {
scene!._removePendingData(token);
scene!.removePendingData(token);
const newData = JSON.parse(data.toString());
return resolve(ParticleSystemSet.Parse(newData, scene!, gpu, capacity));
},
undefined,
undefined,
undefined,
() => {
scene!._removePendingData(token);
scene!.removePendingData(token);
return reject(`An error occurred with the creation of your particle system. Check if your type '${type}' exists.`);
}
);
Expand Down
14 changes: 8 additions & 6 deletions packages/dev/core/src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,8 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
continue;
}

// Do not stop at the first encountered "unready" object as we want to ensure
// all materials are starting off their compilation in parallel.
if (!mesh.isReady(true)) {
isReady = false;
continue;
Expand Down Expand Up @@ -2029,18 +2031,18 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
}

/**
* @param data
* @hidden
* This function can help adding any object to the list of data awaited to be ready in order to check for a complete scene loading.
* @param data defines the object to wait for
*/
public _addPendingData(data: any): void {
public addPendingData(data: any): void {
this._pendingData.push(data);
}

/**
* @param data
* @hidden
* Remove a pending data from the loading list which has previously been added with addPendingData.
* @param data defines the object to remove from the pending list
*/
public _removePendingData(data: any): void {
public removePendingData(data: any): void {
const wasLoading = this.isLoading;
const index = this._pendingData.indexOf(data);

Expand Down
6 changes: 3 additions & 3 deletions packages/tools/tests/test/visualization/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@
},
{
"title": "MeshSimplification",
"playgroundId": "#1ED15P#35",
"playgroundId": "#1ED15P#40",
"referenceImage": "meshSimplification.png"
},
{
Expand All @@ -989,12 +989,12 @@
},
{
"title": "Edges",
"playgroundId": "#TYAHX#114",
"playgroundId": "#TYAHX#244",
"referenceImage": "edges.png"
},
{
"title": "Outline",
"playgroundId": "#10WJ5S#6",
"playgroundId": "#10WJ5S#14",
"referenceImage": "outline.png"
},
{
Expand Down