From 473212e5b72d577871889bb4b2f394195833fbd1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 17 Dec 2015 14:29:41 -0800 Subject: [PATCH] try to be more coherent about queryAABox meaning --- libraries/entities/src/EntityItem.cpp | 16 +++++++---- libraries/entities/src/EntityItem.h | 6 ++-- .../entities/src/EntityScriptingInterface.cpp | 11 ++++++++ libraries/entities/src/EntityTree.cpp | 3 ++ libraries/physics/src/EntityMotionState.cpp | 11 ++++++++ libraries/shared/src/SpatiallyNestable.cpp | 28 +++++++++++++++---- libraries/shared/src/SpatiallyNestable.h | 9 ++++-- 7 files changed, 68 insertions(+), 16 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index bc91b46f5b..89c5d28f99 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1177,7 +1177,7 @@ void EntityItem::setDimensions(const glm::vec3& value) { /// The maximum bounding cube for the entity, independent of it's rotation. /// This accounts for the registration point (upon which rotation occurs around). /// -const AACube& EntityItem::getMaximumAACube(bool& success) const { +AACube EntityItem::getMaximumAACube(bool& success) const { if (_recalcMaxAACube) { // * we know that the position is the center of rotation glm::vec3 centerOfRotation = getPosition(success); // also where _registration point is @@ -1207,7 +1207,7 @@ const AACube& EntityItem::getMaximumAACube(bool& success) const { /// The minimum bounding cube for the entity accounting for it's rotation. /// This accounts for the registration point (upon which rotation occurs around). /// -const AACube& EntityItem::getMinimumAACube(bool& success) const { +AACube EntityItem::getMinimumAACube(bool& success) const { if (_recalcMinAACube) { // _position represents the position of the registration point. glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint; @@ -1236,7 +1236,7 @@ const AACube& EntityItem::getMinimumAACube(bool& success) const { return _minAACube; } -const AABox& EntityItem::getAABox(bool& success) const { +AABox EntityItem::getAABox(bool& success) const { if (_recalcAABox) { // _position represents the position of the registration point. glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint; @@ -1261,11 +1261,17 @@ const AABox& EntityItem::getAABox(bool& success) const { } AACube EntityItem::getQueryAACube(bool& success) const { - AACube result = getMaximumAACube(success); + AACube result = SpatiallyNestable::getQueryAACube(success); if (success) { return result; } - return SpatiallyNestable::getQueryAACube(success); + // this is for when we've loaded an older json file that didn't have queryAACube properties. + result = getMaximumAACube(success); + if (success) { + _queryAACube = result; + _queryAACubeSet = true; + } + return result; } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 5877b9acbd..06434a3ea4 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -231,9 +231,9 @@ public: quint64 getExpiry() const; // position, size, and bounds related helpers - const AACube& getMaximumAACube(bool& success) const; - const AACube& getMinimumAACube(bool& success) const; - const AABox& getAABox(bool& success) const; /// axis aligned bounding box in world-frame (meters) + virtual AACube getMaximumAACube(bool& success) const override; + AACube getMinimumAACube(bool& success) const; + AABox getAABox(bool& success) const; /// axis aligned bounding box in world-frame (meters) using SpatiallyNestable::getQueryAACube; virtual AACube getQueryAACube(bool& success) const override; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 05fd481761..9d5600e615 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -279,6 +279,17 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& } entity->setLastBroadcast(usecTimestampNow()); } + + // if we've moved an entity with children, check/update the queryAACube of all descendents and tell the server + // if they've changed. + // TODO -- ancestors of this entity may also need to expand their queryAACubes. + entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { + if (descendant->setPuffedQueryAACube()) { + EntityItemProperties newQueryCubeProperties; + newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); + queueEntityMessage(PacketType::EntityEdit, descendant->getID(), newQueryCubeProperties); + } + }); }); queueEntityMessage(PacketType::EntityEdit, entityID, properties); return id; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index cb787607a8..b0a2f73b6c 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -89,6 +89,9 @@ void EntityTree::postAddEntity(EntityItemPointer entity) { _isDirty = true; maybeNotifyNewCollisionSoundURL("", entity->getCollisionSoundURL()); emit addingEntity(entity->getEntityItemID()); + + // find and hook up any entities with this entity as a (previously) missing parent + fixupMissingParents(); } bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) { diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 2e23c4ebd8..0e80a28b0a 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -507,6 +507,17 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q entityPacketSender->queueEditEntityMessage(PacketType::EntityEdit, id, properties); _entity->setLastBroadcast(usecTimestampNow()); + // if we've moved an entity with children, check/update the queryAACube of all descendents and tell the server + // if they've changed. + // TODO -- ancestors of this entity may also need to expand their queryAACubes. + _entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { + if (descendant->setPuffedQueryAACube()) { + EntityItemProperties newQueryCubeProperties; + newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); + entityPacketSender->queueEditEntityMessage(PacketType::EntityEdit, descendant->getID(), newQueryCubeProperties); + } + }); + _lastStep = step; } diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index c056173464..43632825be 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -552,11 +552,33 @@ void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) { _queryAACubeSet = true; } +AACube SpatiallyNestable::getMaximumAACube(bool& success) const { + return AACube(getPosition(success) - glm::vec3(0.5f), 1.0f); // XXX +} + +bool SpatiallyNestable::setPuffedQueryAACube() { + bool success; + AACube currentAACube = getMaximumAACube(success); + if (!success) { + qDebug() << "can't getMaximumAACube for" << getID(); + return false; + } + if (_queryAACubeSet && _queryAACube.contains(currentAACube)) { + return false; + } + + // make an AACube with edges twice as long and centered on the object + _queryAACube = AACube(currentAACube.getCorner() - glm::vec3(currentAACube.getScale()), currentAACube.getScale() * 2.0f); + _queryAACubeSet = true; + return true; +} + AACube SpatiallyNestable::getQueryAACube(bool& success) const { if (_queryAACubeSet) { success = true; return _queryAACube; } + success = false; return AACube(getPosition(success) - glm::vec3(0.5f), 1.0f); // XXX } @@ -564,11 +586,7 @@ AACube SpatiallyNestable::getQueryAACube() const { bool success; auto result = getQueryAACube(success); if (!success) { - if (_queryAACubeSet) { - result = _queryAACube; - } else { - qDebug() << "getQueryAACube failed:" << getID(); - } + qDebug() << "getQueryAACube failed for" << getID(); } return result; } diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 63b2dc194f..e5540eb79c 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -68,6 +68,9 @@ public: virtual void setOrientation(const glm::quat& orientation, bool& success); virtual void setOrientation(const glm::quat& orientation); + virtual AACube getMaximumAACube(bool& success) const; + virtual bool setPuffedQueryAACube(); + virtual void setQueryAACube(const AACube& queryAACube); virtual AACube getQueryAACube(bool& success) const; virtual AACube getQueryAACube() const; @@ -106,6 +109,9 @@ public: void markAncestorMissing(bool value) { _missingAncestor = value; } bool getAncestorMissing() { return _missingAncestor; } + void forEachChild(std::function actor); + void forEachDescendant(std::function actor); + protected: const NestableType _nestableType; // EntityItem or an AvatarData QUuid _id; @@ -123,9 +129,6 @@ protected: virtual void locationChanged(); // called when a this object's location has changed virtual void dimensionsChanged() {} // called when a this object's dimensions have changed - void forEachChild(std::function actor); - void forEachDescendant(std::function actor); - // _queryAACube is used to decide where something lives in the octree mutable AACube _queryAACube; mutable bool _queryAACubeSet { false };