From 20fd893b47dfd3b2214c830fd56646c81393e8a6 Mon Sep 17 00:00:00 2001 From: amantley Date: Thu, 16 Nov 2017 18:38:28 -0800 Subject: [PATCH] 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