added Entities.findbyName
Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -766,6 +766,36 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesByType(const QString entity · 765 unmodified lines | |||
| 766 | return result; | 766 | return result; |
| 767 | } | 767 | } |
| 768 | 768 | ||
| 769 | QVector<QUuid> EntityScriptingInterface::findEntitiesByName(const QString entityName, const glm::vec3& center, float radius, bool caseSensitiveSearch) const { | ||
| 770 | |||
| 771 | QVector<QUuid> result; | ||
| 772 | if (_entityTree) { | ||
| 773 | QVector<EntityItemPointer> entities; | ||
| 774 | _entityTree->withReadLock([&] { | ||
| 775 | _entityTree->findEntities(center, radius, entities); | ||
| 776 | }); | ||
| 777 | |||
| 778 | if (caseSensitiveSearch) { | ||
| 779 | foreach(EntityItemPointer entity, entities) { | ||
| 780 | if (entity->getName() == entityName) { | ||
| 781 | result << entity->getEntityItemID(); | ||
| 782 | } | ||
| 783 | } | ||
| 784 | |||
| 785 | } else { | ||
| 786 | QString entityNameLowerCase = entityName.toLower(); | ||
| 787 | |||
| 788 | foreach(EntityItemPointer entity, entities) { | ||
| 789 | QString entityItemLowerCase = entity->getName().toLower(); | ||
| 790 | if (entityItemLowerCase == entityNameLowerCase) { | ||
| 791 | result << entity->getEntityItemID(); | ||
| 792 | } | ||
| 793 | } | ||
| 794 | } | ||
| 795 | } | ||
| 796 | return result; | ||
| 797 | } | ||
| 798 | |||
| 769 | RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, | 799 | RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, |
| 770 | const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | 800 | const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { |
| 771 | QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); | 801 | QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); |