this is the change to add a property for the currentframeplaying

This commit is contained in:
amantley 2017-11-17 18:37:54 -08:00
parent 20fd893b47
commit 013d16cee9
8 changed files with 102 additions and 20 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<int>([&] {
return _lastKnownCurrentFrame;
});
}
//angus change

View file

@ -17,6 +17,7 @@
#include <ThreadSafeValueCache.h>
#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<ModelJointData> _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