mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:50:38 +02:00
AnimClip & accumulateTime smoother looping anims
Looping animations should have an extra frame of interpolation between the start and end frames.
This commit is contained in:
parent
8e7e94c501
commit
073cec41c4
2 changed files with 11 additions and 7 deletions
|
@ -47,16 +47,17 @@ const AnimPoseVec& AnimClip::evaluate(const AnimVariantMap& animVars, float dt,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_anim.size()) {
|
if (_anim.size()) {
|
||||||
int frameCount = _anim.size();
|
|
||||||
|
|
||||||
int prevIndex = (int)glm::floor(_frame);
|
int prevIndex = (int)glm::floor(_frame);
|
||||||
int nextIndex = (int)glm::ceil(_frame);
|
int nextIndex;
|
||||||
if (_loopFlag && nextIndex >= frameCount) {
|
if (_loopFlag && _frame >= _endFrame) {
|
||||||
nextIndex = 0;
|
nextIndex = (int)glm::ceil(_startFrame);
|
||||||
|
} else {
|
||||||
|
nextIndex = (int)glm::ceil(_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// It can be quite possible for the user to set _startFrame and _endFrame to
|
// It can be quite possible for the user to set _startFrame and _endFrame to
|
||||||
// values before or past valid ranges. We clamp the frames here.
|
// values before or past valid ranges. We clamp the frames here.
|
||||||
|
int frameCount = _anim.size();
|
||||||
prevIndex = std::min(std::max(0, prevIndex), frameCount - 1);
|
prevIndex = std::min(std::max(0, prevIndex), frameCount - 1);
|
||||||
nextIndex = std::min(std::max(0, nextIndex), frameCount - 1);
|
nextIndex = std::min(std::max(0, nextIndex), frameCount - 1);
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ float accumulateTime(float startFrame, float endFrame, float timeScale, float cu
|
||||||
|
|
||||||
float frame = currentFrame;
|
float frame = currentFrame;
|
||||||
const float clampedStartFrame = std::min(startFrame, endFrame);
|
const float clampedStartFrame = std::min(startFrame, endFrame);
|
||||||
if (clampedStartFrame == endFrame) {
|
if (fabsf(clampedStartFrame - endFrame) < 1.0f) {
|
||||||
// when clampedStartFrame >= endFrame
|
|
||||||
frame = endFrame;
|
frame = endFrame;
|
||||||
} else if (timeScale > 0.0f) {
|
} else if (timeScale > 0.0f) {
|
||||||
// accumulate time, keeping track of loops and end of animation events.
|
// accumulate time, keeping track of loops and end of animation events.
|
||||||
|
@ -38,6 +37,10 @@ float accumulateTime(float startFrame, float endFrame, float timeScale, float cu
|
||||||
float framesRemaining = (dt * timeScale) * FRAMES_PER_SECOND;
|
float framesRemaining = (dt * timeScale) * FRAMES_PER_SECOND;
|
||||||
while (framesRemaining > 0.0f) {
|
while (framesRemaining > 0.0f) {
|
||||||
float framesTillEnd = endFrame - frame;
|
float framesTillEnd = endFrame - frame;
|
||||||
|
// when looping, add one frame between start and end.
|
||||||
|
if (loopFlag) {
|
||||||
|
framesTillEnd += 1.0f;
|
||||||
|
}
|
||||||
if (framesRemaining >= framesTillEnd) {
|
if (framesRemaining >= framesTillEnd) {
|
||||||
if (loopFlag) {
|
if (loopFlag) {
|
||||||
// anim loop
|
// anim loop
|
||||||
|
|
Loading…
Reference in a new issue