From 0bd67d494d60623dce8438f11e3a862fa581cb37 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 2 Oct 2017 19:27:26 +1300 Subject: [PATCH] Fix UI sometimes turning off/on/off as hand enters entity --- scripts/shapes/modules/hand.js | 4 ++++ scripts/shapes/shapes.js | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/shapes/modules/hand.js b/scripts/shapes/modules/hand.js index 29ed6bfd96..73efed8017 100644 --- a/scripts/shapes/modules/hand.js +++ b/scripts/shapes/modules/hand.js @@ -204,6 +204,10 @@ Hand = function (side) { } if (entityID) { intersectionPosition = Entities.getEntityProperties(entityID, "position").position; + if (Vec3.distance(palmPosition, intersectionPosition) > NEAR_GRAB_RADIUS) { + intersectionPosition = Vec3.sum(palmPosition, + Vec3.multiply(NEAR_GRAB_RADIUS, Vec3.normalize(Vec3.subtract(intersectionPosition, palmPosition)))); + } } } diff --git a/scripts/shapes/shapes.js b/scripts/shapes/shapes.js index 573a9445e7..b4e822c233 100644 --- a/scripts/shapes/shapes.js +++ b/scripts/shapes/shapes.js @@ -930,7 +930,7 @@ // Hide UI if hand is intersecting entity and camera is outside entity, or if hand is intersecting stretch handle. if (side !== dominantHand) { showUI = !intersection.handIntersected || (intersection.entityID !== null - && !isCameraOutsideEntity(intersection.entityID, hand.palmPosition())); + && !isCameraOutsideEntity(intersection.entityID, intersection.intersection)); if (showUI !== isUIVisible) { isUIVisible = !isUIVisible; ui.setVisible(isUIVisible); @@ -952,7 +952,8 @@ && otherEditor.isHandle(intersection.overlayID)) && !(intersection.entityID && (intersection.editableEntity || toolSelected === TOOL_PICK_COLOR) && (wasTriggerClicked || !isTriggerClicked) && !isAutoGrab - && (isTriggerPressed || isCameraOutsideEntity(intersection.entityID, hand.palmPosition()))) + && (isTriggerPressed + || isCameraOutsideEntity(intersection.entityID, intersection.intersection))) && !(intersection.entityID && (intersection.editableEntity || toolSelected === TOOL_PICK_COLOR) && (!wasTriggerClicked || isAutoGrab) && isTriggerClicked)) { // No transition. @@ -969,7 +970,7 @@ setState(EDITOR_HANDLE_SCALING); } else if (intersection.entityID && (intersection.editableEntity || toolSelected === TOOL_PICK_COLOR) && (wasTriggerClicked || !isTriggerClicked) && !isAutoGrab - && (isTriggerPressed || isCameraOutsideEntity(intersection.entityID, hand.palmPosition()))) { + && (isTriggerPressed || isCameraOutsideEntity(intersection.entityID, intersection.intersection))) { intersectedEntityID = intersection.entityID; rootEntityID = Entities.rootOf(intersectedEntityID); setState(EDITOR_HIGHLIGHTING); @@ -1020,7 +1021,7 @@ case EDITOR_HIGHLIGHTING: if (hand.valid() && intersection.entityID && (intersection.editableEntity || toolSelected === TOOL_PICK_COLOR) - && (isTriggerPressed || isCameraOutsideEntity(intersection.entityID, hand.palmPosition())) + && (isTriggerPressed || isCameraOutsideEntity(intersection.entityID, intersection.intersection)) && !(!wasTriggerClicked && isTriggerClicked && (!otherEditor.isEditing(rootEntityID) || toolSelected !== TOOL_SCALE)) && !(!wasTriggerClicked && isTriggerClicked && intersection.overlayID @@ -1100,8 +1101,9 @@ } else { setState(EDITOR_GRABBING); } + } else if (!intersection.entityID || !intersection.editableEntity - || (!isTriggerPressed && !isCameraOutsideEntity(intersection.entityID, hand.palmPosition()))) { + || (!isTriggerPressed && !isCameraOutsideEntity(intersection.entityID, intersection.intersection))) { setState(EDITOR_SEARCHING); } else { log(side, "ERROR: Editor: Unexpected condition B in EDITOR_HIGHLIGHTING!");