浏览代码

further configuration and fixes

Raanan Weber 7 年之前
父节点
当前提交
728f2610e1
共有 3 个文件被更改,包括 80 次插入12 次删除
  1. 59 6
      Viewer/src/configuration/types/extendedDefault.ts
  2. 14 2
      Viewer/src/model/viewerModel.ts
  3. 7 4
      Viewer/src/viewer/viewer.ts

+ 59 - 6
Viewer/src/configuration/types/extendedDefault.ts

@@ -15,17 +15,70 @@ export let extendedDefaultConfiguration: ViewerConfiguration = {
             intensityMode: 0,
             radius: 0.135,
             spotAngle: 59.9967,
-            shadowConfig: {
-                useBlurExponentialShadowMap: true,
-                useKernelBlur: true,
-                blurKernel: 64,
-                blurScale: 4,
-            },
             shadowBufferSize: 512,
             shadowFieldOfView: 60.977,
             shadowFrustumSize: 2.0,
             shadowMinZ: 1.0,
             shadowMaxZ: 10.0
+        },
+        "light2": {
+            type: 0,
+            shadowEnabled: true,
+            target: { x: 1.0, y: 0.53, z: 0.18 },
+            position: { x: 1.49, y: 1.39, z: -1.33 },
+            diffuse: { r: 0.867, g: 0.816, b: 0.788 },
+            intensity: 4.887,
+            intensityMode: 0,
+            radius: 0.0,
+            spotAngle: 34.285,
+            shadowBufferSize: 512,
+            shadowFieldOfView: 28,
+            shadowFrustumSize: 2.0,
+            shadowMinZ: 0.2,
+            shadowMaxZ: 10.0
+        },
+        "light3": {
+            type: 2,
+            shadowEnabled: true,
+            target: { x: 0, y: 1, z: 0 },
+            position: { x: -4, y: -2, z: 2.23 },
+            diffuse: { r: 0.718, g: 0.772, b: 0.749 },
+            intensity: 7.052,
+            intensityMode: 0,
+            radius: 0.5,
+            spotAngle: 42.85,
+            shadowBufferSize: 512,
+            shadowFieldOfView: 45,
+            shadowFrustumSize: 2.0,
+            shadowMinZ: 0.2,
+            shadowMaxZ: 10.0
+        }
+    },
+    scene: {
+        imageProcessingConfiguration: {
+            colorCurves: {
+                shadowsHue: 43.359,
+                shadowsDensity: 1,
+                shadowsSaturation: -25,
+                shadowsExposure: -3.0,
+                midtonesHue: 93.65,
+                midtonesDensity: -15.24,
+                midtonesExposure: 7.37,
+                midtonesSaturation: -15,
+                highlightsHue: 37.2,
+                highlightsDensity: -22.43,
+                highlightsExposure: 45.0,
+                highlightsSaturation: -15,
+
+            }
         }
+    },
+    model: {
+        rotationOffsetAxis: {
+            x: 0,
+            y: 1,
+            z: 0
+        },
+        rotationOffsetAngle: 3.66519
     }
 }

+ 14 - 2
Viewer/src/model/viewerModel.ts

@@ -1,4 +1,4 @@
-import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, AnimationGroup, Animatable, AbstractMesh, Tools, Scene, SceneLoader, Observable, SceneLoaderProgressEvent, Tags, ParticleSystem, Skeleton, IDisposable, Nullable, Animation, Quaternion, Material } from "babylonjs";
+import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, AnimationGroup, Animatable, AbstractMesh, Tools, Scene, SceneLoader, Observable, SceneLoaderProgressEvent, Tags, ParticleSystem, Skeleton, IDisposable, Nullable, Animation, Quaternion, Material, Vector3 } from "babylonjs";
 import { GLTFFileLoader } from "babylonjs-loaders";
 import { IModelConfiguration } from "../configuration/configuration";
 import { IModelAnimation, GroupModelAnimation, AnimationPlayMode } from "./modelAnimation";
@@ -93,7 +93,7 @@ export class ViewerModel implements IDisposable {
 
         this._animations = [];
         //create a copy of the configuration to make sure it doesn't change even after it is changed in the viewer
-        this._modelConfiguration = deepmerge({}, modelConfiguration);
+        this._modelConfiguration = deepmerge(this._viewer.configuration.model || {}, modelConfiguration);
 
         this._viewer.sceneManager.models.push(this);
         this._viewer.onModelAddedObservable.notifyObservers(this);
@@ -292,6 +292,18 @@ export class ViewerModel implements IDisposable {
                 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);
         }

+ 7 - 4
Viewer/src/viewer/viewer.ts

@@ -132,6 +132,8 @@ export abstract class AbstractViewer {
      */
     protected _configurationLoader: ConfigurationLoader;
 
+    protected _isInit: boolean;
+
     constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
         // if exists, use the container id. otherwise, generate a random string.
         if (containerElement.id) {
@@ -415,18 +417,19 @@ export abstract class AbstractViewer {
      */
     private _onTemplateLoaded(): Promise<AbstractViewer> {
         return this._onTemplatesLoaded().then(() => {
-            let modelConfiguration = this._configuration.model;
+            let autoLoad = typeof this._configuration.model === 'string' || (this._configuration.model && this._configuration.model.url);
             return this._initEngine().then((engine) => {
                 return this.onEngineInitObservable.notifyObserversWithPromise(engine);
             }).then(() => {
-                if (modelConfiguration) {
-                    return this.loadModel(modelConfiguration).catch(e => { }).then(() => { return this.sceneManager.scene });
+                if (autoLoad) {
+                    return this.loadModel(this._configuration.model!).catch(e => { }).then(() => { return this.sceneManager.scene });
                 } else {
                     return this.sceneManager.scene || this.sceneManager.initScene(this._configuration.scene);
                 }
             }).then((scene) => {
                 return this.onSceneInitObservable.notifyObserversWithPromise(scene);
             }).then(() => {
+                this._isInit = true;
                 return this.onInitDoneObservable.notifyObserversWithPromise(this);
             }).catch(e => {
                 Tools.Warn(e.toString());
@@ -494,7 +497,7 @@ export abstract class AbstractViewer {
     public initModel(modelConfig: string | IModelConfiguration, clearScene: boolean = true): ViewerModel {
         let modelUrl = (typeof modelConfig === 'string') ? modelConfig : modelConfig.url;
         if (!modelUrl) {
-            throw new Error("no model configuration provided");
+            throw new Error("no model url provided");
         }
         if (clearScene) {