浏览代码

Merge pull request #4316 from RaananW/extending-model-configuration

A few viewer improvements and bug fixes
David Catuhe 7 年之前
父节点
当前提交
e4c0a9eff4

+ 1 - 1
Viewer/src/loader/plugins/index.ts

@@ -22,7 +22,7 @@ export function getLoaderPluginByName(name: string) {
                 pluginCache[name] = new MSFTLodLoaderPlugin();
                 break;
             case 'applyMaterialConfig':
-                pluginCache[name] = new MSFTLodLoaderPlugin();
+                pluginCache[name] = new ApplyMaterialConfigPlugin();
                 break;
             case 'extendedMaterial':
                 pluginCache[name] = new ExtendedMaterialLoaderPlugin();

+ 6 - 0
Viewer/src/model/viewerModel.ts

@@ -125,6 +125,11 @@ export class ViewerModel implements IDisposable {
 
         this._viewer.sceneManager.models.push(this);
         this._viewer.onModelAddedObservable.notifyObservers(this);
+
+        if (this._modelConfiguration.entryAnimation) {
+            this.rootMesh.setEnabled(false);
+        }
+
         this.onLoadedObservable.add(() => {
             this.updateConfiguration(this._modelConfiguration);
             this._viewer.onModelLoadedObservable.notifyObservers(this);
@@ -273,6 +278,7 @@ export class ViewerModel implements IDisposable {
             callback();
             return;
         }
+        this.rootMesh.setEnabled(true);
         // disable blending for the sake of the entry animation;
         this._viewer.sceneManager.animationBlendingEnabled = false;
         this._applyAnimation(this._entryAnimation, true, callback);

+ 17 - 12
Viewer/src/viewer/sceneManager.ts

@@ -123,21 +123,26 @@ export class SceneManager {
         this.labs = new ViewerLabs(this);
 
         this.onSceneInitObservable.add((scene) => {
-            scene.registerBeforeRender(() => {
-                if (this.models.length && scene.animatables && scene.animatables.length > 0) {
-                    // make sure all models are loaded
-                    if (this.models.every((model) => model.state === ModelState.COMPLETE && !model.currentAnimation)) return;
-                    for (let light of this.scene.lights) {
-                        let generator = light.getShadowGenerator();
-                        if (generator) {
-                            // Processing shadows if animates
-                            let shadowMap = generator.getShadowMap();
-                            if (shadowMap) {
-                                shadowMap.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
-                            }
+
+            let updateShadows = () => {
+                for (let light of this.scene.lights) {
+                    let generator = light.getShadowGenerator();
+                    if (generator) {
+                        // Processing shadows if animates
+                        let shadowMap = generator.getShadowMap();
+                        if (shadowMap) {
+                            shadowMap.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
                         }
                     }
                 }
+            }
+            scene.registerBeforeRender(() => {
+                if (scene.animatables && scene.animatables.length > 0) {
+                    // make sure all models are loaded
+                    updateShadows();
+                } else if (!(this.models.every((model) => model.state === ModelState.COMPLETE && !model.currentAnimation))) {
+                    updateShadows();
+                }
             });
             return this._viewer.onSceneInitObservable.notifyObserversWithPromise(this.scene);
         });

+ 3 - 2
Viewer/src/viewer/viewer.ts

@@ -533,7 +533,7 @@ export abstract class AbstractViewer {
             throw new Error("no model url provided");
         }
         if (clearScene) {
-
+            this.sceneManager.clearScene(true, false);
         }
         let configuration: IModelConfiguration;
         if (typeof modelConfig === 'string') {
@@ -546,7 +546,8 @@ export abstract class AbstractViewer {
 
         //merge the configuration for future models:
         if (this._configuration.model && typeof this._configuration.model === 'object') {
-            deepmerge(this._configuration.model, configuration)
+            let globalConfig = deepmerge({}, this._configuration.model)
+            configuration = deepmerge(globalConfig, configuration);
         } else {
             this._configuration.model = configuration;
         }

+ 2 - 0
dist/preview release/what's new.md

@@ -28,6 +28,7 @@
 - No fullscreen button on small devices ([RaananW](https://github.com/RaananW))
 - Nav-Bar is now disaplayed on fullscreen per default ([RaananW](https://github.com/RaananW))
 - Viewer configuration supports deprecated values using the new configurationCompatibility processor  ([RaananW](https://github.com/RaananW))
+- Shadows will only render while models are entering the scene or animating ([RaananW](https://github.com/RaananW))
 
 ## Bug fixes
 
@@ -44,5 +45,6 @@
 - Fix Animation Slider Interaction on Mozilla/Firefox ([sebavan](http://www.github.com/sebavan))
 - Fix Animation Slider Clickable area size Cross Plat ([sebavan](http://www.github.com/sebavan))
 - Ground material didn't take the default main color is no material definition was provided ([RaananW](https://github.com/RaananW))
+- Model configuration was not extended correctly if loaded more than one model ([RaananW](https://github.com/RaananW))
 
 ## Breaking changes