From 663b9c393ed0fea62e2280793ad147cfd03c5deb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Dec 2014 12:43:34 -0800 Subject: [PATCH 1/2] add debugging --- libraries/entities/src/ModelEntityItem.cpp | 9 +++++++++ libraries/entities/src/ModelEntityItem.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index b9bf75178f..ab5a1ee2a9 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -402,6 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) { _animationURL = url; } +void ModelEntityItem::setAnimationFrameIndex(float value) { + if (isAnimatingSomething()) { + qDebug() << "ModelEntityItem::setAnimationFrameIndex()"; + qDebug() << " value:" << value; + qDebug() << " was:" << _animationLoop.getFrameIndex(); + } + _animationLoop.setFrameIndex(value); +} + void ModelEntityItem::setAnimationSettings(const QString& value) { // the animations setting is a JSON string that may contain various animation settings. // if it includes fps, frameIndex, or running, those values will be parsed out and diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 6b4ca2416a..3cf2df899d 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -75,7 +75,7 @@ public: void setModelURL(const QString& url) { _modelURL = url; } void setAnimationURL(const QString& url); static const float DEFAULT_ANIMATION_FRAME_INDEX; - void setAnimationFrameIndex(float value) { _animationLoop.setFrameIndex(value); } + void setAnimationFrameIndex(float value); void setAnimationSettings(const QString& value); static const bool DEFAULT_ANIMATION_IS_PLAYING; From a0ec2ddfe96b845b467ccb47beb18ee082d71542 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 29 Dec 2014 21:07:04 -0800 Subject: [PATCH 2/2] clamp frame index between 0 and 100,000 --- libraries/animation/src/AnimationLoop.cpp | 9 +++++---- libraries/animation/src/AnimationLoop.h | 8 +++++--- libraries/entities/src/ModelEntityItem.cpp | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libraries/animation/src/AnimationLoop.cpp b/libraries/animation/src/AnimationLoop.cpp index 75a3cdd338..e60df1eaf9 100644 --- a/libraries/animation/src/AnimationLoop.cpp +++ b/libraries/animation/src/AnimationLoop.cpp @@ -12,16 +12,18 @@ #include "AnimationCache.h" #include "AnimationLoop.h" +const float AnimationLoop::MAXIMUM_POSSIBLE_FRAME = 100000.0f; + AnimationLoop::AnimationLoop() : _fps(30.0f), _loop(false), _hold(false), _startAutomatically(false), _firstFrame(0.0f), - _lastFrame(FLT_MAX), + _lastFrame(MAXIMUM_POSSIBLE_FRAME), _running(false), _frameIndex(0.0f), - _maxFrameIndexHint(FLT_MAX) + _maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME) { } @@ -53,10 +55,9 @@ AnimationLoop::AnimationLoop(float fps, bool loop, bool hold, bool startAutomati void AnimationLoop::simulate(float deltaTime) { _frameIndex += deltaTime * _fps; - // If we knew the number of frames from the animation, we'd consider using it here // animationGeometry.animationFrames.size() - float maxFrame = _maxFrameIndexHint; + 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) { diff --git a/libraries/animation/src/AnimationLoop.h b/libraries/animation/src/AnimationLoop.h index aff2cd86ee..d4537c4656 100644 --- a/libraries/animation/src/AnimationLoop.h +++ b/libraries/animation/src/AnimationLoop.h @@ -16,6 +16,8 @@ class AnimationDetails; class AnimationLoop { public: + static const float MAXIMUM_POSSIBLE_FRAME; + AnimationLoop(); AnimationLoop(const AnimationDetails& animationDetails); AnimationLoop(float fps, bool loop, bool hold, bool startAutomatically, float firstFrame, @@ -33,10 +35,10 @@ public: void setStartAutomatically(bool startAutomatically); bool getStartAutomatically() const { return _startAutomatically; } - void setFirstFrame(float firstFrame) { _firstFrame = firstFrame; } + void setFirstFrame(float firstFrame) { _firstFrame = glm::clamp(firstFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getFirstFrame() const { return _firstFrame; } - void setLastFrame(float lastFrame) { _lastFrame = lastFrame; } + void setLastFrame(float lastFrame) { _lastFrame = glm::clamp(lastFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getLastFrame() const { return _lastFrame; } void setRunning(bool running); @@ -45,7 +47,7 @@ public: void setFrameIndex(float frameIndex) { _frameIndex = glm::clamp(frameIndex, _firstFrame, _lastFrame); } float getFrameIndex() const { return _frameIndex; } - void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = value; } + void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = glm::clamp(value, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getMaxFrameIndexHint() const { return _maxFrameIndexHint; } void start() { setRunning(true); } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 28dcbc44ca..0989068f2a 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -402,11 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) { } void ModelEntityItem::setAnimationFrameIndex(float value) { +#ifdef WANT_DEBUG if (isAnimatingSomething()) { qDebug() << "ModelEntityItem::setAnimationFrameIndex()"; qDebug() << " value:" << value; qDebug() << " was:" << _animationLoop.getFrameIndex(); + qDebug() << " model URL:" << getModelURL(); + qDebug() << " animation URL:" << getAnimationURL(); } +#endif _animationLoop.setFrameIndex(value); } @@ -425,6 +429,17 @@ void ModelEntityItem::setAnimationSettings(const QString& value) { if (settingsMap.contains("frameIndex")) { float frameIndex = settingsMap["frameIndex"].toFloat(); +#ifdef WANT_DEBUG + if (isAnimatingSomething()) { + qDebug() << "ModelEntityItem::setAnimationSettings() calling setAnimationFrameIndex()..."; + qDebug() << " model URL:" << getModelURL(); + qDebug() << " animation URL:" << getAnimationURL(); + qDebug() << " settings:" << value; + qDebug() << " settingsMap[frameIndex]:" << settingsMap["frameIndex"]; + qDebug(" frameIndex: %20.5f", frameIndex); + } +#endif + setAnimationFrameIndex(frameIndex); }