|
@@ -19,8 +19,9 @@ export abstract class AbstractViewer {
|
|
|
public onSceneInitObservable: PromiseObservable<Scene>;
|
|
|
public onEngineInitObservable: PromiseObservable<Engine>;
|
|
|
public onModelLoadedObservable: PromiseObservable<AbstractMesh[]>;
|
|
|
+ public onInitDoneObservable: PromiseObservable<AbstractViewer>;
|
|
|
|
|
|
- private canvas: HTMLCanvasElement;
|
|
|
+ protected canvas: HTMLCanvasElement;
|
|
|
|
|
|
constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
|
|
|
// if exists, use the container id. otherwise, generate a random string.
|
|
@@ -33,6 +34,7 @@ export abstract class AbstractViewer {
|
|
|
this.onSceneInitObservable = new PromiseObservable();
|
|
|
this.onEngineInitObservable = new PromiseObservable();
|
|
|
this.onModelLoadedObservable = new PromiseObservable();
|
|
|
+ this.onInitDoneObservable = new PromiseObservable();
|
|
|
|
|
|
// add this viewer to the viewer manager
|
|
|
viewerManager.addViewer(this);
|
|
@@ -68,7 +70,7 @@ export abstract class AbstractViewer {
|
|
|
if (canvas) {
|
|
|
this.canvas = canvas;
|
|
|
}
|
|
|
- this.onTemplatesLoaded();
|
|
|
+ this._onTemplateLoaded();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -114,16 +116,33 @@ export abstract class AbstractViewer {
|
|
|
* @memberof AbstractViewer
|
|
|
*/
|
|
|
protected onTemplatesLoaded(): Promise<AbstractViewer> {
|
|
|
- let autoLoadModel = !!this.configuration.model;
|
|
|
- return this.initEngine().then(() => {
|
|
|
- if (autoLoadModel) {
|
|
|
- return this.loadModel();
|
|
|
- } else {
|
|
|
- return this.scene || this.initScene();
|
|
|
- }
|
|
|
- }).then(() => {
|
|
|
- return this;
|
|
|
- });
|
|
|
+ return Promise.resolve(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This will force the creation of an engine and a scene.
|
|
|
+ * It will also load a model if preconfigured.
|
|
|
+ * But first - it will load the extendible onTemplateLoaded()!
|
|
|
+ */
|
|
|
+ private _onTemplateLoaded(): Promise<AbstractViewer> {
|
|
|
+ return this.onTemplatesLoaded().then(() => {
|
|
|
+ let autoLoadModel = !!this.configuration.model;
|
|
|
+ return this.initEngine().then(() => {
|
|
|
+ return this.onEngineInitObservable.notifyWithPromise(this);
|
|
|
+ }).then(() => {
|
|
|
+ if (autoLoadModel) {
|
|
|
+ return this.loadModel();
|
|
|
+ } else {
|
|
|
+ return this.scene || this.initScene();
|
|
|
+ }
|
|
|
+ }).then(() => {
|
|
|
+ return this.onSceneInitObservable.notifyWithPromise(this);
|
|
|
+ }).then(() => {
|
|
|
+ return this.onInitDoneObservable.notifyWithPromise(this);
|
|
|
+ }).then(() => {
|
|
|
+ return this;
|
|
|
+ });
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -157,9 +176,7 @@ export abstract class AbstractViewer {
|
|
|
this.engine.setHardwareScalingLevel(scale);
|
|
|
}
|
|
|
|
|
|
- return this.onEngineInitObservable.notifyWithPromise(this.engine).then(() => {
|
|
|
- return this.engine;
|
|
|
- });
|
|
|
+ return Promise.resolve(this.engine);
|
|
|
}
|
|
|
|
|
|
protected initScene(): Promise<Scene> {
|
|
@@ -176,9 +193,7 @@ export abstract class AbstractViewer {
|
|
|
if (this.configuration.scene && this.configuration.scene.debug) {
|
|
|
this.scene.debugLayer.show();
|
|
|
}
|
|
|
- return this.onSceneInitObservable.notifyWithPromise(this.scene).then(() => {
|
|
|
- return this.scene!;
|
|
|
- });
|
|
|
+ return Promise.resolve(this.scene);
|
|
|
}
|
|
|
|
|
|
public loadModel(model: any = this.configuration.model, clearScene: boolean = true): Promise<Scene> {
|