mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
Update editEntities to do accurate pick on mouse idle
This commit is contained in:
parent
67c3f9a3db
commit
dcb4d9f02d
1 changed files with 43 additions and 24 deletions
|
@ -527,8 +527,15 @@ function mousePressEvent(event) {
|
||||||
|
|
||||||
var highlightedEntityID = { isKnownID: false };
|
var highlightedEntityID = { isKnownID: false };
|
||||||
var mouseCapturedByTool = false;
|
var mouseCapturedByTool = false;
|
||||||
|
var lastMousePosition = null;
|
||||||
|
var idleMouseTimerId = null;
|
||||||
|
var IDLE_MOUSE_TIMEOUT = 200;
|
||||||
|
|
||||||
function mouseMoveEvent(event) {
|
function mouseMoveEvent(event) {
|
||||||
|
if (idleMouseTimerId) {
|
||||||
|
Script.clearTimeout(idleMouseTimerId);
|
||||||
|
}
|
||||||
|
|
||||||
mouseHasMovedSincePress = true;
|
mouseHasMovedSincePress = true;
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
|
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
|
||||||
|
@ -536,36 +543,48 @@ function mouseMoveEvent(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
lastMousePosition = { x: event.x, y: 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;
|
highlightEntityUnderCursor(lastMousePosition, false);
|
||||||
|
idleMouseTimerId = Script.setTimeout(handleIdleMouse, IDLE_MOUSE_TIMEOUT);
|
||||||
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 {
|
} else {
|
||||||
cameraManager.mouseMoveEvent(event);
|
cameraManager.mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleIdleMouse() {
|
||||||
|
idleMouseTimerId = null;
|
||||||
|
highlightEntityUnderCursor(lastMousePosition, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function highlightEntityUnderCursor(position, accurateRay) {
|
||||||
|
var pickRay = Camera.computePickRay(position.x, position.y);
|
||||||
|
var entityIntersection = Entities.findRayIntersection(pickRay, accurateRay === true);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
if (isActive && selectionManager.hasSelection()) {
|
if (isActive && selectionManager.hasSelection()) {
|
||||||
|
|
Loading…
Reference in a new issue