mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
check for and break parenting loops in hasAncestorOfType, findAncestorOfType, isParentPathComplete
This commit is contained in:
parent
4e7a777fda
commit
c1e2653526
2 changed files with 40 additions and 20 deletions
|
@ -748,6 +748,18 @@ const Transform SpatiallyNestable::getTransform() const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpatiallyNestable::breakParentingLoop() const {
|
||||||
|
// someone created a loop. break it...
|
||||||
|
qCDebug(shared) << "Parenting loop detected: " << getID();
|
||||||
|
SpatiallyNestablePointer _this = getThisPointer();
|
||||||
|
_this->setParentID(QUuid());
|
||||||
|
bool setPositionSuccess;
|
||||||
|
AACube aaCube = getQueryAACube(setPositionSuccess);
|
||||||
|
if (setPositionSuccess) {
|
||||||
|
_this->setWorldPosition(aaCube.calcCenter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Transform SpatiallyNestable::getTransform(int jointIndex, bool& success, int depth) const {
|
const Transform SpatiallyNestable::getTransform(int jointIndex, bool& success, int depth) const {
|
||||||
// this returns the world-space transform for this object. It finds its parent's transform (which may
|
// this returns the world-space transform for this object. It finds its parent's transform (which may
|
||||||
// cause this object's parent to query its parent, etc) and multiplies this object's local transform onto it.
|
// cause this object's parent to query its parent, etc) and multiplies this object's local transform onto it.
|
||||||
|
@ -755,15 +767,7 @@ const Transform SpatiallyNestable::getTransform(int jointIndex, bool& success, i
|
||||||
|
|
||||||
if (depth > MAX_PARENTING_CHAIN_SIZE) {
|
if (depth > MAX_PARENTING_CHAIN_SIZE) {
|
||||||
success = false;
|
success = false;
|
||||||
// someone created a loop. break it...
|
breakParentingLoop();
|
||||||
qCDebug(shared) << "Parenting loop detected: " << getID();
|
|
||||||
SpatiallyNestablePointer _this = getThisPointer();
|
|
||||||
_this->setParentID(QUuid());
|
|
||||||
bool setPositionSuccess;
|
|
||||||
AACube aaCube = getQueryAACube(setPositionSuccess);
|
|
||||||
if (setPositionSuccess) {
|
|
||||||
_this->setWorldPosition(aaCube.calcCenter());
|
|
||||||
}
|
|
||||||
return jointInWorldFrame;
|
return jointInWorldFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1208,8 +1212,12 @@ AACube SpatiallyNestable::getQueryAACube() const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpatiallyNestable::hasAncestorOfType(NestableType nestableType) const {
|
bool SpatiallyNestable::hasAncestorOfType(NestableType nestableType, int depth) const {
|
||||||
bool success;
|
if (depth > MAX_PARENTING_CHAIN_SIZE) {
|
||||||
|
breakParentingLoop();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (nestableType == NestableType::Avatar) {
|
if (nestableType == NestableType::Avatar) {
|
||||||
QUuid parentID = getParentID();
|
QUuid parentID = getParentID();
|
||||||
if (parentID == AVATAR_SELF_ID) {
|
if (parentID == AVATAR_SELF_ID) {
|
||||||
|
@ -1217,6 +1225,7 @@ bool SpatiallyNestable::hasAncestorOfType(NestableType nestableType) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool success;
|
||||||
SpatiallyNestablePointer parent = getParentPointer(success);
|
SpatiallyNestablePointer parent = getParentPointer(success);
|
||||||
if (!success || !parent) {
|
if (!success || !parent) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1226,11 +1235,14 @@ bool SpatiallyNestable::hasAncestorOfType(NestableType nestableType) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent->hasAncestorOfType(nestableType);
|
return parent->hasAncestorOfType(nestableType, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUuid SpatiallyNestable::findAncestorOfType(NestableType nestableType) const {
|
const QUuid SpatiallyNestable::findAncestorOfType(NestableType nestableType, int depth) const {
|
||||||
bool success;
|
if (depth > MAX_PARENTING_CHAIN_SIZE) {
|
||||||
|
breakParentingLoop();
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
if (nestableType == NestableType::Avatar) {
|
if (nestableType == NestableType::Avatar) {
|
||||||
QUuid parentID = getParentID();
|
QUuid parentID = getParentID();
|
||||||
|
@ -1239,6 +1251,7 @@ const QUuid SpatiallyNestable::findAncestorOfType(NestableType nestableType) con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool success;
|
||||||
SpatiallyNestablePointer parent = getParentPointer(success);
|
SpatiallyNestablePointer parent = getParentPointer(success);
|
||||||
if (!success || !parent) {
|
if (!success || !parent) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
|
@ -1248,7 +1261,7 @@ const QUuid SpatiallyNestable::findAncestorOfType(NestableType nestableType) con
|
||||||
return parent->getID();
|
return parent->getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent->findAncestorOfType(nestableType);
|
return parent->findAncestorOfType(nestableType, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatiallyNestable::getLocalTransformAndVelocities(
|
void SpatiallyNestable::getLocalTransformAndVelocities(
|
||||||
|
@ -1336,7 +1349,12 @@ void SpatiallyNestable::dump(const QString& prefix) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpatiallyNestable::isParentPathComplete() const {
|
bool SpatiallyNestable::isParentPathComplete(int depth) const {
|
||||||
|
if (depth > MAX_PARENTING_CHAIN_SIZE) {
|
||||||
|
breakParentingLoop();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static const QUuid IDENTITY;
|
static const QUuid IDENTITY;
|
||||||
QUuid parentID = getParentID();
|
QUuid parentID = getParentID();
|
||||||
if (parentID.isNull() || parentID == IDENTITY) {
|
if (parentID.isNull() || parentID == IDENTITY) {
|
||||||
|
@ -1349,5 +1367,5 @@ bool SpatiallyNestable::isParentPathComplete() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent->isParentPathComplete();
|
return parent->isParentPathComplete(depth + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public:
|
||||||
static QString nestableTypeToString(NestableType nestableType);
|
static QString nestableTypeToString(NestableType nestableType);
|
||||||
|
|
||||||
|
|
||||||
virtual bool isParentPathComplete() const;
|
virtual bool isParentPathComplete(int depth = 0) const;
|
||||||
|
|
||||||
|
|
||||||
// world frame
|
// world frame
|
||||||
|
@ -187,8 +187,8 @@ public:
|
||||||
bool isParentIDValid() const { bool success = false; getParentPointer(success); return success; }
|
bool isParentIDValid() const { bool success = false; getParentPointer(success); return success; }
|
||||||
virtual SpatialParentTree* getParentTree() const { return nullptr; }
|
virtual SpatialParentTree* getParentTree() const { return nullptr; }
|
||||||
|
|
||||||
bool hasAncestorOfType(NestableType nestableType) const;
|
bool hasAncestorOfType(NestableType nestableType, int depth = 0) const;
|
||||||
const QUuid findAncestorOfType(NestableType nestableType) const;
|
const QUuid findAncestorOfType(NestableType nestableType, int depth = 0) const;
|
||||||
SpatiallyNestablePointer getParentPointer(bool& success) const;
|
SpatiallyNestablePointer getParentPointer(bool& success) const;
|
||||||
static SpatiallyNestablePointer findByID(QUuid id, bool& success);
|
static SpatiallyNestablePointer findByID(QUuid id, bool& success);
|
||||||
|
|
||||||
|
@ -246,6 +246,8 @@ private:
|
||||||
mutable bool _parentKnowsMe { false };
|
mutable bool _parentKnowsMe { false };
|
||||||
bool _isDead { false };
|
bool _isDead { false };
|
||||||
bool _queryAACubeIsPuffed { false };
|
bool _queryAACubeIsPuffed { false };
|
||||||
|
|
||||||
|
void breakParentingLoop() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue