ソースを参照

changes and bug fixes
environment map configuration, environment texture fix

Raanan Weber 7 年 前
コミット
293c2388d3

+ 3 - 1
Viewer/src/configuration/types/default.ts

@@ -98,7 +98,9 @@ export let defaultConfiguration: ViewerConfiguration = {
             }
         }*/
     },
-    ground: {},
+    ground: {
+        receiveShadows: true
+    },
     engine: {
         antialiasing: true
     },

+ 12 - 0
Viewer/src/configuration/types/environmentMap.ts

@@ -0,0 +1,12 @@
+import { ViewerConfiguration } from './../configuration';
+
+export const environmentMapConfiguration: ViewerConfiguration = {
+    lab: {
+        environmentAssetsRootURL: '/assets/environment/',
+        environmentMap: {
+            texture: 'EnvMap_2.0-256.env',
+            rotationY: 0,
+            tintLevel: 0.4
+        }
+    }
+}

+ 11 - 21
Viewer/src/configuration/types/extended.ts

@@ -15,21 +15,18 @@ export let extendedConfiguration: ViewerConfiguration = {
         "light1": {
             type: 0,
             shadowEnabled: false,
-            target: { x: 0, y: 0, z: 0 },
-            position: { x: -0.78, y: 1.298, z: 1.62 },
-            diffuse: { r: 1.0, g: 1.0, b: 1.0 },
-            intensity: 2,
+            position: { x: -1.78, y: 2.298, z: 2.62 },
+            diffuse: { r: 0.8, g: 0.8, b: 0.8 },
+            intensity: 3,
             intensityMode: 0,
-            radius: 0.135,
-            spotAngle: 59.9967,
+            radius: 3.135,
         },
         "light3": {
             type: 2,
             shadowEnabled: false,
-            target: { x: 0, y: 1, z: 0 },
-            position: { x: -4, y: 2, z: 2.23 },
+            position: { x: -4, y: 2, z: -2.23 },
             diffuse: { r: 0.718, g: 0.772, b: 0.749 },
-            intensity: 3.052,
+            intensity: 2.052,
             intensityMode: 0,
             radius: 0.5,
             spotAngle: 42.85
@@ -52,14 +49,13 @@ export let extendedConfiguration: ViewerConfiguration = {
                 highlightsHue: 37.2,
                 highlightsDensity: -22.43,
                 highlightsExposure: 45.0,
-                highlightsSaturation: -15,
-
+                highlightsSaturation: -15
             }
         },
         mainColor: {
-            r: 0.8,
-            g: 0.8,
-            b: 0.8
+            r: 0.7,
+            g: 0.7,
+            b: 0.7
         }
     },
     loaderPlugins: {
@@ -79,19 +75,13 @@ export let extendedConfiguration: ViewerConfiguration = {
             directEnabled: true,
             directIntensity: 0.884,
             emissiveIntensity: 1.04,
-            environmentIntensity: 0.268
+            environmentIntensity: 0.868
         },
         normalize: true,
         castShadow: true,
         receiveShadows: true
     },
     lab: {
-        environmentAssetsRootURL: '/assets/environment/',
-        environmentMap: {
-            texture: 'EnvMap_2.0-256.env',
-            rotationY: 0,
-            tintLevel: 0.4
-        },
         renderingPipelines: {
             default: {
                 bloomEnabled: true,

+ 4 - 0
Viewer/src/configuration/types/index.ts

@@ -3,6 +3,7 @@ import { defaultConfiguration } from './default';
 import { extendedConfiguration } from './extended';
 import { ViewerConfiguration } from '../configuration';
 import { shadowDirectionalLightConfiguration, shadowSpotlLightConfiguration } from './shadowLight';
+import { environmentMapConfiguration } from './environmentMap';
 import * as deepmerge from '../../../assets/deepmerge.min.js';
 
 let getConfigurationType = function (types: string): ViewerConfiguration {
@@ -10,6 +11,9 @@ let getConfigurationType = function (types: string): ViewerConfiguration {
     let typesSeparated = types.split(",");
     typesSeparated.forEach(type => {
         switch (type.trim()) {
+            case 'environmentMap':
+                config = deepmerge(config, environmentMapConfiguration);
+                break;
             case 'shadowDirectionalLight':
                 config = deepmerge(config, shadowDirectionalLightConfiguration);
                 break;

+ 21 - 6
Viewer/src/configuration/types/shadowLight.ts

@@ -1,18 +1,25 @@
 import { ViewerConfiguration } from './../configuration';
 
 export const shadowDirectionalLightConfiguration: ViewerConfiguration = {
+    model: {
+        receiveShadows: true,
+        castShadow: true
+    },
+    ground: {
+        receiveShadows: true
+    },
     lights: {
         shadowDirectionalLight: {
             type: 1,
             shadowEnabled: true,
-            target: { x: 0, y: 0, z: 1 },
+            target: { x: 0, y: 0, z: 0.5 },
             position: { x: 1.49, y: 2.39, z: -1.33 },
             diffuse: { r: 0.867, g: 0.816, b: 0.788 },
-            intensity: 2.887,
+            intensity: 4.887,
             intensityMode: 0,
             shadowBufferSize: 1024,
-            shadowFrustumSize: 4.0,
-            shadowFieldOfView: 80.977,
+            shadowFrustumSize: 8.0,
+            shadowFieldOfView: 50.977,
             shadowMinZ: 0.1,
             shadowMaxZ: 12.0,
             shadowConfig: {
@@ -24,12 +31,20 @@ export const shadowDirectionalLightConfiguration: ViewerConfiguration = {
 }
 
 export const shadowSpotlLightConfiguration: ViewerConfiguration = {
+    model: {
+        receiveShadows: true,
+        castShadow: true
+    },
+    ground: {
+        receiveShadows: true
+    },
     lights: {
         shadowSpotLight: {
             type: 2,
+            intensity: 2,
             shadowEnabled: true,
-            target: { x: 0, y: 0, z: 0 },
-            position: { x: 0, y: 2.1, z: 2.7 },
+            target: { x: 0, y: 0, z: 0.5 },
+            position: { x: 0, y: 3.5, z: 3.7 },
             angle: 1,
             shadowOrthoScale: 0.5,
             shadowBufferSize: 1024,

+ 54 - 43
Viewer/src/model/viewerModel.ts

@@ -279,44 +279,6 @@ export class ViewerModel implements IDisposable {
                 updateMeshesWithNoParent(variable, configValues.w, 'w');
             }
         }
-        // position?
-        if (this._modelConfiguration.position) {
-            updateXYZ('position', this._modelConfiguration.position);
-        }
-        if (this._modelConfiguration.rotation) {
-            //quaternion?
-            if (this._modelConfiguration.rotation.w) {
-                meshesWithNoParent.forEach(mesh => {
-                    if (!mesh.rotationQuaternion) {
-                        mesh.rotationQuaternion = new Quaternion();
-                    }
-                })
-                updateXYZ('rotationQuaternion', this._modelConfiguration.rotation);
-            } else {
-                updateXYZ('rotation', this._modelConfiguration.rotation);
-            }
-        }
-
-        if (this._modelConfiguration.rotationOffsetAxis) {
-            let rotationAxis = new Vector3(0, 0, 0).copyFrom(this._modelConfiguration.rotationOffsetAxis as Vector3);
-
-            meshesWithNoParent.forEach(m => {
-                if (this._modelConfiguration.rotationOffsetAngle) {
-                    m.rotate(rotationAxis, this._modelConfiguration.rotationOffsetAngle);
-                }
-            })
-
-        }
-
-        if (this._modelConfiguration.scaling) {
-            updateXYZ('scaling', this._modelConfiguration.scaling);
-        }
-
-        if (this._modelConfiguration.castShadow) {
-            this._meshes.forEach(mesh => {
-                Tags.AddTagsTo(mesh, 'castShadow');
-            });
-        }
 
         if (this._modelConfiguration.normalize) {
             let center = false;
@@ -352,13 +314,61 @@ export class ViewerModel implements IDisposable {
                     const center = boundingInfo.min.add(halfSizeVec);
                     mesh.position = center.scale(-1);
 
-                    // Set on ground.
-                    //mesh.position.y = 0;
-
                     // Recompute Info.
                     mesh.computeWorldMatrix(true);
                 });
             }
+        } else {
+            //center automatically
+            meshesWithNoParent.forEach(mesh => {
+                const boundingInfo = mesh.getHierarchyBoundingVectors(true);
+                const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
+                const halfSizeVec = sizeVec.scale(0.5);
+                const center = boundingInfo.min.add(halfSizeVec);
+                mesh.position = center.scale(-1);
+
+                // Recompute Info.
+                mesh.computeWorldMatrix(true);
+            });
+        }
+
+        // position?
+        if (this._modelConfiguration.position) {
+            updateXYZ('position', this._modelConfiguration.position);
+        }
+        if (this._modelConfiguration.rotation) {
+            //quaternion?
+            if (this._modelConfiguration.rotation.w) {
+                meshesWithNoParent.forEach(mesh => {
+                    if (!mesh.rotationQuaternion) {
+                        mesh.rotationQuaternion = new Quaternion();
+                    }
+                })
+                updateXYZ('rotationQuaternion', this._modelConfiguration.rotation);
+            } else {
+                updateXYZ('rotation', this._modelConfiguration.rotation);
+            }
+        }
+
+        if (this._modelConfiguration.rotationOffsetAxis) {
+            let rotationAxis = new Vector3(0, 0, 0).copyFrom(this._modelConfiguration.rotationOffsetAxis as Vector3);
+
+            meshesWithNoParent.forEach(m => {
+                if (this._modelConfiguration.rotationOffsetAngle) {
+                    m.rotate(rotationAxis, this._modelConfiguration.rotationOffsetAngle);
+                }
+            })
+
+        }
+
+        if (this._modelConfiguration.scaling) {
+            updateXYZ('scaling', this._modelConfiguration.scaling);
+        }
+
+        if (this._modelConfiguration.castShadow) {
+            this._meshes.forEach(mesh => {
+                Tags.AddTagsTo(mesh, 'castShadow');
+            });
         }
 
         let meshes = this.rootMesh.getChildMeshes(false);
@@ -394,8 +404,9 @@ export class ViewerModel implements IDisposable {
             if (this._modelConfiguration.material.directEnabled !== undefined) {
                 material.disableLighting = !this._modelConfiguration.material.directEnabled;
             }
-
-            material.reflectionColor = this._viewer.sceneManager.mainColor;
+            if (this._viewer.sceneManager.mainColor) {
+                material.reflectionColor = this._viewer.sceneManager.mainColor;
+            }
         }
         else if (material instanceof BABYLON.MultiMaterial) {
             for (let i = 0; i < material.subMaterials.length; i++) {

+ 1 - 1
Viewer/src/viewer/defaultViewer.ts

@@ -23,7 +23,7 @@ export class DefaultViewer extends AbstractViewer {
         super(containerElement, initialConfiguration);
         this.onModelLoadedObservable.add(this._onModelLoaded);
         this.sceneManager.onSceneInitObservable.add(() => {
-            extendClassWithConfig(this.sceneManager.scene, this._configuration.scene);
+            // extendClassWithConfig(this.sceneManager.scene, this._configuration.scene);
             return this.sceneManager.scene;
         });
 

ファイルの差分が大きいため隠しています
+ 53 - 16
Viewer/src/viewer/sceneManager.ts