Procházet zdrojové kódy

Merge pull request #4512 from TrevorDev/boundingBoxBugFixes

avoid picking error on utility layer and bounding box hover highlighting
David Catuhe před 7 roky
rodič
revize
4193de3ead

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

@@ -34,7 +34,7 @@
 - UtilityLayer class to render another scene as a layer on top of an existing scene ([TrevorDev](https://github.com/TrevorDev))
 - AnimationGroup has now onAnimationGroupEnd observable ([RaananW](https://github.com/RaananW))
 - PointerDragBehavior, SixDofDragBehavior and MultiPointerScaleBehavior to enable drag and drop/scaling with mouse or 6dof controller on a mesh ([TrevorDev](https://github.com/TrevorDev))
-- Gizmo and GizmoManager classes used to manipulate meshes in a scene. Position, rotation, scale, and bounding box gizmos ([TrevorDev](https://github.com/TrevorDev))
+- Gizmo and GizmoManager classes used to manipulate meshes in a scene. Gizmo types include position, rotation, scale, and bounding box ([TrevorDev](https://github.com/TrevorDev))
 - Added a new `mesh.ignoreNonUniformScaling` to turn off non uniform scaling compensation ([Deltakosh](https://github.com/deltakosh))
 - AssetsManager tasks will only run when their state is INIT. It is now possible to remove a task from the assets manager ([RaananW](https://github.com/RaananW))
 - Added sprite isVisible field ([TrevorDev](https://github.com/TrevorDev))

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

@@ -129,6 +129,7 @@ module BABYLON {
             this._laserPointer.rotation.x = Math.PI / 2;
             this._laserPointer.position.z = -0.5;
             this._laserPointer.isVisible = false;
+            this._laserPointer.isPickable = false;
 
             if(!webVRController.mesh){
                 // Create an empty mesh that is used prior to loading the high quality model
@@ -167,6 +168,7 @@ module BABYLON {
         public _setLaserPointerParent(mesh:AbstractMesh){
             var makeNotPick = (root: AbstractMesh) => {
                 root.name += " laserPointer";
+                root.isPickable = false;
                 root.getChildMeshes().forEach((c) => {
                     makeNotPick(c);
                 });

+ 1 - 1
src/Debug/babylon.rayHelper.ts

@@ -25,7 +25,7 @@ module BABYLON {
             this.ray = ray;
         }
 
-        public show(scene: Scene, color: Color3): void {
+        public show(scene: Scene, color?: Color3): void {
 
             if (!this._renderFunction && this.ray) {
 

+ 24 - 1
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -8,6 +8,7 @@ module BABYLON {
         private _scaleBoxesParent:AbstractMesh;
         private _boundingDimensions = new BABYLON.Vector3(1,1,1);
         private _renderObserver:Nullable<Observer<Scene>> = null;
+        private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
 
         /**
          * Creates an BoundingBoxGizmo
@@ -20,10 +21,13 @@ module BABYLON {
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             this._updateScale = false;
 
-            // Create Material
+            // Create Materials
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
             coloredMaterial.emissiveColor = color;
+            var hoverColoredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
+            hoverColoredMaterial.disableLighting = true;
+            hoverColoredMaterial.emissiveColor = color.clone().add(new Color3(0.2,0.2,0.2));
 
             // Build bounding box out of lines
             this._lineBoundingBox = new BABYLON.AbstractMesh("", gizmoLayer.utilityLayerScene);
@@ -141,6 +145,24 @@ module BABYLON {
             }
             this._rootMesh.addChild(this._scaleBoxesParent);
 
+            // Hover color change
+            var pointerIds = new Array<AbstractMesh>();
+            this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo, eventState)=>{
+                if(!pointerIds[(<PointerEvent>pointerInfo.event).pointerId]){
+                    this._rotateSpheresParent.getChildMeshes().concat(this._scaleBoxesParent.getChildMeshes()).forEach((mesh)=>{
+                        if(pointerInfo.pickInfo && pointerInfo.pickInfo.pickedMesh == mesh){
+                            pointerIds[(<PointerEvent>pointerInfo.event).pointerId]=mesh;
+                            mesh.material = hoverColoredMaterial;
+                        }
+                    });
+                }else{
+                    if(pointerInfo.pickInfo && pointerInfo.pickInfo.pickedMesh != pointerIds[(<PointerEvent>pointerInfo.event).pointerId]){
+                        pointerIds[(<PointerEvent>pointerInfo.event).pointerId].material = coloredMaterial;
+                        delete pointerIds[(<PointerEvent>pointerInfo.event).pointerId];
+                    }
+                }
+            });
+
             // Update bounding box positions
             this._renderObserver = this.gizmoLayer.originalScene.onBeforeRenderObservable.add(()=>{
                 this._updateBoundingBox();
@@ -214,6 +236,7 @@ module BABYLON {
          * Disposes of the gizmo
          */
         public dispose(){
+            this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver); 
             this.gizmoLayer.originalScene.onBeforeRenderObservable.remove(this._renderObserver);
             this._lineBoundingBox.dispose();
             this._rotateSpheresParent.dispose();