Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 27 files). Show all
Unified · Split
| @@ -1085,10 +1085,13 @@ QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float · 1084 unmodified lines | ||
| 1085 | 1085 | |
| 1086 | 1086 | EntityItemID result; |
| 1087 | 1087 | if (_entityTree) { |
| 1088 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1088 | + EntityItemPointer closestEntity; | |
| 1089 | 1089 | _entityTree->withReadLock([&] { |
| 1090 | − result = _entityTree->evalClosestEntity(center, radius, PickFilter(searchFilter)); | |
| 1090 | + closestEntity = _entityTree->findClosestEntity(center, radius); | |
| 1091 | 1091 | }); |
| 1092 | + if (closestEntity) { | |
| 1093 | + result = closestEntity->getEntityItemID(); | |
| 1094 | + } | |
| 1092 | 1095 | } |
| 1093 | 1096 | return result; |
| 1094 | 1097 | } |
| @@ -1107,10 +1110,14 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f · 12 unmodified lines | ||
| 1107 | 1110 | |
| 1108 | 1111 | QVector<QUuid> result; |
| 1109 | 1112 | if (_entityTree) { |
| 1110 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1113 | + QVector<EntityItemPointer> entities; | |
| 1111 | 1114 | _entityTree->withReadLock([&] { |
| 1112 | − _entityTree->evalEntitiesInSphere(center, radius, PickFilter(searchFilter), result); | |
| 1115 | + _entityTree->findEntities(center, radius, entities); | |
| 1113 | 1116 | }); |
| 1117 | + | |
| 1118 | + foreach (EntityItemPointer entity, entities) { | |
| 1119 | + result << entity->getEntityItemID(); | |
| 1120 | + } | |
| 1114 | 1121 | } |
| 1115 | 1122 | return result; |
| 1116 | 1123 | } |
| @@ -1120,11 +1127,15 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn · 3 unmodified lines | ||
| 1120 | 1127 | |
| 1121 | 1128 | QVector<QUuid> result; |
| 1122 | 1129 | if (_entityTree) { |
| 1123 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1130 | + QVector<EntityItemPointer> entities; | |
| 1124 | 1131 | _entityTree->withReadLock([&] { |
| 1125 | 1132 | AABox box(corner, dimensions); |
| 1126 | − _entityTree->evalEntitiesInBox(box, PickFilter(searchFilter), result); | |
| 1133 | + _entityTree->findEntities(box, entities); | |
| 1127 | 1134 | }); |
| 1135 | + | |
| 1136 | + foreach (EntityItemPointer entity, entities) { | |
| 1137 | + result << entity->getEntityItemID(); | |
| 1138 | + } | |
| 1128 | 1139 | } |
| 1129 | 1140 | return result; |
| 1130 | 1141 | } |
| @@ -1159,10 +1170,14 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frust · 28 unmodified lines | ||
| 1159 | 1170 | viewFrustum.calculate(); |
| 1160 | 1171 | |
| 1161 | 1172 | if (_entityTree) { |
| 1162 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1173 | + QVector<EntityItemPointer> entities; | |
| 1163 | 1174 | _entityTree->withReadLock([&] { |
| 1164 | − _entityTree->evalEntitiesInFrustum(viewFrustum, PickFilter(searchFilter), result); | |
| 1175 | + _entityTree->findEntities(viewFrustum, entities); | |
| 1165 | 1176 | }); |
| 1177 | + | |
| 1178 | + foreach(EntityItemPointer entity, entities) { | |
| 1179 | + result << entity->getEntityItemID(); | |
| 1180 | + } | |
| 1166 | 1181 | } |
| 1167 | 1182 | } |
| 1168 | 1183 | |
| @@ -1174,64 +1189,86 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesByType(const QString entity · 5 unmodified lines | ||
| 1174 | 1189 | |
| 1175 | 1190 | QVector<QUuid> result; |
| 1176 | 1191 | if (_entityTree) { |
| 1177 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1192 | + QVector<EntityItemPointer> entities; | |
| 1178 | 1193 | _entityTree->withReadLock([&] { |
| 1179 | − _entityTree->evalEntitiesInSphereWithType(center, radius, type, PickFilter(searchFilter), result); | |
| 1194 | + _entityTree->findEntities(center, radius, entities); | |
| 1180 | 1195 | }); |
| 1196 | + | |
| 1197 | + foreach(EntityItemPointer entity, entities) { | |
| 1198 | + if (entity->getType() == type) { | |
| 1199 | + result << entity->getEntityItemID().toString(); | |
| 1200 | + } | |
| 1201 | + } | |
| 1181 | 1202 | } |
| 1182 | 1203 | return result; |
| 1183 | 1204 | } |
| 1184 | 1205 | |
| 1185 | 1206 | QVector<QUuid> EntityScriptingInterface::findEntitiesByName(const QString entityName, const glm::vec3& center, float radius, bool caseSensitiveSearch) const { |
| 1207 | + | |
| 1186 | 1208 | QVector<QUuid> result; |
| 1187 | 1209 | if (_entityTree) { |
| 1210 | + QVector<EntityItemPointer> entities; | |
| 1188 | 1211 | _entityTree->withReadLock([&] { |
| 1189 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1190 | − _entityTree->evalEntitiesInSphereWithName(center, radius, entityName, caseSensitiveSearch, PickFilter(searchFilter), result); | |
| 1212 | + _entityTree->findEntities(center, radius, entities); | |
| 1191 | 1213 | }); |
| 1214 | + | |
| 1215 | + if (caseSensitiveSearch) { | |
| 1216 | + foreach(EntityItemPointer entity, entities) { | |
| 1217 | + if (entity->getName() == entityName) { | |
| 1218 | + result << entity->getEntityItemID(); | |
| 1219 | + } | |
| 1220 | + } | |
| 1221 | + | |
| 1222 | + } else { | |
| 1223 | + QString entityNameLowerCase = entityName.toLower(); | |
| 1224 | + | |
| 1225 | + foreach(EntityItemPointer entity, entities) { | |
| 1226 | + QString entityItemLowerCase = entity->getName().toLower(); | |
| 1227 | + if (entityItemLowerCase == entityNameLowerCase) { | |
| 1228 | + result << entity->getEntityItemID(); | |
| 1229 | + } | |
| 1230 | + } | |
| 1231 | + } | |
| 1192 | 1232 | } |
| 1193 | 1233 | return result; |
| 1194 | 1234 | } |
| 1195 | 1235 | |
| 1196 | −RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, | |
| 1197 | − const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) const { | |
| 1198 | − PROFILE_RANGE(script_entities, __FUNCTION__); | |
| 1236 | +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, | |
| 1237 | + const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | |
| 1199 | 1238 | QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); |
| 1200 | 1239 | QVector<EntityItemID> entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard); |
| 1201 | 1240 | |
| 1202 | − unsigned int searchFilter = PickFilter::getBitMask(PickFilter::FlagBit::DOMAIN_ENTITIES) | PickFilter::getBitMask(PickFilter::FlagBit::AVATAR_ENTITIES); | |
| 1203 | − | |
| 1204 | − if (!precisionPicking) { | |
| 1205 | − searchFilter = searchFilter | PickFilter::getBitMask(PickFilter::FlagBit::COARSE); | |
| 1206 | − } | |
| 1207 | − | |
| 1208 | − if (visibleOnly) { | |
| 1209 | − searchFilter = searchFilter | PickFilter::getBitMask(PickFilter::FlagBit::VISIBLE); | |
| 1210 | − } | |
| 1241 | + return findRayIntersectionVector(ray, precisionPicking, entitiesToInclude, entitiesToDiscard, visibleOnly, collidableOnly); | |
| 1242 | +} | |
| 1211 | 1243 | |
| 1212 | − if (collidableOnly) { | |
| 1213 | − searchFilter = searchFilter | PickFilter::getBitMask(PickFilter::FlagBit::COLLIDABLE); | |
| 1214 | − } | |
| 1244 | +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionVector(const PickRay& ray, bool precisionPicking, | |
| 1245 | + const QVector<EntityItemID>& entityIdsToInclude, const QVector<EntityItemID>& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | |
| 1246 | + PROFILE_RANGE(script_entities, __FUNCTION__); | |
| 1215 | 1247 | |
| 1216 | − return evalRayIntersectionWorker(ray, Octree::Lock, PickFilter(searchFilter), entitiesToInclude, entitiesToDiscard); | |
| 1248 | + return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly); | |
| 1217 | 1249 | } |
| 1218 | 1250 | |
| 1219 | −RayToEntityIntersectionResult EntityScriptingInterface::evalRayIntersectionVector(const PickRay& ray, PickFilter searchFilter, | |
| 1220 | − const QVector<EntityItemID>& entityIdsToInclude, const QVector<EntityItemID>& entityIdsToDiscard) { | |
| 1221 | − PROFILE_RANGE(script_entities, __FUNCTION__); | |
| 1251 | +// FIXME - we should remove this API and encourage all users to use findRayIntersection() instead. We've changed | |
| 1252 | +// findRayIntersection() to be blocking because it never makes sense for a script to get back a non-answer | |
| 1253 | +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking, | |
| 1254 | + const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard) { | |
| 1222 | 1255 | |
| 1223 | − return evalRayIntersectionWorker(ray, Octree::Lock, searchFilter, entityIdsToInclude, entityIdsToDiscard); | |
| 1256 | + qWarning() << "Entities.findRayIntersectionBlocking() is obsolete, use Entities.findRayIntersection() instead."; | |
| 1257 | + const QVector<EntityItemID>& entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); | |
| 1258 | + const QVector<EntityItemID> entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard); | |
| 1259 | + return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entitiesToInclude, entitiesToDiscard); | |
| 1224 | 1260 | } |
| 1225 | 1261 | |
| 1226 | −RayToEntityIntersectionResult EntityScriptingInterface::evalRayIntersectionWorker(const PickRay& ray, | |
| 1227 | − Octree::lockType lockType, PickFilter searchFilter, const QVector<EntityItemID>& entityIdsToInclude, | |
| 1228 | − const QVector<EntityItemID>& entityIdsToDiscard) const { | |
| 1262 | +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, | |
| 1263 | + Octree::lockType lockType, bool precisionPicking, const QVector<EntityItemID>& entityIdsToInclude, | |
| 1264 | + const QVector<EntityItemID>& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | |
| 1265 | + | |
| 1229 | 1266 | |
| 1230 | 1267 | RayToEntityIntersectionResult result; |
| 1231 | 1268 | if (_entityTree) { |
| 1232 | 1269 | OctreeElementPointer element; |
| 1233 | − result.entityID = _entityTree->evalRayIntersection(ray.origin, ray.direction, | |
| 1234 | − entityIdsToInclude, entityIdsToDiscard, searchFilter, | |
| 1270 | + result.entityID = _entityTree->findRayIntersection(ray.origin, ray.direction, | |
| 1271 | + entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly, precisionPicking, | |
| 1235 | 1272 | element, result.distance, result.face, result.surfaceNormal, |
| 1236 | 1273 | result.extraInfo, lockType, &result.accurate); |
| 1237 | 1274 | result.intersects = !result.entityID.isNull(); |
| @@ -1242,22 +1279,23 @@ RayToEntityIntersectionResult EntityScriptingInterface::evalRayIntersectionWorke · 4 unmodified lines | ||
| 1242 | 1279 | return result; |
| 1243 | 1280 | } |
| 1244 | 1281 | |
| 1245 | −ParabolaToEntityIntersectionResult EntityScriptingInterface::evalParabolaIntersectionVector(const PickParabola& parabola, PickFilter searchFilter, | |
| 1246 | − const QVector<EntityItemID>& entityIdsToInclude, const QVector<EntityItemID>& entityIdsToDiscard) { | |
| 1282 | +ParabolaToEntityIntersectionResult EntityScriptingInterface::findParabolaIntersectionVector(const PickParabola& parabola, bool precisionPicking, | |
| 1283 | + const QVector<EntityItemID>& entityIdsToInclude, const QVector<EntityItemID>& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | |
| 1247 | 1284 | PROFILE_RANGE(script_entities, __FUNCTION__); |
| 1248 | 1285 | |
| 1249 | − return evalParabolaIntersectionWorker(parabola, Octree::Lock, searchFilter, entityIdsToInclude, entityIdsToDiscard); | |
| 1286 | + return findParabolaIntersectionWorker(parabola, Octree::Lock, precisionPicking, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly); | |
| 1250 | 1287 | } |
| 1251 | 1288 | |
| 1252 | −ParabolaToEntityIntersectionResult EntityScriptingInterface::evalParabolaIntersectionWorker(const PickParabola& parabola, | |
| 1253 | − Octree::lockType lockType, PickFilter searchFilter, const QVector<EntityItemID>& entityIdsToInclude, | |
| 1254 | − const QVector<EntityItemID>& entityIdsToDiscard) const { | |
| 1289 | +ParabolaToEntityIntersectionResult EntityScriptingInterface::findParabolaIntersectionWorker(const PickParabola& parabola, | |
| 1290 | + Octree::lockType lockType, bool precisionPicking, const QVector<EntityItemID>& entityIdsToInclude, | |
| 1291 | + const QVector<EntityItemID>& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | |
| 1292 | + | |
| 1255 | 1293 | |
| 1256 | 1294 | ParabolaToEntityIntersectionResult result; |
| 1257 | 1295 | if (_entityTree) { |
| 1258 | 1296 | OctreeElementPointer element; |
| 1259 | − result.entityID = _entityTree->evalParabolaIntersection(parabola, | |
| 1260 | − entityIdsToInclude, entityIdsToDiscard, searchFilter, | |
| 1297 | + result.entityID = _entityTree->findParabolaIntersection(parabola, | |
| 1298 | + entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly, precisionPicking, | |
| 1261 | 1299 | element, result.intersection, result.distance, result.parabolicDistance, result.face, result.surfaceNormal, |
| 1262 | 1300 | result.extraInfo, lockType, &result.accurate); |
| 1263 | 1301 | result.intersects = !result.entityID.isNull(); |