Bläddra i källkod

fix bounding box rotation to be relative to bounding box

Trevor Baron 7 år sedan
förälder
incheckning
23357caada

+ 1 - 1
src/Behaviors/Mesh/babylon.sixDofDragBehavior.ts

@@ -83,7 +83,7 @@ module BABYLON {
                         this._virtualOriginMesh.removeChild(this._virtualDragMesh);
                         this._virtualDragMesh.position.copyFrom(pickedMesh.absolutePosition);
                         if(!pickedMesh.rotationQuaternion){
-                            pickedMesh.rotationQuaternion = new Quaternion();
+                            pickedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(pickedMesh.rotation.y,pickedMesh.rotation.x,pickedMesh.rotation.z);
                         }
                         this._virtualDragMesh.rotationQuaternion!.copyFrom(pickedMesh.rotationQuaternion);
                         this._virtualOriginMesh.addChild(this._virtualDragMesh);

+ 8 - 3
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -11,6 +11,7 @@ module BABYLON {
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         private _scaleDragSpeed = 0.2;
 
+        private _tmpQuaternion = new Quaternion();
         /**
          * Creates an BoundingBoxGizmo
          * @param gizmoLayer The utility layer the gizmo will be added to
@@ -78,13 +79,17 @@ module BABYLON {
                         var projectDist = Vector3.Dot(dragAxis, event.delta);
 
                         // Rotate based on axis
+                        if(!this.attachedMesh.rotationQuaternion){
+                            this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.attachedMesh.rotation.y,this.attachedMesh.rotation.x,this.attachedMesh.rotation.z);
+                        }
                         if(i>=8){
-                            this.attachedMesh.rotation.z -= projectDist;
+                            Quaternion.RotationYawPitchRollToRef(0,0,-projectDist, this._tmpQuaternion);
                         }else if(i>=4){
-                            this.attachedMesh.rotation.y -= projectDist;
+                            Quaternion.RotationYawPitchRollToRef(-projectDist,0,0, this._tmpQuaternion);
                         }else{
-                            this.attachedMesh.rotation.x -= projectDist;
+                            Quaternion.RotationYawPitchRollToRef(0,-projectDist,0, this._tmpQuaternion);
                         }
+                        this.attachedMesh.rotationQuaternion!.multiplyInPlace(this._tmpQuaternion);
                     }
                 });