Starting to implement the update function to ModelEntityItem_cpp Also put access to the currently playing frame in RenderableModelEntityItem_cpp

This commit is contained in:
amantley 2017-11-16 18:38:28 -08:00
parent ded81fcab0
commit 20fd893b47
5 changed files with 57 additions and 12 deletions

View file

@ -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())) {

View file

@ -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);

View file

@ -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);
};

View file

@ -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<float>([&] {
return resultWithReadLock<bool>([&] {
return _animationProperties.getRunning();
});
}
@ -614,11 +636,17 @@ float ModelEntityItem::getAnimationCurrentFrame() const {
return _animationProperties.getCurrentFrame();
});
}
//angus change
bool ModelEntityItem::isAnimatingSomething() const {
return resultWithReadLock<float>([&] {
return resultWithReadLock<bool>([&] {
return !_animationProperties.getURL().isEmpty() &&
_animationProperties.getRunning() &&
(_animationProperties.getFPS() != 0.0f);
});
}
float ModelEntityItem::getCurrentlyPlayingFrame() const {
return resultWithReadLock<float>([&] {
return _currentlyPlayingFrame;
});
}

View file

@ -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