|
@@ -86,15 +86,6 @@ export class SceneManager {
|
|
this._handleHardwareLimitations();
|
|
this._handleHardwareLimitations();
|
|
});
|
|
});
|
|
|
|
|
|
- this._viewer.onModelLoadedObservable.add((model) => {
|
|
|
|
- this._configureLights(this._viewer.configuration.lights, model);
|
|
|
|
-
|
|
|
|
- if (this._viewer.configuration.camera || !this.scene.activeCamera) {
|
|
|
|
- this._configureCamera(this._viewer.configuration.camera || {}, model);
|
|
|
|
- }
|
|
|
|
- return this._initEnvironment(model);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
this.labs = new ViewerLabs(this);
|
|
this.labs = new ViewerLabs(this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -184,7 +175,7 @@ export class SceneManager {
|
|
* @param newConfiguration the delta that should be configured. This includes only the changes
|
|
* @param newConfiguration the delta that should be configured. This includes only the changes
|
|
* @param globalConfiguration The global configuration object, after the new configuration was merged into it
|
|
* @param globalConfiguration The global configuration object, after the new configuration was merged into it
|
|
*/
|
|
*/
|
|
- public updateConfiguration(newConfiguration: Partial<ViewerConfiguration>, globalConfiguration: ViewerConfiguration) {
|
|
|
|
|
|
+ public updateConfiguration(newConfiguration: Partial<ViewerConfiguration>, globalConfiguration: ViewerConfiguration, model?: ViewerModel) {
|
|
|
|
|
|
if (newConfiguration.lab) {
|
|
if (newConfiguration.lab) {
|
|
if (newConfiguration.lab.environmentAssetsRootURL) {
|
|
if (newConfiguration.lab.environmentAssetsRootURL) {
|
|
@@ -228,28 +219,26 @@ export class SceneManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// optimizer
|
|
// optimizer
|
|
if (newConfiguration.optimizer) {
|
|
if (newConfiguration.optimizer) {
|
|
this._configureOptimizer(newConfiguration.optimizer);
|
|
this._configureOptimizer(newConfiguration.optimizer);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // configure model
|
|
|
|
+ if (newConfiguration.model && typeof newConfiguration.model === 'object') {
|
|
|
|
+ this._configureModel(newConfiguration.model);
|
|
|
|
+ }
|
|
|
|
+
|
|
// lights
|
|
// lights
|
|
- this._configureLights(newConfiguration.lights);
|
|
|
|
|
|
+ this._configureLights(newConfiguration.lights, model);
|
|
|
|
|
|
// environment
|
|
// environment
|
|
if (newConfiguration.skybox !== undefined || newConfiguration.ground !== undefined) {
|
|
if (newConfiguration.skybox !== undefined || newConfiguration.ground !== undefined) {
|
|
- this._configureEnvironment(newConfiguration.skybox, newConfiguration.ground);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // configure model
|
|
|
|
- if (newConfiguration.model && typeof newConfiguration.model === 'object') {
|
|
|
|
- this._configureModel(newConfiguration.model);
|
|
|
|
|
|
+ this._configureEnvironment(newConfiguration.skybox, newConfiguration.ground, model);
|
|
}
|
|
}
|
|
|
|
|
|
// camera
|
|
// camera
|
|
- this._configureCamera(newConfiguration.camera);
|
|
|
|
|
|
+ this._configureCamera(newConfiguration.camera, model);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -380,6 +369,7 @@ export class SceneManager {
|
|
if (!this.scene.activeCamera) {
|
|
if (!this.scene.activeCamera) {
|
|
this.scene.createDefaultCamera(true, true, true);
|
|
this.scene.createDefaultCamera(true, true, true);
|
|
this.camera = <ArcRotateCamera>this.scene.activeCamera!;
|
|
this.camera = <ArcRotateCamera>this.scene.activeCamera!;
|
|
|
|
+ this.camera.setTarget(Vector3.Zero());
|
|
}
|
|
}
|
|
if (cameraConfig.position) {
|
|
if (cameraConfig.position) {
|
|
let newPosition = this.camera.position.clone();
|
|
let newPosition = this.camera.position.clone();
|
|
@@ -389,8 +379,14 @@ export class SceneManager {
|
|
|
|
|
|
if (cameraConfig.target) {
|
|
if (cameraConfig.target) {
|
|
let newTarget = this.camera.target.clone();
|
|
let newTarget = this.camera.target.clone();
|
|
- extendClassWithConfig(newTarget, cameraConfig.position);
|
|
|
|
|
|
+ extendClassWithConfig(newTarget, cameraConfig.target);
|
|
this.camera.setTarget(newTarget);
|
|
this.camera.setTarget(newTarget);
|
|
|
|
+ } else if (model) {
|
|
|
|
+ const boundingInfo = model.rootMesh.getHierarchyBoundingVectors(true);
|
|
|
|
+ const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
|
|
|
|
+ const halfSizeVec = sizeVec.scale(0.5);
|
|
|
|
+ const center = boundingInfo.min.add(halfSizeVec);
|
|
|
|
+ this.camera.setTarget(center);
|
|
}
|
|
}
|
|
|
|
|
|
if (cameraConfig.rotation) {
|
|
if (cameraConfig.rotation) {
|
|
@@ -414,7 +410,7 @@ export class SceneManager {
|
|
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))
|
|
- this.camera.upperRadiusLimit = sceneDiagonalLenght * 3;
|
|
|
|
|
|
+ this.camera.upperRadiusLimit = sceneDiagonalLenght * 4;
|
|
|
|
|
|
this.onCameraConfiguredObservable.notifyObservers({
|
|
this.onCameraConfiguredObservable.notifyObservers({
|
|
sceneManager: this,
|
|
sceneManager: this,
|
|
@@ -433,12 +429,21 @@ export class SceneManager {
|
|
return Promise.resolve(this.scene);
|
|
return Promise.resolve(this.scene);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
const options: Partial<IEnvironmentHelperOptions> = {
|
|
const options: Partial<IEnvironmentHelperOptions> = {
|
|
createGround: !!groundConfiguration,
|
|
createGround: !!groundConfiguration,
|
|
createSkybox: !!skyboxConifguration,
|
|
createSkybox: !!skyboxConifguration,
|
|
- setupImageProcessing: false // will be done at the scene level!
|
|
|
|
|
|
+ setupImageProcessing: false, // will be done at the scene level!,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ if (model) {
|
|
|
|
+ const boundingInfo = model.rootMesh.getHierarchyBoundingVectors(true);
|
|
|
|
+ const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
|
|
|
|
+ const halfSizeVec = sizeVec.scale(0.5);
|
|
|
|
+ const center = boundingInfo.min.add(halfSizeVec);
|
|
|
|
+ options.groundYBias = -center.y;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (groundConfiguration) {
|
|
if (groundConfiguration) {
|
|
let groundConfig = (typeof groundConfiguration === 'boolean') ? {} : groundConfiguration;
|
|
let groundConfig = (typeof groundConfiguration === 'boolean') ? {} : groundConfiguration;
|
|
|
|
|
|
@@ -574,7 +579,7 @@ export class SceneManager {
|
|
if (Object.keys(lightsToConfigure).length !== lightsAvailable.length) {
|
|
if (Object.keys(lightsToConfigure).length !== lightsAvailable.length) {
|
|
lightsAvailable.forEach(lName => {
|
|
lightsAvailable.forEach(lName => {
|
|
if (lightsToConfigure.indexOf(lName) === -1) {
|
|
if (lightsToConfigure.indexOf(lName) === -1) {
|
|
- this.scene.getLightByName(lName)!.dispose()
|
|
|
|
|
|
+ this.scene.getLightByName(lName)!.dispose();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|