|
@@ -3,7 +3,7 @@
|
|
import { ViewerConfiguration } from './../configuration/configuration';
|
|
import { ViewerConfiguration } from './../configuration/configuration';
|
|
import { Template } from './../templateManager';
|
|
import { Template } from './../templateManager';
|
|
import { AbstractViewer } from './viewer';
|
|
import { AbstractViewer } from './viewer';
|
|
-import { ShadowGenerator, BackgroundMaterial, Observable, ShadowLight, CubeTexture, BouncingBehavior, FramingBehavior, Behavior, Light, Engine, Scene, AutoRotationBehavior, AbstractMesh, Quaternion, StandardMaterial, ArcRotateCamera, ImageProcessingConfiguration, Color3, Vector3, SceneLoader, Mesh, HemisphericLight } from 'babylonjs';
|
|
|
|
|
|
+import { MirrorTexture, Plane, ShadowGenerator, Texture, BackgroundMaterial, Observable, ShadowLight, CubeTexture, BouncingBehavior, FramingBehavior, Behavior, Light, Engine, Scene, AutoRotationBehavior, AbstractMesh, Quaternion, StandardMaterial, ArcRotateCamera, ImageProcessingConfiguration, Color3, Vector3, SceneLoader, Mesh, HemisphericLight } from 'babylonjs';
|
|
import { CameraBehavior } from '../interfaces';
|
|
import { CameraBehavior } from '../interfaces';
|
|
|
|
|
|
export class DefaultViewer extends AbstractViewer {
|
|
export class DefaultViewer extends AbstractViewer {
|
|
@@ -156,7 +156,7 @@ export class DefaultViewer extends AbstractViewer {
|
|
this.setupCamera(meshes);
|
|
this.setupCamera(meshes);
|
|
this.setupLights(meshes);
|
|
this.setupLights(meshes);
|
|
|
|
|
|
- return this.initEnvironment();
|
|
|
|
|
|
+ return this.initEnvironment(meshes);
|
|
}
|
|
}
|
|
|
|
|
|
private setModelMetaData() {
|
|
private setModelMetaData() {
|
|
@@ -188,7 +188,7 @@ export class DefaultViewer extends AbstractViewer {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public initEnvironment(): Promise<Scene> {
|
|
|
|
|
|
+ public initEnvironment(focusMeshes: Array<AbstractMesh> = []): Promise<Scene> {
|
|
if (this.configuration.skybox) {
|
|
if (this.configuration.skybox) {
|
|
// Define a general environment textue
|
|
// Define a general environment textue
|
|
let texture;
|
|
let texture;
|
|
@@ -213,17 +213,62 @@ export class DefaultViewer extends AbstractViewer {
|
|
}
|
|
}
|
|
|
|
|
|
this.extendClassWithConfig(box, this.configuration.skybox);
|
|
this.extendClassWithConfig(box, this.configuration.skybox);
|
|
|
|
+
|
|
|
|
+ box && focusMeshes.push(box);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (this.configuration.ground) {
|
|
if (this.configuration.ground) {
|
|
let groundConfig = (typeof this.configuration.ground === 'boolean') ? {} : this.configuration.ground;
|
|
let groundConfig = (typeof this.configuration.ground === 'boolean') ? {} : this.configuration.ground;
|
|
|
|
|
|
- var ground = Mesh.CreateGround('ground', groundConfig.size || 1000, groundConfig.size || 1000, 8, this.scene);
|
|
|
|
|
|
+ let groundSize = groundConfig.size || (this.configuration.skybox && this.configuration.skybox.scale) || 3000;
|
|
|
|
+
|
|
|
|
+ let ground = Mesh.CreatePlane("BackgroundPlane", groundSize, this.scene);
|
|
|
|
+ let backgroundMaterial = new BackgroundMaterial('groundmat', this.scene);
|
|
|
|
+ ground.rotation.x = Math.PI / 2; // Face up by default.
|
|
|
|
+ ground.receiveShadows = groundConfig.receiveShadows || false;
|
|
|
|
+
|
|
|
|
+ // default values
|
|
|
|
+ backgroundMaterial.alpha = 0.9;
|
|
|
|
+ backgroundMaterial.alphaMode = Engine.ALPHA_PREMULTIPLIED_PORTERDUFF;
|
|
|
|
+ backgroundMaterial.shadowLevel = 0.5;
|
|
|
|
+ backgroundMaterial.primaryLevel = 1;
|
|
|
|
+ backgroundMaterial.primaryColor = new Color3(0.2, 0.2, 0.3).toLinearSpace().scale(3);
|
|
|
|
+ backgroundMaterial.secondaryLevel = 0;
|
|
|
|
+ backgroundMaterial.tertiaryLevel = 0;
|
|
|
|
+ backgroundMaterial.useRGBColor = false;
|
|
|
|
+ backgroundMaterial.enableNoise = true;
|
|
|
|
+
|
|
|
|
+ // if config provided, extend the default values
|
|
|
|
+ if (groundConfig.material) {
|
|
|
|
+ this.extendClassWithConfig(ground, ground.material);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ground.material = backgroundMaterial;
|
|
if (this.configuration.ground === true || groundConfig.shadowOnly) {
|
|
if (this.configuration.ground === true || groundConfig.shadowOnly) {
|
|
- ground.material = new BackgroundMaterial('groundmat', this.scene); //new ShadowOnlyMaterial('groundmat', this.scene);
|
|
|
|
|
|
+ // shadow only:
|
|
|
|
+ ground.receiveShadows = true;
|
|
|
|
+ const diffuseTexture = new Texture("https://assets.babylonjs.com/environments/backgroundGround.png", this.scene);
|
|
|
|
+ diffuseTexture.gammaSpace = false;
|
|
|
|
+ diffuseTexture.hasAlpha = true;
|
|
|
|
+ backgroundMaterial.diffuseTexture = diffuseTexture;
|
|
|
|
+ } else if (groundConfig.mirror) {
|
|
|
|
+ var mirror = new MirrorTexture("mirror", 512, this.scene);
|
|
|
|
+ mirror.mirrorPlane = new Plane(0, -1, 0, 0);
|
|
|
|
+ mirror.renderList = mirror.renderList || [];
|
|
|
|
+ focusMeshes.length && focusMeshes.forEach(m => {
|
|
|
|
+ m && mirror.renderList && mirror.renderList.push(m);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ backgroundMaterial.reflectionTexture = mirror;
|
|
} else {
|
|
} else {
|
|
- ground.material = new StandardMaterial('groundmat', this.scene);
|
|
|
|
|
|
+ if (groundConfig.material) {
|
|
|
|
+ if (groundConfig.material.diffuseTexture) {
|
|
|
|
+ const diffuseTexture = new Texture(groundConfig.material.diffuseTexture, this.scene);
|
|
|
|
+ backgroundMaterial.diffuseTexture = diffuseTexture;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // ground.material = new StandardMaterial('groundmat', this.scene);
|
|
}
|
|
}
|
|
//default configuration
|
|
//default configuration
|
|
if (this.configuration.ground === true) {
|
|
if (this.configuration.ground === true) {
|