Browse Source

make boundingBoxDragBehavior public on gizmo manager, add start/stop drag events to sixDofDragBehavior

Trevor Baron 7 years ago
parent
commit
3233b03bf4

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

@@ -17,6 +17,7 @@
   - Add uniform scaling drag support to scale gizmo ([TrevorDev](https://github.com/TrevorDev))
   - Support interacting with child elements ([TrevorDev](https://github.com/TrevorDev))
   - BoundingBox gizmo support for including/excluding descendants when computing the bounding box ([TrevorDev](https://github.com/TrevorDev))
+  - Drag start and stop events for bounding box drag and uniform scale drag ([TrevorDev](https://github.com/TrevorDev))
 - Particle system improvements ([Deltakosh](https://github.com/deltakosh))
   - Added a ParticleHelper class to create some pre-configured particle systems in a one-liner method style. [Doc](https://doc.babylonjs.com/How_To/ParticleHelper) ([Deltakosh](https://github.com/deltakosh)) / ([DevChris](https://github.com/yovanoc))
   - Improved CPU particles rendering performance (up to x2 on low end devices)

+ 11 - 2
src/Behaviors/Mesh/babylon.sixDofDragBehavior.ts

@@ -33,8 +33,15 @@ module BABYLON {
          * If camera controls should be detached during the drag
          */
         public detachCameraControls = true;
-
-
+        /**
+         * Fires each time a drag starts
+         */
+        public onDragStartObservable = new Observable<{}>()
+        /**
+         *  Fires each time a drag ends (eg. mouse release after drag)
+         */
+        public onDragEndObservable = new Observable<{}>()
+        
         constructor(){
         }
         
@@ -118,6 +125,7 @@ module BABYLON {
                             }
                         }
                         BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                        this.onDragStartObservable.notifyObservers({});
                     }
                 }else if(pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP){
                     if(this.currentDraggingPointerID == (<PointerEvent>pointerInfo.event).pointerId){
@@ -131,6 +139,7 @@ module BABYLON {
                         if(this.detachCameraControls && attachedElement && this._scene.activeCamera && !this._scene.activeCamera.leftCamera){
                             this._scene.activeCamera.attachControl(attachedElement, true);
                         }
+                        this.onDragEndObservable.notifyObservers({});
                     }
                 }else if(pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE){
                     if(this.currentDraggingPointerID == (<PointerEvent>pointerInfo.event).pointerId && this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh){

+ 9 - 6
src/Gizmos/babylon.gizmoManager.ts

@@ -11,7 +11,10 @@ module BABYLON {
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         private _attachedMesh:Nullable<AbstractMesh> = null;
         private _boundingBoxColor = BABYLON.Color3.FromHexString("#0984e3");
-        private _dragBehavior = new BABYLON.SixDofDragBehavior();
+        /**
+         * When bounding box gizmo is enabled, this can be used to track drag/end events
+         */
+        public boundingBoxDragBehavior = new BABYLON.SixDofDragBehavior();
         /**
          * Array of meshes which will have the gizmo attached when a pointer selected them. If null, all meshes are attachable. (Default: null)
          */
@@ -72,7 +75,7 @@ module BABYLON {
          */
         public attachToMesh(mesh:Nullable<AbstractMesh>){
             if(this._attachedMesh){
-                this._attachedMesh.removeBehavior(this._dragBehavior);
+                this._attachedMesh.removeBehavior(this.boundingBoxDragBehavior);
             }
             this._attachedMesh = mesh;
             for(var key in this.gizmos){
@@ -82,7 +85,7 @@ module BABYLON {
                 }
             }
             if(this.boundingBoxGizmoEnabled && this._attachedMesh){
-                this._attachedMesh.addBehavior(this._dragBehavior);
+                this._attachedMesh.addBehavior(this.boundingBoxDragBehavior);
             }
         }
 
@@ -145,8 +148,8 @@ module BABYLON {
                 this.gizmos.boundingBoxGizmo = this.gizmos.boundingBoxGizmo || new BoundingBoxGizmo(this._boundingBoxColor);
                 this.gizmos.boundingBoxGizmo.attachedMesh = this._attachedMesh;
                 if(this._attachedMesh){
-                    this._attachedMesh.removeBehavior(this._dragBehavior);
-                    this._attachedMesh.addBehavior(this._dragBehavior);
+                    this._attachedMesh.removeBehavior(this.boundingBoxDragBehavior);
+                    this._attachedMesh.addBehavior(this.boundingBoxDragBehavior);
                 }
             }else if(this.gizmos.boundingBoxGizmo){
                 this.gizmos.boundingBoxGizmo.attachedMesh = null;
@@ -168,7 +171,7 @@ module BABYLON {
                     gizmo.dispose();
                 }
             }
-            this._dragBehavior.detach();
+            this.boundingBoxDragBehavior.detach();
         }
     }
 }