From b6f28a6732f58edba952063c01e652a05f2e725a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 4 Sep 2019 17:06:21 -0700 Subject: [PATCH] Switch additive animation deltas from a pre multiply to a post multiply. --- libraries/animation/src/AnimBlendLinear.cpp | 8 +++----- libraries/animation/src/AnimClip.cpp | 18 +++++++----------- libraries/animation/src/AnimUtil.cpp | 3 +-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/libraries/animation/src/AnimBlendLinear.cpp b/libraries/animation/src/AnimBlendLinear.cpp index c066dc92eb..d861f07847 100644 --- a/libraries/animation/src/AnimBlendLinear.cpp +++ b/libraries/animation/src/AnimBlendLinear.cpp @@ -110,11 +110,9 @@ void AnimBlendLinear::evaluateAndBlendChildren(const AnimVariantMap& animVars, c // copy translation and scale from nextPoses AnimPose pose = nextPoses[i]; - int parentIndex = _skeleton->getParentIndex((int)i); - if (parentIndex >= 0) { - // but transform nextPoses rot into absPrev parent frame. - pose.rot() = glm::inverse(absPrev[parentIndex].rot()) * pose.rot() * absPrev[parentIndex].rot(); - } + // convert from a rotation that happens in the absolute space of the joint + // into a rotation that happens in the relative space of the joint. + pose.rot() = glm::inverse(absPrev[i].rot()) * pose.rot() * absPrev[i].rot(); relOffsetPoses.push_back(pose); } diff --git a/libraries/animation/src/AnimClip.cpp b/libraries/animation/src/AnimClip.cpp index 1a33cc33d2..3476adc80c 100644 --- a/libraries/animation/src/AnimClip.cpp +++ b/libraries/animation/src/AnimClip.cpp @@ -56,12 +56,12 @@ static void bakeRelativeDeltaAnim(std::vector& anim, const AnimPose // for each joint in animPoses for (size_t i = 0; i < animPoses.size(); ++i) { // convert this relative AnimPose into a delta animation. - animPoses[i] = animPoses[i] * invBasePoses[i]; + animPoses[i] = invBasePoses[i] * animPoses[i]; } } } -void bakeAbsoluteDeltaAnim(std::vector& anim, const AnimPoseVec& basePoses, AnimSkeleton::ConstPointer skeleton, const QString& url, int baseFrame) { +void bakeAbsoluteDeltaAnim(std::vector& anim, const AnimPoseVec& basePoses, AnimSkeleton::ConstPointer skeleton) { // invert all the basePoses AnimPoseVec invBasePoses = basePoses; @@ -73,7 +73,6 @@ void bakeAbsoluteDeltaAnim(std::vector& anim, const AnimPoseVec& ba skeleton->convertRelativePosesToAbsolute(absBasePoses); // for each frame of the animation - int frame = 0; for (auto&& animPoses : anim) { ASSERT(animPoses.size() == basePoses.size()); @@ -81,15 +80,12 @@ void bakeAbsoluteDeltaAnim(std::vector& anim, const AnimPoseVec& ba for (size_t i = 0; i < animPoses.size(); ++i) { // scale and translation are relative frame - animPoses[i] = animPoses[i] * invBasePoses[i]; + animPoses[i] = invBasePoses[i] * animPoses[i]; - // but transform the rotation delta into the absolute frame. - int parentIndex = skeleton->getParentIndex((int)i); - if (parentIndex >= 0) { - animPoses[i].rot() = absBasePoses[parentIndex].rot() * animPoses[i].rot() * glm::inverse(absBasePoses[parentIndex].rot()); - } + // convert from a rotation that happens in the relative space of the joint + // into a rotation that happens in the absolute space of the joint. + animPoses[i].rot() = absBasePoses[i].rot() * animPoses[i].rot() * glm::inverse(absBasePoses[i].rot()); } - frame++; } } @@ -297,7 +293,7 @@ const AnimPoseVec& AnimClip::evaluate(const AnimVariantMap& animVars, const Anim auto baseAnim = copyAndRetargetFromNetworkAnim(_baseNetworkAnim, _skeleton); if (_blendType == AnimBlendType_AddAbsolute) { - bakeAbsoluteDeltaAnim(_anim, baseAnim[(int)_baseFrame], _skeleton, _url, _baseFrame); + bakeAbsoluteDeltaAnim(_anim, baseAnim[(int)_baseFrame], _skeleton); } else { // AnimBlendType_AddRelative bakeRelativeDeltaAnim(_anim, baseAnim[(int)_baseFrame]); diff --git a/libraries/animation/src/AnimUtil.cpp b/libraries/animation/src/AnimUtil.cpp index dff7bb194c..8830cb78b1 100644 --- a/libraries/animation/src/AnimUtil.cpp +++ b/libraries/animation/src/AnimUtil.cpp @@ -68,8 +68,7 @@ void blendAdd(size_t numPoses, const AnimPose* a, const AnimPose* b, float alpha delta = -delta; } delta = glm::lerp(identity, delta, alpha); - result[i].rot() = glm::normalize(delta * aPose.rot()); - + result[i].rot() = glm::normalize(aPose.rot() * delta); result[i].trans() = aPose.trans() + (alpha * bPose.trans()); } }