mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 07:22:43 +02:00
fixes the stutter in animation when observer moves
This commit is contained in:
parent
28091f5866
commit
5c2cc20313
4 changed files with 13 additions and 8 deletions
|
@ -138,11 +138,9 @@ void AnimationHandle::simulate(float deltaTime) {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: When moving the loop/frame calculations to AnimationLoop class, we changed this behavior
|
||||
// see AnimationLoop class for more details. Do we need to support clamping the endFrameIndex to
|
||||
// the max number of frames in the geometry???
|
||||
//
|
||||
// float endFrameIndex = qMin(_lastFrame, animationGeometry.animationFrames.size() - (_loop ? 0.0f : 1.0f));
|
||||
if (_animationLoop.getMaxFrameIndexHint() != animationGeometry.animationFrames.size()) {
|
||||
_animationLoop.setMaxFrameIndexHint(animationGeometry.animationFrames.size());
|
||||
}
|
||||
|
||||
// blend between the closest two frames
|
||||
applyFrame(getFrameIndex());
|
||||
|
|
|
@ -20,7 +20,8 @@ AnimationLoop::AnimationLoop() :
|
|||
_firstFrame(0.0f),
|
||||
_lastFrame(FLT_MAX),
|
||||
_running(false),
|
||||
_frameIndex(0.0f)
|
||||
_frameIndex(0.0f),
|
||||
_maxFrameIndexHint(FLT_MAX)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,7 @@ void AnimationLoop::simulate(float deltaTime) {
|
|||
|
||||
// If we knew the number of frames from the animation, we'd consider using it here
|
||||
// animationGeometry.animationFrames.size()
|
||||
float maxFrame = _lastFrame;
|
||||
float maxFrame = _maxFrameIndexHint;
|
||||
float endFrameIndex = qMin(_lastFrame, maxFrame - (_loop ? 0.0f : 1.0f));
|
||||
float startFrameIndex = qMin(_firstFrame, endFrameIndex);
|
||||
if ((!_loop && (_frameIndex < startFrameIndex || _frameIndex > endFrameIndex)) || startFrameIndex == endFrameIndex) {
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
|
||||
void setFrameIndex(float frameIndex) { _frameIndex = glm::clamp(frameIndex, _firstFrame, _lastFrame); }
|
||||
float getFrameIndex() const { return _frameIndex; }
|
||||
|
||||
void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = value; }
|
||||
float getMaxFrameIndexHint() const { return _maxFrameIndexHint; }
|
||||
|
||||
void start() { setRunning(true); }
|
||||
void stop() { setRunning(false); }
|
||||
|
@ -58,6 +61,7 @@ private:
|
|||
float _lastFrame;
|
||||
bool _running;
|
||||
float _frameIndex;
|
||||
float _maxFrameIndexHint;
|
||||
};
|
||||
|
||||
#endif // hifi_AnimationLoop_h
|
||||
|
|
|
@ -344,7 +344,9 @@ QVector<glm::quat> ModelEntityItem::getAnimationFrame() {
|
|||
Animation* myAnimation = getAnimation(_animationURL);
|
||||
QVector<FBXAnimationFrame> frames = myAnimation->getFrames();
|
||||
int frameCount = frames.size();
|
||||
|
||||
if (_animationLoop.getMaxFrameIndexHint() != frameCount) {
|
||||
_animationLoop.setMaxFrameIndexHint(frameCount);
|
||||
}
|
||||
if (frameCount > 0) {
|
||||
int animationFrameIndex = (int)(glm::floor(getAnimationFrameIndex())) % frameCount;
|
||||
if (animationFrameIndex < 0 || animationFrameIndex > frameCount) {
|
||||
|
|
Loading…
Reference in a new issue