mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 03:56:11 +02:00
Move entity selection to click event and add ability to deselect
This commit is contained in:
parent
167ab05de4
commit
77365ec282
2 changed files with 80 additions and 61 deletions
|
@ -89,11 +89,19 @@ SelectionManager = (function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
that.addEntity = function(entityID) {
|
that.addEntity = function(entityID, toggleSelection) {
|
||||||
if (entityID.isKnownID) {
|
if (entityID.isKnownID) {
|
||||||
var idx = that.selections.indexOf(entityID);
|
var idx = -1;
|
||||||
|
for (var i = 0; i < that.selections.length; i++) {
|
||||||
|
if (entityID.id == that.selections[i].id) {
|
||||||
|
idx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (idx == -1) {
|
if (idx == -1) {
|
||||||
that.selections.push(entityID);
|
that.selections.push(entityID);
|
||||||
|
} else if (toggleSelection) {
|
||||||
|
that.selections.splice(idx, 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var idx = that.pendingSelections.indexOf(entityID);
|
var idx = that.pendingSelections.indexOf(entityID);
|
||||||
|
|
|
@ -485,20 +485,93 @@ function findClickedEntity(event) {
|
||||||
return { pickRay: pickRay, entityID: foundEntity };
|
return { pickRay: pickRay, entityID: foundEntity };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mouseHasMovedSincePress = false;
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
|
mouseHasMovedSincePress = false;
|
||||||
|
|
||||||
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) {
|
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
var entitySelected = false;
|
|
||||||
if (cameraManager.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) {
|
if (cameraManager.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) {
|
||||||
// Event handled; do nothing.
|
// Event handled; do nothing.
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
} else if (Menu.isOptionChecked(MENU_INSPECT_TOOL_ENABLED)) {
|
||||||
|
var result = findClickedEntity(event);
|
||||||
|
if (event.isRightButton) {
|
||||||
|
if (result !== null) {
|
||||||
|
var currentProperties = Entities.getEntityProperties(result.entityID);
|
||||||
|
cameraManager.enable();
|
||||||
|
cameraManager.focus(currentProperties.position, null, Menu.isOptionChecked(MENU_EASE_ON_FOCUS));
|
||||||
|
cameraManager.mousePressEvent(event);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
cameraManager.mousePressEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var highlightedEntityID = { isKnownID: false };
|
||||||
|
|
||||||
|
function mouseMoveEvent(event) {
|
||||||
|
mouseHasMovedSincePress = true;
|
||||||
|
if (isActive) {
|
||||||
|
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
|
||||||
|
if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cameraManager.mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function mouseReleaseEvent(event) {
|
||||||
|
if (isActive && selectionManager.hasSelection()) {
|
||||||
|
tooltip.show(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraManager.mouseReleaseEvent(event);
|
||||||
|
|
||||||
|
if (!mouseHasMovedSincePress) {
|
||||||
|
mouseClickEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mouseClickEvent(event) {
|
||||||
var result = findClickedEntity(event);
|
var result = findClickedEntity(event);
|
||||||
if (result === null) {
|
if (result === null) {
|
||||||
|
if (!event.isShifted) {
|
||||||
selectionManager.clearSelections();
|
selectionManager.clearSelections();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var pickRay = result.pickRay;
|
var pickRay = result.pickRay;
|
||||||
|
@ -545,76 +618,14 @@ function mousePressEvent(event) {
|
||||||
if (!event.isShifted) {
|
if (!event.isShifted) {
|
||||||
selectionManager.clearSelections();
|
selectionManager.clearSelections();
|
||||||
}
|
}
|
||||||
selectionManager.addEntity(foundEntity);
|
|
||||||
|
var toggle = event.isShifted;
|
||||||
|
selectionManager.addEntity(foundEntity, toggle);
|
||||||
|
|
||||||
print("Model selected: " + foundEntity.id);
|
print("Model selected: " + foundEntity.id);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (entitySelected) {
|
|
||||||
selectionDisplay.select(selectedEntityID, event);
|
selectionDisplay.select(selectedEntityID, event);
|
||||||
}
|
}
|
||||||
} else if (Menu.isOptionChecked(MENU_INSPECT_TOOL_ENABLED)) {
|
|
||||||
var result = findClickedEntity(event);
|
|
||||||
if (event.isRightButton) {
|
|
||||||
if (result !== null) {
|
|
||||||
var currentProperties = Entities.getEntityProperties(result.entityID);
|
|
||||||
cameraManager.enable();
|
|
||||||
cameraManager.focus(currentProperties.position, null, Menu.isOptionChecked(MENU_EASE_ON_FOCUS));
|
|
||||||
cameraManager.mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cameraManager.mousePressEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var highlightedEntityID = { isKnownID: false };
|
|
||||||
|
|
||||||
function mouseMoveEvent(event) {
|
|
||||||
if (isActive) {
|
|
||||||
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
|
|
||||||
if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cameraManager.mouseMoveEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
|
||||||
if (isActive && selectionManager.hasSelection()) {
|
|
||||||
tooltip.show(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraManager.mouseReleaseEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
|
|
Loading…
Reference in a new issue