From e13a74213c0f51f75c89caaaffc6655bd515a02c Mon Sep 17 00:00:00 2001 From: amantley Date: Mon, 6 Nov 2017 17:29:19 -0800 Subject: [PATCH 01/20] this is holder spot to put avatar entity animation code --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 7db19704b4..3959bf0bf0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -979,6 +979,8 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } + //this a spot to work on the avatar npc in my branch + QVector jointsData; const QVector& frames = _animation->getFramesReference(); // NOTE: getFrames() is too heavy From af0304fd6b48122f97373f70c5d751f5c6e5c9e6 Mon Sep 17 00:00:00 2001 From: amantley Date: Thu, 9 Nov 2017 10:04:12 -0800 Subject: [PATCH 02/20] preliminary changes for the property fixes --- .../src/RenderableModelEntityItem.cpp | 38 +++++++++++++++++-- .../src/RenderableModelEntityItem.h | 2 + libraries/entities/src/ModelEntityItem.cpp | 7 ++++ libraries/entities/src/ModelEntityItem.h | 1 + 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3959bf0bf0..40e5066e2d 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -979,6 +979,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } + //added by angus //this a spot to work on the avatar npc in my branch QVector jointsData; @@ -989,6 +990,19 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } + //get entity model anim props + bool isLooping = entity->getAnimationLoop(); + int firstFrame = entity->getAnimationFirstFrame(); + int lastFrame = entity->getAnimationLastFrame(); + bool isHolding = entity->getAnimationHold(); + int updatedFrameCount = frameCount; + + if ((firstFrame >= 0) && (firstFrame < lastFrame) && (lastFrame <= frameCount)) { + //length of animation in now determined by first and last frame + updatedFrameCount = lastFrame - firstFrame; + } + + if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); return; @@ -997,11 +1011,25 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto now = usecTimestampNow(); auto interval = now - _lastAnimated; _lastAnimated = now; - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + //we handle the hold animation property here + //if hold don't advance the current frame. + if (!isHolding) { + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + } { - int animationCurrentFrame = (int)(glm::floor(_currentFrame)) % frameCount; + //where are we in the currently defined animation segment? + int animationCurrentFrame = (int)(glm::floor(_currentFrame)) % updatedFrameCount; + //this starts us at the offset first frame. + animationCurrentFrame += firstFrame; + + //here we implement the looping animation property + //if we have played through the animation once then we hold on the last frame + if (!isLooping && (_currentFrame > (updatedFrameCount - 1))) { + animationCurrentFrame = updatedFrameCount + firstFrame; + } + if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) { animationCurrentFrame = 0; } @@ -1314,7 +1342,9 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if (newAnimationProperties != _renderAnimationProperties) { withWriteLock([&] { _renderAnimationProperties = newAnimationProperties; - _currentFrame = _renderAnimationProperties.getCurrentFrame(); + //if (entity->getAnimationHold()) { + // _currentFrame = _renderAnimationProperties.getCurrentFrame(); + //} }); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 0272bed575..d33976e356 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -185,6 +185,8 @@ private: bool _animating { false }; uint64_t _lastAnimated { 0 }; float _currentFrame { 0 }; + //bool _previousHold{ false }; + float _currentFramePropertyValue{ 0 }; }; diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 26f063f7cc..ae73fa684a 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -538,6 +538,13 @@ void ModelEntityItem::setAnimationLoop(bool loop) { }); } +bool ModelEntityItem::getAnimationLoop() const { + return resultWithReadLock([&] { + return _animationProperties.getLoop(); + }); +} + + void ModelEntityItem::setAnimationHold(bool hold) { withWriteLock([&] { _animationProperties.setHold(hold); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 2c3ef3aa2d..698197b1a6 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -90,6 +90,7 @@ public: bool getAnimationAllowTranslation() const { return _animationProperties.getAllowTranslation(); }; void setAnimationLoop(bool loop); + bool getAnimationLoop() const; void setAnimationHold(bool hold); bool getAnimationHold() const; From 1a06c6ef118257a97674844425ea445b968ae204 Mon Sep 17 00:00:00 2001 From: amantley Date: Fri, 10 Nov 2017 15:23:17 -0800 Subject: [PATCH 03/20] all entity animation fixes done except play animation --- .../src/RenderableModelEntityItem.cpp | 50 +++++++++++++------ .../src/RenderableModelEntityItem.h | 4 ++ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 4ebdfb7b8b..989f019980 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1012,24 +1012,33 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto now = usecTimestampNow(); auto interval = now - _lastAnimated; _lastAnimated = now; - //we handle the hold animation property here - //if hold don't advance the current frame. - if (!isHolding) { - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + + + //here we implement the looping animation property + //if we have played through the animation once then we hold on the last frame + // if (!isLooping && (_currentFrame > _endAnim)) { + //don't advance current frame!!! + + //}else{ + if( isLooping || ( _currentFrame < _endAnim ) ){ + //else advance the current frame. + //if hold or not playing don't advance the current frame. + if (!isHolding && entity->getAnimationIsPlaying()) { + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + } } { //where are we in the currently defined animation segment? - int animationCurrentFrame = (int)(glm::floor(_currentFrame)) % updatedFrameCount; - //this starts us at the offset first frame. - animationCurrentFrame += firstFrame; + int animationCurrentFrame = (int)(glm::floor(_currentFrame - _renderAnimationProperties.getFirstFrame())) % updatedFrameCount; + //this gives us the absolute frame value to use by adding the first frame value. + animationCurrentFrame += _renderAnimationProperties.getFirstFrame(); + - //here we implement the looping animation property - //if we have played through the animation once then we hold on the last frame - if (!isLooping && (_currentFrame > (updatedFrameCount - 1))) { - animationCurrentFrame = updatedFrameCount + firstFrame; - } + + + if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) { animationCurrentFrame = 0; @@ -1352,10 +1361,19 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce auto newAnimationProperties = entity->getAnimationProperties(); if (newAnimationProperties != _renderAnimationProperties) { withWriteLock([&] { + if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { + _currentFrame = newAnimationProperties.getCurrentFrame(); + _endAnim = (_currentFrame - 1) + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())); + //qCDebug(entitiesrenderer) << "reset current frame" << _endAnim; + } + if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { + //set the end of animation relative to the current frame + //qCDebug(entitiesrenderer) << "turned off looping"; + float startOffset = newAnimationProperties.getCurrentFrame() - newAnimationProperties.getFirstFrame(); + float posRelativeToStart = (_currentFrame - newAnimationProperties.getFirstFrame()) - startOffset; + _endAnim = (_currentFrame - 1) + (((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - ((int)(glm::floor(posRelativeToStart)) % ((int)newAnimationProperties.getLastFrame() - (int)newAnimationProperties.getFirstFrame()))); + } _renderAnimationProperties = newAnimationProperties; - //if (entity->getAnimationHold()) { - // _currentFrame = _renderAnimationProperties.getCurrentFrame(); - //} }); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index d33976e356..65b915465c 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -187,6 +187,10 @@ private: float _currentFrame { 0 }; //bool _previousHold{ false }; float _currentFramePropertyValue{ 0 }; + float _firstFramePropertyValue{ 0 }; + float _lastFramePropertyValue{ 0 }; + bool _stopLoop{ false }; + float _endAnim{ 0 }; }; From 3f7a9e97039eb5e5e58d051c0af7384aded17e26 Mon Sep 17 00:00:00 2001 From: amantley Date: Fri, 10 Nov 2017 15:36:57 -0800 Subject: [PATCH 04/20] all entity animation fixes including the animation play reset --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 989f019980..3ed0bdfc43 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1364,6 +1364,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { _currentFrame = newAnimationProperties.getCurrentFrame(); _endAnim = (_currentFrame - 1) + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())); + _lastAnimated = 0; //qCDebug(entitiesrenderer) << "reset current frame" << _endAnim; } if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { From 842cddde88603469e5791ded31682d244010ba9a Mon Sep 17 00:00:00 2001 From: amantley Date: Mon, 13 Nov 2017 11:58:49 -0800 Subject: [PATCH 05/20] Deleted new members of RenderableModelEntity.h that were not necessary to implement the loop,hold,play properties for an entity animationq --- libraries/entities-renderer/src/RenderableModelEntityItem.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 65b915465c..16892ce3e0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -185,11 +185,6 @@ private: bool _animating { false }; uint64_t _lastAnimated { 0 }; float _currentFrame { 0 }; - //bool _previousHold{ false }; - float _currentFramePropertyValue{ 0 }; - float _firstFramePropertyValue{ 0 }; - float _lastFramePropertyValue{ 0 }; - bool _stopLoop{ false }; float _endAnim{ 0 }; }; From cc43d8115c3fff02e5aa0d878f0eeabf427bb248 Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 15 Nov 2017 17:41:33 -0800 Subject: [PATCH 06/20] In response to bug in the original PR, in RenderModelEntityItem.cpp I made a change in the handling of the boundary cases for the first and last frame properties. Also deleted some extraneous comments. --- .../src/RenderableModelEntityItem.cpp | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3ed0bdfc43..aedc649470 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -980,8 +980,6 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } - //added by angus - //this a spot to work on the avatar npc in my branch QVector jointsData; @@ -1000,7 +998,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { if ((firstFrame >= 0) && (firstFrame < lastFrame) && (lastFrame <= frameCount)) { //length of animation in now determined by first and last frame - updatedFrameCount = lastFrame - firstFrame; + updatedFrameCount = (lastFrame - firstFrame + 1); } @@ -1016,14 +1014,12 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { //here we implement the looping animation property //if we have played through the animation once then we hold on the last frame - // if (!isLooping && (_currentFrame > _endAnim)) { - //don't advance current frame!!! - - //}else{ + if( isLooping || ( _currentFrame < _endAnim ) ){ //else advance the current frame. //if hold or not playing don't advance the current frame. - if (!isHolding && entity->getAnimationIsPlaying()) { + //also if the animFrame is outside of first or last frame then don't advance the motion. + if (!isHolding && entity->getAnimationIsPlaying() && !( _renderAnimationProperties.getCurrentFrame() > _renderAnimationProperties.getLastFrame() ) && !( _renderAnimationProperties.getCurrentFrame() < _renderAnimationProperties.getFirstFrame() ) ) { float deltaTime = (float)interval / (float)USECS_PER_SECOND; _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); } @@ -1362,17 +1358,14 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if (newAnimationProperties != _renderAnimationProperties) { withWriteLock([&] { if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { - _currentFrame = newAnimationProperties.getCurrentFrame(); - _endAnim = (_currentFrame - 1) + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())); - _lastAnimated = 0; - //qCDebug(entitiesrenderer) << "reset current frame" << _endAnim; - } - if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { - //set the end of animation relative to the current frame - //qCDebug(entitiesrenderer) << "turned off looping"; - float startOffset = newAnimationProperties.getCurrentFrame() - newAnimationProperties.getFirstFrame(); - float posRelativeToStart = (_currentFrame - newAnimationProperties.getFirstFrame()) - startOffset; - _endAnim = (_currentFrame - 1) + (((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - ((int)(glm::floor(posRelativeToStart)) % ((int)newAnimationProperties.getLastFrame() - (int)newAnimationProperties.getFirstFrame()))); + if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { + _currentFrame = newAnimationProperties.getCurrentFrame(); + _endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() ); + _lastAnimated = 0; + } + }else if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { + int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1); + _endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; } _renderAnimationProperties = newAnimationProperties; }); From 881b22ab159d637561971b63596d7e176cf5552e Mon Sep 17 00:00:00 2001 From: amantley Date: Thu, 16 Nov 2017 12:41:56 -0800 Subject: [PATCH 07/20] added update function to modelEntityItem.cpp --- .../src/RenderableModelEntityItem.cpp | 1 + libraries/entities/src/ModelEntityItem.cpp | 23 +++++++++++++++++++ libraries/entities/src/ModelEntityItem.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index aedc649470..e78e609699 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1356,6 +1356,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce // make a copy of the animation properites auto newAnimationProperties = entity->getAnimationProperties(); if (newAnimationProperties != _renderAnimationProperties) { + qCDebug(entitiesrenderer) << "this is where the change is currently handled in the rendering code"; withWriteLock([&] { if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index ae73fa684a..515d76a9b3 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -186,6 +186,29 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit } +//angus +/* +void ModelEntityItem::update(const quint64& now) { + + //put something here + qCDebug(entities) << "model entity item update"; + + +} + +bool ModelEntityItem::needsToCallUpdate() const { + + + //put something here + qCDebug(entities) << "needs to call update"; + return true; +} +*/ +//angus + + + + void ModelEntityItem::debugDump() const { qCDebug(entities) << "ModelEntityItem id:" << getEntityItemID(); qCDebug(entities) << " edited ago:" << getEditedAgo(); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 698197b1a6..4f13fbdf6a 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -46,8 +46,10 @@ public: EntityPropertyFlags& propertyFlags, bool overwriteLocalData, bool& somethingChanged) override; + //angus //virtual void update(const quint64& now) override; //virtual bool needsToCallUpdate() const override; + //angus virtual void debugDump() const override; void setShapeType(ShapeType type) override; From 20fd893b47dfd3b2214c830fd56646c81393e8a6 Mon Sep 17 00:00:00 2001 From: amantley Date: Thu, 16 Nov 2017 18:38:28 -0800 Subject: [PATCH 08/20] Starting to implement the update function to ModelEntityItem_cpp Also put access to the currently playing frame in RenderableModelEntityItem_cpp --- .../src/RenderableModelEntityItem.cpp | 4 +- .../entities/src/AnimationPropertyGroup.cpp | 12 ++++++ .../entities/src/AnimationPropertyGroup.h | 1 + libraries/entities/src/ModelEntityItem.cpp | 42 +++++++++++++++---- libraries/entities/src/ModelEntityItem.h | 10 ++++- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e78e609699..2ba8a7a45f 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -971,9 +971,6 @@ void ModelEntityRenderer::onRemoveFromSceneTyped(const TypedEntityPointer& entit entity->setModel({}); } -bool operator!=(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b) { - return !(a == b); -} void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { if (!_animation || !_animation->isLoaded()) { @@ -1357,6 +1354,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce auto newAnimationProperties = entity->getAnimationProperties(); if (newAnimationProperties != _renderAnimationProperties) { qCDebug(entitiesrenderer) << "this is where the change is currently handled in the rendering code"; + qCDebug(entitiesrenderer) << "getting the currently playing frame from the modelentityitem update" << entity->getCurrentlyPlayingFrame(); withWriteLock([&] { if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { diff --git a/libraries/entities/src/AnimationPropertyGroup.cpp b/libraries/entities/src/AnimationPropertyGroup.cpp index d6a2937553..c871849064 100644 --- a/libraries/entities/src/AnimationPropertyGroup.cpp +++ b/libraries/entities/src/AnimationPropertyGroup.cpp @@ -31,6 +31,18 @@ bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b (a._hold == b._hold); } +bool operator!=(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b) { + return + (a._url != b._url) || + (a._currentFrame != b._currentFrame) || + (a._running != b._running) || + (a._loop != b._loop) || + (a._firstFrame != b._firstFrame) || + (a._lastFrame != b._lastFrame) || + (a._hold != b._hold); +} + + void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const { COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_URL, Animation, animation, URL, url); COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_ALLOW_TRANSLATION, Animation, animation, AllowTranslation, allowTranslation); diff --git a/libraries/entities/src/AnimationPropertyGroup.h b/libraries/entities/src/AnimationPropertyGroup.h index affa960d66..54d4ced92f 100644 --- a/libraries/entities/src/AnimationPropertyGroup.h +++ b/libraries/entities/src/AnimationPropertyGroup.h @@ -89,6 +89,7 @@ public: protected: friend bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b); + friend bool operator!=(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b); void setFromOldAnimationSettings(const QString& value); }; diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 515d76a9b3..c24efa8eec 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -187,12 +187,33 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit //angus -/* + void ModelEntityItem::update(const quint64& now) { //put something here - qCDebug(entities) << "model entity item update"; + //qCDebug(entities) << "model entity item update" << getName() << " " << getEntityItemID(); + { + auto currentAnimationProperties = this->getAnimationProperties(); + + if (_previousAnimationProperties != currentAnimationProperties) { + qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code"; + withWriteLock([&] { + //if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { + // if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { + // _currentFrame = newAnimationProperties.getCurrentFrame(); + // _endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() ); + //_lastAnimated = 0; + // } + //}else if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { + // int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1); + // _endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; + // } + _previousAnimationProperties = currentAnimationProperties; + }); + } + + } } @@ -200,10 +221,10 @@ bool ModelEntityItem::needsToCallUpdate() const { //put something here - qCDebug(entities) << "needs to call update"; + //qCDebug(entities) << "needs to call update"; return true; } -*/ + //angus @@ -603,8 +624,9 @@ float ModelEntityItem::getAnimationLastFrame() const { return _animationProperties.getLastFrame(); }); } +//angus change bool ModelEntityItem::getAnimationIsPlaying() const { - return resultWithReadLock([&] { + return resultWithReadLock([&] { return _animationProperties.getRunning(); }); } @@ -614,11 +636,17 @@ float ModelEntityItem::getAnimationCurrentFrame() const { return _animationProperties.getCurrentFrame(); }); } - +//angus change bool ModelEntityItem::isAnimatingSomething() const { - return resultWithReadLock([&] { + return resultWithReadLock([&] { return !_animationProperties.getURL().isEmpty() && _animationProperties.getRunning() && (_animationProperties.getFPS() != 0.0f); }); } + +float ModelEntityItem::getCurrentlyPlayingFrame() const { + return resultWithReadLock([&] { + return _currentlyPlayingFrame; + }); +} diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 4f13fbdf6a..c9c33e10c9 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -47,8 +47,8 @@ public: bool& somethingChanged) override; //angus - //virtual void update(const quint64& now) override; - //virtual bool needsToCallUpdate() const override; + virtual void update(const quint64& now) override; + virtual bool needsToCallUpdate() const override; //angus virtual void debugDump() const override; @@ -107,6 +107,8 @@ public: float getAnimationCurrentFrame() const; bool isAnimatingSomething() const; + float getCurrentlyPlayingFrame() const; + static const QString DEFAULT_TEXTURES; const QString getTextures() const; void setTextures(const QString& textures); @@ -163,6 +165,10 @@ protected: QString _textures; ShapeType _shapeType = SHAPE_TYPE_NONE; + +private: + float _currentlyPlayingFrame{ 0 }; + AnimationPropertyGroup _previousAnimationProperties; }; #endif // hifi_ModelEntityItem_h From 013d16cee9e0d30c05458e76685ae8675549efba Mon Sep 17 00:00:00 2001 From: amantley Date: Fri, 17 Nov 2017 18:37:54 -0800 Subject: [PATCH 09/20] this is the change to add a property for the currentframeplaying --- .../src/RenderableModelEntityItem.cpp | 27 +++++++-- .../src/RenderableModelEntityItem.h | 4 +- .../entities/src/AnimationPropertyGroup.cpp | 16 +++++ .../entities/src/AnimationPropertyGroup.h | 1 + .../entities/src/EntityItemProperties.cpp | 1 + libraries/entities/src/EntityPropertyFlags.h | 2 + libraries/entities/src/ModelEntityItem.cpp | 60 +++++++++++++++---- libraries/entities/src/ModelEntityItem.h | 11 +++- 8 files changed, 102 insertions(+), 20 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 2ba8a7a45f..3176010536 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -993,12 +993,19 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { bool isHolding = entity->getAnimationHold(); int updatedFrameCount = frameCount; + //get the updated frame from the ModelEntity + auto modelAnimProperties = entity->getAnimationProperties(); + withWriteLock([&] { + _currentFrame = modelAnimProperties.getCurrentlyPlayingFrame(); + }); + qCDebug(entitiesrenderer) << "the client frame count is the following " << _currentFrame; + if ((firstFrame >= 0) && (firstFrame < lastFrame) && (lastFrame <= frameCount)) { //length of animation in now determined by first and last frame updatedFrameCount = (lastFrame - firstFrame + 1); } - + /* if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); return; @@ -1008,7 +1015,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto interval = now - _lastAnimated; _lastAnimated = now; - + //here we implement the looping animation property //if we have played through the animation once then we hold on the last frame @@ -1021,12 +1028,12 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); } } - + */ { //where are we in the currently defined animation segment? - int animationCurrentFrame = (int)(glm::floor(_currentFrame - _renderAnimationProperties.getFirstFrame())) % updatedFrameCount; + int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount; //this gives us the absolute frame value to use by adding the first frame value. - animationCurrentFrame += _renderAnimationProperties.getFirstFrame(); + animationCurrentFrame += firstFrame; @@ -1347,7 +1354,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if (model->getRenderItemsNeedUpdate()) { model->updateRenderItems(); } - + /* { DETAILED_PROFILE_RANGE(simulation_physics, "CheckAnimation"); // make a copy of the animation properites @@ -1370,6 +1377,14 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce }); } } + */ + //angus + { + + //_currentFrame = entity->getCurrentlyPlayingFrame(); + } + //angus + if (_animating) { DETAILED_PROFILE_RANGE(simulation_physics, "Animate"); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 16892ce3e0..3a0c5c506b 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -183,9 +183,9 @@ private: bool _marketplaceEntity { false }; bool _shouldHighlight { false }; bool _animating { false }; - uint64_t _lastAnimated { 0 }; + //uint64_t _lastAnimated { 0 }; float _currentFrame { 0 }; - float _endAnim{ 0 }; + //float _endAnim{ 0 }; }; diff --git a/libraries/entities/src/AnimationPropertyGroup.cpp b/libraries/entities/src/AnimationPropertyGroup.cpp index c871849064..5f5d68be24 100644 --- a/libraries/entities/src/AnimationPropertyGroup.cpp +++ b/libraries/entities/src/AnimationPropertyGroup.cpp @@ -53,6 +53,7 @@ void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desire COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_FIRST_FRAME, Animation, animation, FirstFrame, firstFrame); COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_LAST_FRAME, Animation, animation, LastFrame, lastFrame); COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_HOLD, Animation, animation, Hold, hold); + COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, Animation, animation, CurrentlyPlayingFrame, currentlyPlayingFrame); } @@ -73,6 +74,9 @@ void AnimationPropertyGroup::copyFromScriptValue(const QScriptValue& object, boo COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, lastFrame, float, setLastFrame); COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, hold, bool, setHold); + //angus added + COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, currentlyPlayingFrame, float, setCurrentlyPlayingFrame); + // legacy property support COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(animationFPS, float, setFPS, getFPS); COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(animationIsPlaying, bool, setRunning, getRunning); @@ -89,6 +93,7 @@ void AnimationPropertyGroup::merge(const AnimationPropertyGroup& other) { COPY_PROPERTY_IF_CHANGED(firstFrame); COPY_PROPERTY_IF_CHANGED(lastFrame); COPY_PROPERTY_IF_CHANGED(hold); + COPY_PROPERTY_IF_CHANGED(currentlyPlayingFrame); } void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { @@ -195,6 +200,8 @@ bool AnimationPropertyGroup::appendToEditPacket(OctreePacketData* packetData, APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, getFirstFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, getLastFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, getHold()); + //angus + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, getCurrentlyPlayingFrame()); return true; } @@ -216,6 +223,7 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold); + READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, float, setCurrentlyPlayingFrame); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_URL, URL); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_FPS, FPS); @@ -226,6 +234,7 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_LAST_FRAME, LastFrame); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_HOLD, Hold); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_ALLOW_TRANSLATION, AllowTranslation); + DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame); processedBytes += bytesRead; @@ -258,6 +267,7 @@ EntityPropertyFlags AnimationPropertyGroup::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_ANIMATION_LAST_FRAME, lastFrame); CHECK_PROPERTY_CHANGE(PROP_ANIMATION_HOLD, hold); CHECK_PROPERTY_CHANGE(PROP_ANIMATION_ALLOW_TRANSLATION, allowTranslation); + CHECK_PROPERTY_CHANGE(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, currentlyPlayingFrame); return changedProperties; } @@ -272,6 +282,7 @@ void AnimationPropertyGroup::getProperties(EntityItemProperties& properties) con COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, FirstFrame, getFirstFrame); COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, LastFrame, getLastFrame); COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, Hold, getHold); + COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, CurrentlyPlayingFrame, getCurrentlyPlayingFrame); } bool AnimationPropertyGroup::setProperties(const EntityItemProperties& properties) { @@ -286,6 +297,7 @@ bool AnimationPropertyGroup::setProperties(const EntityItemProperties& propertie SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, FirstFrame, firstFrame, setFirstFrame); SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, LastFrame, lastFrame, setLastFrame); SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, Hold, hold, setHold); + SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, CurrentlyPlayingFrame, currentlyPlayingFrame, setCurrentlyPlayingFrame); return somethingChanged; } @@ -301,6 +313,8 @@ EntityPropertyFlags AnimationPropertyGroup::getEntityProperties(EncodeBitstreamP requestedProperties += PROP_ANIMATION_LAST_FRAME; requestedProperties += PROP_ANIMATION_HOLD; requestedProperties += PROP_ANIMATION_ALLOW_TRANSLATION; + //angus + requestedProperties += PROP_ANIMATION_CURRENTLY_PLAYING_FRAME; return requestedProperties; } @@ -324,6 +338,7 @@ void AnimationPropertyGroup::appendSubclassData(OctreePacketData* packetData, En APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, getFirstFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, getLastFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, getHold()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, getCurrentlyPlayingFrame()); } int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, @@ -343,5 +358,6 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold); + READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, float, setCurrentlyPlayingFrame); return bytesRead; } diff --git a/libraries/entities/src/AnimationPropertyGroup.h b/libraries/entities/src/AnimationPropertyGroup.h index 54d4ced92f..8d0087b56d 100644 --- a/libraries/entities/src/AnimationPropertyGroup.h +++ b/libraries/entities/src/AnimationPropertyGroup.h @@ -86,6 +86,7 @@ public: DEFINE_PROPERTY(PROP_ANIMATION_LAST_FRAME, LastFrame, lastFrame, float, MAXIMUM_POSSIBLE_FRAME); // was animationSettings.lastFrame DEFINE_PROPERTY(PROP_ANIMATION_HOLD, Hold, hold, bool, false); // was animationSettings.hold DEFINE_PROPERTY(PROP_ANIMATION_ALLOW_TRANSLATION, AllowTranslation, allowTranslation, bool, true); + DEFINE_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame, currentlyPlayingFrame, float, 0.0f); protected: friend bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 108fc14e30..77fa1231f1 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -1148,6 +1148,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_LAST_FRAME, Animation, animation, LastFrame, lastFrame); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_HOLD, Animation, animation, Hold, hold); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_ALLOW_TRANSLATION, Animation, animation, AllowTranslation, allowTranslation); + ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, Animation, animation, CurrentlyPlayingFrame, currentlyPlayingFrame); ADD_GROUP_PROPERTY_TO_MAP(PROP_SKYBOX_COLOR, Skybox, skybox, Color, color); ADD_GROUP_PROPERTY_TO_MAP(PROP_SKYBOX_URL, Skybox, skybox, URL, url); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 35d40b669a..3b1f4d60d0 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -40,6 +40,8 @@ enum EntityPropertyList { PROP_ANIMATION_FRAME_INDEX, PROP_ANIMATION_PLAYING, PROP_ANIMATION_ALLOW_TRANSLATION, + //angus + PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, // these properties are supported by the EntityItem base class PROP_REGISTRATION_POINT, diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index c24efa8eec..67357a6905 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -199,19 +199,20 @@ void ModelEntityItem::update(const quint64& now) { if (_previousAnimationProperties != currentAnimationProperties) { qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code"; withWriteLock([&] { - //if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { - // if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { - // _currentFrame = newAnimationProperties.getCurrentFrame(); - // _endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() ); - //_lastAnimated = 0; - // } - //}else if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { - // int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1); - // _endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; - // } + if ( (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) || (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { + if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) { + _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame(); + _endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() ); + _lastAnimated = 0; + } + }else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) { + int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); + _endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; + } _previousAnimationProperties = currentAnimationProperties; }); } + updateFrameCount(); } @@ -225,6 +226,38 @@ bool ModelEntityItem::needsToCallUpdate() const { return true; } +void ModelEntityItem::updateFrameCount() { + + + if (!_lastAnimated) { + _lastAnimated = usecTimestampNow(); + return; + } + + auto now = usecTimestampNow(); + auto interval = now - _lastAnimated; + _lastAnimated = now; + + + //here we implement the looping animation property + //get entity anim props + bool isLooping = getAnimationLoop(); + int firstFrame = getAnimationFirstFrame(); + int lastFrame = getAnimationLastFrame(); + bool isHolding = getAnimationHold(); + + if (isLooping || (_currentlyPlayingFrame < _endAnim)) { + //else advance the current frame. + //if hold or not playing don't advance the current frame. + //also if the animFrame is outside of first or last frame then don't advance the motion. + if (!isHolding && getAnimationIsPlaying() && !(_previousAnimationProperties.getCurrentFrame() > _previousAnimationProperties.getLastFrame()) && !(_previousAnimationProperties.getCurrentFrame() < _previousAnimationProperties.getFirstFrame())) { + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS()); + qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame; + } + } +} + //angus @@ -650,3 +683,10 @@ float ModelEntityItem::getCurrentlyPlayingFrame() const { return _currentlyPlayingFrame; }); } + +int ModelEntityItem::getLastKnownCurrentFrame() const { + return resultWithReadLock([&] { + return _lastKnownCurrentFrame; + }); +} +//angus change \ No newline at end of file diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index c9c33e10c9..3df0ccdc36 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -17,6 +17,7 @@ #include #include "AnimationPropertyGroup.h" + class ModelEntityItem : public EntityItem { public: static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); @@ -49,6 +50,7 @@ public: //angus virtual void update(const quint64& now) override; virtual bool needsToCallUpdate() const override; + void updateFrameCount(); //angus virtual void debugDump() const override; @@ -108,6 +110,7 @@ public: bool isAnimatingSomething() const; float getCurrentlyPlayingFrame() const; + int getLastKnownCurrentFrame() const; static const QString DEFAULT_TEXTURES; const QString getTextures() const; @@ -152,7 +155,7 @@ protected: }; QVector _localJointData; - int _lastKnownCurrentFrame; + int _lastKnownCurrentFrame{-1}; rgbColor _color; QString _modelURL; @@ -167,8 +170,12 @@ protected: ShapeType _shapeType = SHAPE_TYPE_NONE; private: - float _currentlyPlayingFrame{ 0 }; + //angus + float _currentlyPlayingFrame{ -1 }; + float _endAnim{ 0 }; + uint64_t _lastAnimated{ 0 }; AnimationPropertyGroup _previousAnimationProperties; + //angus }; #endif // hifi_ModelEntityItem_h From befa0f8ab54de74211b85361565c86bd9351f138 Mon Sep 17 00:00:00 2001 From: amantley Date: Mon, 20 Nov 2017 09:11:15 -0800 Subject: [PATCH 10/20] now the update frame is only happening in the assignment client code. added setCurrentlyPlayingFrame to ModelEntityItem.cpp --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 3 ++- libraries/entities/src/ModelEntityItem.cpp | 8 ++++++++ libraries/entities/src/ModelEntityItem.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 07d8716656..42fcd9af6f 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -309,7 +309,8 @@ void EntityTreeRenderer::update(bool simulate) { PerformanceTimer perfTimer("ETRupdate"); if (_tree && !_shuttingDown) { EntityTreePointer tree = std::static_pointer_cast(_tree); - tree->update(simulate); + //angus + //tree->update(simulate); // Update the rendereable entities as needed { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 67357a6905..c6e6a7a069 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -254,6 +254,7 @@ void ModelEntityItem::updateFrameCount() { float deltaTime = (float)interval / (float)USECS_PER_SECOND; _currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS()); qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame; + setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame); } } } @@ -609,6 +610,12 @@ void ModelEntityItem::setAnimationCurrentFrame(float value) { }); } +void ModelEntityItem::setAnimationCurrentlyPlayingFrame(float value) { + withWriteLock([&] { + _animationProperties.setCurrentlyPlayingFrame(value); + }); +} + void ModelEntityItem::setAnimationLoop(bool loop) { withWriteLock([&] { _animationProperties.setLoop(loop); @@ -669,6 +676,7 @@ float ModelEntityItem::getAnimationCurrentFrame() const { return _animationProperties.getCurrentFrame(); }); } + //angus change bool ModelEntityItem::isAnimatingSomething() const { return resultWithReadLock([&] { diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 3df0ccdc36..1c1c834d82 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -87,6 +87,7 @@ public: void setAnimationURL(const QString& url); void setAnimationCurrentFrame(float value); + void setAnimationCurrentlyPlayingFrame(float value); void setAnimationIsPlaying(bool value); void setAnimationFPS(float value); From 1e5d099b06feaac93e092a4d5e70311b87258714 Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 21 Nov 2017 17:36:01 -0800 Subject: [PATCH 11/20] changed the currentlyplayingframe property so that it is updated in RenderableModelEntity.cpp now. Remains to remove everything but initializing currentlyPlayingFrame in ModelEntityRender.cpp --- .../src/RenderableModelEntityItem.cpp | 30 +++++++++---------- .../src/RenderableModelEntityItem.h | 7 +++-- .../entities/src/AnimationPropertyGroup.cpp | 9 ++++++ libraries/entities/src/ModelEntityItem.cpp | 5 +++- libraries/entities/src/ModelEntityItem.h | 2 ++ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3176010536..a3e90c925f 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -995,9 +995,13 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { //get the updated frame from the ModelEntity auto modelAnimProperties = entity->getAnimationProperties(); - withWriteLock([&] { - _currentFrame = modelAnimProperties.getCurrentlyPlayingFrame(); - }); + + + //_currentFrame = modelAnimProperties.getCurrentlyPlayingFrame(); + + //tempbool = modelAnimProperties.getRunning(); + //qCDebug(entitiesrenderer) << "is playing is: " << tempbool; + qCDebug(entitiesrenderer) << "the client frame count is the following " << _currentFrame; if ((firstFrame >= 0) && (firstFrame < lastFrame) && (lastFrame <= frameCount)) { @@ -1005,7 +1009,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { updatedFrameCount = (lastFrame - firstFrame + 1); } - /* + if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); return; @@ -1025,13 +1029,13 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { //also if the animFrame is outside of first or last frame then don't advance the motion. if (!isHolding && entity->getAnimationIsPlaying() && !( _renderAnimationProperties.getCurrentFrame() > _renderAnimationProperties.getLastFrame() ) && !( _renderAnimationProperties.getCurrentFrame() < _renderAnimationProperties.getFirstFrame() ) ) { float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + _currentlyPlayingFrame += (deltaTime * _renderAnimationProperties.getFPS()); } } - */ + { //where are we in the currently defined animation segment? - int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount; + int animationCurrentFrame = (int)(glm::floor(_currentlyPlayingFrame - firstFrame)) % updatedFrameCount; //this gives us the absolute frame value to use by adding the first frame value. animationCurrentFrame += firstFrame; @@ -1354,7 +1358,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if (model->getRenderItemsNeedUpdate()) { model->updateRenderItems(); } - /* + { DETAILED_PROFILE_RANGE(simulation_physics, "CheckAnimation"); // make a copy of the animation properites @@ -1373,17 +1377,13 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1); _endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; } + _currentlyPlayingFrame = newAnimationProperties.getCurrentlyPlayingFrame(); _renderAnimationProperties = newAnimationProperties; }); } } - */ - //angus - { - - //_currentFrame = entity->getCurrentlyPlayingFrame(); - } - //angus + //angus + if (_animating) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 3a0c5c506b..e6a970d0eb 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -183,10 +183,11 @@ private: bool _marketplaceEntity { false }; bool _shouldHighlight { false }; bool _animating { false }; - //uint64_t _lastAnimated { 0 }; + uint64_t _lastAnimated { 0 }; float _currentFrame { 0 }; - //float _endAnim{ 0 }; - + float _endAnim{ 0 }; + bool tempbool{ false }; + float _currentlyPlayingFrame{ 0 }; }; } } // namespace diff --git a/libraries/entities/src/AnimationPropertyGroup.cpp b/libraries/entities/src/AnimationPropertyGroup.cpp index 5f5d68be24..8488c6fb25 100644 --- a/libraries/entities/src/AnimationPropertyGroup.cpp +++ b/libraries/entities/src/AnimationPropertyGroup.cpp @@ -109,6 +109,7 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { bool loop = getLoop(); bool hold = getHold(); bool allowTranslation = getAllowTranslation(); + float currentlyPlayingFrame = getCurrentlyPlayingFrame(); QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8()); QJsonObject settingsAsJsonObject = settingsAsJson.object(); @@ -147,6 +148,10 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { allowTranslation = settingsMap["allowTranslation"].toBool(); } + if (settingsMap.contains("currentlyPlayingFrame")) { + currentlyPlayingFrame = settingsMap["currentlyPlayingFrame"].toFloat(); + } + setAllowTranslation(allowTranslation); setFPS(fps); setCurrentFrame(currentFrame); @@ -155,6 +160,7 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { setLastFrame(lastFrame); setLoop(loop); setHold(hold); + setCurrentlyPlayingFrame(currentlyPlayingFrame); } @@ -179,6 +185,9 @@ void AnimationPropertyGroup::listChangedProperties(QList& out) { if (allowTranslationChanged()) { out << "animation-allowTranslation"; } + if (currentlyPlayingFrameChanged()) { + out << "animation-currentlyPlayingFrame"; + } } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index c6e6a7a069..784193d3d5 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -209,9 +209,10 @@ void ModelEntityItem::update(const quint64& now) { int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); _endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; } - _previousAnimationProperties = currentAnimationProperties; + //_previousAnimationProperties = currentAnimationProperties; }); } + _previousAnimationProperties = currentAnimationProperties; updateFrameCount(); } @@ -256,6 +257,7 @@ void ModelEntityItem::updateFrameCount() { qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame; setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame); } + } } @@ -611,6 +613,7 @@ void ModelEntityItem::setAnimationCurrentFrame(float value) { } void ModelEntityItem::setAnimationCurrentlyPlayingFrame(float value) { + _dirtyFlags |= Simulation::DIRTY_UPDATEABLE; withWriteLock([&] { _animationProperties.setCurrentlyPlayingFrame(value); }); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 1c1c834d82..2e901ed318 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -176,6 +176,8 @@ private: float _endAnim{ 0 }; uint64_t _lastAnimated{ 0 }; AnimationPropertyGroup _previousAnimationProperties; + bool _propTestFlag{ true }; + bool _propTestFlag2{ true }; //angus }; From fdf5139a7409c231598d59e4350b85415e062243 Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 22 Nov 2017 17:52:13 -0800 Subject: [PATCH 12/20] everything now works with an atomic start time property. but now I will get rid of this and use current frame instead --- .../src/RenderableModelEntityItem.cpp | 33 ++++++++--- .../src/RenderableModelEntityItem.h | 2 +- .../entities/src/AnimationPropertyGroup.cpp | 10 ++-- .../entities/src/AnimationPropertyGroup.h | 2 +- libraries/entities/src/ModelEntityItem.cpp | 55 ++++++++++++------- libraries/entities/src/ModelEntityItem.h | 6 +- 6 files changed, 70 insertions(+), 38 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index a3e90c925f..80aba9deba 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -997,7 +997,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto modelAnimProperties = entity->getAnimationProperties(); - //_currentFrame = modelAnimProperties.getCurrentlyPlayingFrame(); + //_currentFrame = modelAnimProperties.getCurrentFrame(); //tempbool = modelAnimProperties.getRunning(); //qCDebug(entitiesrenderer) << "is playing is: " << tempbool; @@ -1016,26 +1016,44 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { } auto now = usecTimestampNow(); - auto interval = now - _lastAnimated; + + //find out how long it has been since this animation started. + auto interval = now - _currentlyPlayingFrame; + //auto interval = now - _lastAnimated; _lastAnimated = now; + //new global start time code + float nowTime = (float)interval / (float)USECS_PER_SECOND; + float oldCurrentFrame = _currentFrame; + _currentFrame = _renderAnimationProperties.getCurrentFrame() + (nowTime * _renderAnimationProperties.getFPS()); + + //here we implement the looping animation property //if we have played through the animation once then we hold on the last frame - if( isLooping || ( _currentFrame < _endAnim ) ){ + if( isLooping || (_currentFrame < _endAnim ) ){ //else advance the current frame. //if hold or not playing don't advance the current frame. //also if the animFrame is outside of first or last frame then don't advance the motion. if (!isHolding && entity->getAnimationIsPlaying() && !( _renderAnimationProperties.getCurrentFrame() > _renderAnimationProperties.getLastFrame() ) && !( _renderAnimationProperties.getCurrentFrame() < _renderAnimationProperties.getFirstFrame() ) ) { - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentlyPlayingFrame += (deltaTime * _renderAnimationProperties.getFPS()); + //float deltaTime = (float)interval / (float)USECS_PER_SECOND; + //_currentlyPlayingFrame += (deltaTime * _renderAnimationProperties.getFPS()); + //do nothing } + else { + //use old currentFrame + _currentFrame = oldCurrentFrame; + } + } + else { + //make current frame the endanim frame + _currentFrame = _endAnim; } { //where are we in the currently defined animation segment? - int animationCurrentFrame = (int)(glm::floor(_currentlyPlayingFrame - firstFrame)) % updatedFrameCount; + int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount; //this gives us the absolute frame value to use by adding the first frame value. animationCurrentFrame += firstFrame; @@ -1369,7 +1387,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce withWriteLock([&] { if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { - _currentFrame = newAnimationProperties.getCurrentFrame(); + _currentFrame = newAnimationProperties.getCurrentFrame();// +((float)newAnimationProperties.getCurrentlyPlayingFrame() / (float)USECS_PER_SECOND)*(newAnimationProperties.getFPS()); _endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() ); _lastAnimated = 0; } @@ -1378,6 +1396,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce _endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; } _currentlyPlayingFrame = newAnimationProperties.getCurrentlyPlayingFrame(); + qCDebug(entitiesrenderer) << "renderable update to currently playing frame " << _currentlyPlayingFrame; _renderAnimationProperties = newAnimationProperties; }); } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index e6a970d0eb..fdb0cf5d2c 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -187,7 +187,7 @@ private: float _currentFrame { 0 }; float _endAnim{ 0 }; bool tempbool{ false }; - float _currentlyPlayingFrame{ 0 }; + quint64 _currentlyPlayingFrame{ 0 }; }; } } // namespace diff --git a/libraries/entities/src/AnimationPropertyGroup.cpp b/libraries/entities/src/AnimationPropertyGroup.cpp index 8488c6fb25..67de381d1b 100644 --- a/libraries/entities/src/AnimationPropertyGroup.cpp +++ b/libraries/entities/src/AnimationPropertyGroup.cpp @@ -75,7 +75,7 @@ void AnimationPropertyGroup::copyFromScriptValue(const QScriptValue& object, boo COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, hold, bool, setHold); //angus added - COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, currentlyPlayingFrame, float, setCurrentlyPlayingFrame); + COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, currentlyPlayingFrame, quint64, setCurrentlyPlayingFrame); // legacy property support COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(animationFPS, float, setFPS, getFPS); @@ -109,7 +109,7 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { bool loop = getLoop(); bool hold = getHold(); bool allowTranslation = getAllowTranslation(); - float currentlyPlayingFrame = getCurrentlyPlayingFrame(); + quint64 currentlyPlayingFrame = getCurrentlyPlayingFrame(); QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8()); QJsonObject settingsAsJsonObject = settingsAsJson.object(); @@ -149,7 +149,7 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { } if (settingsMap.contains("currentlyPlayingFrame")) { - currentlyPlayingFrame = settingsMap["currentlyPlayingFrame"].toFloat(); + currentlyPlayingFrame = settingsMap["currentlyPlayingFrame"].toULongLong(); } setAllowTranslation(allowTranslation); @@ -232,7 +232,7 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold); - READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, float, setCurrentlyPlayingFrame); + READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, quint64, setCurrentlyPlayingFrame); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_URL, URL); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_FPS, FPS); @@ -367,6 +367,6 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold); - READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, float, setCurrentlyPlayingFrame); + READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, quint64, setCurrentlyPlayingFrame); return bytesRead; } diff --git a/libraries/entities/src/AnimationPropertyGroup.h b/libraries/entities/src/AnimationPropertyGroup.h index 8d0087b56d..1a3da52684 100644 --- a/libraries/entities/src/AnimationPropertyGroup.h +++ b/libraries/entities/src/AnimationPropertyGroup.h @@ -86,7 +86,7 @@ public: DEFINE_PROPERTY(PROP_ANIMATION_LAST_FRAME, LastFrame, lastFrame, float, MAXIMUM_POSSIBLE_FRAME); // was animationSettings.lastFrame DEFINE_PROPERTY(PROP_ANIMATION_HOLD, Hold, hold, bool, false); // was animationSettings.hold DEFINE_PROPERTY(PROP_ANIMATION_ALLOW_TRANSLATION, AllowTranslation, allowTranslation, bool, true); - DEFINE_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame, currentlyPlayingFrame, float, 0.0f); + DEFINE_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame, currentlyPlayingFrame, quint64, 0); protected: friend bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b); diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 784193d3d5..bdf4f6f3f9 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -200,19 +200,23 @@ void ModelEntityItem::update(const quint64& now) { qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code"; withWriteLock([&] { if ( (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) || (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { - if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) { - _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame(); - _endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() ); - _lastAnimated = 0; - } - }else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) { - int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); - _endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; + // if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) { + // _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame(); + //_endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() ); + //_lastAnimated = 0; + // } + setAnimationCurrentlyPlayingFrame(usecTimestampNow()); } - //_previousAnimationProperties = currentAnimationProperties; + //else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) { + // int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); + //_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; + //} + _previousAnimationProperties = currentAnimationProperties; }); + + qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, currently playing frame is: " << currentAnimationProperties.getCurrentlyPlayingFrame(); } - _previousAnimationProperties = currentAnimationProperties; + //_previousAnimationProperties = currentAnimationProperties; updateFrameCount(); } @@ -229,36 +233,45 @@ bool ModelEntityItem::needsToCallUpdate() const { void ModelEntityItem::updateFrameCount() { - + if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); return; } + auto now = usecTimestampNow(); - auto interval = now - _lastAnimated; - _lastAnimated = now; + + //this is now getting the time since the server started the animation. + //auto interval = now - _currentlyPlayingFrame; + //auto interval = now - _lastAnimated; + //_lastAnimated = now; + + //here we implement the looping animation property //get entity anim props + bool isLooping = getAnimationLoop(); int firstFrame = getAnimationFirstFrame(); int lastFrame = getAnimationLastFrame(); bool isHolding = getAnimationHold(); - if (isLooping || (_currentlyPlayingFrame < _endAnim)) { + //if (isLooping || (_currentFrame < _endAnim)) { //else advance the current frame. //if hold or not playing don't advance the current frame. //also if the animFrame is outside of first or last frame then don't advance the motion. if (!isHolding && getAnimationIsPlaying() && !(_previousAnimationProperties.getCurrentFrame() > _previousAnimationProperties.getLastFrame()) && !(_previousAnimationProperties.getCurrentFrame() < _previousAnimationProperties.getFirstFrame())) { - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS()); - qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame; - setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame); + // float deltaTime = (float)interval / (float)USECS_PER_SECOND; + // _currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS()); + // qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame; + // setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame); + setAnimationCurrentlyPlayingFrame(now); } - } + //} + } //angus @@ -612,7 +625,7 @@ void ModelEntityItem::setAnimationCurrentFrame(float value) { }); } -void ModelEntityItem::setAnimationCurrentlyPlayingFrame(float value) { +void ModelEntityItem::setAnimationCurrentlyPlayingFrame(quint64 value) { _dirtyFlags |= Simulation::DIRTY_UPDATEABLE; withWriteLock([&] { _animationProperties.setCurrentlyPlayingFrame(value); @@ -689,7 +702,7 @@ bool ModelEntityItem::isAnimatingSomething() const { }); } -float ModelEntityItem::getCurrentlyPlayingFrame() const { +quint64 ModelEntityItem::getCurrentlyPlayingFrame() const { return resultWithReadLock([&] { return _currentlyPlayingFrame; }); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 2e901ed318..dad022ae0a 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -87,7 +87,7 @@ public: void setAnimationURL(const QString& url); void setAnimationCurrentFrame(float value); - void setAnimationCurrentlyPlayingFrame(float value); + void setAnimationCurrentlyPlayingFrame(quint64 value); void setAnimationIsPlaying(bool value); void setAnimationFPS(float value); @@ -110,7 +110,7 @@ public: float getAnimationCurrentFrame() const; bool isAnimatingSomething() const; - float getCurrentlyPlayingFrame() const; + quint64 getCurrentlyPlayingFrame() const; int getLastKnownCurrentFrame() const; static const QString DEFAULT_TEXTURES; @@ -172,7 +172,7 @@ protected: private: //angus - float _currentlyPlayingFrame{ -1 }; + quint64 _currentlyPlayingFrame{ 0 }; float _endAnim{ 0 }; uint64_t _lastAnimated{ 0 }; AnimationPropertyGroup _previousAnimationProperties; From 2e75016021d41cd4057c9c1f44a5325c2dd5c7cc Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 22 Nov 2017 17:53:21 -0800 Subject: [PATCH 13/20] changes to modelEntity.cpp --- .../src/RenderableModelEntityItem.cpp | 46 +++++++++---------- libraries/entities/src/ModelEntityItem.cpp | 45 +++++++++++------- libraries/entities/src/ModelEntityItem.h | 1 + 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 80aba9deba..b3417e7946 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -991,7 +991,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { int firstFrame = entity->getAnimationFirstFrame(); int lastFrame = entity->getAnimationLastFrame(); bool isHolding = entity->getAnimationHold(); - int updatedFrameCount = frameCount; + int updatedFrameCount = lastFrame - firstFrame + 1; //get the updated frame from the ModelEntity auto modelAnimProperties = entity->getAnimationProperties(); @@ -1018,45 +1018,45 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto now = usecTimestampNow(); //find out how long it has been since this animation started. - auto interval = now - _currentlyPlayingFrame; - //auto interval = now - _lastAnimated; + + auto interval = now - _lastAnimated; _lastAnimated = now; - - //new global start time code - float nowTime = (float)interval / (float)USECS_PER_SECOND; float oldCurrentFrame = _currentFrame; - _currentFrame = _renderAnimationProperties.getCurrentFrame() + (nowTime * _renderAnimationProperties.getFPS()); - + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); //here we implement the looping animation property //if we have played through the animation once then we hold on the last frame - if( isLooping || (_currentFrame < _endAnim ) ){ + if( isLooping || (_currentFrame < _renderAnimationProperties.getLastFrame() ) ){ //else advance the current frame. //if hold or not playing don't advance the current frame. //also if the animFrame is outside of first or last frame then don't advance the motion. if (!isHolding && entity->getAnimationIsPlaying() && !( _renderAnimationProperties.getCurrentFrame() > _renderAnimationProperties.getLastFrame() ) && !( _renderAnimationProperties.getCurrentFrame() < _renderAnimationProperties.getFirstFrame() ) ) { - //float deltaTime = (float)interval / (float)USECS_PER_SECOND; - //_currentlyPlayingFrame += (deltaTime * _renderAnimationProperties.getFPS()); - //do nothing + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + while ((_currentFrame - _renderAnimationProperties.getFirstFrame()) > updatedFrameCount) { + _currentFrame -= updatedFrameCount; + } } else { //use old currentFrame _currentFrame = oldCurrentFrame; } - } - else { + }else { //make current frame the endanim frame - _currentFrame = _endAnim; + _currentFrame = _renderAnimationProperties.getLastFrame(); } + //save the last place that we rendered ourselves. + //entity->setAnimationCurrentFrame(_currentFrame); { //where are we in the currently defined animation segment? - int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount; + // int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount; //this gives us the absolute frame value to use by adding the first frame value. - animationCurrentFrame += firstFrame; - + // animationCurrentFrame += firstFrame; + int animationCurrentFrame = (int)(glm::floor(_currentFrame)); @@ -1383,7 +1383,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce auto newAnimationProperties = entity->getAnimationProperties(); if (newAnimationProperties != _renderAnimationProperties) { qCDebug(entitiesrenderer) << "this is where the change is currently handled in the rendering code"; - qCDebug(entitiesrenderer) << "getting the currently playing frame from the modelentityitem update" << entity->getCurrentlyPlayingFrame(); + qCDebug(entitiesrenderer) << "getting the currently playing frame from the modelentityitem update" << newAnimationProperties.getCurrentFrame(); withWriteLock([&] { if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { @@ -1392,11 +1392,11 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce _lastAnimated = 0; } }else if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) { - int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1); - _endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; + //int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1); + //_endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; } - _currentlyPlayingFrame = newAnimationProperties.getCurrentlyPlayingFrame(); - qCDebug(entitiesrenderer) << "renderable update to currently playing frame " << _currentlyPlayingFrame; + _currentFrame = newAnimationProperties.getCurrentFrame(); + qCDebug(entitiesrenderer) << "renderable update to current frame " << _currentFrame; _renderAnimationProperties = newAnimationProperties; }); } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index bdf4f6f3f9..b853077ca1 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -199,22 +199,27 @@ void ModelEntityItem::update(const quint64& now) { if (_previousAnimationProperties != currentAnimationProperties) { qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code"; withWriteLock([&] { - if ( (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) || (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { + _previousAnimationProperties = currentAnimationProperties; + if ( (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { // if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) { // _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame(); //_endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() ); //_lastAnimated = 0; // } - setAnimationCurrentlyPlayingFrame(usecTimestampNow()); + qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, current frame is: \n\n" << currentAnimationProperties.getCurrentFrame(); + setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); } - //else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) { - // int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); - //_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; - //} - _previousAnimationProperties = currentAnimationProperties; + else { + //else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) { + // int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); + //_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; + //} + setAnimationCurrentFrame(currentAnimationProperties.getCurrentFrame()); + } + }); - qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, currently playing frame is: " << currentAnimationProperties.getCurrentlyPlayingFrame(); + qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, current frame is: " << currentAnimationProperties.getCurrentFrame(); } //_previousAnimationProperties = currentAnimationProperties; updateFrameCount(); @@ -244,8 +249,8 @@ void ModelEntityItem::updateFrameCount() { //this is now getting the time since the server started the animation. //auto interval = now - _currentlyPlayingFrame; - //auto interval = now - _lastAnimated; - //_lastAnimated = now; + auto interval = now - _lastAnimated; + _lastAnimated = now; @@ -257,20 +262,28 @@ void ModelEntityItem::updateFrameCount() { int firstFrame = getAnimationFirstFrame(); int lastFrame = getAnimationLastFrame(); bool isHolding = getAnimationHold(); + int updatedFrameCount = lastFrame - firstFrame + 1; - //if (isLooping || (_currentFrame < _endAnim)) { + if (isLooping || (_currentFrame < _previousAnimationProperties.getLastFrame())) { //else advance the current frame. //if hold or not playing don't advance the current frame. //also if the animFrame is outside of first or last frame then don't advance the motion. if (!isHolding && getAnimationIsPlaying() && !(_previousAnimationProperties.getCurrentFrame() > _previousAnimationProperties.getLastFrame()) && !(_previousAnimationProperties.getCurrentFrame() < _previousAnimationProperties.getFirstFrame())) { - // float deltaTime = (float)interval / (float)USECS_PER_SECOND; - // _currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS()); - // qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame; + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * _previousAnimationProperties.getFPS()); + while ((_currentFrame - _previousAnimationProperties.getFirstFrame()) > updatedFrameCount) { + _currentFrame -= updatedFrameCount; + } + qCDebug(entities) << "the frame is now 1 " << _currentFrame; // setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame); - setAnimationCurrentlyPlayingFrame(now); + setAnimationCurrentFrame(_currentFrame); } - //} + } else { + _currentFrame = getAnimationLastFrame(); + setAnimationCurrentFrame(_currentFrame); + qCDebug(entities) << "the frame is now 2 " << _currentFrame; + } } diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index dad022ae0a..973f49aec4 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -178,6 +178,7 @@ private: AnimationPropertyGroup _previousAnimationProperties; bool _propTestFlag{ true }; bool _propTestFlag2{ true }; + float _currentFrame{ 0 }; //angus }; From d607ca0914445d26e9d23bbeed17517c0ba3a315 Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 28 Nov 2017 11:04:48 -0800 Subject: [PATCH 14/20] initialize the _lastAnimated time when the modelEntityRenderer is instantiated, this fixes the sync between interface and the server --- .../src/RenderableModelEntityItem.cpp | 157 +++++++++++------- .../src/RenderableModelEntityItem.h | 7 +- libraries/entities/src/ModelEntityItem.cpp | 133 ++++++++++----- libraries/entities/src/ModelEntityItem.h | 3 +- 4 files changed, 190 insertions(+), 110 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index ba0272ed2a..fa24a171f1 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -63,13 +63,17 @@ bool ModelEntityWrapper::isModelLoaded() const { EntityItemPointer RenderableModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItemPointer entity(new RenderableModelEntityItem(entityID, properties.getDimensionsInitialized()), [](EntityItem* ptr) { ptr->deleteLater(); }); + entity->setProperties(properties); + return entity; } RenderableModelEntityItem::RenderableModelEntityItem(const EntityItemID& entityItemID, bool dimensionsInitialized) : ModelEntityWrapper(entityItemID), _dimensionsInitialized(dimensionsInitialized) { + + } RenderableModelEntityItem::~RenderableModelEntityItem() { } @@ -987,34 +991,22 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { } //get entity model anim props - bool isLooping = entity->getAnimationLoop(); - int firstFrame = entity->getAnimationFirstFrame(); - int lastFrame = entity->getAnimationLastFrame(); - bool isHolding = entity->getAnimationHold(); - int updatedFrameCount = lastFrame - firstFrame + 1; - - //get the updated frame from the ModelEntity - auto modelAnimProperties = entity->getAnimationProperties(); - - //_currentFrame = modelAnimProperties.getCurrentFrame(); + int updatedFrameCount = entity->getAnimationLastFrame() - entity->getAnimationFirstFrame() + 1; + - //tempbool = modelAnimProperties.getRunning(); - //qCDebug(entitiesrenderer) << "is playing is: " << tempbool; - - qCDebug(entitiesrenderer) << "the client frame count is the following " << _currentFrame; - - if ((firstFrame >= 0) && (firstFrame < lastFrame) && (lastFrame <= frameCount)) { - //length of animation in now determined by first and last frame - updatedFrameCount = (lastFrame - firstFrame + 1); + if ((entity->getAnimationFirstFrame() < 0) && (entity->getAnimationFirstFrame() > entity->getAnimationLastFrame())){// && (lastFrame <= frameCount)) { + //we don't increment currentframe if the first frame is < zero or > than last frame. + //return; } + if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); return; } - + auto now = usecTimestampNow(); //find out how long it has been since this animation started. @@ -1022,46 +1014,38 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto interval = now - _lastAnimated; _lastAnimated = now; - float oldCurrentFrame = _currentFrame; - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); + //here we implement the looping animation property //if we have played through the animation once then we hold on the last frame - - if( isLooping || (_currentFrame < _renderAnimationProperties.getLastFrame() ) ){ - //else advance the current frame. - //if hold or not playing don't advance the current frame. - //also if the animFrame is outside of first or last frame then don't advance the motion. - if (!isHolding && entity->getAnimationIsPlaying() && !( _renderAnimationProperties.getCurrentFrame() > _renderAnimationProperties.getLastFrame() ) && !( _renderAnimationProperties.getCurrentFrame() < _renderAnimationProperties.getFirstFrame() ) ) { - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * _renderAnimationProperties.getFPS()); - while ((_currentFrame - _renderAnimationProperties.getFirstFrame()) > updatedFrameCount) { - _currentFrame -= updatedFrameCount; + if (!(entity->getAnimationHold()) && entity->getAnimationIsPlaying()) { + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * entity->getAnimationFPS()); + if (_currentFrame > entity->getAnimationLastFrame()) { + if (entity->getAnimationLoop()) { + while ((_currentFrame - entity->getAnimationFirstFrame()) > (updatedFrameCount - 1)) { + _currentFrame -= (updatedFrameCount - 1); + } + }else{ + _currentFrame = entity->getAnimationLastFrame(); + } + }else if (_currentFrame < entity->getAnimationFirstFrame()) { + if (entity->getAnimationFirstFrame() < 0) { + _currentFrame = 0; + }else { + _currentFrame = entity->getAnimationFirstFrame(); } } - else { - //use old currentFrame - _currentFrame = oldCurrentFrame; - } - }else { - //make current frame the endanim frame - _currentFrame = _renderAnimationProperties.getLastFrame(); } - //save the last place that we rendered ourselves. - //entity->setAnimationCurrentFrame(_currentFrame); - - { + qCDebug(entitiesrenderer) << "_currentFrame " << _currentFrame; + + + { //where are we in the currently defined animation segment? - // int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount; - //this gives us the absolute frame value to use by adding the first frame value. - // animationCurrentFrame += firstFrame; int animationCurrentFrame = (int)(glm::floor(_currentFrame)); - - - - - + //in the case where the last frame is greater than the framecount then clamp + //it to the end of the animation until it loops around. + if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) { animationCurrentFrame = 0; } @@ -1382,23 +1366,65 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce // make a copy of the animation properites auto newAnimationProperties = entity->getAnimationProperties(); if (newAnimationProperties != _renderAnimationProperties) { - qCDebug(entitiesrenderer) << "this is where the change is currently handled in the rendering code"; - qCDebug(entitiesrenderer) << "getting the currently playing frame from the modelentityitem update" << newAnimationProperties.getCurrentFrame(); withWriteLock([&] { - if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { - if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) { + if ((newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { + if (_currentFrame < 0) { + qCDebug(entitiesrenderer) << "point A before assign" << _currentFrame; _currentFrame = newAnimationProperties.getCurrentFrame();// +((float)newAnimationProperties.getCurrentlyPlayingFrame() / (float)USECS_PER_SECOND)*(newAnimationProperties.getFPS()); - _endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() ); - _lastAnimated = 0; + qCDebug(entitiesrenderer) << "point A after assign" << _currentFrame; + qCDebug(entitiesrenderer) << "current " <getAnimationProperties(); + } else { + //if first frame is less than zero then don't do anything. + if (!(entity->getAnimationFirstFrame() < 0)) { + // if the current frame is less than zero, this is from the initialization. + if (_currentFrame < 0) { + qCDebug(entitiesrenderer) << "point D property current frame " << entity->getName() << newAnimationProperties.getCurrentFrame(); + if ((newAnimationProperties.getCurrentFrame() < newAnimationProperties.getLastFrame()) && (newAnimationProperties.getCurrentFrame() > newAnimationProperties.getFirstFrame())) { + + _currentFrame = newAnimationProperties.getCurrentFrame(); + qCDebug(entitiesrenderer) << "point D.1 " << _currentFrame; + qCDebug(entitiesrenderer) << "last animated " << _lastAnimated; + _lastAnimated = usecTimestampNow(); + } + else { + _currentFrame = newAnimationProperties.getFirstFrame(); + qCDebug(entitiesrenderer) << "point D.2 " << _currentFrame; + _lastAnimated = usecTimestampNow(); + qCDebug(entitiesrenderer) << entity->getName() << "last animated " << _lastAnimated; + } + } + } + } } //angus @@ -1410,9 +1436,12 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if (!jointsMapped()) { mapJoints(entity, model->getJointNames()); } - animate(entity); + if (!(entity->getAnimationFirstFrame() < 0) && !(entity->getAnimationFirstFrame() > entity->getAnimationLastFrame())) { + animate(entity); + } emit requestRenderUpdate(); } + } void ModelEntityRenderer::flagForCollisionGeometryUpdate() { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index fdb0cf5d2c..7f3ee47534 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -133,7 +133,10 @@ class ModelEntityRenderer : public TypedEntityRenderergetAnimationProperties(); if (_previousAnimationProperties != currentAnimationProperties) { - qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code"; + //qCDebug(entities) << "properties changed in modelentity code" << _currentFrame; withWriteLock([&] { - _previousAnimationProperties = currentAnimationProperties; + if ( (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { - // if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) { - // _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame(); - //_endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() ); - //_lastAnimated = 0; - // } - qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, current frame is: \n\n" << currentAnimationProperties.getCurrentFrame(); + _lastAnimated = usecTimestampNow(); + _currentFrame = currentAnimationProperties.getFirstFrame(); + qCDebug(entities) << "point 2 " << _currentFrame; setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); - } - else { - //else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) { - // int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1); - //_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length; - //} - setAnimationCurrentFrame(currentAnimationProperties.getCurrentFrame()); + }else if (currentAnimationProperties.getHold() && !_previousAnimationProperties.getHold()) { + //_lastAnimated = 0; + //_currentFrame = currentAnimationProperties.getCurrentFrame(); + qCDebug(entities) << "hold is pressed" << _currentFrame; + }else if (!currentAnimationProperties.getHold() && _previousAnimationProperties.getHold()) { + //_lastAnimated = 0; + //_currentFrame = currentAnimationProperties.getCurrentFrame(); + qCDebug(entities) << "hold is unpressed" << _currentFrame; + }else if (!currentAnimationProperties.getLoop() && _previousAnimationProperties.getLoop()) { + //_lastAnimated = 0; + qCDebug(entities) << "loop is unpressed" << _currentFrame; + }else if (currentAnimationProperties.getLoop() && !_previousAnimationProperties.getLoop()) { + //_lastAnimated = 0; + qCDebug(entities) << "loop is pressed" << _currentFrame; + }else if(currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()){ + _currentFrame = currentAnimationProperties.getCurrentFrame(); + // if (_currentFrame < currentAnimationProperties.getFirstFrame()) { + // _currentFrame = currentAnimationProperties.getFirstFrame(); + // } + // current frame greater than lastframe is dealt with in updateframe. + //_lastAnimated = usecTimestampNow(); + qCDebug(entities) << "point 3 " << _currentFrame; } }); - - qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, current frame is: " << currentAnimationProperties.getCurrentFrame(); + _previousAnimationProperties = this->getAnimationProperties(); + //qCDebug(entities) << "point 4 " << _currentFrame; + } + else { + + //if the first frame is less than zero that is an error, so don't do anything. + if (!(getAnimationFirstFrame() < 0)) { + //if the current frame is less than zero then we are restarting the server. + if (_currentFrame < 0) { + qCDebug(entities) << "point 3.5 " << _currentFrame; + //_previousAnimationProperties = currentAnimationProperties; + if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { + _currentFrame = currentAnimationProperties.getCurrentFrame(); + } + else { + _currentFrame = currentAnimationProperties.getFirstFrame(); + setAnimationCurrentFrame(_currentFrame); + _lastAnimated = 0; + } + } + } } //_previousAnimationProperties = currentAnimationProperties; - updateFrameCount(); - + if (isAnimatingSomething()) { + if (!(getAnimationFirstFrame() < 0) && !(getAnimationFirstFrame() > getAnimationLastFrame()) ) { + updateFrameCount(); + } + } } } @@ -252,9 +286,6 @@ void ModelEntityItem::updateFrameCount() { auto interval = now - _lastAnimated; _lastAnimated = now; - - - //here we implement the looping animation property //get entity anim props @@ -263,28 +294,37 @@ void ModelEntityItem::updateFrameCount() { int lastFrame = getAnimationLastFrame(); bool isHolding = getAnimationHold(); int updatedFrameCount = lastFrame - firstFrame + 1; - - if (isLooping || (_currentFrame < _previousAnimationProperties.getLastFrame())) { - //else advance the current frame. - //if hold or not playing don't advance the current frame. - //also if the animFrame is outside of first or last frame then don't advance the motion. - if (!isHolding && getAnimationIsPlaying() && !(_previousAnimationProperties.getCurrentFrame() > _previousAnimationProperties.getLastFrame()) && !(_previousAnimationProperties.getCurrentFrame() < _previousAnimationProperties.getFirstFrame())) { - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * _previousAnimationProperties.getFPS()); - while ((_currentFrame - _previousAnimationProperties.getFirstFrame()) > updatedFrameCount) { - _currentFrame -= updatedFrameCount; - } - qCDebug(entities) << "the frame is now 1 " << _currentFrame; - // setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame); - setAnimationCurrentFrame(_currentFrame); - } - - } else { - _currentFrame = getAnimationLastFrame(); - setAnimationCurrentFrame(_currentFrame); - qCDebug(entities) << "the frame is now 2 " << _currentFrame; - } + + + + //qCDebug(entities) << "point 5 " << _currentFrame; + + if (!isHolding && getAnimationIsPlaying()) { + float deltaTime = (float)interval / (float)USECS_PER_SECOND; + _currentFrame += (deltaTime * getAnimationFPS()); + if (_currentFrame > getAnimationLastFrame()) { + if (isLooping) { + while ((_currentFrame - getAnimationFirstFrame()) > (updatedFrameCount - 1)) { + _currentFrame -= (updatedFrameCount - 1); + } + } + else { + _currentFrame = getAnimationLastFrame(); + } + } + else if (_currentFrame < getAnimationFirstFrame()) { + if (getAnimationFirstFrame() < 0) { + _currentFrame = 0; + } + else { + _currentFrame = getAnimationFirstFrame(); + } + } + setAnimationCurrentFrame(_currentFrame); + } + + //qCDebug(entities) << "_currentFrame is " << _currentFrame; } //angus @@ -706,6 +746,13 @@ float ModelEntityItem::getAnimationCurrentFrame() const { }); } +float ModelEntityItem::getAnimationFPS() const { + return resultWithReadLock([&] { + return _animationProperties.getFPS(); + }); +} + + //angus change bool ModelEntityItem::isAnimatingSomething() const { return resultWithReadLock([&] { diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 973f49aec4..3dd30761ec 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -108,6 +108,7 @@ public: bool getAnimationIsPlaying() const; float getAnimationCurrentFrame() const; + float getAnimationFPS() const; bool isAnimatingSomething() const; quint64 getCurrentlyPlayingFrame() const; @@ -178,7 +179,7 @@ private: AnimationPropertyGroup _previousAnimationProperties; bool _propTestFlag{ true }; bool _propTestFlag2{ true }; - float _currentFrame{ 0 }; + float _currentFrame{ -1 }; //angus }; From 101e67498ad643f4fedb053f589e6075e57c7991 Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 28 Nov 2017 14:11:56 -0800 Subject: [PATCH 15/20] cleaned up the code to remove _currentFrame updating in RenderModelEntityItem also removed the unnessary currently playing frame property --- .../src/EntityTreeRenderer.cpp | 5 +- .../src/RenderableModelEntityItem.cpp | 123 +----------------- .../src/RenderableModelEntityItem.h | 6 +- .../entities/src/AnimationPropertyGroup.cpp | 24 ---- .../entities/src/AnimationPropertyGroup.h | 1 - .../entities/src/EntityItemProperties.cpp | 1 - libraries/entities/src/EntityPropertyFlags.h | 2 - libraries/entities/src/ModelEntityItem.cpp | 82 ++++-------- libraries/entities/src/ModelEntityItem.h | 10 +- 9 files changed, 35 insertions(+), 219 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index e3bbfca6cd..5dc1308ae3 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -402,8 +402,9 @@ void EntityTreeRenderer::update(bool simulate) { PerformanceTimer perfTimer("ETRupdate"); if (_tree && !_shuttingDown) { EntityTreePointer tree = std::static_pointer_cast(_tree); - //angus - //tree->update(simulate); + + //here we update _currentFrame and _lastAnimated and sync with the server properties. + tree->update(simulate); // Update the rendereable entities as needed { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index fa24a171f1..5170596741 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -990,59 +990,10 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } - //get entity model anim props - - int updatedFrameCount = entity->getAnimationLastFrame() - entity->getAnimationFirstFrame() + 1; - - - if ((entity->getAnimationFirstFrame() < 0) && (entity->getAnimationFirstFrame() > entity->getAnimationLastFrame())){// && (lastFrame <= frameCount)) { - //we don't increment currentframe if the first frame is < zero or > than last frame. - //return; - } - - - - if (!_lastAnimated) { - _lastAnimated = usecTimestampNow(); - return; - } - - auto now = usecTimestampNow(); - - //find out how long it has been since this animation started. - - auto interval = now - _lastAnimated; - _lastAnimated = now; - - - - //here we implement the looping animation property - //if we have played through the animation once then we hold on the last frame - if (!(entity->getAnimationHold()) && entity->getAnimationIsPlaying()) { - float deltaTime = (float)interval / (float)USECS_PER_SECOND; - _currentFrame += (deltaTime * entity->getAnimationFPS()); - if (_currentFrame > entity->getAnimationLastFrame()) { - if (entity->getAnimationLoop()) { - while ((_currentFrame - entity->getAnimationFirstFrame()) > (updatedFrameCount - 1)) { - _currentFrame -= (updatedFrameCount - 1); - } - }else{ - _currentFrame = entity->getAnimationLastFrame(); - } - }else if (_currentFrame < entity->getAnimationFirstFrame()) { - if (entity->getAnimationFirstFrame() < 0) { - _currentFrame = 0; - }else { - _currentFrame = entity->getAnimationFirstFrame(); - } - } - } - qCDebug(entitiesrenderer) << "_currentFrame " << _currentFrame; - - + //the code to find the current frame is now in modelEntityItem.cpp and we access it below -Angus { //where are we in the currently defined animation segment? - int animationCurrentFrame = (int)(glm::floor(_currentFrame)); + int animationCurrentFrame = (int)(glm::floor(entity->getAnimationCurrentFrame())); //in the case where the last frame is greater than the framecount then clamp //it to the end of the animation until it loops around. @@ -1361,74 +1312,8 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce model->updateRenderItems(); } - { - DETAILED_PROFILE_RANGE(simulation_physics, "CheckAnimation"); - // make a copy of the animation properites - auto newAnimationProperties = entity->getAnimationProperties(); - if (newAnimationProperties != _renderAnimationProperties) { - withWriteLock([&] { - if ((newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) { - if (_currentFrame < 0) { - qCDebug(entitiesrenderer) << "point A before assign" << _currentFrame; - _currentFrame = newAnimationProperties.getCurrentFrame();// +((float)newAnimationProperties.getCurrentlyPlayingFrame() / (float)USECS_PER_SECOND)*(newAnimationProperties.getFPS()); - qCDebug(entitiesrenderer) << "point A after assign" << _currentFrame; - qCDebug(entitiesrenderer) << "current " <getAnimationProperties(); - } else { - //if first frame is less than zero then don't do anything. - if (!(entity->getAnimationFirstFrame() < 0)) { - // if the current frame is less than zero, this is from the initialization. - if (_currentFrame < 0) { - qCDebug(entitiesrenderer) << "point D property current frame " << entity->getName() << newAnimationProperties.getCurrentFrame(); - if ((newAnimationProperties.getCurrentFrame() < newAnimationProperties.getLastFrame()) && (newAnimationProperties.getCurrentFrame() > newAnimationProperties.getFirstFrame())) { - - _currentFrame = newAnimationProperties.getCurrentFrame(); - qCDebug(entitiesrenderer) << "point D.1 " << _currentFrame; - qCDebug(entitiesrenderer) << "last animated " << _lastAnimated; - _lastAnimated = usecTimestampNow(); - } - else { - _currentFrame = newAnimationProperties.getFirstFrame(); - qCDebug(entitiesrenderer) << "point D.2 " << _currentFrame; - _lastAnimated = usecTimestampNow(); - qCDebug(entitiesrenderer) << entity->getName() << "last animated " << _lastAnimated; - } - } - } - - } - } - //angus - + //The code to deal with the change of properties is now in ModelEntityItem.cpp + //That is where _currentFrame and _lastAnimated are updated. if (_animating) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 7f3ee47534..1ca72ce57d 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -133,10 +133,7 @@ class ModelEntityRenderer : public TypedEntityRenderer& out) { if (allowTranslationChanged()) { out << "animation-allowTranslation"; } - if (currentlyPlayingFrameChanged()) { - out << "animation-currentlyPlayingFrame"; - } } @@ -209,8 +196,6 @@ bool AnimationPropertyGroup::appendToEditPacket(OctreePacketData* packetData, APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, getFirstFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, getLastFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, getHold()); - //angus - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, getCurrentlyPlayingFrame()); return true; } @@ -232,7 +217,6 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold); - READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, quint64, setCurrentlyPlayingFrame); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_URL, URL); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_FPS, FPS); @@ -243,7 +227,6 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_LAST_FRAME, LastFrame); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_HOLD, Hold); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_ALLOW_TRANSLATION, AllowTranslation); - DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame); processedBytes += bytesRead; @@ -276,7 +259,6 @@ EntityPropertyFlags AnimationPropertyGroup::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_ANIMATION_LAST_FRAME, lastFrame); CHECK_PROPERTY_CHANGE(PROP_ANIMATION_HOLD, hold); CHECK_PROPERTY_CHANGE(PROP_ANIMATION_ALLOW_TRANSLATION, allowTranslation); - CHECK_PROPERTY_CHANGE(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, currentlyPlayingFrame); return changedProperties; } @@ -291,7 +273,6 @@ void AnimationPropertyGroup::getProperties(EntityItemProperties& properties) con COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, FirstFrame, getFirstFrame); COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, LastFrame, getLastFrame); COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, Hold, getHold); - COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Animation, CurrentlyPlayingFrame, getCurrentlyPlayingFrame); } bool AnimationPropertyGroup::setProperties(const EntityItemProperties& properties) { @@ -306,7 +287,6 @@ bool AnimationPropertyGroup::setProperties(const EntityItemProperties& propertie SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, FirstFrame, firstFrame, setFirstFrame); SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, LastFrame, lastFrame, setLastFrame); SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, Hold, hold, setHold); - SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Animation, CurrentlyPlayingFrame, currentlyPlayingFrame, setCurrentlyPlayingFrame); return somethingChanged; } @@ -322,8 +302,6 @@ EntityPropertyFlags AnimationPropertyGroup::getEntityProperties(EncodeBitstreamP requestedProperties += PROP_ANIMATION_LAST_FRAME; requestedProperties += PROP_ANIMATION_HOLD; requestedProperties += PROP_ANIMATION_ALLOW_TRANSLATION; - //angus - requestedProperties += PROP_ANIMATION_CURRENTLY_PLAYING_FRAME; return requestedProperties; } @@ -347,7 +325,6 @@ void AnimationPropertyGroup::appendSubclassData(OctreePacketData* packetData, En APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, getFirstFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, getLastFrame()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, getHold()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, getCurrentlyPlayingFrame()); } int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, @@ -367,6 +344,5 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame); READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold); - READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, quint64, setCurrentlyPlayingFrame); return bytesRead; } diff --git a/libraries/entities/src/AnimationPropertyGroup.h b/libraries/entities/src/AnimationPropertyGroup.h index 1a3da52684..54d4ced92f 100644 --- a/libraries/entities/src/AnimationPropertyGroup.h +++ b/libraries/entities/src/AnimationPropertyGroup.h @@ -86,7 +86,6 @@ public: DEFINE_PROPERTY(PROP_ANIMATION_LAST_FRAME, LastFrame, lastFrame, float, MAXIMUM_POSSIBLE_FRAME); // was animationSettings.lastFrame DEFINE_PROPERTY(PROP_ANIMATION_HOLD, Hold, hold, bool, false); // was animationSettings.hold DEFINE_PROPERTY(PROP_ANIMATION_ALLOW_TRANSLATION, AllowTranslation, allowTranslation, bool, true); - DEFINE_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame, currentlyPlayingFrame, quint64, 0); protected: friend bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 77fa1231f1..108fc14e30 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -1148,7 +1148,6 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_LAST_FRAME, Animation, animation, LastFrame, lastFrame); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_HOLD, Animation, animation, Hold, hold); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_ALLOW_TRANSLATION, Animation, animation, AllowTranslation, allowTranslation); - ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, Animation, animation, CurrentlyPlayingFrame, currentlyPlayingFrame); ADD_GROUP_PROPERTY_TO_MAP(PROP_SKYBOX_COLOR, Skybox, skybox, Color, color); ADD_GROUP_PROPERTY_TO_MAP(PROP_SKYBOX_URL, Skybox, skybox, URL, url); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 3b1f4d60d0..35d40b669a 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -40,8 +40,6 @@ enum EntityPropertyList { PROP_ANIMATION_FRAME_INDEX, PROP_ANIMATION_PLAYING, PROP_ANIMATION_ALLOW_TRANSLATION, - //angus - PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, // these properties are supported by the EntityItem base class PROP_REGISTRATION_POINT, diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 23b352fc19..4facd1f253 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -33,6 +33,9 @@ EntityItemPointer ModelEntityItem::factory(const EntityItemID& entityID, const E ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) { + _lastAnimated = usecTimestampNow(); + qCDebug(entities) << "init last animated " << _lastAnimated; + //set the last animated when interface (re)starts _type = EntityTypes::Model; _lastKnownCurrentFrame = -1; _color[0] = _color[1] = _color[2] = 0; @@ -186,52 +189,45 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit } -//angus +//added update for property fix void ModelEntityItem::update(const quint64& now) { - //put something here - //qCDebug(entities) << "model entity item update" << getName() << " " << getEntityItemID(); { auto currentAnimationProperties = this->getAnimationProperties(); if (_previousAnimationProperties != currentAnimationProperties) { - //qCDebug(entities) << "properties changed in modelentity code" << _currentFrame; - withWriteLock([&] { - + + withWriteLock([&] { if ( (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { - _lastAnimated = usecTimestampNow(); - _currentFrame = currentAnimationProperties.getFirstFrame(); - qCDebug(entities) << "point 2 " << _currentFrame; - setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); + if (_currentFrame < 0) { + _currentFrame = currentAnimationProperties.getCurrentFrame(); + setAnimationCurrentFrame(_currentFrame); + qCDebug(entities) << "restart code hit " << _currentFrame; + } + else { + _lastAnimated = usecTimestampNow(); + qCDebug(entities) << "last animated 1" << _lastAnimated; + _currentFrame = currentAnimationProperties.getFirstFrame(); + qCDebug(entities) << "point 2 " << _currentFrame; + setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); + } }else if (currentAnimationProperties.getHold() && !_previousAnimationProperties.getHold()) { - //_lastAnimated = 0; - //_currentFrame = currentAnimationProperties.getCurrentFrame(); qCDebug(entities) << "hold is pressed" << _currentFrame; }else if (!currentAnimationProperties.getHold() && _previousAnimationProperties.getHold()) { - //_lastAnimated = 0; - //_currentFrame = currentAnimationProperties.getCurrentFrame(); qCDebug(entities) << "hold is unpressed" << _currentFrame; }else if (!currentAnimationProperties.getLoop() && _previousAnimationProperties.getLoop()) { - //_lastAnimated = 0; qCDebug(entities) << "loop is unpressed" << _currentFrame; }else if (currentAnimationProperties.getLoop() && !_previousAnimationProperties.getLoop()) { - //_lastAnimated = 0; qCDebug(entities) << "loop is pressed" << _currentFrame; }else if(currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()){ _currentFrame = currentAnimationProperties.getCurrentFrame(); - // if (_currentFrame < currentAnimationProperties.getFirstFrame()) { - // _currentFrame = currentAnimationProperties.getFirstFrame(); - // } - // current frame greater than lastframe is dealt with in updateframe. - //_lastAnimated = usecTimestampNow(); qCDebug(entities) << "point 3 " << _currentFrame; } }); _previousAnimationProperties = this->getAnimationProperties(); - //qCDebug(entities) << "point 4 " << _currentFrame; } else { @@ -243,11 +239,13 @@ void ModelEntityItem::update(const quint64& now) { //_previousAnimationProperties = currentAnimationProperties; if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { _currentFrame = currentAnimationProperties.getCurrentFrame(); + qCDebug(entities) << "current frame less than zero " << _currentFrame; } else { _currentFrame = currentAnimationProperties.getFirstFrame(); setAnimationCurrentFrame(_currentFrame); - _lastAnimated = 0; + _lastAnimated = usecTimestampNow(); + qCDebug(entities) << "last animated 2" << _lastAnimated; } } } @@ -264,9 +262,6 @@ void ModelEntityItem::update(const quint64& now) { bool ModelEntityItem::needsToCallUpdate() const { - - //put something here - //qCDebug(entities) << "needs to call update"; return true; } @@ -282,29 +277,17 @@ void ModelEntityItem::updateFrameCount() { auto now = usecTimestampNow(); //this is now getting the time since the server started the animation. - //auto interval = now - _currentlyPlayingFrame; auto interval = now - _lastAnimated; _lastAnimated = now; - //here we implement the looping animation property - //get entity anim props - bool isLooping = getAnimationLoop(); - int firstFrame = getAnimationFirstFrame(); - int lastFrame = getAnimationLastFrame(); - bool isHolding = getAnimationHold(); - int updatedFrameCount = lastFrame - firstFrame + 1; + int updatedFrameCount = getAnimationLastFrame() - getAnimationFirstFrame() + 1; - - - - //qCDebug(entities) << "point 5 " << _currentFrame; - - if (!isHolding && getAnimationIsPlaying()) { + if (!getAnimationHold() && getAnimationIsPlaying()) { float deltaTime = (float)interval / (float)USECS_PER_SECOND; _currentFrame += (deltaTime * getAnimationFPS()); if (_currentFrame > getAnimationLastFrame()) { - if (isLooping) { + if (getAnimationLoop()) { while ((_currentFrame - getAnimationFirstFrame()) > (updatedFrameCount - 1)) { _currentFrame -= (updatedFrameCount - 1); } @@ -327,7 +310,7 @@ void ModelEntityItem::updateFrameCount() { //qCDebug(entities) << "_currentFrame is " << _currentFrame; } -//angus + @@ -678,13 +661,6 @@ void ModelEntityItem::setAnimationCurrentFrame(float value) { }); } -void ModelEntityItem::setAnimationCurrentlyPlayingFrame(quint64 value) { - _dirtyFlags |= Simulation::DIRTY_UPDATEABLE; - withWriteLock([&] { - _animationProperties.setCurrentlyPlayingFrame(value); - }); -} - void ModelEntityItem::setAnimationLoop(bool loop) { withWriteLock([&] { _animationProperties.setLoop(loop); @@ -753,7 +729,6 @@ float ModelEntityItem::getAnimationFPS() const { } -//angus change bool ModelEntityItem::isAnimatingSomething() const { return resultWithReadLock([&] { return !_animationProperties.getURL().isEmpty() && @@ -762,15 +737,8 @@ bool ModelEntityItem::isAnimatingSomething() const { }); } -quint64 ModelEntityItem::getCurrentlyPlayingFrame() const { - return resultWithReadLock([&] { - return _currentlyPlayingFrame; - }); -} - int ModelEntityItem::getLastKnownCurrentFrame() const { return resultWithReadLock([&] { return _lastKnownCurrentFrame; }); } -//angus change \ No newline at end of file diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 3dd30761ec..4aa52d4cef 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -47,11 +47,11 @@ public: EntityPropertyFlags& propertyFlags, bool overwriteLocalData, bool& somethingChanged) override; - //angus + //update and needstocallupdate added back for the entity property fix virtual void update(const quint64& now) override; virtual bool needsToCallUpdate() const override; void updateFrameCount(); - //angus + virtual void debugDump() const override; void setShapeType(ShapeType type) override; @@ -87,7 +87,6 @@ public: void setAnimationURL(const QString& url); void setAnimationCurrentFrame(float value); - void setAnimationCurrentlyPlayingFrame(quint64 value); void setAnimationIsPlaying(bool value); void setAnimationFPS(float value); @@ -111,7 +110,6 @@ public: float getAnimationFPS() const; bool isAnimatingSomething() const; - quint64 getCurrentlyPlayingFrame() const; int getLastKnownCurrentFrame() const; static const QString DEFAULT_TEXTURES; @@ -173,12 +171,8 @@ protected: private: //angus - quint64 _currentlyPlayingFrame{ 0 }; - float _endAnim{ 0 }; uint64_t _lastAnimated{ 0 }; AnimationPropertyGroup _previousAnimationProperties; - bool _propTestFlag{ true }; - bool _propTestFlag2{ true }; float _currentFrame{ -1 }; //angus }; From 778d98f56b8b388b012ad08f72ccfb63a3295ca7 Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 28 Nov 2017 18:42:03 -0800 Subject: [PATCH 16/20] made some changes to fix coding standard problems in the code, also added the update for the EntityItem base class to the update function --- .../src/EntityTreeRenderer.cpp | 4 +- .../src/RenderableModelEntityItem.cpp | 16 ++--- .../src/RenderableModelEntityItem.h | 4 +- libraries/entities/src/ModelEntityItem.cpp | 62 ++++++++----------- libraries/entities/src/ModelEntityItem.h | 4 +- 5 files changed, 37 insertions(+), 53 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 5dc1308ae3..7103e72f54 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -403,7 +403,7 @@ void EntityTreeRenderer::update(bool simulate) { if (_tree && !_shuttingDown) { EntityTreePointer tree = std::static_pointer_cast(_tree); - //here we update _currentFrame and _lastAnimated and sync with the server properties. + // here we update _currentFrame and _lastAnimated and sync with the server properties. tree->update(simulate); // Update the rendereable entities as needed @@ -738,7 +738,7 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event) { PickRay ray = _viewState->computePickRay(event->x(), event->y()); RayToEntityIntersectionResult rayPickResult = _getPrevRayPickResultOperator(_mouseRayPickID); if (rayPickResult.intersects && rayPickResult.entity) { - //qCDebug(entitiesrenderer) << "mouseReleaseEvent over entity:" << rayPickResult.entityID; + // qCDebug(entitiesrenderer) << "mouseReleaseEvent over entity:" << rayPickResult.entityID; glm::vec2 pos2D = projectOntoEntityXYPlane(rayPickResult.entity, ray, rayPickResult); PointerEvent pointerEvent(PointerEvent::Release, PointerManager::MOUSE_POINTER_ID, diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 5170596741..fa75702b89 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -465,7 +465,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { shapeInfo.setParams(type, dimensions, getCompoundShapeURL()); } else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) { // TODO: assert we never fall in here when model not fully loaded - //assert(_model && _model->isLoaded()); + // assert(_model && _model->isLoaded()); updateModelBounds(); model->updateGeometry(); @@ -992,10 +992,10 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { //the code to find the current frame is now in modelEntityItem.cpp and we access it below -Angus { - //where are we in the currently defined animation segment? + // where are we in the currently defined animation segment? int animationCurrentFrame = (int)(glm::floor(entity->getAnimationCurrentFrame())); - //in the case where the last frame is greater than the framecount then clamp - //it to the end of the animation until it loops around. + // in the case where the last frame is greater than the framecount then clamp + // it to the end of the animation until it loops around. if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) { animationCurrentFrame = 0; @@ -1032,10 +1032,10 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { glm::mat4 translationMat; if (allowTranslation) { - if(index < translations.size()){ + if (index < translations.size()) { translationMat = glm::translate(translations[index]); } - } else if (index < animationJointNames.size()){ + } else if (index < animationJointNames.size()) { QString jointName = fbxJoints[index].name; // Pushing this here so its not done on every entity, with the exceptions of those allowing for translation if (originalFbxIndices.contains(jointName)) { @@ -1312,8 +1312,8 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce model->updateRenderItems(); } - //The code to deal with the change of properties is now in ModelEntityItem.cpp - //That is where _currentFrame and _lastAnimated are updated. + // The code to deal with the change of properties is now in ModelEntityItem.cpp + // That is where _currentFrame and _lastAnimated are updated. if (_animating) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 1ca72ce57d..44ee82713d 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -33,7 +33,7 @@ namespace render { namespace entities { class ModelEntityRenderer; } } -//#define MODEL_ENTITY_USE_FADE_EFFECT +// #define MODEL_ENTITY_USE_FADE_EFFECT class ModelEntityWrapper : public ModelEntityItem { using Parent = ModelEntityItem; friend class render::entities::ModelEntityRenderer; @@ -185,8 +185,6 @@ private: bool _animating { false }; uint64_t _lastAnimated { 0 }; float _currentFrame { -1 }; - float _endAnim{ 0 }; - bool tempbool{ false }; }; } } // namespace diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 4facd1f253..594353ee68 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -34,8 +34,7 @@ EntityItemPointer ModelEntityItem::factory(const EntityItemID& entityID, const E ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) { _lastAnimated = usecTimestampNow(); - qCDebug(entities) << "init last animated " << _lastAnimated; - //set the last animated when interface (re)starts + // set the last animated when interface (re)starts _type = EntityTypes::Model; _lastKnownCurrentFrame = -1; _color[0] = _color[1] = _color[2] = 0; @@ -190,79 +189,71 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit -//added update for property fix +// added update for property fix void ModelEntityItem::update(const quint64& now) { - { auto currentAnimationProperties = this->getAnimationProperties(); if (_previousAnimationProperties != currentAnimationProperties) { - withWriteLock([&] { - if ( (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { + if ((currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { if (_currentFrame < 0) { _currentFrame = currentAnimationProperties.getCurrentFrame(); setAnimationCurrentFrame(_currentFrame); - qCDebug(entities) << "restart code hit " << _currentFrame; - } - else { + qCDebug(entities) << "restart code hit last animated is " << _lastAnimated << " now is " << now; + } else { _lastAnimated = usecTimestampNow(); qCDebug(entities) << "last animated 1" << _lastAnimated; _currentFrame = currentAnimationProperties.getFirstFrame(); qCDebug(entities) << "point 2 " << _currentFrame; setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); } - }else if (currentAnimationProperties.getHold() && !_previousAnimationProperties.getHold()) { + } else if (currentAnimationProperties.getHold() && !_previousAnimationProperties.getHold()) { qCDebug(entities) << "hold is pressed" << _currentFrame; - }else if (!currentAnimationProperties.getHold() && _previousAnimationProperties.getHold()) { + } else if (!currentAnimationProperties.getHold() && _previousAnimationProperties.getHold()) { qCDebug(entities) << "hold is unpressed" << _currentFrame; - }else if (!currentAnimationProperties.getLoop() && _previousAnimationProperties.getLoop()) { + } else if (!currentAnimationProperties.getLoop() && _previousAnimationProperties.getLoop()) { qCDebug(entities) << "loop is unpressed" << _currentFrame; - }else if (currentAnimationProperties.getLoop() && !_previousAnimationProperties.getLoop()) { + } else if (currentAnimationProperties.getLoop() && !_previousAnimationProperties.getLoop()) { qCDebug(entities) << "loop is pressed" << _currentFrame; - }else if(currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()){ + } else if (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) { _currentFrame = currentAnimationProperties.getCurrentFrame(); qCDebug(entities) << "point 3 " << _currentFrame; } }); _previousAnimationProperties = this->getAnimationProperties(); - } - else { + } else { - //if the first frame is less than zero that is an error, so don't do anything. + // if the first frame is less than zero that is an error, so don't do anything. if (!(getAnimationFirstFrame() < 0)) { - //if the current frame is less than zero then we are restarting the server. + // if the current frame is less than zero then we are restarting the server. if (_currentFrame < 0) { - qCDebug(entities) << "point 3.5 " << _currentFrame; - //_previousAnimationProperties = currentAnimationProperties; if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { _currentFrame = currentAnimationProperties.getCurrentFrame(); - qCDebug(entities) << "current frame less than zero " << _currentFrame; - } - else { + } else { _currentFrame = currentAnimationProperties.getFirstFrame(); setAnimationCurrentFrame(_currentFrame); _lastAnimated = usecTimestampNow(); - qCDebug(entities) << "last animated 2" << _lastAnimated; } } } } - //_previousAnimationProperties = currentAnimationProperties; + // _previousAnimationProperties = currentAnimationProperties; if (isAnimatingSomething()) { - if (!(getAnimationFirstFrame() < 0) && !(getAnimationFirstFrame() > getAnimationLastFrame()) ) { + if (!(getAnimationFirstFrame() < 0) && !(getAnimationFirstFrame() > getAnimationLastFrame())) { updateFrameCount(); } } } - + EntityItem::update(now); } bool ModelEntityItem::needsToCallUpdate() const { - return true; + //return isAnimatingSomething() || EntityItem::needsToCallUpdate(); + return true; } void ModelEntityItem::updateFrameCount() { @@ -276,7 +267,7 @@ void ModelEntityItem::updateFrameCount() { auto now = usecTimestampNow(); - //this is now getting the time since the server started the animation. + // this is now getting the time since the server started the animation. auto interval = now - _lastAnimated; _lastAnimated = now; @@ -291,23 +282,20 @@ void ModelEntityItem::updateFrameCount() { while ((_currentFrame - getAnimationFirstFrame()) > (updatedFrameCount - 1)) { _currentFrame -= (updatedFrameCount - 1); } - } - else { + } else { _currentFrame = getAnimationLastFrame(); } - } - else if (_currentFrame < getAnimationFirstFrame()) { + } else if (_currentFrame < getAnimationFirstFrame()) { if (getAnimationFirstFrame() < 0) { _currentFrame = 0; - } - else { + } else { _currentFrame = getAnimationFirstFrame(); } } setAnimationCurrentFrame(_currentFrame); } - //qCDebug(entities) << "_currentFrame is " << _currentFrame; + } @@ -709,7 +697,7 @@ float ModelEntityItem::getAnimationLastFrame() const { return _animationProperties.getLastFrame(); }); } -//angus change + bool ModelEntityItem::getAnimationIsPlaying() const { return resultWithReadLock([&] { return _animationProperties.getRunning(); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 4aa52d4cef..c0ca12c7f9 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -47,7 +47,7 @@ public: EntityPropertyFlags& propertyFlags, bool overwriteLocalData, bool& somethingChanged) override; - //update and needstocallupdate added back for the entity property fix + // update() and needstocallupdate() added back for the entity property fix virtual void update(const quint64& now) override; virtual bool needsToCallUpdate() const override; void updateFrameCount(); @@ -170,11 +170,9 @@ protected: ShapeType _shapeType = SHAPE_TYPE_NONE; private: - //angus uint64_t _lastAnimated{ 0 }; AnimationPropertyGroup _previousAnimationProperties; float _currentFrame{ -1 }; - //angus }; #endif // hifi_ModelEntityItem_h From 233d693d76634c9d04f80be699b029e325496a48 Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 29 Nov 2017 10:51:04 -0800 Subject: [PATCH 17/20] removed debug print statements and fixed negative FPS handling --- .../src/RenderableModelEntityItem.cpp | 9 +-- libraries/entities/src/ModelEntityItem.cpp | 56 +++++++++---------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index fa75702b89..d5befbe572 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -981,7 +981,6 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } - QVector jointsData; const QVector& frames = _animation->getFramesReference(); // NOTE: getFrames() is too heavy @@ -990,13 +989,12 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } - //the code to find the current frame is now in modelEntityItem.cpp and we access it below -Angus { - // where are we in the currently defined animation segment? + // the current frame is set on the server in update() in ModelEntityItem.cpp int animationCurrentFrame = (int)(glm::floor(entity->getAnimationCurrentFrame())); + // in the case where the last frame is greater than the framecount then clamp // it to the end of the animation until it loops around. - if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) { animationCurrentFrame = 0; } @@ -1314,8 +1312,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce // The code to deal with the change of properties is now in ModelEntityItem.cpp // That is where _currentFrame and _lastAnimated are updated. - - if (_animating) { DETAILED_PROFILE_RANGE(simulation_physics, "Animate"); if (!jointsMapped()) { @@ -1326,7 +1322,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce } emit requestRenderUpdate(); } - } void ModelEntityRenderer::flagForCollisionGeometryUpdate() { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 594353ee68..260074da68 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -189,48 +189,47 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit -// added update for property fix +// added update function back for property fix void ModelEntityItem::update(const quint64& now) { { auto currentAnimationProperties = this->getAnimationProperties(); if (_previousAnimationProperties != currentAnimationProperties) { - withWriteLock([&] { - if ((currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { + withWriteLock([&] { + // if we hit start animation or change the first or last frame then restart the animation + if ((currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || + (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || + (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) { + + // when we start interface and the property is are set then the current frame is initialized to -1 if (_currentFrame < 0) { + // don't reset _lastAnimated here because we need the timestamp from the ModelEntityItem constructor for when the properties were set _currentFrame = currentAnimationProperties.getCurrentFrame(); setAnimationCurrentFrame(_currentFrame); - qCDebug(entities) << "restart code hit last animated is " << _lastAnimated << " now is " << now; } else { _lastAnimated = usecTimestampNow(); - qCDebug(entities) << "last animated 1" << _lastAnimated; _currentFrame = currentAnimationProperties.getFirstFrame(); - qCDebug(entities) << "point 2 " << _currentFrame; setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); } - } else if (currentAnimationProperties.getHold() && !_previousAnimationProperties.getHold()) { - qCDebug(entities) << "hold is pressed" << _currentFrame; - } else if (!currentAnimationProperties.getHold() && _previousAnimationProperties.getHold()) { - qCDebug(entities) << "hold is unpressed" << _currentFrame; - } else if (!currentAnimationProperties.getLoop() && _previousAnimationProperties.getLoop()) { - qCDebug(entities) << "loop is unpressed" << _currentFrame; - } else if (currentAnimationProperties.getLoop() && !_previousAnimationProperties.getLoop()) { - qCDebug(entities) << "loop is pressed" << _currentFrame; } else if (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) { + // don't reset _lastAnimated here because the currentFrame was set with the previous setting of _lastAnimated _currentFrame = currentAnimationProperties.getCurrentFrame(); - qCDebug(entities) << "point 3 " << _currentFrame; + // qCDebug(entities) << "point 3 " << _currentFrame; } }); _previousAnimationProperties = this->getAnimationProperties(); + } else { - - // if the first frame is less than zero that is an error, so don't do anything. + // else the animation properties have not changed. + // if the first frame is less than zero don't do anything. if (!(getAnimationFirstFrame() < 0)) { - // if the current frame is less than zero then we are restarting the server. + + // if the current frame is less than zero then we have restarted the server. if (_currentFrame < 0) { - if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { + if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && + (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { _currentFrame = currentAnimationProperties.getCurrentFrame(); } else { _currentFrame = currentAnimationProperties.getFirstFrame(); @@ -240,38 +239,40 @@ void ModelEntityItem::update(const quint64& now) { } } } - // _previousAnimationProperties = currentAnimationProperties; + if (isAnimatingSomething()) { if (!(getAnimationFirstFrame() < 0) && !(getAnimationFirstFrame() > getAnimationLastFrame())) { updateFrameCount(); } } } + EntityItem::update(now); } bool ModelEntityItem::needsToCallUpdate() const { - //return isAnimatingSomething() || EntityItem::needsToCallUpdate(); return true; } void ModelEntityItem::updateFrameCount() { - if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); return; } - auto now = usecTimestampNow(); - // this is now getting the time since the server started the animation. + // update the interval since the last animation. auto interval = now - _lastAnimated; _lastAnimated = now; - + // if fps is negative then increment timestamp and return. + if (getAnimationFPS() < 0.0) { + return; + } + int updatedFrameCount = getAnimationLastFrame() - getAnimationFirstFrame() + 1; if (!getAnimationHold() && getAnimationIsPlaying()) { @@ -298,11 +299,6 @@ void ModelEntityItem::updateFrameCount() { } - - - - - void ModelEntityItem::debugDump() const { qCDebug(entities) << "ModelEntityItem id:" << getEntityItemID(); qCDebug(entities) << " edited ago:" << getEditedAgo(); From 29538851b61c17a8e8561dd1534942e535f40589 Mon Sep 17 00:00:00 2001 From: amantley Date: Mon, 11 Dec 2017 18:50:07 -0800 Subject: [PATCH 18/20] Made the changes from the latest code review, except getting rid of the while loop. --- .../src/RenderableModelEntityItem.cpp | 4 +-- .../src/RenderableModelEntityItem.h | 1 - .../entities/src/AnimationPropertyGroup.cpp | 9 +++--- libraries/entities/src/ModelEntityItem.cpp | 31 ++++++++++--------- libraries/entities/src/ModelEntityItem.h | 4 +-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 4686cc94bc..e578e4858d 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -992,7 +992,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } - { + { // the current frame is set on the server in update() in ModelEntityItem.cpp int animationCurrentFrame = (int)(glm::floor(entity->getAnimationCurrentFrame())); @@ -1313,7 +1313,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce } // The code to deal with the change of properties is now in ModelEntityItem.cpp - // That is where _currentFrame and _lastAnimated are updated. + // That is where _currentFrame and _lastAnimated were updated. if (_animating) { DETAILED_PROFILE_RANGE(simulation_physics, "Animate"); if (!jointsMapped()) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 44ee82713d..b4f2665692 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -184,7 +184,6 @@ private: bool _shouldHighlight { false }; bool _animating { false }; uint64_t _lastAnimated { 0 }; - float _currentFrame { -1 }; }; } } // namespace diff --git a/libraries/entities/src/AnimationPropertyGroup.cpp b/libraries/entities/src/AnimationPropertyGroup.cpp index 932bdbf8c0..2af56fb6b2 100644 --- a/libraries/entities/src/AnimationPropertyGroup.cpp +++ b/libraries/entities/src/AnimationPropertyGroup.cpp @@ -22,24 +22,25 @@ const float AnimationPropertyGroup::MAXIMUM_POSSIBLE_FRAME = 100000.0f; bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b) { return - (a._url == b._url) && + (a._currentFrame == b._currentFrame) && (a._running == b._running) && (a._loop == b._loop) && + (a._hold == b._hold) && (a._firstFrame == b._firstFrame) && (a._lastFrame == b._lastFrame) && - (a._hold == b._hold); + (a._url == b._url); } bool operator!=(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b) { return - (a._url != b._url) || (a._currentFrame != b._currentFrame) || (a._running != b._running) || (a._loop != b._loop) || + (a._hold != b._hold) || (a._firstFrame != b._firstFrame) || (a._lastFrame != b._lastFrame) || - (a._hold != b._hold); + (a._url != b._url); } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 260074da68..4ade724a82 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -207,11 +207,16 @@ void ModelEntityItem::update(const quint64& now) { // don't reset _lastAnimated here because we need the timestamp from the ModelEntityItem constructor for when the properties were set _currentFrame = currentAnimationProperties.getCurrentFrame(); setAnimationCurrentFrame(_currentFrame); + qCDebug(entities) << "setting first frame 1 " << _currentFrame; } else { - _lastAnimated = usecTimestampNow(); + _lastAnimated = usecTimestampNow(); _currentFrame = currentAnimationProperties.getFirstFrame(); setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); + qCDebug(entities) << "setting first frame 2" << _currentFrame; } + } else if (!currentAnimationProperties.getRunning() && _previousAnimationProperties.getRunning()) { + _currentFrame = currentAnimationProperties.getFirstFrame(); + setAnimationCurrentFrame(_currentFrame); } else if (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) { // don't reset _lastAnimated here because the currentFrame was set with the previous setting of _lastAnimated _currentFrame = currentAnimationProperties.getCurrentFrame(); @@ -228,13 +233,15 @@ void ModelEntityItem::update(const quint64& now) { // if the current frame is less than zero then we have restarted the server. if (_currentFrame < 0) { + //qCDebug(entities) << "setting first frame 3 " << _currentFrame; if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { - _currentFrame = currentAnimationProperties.getCurrentFrame(); + // _currentFrame = currentAnimationProperties.getCurrentFrame(); } else { - _currentFrame = currentAnimationProperties.getFirstFrame(); - setAnimationCurrentFrame(_currentFrame); - _lastAnimated = usecTimestampNow(); + //qCDebug(entities) << "setting first frame 4 " << _currentFrame; + // _currentFrame = currentAnimationProperties.getFirstFrame(); + // setAnimationCurrentFrame(_currentFrame); + // _lastAnimated = usecTimestampNow(); } } } @@ -269,7 +276,7 @@ void ModelEntityItem::updateFrameCount() { _lastAnimated = now; // if fps is negative then increment timestamp and return. - if (getAnimationFPS() < 0.0) { + if (getAnimationFPS() < 0.0f) { return; } @@ -280,8 +287,9 @@ void ModelEntityItem::updateFrameCount() { _currentFrame += (deltaTime * getAnimationFPS()); if (_currentFrame > getAnimationLastFrame()) { if (getAnimationLoop()) { - while ((_currentFrame - getAnimationFirstFrame()) > (updatedFrameCount - 1)) { - _currentFrame -= (updatedFrameCount - 1); + //_currentFrame = getAnimationFirstFrame() + (int)(glm::floor(_currentFrame - getAnimationFirstFrame())) % (updatedFrameCount - 1); + while (_currentFrame > (getAnimationFirstFrame() + (updatedFrameCount - 1))) { + _currentFrame = _currentFrame - (updatedFrameCount - 1); } } else { _currentFrame = getAnimationLastFrame(); @@ -293,6 +301,7 @@ void ModelEntityItem::updateFrameCount() { _currentFrame = getAnimationFirstFrame(); } } + qCDebug(entities) << "in update frame " << _currentFrame; setAnimationCurrentFrame(_currentFrame); } @@ -720,9 +729,3 @@ bool ModelEntityItem::isAnimatingSomething() const { (_animationProperties.getFPS() != 0.0f); }); } - -int ModelEntityItem::getLastKnownCurrentFrame() const { - return resultWithReadLock([&] { - return _lastKnownCurrentFrame; - }); -} diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index c0ca12c7f9..7fee022011 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -110,8 +110,6 @@ public: float getAnimationFPS() const; bool isAnimatingSomething() const; - int getLastKnownCurrentFrame() const; - static const QString DEFAULT_TEXTURES; const QString getTextures() const; void setTextures(const QString& textures); @@ -172,7 +170,7 @@ protected: private: uint64_t _lastAnimated{ 0 }; AnimationPropertyGroup _previousAnimationProperties; - float _currentFrame{ -1 }; + float _currentFrame{ -1.0f }; }; #endif // hifi_ModelEntityItem_h From 079d9639e477844bdb79f213cafc21334f15f806 Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 12 Dec 2017 09:12:11 -0800 Subject: [PATCH 19/20] Got rid of the while loop in updateFrameCount in ModelEntityItem_cpp --- libraries/entities/src/ModelEntityItem.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 4ade724a82..3215ab9dd0 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -287,10 +287,7 @@ void ModelEntityItem::updateFrameCount() { _currentFrame += (deltaTime * getAnimationFPS()); if (_currentFrame > getAnimationLastFrame()) { if (getAnimationLoop()) { - //_currentFrame = getAnimationFirstFrame() + (int)(glm::floor(_currentFrame - getAnimationFirstFrame())) % (updatedFrameCount - 1); - while (_currentFrame > (getAnimationFirstFrame() + (updatedFrameCount - 1))) { - _currentFrame = _currentFrame - (updatedFrameCount - 1); - } + _currentFrame = getAnimationFirstFrame() + (int)(glm::floor(_currentFrame - getAnimationFirstFrame())) % (updatedFrameCount - 1); } else { _currentFrame = getAnimationLastFrame(); } From 5bc113c81844d9d7753c8214ab67dd6f41f60d7c Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 13 Dec 2017 19:07:23 -0800 Subject: [PATCH 20/20] deleted some debug print statements in ModelEntityItemcpp and deleted else statement that was superfluous --- libraries/entities/src/ModelEntityItem.cpp | 28 ++++------------------ 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 3215ab9dd0..323584c7ee 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -207,12 +207,10 @@ void ModelEntityItem::update(const quint64& now) { // don't reset _lastAnimated here because we need the timestamp from the ModelEntityItem constructor for when the properties were set _currentFrame = currentAnimationProperties.getCurrentFrame(); setAnimationCurrentFrame(_currentFrame); - qCDebug(entities) << "setting first frame 1 " << _currentFrame; } else { _lastAnimated = usecTimestampNow(); _currentFrame = currentAnimationProperties.getFirstFrame(); setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame()); - qCDebug(entities) << "setting first frame 2" << _currentFrame; } } else if (!currentAnimationProperties.getRunning() && _previousAnimationProperties.getRunning()) { _currentFrame = currentAnimationProperties.getFirstFrame(); @@ -220,31 +218,11 @@ void ModelEntityItem::update(const quint64& now) { } else if (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) { // don't reset _lastAnimated here because the currentFrame was set with the previous setting of _lastAnimated _currentFrame = currentAnimationProperties.getCurrentFrame(); - // qCDebug(entities) << "point 3 " << _currentFrame; } }); _previousAnimationProperties = this->getAnimationProperties(); - } else { - // else the animation properties have not changed. - // if the first frame is less than zero don't do anything. - if (!(getAnimationFirstFrame() < 0)) { - - // if the current frame is less than zero then we have restarted the server. - if (_currentFrame < 0) { - //qCDebug(entities) << "setting first frame 3 " << _currentFrame; - if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && - (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) { - // _currentFrame = currentAnimationProperties.getCurrentFrame(); - } else { - //qCDebug(entities) << "setting first frame 4 " << _currentFrame; - // _currentFrame = currentAnimationProperties.getFirstFrame(); - // setAnimationCurrentFrame(_currentFrame); - // _lastAnimated = usecTimestampNow(); - } - } - } } if (isAnimatingSomething()) { @@ -263,6 +241,10 @@ bool ModelEntityItem::needsToCallUpdate() const { } void ModelEntityItem::updateFrameCount() { + + if (_currentFrame < 0.0f) { + return; + } if (!_lastAnimated) { _lastAnimated = usecTimestampNow(); @@ -298,7 +280,7 @@ void ModelEntityItem::updateFrameCount() { _currentFrame = getAnimationFirstFrame(); } } - qCDebug(entities) << "in update frame " << _currentFrame; + // qCDebug(entities) << "in update frame " << _currentFrame; setAnimationCurrentFrame(_currentFrame); }