|
@@ -3,6 +3,7 @@ import { TemplateManager } from './../templateManager';
|
|
import configurationLoader from './../configuration/loader';
|
|
import configurationLoader from './../configuration/loader';
|
|
import { Observable, Engine, Scene, ArcRotateCamera, Vector3, SceneLoader, AbstractMesh, Mesh, HemisphericLight } from 'babylonjs';
|
|
import { Observable, Engine, Scene, ArcRotateCamera, Vector3, SceneLoader, AbstractMesh, Mesh, HemisphericLight } from 'babylonjs';
|
|
import { ViewerConfiguration } from '../configuration/configuration';
|
|
import { ViewerConfiguration } from '../configuration/configuration';
|
|
|
|
+import { PromiseObservable } from '../util/promiseObservable';
|
|
|
|
|
|
export abstract class AbstractViewer {
|
|
export abstract class AbstractViewer {
|
|
|
|
|
|
@@ -14,6 +15,11 @@ export abstract class AbstractViewer {
|
|
|
|
|
|
protected configuration: ViewerConfiguration;
|
|
protected configuration: ViewerConfiguration;
|
|
|
|
|
|
|
|
+ // observables
|
|
|
|
+ public onSceneInitObservable: PromiseObservable<Scene>;
|
|
|
|
+ public onEngineInitObservable: PromiseObservable<Engine>;
|
|
|
|
+ public onModelLoadedObservable: PromiseObservable<AbstractMesh[]>;
|
|
|
|
+
|
|
constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
|
|
constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
|
|
// if exists, use the container id. otherwise, generate a random string.
|
|
// if exists, use the container id. otherwise, generate a random string.
|
|
if (containerElement.id) {
|
|
if (containerElement.id) {
|
|
@@ -22,6 +28,10 @@ export abstract class AbstractViewer {
|
|
this.baseId = containerElement.id = 'bjs' + Math.random().toString(32).substr(2, 8);
|
|
this.baseId = containerElement.id = 'bjs' + Math.random().toString(32).substr(2, 8);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ this.onSceneInitObservable = new PromiseObservable();
|
|
|
|
+ this.onEngineInitObservable = new PromiseObservable();
|
|
|
|
+ this.onModelLoadedObservable = new PromiseObservable();
|
|
|
|
+
|
|
// add this viewer to the viewer manager
|
|
// add this viewer to the viewer manager
|
|
viewerManager.addViewer(this);
|
|
viewerManager.addViewer(this);
|
|
|
|
|
|
@@ -93,7 +103,9 @@ export abstract class AbstractViewer {
|
|
var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
|
|
var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
|
|
this.engine.setHardwareScalingLevel(scale);
|
|
this.engine.setHardwareScalingLevel(scale);
|
|
|
|
|
|
- return Promise.resolve(this.engine);
|
|
|
|
|
|
+ return this.onEngineInitObservable.notifyWithPromise(this.engine).then(() => {
|
|
|
|
+ return this.engine;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
protected initScene(): Promise<Scene> {
|
|
protected initScene(): Promise<Scene> {
|
|
@@ -110,7 +122,9 @@ export abstract class AbstractViewer {
|
|
if (this.configuration.scene && this.configuration.scene.debug) {
|
|
if (this.configuration.scene && this.configuration.scene.debug) {
|
|
this.scene.debugLayer.show();
|
|
this.scene.debugLayer.show();
|
|
}
|
|
}
|
|
- return Promise.resolve(this.scene);
|
|
|
|
|
|
+ return this.onSceneInitObservable.notifyWithPromise(this.scene).then(() => {
|
|
|
|
+ return this.scene;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
public loadModel(model: any = this.configuration.model, clearScene: boolean = true): Promise<Scene> {
|
|
public loadModel(model: any = this.configuration.model, clearScene: boolean = true): Promise<Scene> {
|
|
@@ -133,15 +147,12 @@ export abstract class AbstractViewer {
|
|
}, plugin);
|
|
}, plugin);
|
|
});
|
|
});
|
|
}).then((meshes: Array<AbstractMesh>) => {
|
|
}).then((meshes: Array<AbstractMesh>) => {
|
|
- return this.onModelLoaded(meshes);
|
|
|
|
|
|
+ return this.onModelLoadedObservable.notifyWithPromise(meshes).then(() => {
|
|
|
|
+ return this.scene;
|
|
|
|
+ });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- protected onModelLoaded(meshes: Array<AbstractMesh>): Promise<Scene> {
|
|
|
|
- console.log("model loaded");
|
|
|
|
- return Promise.resolve(this.scene);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public abstract initEnvironment(): Promise<Scene>;
|
|
public abstract initEnvironment(): Promise<Scene>;
|
|
|
|
|
|
}
|
|
}
|