mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 12:14:00 +02:00
first cut at migrating entity animation frame calculations to use AnimationLoop
This commit is contained in:
parent
d2ab3e69f0
commit
245f019836
3 changed files with 43 additions and 24 deletions
|
@ -40,6 +40,18 @@
|
|||
} \
|
||||
}
|
||||
|
||||
#define READ_ENTITY_PROPERTY_SETTER(P,T,M) \
|
||||
if (propertyFlags.getHasProperty(P)) { \
|
||||
T fromBuffer; \
|
||||
memcpy(&fromBuffer, dataAt, sizeof(fromBuffer)); \
|
||||
dataAt += sizeof(fromBuffer); \
|
||||
bytesRead += sizeof(fromBuffer); \
|
||||
if (overwriteLocalData) { \
|
||||
M(fromBuffer); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define READ_ENTITY_PROPERTY_QUAT(P,M) \
|
||||
if (propertyFlags.getHasProperty(P)) { \
|
||||
glm::quat fromBuffer; \
|
||||
|
|
|
@ -33,10 +33,11 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityI
|
|||
{
|
||||
_type = EntityTypes::Model;
|
||||
setProperties(properties, true);
|
||||
_animationFrameIndex = 0.0f;
|
||||
_lastAnimated = usecTimestampNow();
|
||||
_jointMappingCompleted = false;
|
||||
_color[0] = _color[1] = _color[2] = 0;
|
||||
|
||||
//_animationFrameIndex = 0.0f;
|
||||
}
|
||||
|
||||
EntityItemProperties ModelEntityItem::getProperties() const {
|
||||
|
@ -100,9 +101,9 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
|
|||
READ_ENTITY_PROPERTY_COLOR(PROP_COLOR, _color);
|
||||
READ_ENTITY_PROPERTY_STRING(PROP_MODEL_URL, setModelURL);
|
||||
READ_ENTITY_PROPERTY_STRING(PROP_ANIMATION_URL, setAnimationURL);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, _animationFPS);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, _animationFrameIndex);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, _animationIsPlaying);
|
||||
READ_ENTITY_PROPERTY_SETTER(PROP_ANIMATION_FPS, float, setAnimationFPS);
|
||||
READ_ENTITY_PROPERTY_SETTER(PROP_ANIMATION_FRAME_INDEX, float, setAnimationFrameIndex);
|
||||
READ_ENTITY_PROPERTY_SETTER(PROP_ANIMATION_PLAYING, bool, setAnimationIsPlaying);
|
||||
READ_ENTITY_PROPERTY_STRING(PROP_TEXTURES, setTextures);
|
||||
|
||||
return bytesRead;
|
||||
|
@ -199,19 +200,25 @@ int ModelEntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* dat
|
|||
bytesRead += animationURLLength;
|
||||
|
||||
// animationIsPlaying
|
||||
memcpy(&_animationIsPlaying, dataAt, sizeof(_animationIsPlaying));
|
||||
dataAt += sizeof(_animationIsPlaying);
|
||||
bytesRead += sizeof(_animationIsPlaying);
|
||||
bool animationIsPlaying;
|
||||
memcpy(&animationIsPlaying, dataAt, sizeof(animationIsPlaying));
|
||||
dataAt += sizeof(animationIsPlaying);
|
||||
bytesRead += sizeof(animationIsPlaying);
|
||||
setAnimationIsPlaying(animationIsPlaying);
|
||||
|
||||
// animationFrameIndex
|
||||
memcpy(&_animationFrameIndex, dataAt, sizeof(_animationFrameIndex));
|
||||
dataAt += sizeof(_animationFrameIndex);
|
||||
bytesRead += sizeof(_animationFrameIndex);
|
||||
float animationFrameIndex;
|
||||
memcpy(&animationFrameIndex, dataAt, sizeof(animationFrameIndex));
|
||||
dataAt += sizeof(animationFrameIndex);
|
||||
bytesRead += sizeof(animationFrameIndex);
|
||||
setAnimationFrameIndex(animationFrameIndex);
|
||||
|
||||
// animationFPS
|
||||
memcpy(&_animationFPS, dataAt, sizeof(_animationFPS));
|
||||
dataAt += sizeof(_animationFPS);
|
||||
bytesRead += sizeof(_animationFPS);
|
||||
float animationFPS;
|
||||
memcpy(&animationFPS, dataAt, sizeof(animationFPS));
|
||||
dataAt += sizeof(animationFPS);
|
||||
bytesRead += sizeof(animationFPS);
|
||||
setAnimationFPS(animationFPS);
|
||||
}
|
||||
}
|
||||
return bytesRead;
|
||||
|
@ -314,7 +321,7 @@ QVector<glm::quat> ModelEntityItem::getAnimationFrame() {
|
|||
int frameCount = frames.size();
|
||||
|
||||
if (frameCount > 0) {
|
||||
int animationFrameIndex = (int)(glm::floor(_animationFrameIndex)) % frameCount;
|
||||
int animationFrameIndex = (int)(glm::floor(getAnimationFrameIndex())) % frameCount;
|
||||
|
||||
if (animationFrameIndex < 0 || animationFrameIndex > frameCount) {
|
||||
animationFrameIndex = 0;
|
||||
|
@ -363,7 +370,7 @@ void ModelEntityItem::update(const quint64& updateTime) {
|
|||
if (getAnimationIsPlaying()) {
|
||||
float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND;
|
||||
_lastAnimated = now;
|
||||
_animationFrameIndex += deltaTime * _animationFPS;
|
||||
_animationLoop.simulate(deltaTime);
|
||||
} else {
|
||||
_lastAnimated = now;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#ifndef hifi_ModelEntityItem_h
|
||||
#define hifi_ModelEntityItem_h
|
||||
|
||||
#include <AnimationLoop.h>
|
||||
|
||||
#include "EntityItem.h"
|
||||
|
||||
class ModelEntityItem : public EntityItem {
|
||||
|
@ -73,21 +75,21 @@ public:
|
|||
void setModelURL(const QString& url) { _modelURL = url; }
|
||||
void setAnimationURL(const QString& url) { _animationURL = url; }
|
||||
static const float DEFAULT_ANIMATION_FRAME_INDEX;
|
||||
void setAnimationFrameIndex(float value) { _animationFrameIndex = value; }
|
||||
void setAnimationFrameIndex(float value) { _animationLoop.setFrameIndex(value); }
|
||||
|
||||
static const bool DEFAULT_ANIMATION_IS_PLAYING;
|
||||
void setAnimationIsPlaying(bool value) { _animationIsPlaying = value; }
|
||||
void setAnimationIsPlaying(bool value) { _animationLoop.setRunning(value); }
|
||||
|
||||
static const float DEFAULT_ANIMATION_FPS;
|
||||
void setAnimationFPS(float value) { _animationFPS = value; }
|
||||
void setAnimationFPS(float value) { _animationLoop.setFPS(value); }
|
||||
|
||||
void mapJoints(const QStringList& modelJointNames);
|
||||
QVector<glm::quat> getAnimationFrame();
|
||||
bool jointsMapped() const { return _jointMappingCompleted; }
|
||||
|
||||
bool getAnimationIsPlaying() const { return _animationIsPlaying; }
|
||||
float getAnimationFrameIndex() const { return _animationFrameIndex; }
|
||||
float getAnimationFPS() const { return _animationFPS; }
|
||||
bool getAnimationIsPlaying() const { return _animationLoop.isRunning(); }
|
||||
float getAnimationFrameIndex() const { return _animationLoop.getFrameIndex(); }
|
||||
float getAnimationFPS() const { return _animationLoop.getFPS(); }
|
||||
|
||||
static const QString DEFAULT_TEXTURES;
|
||||
const QString& getTextures() const { return _textures; }
|
||||
|
@ -106,9 +108,7 @@ protected:
|
|||
|
||||
quint64 _lastAnimated;
|
||||
QString _animationURL;
|
||||
float _animationFrameIndex; // we keep this as a float and round to int only when we need the exact index
|
||||
bool _animationIsPlaying;
|
||||
float _animationFPS;
|
||||
AnimationLoop _animationLoop;
|
||||
QString _textures;
|
||||
|
||||
// used on client side
|
||||
|
|
Loading…
Reference in a new issue