Merge pull request #3709 from huffman/entity-tool-updates

Entity tool cleanup and fixes
This commit is contained in:
AndrewMeadows 2014-11-03 08:37:01 -08:00
commit 61d12ba0a9
3 changed files with 37 additions and 104 deletions

View file

@ -86,7 +86,7 @@ CameraManager = function() {
that.updateCamera(); that.updateCamera();
cameraTool.setVisible(true); cameraTool.setVisible(false);
} }
that.disable = function(ignoreCamera) { that.disable = function(ignoreCamera) {
@ -100,7 +100,7 @@ CameraManager = function() {
cameraTool.setVisible(false); cameraTool.setVisible(false);
} }
that.focus = function(entityProperties) { that.focus = function() {
var dim = SelectionManager.worldDimensions; var dim = SelectionManager.worldDimensions;
var size = Math.max(dim.x, Math.max(dim.y, dim.z)); var size = Math.max(dim.x, Math.max(dim.y, dim.z));

View file

@ -209,12 +209,6 @@ SelectionDisplay = (function () {
var lastCameraOrientation = Camera.getOrientation(); var lastCameraOrientation = Camera.getOrientation();
var lastPlaneIntersection; var lastPlaneIntersection;
var currentSelection = { id: -1, isKnownID: false };
var entitySelected = false;
var selectedEntityProperties;
var selectedEntityPropertiesOriginalPosition;
var selectedEntityPropertiesOriginalDimensions;
var handleHoverColor = { red: 224, green: 67, blue: 36 }; var handleHoverColor = { red: 224, green: 67, blue: 36 };
var handleHoverAlpha = 1.0; var handleHoverAlpha = 1.0;
@ -656,20 +650,12 @@ SelectionDisplay = (function () {
}; };
that.select = function(entityID, event) { that.select = function(entityID, event) {
var properties = Entities.getEntityProperties(entityID); var properties = Entities.getEntityProperties(SelectionManager.selections[0]);
// if (currentSelection.isKnownID == true) {
// that.unselect(currentSelection);
// }
currentSelection = entityID;
entitySelected = true;
// lastCameraPosition = Camera.getPosition(); lastCameraPosition = Camera.getPosition();
lastCameraOrientation = Camera.getOrientation(); lastCameraOrientation = Camera.getOrientation();
if (event !== false) { if (event !== false) {
selectedEntityProperties = properties;
selectedEntityPropertiesOriginalPosition = properties.position;
selectedEntityPropertiesOriginalDimensions = properties.dimensions;
pickRay = Camera.computePickRay(event.x, event.y); pickRay = Camera.computePickRay(event.x, event.y);
lastPlaneIntersection = rayPlaneIntersection(pickRay, properties.position, Quat.getFront(lastCameraOrientation)); lastPlaneIntersection = rayPlaneIntersection(pickRay, properties.position, Quat.getFront(lastCameraOrientation));
@ -678,8 +664,6 @@ SelectionDisplay = (function () {
print("select() with EVENT...... "); print("select() with EVENT...... ");
print(" event.y:" + event.y); print(" event.y:" + event.y);
Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection); Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection);
Vec3.print(" originalPosition:", selectedEntityPropertiesOriginalPosition);
Vec3.print(" originalDimensions:", selectedEntityPropertiesOriginalDimensions);
Vec3.print(" current position:", properties.position); Vec3.print(" current position:", properties.position);
} }
@ -939,11 +923,6 @@ SelectionDisplay = (function () {
}; };
that.unselectAll = function () { that.unselectAll = function () {
if (currentSelection.isKnownID == true) {
that.unselect(currentSelection);
}
currentSelection = { id: -1, isKnownID: false };
entitySelected = false;
}; };
that.updateHandles = function() { that.updateHandles = function() {
@ -952,7 +931,9 @@ SelectionDisplay = (function () {
return; return;
} }
that.updateRotationHandles(); that.updateRotationHandles();
that.highlightSelectable();
var rotation, dimensions, position; var rotation, dimensions, position;
@ -1113,12 +1094,6 @@ SelectionDisplay = (function () {
}; };
that.unselect = function (entityID) { that.unselect = function (entityID) {
that.setOverlaysVisible(false);
Entities.editEntity(entityID, { localRenderAlpha: 1.0 });
currentSelection = { id: -1, isKnownID: false };
entitySelected = false;
}; };
var initialXZPick = null; var initialXZPick = null;
@ -1207,15 +1182,16 @@ SelectionDisplay = (function () {
} }
} }
tooltip.updateText(selectedEntityProperties);
that.select(currentSelection, false); // TODO: this should be more than highlighted
SelectionManager._update(); SelectionManager._update();
} }
}; };
var lastXYPick = null
addGrabberTool(grabberMoveUp, { addGrabberTool(grabberMoveUp, {
mode: "TRANSLATE_UP_DOWN", mode: "TRANSLATE_UP_DOWN",
onBegin: function(event) { onBegin: function(event) {
lastXYPick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, Quat.getFront(lastCameraOrientation));
SelectionManager.saveProperties(); SelectionManager.saveProperties();
// Duplicate entities if alt is pressed. This will make a // Duplicate entities if alt is pressed. This will make a
@ -1243,7 +1219,7 @@ SelectionDisplay = (function () {
// translate mode left/right based on view toward entity // translate mode left/right based on view toward entity
var newIntersection = rayPlaneIntersection(pickRay, var newIntersection = rayPlaneIntersection(pickRay,
selectedEntityPropertiesOriginalPosition, SelectionManager.worldPosition,
Quat.getFront(lastCameraOrientation)); Quat.getFront(lastCameraOrientation));
var vector = Vec3.subtract(newIntersection, lastPlaneIntersection); var vector = Vec3.subtract(newIntersection, lastPlaneIntersection);
@ -1253,8 +1229,6 @@ SelectionDisplay = (function () {
vector.x = 0; vector.x = 0;
vector.z = 0; vector.z = 0;
// newPosition = Vec3.sum(selectedEntityPropertiesOriginalPosition, vector);
var wantDebug = false; var wantDebug = false;
if (wantDebug) { if (wantDebug) {
print("translateUpDown... "); print("translateUpDown... ");
@ -1262,8 +1236,6 @@ SelectionDisplay = (function () {
Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection); Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection);
Vec3.print(" newIntersection:", newIntersection); Vec3.print(" newIntersection:", newIntersection);
Vec3.print(" vector:", vector); Vec3.print(" vector:", vector);
Vec3.print(" originalPosition:", selectedEntityPropertiesOriginalPosition);
Vec3.print(" recentPosition:", selectedEntityProperties.position);
Vec3.print(" newPosition:", newPosition); Vec3.print(" newPosition:", newPosition);
} }
for (var i = 0; i < SelectionManager.selections.length; i++) { for (var i = 0; i < SelectionManager.selections.length; i++) {
@ -1273,8 +1245,6 @@ SelectionDisplay = (function () {
Entities.editEntity(SelectionManager.selections[i], properties); Entities.editEntity(SelectionManager.selections[i], properties);
} }
tooltip.updateText(selectedEntityProperties);
that.select(currentSelection, false); // TODO: this should be more than highlighted
SelectionManager._update(); SelectionManager._update();
}, },
}); });
@ -1306,7 +1276,7 @@ SelectionDisplay = (function () {
var rotation = null; var rotation = null;
var onBegin = function(event) { var onBegin = function(event) {
var properties = Entities.getEntityProperties(currentSelection); var properties = Entities.getEntityProperties(SelectionManager.selections[0]);
initialProperties = properties; initialProperties = properties;
rotation = spaceMode == SPACE_LOCAL ? properties.rotation : Quat.fromPitchYawRollDegrees(0, 0, 0); rotation = spaceMode == SPACE_LOCAL ? properties.rotation : Quat.fromPitchYawRollDegrees(0, 0, 0);
@ -1445,11 +1415,11 @@ SelectionDisplay = (function () {
var changeInPosition = Vec3.multiplyQbyV(rotation, vec3Mult(p, changeInDimensions)); var changeInPosition = Vec3.multiplyQbyV(rotation, vec3Mult(p, changeInDimensions));
var newPosition = Vec3.sum(initialPosition, changeInPosition); var newPosition = Vec3.sum(initialPosition, changeInPosition);
selectedEntityProperties.position = newPosition;
selectedEntityProperties.dimensions = newDimensions;
for (var i = 0; i < SelectionManager.selections.length; i++) { for (var i = 0; i < SelectionManager.selections.length; i++) {
Entities.editEntity(SelectionManager.selections[i], selectedEntityProperties); Entities.editEntity(SelectionManager.selections[i], {
position: newPosition,
dimensions: newDimensions,
});
} }
var wantDebug = false; var wantDebug = false;
@ -1460,18 +1430,14 @@ SelectionDisplay = (function () {
Vec3.print(" vector:", vector); Vec3.print(" vector:", vector);
Vec3.print(" oldPOS:", oldPOS); Vec3.print(" oldPOS:", oldPOS);
Vec3.print(" newPOS:", newPOS); Vec3.print(" newPOS:", newPOS);
Vec3.print(" oldDimensions:", selectedEntityPropertiesOriginalDimensions);
Vec3.print(" changeInDimensions:", changeInDimensions); Vec3.print(" changeInDimensions:", changeInDimensions);
Vec3.print(" newDimensions:", newDimensions); Vec3.print(" newDimensions:", newDimensions);
Vec3.print(" oldPosition:", selectedEntityPropertiesOriginalPosition);
Vec3.print(" changeInPosition:", changeInPosition); Vec3.print(" changeInPosition:", changeInPosition);
Vec3.print(" newPosition:", newPosition); Vec3.print(" newPosition:", newPosition);
} }
tooltip.updateText(selectedEntityProperties);
SelectionManager._update(); SelectionManager._update();
that.select(currentSelection, false); // TODO: this should be more than highlighted
}; };
@ -1590,7 +1556,6 @@ SelectionDisplay = (function () {
} }
if (result.intersects) { if (result.intersects) {
var properties = Entities.getEntityProperties(currentSelection);
var center = yawCenter; var center = yawCenter;
var zero = yawZero; var zero = yawZero;
var centerToZero = Vec3.subtract(center, zero); var centerToZero = Vec3.subtract(center, zero);
@ -1664,8 +1629,8 @@ SelectionDisplay = (function () {
// 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;
var halfDimensions = Vec3.multiply(selectionManager.worldDimensions, 0.5); var halfDimensions = Vec3.multiply(selectionManager.worldDimensions, 0.5);
var innerRadius = diagonal; innerRadius = diagonal;
var outerRadius = diagonal * 1.15; outerRadius = diagonal * 1.15;
var innerAlpha = 0.2; var innerAlpha = 0.2;
var outerAlpha = 0.2; var outerAlpha = 0.2;
Overlays.editOverlay(rotateOverlayInner, Overlays.editOverlay(rotateOverlayInner,
@ -1721,7 +1686,7 @@ SelectionDisplay = (function () {
} }
if (result.intersects) { if (result.intersects) {
var properties = Entities.getEntityProperties(currentSelection); var properties = Entities.getEntityProperties(selectionManager.selections[0]);
var center = pitchCenter; var center = pitchCenter;
var zero = pitchZero; var zero = pitchZero;
var centerToZero = Vec3.subtract(center, zero); var centerToZero = Vec3.subtract(center, zero);
@ -1794,8 +1759,8 @@ SelectionDisplay = (function () {
// 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;
var halfDimensions = Vec3.multiply(selectionManager.worldDimensions, 0.5); var halfDimensions = Vec3.multiply(selectionManager.worldDimensions, 0.5);
var innerRadius = diagonal; innerRadius = diagonal;
var outerRadius = diagonal * 1.15; outerRadius = diagonal * 1.15;
var innerAlpha = 0.2; var innerAlpha = 0.2;
var outerAlpha = 0.2; var outerAlpha = 0.2;
Overlays.editOverlay(rotateOverlayInner, Overlays.editOverlay(rotateOverlayInner,
@ -1851,7 +1816,7 @@ SelectionDisplay = (function () {
} }
if (result.intersects) { if (result.intersects) {
var properties = Entities.getEntityProperties(currentSelection); var properties = Entities.getEntityProperties(selectionManager.selections[0]);
var center = rollCenter; var center = rollCenter;
var zero = rollZero; var zero = rollZero;
var centerToZero = Vec3.subtract(center, zero); var centerToZero = Vec3.subtract(center, zero);
@ -1915,9 +1880,9 @@ SelectionDisplay = (function () {
}); });
that.checkMove = function() { that.checkMove = function() {
if (currentSelection.isKnownID && if (SelectionManager.hasSelection() &&
(!Vec3.equal(Camera.getPosition(), lastCameraPosition) || !Quat.equal(Camera.getOrientation(), lastCameraOrientation))){ (!Vec3.equal(Camera.getPosition(), lastCameraPosition) || !Quat.equal(Camera.getOrientation(), lastCameraOrientation))){
that.select(currentSelection, false, false); that.select(selectionManager.selections[0], false, false);
} }
}; };
@ -2033,7 +1998,7 @@ SelectionDisplay = (function () {
var overlayOrientation; var overlayOrientation;
var overlayCenter; var overlayCenter;
var properties = Entities.getEntityProperties(currentSelection); var properties = Entities.getEntityProperties(selectionManager.selections[0]);
var angles = Quat.safeEulerAngles(properties.rotation); var angles = Quat.safeEulerAngles(properties.rotation);
var pitch = angles.x; var pitch = angles.x;
var yaw = angles.y; var yaw = angles.y;
@ -2169,12 +2134,11 @@ SelectionDisplay = (function () {
if (somethingClicked) { if (somethingClicked) {
pickRay = Camera.computePickRay(event.x, event.y); pickRay = Camera.computePickRay(event.x, event.y);
lastPlaneIntersection = rayPlaneIntersection(pickRay, selectedEntityPropertiesOriginalPosition, lastPlaneIntersection = rayPlaneIntersection(pickRay, selectionManager.worldPosition,
Quat.getFront(lastCameraOrientation)); Quat.getFront(lastCameraOrientation));
if (wantDebug) { if (wantDebug) {
print("mousePressEvent()...... " + overlayNames[result.overlayID]); print("mousePressEvent()...... " + overlayNames[result.overlayID]);
Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection); Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection);
Vec3.print(" originalPosition:", selectedEntityPropertiesOriginalPosition);
} }
} }
@ -2289,8 +2253,8 @@ SelectionDisplay = (function () {
}; };
that.updateHandleSizes = function() { that.updateHandleSizes = function() {
if (selectedEntityProperties) { if (selectionManager.hasSelection()) {
var diff = Vec3.subtract(selectedEntityProperties.position, Camera.getPosition()); var diff = Vec3.subtract(selectionManager.worldPosition, Camera.getPosition());
var grabberSize = Vec3.length(diff) * GRABBER_DISTANCE_TO_SIZE_RATIO; var grabberSize = Vec3.length(diff) * GRABBER_DISTANCE_TO_SIZE_RATIO;
for (var i = 0; i < stretchHandles.length; i++) { for (var i = 0; i < stretchHandles.length; i++) {
Overlays.editOverlay(stretchHandles[i], { Overlays.editOverlay(stretchHandles[i], {
@ -2336,15 +2300,10 @@ SelectionDisplay = (function () {
mode = "UNKNOWN"; mode = "UNKNOWN";
// if something is selected, then reset the "original" properties for any potential next click+move operation // if something is selected, then reset the "original" properties for any potential next click+move operation
if (entitySelected) { if (SelectionManager.hasSelection()) {
if (showHandles) { if (showHandles) {
that.select(currentSelection, event); that.select(SelectionManager.selections[0], event);
} }
selectedEntityProperties = Entities.getEntityProperties(currentSelection);
selectedEntityPropertiesOriginalPosition = properties.position;
selectedEntityPropertiesOriginalDimensions = properties.dimensions;
} }
}; };

View file

@ -256,7 +256,7 @@ var toolBar = (function () {
if (activeButton === toolBar.clicked(clickedOverlay)) { if (activeButton === toolBar.clicked(clickedOverlay)) {
isActive = !isActive; isActive = !isActive;
if (!isActive) { if (!isActive) {
selectionDisplay.unselectAll(); selectionManager.clearSelections();
cameraManager.disable(); cameraManager.disable();
} else { } else {
cameraManager.enable(); cameraManager.enable();
@ -386,9 +386,7 @@ function isLocked(properties) {
} }
var entitySelected = false;
var selectedEntityID; var selectedEntityID;
var selectedEntityProperties;
var mouseLastPosition; var mouseLastPosition;
var orientation; var orientation;
var intersection; var intersection;
@ -408,13 +406,12 @@ function mousePressEvent(event) {
mouseLastPosition = { x: event.x, y: event.y }; mouseLastPosition = { x: event.x, y: event.y };
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
var entitySelected = false;
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)
|| cameraManager.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) { || cameraManager.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) {
// Event handled; do nothing. // Event handled; do nothing.
return; return;
} else { } else {
entitySelected = false;
selectionDisplay.unselectAll();
// If we aren't active and didn't click on an overlay: quit // If we aren't active and didn't click on an overlay: quit
if (!isActive) { if (!isActive) {
@ -426,6 +423,7 @@ function mousePressEvent(event) {
var foundIntersection = Entities.findRayIntersection(pickRay); var foundIntersection = Entities.findRayIntersection(pickRay);
if(!foundIntersection.accurate) { if(!foundIntersection.accurate) {
selectionManager.clearSelections();
return; return;
} }
var foundEntity = foundIntersection.entityID; var foundEntity = foundIntersection.entityID;
@ -434,6 +432,7 @@ function mousePressEvent(event) {
var identify = Entities.identifyEntity(foundEntity); var identify = Entities.identifyEntity(foundEntity);
if (!identify.isKnownID) { if (!identify.isKnownID) {
print("Unknown ID " + identify.id + " (update loop " + foundEntity.id + ")"); print("Unknown ID " + identify.id + " (update loop " + foundEntity.id + ")");
selectionManager.clearSelections();
return; return;
} }
foundEntity = identify; foundEntity = identify;
@ -474,7 +473,6 @@ function mousePressEvent(event) {
if (0 < x && sizeOK) { if (0 < x && sizeOK) {
entitySelected = true; entitySelected = true;
selectedEntityID = foundEntity; selectedEntityID = foundEntity;
selectedEntityProperties = properties;
orientation = MyAvatar.orientation; orientation = MyAvatar.orientation;
intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation)); intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation));
@ -483,29 +481,11 @@ function mousePressEvent(event) {
} }
selectionManager.addEntity(foundEntity); selectionManager.addEntity(foundEntity);
print("Model selected selectedEntityID:" + selectedEntityID.id); print("Model selected: " + foundEntity.id);
} }
} }
} }
if (entitySelected) { if (entitySelected) {
selectedEntityProperties.oldDimensions = selectedEntityProperties.dimensions;
selectedEntityProperties.oldPosition = {
x: selectedEntityProperties.position.x,
y: selectedEntityProperties.position.y,
z: selectedEntityProperties.position.z,
};
selectedEntityProperties.oldRotation = {
x: selectedEntityProperties.rotation.x,
y: selectedEntityProperties.rotation.y,
z: selectedEntityProperties.rotation.z,
w: selectedEntityProperties.rotation.w,
};
selectedEntityProperties.glowLevel = 0.0;
print("Clicked on " + selectedEntityID.id + " " + entitySelected);
tooltip.updateText(selectedEntityProperties);
tooltip.show(true);
selectionDisplay.select(selectedEntityID, event); selectionDisplay.select(selectedEntityID, event);
} }
} }
@ -554,7 +534,7 @@ function mouseReleaseEvent(event) {
if (!isActive) { if (!isActive) {
return; return;
} }
if (entitySelected) { if (selectionManager.hasSelection()) {
tooltip.show(false); tooltip.show(false);
} }
cameraManager.mouseReleaseEvent(event); cameraManager.mouseReleaseEvent(event);
@ -642,7 +622,7 @@ function handeMenuEvent(menuItem) {
allowLargeModels = Menu.isOptionChecked("Allow Select Large Models"); allowLargeModels = Menu.isOptionChecked("Allow Select Large Models");
} else if (menuItem == "Delete") { } else if (menuItem == "Delete") {
if (SelectionManager.hasSelection()) { if (SelectionManager.hasSelection()) {
print(" Delete Entity.... selectedEntityID="+ selectedEntityID); print(" Delete Entities");
SelectionManager.saveProperties(); SelectionManager.saveProperties();
var savedProperties = []; var savedProperties = [];
for (var i = 0; i < selectionManager.selections.length; i++) { for (var i = 0; i < selectionManager.selections.length; i++) {
@ -657,8 +637,6 @@ function handeMenuEvent(menuItem) {
} }
SelectionManager.clearSelections(); SelectionManager.clearSelections();
pushCommandForSelections([], savedProperties); pushCommandForSelections([], savedProperties);
selectionDisplay.unselect(selectedEntityID);
entitySelected = false;
} else { } else {
print(" Delete Entity.... not holding..."); print(" Delete Entity.... not holding...");
} }
@ -706,11 +684,7 @@ Controller.keyReleaseEvent.connect(function (event) {
} else if (event.text == "TAB") { } else if (event.text == "TAB") {
selectionDisplay.toggleSpaceMode(); selectionDisplay.toggleSpaceMode();
} else if (event.text == "f") { } else if (event.text == "f") {
if (entitySelected) { cameraManager.focus();
// Get latest properties
var properties = Entities.getEntityProperties(selectedEntityID);
cameraManager.focus(properties);
}
} else if (event.text == '[') { } else if (event.text == '[') {
if (isActive) { if (isActive) {
cameraManager.enable(); cameraManager.enable();