mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Removed sync and timescale from AnimBlendLinear node.
AnimBlendLinearMove will now be used instead.
This commit is contained in:
parent
a66f31bb20
commit
8689170415
4 changed files with 4 additions and 87 deletions
|
@ -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": [
|
||||
|
|
|
@ -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<float> offsets(_children.size(), 0.0f);
|
||||
std::vector<float> 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<AnimClip>(_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<AnimClip>(_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<AnimClip>(_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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<AnimBlendLinear>(id, alpha, sync, timeScale);
|
||||
auto node = std::make_shared<AnimBlendLinear>(id, alpha);
|
||||
|
||||
if (!alphaVar.isEmpty()) {
|
||||
node->setAlphaVar(alphaVar);
|
||||
}
|
||||
|
||||
if (!timeScaleVar.isEmpty()) {
|
||||
node->setTimeScaleVar(timeScaleVar);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue