diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index cccc13711d..3189ad3c77 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -587,7 +587,7 @@ void MyAvatar::simulate(float deltaTime) { MovingEntitiesOperator moveOperator; forEachDescendant([&](SpatiallyNestablePointer object) { // if the queryBox has changed, tell the entity-server - if (object->getNestableType() == NestableType::Entity && object->checkAndMaybeUpdateQueryAACube()) { + if (object->getNestableType() == NestableType::Entity && object->updateQueryAACube()) { EntityItemPointer entity = std::static_pointer_cast(object); bool success; AACube newCube = entity->getQueryAACube(success); diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 3328076911..047217b6aa 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -69,8 +69,8 @@ ParticleEffectEntityRenderer::ParticleEffectEntityRenderer(const EntityItemPoint } bool ParticleEffectEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - entity->checkAndMaybeUpdateQueryAACube(); - + entity->updateQueryAACube(); + if (_emitting != entity->getIsEmitting()) { return true; } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 9e48876cfb..421efac687 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1392,8 +1392,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(lastEditedBy, setLastEditedBy); - AACube saveQueryAACube = _queryAACube; - if (checkAndMaybeUpdateQueryAACube() && saveQueryAACube != _queryAACube) { + if (updateQueryAACube()) { somethingChanged = true; } @@ -1557,6 +1556,9 @@ AACube EntityItem::getQueryAACube(bool& success) const { return result; } +bool EntityItem::shouldPuffQueryAACube() const { + return hasActions() || isChildOfMyAvatar(); +} // NOTE: This should only be used in cases of old bitstreams which only contain radius data // 0,0,0 --> maxDimension,maxDimension,maxDimension diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 01a4f67b2c..764ff34f99 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -240,6 +240,7 @@ public: using SpatiallyNestable::getQueryAACube; virtual AACube getQueryAACube(bool& success) const override; + virtual bool shouldPuffQueryAACube() const override; QString getScript() const; void setScript(const QString& value); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index f5117dddc0..66bb24825f 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -457,7 +457,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& // if they've changed. entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { if (descendant->getNestableType() == NestableType::Entity) { - if (descendant->checkAndMaybeUpdateQueryAACube()) { + if (descendant->updateQueryAACube()) { EntityItemPointer entityDescendant = std::static_pointer_cast(descendant); EntityItemProperties newQueryCubeProperties; newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); @@ -1792,4 +1792,4 @@ QString EntityScriptingInterface::computeCertificateID(const QUuid& entityID) { } return result; } -#endif \ No newline at end of file +#endif diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d16aeaa6e1..e4de39a799 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -1804,7 +1804,7 @@ QVector EntityTree::sendEntities(EntityEditPacketSender* packetSen addToNeedsParentFixupList(entity); } entity->forceQueryAACubeUpdate(); - entity->checkAndMaybeUpdateQueryAACube(); + entity->updateQueryAACube(); moveOperator.addEntityToMoveList(entity, entity->getQueryAACube()); i++; } else { diff --git a/libraries/entities/src/SimpleEntitySimulation.cpp b/libraries/entities/src/SimpleEntitySimulation.cpp index d41b22137e..3203c2968c 100644 --- a/libraries/entities/src/SimpleEntitySimulation.cpp +++ b/libraries/entities/src/SimpleEntitySimulation.cpp @@ -136,7 +136,7 @@ void SimpleEntitySimulation::sortEntitiesThatMoved() { SetOfEntities::iterator itemItr = _entitiesToSort.begin(); while (itemItr != _entitiesToSort.end()) { EntityItemPointer entity = *itemItr; - entity->checkAndMaybeUpdateQueryAACube(); + entity->updateQueryAACube(); ++itemItr; } EntitySimulation::sortEntitiesThatMoved(); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index df46f7ada7..6884482074 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -581,7 +581,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ } if (properties.transformChanged()) { - if (_entity->checkAndMaybeUpdateQueryAACube(true)) { + if (_entity->updateQueryAACube()) { // due to parenting, the server may not know where something is in world-space, so include the bounding cube. properties.setQueryAACube(_entity->getQueryAACube()); } @@ -648,7 +648,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ _entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { if (descendant->getNestableType() == NestableType::Entity) { EntityItemPointer entityDescendant = std::static_pointer_cast(descendant); - if (descendant->checkAndMaybeUpdateQueryAACube()) { + if (descendant->updateQueryAACube()) { EntityItemProperties newQueryCubeProperties; newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); newQueryCubeProperties.setLastEdited(properties.getLastEdited()); diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 58456f7e9a..baa289095d 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -963,37 +963,39 @@ AACube SpatiallyNestable::getMaximumAACube(bool& success) const { const float PARENTED_EXPANSION_FACTOR = 3.0f; -bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube(bool forcePuffed) { - bool updated = false; - bool success = false; +bool SpatiallyNestable::updateQueryAACube() { + if (!queryAACubeNeedsUpdate()) { + return false; + } + + bool success; AACube maxAACube = getMaximumAACube(success); if (success) { - // maybe update _queryAACube - if (!_queryAACubeSet || !_queryAACube.contains(maxAACube)) { - if (forcePuffed || _parentJointIndex != INVALID_JOINT_INDEX || _children.size() > 0 ) { - // make an expanded AACube centered on the object - float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale(); - _queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale); - } else { - _queryAACube = maxAACube; - } - updated = true; - - forEachDescendant([&](const SpatiallyNestablePointer& descendant) { - bool childSuccess; - AACube descendantAACube = descendant->getQueryAACube(childSuccess); - if (childSuccess) { - if (_queryAACube.contains(descendantAACube)) { - return ; - } - _queryAACube += descendantAACube.getMinimumPoint(); - _queryAACube += descendantAACube.getMaximumPoint(); - } - }); - _queryAACubeSet = true; + if (shouldPuffQueryAACube()) { + // make an expanded AACube centered on the object + float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale(); + _queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale); + _queryAACubeIsPuffed = true; + } else { + _queryAACube = maxAACube; + _queryAACubeIsPuffed = false; } + + forEachDescendant([&](const SpatiallyNestablePointer& descendant) { + bool childSuccess; + AACube descendantAACube = descendant->getQueryAACube(childSuccess); + if (childSuccess) { + if (_queryAACube.contains(descendantAACube)) { + return; // from lambda + } + _queryAACube += descendantAACube.getMinimumPoint(); + _queryAACube += descendantAACube.getMaximumPoint(); + } + }); + + _queryAACubeSet = true; } - return updated; + return true; } void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) { @@ -1016,6 +1018,10 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const { return true; } + if (shouldPuffQueryAACube() != _queryAACubeIsPuffed) { + return true; + } + // make sure children are still in their boxes, also. bool childNeedsUpdate = false; forEachDescendantTest([&](const SpatiallyNestablePointer& descendant) { @@ -1029,31 +1035,6 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const { return childNeedsUpdate; } -void SpatiallyNestable::updateQueryAACube() { - bool success; - AACube maxAACube = getMaximumAACube(success); - if (_parentJointIndex != INVALID_JOINT_INDEX || _children.size() > 0 ) { - // make an expanded AACube centered on the object - float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale(); - _queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale); - } else { - _queryAACube = maxAACube; - } - - forEachDescendant([&](const SpatiallyNestablePointer& descendant) { - bool success; - AACube descendantAACube = descendant->getQueryAACube(success); - if (success) { - if (_queryAACube.contains(descendantAACube)) { - return; - } - _queryAACube += descendantAACube.getMinimumPoint(); - _queryAACube += descendantAACube.getMaximumPoint(); - } - }); - _queryAACubeSet = true; -} - AACube SpatiallyNestable::getQueryAACube(bool& success) const { if (_queryAACubeSet) { success = true; diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 9be6dc14ef..37f6cfdfd9 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -106,11 +106,11 @@ public: virtual glm::vec3 getParentAngularVelocity(bool& success) const; virtual AACube getMaximumAACube(bool& success) const; - bool checkAndMaybeUpdateQueryAACube(bool forcePuffed = false); - void updateQueryAACube(); virtual void setQueryAACube(const AACube& queryAACube); virtual bool queryAACubeNeedsUpdate() const; + virtual bool shouldPuffQueryAACube() const { return false; } + bool updateQueryAACube(); void forceQueryAACubeUpdate() { _queryAACubeSet = false; } virtual AACube getQueryAACube(bool& success) const; virtual AACube getQueryAACube() const; @@ -234,6 +234,7 @@ private: glm::vec3 _angularVelocity; mutable bool _parentKnowsMe { false }; bool _isDead { false }; + bool _queryAACubeIsPuffed { false }; };