mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
move checkAndAdjustQueryAACube into SpatiallyNestable
This commit is contained in:
parent
1e8706b1da
commit
5f05d576cc
5 changed files with 57 additions and 29 deletions
|
@ -1202,25 +1202,24 @@ const Transform EntityItem::getTransformToCenter(bool& success) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
void EntityItem::checkAndAdjustQueryAACube() {
|
||||
bool maxAACubeSuccess;
|
||||
AACube maxAACube = getMaximumAACube(maxAACubeSuccess);
|
||||
if (maxAACubeSuccess) {
|
||||
if (!_queryAACubeSet || !_queryAACube.contains(maxAACube)) {
|
||||
// allow server to patch up broken queryAACubes
|
||||
EntityTreePointer tree = getTree();
|
||||
if (tree) {
|
||||
EntityItemProperties properties;
|
||||
properties.setQueryAACube(maxAACube);
|
||||
tree->updateEntity(getID(), properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// void EntityItem::checkAndAdjustQueryAACube() {
|
||||
// bool maxAACubeSuccess;
|
||||
// AACube maxAACube = getMaximumAACube(maxAACubeSuccess);
|
||||
// if (maxAACubeSuccess) {
|
||||
// if (!_queryAACubeSet || !_queryAACube.contains(maxAACube)) {
|
||||
// // allow server to patch up broken queryAACubes
|
||||
// EntityTreePointer tree = getTree();
|
||||
// if (tree) {
|
||||
// EntityItemProperties properties;
|
||||
// properties.setQueryAACube(maxAACube);
|
||||
// tree->updateEntity(getID(), properties);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void EntityItem::setParentID(const QUuid& parentID) {
|
||||
SpatiallyNestable::setParentID(parentID);
|
||||
checkAndAdjustQueryAACube();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1229,7 +1228,6 @@ void EntityItem::setDimensions(const glm::vec3& value) {
|
|||
return;
|
||||
}
|
||||
setScale(value);
|
||||
checkAndAdjustQueryAACube();
|
||||
}
|
||||
|
||||
/// The maximum bounding cube for the entity, independent of it's rotation.
|
||||
|
@ -1322,6 +1320,20 @@ AABox EntityItem::getAABox(bool& success) const {
|
|||
return _cachedAABox;
|
||||
}
|
||||
|
||||
AACube EntityItem::getQueryAACube(bool& success) const {
|
||||
AACube result = SpatiallyNestable::getQueryAACube(success);
|
||||
if (success) {
|
||||
return result;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
// NOTE: This should only be used in cases of old bitstreams which only contain radius data
|
||||
// 0,0,0 --> maxDimension,maxDimension,maxDimension
|
||||
// ... has a corner to corner distance of glm::length(maxDimension,maxDimension,maxDimension)
|
||||
|
|
|
@ -179,8 +179,6 @@ public:
|
|||
QString getDescription() const { return _description; }
|
||||
void setDescription(QString value) { _description = value; }
|
||||
|
||||
void checkAndAdjustQueryAACube();
|
||||
|
||||
virtual void setParentID(const QUuid& parentID);
|
||||
|
||||
/// Dimensions in meters (0.0 - TREE_SCALE)
|
||||
|
@ -242,6 +240,8 @@ public:
|
|||
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;
|
||||
const QString& getScript() const { return _script; }
|
||||
void setScript(const QString& value) { _script = value; }
|
||||
|
||||
|
|
|
@ -992,15 +992,21 @@ void EntityTree::fixupMissingParents() {
|
|||
EntityItemWeakPointer entityWP = iter.next();
|
||||
EntityItemPointer entity = entityWP.lock();
|
||||
if (entity) {
|
||||
bool success;
|
||||
AACube newCube = entity->getQueryAACube(success);
|
||||
if (success) {
|
||||
// this entity's parent (or ancestry) was previously not fully known, and now is. Update its
|
||||
// location in the EntityTree.
|
||||
moveOperator.addEntityToMoveList(entity, newCube);
|
||||
iter.remove();
|
||||
entity->markAncestorMissing(false);
|
||||
bool maxAACubeSuccess;
|
||||
AACube maxAACube = entity->getMaximumAACube(maxAACubeSuccess);
|
||||
bool queryAACubeSuccess;
|
||||
AACube newCube = entity->getQueryAACube(queryAACubeSuccess);
|
||||
if (!maxAACubeSuccess || !queryAACubeSuccess) {
|
||||
continue;
|
||||
}
|
||||
if (!newCube.contains(maxAACube)) {
|
||||
newCube = maxAACube;
|
||||
}
|
||||
// this entity's parent (or ancestry) was previously not fully known, and now is. Update its
|
||||
// location in the EntityTree.
|
||||
moveOperator.addEntityToMoveList(entity, newCube);
|
||||
iter.remove();
|
||||
entity->markAncestorMissing(false);
|
||||
} else {
|
||||
// entity was deleted before we found its parent.
|
||||
iter.remove();
|
||||
|
|
|
@ -752,6 +752,7 @@ void SpatiallyNestable::forEachDescendant(std::function<void(SpatiallyNestablePo
|
|||
}
|
||||
|
||||
void SpatiallyNestable::locationChanged() {
|
||||
checkAndAdjustQueryAACube();
|
||||
forEachChild([&](SpatiallyNestablePointer object) {
|
||||
object->locationChanged();
|
||||
});
|
||||
|
@ -761,13 +762,21 @@ AACube SpatiallyNestable::getMaximumAACube(bool& success) const {
|
|||
return AACube(getPosition(success) - glm::vec3(defaultAACubeSize / 2.0f), defaultAACubeSize);
|
||||
}
|
||||
|
||||
void SpatiallyNestable::checkAndAdjustQueryAACube() {
|
||||
bool success;
|
||||
AACube maxAACube = getMaximumAACube(success);
|
||||
if (success && (!_queryAACubeSet || !_queryAACube.contains(maxAACube))) {
|
||||
setQueryAACube(maxAACube);
|
||||
}
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) {
|
||||
if (queryAACube.containsNaN()) {
|
||||
qDebug() << "SpatiallyNestable::setQueryAACube -- cube contains NaN";
|
||||
return;
|
||||
}
|
||||
_queryAACube = queryAACube;
|
||||
if (queryAACube.getScale() > 0.0f) {
|
||||
if (_queryAACube.getScale() > 0.0f) {
|
||||
_queryAACubeSet = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ public:
|
|||
virtual glm::vec3 getParentAngularVelocity(bool& success) const;
|
||||
|
||||
virtual AACube getMaximumAACube(bool& success) const;
|
||||
virtual void checkAndAdjustQueryAACube();
|
||||
virtual bool computePuffedQueryAACube();
|
||||
|
||||
virtual void setQueryAACube(const AACube& queryAACube);
|
||||
|
@ -156,7 +157,7 @@ protected:
|
|||
mutable QHash<QUuid, SpatiallyNestableWeakPointer> _children;
|
||||
|
||||
virtual void locationChanged(); // called when a this object's location has changed
|
||||
virtual void dimensionsChanged() {} // called when a this object's dimensions have changed
|
||||
virtual void dimensionsChanged() { checkAndAdjustQueryAACube(); } // called when a this object's dimensions have changed
|
||||
|
||||
// _queryAACube is used to decide where something lives in the octree
|
||||
mutable AACube _queryAACube;
|
||||
|
|
Loading…
Reference in a new issue