diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index db9f7757cf..4351ffd230 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3701,7 +3701,18 @@ void Application::setKeyboardFocusEntity(QUuid id) { void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { auto entityScriptingInterface = DependencyManager::get(); if (_keyboardFocusedItem.get() != entityItemID) { + // reset focused entity _keyboardFocusedItem.set(UNKNOWN_ENTITY_ID); + if (_keyboardFocusHighlight) { + _keyboardFocusHighlight->setVisible(false); + } + + // if invalid, return without expensive (locking) operations + if (entityItemID == UNKNOWN_ENTITY_ID) { + return; + } + + // if valid, query properties auto properties = entityScriptingInterface->getEntityProperties(entityItemID); if (!properties.getLocked() && properties.getVisible()) { auto entity = getEntities()->getTree()->findEntityByID(entityItemID); @@ -3712,6 +3723,8 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { } _keyboardFocusedItem.set(entityItemID); _lastAcceptedKeyPress = usecTimestampNow(); + + // create a focus if (_keyboardFocusHighlightID < 0 || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) { _keyboardFocusHighlight = std::make_shared(); _keyboardFocusHighlight->setAlpha(1.0f); @@ -3723,17 +3736,16 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { _keyboardFocusHighlight->setColorPulse(1.0); _keyboardFocusHighlight->setIgnoreRayIntersection(true); _keyboardFocusHighlight->setDrawInFront(false); + _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight); } + + // position the focus _keyboardFocusHighlight->setRotation(entity->getRotation()); _keyboardFocusHighlight->setPosition(entity->getPosition()); _keyboardFocusHighlight->setDimensions(entity->getDimensions() * 1.05f); _keyboardFocusHighlight->setVisible(true); - _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight); } } - if (_keyboardFocusedItem.get() == UNKNOWN_ENTITY_ID && _keyboardFocusHighlight) { - _keyboardFocusHighlight->setVisible(false); - } } } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index d30b69c5f8..9df23dad2c 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1778,7 +1778,7 @@ void AvatarData::setAvatarEntityData(const AvatarEntityMap& avatarEntityData) { AvatarEntityIDs AvatarData::getAndClearRecentlyDetachedIDs() { AvatarEntityIDs result; if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(const_cast(this), "getRecentlyDetachedIDs", Qt::BlockingQueuedConnection, + QMetaObject::invokeMethod(const_cast(this), "getAndClearRecentlyDetachedIDs", Qt::BlockingQueuedConnection, Q_RETURN_ARG(AvatarEntityIDs, result)); return result; }