Jelajahi Sumber

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 7 tahun lalu
induk
melakukan
40467395b5

+ 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)

+ 13 - 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){
@@ -213,6 +222,8 @@ module BABYLON {
             if(this._virtualDragMesh){
                 this._virtualDragMesh.dispose();
             }
+            this.onDragEndObservable.clear();
+            this.onDragStartObservable.clear();
         }
     }
 }

+ 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();
         }
     }
 }

+ 10 - 11
src/Gizmos/babylon.scaleGizmo.ts

@@ -17,17 +17,16 @@ module BABYLON {
         public zGizmo:AxisScaleGizmo;
 
         /**
-         * @hidden
          * Internal gizmo used to scale all axis equally
          */
-        private _uniformGizmo:AxisScaleGizmo;
+        public uniformScaleGizmo:AxisScaleGizmo;
 
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
             if(this.xGizmo){
                 this.xGizmo.attachedMesh = mesh;
                 this.yGizmo.attachedMesh = mesh;
                 this.zGizmo.attachedMesh = mesh;
-                this._uniformGizmo.attachedMesh = mesh;
+                this.uniformScaleGizmo.attachedMesh = mesh;
             }
         }
         /**
@@ -41,12 +40,12 @@ module BABYLON {
             this.zGizmo = new AxisScaleGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
 
             // Create uniform scale gizmo
-            this._uniformGizmo = new AxisScaleGizmo(new Vector3(0,1,0), BABYLON.Color3.Yellow().scale(0.5), gizmoLayer);
-            this._uniformGizmo.updateGizmoRotationToMatchAttachedMesh = false;
-            this._uniformGizmo.uniformScaling = true
-            var octahedron = BABYLON.Mesh.CreatePolyhedron("", {type: 1}, this._uniformGizmo.gizmoLayer.utilityLayerScene);
+            this.uniformScaleGizmo = new AxisScaleGizmo(new Vector3(0,1,0), BABYLON.Color3.Yellow().scale(0.5), gizmoLayer);
+            this.uniformScaleGizmo.updateGizmoRotationToMatchAttachedMesh = false;
+            this.uniformScaleGizmo.uniformScaling = true
+            var octahedron = BABYLON.Mesh.CreatePolyhedron("", {type: 1}, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);
             octahedron.scaling.scaleInPlace(0.007);
-            this._uniformGizmo.setCustomMesh(octahedron, true);
+            this.uniformScaleGizmo.setCustomMesh(octahedron, true);
             
             this.attachedMesh = null;
         }
@@ -70,7 +69,7 @@ module BABYLON {
                 this.xGizmo.snapDistance = value;
                 this.yGizmo.snapDistance = value;
                 this.zGizmo.snapDistance = value;
-                this._uniformGizmo.snapDistance = value;
+                this.uniformScaleGizmo.snapDistance = value;
             }
         }
         public get snapDistance(){
@@ -85,7 +84,7 @@ module BABYLON {
                 this.xGizmo.scaleRatio = value;
                 this.yGizmo.scaleRatio = value;
                 this.zGizmo.scaleRatio = value;
-                this._uniformGizmo.scaleRatio = value;
+                this.uniformScaleGizmo.scaleRatio = value;
             }
         }
         public get scaleRatio(){
@@ -99,7 +98,7 @@ module BABYLON {
             this.xGizmo.dispose();
             this.yGizmo.dispose();
             this.zGizmo.dispose();
-            this._uniformGizmo.dispose();
+            this.uniformScaleGizmo.dispose();
         }
     }
 }