Explorar el Código

remove from scene recursive, when mesh is attached set laser pointer in vr helper

Trevor Baron hace 7 años
padre
commit
9502a48c8b

+ 8 - 1
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -104,7 +104,7 @@ module BABYLON {
 
     class VRExperienceHelperControllerGazer extends VRExperienceHelperGazer{
         private _laserPointer: Mesh;
-
+        private _meshAttachedObserver: Nullable<Observer<AbstractMesh>>;
         constructor(public webVRController: WebVRController, scene: Scene, gazeTrackerToClone:Mesh){
             super(scene, gazeTrackerToClone);
             // Laser pointer
@@ -127,6 +127,10 @@ module BABYLON {
             }
 
             this._setLaserPointerParent(webVRController.mesh!);
+
+            this._meshAttachedObserver = webVRController._meshAttachedObservable.add((mesh)=>{
+                this._setLaserPointerParent(mesh);
+            });
         }
 
         _getForwardRay(length:number):Ray{
@@ -176,6 +180,9 @@ module BABYLON {
         dispose(){
             super.dispose();
             this._laserPointer.dispose();
+            if(this._meshAttachedObserver){
+                this.webVRController._meshAttachedObservable.remove(this._meshAttachedObserver);
+            }
         }
     }
 

+ 6 - 0
src/Gamepad/Controllers/babylon.poseEnabledController.ts

@@ -239,6 +239,11 @@ module BABYLON {
         }
 
         /**
+         * @hidden
+         */
+        public _meshAttachedObservable = new Observable<AbstractMesh>()
+
+        /**
          * Attaches a mesh to the controller
          * @param mesh the mesh to be attached
          */
@@ -253,6 +258,7 @@ module BABYLON {
             if (!this._mesh.rotationQuaternion) {
                 this._mesh.rotationQuaternion = new Quaternion();
             }
+            this._meshAttachedObservable.notifyObservers(mesh);
         }
 
         /**

+ 8 - 3
src/babylon.scene.ts

@@ -2941,12 +2941,13 @@
             this.onNewMeshAddedObservable.notifyObservers(newMesh);
         }
 
-        /**
+      /**
          * Remove a mesh for the list of scene's meshes
          * @param toRemove defines the mesh to remove
+         * @param recursive if all child meshes should also be removed from the scene
          * @returns the index where the mesh was in the mesh list
          */
-        public removeMesh(toRemove: AbstractMesh): number {
+        public removeMesh(toRemove: AbstractMesh, recursive = false): number {
             var index = this.meshes.indexOf(toRemove);
             if (index !== -1) {
                 // Remove from the scene if mesh found
@@ -2954,7 +2955,11 @@
             }
 
             this.onMeshRemovedObservable.notifyObservers(toRemove);
-
+            if(recursive){
+                toRemove.getChildMeshes().forEach((m)=>{
+                    this.removeMesh(m);
+                })
+            }
             return index;
         }