浏览代码

Merge pull request #4959 from TrevorDev/gazeDispose

Gaze dispose
sebavan 7 年之前
父节点
当前提交
c3f0e43fc8
共有 3 个文件被更改,包括 45 次插入5 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 43 4
      src/Cameras/VR/babylon.vrExperienceHelper.ts
  3. 1 1
      src/Mesh/babylon.mesh.ts

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

@@ -161,6 +161,7 @@
 - Fix File Loading if hosted from `file:`-Protocol ([ltetzlaff](https://github.com/ltetzlaff))
 - Do not throw error when updating a controller with no left stick ([TrevorDev](https://github.com/TrevorDev))
 - Exiting VR can result in messed up view ([TrevorDev](https://github.com/TrevorDev))
+- Dispose existing gazeTrackers when setting a new one, remove pivot matrix of meshes using boundingBoxGizmo ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 

+ 43 - 4
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -405,7 +405,7 @@ module BABYLON {
         }
 
         /**
-         * The mesh used to display where the user is selecting, 
+         * The mesh used to display where the user is selecting, this mesh will be cloned and set as the gazeTracker for the left and right controller
          * when set bakeCurrentTransformIntoVertices will be called on the mesh.
          * See http://doc.babylonjs.com/resources/baking_transformations 
          */
@@ -415,6 +415,18 @@ module BABYLON {
 
         public set gazeTrackerMesh(value: Mesh) {
             if (value) {
+                // Dispose of existing meshes
+                if( this._cameraGazer._gazeTracker){
+                    this._cameraGazer._gazeTracker.dispose();
+                }
+                if (this._leftController && this._leftController._gazeTracker) {
+                    this._leftController._gazeTracker.dispose();
+                }
+                if (this._rightController && this._rightController._gazeTracker) {
+                    this._rightController._gazeTracker.dispose();
+                }
+
+                // Set and create gaze trackers on head and controllers
                 this._cameraGazer._gazeTracker = value;
                 this._cameraGazer._gazeTracker.bakeCurrentTransformIntoVertices();
                 this._cameraGazer._gazeTracker.isPickable = false;
@@ -431,6 +443,31 @@ module BABYLON {
         }
 
         /**
+         * If the gaze trackers scale should be updated to be constant size when pointing at near/far meshes
+         */
+        public updateGazeTrackerScale = true;
+
+        /**
+         * The gaze tracking mesh corresponding to the left controller
+         */
+        public get leftControllerGazeTrackerMesh():Nullable<Mesh>{
+            if (this._leftController) {
+                return this._leftController._gazeTracker;
+            }
+            return null;
+        }
+
+        /**
+         * The gaze tracking mesh corresponding to the right controller
+         */
+        public get rightControllerGazeTrackerMesh():Nullable<Mesh>{
+            if (this._rightController) {
+                return this._rightController._gazeTracker;
+            }
+            return null;
+        }
+
+        /**
          * If the ray of the gaze should be displayed.
          */
         public get displayGaze(): boolean {
@@ -1653,9 +1690,11 @@ module BABYLON {
                     if (gazer._isActionableMesh) {
                         multiplier = 3;
                     }
-                    gazer._gazeTracker.scaling.x = hit.distance * multiplier;
-                    gazer._gazeTracker.scaling.y = hit.distance * multiplier;
-                    gazer._gazeTracker.scaling.z = hit.distance * multiplier;
+                    if(this.updateGazeTrackerScale){
+                        gazer._gazeTracker.scaling.x = hit.distance * multiplier;
+                        gazer._gazeTracker.scaling.y = hit.distance * multiplier;
+                        gazer._gazeTracker.scaling.z = hit.distance * multiplier;
+                    }
 
                     var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);
                     // To avoid z-fighting

+ 1 - 1
src/Mesh/babylon.mesh.ts

@@ -1816,7 +1816,7 @@
          * The optional parameter `doNotCloneChildren` (default `false`) allows/denies the recursive cloning of the original mesh children if any.
          * The parameter `clonePhysicsImpostor` (default `true`)  allows/denies the cloning in the same time of the original mesh `body` used by the physics engine, if any. 
          */
-        public clone(name: string, newParent?: Node, doNotCloneChildren?: boolean, clonePhysicsImpostor: boolean = true): Mesh {
+        public clone(name: string = "", newParent?: Node, doNotCloneChildren?: boolean, clonePhysicsImpostor: boolean = true): Mesh {
             return new Mesh(name, this.getScene(), newParent, this, doNotCloneChildren, clonePhysicsImpostor);
         }