Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #include "EntityTree.h" |
| 22 | 22 | #include "LightEntityItem.h" |
| 23 | 23 | #include "ModelEntityItem.h" |
| 24 | +#include "QVariantGLM.h" | |
| 24 | 25 | #include "SimulationOwner.h" |
| 25 | 26 | #include "ZoneEntityItem.h" |
| 26 | 27 | |
| @@ -550,14 +551,6 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f · 523 unmodified lines | ||
| 550 | 551 | return result; |
| 551 | 552 | } |
| 552 | 553 | |
| 553 | −QVector<QUuid> EntityScriptingInterface::findEntitiesInView(const glm::vec3& center, float radius) const { | |
| 554 | − QVector<QUuid> result; | |
| 555 | − | |
| 556 | − // TODO | |
| 557 | − | |
| 558 | − return result; | |
| 559 | −} | |
| 560 | − | |
| 561 | 554 | QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { |
| 562 | 555 | QVector<QUuid> result; |
| 563 | 556 | if (_entityTree) { |
| @@ -574,6 +567,48 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn · 10 unmodified lines | ||
| 574 | 567 | return result; |
| 575 | 568 | } |
| 576 | 569 | |
| 570 | +QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frustum) const { | |
| 571 | + QVector<QUuid> result; | |
| 572 | + | |
| 573 | + const QString POSITION_PROPERTY = "position"; | |
| 574 | + bool positionOK = frustum.contains(POSITION_PROPERTY); | |
| 575 | + glm::vec3 position = positionOK ? qMapToGlmVec3(frustum[POSITION_PROPERTY]) : glm::vec3(); | |
| 576 | + | |
| 577 | + const QString ORIENTATION_PROPERTY = "orientation"; | |
| 578 | + bool orientationOK = frustum.contains(ORIENTATION_PROPERTY); | |
| 579 | + glm::quat orientation = orientationOK ? qMapToGlmQuat(frustum[ORIENTATION_PROPERTY]) : glm::quat(); | |
| 580 | + | |
| 581 | + const QString PROJECTION_PROPERTY = "projection"; | |
| 582 | + bool projectionOK = frustum.contains(PROJECTION_PROPERTY); | |
| 583 | + glm::mat4 projection = projectionOK ? qMapToGlmMat4(frustum[PROJECTION_PROPERTY]) : glm::mat4(); | |
| 584 | + | |
| 585 | + const QString CENTER_RADIUS_PROPERTY = "centerRadius"; | |
| 586 | + bool centerRadiusOK = frustum.contains(CENTER_RADIUS_PROPERTY); | |
| 587 | + float centerRadius = centerRadiusOK ? frustum[CENTER_RADIUS_PROPERTY].toFloat() : 0.0f; | |
| 588 | + | |
| 589 | + if (positionOK && orientationOK && projectionOK && centerRadiusOK) { | |
| 590 | + ViewFrustum viewFrustum; | |
| 591 | + viewFrustum.setPosition(position); | |
| 592 | + viewFrustum.setOrientation(orientation); | |
| 593 | + viewFrustum.setProjection(projection); | |
| 594 | + viewFrustum.setCenterRadius(centerRadius); | |
| 595 | + viewFrustum.calculate(); | |
| 596 | + | |
| 597 | + if (_entityTree) { | |
| 598 | + QVector<EntityItemPointer> entities; | |
| 599 | + _entityTree->withReadLock([&] { | |
| 600 | + _entityTree->findEntities(viewFrustum, entities); | |
| 601 | + }); | |
| 602 | + | |
| 603 | + foreach(EntityItemPointer entity, entities) { | |
| 604 | + result << entity->getEntityItemID(); | |
| 605 | + } | |
| 606 | + } | |
| 607 | + } | |
| 608 | + | |
| 609 | + return result; | |
| 610 | +} | |
| 611 | + | |
| 577 | 612 | RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, |
| 578 | 613 | const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard) { |
| 579 | 614 | |