only update cauterization of child entities when something relevant changes

This commit is contained in:
Seth Alves 2018-02-02 08:56:11 -08:00
parent bdf6736a54
commit 14d5029f4d
3 changed files with 36 additions and 11 deletions

View file

@ -504,6 +504,16 @@ void MyAvatar::updateEyeContactTarget(float deltaTime) {
extern QByteArray avatarStateToFrame(const AvatarData* _avatar);
extern void avatarStateFromFrame(const QByteArray& frameData, AvatarData* _avatar);
void MyAvatar::beParentOfChild(SpatiallyNestablePointer newChild) const {
_cauterizationNeedsUpdate = true;
SpatiallyNestable::beParentOfChild(newChild);
}
void MyAvatar::forgetChild(SpatiallyNestablePointer newChild) const {
_cauterizationNeedsUpdate = true;
SpatiallyNestable::forgetChild(newChild);
}
void MyAvatar::updateChildCauterization(SpatiallyNestablePointer object) {
if (object->getNestableType() == NestableType::Entity) {
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object);
@ -516,16 +526,19 @@ void MyAvatar::simulate(float deltaTime) {
animateScaleChanges(deltaTime);
const std::unordered_set<int>& headBoneSet = _skeletonModel->getCauterizeBoneSet();
forEachChild([&](SpatiallyNestablePointer object) {
bool isChildOfHead = headBoneSet.find(object->getParentJointIndex()) != headBoneSet.end();
if (isChildOfHead) {
updateChildCauterization(object);
object->forEachDescendant([&](SpatiallyNestablePointer descendant) {
updateChildCauterization(descendant);
});
}
});
if (_cauterizationNeedsUpdate) {
const std::unordered_set<int>& headBoneSet = _skeletonModel->getCauterizeBoneSet();
forEachChild([&](SpatiallyNestablePointer object) {
bool isChildOfHead = headBoneSet.find(object->getParentJointIndex()) != headBoneSet.end();
if (isChildOfHead) {
updateChildCauterization(object);
object->forEachDescendant([&](SpatiallyNestablePointer descendant) {
updateChildCauterization(descendant);
});
}
});
_cauterizationNeedsUpdate = false;
}
{
PerformanceTimer perfTimer("transform");
@ -1438,6 +1451,7 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
Avatar::setSkeletonModelURL(skeletonModelURL);
_skeletonModel->setVisibleInScene(true, qApp->getMain3DScene(), render::ItemKey::TAG_BITS_NONE);
_headBoneSet.clear();
_cauterizationNeedsUpdate = true;
emit skeletonChanged();
}
@ -1809,6 +1823,8 @@ void MyAvatar::initHeadBones() {
}
q.pop();
}
_cauterizationNeedsUpdate = true;
}
QUrl MyAvatar::getAnimGraphOverrideUrl() const {
@ -1879,6 +1895,7 @@ void MyAvatar::postUpdate(float deltaTime, const render::ScenePointer& scene) {
_fstAnimGraphOverrideUrl = _skeletonModel->getGeometry()->getAnimGraphOverrideUrl();
initAnimGraph();
_isAnimatingScale = true;
_cauterizationNeedsUpdate = true;
}
if (_enableDebugDrawDefaultPose || _enableDebugDrawAnimPose) {
@ -1967,6 +1984,7 @@ void MyAvatar::preDisplaySide(RenderArgs* renderArgs) {
// toggle using the cauterizedBones depending on where the camera is and the rendering pass type.
const bool shouldDrawHead = shouldRenderHead(renderArgs);
if (shouldDrawHead != _prevShouldDrawHead) {
_cauterizationNeedsUpdate = true;
_skeletonModel->setEnableCauterization(!shouldDrawHead);
for (int i = 0; i < _attachmentData.size(); i++) {

View file

@ -633,6 +633,11 @@ signals:
private slots:
void leaveDomain();
protected:
virtual void beParentOfChild(SpatiallyNestablePointer newChild) const override;
virtual void forgetChild(SpatiallyNestablePointer newChild) const override;
private:
bool requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& positionOut);
@ -812,6 +817,8 @@ private:
bool _enableDebugDrawIKChains { false };
bool _enableDebugDrawDetailedCollision { false };
mutable bool _cauterizationNeedsUpdate; // do we need to scan children and update their "cauterized" state?
AudioListenerMode _audioListenerMode;
glm::vec3 _customListenPosition;
glm::quat _customListenOrientation;

View file

@ -19,7 +19,7 @@ namespace render {
ItemKey::Builder builder;
builder.withTypeLight();
builder.withTagBits(ItemKey::TAG_BITS_ALL);
if (!payload) {
if (payload) {
if (!payload->isVisible()) {
builder.withInvisible();
}