|
@@ -52,13 +52,15 @@ module BABYLON {
|
|
// Add drag behavior to handle events when the gizmo is dragged
|
|
// Add drag behavior to handle events when the gizmo is dragged
|
|
this.dragBehavior = new PointerDragBehavior({dragPlaneNormal: planeNormal});
|
|
this.dragBehavior = new PointerDragBehavior({dragPlaneNormal: planeNormal});
|
|
this.dragBehavior.moveAttached = false;
|
|
this.dragBehavior.moveAttached = false;
|
|
|
|
+ this.dragBehavior.maxDragAngle = Math.PI*9/20;
|
|
|
|
+ this.dragBehavior._useAlternatePickedPointAboveMaxDragAngle = true;
|
|
this._rootMesh.addBehavior(this.dragBehavior);
|
|
this._rootMesh.addBehavior(this.dragBehavior);
|
|
|
|
|
|
- var lastDragPosition:Nullable<Vector3> = null;
|
|
|
|
|
|
+ var lastDragPosition = new Vector3();
|
|
|
|
|
|
this.dragBehavior.onDragStartObservable.add((e)=>{
|
|
this.dragBehavior.onDragStartObservable.add((e)=>{
|
|
if(this.attachedMesh){
|
|
if(this.attachedMesh){
|
|
- lastDragPosition = e.dragPlanePoint;
|
|
|
|
|
|
+ lastDragPosition.copyFrom(e.dragPlanePoint);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
@@ -69,9 +71,9 @@ module BABYLON {
|
|
var tmpSnapEvent = {snapDistance: 0};
|
|
var tmpSnapEvent = {snapDistance: 0};
|
|
var currentSnapDragDistance = 0;
|
|
var currentSnapDragDistance = 0;
|
|
this.dragBehavior.onDragObservable.add((event)=>{
|
|
this.dragBehavior.onDragObservable.add((event)=>{
|
|
- if(this.attachedMesh && lastDragPosition){
|
|
|
|
|
|
+ if(this.attachedMesh){
|
|
if(!this.attachedMesh.rotationQuaternion){
|
|
if(!this.attachedMesh.rotationQuaternion){
|
|
- this.attachedMesh.rotationQuaternion = new BABYLON.Quaternion();
|
|
|
|
|
|
+ this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.attachedMesh.rotation.y, this.attachedMesh.rotation.x, this.attachedMesh.rotation.z);
|
|
}
|
|
}
|
|
// Calc angle over full 360 degree (https://stackoverflow.com/questions/43493711/the-angle-between-two-3d-vectors-with-a-result-range-0-360)
|
|
// Calc angle over full 360 degree (https://stackoverflow.com/questions/43493711/the-angle-between-two-3d-vectors-with-a-result-range-0-360)
|
|
var newVector = event.dragPlanePoint.subtract(this.attachedMesh.position).normalize();
|
|
var newVector = event.dragPlanePoint.subtract(this.attachedMesh.position).normalize();
|
|
@@ -113,10 +115,16 @@ module BABYLON {
|
|
var quaternionCoefficient = Math.sin(angle/2)
|
|
var quaternionCoefficient = Math.sin(angle/2)
|
|
var amountToRotate = new BABYLON.Quaternion(planeNormalTowardsCamera.x*quaternionCoefficient,planeNormalTowardsCamera.y*quaternionCoefficient,planeNormalTowardsCamera.z*quaternionCoefficient,Math.cos(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);
|
|
|
|
|
|
+ if(this.updateGizmoRotationToMatchAttachedMesh){
|
|
|
|
+ // Rotate selected mesh quaternion over fixed axis
|
|
|
|
+ this.attachedMesh.rotationQuaternion.multiplyToRef(amountToRotate,this.attachedMesh.rotationQuaternion);
|
|
|
|
+ }else{
|
|
|
|
+ // Rotate selected mesh quaternion over rotated axis
|
|
|
|
+ amountToRotate.multiplyToRef(this.attachedMesh.rotationQuaternion,this.attachedMesh.rotationQuaternion);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
- lastDragPosition = event.dragPlanePoint;
|
|
|
|
|
|
+ lastDragPosition.copyFrom(event.dragPlanePoint);
|
|
if(snapped){
|
|
if(snapped){
|
|
tmpSnapEvent.snapDistance = angle;
|
|
tmpSnapEvent.snapDistance = angle;
|
|
this.onSnapObservable.notifyObservers(tmpSnapEvent);
|
|
this.onSnapObservable.notifyObservers(tmpSnapEvent);
|