Browse Source

Commented obvservable changes.

Atulya Ravishankar 7 years ago
parent
commit
72bf079cda

+ 6 - 3
Viewer/src/managers/observablesManager.ts

@@ -54,8 +54,13 @@ export class ObservablesManager {
      */
      */
     public onFrameRenderedObservable: Observable<any>;
     public onFrameRenderedObservable: Observable<any>;
 
 
-
+    /**
+     * Will notify when VR mode is entered.
+     */
     public onEnteringVRObservable: Observable<any>;
     public onEnteringVRObservable: Observable<any>;
+    /**
+     * Will notify when VR mode is exited.
+     */
     public onExitingVRObservable: Observable<any>;
     public onExitingVRObservable: Observable<any>;
 
 
     constructor() {
     constructor() {
@@ -70,7 +75,6 @@ export class ObservablesManager {
         this.onViewerInitStartedObservable = new Observable();
         this.onViewerInitStartedObservable = new Observable();
         this.onLoaderInitObservable = new Observable();
         this.onLoaderInitObservable = new Observable();
         this.onFrameRenderedObservable = new Observable();
         this.onFrameRenderedObservable = new Observable();
-
         this.onEnteringVRObservable = new Observable();
         this.onEnteringVRObservable = new Observable();
         this.onExitingVRObservable = new Observable();
         this.onExitingVRObservable = new Observable();
     }
     }
@@ -86,7 +90,6 @@ export class ObservablesManager {
         this.onViewerInitDoneObservable.clear();
         this.onViewerInitDoneObservable.clear();
         this.onLoaderInitObservable.clear();
         this.onLoaderInitObservable.clear();
         this.onFrameRenderedObservable.clear();
         this.onFrameRenderedObservable.clear();
-
         this.onEnteringVRObservable.clear();
         this.onEnteringVRObservable.clear();
         this.onExitingVRObservable.clear();
         this.onExitingVRObservable.clear();
     }
     }

+ 7 - 3
Viewer/src/managers/sceneManager.ts

@@ -59,7 +59,13 @@ export class SceneManager {
      */
      */
     onVRConfiguredObservable: Observable<IPostConfigurationCallback<VRExperienceHelper, IVRConfiguration>>;
     onVRConfiguredObservable: Observable<IPostConfigurationCallback<VRExperienceHelper, IVRConfiguration>>;
 
 
+    /**
+     * Will notify when VR mode is entered.
+     */
     onEnteringVRObservable: Observable<any>;
     onEnteringVRObservable: Observable<any>;
+    /**
+     * Will notify when VR mode is exited.
+     */
     onExitingVRObservable: Observable<any>;
     onExitingVRObservable: Observable<any>;
 
 
     /**
     /**
@@ -136,7 +142,6 @@ export class SceneManager {
         this.onSceneOptimizerConfiguredObservable = new Observable();
         this.onSceneOptimizerConfiguredObservable = new Observable();
         this.onEnvironmentConfiguredObservable = new Observable();
         this.onEnvironmentConfiguredObservable = new Observable();
         this.onVRConfiguredObservable = new Observable();
         this.onVRConfiguredObservable = new Observable();
-
         this.onEnteringVRObservable = new Observable();
         this.onEnteringVRObservable = new Observable();
         this.onExitingVRObservable = new Observable();
         this.onExitingVRObservable = new Observable();
 
 
@@ -945,7 +950,7 @@ export class SceneManager {
         this.camera.beta = (this._globalConfiguration.camera && this._globalConfiguration.camera.beta) || this.camera.beta;
         this.camera.beta = (this._globalConfiguration.camera && this._globalConfiguration.camera.beta) || this.camera.beta;
         this.camera.radius = (this._globalConfiguration.camera && this._globalConfiguration.camera.radius) || this.camera.radius;
         this.camera.radius = (this._globalConfiguration.camera && this._globalConfiguration.camera.radius) || this.camera.radius;
 
 
-        const sceneDiagonalLenght = sizeVec.length(); 
+        const sceneDiagonalLenght = sizeVec.length();
         if (isFinite(sceneDiagonalLenght))
         if (isFinite(sceneDiagonalLenght))
             this.camera.upperRadiusLimit = sceneDiagonalLenght * 4;
             this.camera.upperRadiusLimit = sceneDiagonalLenght * 4;
 
 
@@ -1431,7 +1436,6 @@ export class SceneManager {
         this.onSceneInitObservable.clear();
         this.onSceneInitObservable.clear();
         this.onSceneOptimizerConfiguredObservable.clear();
         this.onSceneOptimizerConfiguredObservable.clear();
         this.onVRConfiguredObservable.clear();
         this.onVRConfiguredObservable.clear();
-
         this.onEnteringVRObservable.clear();
         this.onEnteringVRObservable.clear();
         this.onExitingVRObservable.clear();
         this.onExitingVRObservable.clear();
 
 

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

@@ -121,9 +121,15 @@ export abstract class AbstractViewer {
         return this.observablesManager.onFrameRenderedObservable;
         return this.observablesManager.onFrameRenderedObservable;
     }
     }
 
 
+    /**
+     * Observers registered here will be executed when VR more is entered.
+     */
     public get onEnteringVRObservable(): Observable<AbstractViewer> {
     public get onEnteringVRObservable(): Observable<AbstractViewer> {
         return this.observablesManager.onEnteringVRObservable;
         return this.observablesManager.onEnteringVRObservable;
     }
     }
+    /**
+     * Observers registered here will be executed when VR mode is exited.
+     */
     public get onExitingVRObservable(): Observable<AbstractViewer> {
     public get onExitingVRObservable(): Observable<AbstractViewer> {
         return this.observablesManager.onExitingVRObservable;
         return this.observablesManager.onExitingVRObservable;
     }
     }
@@ -153,7 +159,6 @@ export abstract class AbstractViewer {
      * This functions are also registered at the native scene. The reference can be used to unregister them.
      * This functions are also registered at the native scene. The reference can be used to unregister them.
      */
      */
     protected _registeredOnBeforeRenderFunctions: Array<() => void>;
     protected _registeredOnBeforeRenderFunctions: Array<() => void>;
-
     /**
     /**
      * The configuration loader of this viewer
      * The configuration loader of this viewer
      */
      */
@@ -272,45 +277,6 @@ export abstract class AbstractViewer {
 
 
     protected _vrInit: boolean = false;
     protected _vrInit: boolean = false;
 
 
-    // private upscaleModelAndEnvironment() {
-    //     // scale the model
-    //     if (this.sceneManager.models.length) {
-    //         let boundingVectors = this.sceneManager.models[0].rootMesh.getHierarchyBoundingVectors();
-    //         let sizeVec = boundingVectors.max.subtract(boundingVectors.min);
-    //         let maxDimension = Math.max(sizeVec.x, sizeVec.y, sizeVec.z);
-    //         this._vrScale = (1 / maxDimension);
-    //         if (this.configuration.vr && this.configuration.vr.objectScaleFactor) {
-    //             this._vrScale *= this.configuration.vr.objectScaleFactor;
-    //         }
-
-    //         this.sceneManager.models[0].rootMesh.scaling.scaleInPlace(this._vrScale);
-
-    //         // reposition the object to "float" in front of the user
-    //         this.sceneManager.models[0].rootMesh.position.y += this._vrModelRepositioning;
-    //         this.sceneManager.models[0].rootMesh.rotationQuaternion = null;
-    //     }
-
-    //     // scale the environment to match the model
-    //     if (this.sceneManager.environmentHelper) {
-    //         this.sceneManager.environmentHelper.ground && this.sceneManager.environmentHelper.ground.scaling.scaleInPlace(this._vrScale);
-    //         this.sceneManager.environmentHelper.skybox && this.sceneManager.environmentHelper.skybox.scaling.scaleInPlace(this._vrScale);
-    //     }
-    // }
-
-    // private downscaleModelAndEnvironment() {
-    //     // undo the scaling of the model
-    //     if (this.sceneManager.models.length) {
-    //         this.sceneManager.models[0].rootMesh.scaling.scaleInPlace(1 / this._vrScale);
-    //         this.sceneManager.models[0].rootMesh.position.y -= this._vrModelRepositioning;
-    //     }
-
-    //     // undo the scaling of the environment
-    //     if (this.sceneManager.environmentHelper) {
-    //         this.sceneManager.environmentHelper.ground && this.sceneManager.environmentHelper.ground.scaling.scaleInPlace(1 / this._vrScale);
-    //         this.sceneManager.environmentHelper.skybox && this.sceneManager.environmentHelper.skybox.scaling.scaleInPlace(1 / this._vrScale);
-    //     }
-    // }
-
     public toggleVR() {
     public toggleVR() {
         if (!this._vrInit) {
         if (!this._vrInit) {
             this._initVR();
             this._initVR();
@@ -318,11 +284,6 @@ export abstract class AbstractViewer {
 
 
         if (this.sceneManager.vrHelper && !this.sceneManager.vrHelper.isInVRMode) {
         if (this.sceneManager.vrHelper && !this.sceneManager.vrHelper.isInVRMode) {
 
 
-            //this.sceneManager.onEnteringVRObservable.remove(o)
-            // this.sceneManager.onEnteringVRObservable.add(() => {
-            //     this.onEnteringVRObservable.notifyObservers(this);
-            // });
-
             // make sure the floor is set
             // make sure the floor is set
             if (this.sceneManager.environmentHelper && this.sceneManager.environmentHelper.ground) {
             if (this.sceneManager.environmentHelper && this.sceneManager.environmentHelper.ground) {
                 this.sceneManager.vrHelper.addFloorMesh(this.sceneManager.environmentHelper.ground);
                 this.sceneManager.vrHelper.addFloorMesh(this.sceneManager.environmentHelper.ground);
@@ -350,8 +311,6 @@ export abstract class AbstractViewer {
                     }
                     }
                 }
                 }
 
 
-                console.log("upscaling");
-
                 // scale the model
                 // scale the model
                 if (this.sceneManager.models.length) {
                 if (this.sceneManager.models.length) {
                     let boundingVectors = this.sceneManager.models[0].rootMesh.getHierarchyBoundingVectors();
                     let boundingVectors = this.sceneManager.models[0].rootMesh.getHierarchyBoundingVectors();
@@ -395,14 +354,6 @@ export abstract class AbstractViewer {
         if (this.sceneManager.vrHelper) {
         if (this.sceneManager.vrHelper) {
             this.sceneManager.onExitingVRObservable.add(() => {
             this.sceneManager.onExitingVRObservable.add(() => {
                 if (this._vrToggled) {
                 if (this._vrToggled) {
-
-                    //this.sceneManager.onExitingVRObservable.remove(o)
-                    // var o = this.sceneManager.onExitingVRObservable.add(() => {
-                    //     this.onExitingVRObservable.notifyObservers(this);
-                    // });
-
-                    console.log("downscaling");
-
                     this._vrToggled = false;
                     this._vrToggled = false;
                     
                     
                     // undo the scaling of the model
                     // undo the scaling of the model
@@ -722,8 +673,7 @@ export abstract class AbstractViewer {
         // create a new template manager for this viewer
         // create a new template manager for this viewer
         this.sceneManager = new SceneManager(this.engine, this._configurationContainer, this.observablesManager);
         this.sceneManager = new SceneManager(this.engine, this._configurationContainer, this.observablesManager);
         
         
-        // //this.sceneManager.onEnteringVRObservable.remove(o)
-        var o = this.sceneManager.onEnteringVRObservable.add(() => {
+        this.sceneManager.onEnteringVRObservable.add(() => {
             this.onEnteringVRObservable.notifyObservers(this);
             this.onEnteringVRObservable.notifyObservers(this);
         });
         });
         
         

+ 2 - 10
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -71,8 +71,6 @@ module BABYLON {
         /** @hidden */
         /** @hidden */
         public _activePointer = false;
         public _activePointer = false;
 
 
-        
-
         constructor(public scene: Scene, gazeTrackerToClone: Nullable<Mesh> = null) {
         constructor(public scene: Scene, gazeTrackerToClone: Nullable<Mesh> = null) {
             this._id = VRExperienceHelperGazer._idCounter++;
             this._id = VRExperienceHelperGazer._idCounter++;
 
 
@@ -258,7 +256,7 @@ module BABYLON {
         private _webVRrequesting = false;
         private _webVRrequesting = false;
         // Are we presenting to the headset right now?
         // Are we presenting to the headset right now?
         private _webVRpresenting = false;
         private _webVRpresenting = false;
-
+        // Have we entered VR?
         private hasEnteredVR: boolean;
         private hasEnteredVR: boolean;
 
 
         // Are we presenting in the fullscreen fallback?
         // Are we presenting in the fullscreen fallback?
@@ -778,12 +776,6 @@ module BABYLON {
         private onVrDisplayPresentChange() {
         private onVrDisplayPresentChange() {
             var vrDisplay = this._scene.getEngine().getVRDevice();
             var vrDisplay = this._scene.getEngine().getVRDevice();
             if (vrDisplay) {
             if (vrDisplay) {
-                // var wasPresenting = this._webVRpresenting;
-                // if (wasPresenting && this.isInVRMode) {
-                //     this.exitVR();
-                // }
-                // // A VR display is connected
-                // this._webVRpresenting = vrDisplay.isPresenting;
                 var wasPresenting = this._webVRpresenting;
                 var wasPresenting = this._webVRpresenting;
                 this._webVRpresenting = vrDisplay.isPresenting;
                 this._webVRpresenting = vrDisplay.isPresenting;
                 if (wasPresenting && !this._webVRpresenting)
                 if (wasPresenting && !this._webVRpresenting)
@@ -886,7 +878,7 @@ module BABYLON {
          * Attempt to exit VR, or fullscreen.
          * Attempt to exit VR, or fullscreen.
          */
          */
         public exitVR() {
         public exitVR() {
-            if (this.hasEnteredVR) { ////////////////////////////////////////////////////////////////////////// risky!
+            if (this.hasEnteredVR) {
                 if (this.onExitingVRObservable) {
                 if (this.onExitingVRObservable) {
                     try {
                     try {
                         this.onExitingVRObservable.notifyObservers(this);
                         this.onExitingVRObservable.notifyObservers(this);