Просмотр исходного кода

Merge pull request #5661 from BabylonJS/validateDragPredicate

validateDragPredicate
David Catuhe 6 лет назад
Родитель
Сommit
98d34317a9

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

@@ -150,6 +150,7 @@
 - Do not clone mesh observables ([Sebavan](https://github.com/Sebavan))
 - Fixed Inspector resolution with AMD loader ([Sebavan](https://github.com/Sebavan))
 - Fix a bug when a call to `updateIndices` leads to changing the size of the index buffer by recreating the subMeshes in that case ([barroij](https://github.com/barroij))
+- PointerDragBehavior validateDrag predicate to stop dragging to specific points ([TrevorDev](https://github.com/TrevorDev))
 
 ### Viewer
 

+ 8 - 1
src/Behaviors/Mesh/babylon.pointerDragBehavior.ts

@@ -97,6 +97,11 @@ module BABYLON {
         }
 
         /**
+         * Predicate to determine if it is valid to move the object to a new position when it is moved
+         */
+        public validateDrag = (targetPosition: Vector3) => {return true; };
+
+        /**
          *  The name of the behavior
          */
         public get name(): string {
@@ -192,7 +197,9 @@ module BABYLON {
                     this._targetPosition.subtractToRef((this._attachedNode).absolutePosition, this._tmpVector);
                     this._tmpVector.scaleInPlace(this.dragDeltaRatio);
                     (this._attachedNode).getAbsolutePosition().addToRef(this._tmpVector, this._tmpVector);
-                    (this._attachedNode).setAbsolutePosition(this._tmpVector);
+                    if (this.validateDrag(this._tmpVector)) {
+                        (this._attachedNode).setAbsolutePosition(this._tmpVector);
+                    }
                     BoundingBoxGizmo._RestorePivotPoint(this._attachedNode);
                 }
             });