|
@@ -421,7 +421,9 @@ export abstract class AbstractViewer {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- const sceneExtends = this.scene.getWorldExtends();
|
|
|
|
|
|
+ const sceneExtends = this.scene.getWorldExtends((mesh) => {
|
|
|
|
+ return !this.environmentHelper || (mesh !== this.environmentHelper.ground && mesh !== this.environmentHelper.rootMesh && mesh !== this.environmentHelper.skybox);
|
|
|
|
+ });
|
|
const sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);
|
|
const sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);
|
|
const sceneDiagonalLenght = sceneDiagonal.length();
|
|
const sceneDiagonalLenght = sceneDiagonal.length();
|
|
if (isFinite(sceneDiagonalLenght))
|
|
if (isFinite(sceneDiagonalLenght))
|
|
@@ -744,13 +746,36 @@ export abstract class AbstractViewer {
|
|
return Promise.resolve(this.scene);
|
|
return Promise.resolve(this.scene);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private isLoading: boolean;
|
|
|
|
+ private nextLoading: Function;
|
|
|
|
+
|
|
public loadModel(model: any = this.configuration.model, clearScene: boolean = true): Promise<Scene> {
|
|
public loadModel(model: any = this.configuration.model, clearScene: boolean = true): Promise<Scene> {
|
|
// no model was provided? Do nothing!
|
|
// no model was provided? Do nothing!
|
|
- if (!model.url) {
|
|
|
|
|
|
+ let modelUrl = (typeof model === 'string') ? model : model.url;
|
|
|
|
+ if (!modelUrl) {
|
|
return Promise.resolve(this.scene);
|
|
return Promise.resolve(this.scene);
|
|
}
|
|
}
|
|
- this.configuration.model = model;
|
|
|
|
- let modelUrl = (typeof model === 'string') ? model : model.url;
|
|
|
|
|
|
+ if (this.isLoading) {
|
|
|
|
+ //another model is being model. Wait for it to finish, trigger the load afterwards
|
|
|
|
+ this.nextLoading = () => {
|
|
|
|
+ delete this.nextLoading;
|
|
|
|
+ this.loadModel(model, clearScene);
|
|
|
|
+ }
|
|
|
|
+ return Promise.resolve(this.scene);
|
|
|
|
+ }
|
|
|
|
+ this.isLoading = true;
|
|
|
|
+ if ((typeof model === 'string')) {
|
|
|
|
+ if (this.configuration.model && typeof this.configuration.model === 'object') {
|
|
|
|
+ this.configuration.model.url = model;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (this.configuration.model) {
|
|
|
|
+ deepmerge(this.configuration.model, model)
|
|
|
|
+ } else {
|
|
|
|
+ this.configuration.model = model;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
let parts = modelUrl.split('/');
|
|
let parts = modelUrl.split('/');
|
|
let filename = parts.pop();
|
|
let filename = parts.pop();
|
|
let base = parts.join('/') + '/';
|
|
let base = parts.join('/') + '/';
|
|
@@ -761,13 +786,18 @@ export abstract class AbstractViewer {
|
|
|
|
|
|
if (clearScene) {
|
|
if (clearScene) {
|
|
scene.meshes.forEach(mesh => {
|
|
scene.meshes.forEach(mesh => {
|
|
- mesh.dispose();
|
|
|
|
|
|
+ if (Tags.MatchesQuery(mesh, "viewerMesh")) {
|
|
|
|
+ mesh.dispose();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
return scene!;
|
|
return scene!;
|
|
}).then(() => {
|
|
}).then(() => {
|
|
return new Promise<Array<AbstractMesh>>((resolve, reject) => {
|
|
return new Promise<Array<AbstractMesh>>((resolve, reject) => {
|
|
this.lastUsedLoader = SceneLoader.ImportMesh(undefined, base, filename, this.scene, (meshes) => {
|
|
this.lastUsedLoader = SceneLoader.ImportMesh(undefined, base, filename, this.scene, (meshes) => {
|
|
|
|
+ meshes.forEach(mesh => {
|
|
|
|
+ Tags.AddTagsTo(mesh, "viewerMesh");
|
|
|
|
+ });
|
|
resolve(meshes);
|
|
resolve(meshes);
|
|
}, (progressEvent) => {
|
|
}, (progressEvent) => {
|
|
this.onModelLoadProgressObservable.notifyObserversWithPromise(progressEvent);
|
|
this.onModelLoadProgressObservable.notifyObserversWithPromise(progressEvent);
|
|
@@ -783,7 +813,7 @@ export abstract class AbstractViewer {
|
|
return this.onModelLoadedObservable.notifyObserversWithPromise(meshes)
|
|
return this.onModelLoadedObservable.notifyObserversWithPromise(meshes)
|
|
.then(() => {
|
|
.then(() => {
|
|
// update the models' configuration
|
|
// update the models' configuration
|
|
- this.configureModel(model, meshes);
|
|
|
|
|
|
+ this.configureModel(this.configuration.model || model, meshes);
|
|
this.configureLights(this.configuration.lights);
|
|
this.configureLights(this.configuration.lights);
|
|
|
|
|
|
if (this.configuration.camera) {
|
|
if (this.configuration.camera) {
|
|
@@ -791,12 +821,16 @@ export abstract class AbstractViewer {
|
|
}
|
|
}
|
|
return this.initEnvironment(meshes);
|
|
return this.initEnvironment(meshes);
|
|
}).then(() => {
|
|
}).then(() => {
|
|
|
|
+ this.isLoading = false;
|
|
|
|
+ if (this.nextLoading) {
|
|
|
|
+ return this.nextLoading();
|
|
|
|
+ }
|
|
return this.scene;
|
|
return this.scene;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- protected initEnvironment(focusMeshes: Array<AbstractMesh> = []): Promise<Scene> {
|
|
|
|
|
|
+ protected initEnvironment(focusMeshes: Array<AbstractMesh> = this.scene.meshes): Promise<Scene> {
|
|
this.configureEnvironment(this.configuration.skybox, this.configuration.ground);
|
|
this.configureEnvironment(this.configuration.skybox, this.configuration.ground);
|
|
|
|
|
|
return Promise.resolve(this.scene);
|
|
return Promise.resolve(this.scene);
|