|
@@ -1,4 +1,4 @@
|
|
|
-module BABYLON {
|
|
|
+module BABYLON {
|
|
|
|
|
|
export enum AssetTaskState {
|
|
|
INIT,
|
|
@@ -80,6 +80,24 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ export interface IAssetsProgressEvent {
|
|
|
+ remainingCount: number;
|
|
|
+ totalCount: number;
|
|
|
+ task: IAssetTask;
|
|
|
+ }
|
|
|
+
|
|
|
+ export class AssetsProgressEvent implements IAssetsProgressEvent {
|
|
|
+ remainingCount: number;
|
|
|
+ totalCount: number;
|
|
|
+ task: IAssetTask;
|
|
|
+
|
|
|
+ constructor(remainingCount: number, totalCount: number, task: IAssetTask) {
|
|
|
+ this.remainingCount = remainingCount;
|
|
|
+ this.totalCount = totalCount;
|
|
|
+ this.task = task;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
export class MeshAssetTask extends AbstractAssetTask implements IAssetTask {
|
|
|
public loadedMeshes: Array<AbstractMesh>;
|
|
|
public loadedParticleSystems: Array<ParticleSystem>;
|
|
@@ -245,12 +263,14 @@
|
|
|
public onFinish: (tasks: IAssetTask[]) => void;
|
|
|
public onTaskSuccess: (task: IAssetTask) => void;
|
|
|
public onTaskError: (task: IAssetTask) => void;
|
|
|
+ public onProgress: (remainingCount: number, totalCount: number, task: IAssetTask) => void;
|
|
|
|
|
|
//Observables
|
|
|
|
|
|
public onTaskSuccessObservable = new Observable<IAssetTask>();
|
|
|
public onTaskErrorObservable = new Observable<IAssetTask>();
|
|
|
public onTasksDoneObservable = new Observable<IAssetTask[]>();
|
|
|
+ public onProgressObservable = new Observable<IAssetsProgressEvent>();
|
|
|
|
|
|
public useDefaultLoadingScreen = true;
|
|
|
|
|
@@ -308,9 +328,30 @@
|
|
|
return task;
|
|
|
}
|
|
|
|
|
|
- private _decreaseWaitingTasksCount(): void {
|
|
|
+ private _decreaseWaitingTasksCount(task: AbstractAssetTask): void {
|
|
|
this.waitingTasksCount--;
|
|
|
|
|
|
+ try {
|
|
|
+ if (this.onProgress) {
|
|
|
+ this.onProgress(
|
|
|
+ this.waitingTasksCount,
|
|
|
+ this.tasks.length,
|
|
|
+ task
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ this.onProgressObservable.notifyObservers(
|
|
|
+ new AssetsProgressEvent(
|
|
|
+ this.waitingTasksCount,
|
|
|
+ this.tasks.length,
|
|
|
+ task
|
|
|
+ )
|
|
|
+ );
|
|
|
+ } catch (e) {
|
|
|
+ Tools.Error("Error running progress callbacks.");
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+
|
|
|
if (this.waitingTasksCount === 0) {
|
|
|
try {
|
|
|
if (this.onFinish) {
|
|
@@ -335,7 +376,7 @@
|
|
|
this.onTaskSuccess(task);
|
|
|
}
|
|
|
this.onTaskSuccessObservable.notifyObservers(task);
|
|
|
- this._decreaseWaitingTasksCount();
|
|
|
+ this._decreaseWaitingTasksCount(task);
|
|
|
} catch (e) {
|
|
|
error("Error executing task success callbacks", e);
|
|
|
}
|
|
@@ -351,7 +392,7 @@
|
|
|
this.onTaskError(task);
|
|
|
}
|
|
|
this.onTaskErrorObservable.notifyObservers(task);
|
|
|
- this._decreaseWaitingTasksCount();
|
|
|
+ this._decreaseWaitingTasksCount(task);
|
|
|
}
|
|
|
|
|
|
task.run(this._scene, done, error);
|
|
@@ -385,4 +426,4 @@
|
|
|
return this;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|