mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 15:23:05 +02:00
Merge pull request #14219 from SamGondelman/materialCull
QueryAACube fixes and materials expand to include their parent
This commit is contained in:
commit
8e5bc1678f
6 changed files with 61 additions and 16 deletions
|
@ -191,8 +191,6 @@ void Base3DOverlay::setProperties(const QVariantMap& originalProperties) {
|
||||||
|
|
||||||
if (properties["parentID"].isValid()) {
|
if (properties["parentID"].isValid()) {
|
||||||
setParentID(QUuid(properties["parentID"].toString()));
|
setParentID(QUuid(properties["parentID"].toString()));
|
||||||
bool success;
|
|
||||||
getParentPointer(success); // call this to hook-up the parent's back-pointers to its child overlays
|
|
||||||
needRenderItemUpdate = true;
|
needRenderItemUpdate = true;
|
||||||
}
|
}
|
||||||
if (properties["parentJointIndex"].isValid()) {
|
if (properties["parentJointIndex"].isValid()) {
|
||||||
|
|
|
@ -1933,6 +1933,14 @@ void EntityTree::fixupNeedsParentFixups() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
entity->locationChanged(true);
|
entity->locationChanged(true);
|
||||||
|
|
||||||
|
// Update our parent's bounding box
|
||||||
|
bool success = false;
|
||||||
|
auto parent = entity->getParentPointer(success);
|
||||||
|
if (success && parent) {
|
||||||
|
parent->updateQueryAACube();
|
||||||
|
}
|
||||||
|
|
||||||
entity->postParentFixup();
|
entity->postParentFixup();
|
||||||
} else if (getIsServer() || _avatarIDs.contains(entity->getParentID())) {
|
} else if (getIsServer() || _avatarIDs.contains(entity->getParentID())) {
|
||||||
// this is a child of an avatar, which the entity server will never have
|
// this is a child of an avatar, which the entity server will never have
|
||||||
|
|
|
@ -314,8 +314,25 @@ void MaterialEntityItem::applyMaterial() {
|
||||||
_retryApply = true;
|
_retryApply = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AACube MaterialEntityItem::calculateInitialQueryAACube(bool& success) {
|
||||||
|
AACube aaCube = EntityItem::calculateInitialQueryAACube(success);
|
||||||
|
// A Material entity's queryAACube contains its parent's queryAACube
|
||||||
|
auto parent = getParentPointer(success);
|
||||||
|
if (success && parent) {
|
||||||
|
success = false;
|
||||||
|
AACube parentQueryAACube = parent->calculateInitialQueryAACube(success);
|
||||||
|
if (success) {
|
||||||
|
aaCube += parentQueryAACube.getMinimumPoint();
|
||||||
|
aaCube += parentQueryAACube.getMaximumPoint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aaCube;
|
||||||
|
}
|
||||||
|
|
||||||
void MaterialEntityItem::postParentFixup() {
|
void MaterialEntityItem::postParentFixup() {
|
||||||
removeMaterial();
|
removeMaterial();
|
||||||
|
_queryAACubeSet = false; // force an update so we contain our parent
|
||||||
|
updateQueryAACube();
|
||||||
applyMaterial();
|
applyMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,8 @@ public:
|
||||||
|
|
||||||
void postParentFixup() override;
|
void postParentFixup() override;
|
||||||
|
|
||||||
|
AACube calculateInitialQueryAACube(bool& success) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// URL for this material. Currently, only JSON format is supported. Set to "materialData" to use the material data to live edit a material.
|
// URL for this material. Currently, only JSON format is supported. Set to "materialData" to use the material data to live edit a material.
|
||||||
// The following fields are supported in the JSON:
|
// The following fields are supported in the JSON:
|
||||||
|
|
|
@ -75,7 +75,10 @@ void SpatiallyNestable::setParentID(const QUuid& parentID) {
|
||||||
});
|
});
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
getParentPointer(success);
|
auto parent = getParentPointer(success);
|
||||||
|
if (success && parent) {
|
||||||
|
parent->updateQueryAACube();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform SpatiallyNestable::getParentTransform(bool& success, int depth) const {
|
Transform SpatiallyNestable::getParentTransform(bool& success, int depth) const {
|
||||||
|
@ -155,12 +158,14 @@ void SpatiallyNestable::beParentOfChild(SpatiallyNestablePointer newChild) const
|
||||||
_childrenLock.withWriteLock([&] {
|
_childrenLock.withWriteLock([&] {
|
||||||
_children[newChild->getID()] = newChild;
|
_children[newChild->getID()] = newChild;
|
||||||
});
|
});
|
||||||
|
// Our QueryAACube will automatically be updated to include our new child
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatiallyNestable::forgetChild(SpatiallyNestablePointer newChild) const {
|
void SpatiallyNestable::forgetChild(SpatiallyNestablePointer newChild) const {
|
||||||
_childrenLock.withWriteLock([&] {
|
_childrenLock.withWriteLock([&] {
|
||||||
_children.remove(newChild->getID());
|
_children.remove(newChild->getID());
|
||||||
});
|
});
|
||||||
|
_queryAACubeSet = false; // We need to reset our queryAACube when we lose a child
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatiallyNestable::setParentJointIndex(quint16 parentJointIndex) {
|
void SpatiallyNestable::setParentJointIndex(quint16 parentJointIndex) {
|
||||||
|
@ -1092,7 +1097,23 @@ AACube SpatiallyNestable::getMaximumAACube(bool& success) const {
|
||||||
return AACube(getWorldPosition(success) - glm::vec3(defaultAACubeSize / 2.0f), defaultAACubeSize);
|
return AACube(getWorldPosition(success) - glm::vec3(defaultAACubeSize / 2.0f), defaultAACubeSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AACube SpatiallyNestable::calculateInitialQueryAACube(bool& success) {
|
||||||
|
success = false;
|
||||||
|
AACube maxAACube = getMaximumAACube(success);
|
||||||
|
if (!success) {
|
||||||
|
return AACube();
|
||||||
|
}
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
if (shouldPuffQueryAACube()) {
|
||||||
|
// make an expanded AACube centered on the object
|
||||||
const float PARENTED_EXPANSION_FACTOR = 3.0f;
|
const float PARENTED_EXPANSION_FACTOR = 3.0f;
|
||||||
|
float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale();
|
||||||
|
return AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale);
|
||||||
|
} else {
|
||||||
|
return maxAACube;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SpatiallyNestable::updateQueryAACube() {
|
bool SpatiallyNestable::updateQueryAACube() {
|
||||||
if (!queryAACubeNeedsUpdate()) {
|
if (!queryAACubeNeedsUpdate()) {
|
||||||
|
@ -1100,20 +1121,12 @@ bool SpatiallyNestable::updateQueryAACube() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success;
|
bool success;
|
||||||
AACube maxAACube = getMaximumAACube(success);
|
AACube initialQueryAACube = calculateInitialQueryAACube(success);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_queryAACube = initialQueryAACube;
|
||||||
if (shouldPuffQueryAACube()) {
|
_queryAACubeIsPuffed = 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) {
|
forEachDescendant([&](const SpatiallyNestablePointer& descendant) {
|
||||||
bool childSuccess;
|
bool childSuccess;
|
||||||
|
@ -1128,6 +1141,12 @@ bool SpatiallyNestable::updateQueryAACube() {
|
||||||
});
|
});
|
||||||
|
|
||||||
_queryAACubeSet = true;
|
_queryAACubeSet = true;
|
||||||
|
|
||||||
|
auto parent = getParentPointer(success);
|
||||||
|
if (success && parent) {
|
||||||
|
parent->updateQueryAACube();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1158,7 +1177,7 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const {
|
||||||
// make sure children are still in their boxes, also.
|
// make sure children are still in their boxes, also.
|
||||||
bool childNeedsUpdate = false;
|
bool childNeedsUpdate = false;
|
||||||
forEachDescendantTest([&](const SpatiallyNestablePointer& descendant) {
|
forEachDescendantTest([&](const SpatiallyNestablePointer& descendant) {
|
||||||
if (!childNeedsUpdate && descendant->queryAACubeNeedsUpdate()) {
|
if (descendant->queryAACubeNeedsUpdate() || !_queryAACube.contains(descendant->getQueryAACube())) {
|
||||||
childNeedsUpdate = true;
|
childNeedsUpdate = true;
|
||||||
// Don't recurse further
|
// Don't recurse further
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -112,6 +112,7 @@ public:
|
||||||
virtual glm::vec3 getParentAngularVelocity(bool& success) const;
|
virtual glm::vec3 getParentAngularVelocity(bool& success) const;
|
||||||
|
|
||||||
virtual AACube getMaximumAACube(bool& success) const;
|
virtual AACube getMaximumAACube(bool& success) const;
|
||||||
|
virtual AACube calculateInitialQueryAACube(bool& success);
|
||||||
|
|
||||||
virtual void setQueryAACube(const AACube& queryAACube);
|
virtual void setQueryAACube(const AACube& queryAACube);
|
||||||
virtual bool queryAACubeNeedsUpdate() const;
|
virtual bool queryAACubeNeedsUpdate() const;
|
||||||
|
|
Loading…
Reference in a new issue