From 86891704159f0154d48070a66a2ad3c8c55a84e6 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 22 Oct 2015 16:40:53 -0700 Subject: [PATCH] Removed sync and timescale from AnimBlendLinear node. AnimBlendLinearMove will now be used instead. --- .../defaultAvatar_full/avatar-animation.json | 4 -- libraries/animation/src/AnimBlendLinear.cpp | 63 +------------------ libraries/animation/src/AnimBlendLinear.h | 15 +---- libraries/animation/src/AnimNodeLoader.cpp | 9 +-- 4 files changed, 4 insertions(+), 87 deletions(-) diff --git a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json index 46c5cd9567..c6c67a21d5 100644 --- a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json +++ b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json @@ -190,8 +190,6 @@ "type": "blendLinear", "data": { "alpha": 0.0, - "sync": false, - "timeScale": 1.0, "alphaVar": "rightHandGrabBlend" }, "children": [ @@ -341,8 +339,6 @@ "type": "blendLinear", "data": { "alpha": 0.0, - "sync": false, - "timeScale": 1.0, "alphaVar": "leftHandGrabBlend" }, "children": [ diff --git a/libraries/animation/src/AnimBlendLinear.cpp b/libraries/animation/src/AnimBlendLinear.cpp index 1f9026de9d..52c440a14e 100644 --- a/libraries/animation/src/AnimBlendLinear.cpp +++ b/libraries/animation/src/AnimBlendLinear.cpp @@ -14,11 +14,9 @@ #include "AnimUtil.h" #include "AnimClip.h" -AnimBlendLinear::AnimBlendLinear(const QString& id, float alpha, bool sync, float timeScale) : +AnimBlendLinear::AnimBlendLinear(const QString& id, float alpha) : AnimNode(AnimNode::Type::BlendLinear, id), - _alpha(alpha), - _sync(sync), - _timeScale(timeScale) { + _alpha(alpha) { } @@ -29,7 +27,6 @@ AnimBlendLinear::~AnimBlendLinear() { const AnimPoseVec& AnimBlendLinear::evaluate(const AnimVariantMap& animVars, float dt, Triggers& triggersOut) { _alpha = animVars.lookup(_alphaVar, _alpha); - _timeScale = animVars.lookup(_timeScaleVar, _timeScale); if (_children.size() == 0) { for (auto&& pose : _poses) { @@ -44,10 +41,6 @@ const AnimPoseVec& AnimBlendLinear::evaluate(const AnimVariantMap& animVars, flo size_t nextPoseIndex = glm::ceil(clampedAlpha); float alpha = glm::fract(clampedAlpha); - if (_sync) { - setSyncAndAccumulateTime(dt, prevPoseIndex, nextPoseIndex, triggersOut); - } - evaluateAndBlendChildren(animVars, triggersOut, alpha, prevPoseIndex, nextPoseIndex, dt); } return _poses; @@ -75,55 +68,3 @@ void AnimBlendLinear::evaluateAndBlendChildren(const AnimVariantMap& animVars, T } } } - -void AnimBlendLinear::setSyncAndAccumulateTime(float dt, size_t prevPoseIndex, size_t nextPoseIndex, Triggers& triggersOut) { - std::vector offsets(_children.size(), 0.0f); - std::vector timeScales(_children.size(), 1.0f); - - float lengthSum = 0.0f; - for (size_t i = 0; i < _children.size(); i++) { - // abort if we find a child that is NOT a clipNode. - if (_children[i]->getType() != AnimNode::Type::Clip) { - // TODO: FIXME: make sync this work for other node types. - return; - } - auto clipNode = std::dynamic_pointer_cast(_children[i]); - assert(clipNode); - if (clipNode) { - lengthSum += (clipNode->getEndFrame() - clipNode->getStartFrame()) + 1.0f; - } - } - - _averageLength = lengthSum / (float)_children.size(); - - float progress = (_syncFrame / _averageLength); - - auto prevClipNode = std::dynamic_pointer_cast(_children[prevPoseIndex]); - float prevLength = (prevClipNode->getEndFrame() - prevClipNode->getStartFrame()) + 1.0f; - float prevOffset = prevClipNode->getStartFrame(); - float prevFrame = prevOffset + (progress * prevLength); - float prevTimeScale = _timeScale * (_averageLength / prevLength); - prevClipNode->setTimeScale(prevTimeScale); - prevClipNode->setCurrentFrame(prevFrame); - - auto nextClipNode = std::dynamic_pointer_cast(_children[nextPoseIndex]); - float nextLength = (nextClipNode->getEndFrame() - nextClipNode->getStartFrame()) + 1.0f; - float nextOffset = nextClipNode->getStartFrame(); - float nextFrame = nextOffset + (progress * nextLength); - float nextTimeScale = _timeScale * (_averageLength / nextLength); - nextClipNode->setTimeScale(nextTimeScale); - nextClipNode->setCurrentFrame(nextFrame); - - const float START_FRAME = 0.0f; - const bool LOOP_FLAG = true; - _syncFrame = ::accumulateTime(START_FRAME, _averageLength, _timeScale, _syncFrame, dt, LOOP_FLAG, _id, triggersOut); -} - -void AnimBlendLinear::setCurrentFrameInternal(float frame) { - // because dt is 0, we should not encounter any triggers - const float dt = 0.0f; - Triggers triggers; - const float START_FRAME = 0.0f; - const bool LOOP_FLAG = true; - _syncFrame = ::accumulateTime(START_FRAME, _averageLength, _timeScale, frame, dt, LOOP_FLAG, _id, triggers); -} diff --git a/libraries/animation/src/AnimBlendLinear.h b/libraries/animation/src/AnimBlendLinear.h index 7def6be91d..2478f9b473 100644 --- a/libraries/animation/src/AnimBlendLinear.h +++ b/libraries/animation/src/AnimBlendLinear.h @@ -22,21 +22,17 @@ // between 0 and n - 1. This alpha can be used to linearly interpolate between // the closest two children poses. This can be used to sweep through a series // of animation poses. -// -// The sync flag is used to synchronize between child animations of different lengths. -// Typically used to synchronize blending between walk and run cycles. class AnimBlendLinear : public AnimNode { public: friend class AnimTests; - AnimBlendLinear(const QString& id, float alpha, bool sync, float timeScale); + AnimBlendLinear(const QString& id, float alpha); virtual ~AnimBlendLinear() override; virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, float dt, Triggers& triggersOut) override; void setAlphaVar(const QString& alphaVar) { _alphaVar = alphaVar; } - void setTimeScaleVar(const QString& timeScaleVar) { _timeScaleVar = timeScaleVar; } protected: // for AnimDebugDraw rendering @@ -44,21 +40,12 @@ protected: void evaluateAndBlendChildren(const AnimVariantMap& animVars, Triggers& triggersOut, float alpha, size_t prevPoseIndex, size_t nextPoseIndex, float dt); - void setSyncAndAccumulateTime(float dt, size_t prevPoseIndex, size_t nextPoseIndex, Triggers& triggersOut); - - virtual void setCurrentFrameInternal(float frame) override; AnimPoseVec _poses; float _alpha; - bool _sync; - float _timeScale; - - float _syncFrame = 0.0f; - float _averageLength = 0.0f; // average length of child animations in frames. QString _alphaVar; - QString _timeScaleVar; // no copies AnimBlendLinear(const AnimBlendLinear&) = delete; diff --git a/libraries/animation/src/AnimNodeLoader.cpp b/libraries/animation/src/AnimNodeLoader.cpp index 38296923e3..2a52e04e1d 100644 --- a/libraries/animation/src/AnimNodeLoader.cpp +++ b/libraries/animation/src/AnimNodeLoader.cpp @@ -225,22 +225,15 @@ static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString& static AnimNode::Pointer loadBlendLinearNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) { READ_FLOAT(alpha, jsonObj, id, jsonUrl, nullptr); - READ_BOOL(sync, jsonObj, id, jsonUrl, nullptr); - READ_FLOAT(timeScale, jsonObj, id, jsonUrl, nullptr); READ_OPTIONAL_STRING(alphaVar, jsonObj); - READ_OPTIONAL_STRING(timeScaleVar, jsonObj); - auto node = std::make_shared(id, alpha, sync, timeScale); + auto node = std::make_shared(id, alpha); if (!alphaVar.isEmpty()) { node->setAlphaVar(alphaVar); } - if (!timeScaleVar.isEmpty()) { - node->setTimeScaleVar(timeScaleVar); - } - return node; }