|
@@ -5,6 +5,12 @@ module BABYLON {
|
|
|
export class PlaneRotationGizmo extends Gizmo {
|
|
|
private _dragBehavior:PointerDragBehavior;
|
|
|
private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Rotation distance in radians that the gizmo will snap to (Defult: 0)
|
|
|
+ */
|
|
|
+ public snapDistance = 0;
|
|
|
+
|
|
|
/**
|
|
|
* Creates a PlaneRotationGizmo
|
|
|
* @param gizmoLayer The utility layer the gizmo will be added to
|
|
@@ -52,6 +58,8 @@ module BABYLON {
|
|
|
var rotationMatrix = new Matrix();
|
|
|
var planeNormalTowardsCamera = new Vector3();
|
|
|
var localPlaneNormalTowardsCamera = new Vector3();
|
|
|
+
|
|
|
+ var currentSnapDragDistance = 0;
|
|
|
this._dragBehavior.onDragObservable.add((event)=>{
|
|
|
if(!this.interactionsEnabled){
|
|
|
return;
|
|
@@ -83,13 +91,23 @@ module BABYLON {
|
|
|
var halfCircleSide = Vector3.Dot(localPlaneNormalTowardsCamera, cross) > 0.0;
|
|
|
if (halfCircleSide) angle = -angle;
|
|
|
|
|
|
+ // Snapping logic
|
|
|
+ if(this.snapDistance != 0){
|
|
|
+ currentSnapDragDistance+=angle
|
|
|
+ if(Math.abs(currentSnapDragDistance)>this.snapDistance){
|
|
|
+ var dragSteps = Math.floor(currentSnapDragDistance/this.snapDistance);
|
|
|
+ currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;
|
|
|
+ angle = this.snapDistance*dragSteps;
|
|
|
+ }else{
|
|
|
+ angle = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Convert angle and axis to quaternion (http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm)
|
|
|
+ var quaternionCoefficient = Math.sin(angle/2)
|
|
|
+ var amountToRotate = new BABYLON.Quaternion(planeNormalTowardsCamera.x*quaternionCoefficient,planeNormalTowardsCamera.y*quaternionCoefficient,planeNormalTowardsCamera.z*quaternionCoefficient,Math.cos(angle/2));
|
|
|
|
|
|
- // Convert angle and axis to quaternion (http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm)
|
|
|
- var quaternionCoefficient = Math.sin(angle/2)
|
|
|
- var amountToRotate = new BABYLON.Quaternion(planeNormalTowardsCamera.x*quaternionCoefficient,planeNormalTowardsCamera.y*quaternionCoefficient,planeNormalTowardsCamera.z*quaternionCoefficient,Math.cos(angle/2));
|
|
|
-
|
|
|
- // Rotate selected mesh quaternion over fixed axis
|
|
|
- this.attachedMesh.rotationQuaternion.multiplyToRef(amountToRotate,this.attachedMesh.rotationQuaternion);
|
|
|
+ // Rotate selected mesh quaternion over fixed axis
|
|
|
+ this.attachedMesh.rotationQuaternion.multiplyToRef(amountToRotate,this.attachedMesh.rotationQuaternion);
|
|
|
|
|
|
lastDragPosition = event.dragPlanePoint;
|
|
|
}
|