mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-10 19:19:42 +02:00
[Case 6491] Dedupe rotation handle tool code (details below).
Pulled the common code shared between the rotation handle tools out into helper funcs: * helperRotationHandleOnBegin * helperRotationHandleOnMove * helperRotationHandleOnEnd These functions either take in or derive the necessary info needed to handle a specific rotation axis. NOTE(s): * Tested yaw, pitch, & roll handles using a box. The behavior remained consistent with that prior to this commit. Reviewed-by: Leander Hasty <leander@1stplayable.com> Changes Committed: modified: scripts/system/libraries/entitySelectionTool.js
This commit is contained in:
parent
926789437c
commit
96afbeca23
1 changed files with 226 additions and 517 deletions
|
@ -3661,29 +3661,16 @@ SelectionDisplay = (function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// YAW GRABBER TOOL DEFINITION
|
function helperRotationHandleOnBegin( rotMode, rotNormal, rotCenter, handleRotation ) {
|
||||||
var initialPosition = SelectionManager.worldPosition;
|
|
||||||
addGrabberTool(yawHandle, {
|
|
||||||
mode: "ROTATE_YAW",
|
|
||||||
onBegin: function(event) {
|
|
||||||
var wantDebug = false;
|
var wantDebug = false;
|
||||||
if (wantDebug) {
|
if (wantDebug) {
|
||||||
print("================== HANDLE_YAW(Beg) -> =======================");
|
print("================== " + rotMode + "(onBegin) -> =======================");
|
||||||
}
|
|
||||||
SelectionManager.saveProperties();
|
|
||||||
initialPosition = SelectionManager.worldPosition;
|
|
||||||
mode = "ROTATE_YAW";
|
|
||||||
rotationNormal = yawNormal;
|
|
||||||
//note: It's expected that the intersection is passed when this is called.
|
|
||||||
if (arguments.length >= 2 ) {
|
|
||||||
yawZero = arguments[ 1 ];
|
|
||||||
} else {
|
|
||||||
print("ERROR( yawHandle.onBegin ) - Intersection wasn't passed!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wantDebug) {
|
SelectionManager.saveProperties();
|
||||||
Vec3.print(" yawZero: ", yawZero);
|
initialPosition = SelectionManager.worldPosition;
|
||||||
}
|
mode = rotMode;
|
||||||
|
rotationNormal = rotNormal;
|
||||||
|
|
||||||
// Size the overlays to the current selection size
|
// Size the overlays to the current selection size
|
||||||
var diagonal = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1;
|
var diagonal = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1;
|
||||||
|
@ -3694,8 +3681,8 @@ SelectionDisplay = (function() {
|
||||||
var outerAlpha = 0.2;
|
var outerAlpha = 0.2;
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
Overlays.editOverlay(rotateOverlayInner, {
|
||||||
visible: true,
|
visible: true,
|
||||||
rotation: yawHandleRotation,
|
rotation: handleRotation,
|
||||||
position: yawCenter,
|
position: rotCenter,
|
||||||
size: innerRadius,
|
size: innerRadius,
|
||||||
innerRadius: 0.9,
|
innerRadius: 0.9,
|
||||||
startAt: 0,
|
startAt: 0,
|
||||||
|
@ -3705,8 +3692,8 @@ SelectionDisplay = (function() {
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
Overlays.editOverlay(rotateOverlayOuter, {
|
||||||
visible: true,
|
visible: true,
|
||||||
rotation: yawHandleRotation,
|
rotation: handleRotation,
|
||||||
position: yawCenter,
|
position: rotCenter,
|
||||||
size: outerRadius,
|
size: outerRadius,
|
||||||
innerRadius: 0.9,
|
innerRadius: 0.9,
|
||||||
startAt: 0,
|
startAt: 0,
|
||||||
|
@ -3716,8 +3703,8 @@ SelectionDisplay = (function() {
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
Overlays.editOverlay(rotateOverlayCurrent, {
|
||||||
visible: true,
|
visible: true,
|
||||||
rotation: yawHandleRotation,
|
rotation: handleRotation,
|
||||||
position: yawCenter,
|
position: rotCenter,
|
||||||
size: outerRadius,
|
size: outerRadius,
|
||||||
startAt: 0,
|
startAt: 0,
|
||||||
endAt: 0,
|
endAt: 0,
|
||||||
|
@ -3726,39 +3713,39 @@ SelectionDisplay = (function() {
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayTarget, {
|
Overlays.editOverlay(rotateOverlayTarget, {
|
||||||
visible: true,
|
visible: true,
|
||||||
rotation: yawHandleRotation,
|
rotation: handleRotation,
|
||||||
position: yawCenter
|
position: rotCenter
|
||||||
});
|
});
|
||||||
|
|
||||||
Overlays.editOverlay(rotationDegreesDisplay, {
|
Overlays.editOverlay(rotationDegreesDisplay, {
|
||||||
visible: true,
|
visible: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
updateRotationDegreesOverlay(0, yawHandleRotation, yawCenter);
|
updateRotationDegreesOverlay(0, handleRotation, rotCenter);
|
||||||
if(wantDebug){
|
if (wantDebug) {
|
||||||
print("================== HANDLE_YAW(Beg) <- =======================");
|
print("================== " + rotMode + "(onBegin) <- =======================");
|
||||||
}
|
}
|
||||||
},
|
}//--End_Function( helperRotationHandleOnBegin )
|
||||||
onEnd: function(event, reason) {
|
|
||||||
print("================== HANDLE_YAW(End) -> =======================");
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotationDegreesDisplay, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
|
|
||||||
pushCommandForSelections();
|
function helperRotationHandleOnMove( event, rotMode, rotZero, rotCenter, handleRotation ) {
|
||||||
print("================== HANDLE_YAW(End) <- =======================");
|
|
||||||
},
|
if ( ! (rotMode == "ROTATE_YAW" || rotMode == "ROTATE_PITCH" || rotMode == "ROTATE_ROLL") ) {
|
||||||
onMove: function(event) {
|
print("ERROR( handleRotationHandleOnMove ) - Encountered Unknown/Invalid RotationMode: " + rotMode );
|
||||||
print("================== HANDLE_YAW(Mve) -> =======================");
|
|
||||||
|
//--EARLY EXIT--
|
||||||
|
return;
|
||||||
|
} else if ( ! rotZero ) {
|
||||||
|
print("ERROR( handleRotationHandleOnMove ) - Invalid RotationZero Specified" );
|
||||||
|
|
||||||
|
//--EARLY EXIT--
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var wantDebug = false;
|
||||||
|
if (wantDebug) {
|
||||||
|
print("================== "+ rotMode + "(onMove) -> =======================");
|
||||||
|
Vec3.print(" rotZero: ", rotZero);
|
||||||
|
}
|
||||||
var pickRay = generalComputePickRay(event.x, event.y);
|
var pickRay = generalComputePickRay(event.x, event.y);
|
||||||
Overlays.editOverlay(selectionBox, {
|
Overlays.editOverlay(selectionBox, {
|
||||||
visible: false
|
visible: false
|
||||||
|
@ -3768,29 +3755,36 @@ SelectionDisplay = (function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
var result = Overlays.findRayIntersection(pickRay, true, [rotateOverlayTarget]);
|
var result = Overlays.findRayIntersection(pickRay, true, [rotateOverlayTarget]);
|
||||||
|
|
||||||
if (result.intersects) {
|
if (result.intersects) {
|
||||||
var center = yawCenter;
|
var centerToZero = Vec3.subtract(rotZero, rotCenter);
|
||||||
var zero = yawZero;
|
var centerToIntersect = Vec3.subtract(result.intersection, rotCenter);
|
||||||
var centerToZero = Vec3.subtract(zero, center);
|
if (wantDebug) {
|
||||||
var centerToIntersect = Vec3.subtract(result.intersection, center);
|
Vec3.print(" RotationNormal: ", rotationNormal);
|
||||||
|
}
|
||||||
// Note: orientedAngle which wants normalized centerToZero and centerToIntersect
|
// Note: orientedAngle which wants normalized centerToZero and centerToIntersect
|
||||||
// handles that internally, so it's to pass unnormalized vectors here.
|
// handles that internally, so it's to pass unnormalized vectors here.
|
||||||
print(" RotNormal - X: " + rotationNormal.x + " Y: " + rotationNormal.y + " Z: " + rotationNormal.z);
|
|
||||||
var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal);
|
var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal);
|
||||||
var distanceFromCenter = Vec3.distance(center, result.intersection);
|
|
||||||
|
var distanceFromCenter = Vec3.distance(rotCenter, result.intersection);
|
||||||
var snapToInner = distanceFromCenter < innerRadius;
|
var snapToInner = distanceFromCenter < innerRadius;
|
||||||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
||||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
||||||
var yawChange = Quat.fromVec3Degrees({
|
|
||||||
x: 0,
|
|
||||||
y: angleFromZero,
|
|
||||||
z: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
updateSelectionsRotation( yawChange );
|
var rotChange = null;
|
||||||
|
switch( rotMode ) {
|
||||||
|
case "ROTATE_YAW":
|
||||||
|
rotChange = Quat.fromVec3Degrees( {x: 0, y: angleFromZero, z: 0} );
|
||||||
|
break;
|
||||||
|
case "ROTATE_PITCH":
|
||||||
|
rotChange = Quat.fromVec3Degrees( {x: angleFromZero, y: 0, z: 0} );
|
||||||
|
break;
|
||||||
|
case "ROTATE_ROLL":
|
||||||
|
rotChange = Quat.fromVec3Degrees( {x: 0, y: 0, z: angleFromZero} );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
updateSelectionsRotation( rotChange );
|
||||||
|
|
||||||
updateRotationDegreesOverlay(angleFromZero, yawHandleRotation, yawCenter);
|
updateRotationDegreesOverlay(angleFromZero, handleRotation, rotCenter);
|
||||||
|
|
||||||
// update the rotation display accordingly...
|
// update the rotation display accordingly...
|
||||||
var startAtCurrent = 0;
|
var startAtCurrent = 0;
|
||||||
|
@ -3840,378 +3834,93 @@ SelectionDisplay = (function() {
|
||||||
minorTickMarksLength: 0.1,
|
minorTickMarksLength: 0.1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}//--End_If( results.intersects )
|
||||||
|
|
||||||
|
if (wantDebug) {
|
||||||
|
print("================== "+ rotMode + "(onMove) <- =======================");
|
||||||
}
|
}
|
||||||
print("================== HANDLE_YAW(Mve) <- =======================");
|
}//--End_Function( helperRotationHandleOnMove )
|
||||||
|
|
||||||
|
function helperRotationHandleOnEnd() {
|
||||||
|
var wantDebug = false;
|
||||||
|
if (wantDebug) {
|
||||||
|
print("================== " + mode + "(onEnd) -> =======================");
|
||||||
|
}
|
||||||
|
Overlays.editOverlay(rotateOverlayInner, {
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(rotateOverlayOuter, {
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(rotateOverlayCurrent, {
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(rotationDegreesDisplay, {
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
|
||||||
|
pushCommandForSelections();
|
||||||
|
|
||||||
|
if (wantDebug) {
|
||||||
|
print("================== " + mode + "(onEnd) <- =======================");
|
||||||
|
}
|
||||||
|
}//--End_Function( helperRotationHandleOnEnd )
|
||||||
|
|
||||||
|
|
||||||
|
// YAW GRABBER TOOL DEFINITION
|
||||||
|
var initialPosition = SelectionManager.worldPosition;
|
||||||
|
addGrabberTool(yawHandle, {
|
||||||
|
mode: "ROTATE_YAW",
|
||||||
|
onBegin: function(event, zeroPoint) {
|
||||||
|
//note: It's expected that the intersection is passed when this is called.
|
||||||
|
// validity will be checked later as a pre-requisite for onMove handling.
|
||||||
|
yawZero = zeroPoint;
|
||||||
|
|
||||||
|
helperRotationHandleOnBegin( "ROTATE_YAW", yawNormal, yawCenter, yawHandleRotation );
|
||||||
|
},
|
||||||
|
onEnd: function(event, reason) {
|
||||||
|
helperRotationHandleOnEnd();
|
||||||
|
},
|
||||||
|
onMove: function(event) {
|
||||||
|
helperRotationHandleOnMove( event, "ROTATE_YAW", yawZero, yawCenter, yawHandleRotation );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// PITCH GRABBER TOOL DEFINITION
|
// PITCH GRABBER TOOL DEFINITION
|
||||||
addGrabberTool(pitchHandle, {
|
addGrabberTool(pitchHandle, {
|
||||||
mode: "ROTATE_PITCH",
|
mode: "ROTATE_PITCH",
|
||||||
onBegin: function (event) {
|
onBegin: function (event, zeroPoint) {
|
||||||
var wantDebug = false;
|
|
||||||
if (wantDebug){
|
|
||||||
print("================== HANDLE_PITCH(Beg) -> =======================");
|
|
||||||
}
|
|
||||||
SelectionManager.saveProperties();
|
|
||||||
initialPosition = SelectionManager.worldPosition;
|
|
||||||
mode = "ROTATE_PITCH";
|
|
||||||
rotationNormal = pitchNormal;
|
|
||||||
//note: It's expected that the intersection is passed when this is called.
|
//note: It's expected that the intersection is passed when this is called.
|
||||||
if (arguments.length >= 2 ) {
|
// validity will be checked later as a pre-requisite for onMove handling.
|
||||||
pitchZero = arguments[ 1 ];
|
pitchZero = zeroPoint;
|
||||||
} else {
|
|
||||||
print("ERROR( pitchHandle.onBegin ) - Intersection wasn't passed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wantDebug) {
|
helperRotationHandleOnBegin( "ROTATE_PITCH", pitchNormal, pitchCenter, pitchHandleRotation );
|
||||||
Vec3.print(" pitchZero: ", pitchZero);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size the overlays to the current selection size
|
|
||||||
var diagonal = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1;
|
|
||||||
var halfDimensions = Vec3.multiply(selectionManager.worldDimensions, 0.5);
|
|
||||||
innerRadius = diagonal;
|
|
||||||
outerRadius = diagonal * 1.15;
|
|
||||||
var innerAlpha = 0.2;
|
|
||||||
var outerAlpha = 0.2;
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
visible: true,
|
|
||||||
rotation: pitchHandleRotation,
|
|
||||||
position: pitchCenter,
|
|
||||||
size: innerRadius,
|
|
||||||
innerRadius: 0.9,
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360,
|
|
||||||
alpha: innerAlpha
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
visible: true,
|
|
||||||
rotation: pitchHandleRotation,
|
|
||||||
position: pitchCenter,
|
|
||||||
size: outerRadius,
|
|
||||||
innerRadius: 0.9,
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360,
|
|
||||||
alpha: outerAlpha,
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
visible: true,
|
|
||||||
rotation: pitchHandleRotation,
|
|
||||||
position: pitchCenter,
|
|
||||||
size: outerRadius,
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 0,
|
|
||||||
innerRadius: 0.9,
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotationDegreesDisplay, {
|
|
||||||
visible: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayTarget, {
|
|
||||||
visible: true,
|
|
||||||
rotation: pitchHandleRotation,
|
|
||||||
position: pitchCenter
|
|
||||||
});
|
|
||||||
|
|
||||||
updateRotationDegreesOverlay(0, pitchHandleRotation, pitchCenter);
|
|
||||||
if(wantDebug){
|
|
||||||
print("================== HANDLE_PITCH(Beg) <- =======================");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onEnd: function(event, reason) {
|
onEnd: function(event, reason) {
|
||||||
print("================== HANDLE_PITCH(End) -> =======================");
|
helperRotationHandleOnEnd();
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotationDegreesDisplay, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
|
|
||||||
pushCommandForSelections();
|
|
||||||
print("================== HANDLE_PITCH(End) <- =======================");
|
|
||||||
},
|
},
|
||||||
onMove: function (event) {
|
onMove: function (event) {
|
||||||
print("================== HANDLE_PITCH(Mve) -> =======================");
|
helperRotationHandleOnMove( event, "ROTATE_PITCH", pitchZero, pitchCenter, pitchHandleRotation );
|
||||||
var pickRay = generalComputePickRay(event.x, event.y);
|
|
||||||
Overlays.editOverlay(selectionBox, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(baseOfEntityProjectionOverlay, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
var result = Overlays.findRayIntersection(pickRay, true, [rotateOverlayTarget]);
|
|
||||||
|
|
||||||
if (result.intersects) {
|
|
||||||
var center = pitchCenter;
|
|
||||||
var zero = pitchZero;
|
|
||||||
var centerToZero = Vec3.subtract(zero, center);
|
|
||||||
var centerToIntersect = Vec3.subtract(result.intersection, center);
|
|
||||||
// Note: orientedAngle which wants normalized centerToZero & centerToIntersect, handles
|
|
||||||
// this internally, so it's fine to pass non-normalized versions here.
|
|
||||||
print(" RotNormal - X: " + rotationNormal.x + " Y: " + rotationNormal.y + " Z: " + rotationNormal.z);
|
|
||||||
var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal);
|
|
||||||
|
|
||||||
var distanceFromCenter = Vec3.distance(center, result.intersection);
|
|
||||||
var snapToInner = distanceFromCenter < innerRadius;
|
|
||||||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
|
||||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
|
||||||
|
|
||||||
var pitchChange = Quat.fromVec3Degrees({
|
|
||||||
x: angleFromZero,
|
|
||||||
y: 0,
|
|
||||||
z: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
updateSelectionsRotation( pitchChange );
|
|
||||||
|
|
||||||
updateRotationDegreesOverlay(angleFromZero, pitchHandleRotation, pitchCenter);
|
|
||||||
|
|
||||||
// update the rotation display accordingly...
|
|
||||||
var startAtCurrent = 0;
|
|
||||||
var endAtCurrent = angleFromZero;
|
|
||||||
var startAtRemainder = angleFromZero;
|
|
||||||
var endAtRemainder = 360;
|
|
||||||
if (angleFromZero < 0) {
|
|
||||||
startAtCurrent = 360 + angleFromZero;
|
|
||||||
endAtCurrent = 360;
|
|
||||||
startAtRemainder = 0;
|
|
||||||
endAtRemainder = startAtCurrent;
|
|
||||||
}
|
|
||||||
if (snapToInner) {
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
startAt: startAtRemainder,
|
|
||||||
endAt: endAtRemainder
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
startAt: startAtCurrent,
|
|
||||||
endAt: endAtCurrent,
|
|
||||||
size: innerRadius,
|
|
||||||
majorTickMarksAngle: innerSnapAngle,
|
|
||||||
minorTickMarksAngle: 0,
|
|
||||||
majorTickMarksLength: -0.25,
|
|
||||||
minorTickMarksLength: 0,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
startAt: startAtRemainder,
|
|
||||||
endAt: endAtRemainder
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
startAt: startAtCurrent,
|
|
||||||
endAt: endAtCurrent,
|
|
||||||
size: outerRadius,
|
|
||||||
majorTickMarksAngle: 45.0,
|
|
||||||
minorTickMarksAngle: 5,
|
|
||||||
majorTickMarksLength: 0.25,
|
|
||||||
minorTickMarksLength: 0.1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print("================== HANDLE_PITCH(Mve) <- =======================");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// ROLL GRABBER TOOL DEFINITION
|
// ROLL GRABBER TOOL DEFINITION
|
||||||
addGrabberTool(rollHandle, {
|
addGrabberTool(rollHandle, {
|
||||||
mode: "ROTATE_ROLL",
|
mode: "ROTATE_ROLL",
|
||||||
onBegin: function (event) {
|
onBegin: function (event, zeroPoint) {
|
||||||
var wantDebug = false;
|
|
||||||
if(wantDebug){
|
|
||||||
print("================== HANDLE_ROLL(Beg) -> =======================");
|
|
||||||
}
|
|
||||||
SelectionManager.saveProperties();
|
|
||||||
initialPosition = SelectionManager.worldPosition;
|
|
||||||
mode = "ROTATE_ROLL";
|
|
||||||
rotationNormal = rollNormal;
|
|
||||||
//note: It's expected that the intersection is passed when this is called.
|
//note: It's expected that the intersection is passed when this is called.
|
||||||
if (arguments.length >= 2 ) {
|
// validity will be checked later as a pre-requisite for onMove handling.
|
||||||
rollZero = arguments[ 1 ];
|
rollZero = zeroPoint;
|
||||||
} else {
|
|
||||||
print("ERROR( rollHandle.onBegin ) - Intersection wasn't passed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wantDebug) {
|
helperRotationHandleOnBegin( "ROTATE_ROLL", rollNormal, rollCenter, rollHandleRotation );
|
||||||
Vec3.print(" rollZero: ", rollZero);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size the overlays to the current selection size
|
|
||||||
var diagonal = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1;
|
|
||||||
var halfDimensions = Vec3.multiply(selectionManager.worldDimensions, 0.5);
|
|
||||||
innerRadius = diagonal;
|
|
||||||
outerRadius = diagonal * 1.15;
|
|
||||||
var innerAlpha = 0.2;
|
|
||||||
var outerAlpha = 0.2;
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
visible: true,
|
|
||||||
rotation: rollHandleRotation,
|
|
||||||
position: rollCenter,
|
|
||||||
size: innerRadius,
|
|
||||||
innerRadius: 0.9,
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360,
|
|
||||||
alpha: innerAlpha
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
visible: true,
|
|
||||||
rotation: rollHandleRotation,
|
|
||||||
position: rollCenter,
|
|
||||||
size: outerRadius,
|
|
||||||
innerRadius: 0.9,
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360,
|
|
||||||
alpha: outerAlpha,
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
visible: true,
|
|
||||||
rotation: rollHandleRotation,
|
|
||||||
position: rollCenter,
|
|
||||||
size: outerRadius,
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 0,
|
|
||||||
innerRadius: 0.9,
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotationDegreesDisplay, {
|
|
||||||
visible: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
Overlays.editOverlay(rotateOverlayTarget, {
|
|
||||||
visible: true,
|
|
||||||
rotation: rollHandleRotation,
|
|
||||||
position: rollCenter
|
|
||||||
});
|
|
||||||
|
|
||||||
updateRotationDegreesOverlay(0, rollHandleRotation, rollCenter);
|
|
||||||
if(wantDebug){
|
|
||||||
print("================== HANDLE_ROLL(Beg) <- =======================");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onEnd: function (event, reason) {
|
onEnd: function (event, reason) {
|
||||||
print("================== HANDLE_ROLL(End) -> =======================");
|
helperRotationHandleOnEnd();
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotationDegreesDisplay, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
|
|
||||||
pushCommandForSelections();
|
|
||||||
print("================== HANDLE_ROLL(End) <- =======================");
|
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
print("================== HANDLE_ROLL(Mve) -> =======================");
|
helperRotationHandleOnMove( event, "ROTATE_ROLL", rollZero, rollCenter, rollHandleRotation );
|
||||||
var pickRay = generalComputePickRay(event.x, event.y);
|
|
||||||
Overlays.editOverlay(selectionBox, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(baseOfEntityProjectionOverlay, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
var result = Overlays.findRayIntersection(pickRay, true, [rotateOverlayTarget]);
|
|
||||||
|
|
||||||
if (result.intersects) {
|
|
||||||
var center = rollCenter;
|
|
||||||
var zero = rollZero;
|
|
||||||
var centerToZero = Vec3.subtract(zero, center);
|
|
||||||
var centerToIntersect = Vec3.subtract(result.intersection, center);
|
|
||||||
// Note: orientedAngle which wants normalized centerToZero & centerToIntersect, handles
|
|
||||||
// this internally, so it's fine to pass non-normalized versions here.
|
|
||||||
print(" RotNormal - X: " + rotationNormal.x + " Y: " + rotationNormal.y + " Z: " + rotationNormal.z);
|
|
||||||
var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal);
|
|
||||||
|
|
||||||
var distanceFromCenter = Vec3.distance(center, result.intersection);
|
|
||||||
var snapToInner = distanceFromCenter < innerRadius;
|
|
||||||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
|
||||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
|
||||||
|
|
||||||
var rollChange = Quat.fromVec3Degrees({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: angleFromZero
|
|
||||||
});
|
|
||||||
|
|
||||||
updateSelectionsRotation( rollChange );
|
|
||||||
|
|
||||||
updateRotationDegreesOverlay(angleFromZero, rollHandleRotation, rollCenter);
|
|
||||||
|
|
||||||
// update the rotation display accordingly...
|
|
||||||
var startAtCurrent = 0;
|
|
||||||
var endAtCurrent = angleFromZero;
|
|
||||||
var startAtRemainder = angleFromZero;
|
|
||||||
var endAtRemainder = 360;
|
|
||||||
if (angleFromZero < 0) {
|
|
||||||
startAtCurrent = 360 + angleFromZero;
|
|
||||||
endAtCurrent = 360;
|
|
||||||
startAtRemainder = 0;
|
|
||||||
endAtRemainder = startAtCurrent;
|
|
||||||
}
|
|
||||||
if (snapToInner) {
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
startAt: startAtRemainder,
|
|
||||||
endAt: endAtRemainder
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
startAt: startAtCurrent,
|
|
||||||
endAt: endAtCurrent,
|
|
||||||
size: innerRadius,
|
|
||||||
majorTickMarksAngle: innerSnapAngle,
|
|
||||||
minorTickMarksAngle: 0,
|
|
||||||
majorTickMarksLength: -0.25,
|
|
||||||
minorTickMarksLength: 0,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Overlays.editOverlay(rotateOverlayInner, {
|
|
||||||
startAt: 0,
|
|
||||||
endAt: 360
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayOuter, {
|
|
||||||
startAt: startAtRemainder,
|
|
||||||
endAt: endAtRemainder
|
|
||||||
});
|
|
||||||
Overlays.editOverlay(rotateOverlayCurrent, {
|
|
||||||
startAt: startAtCurrent,
|
|
||||||
endAt: endAtCurrent,
|
|
||||||
size: outerRadius,
|
|
||||||
majorTickMarksAngle: 45.0,
|
|
||||||
minorTickMarksAngle: 5,
|
|
||||||
majorTickMarksLength: 0.25,
|
|
||||||
minorTickMarksLength: 0.1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print("================== HANDLE_ROLL(Mve) <- =======================");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue