浏览代码

fixing camera re-attach after drag

Raanan Weber 4 年之前
父节点
当前提交
87f800cbdf
共有 2 个文件被更改,包括 13 次插入8 次删除
  1. 5 3
      src/Behaviors/Meshes/pointerDragBehavior.ts
  2. 8 5
      src/Behaviors/Meshes/sixDofDragBehavior.ts

+ 5 - 3
src/Behaviors/Meshes/pointerDragBehavior.ts

@@ -153,7 +153,7 @@ export class PointerDragBehavior implements Behavior<AbstractMesh> {
     private _alternatePickedPoint = new Vector3(0, 0, 0);
     private _worldDragAxis = new Vector3(0, 0, 0);
     private _targetPosition = new Vector3(0, 0, 0);
-    private _attachedElement: Nullable<HTMLElement> = null;
+    private _attachedToElement: boolean = false;
     /**
      * Attaches the drag behavior the passed in mesh
      * @param ownerNode The mesh that will be dragged around once attached
@@ -258,13 +258,14 @@ export class PointerDragBehavior implements Behavior<AbstractMesh> {
         this._moving = false;
 
         // Reattach camera controls
-        if (this.detachCameraControls && this._attachedElement && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {
+        if (this.detachCameraControls && this._attachedToElement && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {
             if (this._scene.activeCamera.getClassName() === "ArcRotateCamera") {
                 const arcRotateCamera = this._scene.activeCamera as ArcRotateCamera;
                 arcRotateCamera.attachControl(arcRotateCamera.inputs ? arcRotateCamera.inputs.noPreventDefault : true, arcRotateCamera._useCtrlForPanning, arcRotateCamera._panningMouseButton);
             } else {
                 this._scene.activeCamera.attachControl(this._scene.activeCamera.inputs ? this._scene.activeCamera.inputs.noPreventDefault : true);
             }
+            this._attachedToElement = false;
         }
     }
 
@@ -320,8 +321,9 @@ export class PointerDragBehavior implements Behavior<AbstractMesh> {
             if (this.detachCameraControls && this._scene.activeCamera && this._scene.activeCamera.inputs && !this._scene.activeCamera.leftCamera) {
                 if (this._scene.activeCamera.inputs.attachedToElement) {
                     this._scene.activeCamera.detachControl();
+                    this._attachedToElement = true;
                 } else {
-                    this._attachedElement = null;
+                    this._attachedToElement = false;
                 }
             }
         }

+ 8 - 5
src/Behaviors/Meshes/sixDofDragBehavior.ts

@@ -22,7 +22,7 @@ export class SixDofDragBehavior implements Behavior<Mesh> {
     private _pointerObserver: Nullable<Observer<PointerInfo>>;
     private _moving = false;
     private _startingOrientation = new Quaternion();
-    private _attachedElement: Nullable<HTMLElement> = null;
+    private _attachedToElement: boolean = false;
 
     /**
      * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 3)
@@ -144,12 +144,13 @@ export class SixDofDragBehavior implements Behavior<Mesh> {
                     this.dragging = true;
                     this.currentDraggingPointerID = (<PointerEvent>pointerInfo.event).pointerId;
 
-                    // Detatch camera controls
+                    // Detach camera controls
                     if (this.detachCameraControls && this._pointerCamera && !this._pointerCamera.leftCamera) {
                         if (this._pointerCamera.inputs.attachedToElement) {
                             this._pointerCamera.detachControl();
+                            this._attachedToElement = true;
                         } else {
-                            this._attachedElement = null;
+                            this._attachedToElement = false;
                         }
                     }
                     PivotTools._RestorePivotPoint(pickedMesh);
@@ -164,8 +165,9 @@ export class SixDofDragBehavior implements Behavior<Mesh> {
                     this._virtualOriginMesh.removeChild(this._virtualDragMesh);
 
                     // Reattach camera controls
-                    if (this.detachCameraControls && this._attachedElement && this._pointerCamera && !this._pointerCamera.leftCamera) {
+                    if (this.detachCameraControls && this._attachedToElement && this._pointerCamera && !this._pointerCamera.leftCamera) {
                         this._pointerCamera.attachControl(true);
+                        this._attachedToElement = false;
                     }
                     this.onDragEndObservable.notifyObservers({});
                 }
@@ -245,8 +247,9 @@ export class SixDofDragBehavior implements Behavior<Mesh> {
      */
     public detach(): void {
         if (this._scene) {
-            if (this.detachCameraControls && this._attachedElement && this._pointerCamera && !this._pointerCamera.leftCamera) {
+            if (this.detachCameraControls && this._attachedToElement && this._pointerCamera && !this._pointerCamera.leftCamera) {
                 this._pointerCamera.attachControl(true);
+                this._attachedToElement = false;
             }
             this._scene.onPointerObservable.remove(this._pointerObserver);
         }