fix getEntityObject and tablet highlighting (Overlays.findOverlays)

This commit is contained in:
SamGondelman 2019-02-01 16:23:06 -08:00
parent 391cca787f
commit 4b406bf41c
5 changed files with 23 additions and 8 deletions

View file

@ -1955,6 +1955,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
return false;
});
EntityTree::setGetEntityObjectOperator([this](const QUuid& id) -> QObject* {
auto entities = getEntities();
if (auto entity = entities->renderableForEntityId(id)) {
return qobject_cast<QObject*>(entity.get());
}
return nullptr;
});
EntityTree::setTextSizeOperator([this](const QUuid& id, const QString& text) {
auto entities = getEntities();
if (auto entity = entities->renderableForEntityId(id)) {

View file

@ -1326,6 +1326,8 @@ QVector<QUuid> Overlays::findOverlays(const glm::vec3& center, float radius) {
auto entityTree = DependencyManager::get<EntityScriptingInterface>()->getEntityTree();
if (entityTree) {
unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::LOCAL_ENTITIES);
// For legacy reasons, this only finds visible objects
searchFilter = searchFilter | PickFilter::getBitMask(PickFilter::FlagBit::VISIBLE);
entityTree->withReadLock([&] {
entityTree->evalEntitiesInSphere(center, radius, PickFilter(searchFilter), result);
});

View file

@ -1017,14 +1017,7 @@ QString EntityScriptingInterface::getEntityType(const QUuid& entityID) {
}
QObject* EntityScriptingInterface::getEntityObject(const QUuid& id) {
QObject* toReturn { nullptr };
_entityTree->withReadLock([&] {
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(id);
if (entity) {
toReturn = qobject_cast<QObject*>(&(*entity));
}
});
return toReturn;
return EntityTree::getEntityObject(id);
}
bool EntityScriptingInterface::isLoaded(const QUuid& id) {

View file

@ -2957,6 +2957,7 @@ std::function<bool(const QUuid&, graphics::MaterialLayer, const std::string&)> E
std::function<bool(const QUuid&, graphics::MaterialPointer, const std::string&)> EntityTree::_removeMaterialFromEntityOperator = nullptr;
std::function<bool(const QUuid&, graphics::MaterialLayer, const std::string&)> EntityTree::_addMaterialToAvatarOperator = nullptr;
std::function<bool(const QUuid&, graphics::MaterialPointer, const std::string&)> EntityTree::_removeMaterialFromAvatarOperator = nullptr;
std::function<QObject*(const QUuid&)> EntityTree::_getEntityObjectOperator = nullptr;
std::function<QSizeF(const QUuid&, const QString&)> EntityTree::_textSizeOperator = nullptr;
bool EntityTree::addMaterialToEntity(const QUuid& entityID, graphics::MaterialLayer material, const std::string& parentMaterialName) {
@ -2987,6 +2988,13 @@ bool EntityTree::removeMaterialFromAvatar(const QUuid& avatarID, graphics::Mater
return false;
}
QObject* EntityTree::getEntityObject(const QUuid& id) {
if (_getEntityObjectOperator) {
return _getEntityObjectOperator(id);
}
return nullptr;
}
QSizeF EntityTree::textSize(const QUuid& id, const QString& text) {
if (_textSizeOperator) {
return _textSizeOperator(id, text);

View file

@ -272,6 +272,9 @@ public:
static bool addMaterialToAvatar(const QUuid& avatarID, graphics::MaterialLayer material, const std::string& parentMaterialName);
static bool removeMaterialFromAvatar(const QUuid& avatarID, graphics::MaterialPointer material, const std::string& parentMaterialName);
static void setGetEntityObjectOperator(std::function<QObject*(const QUuid&)> getEntityObjectOperator) { _getEntityObjectOperator = getEntityObjectOperator; }
static QObject* getEntityObject(const QUuid& id);
static void setTextSizeOperator(std::function<QSizeF(const QUuid&, const QString&)> textSizeOperator) { _textSizeOperator = textSizeOperator; }
static QSizeF textSize(const QUuid& id, const QString& text);
@ -387,6 +390,7 @@ private:
static std::function<bool(const QUuid&, graphics::MaterialPointer, const std::string&)> _removeMaterialFromEntityOperator;
static std::function<bool(const QUuid&, graphics::MaterialLayer, const std::string&)> _addMaterialToAvatarOperator;
static std::function<bool(const QUuid&, graphics::MaterialPointer, const std::string&)> _removeMaterialFromAvatarOperator;
static std::function<QObject*(const QUuid&)> _getEntityObjectOperator;
static std::function<QSizeF(const QUuid&, const QString&)> _textSizeOperator;
std::vector<int32_t> _staleProxies;