Merge pull request #3585 from ZappoMan/editToolsImprovements

various edit tool fixes
This commit is contained in:
AndrewMeadows 2014-10-13 10:12:47 -07:00
commit d90d30ad9f
4 changed files with 208 additions and 50 deletions

View file

@ -16,6 +16,8 @@ Script.include("libraries/globals.js");
SelectionDisplay = (function () {
var that = {};
var MINIMUM_DIMENSION = 0.001;
var mode = "UNKNOWN";
var overlayNames = new Array();
var lastAvatarPosition = MyAvatar.position;
@ -260,6 +262,9 @@ SelectionDisplay = (function () {
visible: false,
rotation: yawOverlayRotation,
ignoreRayIntersection: true, // always ignore this
hasTickMarks: true,
majorTickMarksColor: { red: 0, green: 0, blue: 0 },
minorTickMarksColor: { red: 0, green: 0, blue: 0 },
});
var yawHandle = Overlays.addOverlay("billboard", {
@ -393,14 +398,8 @@ SelectionDisplay = (function () {
that.highlightSelectable = function(entityID) {
var properties = Entities.getEntityProperties(entityID);
var center = { x: properties.position.x, y: properties.position.y, z: properties.position.z };
Overlays.editOverlay(highlightBox,
{
visible: true,
position: center,
dimensions: properties.dimensions,
rotation: properties.rotation,
});
Overlays.editOverlay(highlightBox, { visible: true, position: properties.boundingBox.center,
dimensions: properties.boundingBox.dimensions });
};
that.unhighlightSelectable = function(entityID) {
@ -642,8 +641,8 @@ SelectionDisplay = (function () {
Overlays.editOverlay(highlightBox, { visible: false });
Overlays.editOverlay(selectionBox, { visible: selectionBoxVisible, position: objectCenter, dimensions: properties.dimensions,
rotation: properties.rotation,});
Overlays.editOverlay(selectionBox, { visible: selectionBoxVisible, position: properties.boundingBox.center,
dimensions: properties.boundingBox.dimensions });
Overlays.editOverlay(grabberMoveUp, { visible: translateHandlesVisible, position: { x: boundsCenter.x, y: top + grabberMoveUpOffset, z: boundsCenter.z } });
@ -889,6 +888,11 @@ SelectionDisplay = (function () {
// dimensions changes by: (oldNEAR - newNEAR)
var changeInDimensions = { x: 0, y: 0, z: (oldNEAR - newNEAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: 0, y: 0, z: (oldNEAR - newNEAR) * -0.5 };
var newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, changeInPosition);
var wantDebug = false;
@ -934,6 +938,11 @@ SelectionDisplay = (function () {
var newFAR = oldFAR + vector.z;
var changeInDimensions = { x: 0, y: 0, z: (newFAR - oldFAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: 0, y: 0, z: (newFAR - oldFAR) * 0.5 };
var newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, changeInPosition);
var wantDebug = false;
@ -979,6 +988,11 @@ SelectionDisplay = (function () {
var newTOP = oldTOP + vector.y;
var changeInDimensions = { x: 0, y: (newTOP - oldTOP), z: 0 };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
var changeInPosition = { x: 0, y: (newTOP - oldTOP) * 0.5, z: 0 };
var newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, changeInPosition);
var wantDebug = false;
@ -1023,6 +1037,11 @@ SelectionDisplay = (function () {
var newBOTTOM = oldBOTTOM + vector.y;
var changeInDimensions = { x: 0, y: (oldBOTTOM - newBOTTOM), z: 0 };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
var changeInPosition = { x: 0, y: (oldBOTTOM - newBOTTOM) * -0.5, z: 0 };
var newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, changeInPosition);
var wantDebug = false;
@ -1067,6 +1086,11 @@ SelectionDisplay = (function () {
var newRIGHT = oldRIGHT + vector.x;
var changeInDimensions = { x: (newRIGHT - oldRIGHT), y: 0 , z: 0 };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newRIGHT - oldRIGHT) * 0.5, y: 0, z: 0 };
var newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, changeInPosition);
var wantDebug = false;
@ -1111,6 +1135,11 @@ SelectionDisplay = (function () {
var newLEFT = oldLEFT + vector.x;
var changeInDimensions = { x: (oldLEFT - newLEFT), y: 0, z: 0 };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (oldLEFT - newLEFT) * -0.5, y: 0, z: 0 };
var newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, changeInPosition);
var wantDebug = false;
@ -1163,6 +1192,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newRIGHT - oldRIGHT), y: (newBOTTOM - oldBOTTOM) , z: (newNEAR - oldNEAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newRIGHT - oldRIGHT) * 0.5,
y: (newBOTTOM - oldBOTTOM) * -0.5,
z: (newNEAR - oldNEAR) * -0.5 };
@ -1217,6 +1259,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newLEFT - oldLEFT), y: (newBOTTOM - oldBOTTOM) , z: (newNEAR - oldNEAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newLEFT - oldLEFT) * -0.5,
y: (newBOTTOM - oldBOTTOM) * -0.5,
z: (newNEAR - oldNEAR) * -0.5 };
@ -1271,6 +1326,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newRIGHT - oldRIGHT), y: (newTOP - oldTOP) , z: (newNEAR - oldNEAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newRIGHT - oldRIGHT) * 0.5,
y: (newTOP - oldTOP) * 0.5,
z: (newNEAR - oldNEAR) * -0.5 };
@ -1325,6 +1393,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newLEFT - oldLEFT), y: (newTOP - oldTOP) , z: (newNEAR - oldNEAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newLEFT - oldLEFT) * -0.5,
y: (newTOP - oldTOP) * 0.5,
z: (newNEAR - oldNEAR) * -0.5 };
@ -1379,6 +1460,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newRIGHT - oldRIGHT), y: (newBOTTOM - oldBOTTOM) , z: (newFAR - oldFAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newRIGHT - oldRIGHT) * 0.5,
y: (newBOTTOM - oldBOTTOM) * -0.5,
z: (newFAR - oldFAR) * 0.5 };
@ -1433,6 +1527,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newLEFT - oldLEFT), y: (newBOTTOM - oldBOTTOM) , z: (newFAR - oldFAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newLEFT - oldLEFT) * -0.5,
y: (newBOTTOM - oldBOTTOM) * -0.5,
z: (newFAR - oldFAR) * 0.5 };
@ -1487,6 +1594,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newRIGHT - oldRIGHT), y: (newTOP - oldTOP) , z: (newFAR - oldFAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newRIGHT - oldRIGHT) * 0.5,
y: (newTOP - oldTOP) * 0.5,
z: (newFAR - oldFAR) * 0.5 };
@ -1541,6 +1661,19 @@ SelectionDisplay = (function () {
var changeInDimensions = { x: (newLEFT - oldLEFT), y: (newTOP - oldTOP) , z: (newFAR - oldFAR) };
var newDimensions = Vec3.sum(selectedEntityPropertiesOriginalDimensions, changeInDimensions);
if (newDimensions.x < MINIMUM_DIMENSION) {
newDimensions.x = MINIMUM_DIMENSION;
}
if (newDimensions.y < MINIMUM_DIMENSION) {
newDimensions.y = MINIMUM_DIMENSION;
}
if (newDimensions.z < MINIMUM_DIMENSION) {
newDimensions.z = MINIMUM_DIMENSION;
}
var changeInPosition = { x: (newLEFT - oldLEFT) * -0.5,
y: (newTOP - oldTOP) * 0.5,
z: (newFAR - oldFAR) * 0.5 };
@ -1620,11 +1753,15 @@ SelectionDisplay = (function () {
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 });
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 });
Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius,
majorTickMarksAngle: 45.0, minorTickMarksAngle: 5,
majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, });
}
}
@ -1680,11 +1817,15 @@ SelectionDisplay = (function () {
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 });
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 });
Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius,
majorTickMarksAngle: 45.0, minorTickMarksAngle: 5,
majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, });
}
}
};
@ -1738,11 +1879,15 @@ SelectionDisplay = (function () {
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 });
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 });
Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius,
majorTickMarksAngle: 45.0, minorTickMarksAngle: 5,
majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, });
}
}
};
@ -1755,6 +1900,7 @@ SelectionDisplay = (function () {
};
that.mousePressEvent = function(event) {
var somethingClicked = false;
var pickRay = Camera.computePickRay(event.x, event.y);
@ -2055,6 +2201,8 @@ SelectionDisplay = (function () {
Overlays.editOverlay(yawHandle, { ignoreRayIntersection: false });
Overlays.editOverlay(pitchHandle, { ignoreRayIntersection: false });
Overlays.editOverlay(rollHandle, { ignoreRayIntersection: false });
return somethingClicked;
};
that.mouseMoveEvent = function(event) {
@ -2121,8 +2269,9 @@ SelectionDisplay = (function () {
break;
default:
// nothing to do by default
break;
return false;
}
return true;
};
that.mouseReleaseEvent = function(event) {
@ -2156,8 +2305,9 @@ SelectionDisplay = (function () {
};
Controller.mousePressEvent.connect(that.mousePressEvent);
Controller.mouseMoveEvent.connect(that.mouseMoveEvent);
// NOTE: mousePressEvent and mouseMoveEvent from the main script should call us., so we don't hook these:
// Controller.mousePressEvent.connect(that.mousePressEvent);
// Controller.mouseMoveEvent.connect(that.mouseMoveEvent);
Controller.mouseReleaseEvent.connect(that.mouseReleaseEvent);
return that;

View file

@ -338,13 +338,15 @@ function rayPlaneIntersection(pickRay, point, normal) {
function mousePressEvent(event) {
mouseLastPosition = { x: event.x, y: event.y };
entitySelected = false;
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) {
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) {
// Event handled; do nothing.
return;
} else {
entitySelected = false;
selectionDisplay.unselectAll();
// If we aren't active and didn't click on an overlay: quit
if (!isActive) {
return;
@ -440,34 +442,36 @@ function mouseMoveEvent(event) {
if (!isActive) {
return;
}
// allow the selectionDisplay to handle the event first, if it doesn't handle it, then do our own thing
if (selectionDisplay.mouseMoveEvent(event)) {
return;
}
var pickRay = Camera.computePickRay(event.x, event.y);
if (!entitySelected) {
var entityIntersection = Entities.findRayIntersection(pickRay);
if (entityIntersection.accurate) {
if(highlightedEntityID.isKnownID && highlightedEntityID.id != entityIntersection.entityID.id) {
selectionDisplay.unhighlightSelectable(highlightedEntityID);
highlightedEntityID = { id: -1, isKnownID: false };
}
var halfDiagonal = Vec3.length(entityIntersection.properties.dimensions) / 2.0;
var angularSize = 2 * Math.atan(halfDiagonal / Vec3.distance(Camera.getPosition(),
entityIntersection.properties.position)) * 180 / 3.14;
var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE)
&& (allowSmallModels || angularSize > MIN_ANGULAR_SIZE);
if (entityIntersection.entityID.isKnownID && sizeOK) {
if (wantEntityGlow) {
Entities.editEntity(entityIntersection.entityID, { glowLevel: 0.25 });
}
highlightedEntityID = entityIntersection.entityID;
selectionDisplay.highlightSelectable(entityIntersection.entityID);
}
var entityIntersection = Entities.findRayIntersection(pickRay);
if (entityIntersection.accurate) {
if(highlightedEntityID.isKnownID && highlightedEntityID.id != entityIntersection.entityID.id) {
selectionDisplay.unhighlightSelectable(highlightedEntityID);
highlightedEntityID = { id: -1, isKnownID: false };
}
return;
var halfDiagonal = Vec3.length(entityIntersection.properties.dimensions) / 2.0;
var angularSize = 2 * Math.atan(halfDiagonal / Vec3.distance(Camera.getPosition(),
entityIntersection.properties.position)) * 180 / 3.14;
var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE)
&& (allowSmallModels || angularSize > MIN_ANGULAR_SIZE);
if (entityIntersection.entityID.isKnownID && sizeOK) {
if (wantEntityGlow) {
Entities.editEntity(entityIntersection.entityID, { glowLevel: 0.25 });
}
highlightedEntityID = entityIntersection.entityID;
selectionDisplay.highlightSelectable(entityIntersection.entityID);
}
}
}

View file

@ -168,7 +168,8 @@ void Circle3DOverlay::render() {
xColor color = getMajorTickMarksColor();
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
float angle = startAt;
float tickMarkAngle = getMajorTickMarksAngle();
float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle;
float angleInRadians = glm::radians(angle);
float tickMarkLength = getMajorTickMarksLength();
float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius;
@ -183,7 +184,7 @@ void Circle3DOverlay::render() {
glVertex2f(thisPointA.x, thisPointA.y);
glVertex2f(thisPointB.x, thisPointB.y);
angle += getMajorTickMarksAngle();
angle += tickMarkAngle;
}
}
@ -193,7 +194,8 @@ void Circle3DOverlay::render() {
xColor color = getMinorTickMarksColor();
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
float angle = startAt;
float tickMarkAngle = getMinorTickMarksAngle();
float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle;
float angleInRadians = glm::radians(angle);
float tickMarkLength = getMinorTickMarksLength();
float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius;
@ -208,7 +210,7 @@ void Circle3DOverlay::render() {
glVertex2f(thisPointA.x, thisPointA.y);
glVertex2f(thisPointB.x, thisPointB.y);
angle += getMinorTickMarksAngle();
angle += tickMarkAngle;
}
}

View file

@ -179,9 +179,11 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
QScriptValue bottomRightNear = vec3toScriptValue(engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3toScriptValue(engine, aaBox.calcTopFarLeft());
QScriptValue center = vec3toScriptValue(engine, aaBox.calcCenter());
QScriptValue boundingBoxDimensions = vec3toScriptValue(engine, aaBox.getDimensions());
boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("center", center);
boundingBox.setProperty("dimensions", boundingBoxDimensions);
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(boundingBox, boundingBox); // gettable, but not settable
return properties;