mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
get animation to actually run again
This commit is contained in:
parent
aca25bd76e
commit
91a27e3adf
6 changed files with 66 additions and 74 deletions
|
@ -14,8 +14,7 @@
|
|||
|
||||
const float AnimationLoop::MAXIMUM_POSSIBLE_FRAME = 100000.0f;
|
||||
|
||||
AnimationLoop::AnimationLoop()
|
||||
/*:
|
||||
AnimationLoop::AnimationLoop() :
|
||||
_fps(30.0f),
|
||||
_loop(false),
|
||||
_hold(false),
|
||||
|
@ -24,7 +23,7 @@ _firstFrame(0.0f),
|
|||
_lastFrame(MAXIMUM_POSSIBLE_FRAME),
|
||||
_running(false),
|
||||
_frameIndex(0.0f),
|
||||
_maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME)*/
|
||||
_maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -85,6 +84,7 @@ void AnimationLoop::setStartAutomatically(bool startAutomatically) {
|
|||
}
|
||||
|
||||
void AnimationLoop::setRunning(bool running) {
|
||||
qDebug() << "AnimationLoop::setRunning() new running:" << running << "old _running:" << _running;
|
||||
// don't do anything if the new value is the same as the value we already have
|
||||
if (_running != running) {
|
||||
_running = running;
|
||||
|
|
|
@ -269,6 +269,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
|||
if (_model) {
|
||||
// handle animations..
|
||||
if (hasAnimation()) {
|
||||
|
||||
if (!jointsMapped()) {
|
||||
QStringList modelJointNames = _model->getJointNames();
|
||||
mapJoints(modelJointNames);
|
||||
|
|
|
@ -17,22 +17,35 @@
|
|||
#include "EntityItemProperties.h"
|
||||
#include "EntityItemPropertiesMacros.h"
|
||||
|
||||
AnimationPropertyGroup::AnimationPropertyGroup() {
|
||||
//_url = QString();
|
||||
|
||||
AnimationPropertyGroup::AnimationPropertyGroup() :
|
||||
CONSTRUCT_PROPERTY(fps, 30.0f),
|
||||
CONSTRUCT_PROPERTY(running, false),
|
||||
CONSTRUCT_PROPERTY(loop, true),
|
||||
CONSTRUCT_PROPERTY(firstFrame, 0.0f),
|
||||
CONSTRUCT_PROPERTY(lastFrame, AnimationLoop::MAXIMUM_POSSIBLE_FRAME),
|
||||
CONSTRUCT_PROPERTY(hold, false),
|
||||
CONSTRUCT_PROPERTY(startAutomatically, false)
|
||||
{
|
||||
static const QString DEFAULT_URL;
|
||||
|
||||
_url = DEFAULT_URL;
|
||||
}
|
||||
|
||||
void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_URL, AnimationSettings, animationSettings, URL, url);
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::copyToScriptValue() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_FPS, AnimationSettings, animationSettings, FPS, fps, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_FRAME_INDEX, AnimationSettings, animationSettings, FrameIndex, frameIndex, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_FRAME_INDEX, AnimationSettings, animationSettings, Running, running, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_LOOP, AnimationSettings, animationSettings, Loop, loop, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_FIRST_FRAME, AnimationSettings, animationSettings, FirstFrame, firstFrame, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_LAST_FRAME, AnimationSettings, animationSettings, LastFrame, lastFrame, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_HOLD, AnimationSettings, animationSettings, Hold, hold, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_START_AUTOMATICALLY, AnimationSettings, animationSettings, StartAutomatically, startAutomatically, _animationLoop->getFPS);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_FRAME_INDEX, AnimationSettings, animationSettings, Running, running, _animationLoop->getRunning);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_LOOP, AnimationSettings, animationSettings, Loop, loop, _animationLoop->getLoop);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_FIRST_FRAME, AnimationSettings, animationSettings, FirstFrame, firstFrame, _animationLoop->getFirstFrame);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_LAST_FRAME, AnimationSettings, animationSettings, LastFrame, lastFrame, _animationLoop->getLastFrame);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_HOLD, AnimationSettings, animationSettings, Hold, hold, _animationLoop->getHold);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ANIMATION_START_AUTOMATICALLY, AnimationSettings, animationSettings, StartAutomatically, startAutomatically, _animationLoop->getStartAutomatically);
|
||||
} else {
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_FPS, AnimationSettings, animationSettings, FPS, fps);
|
||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_ANIMATION_FRAME_INDEX, AnimationSettings, animationSettings, FrameIndex, frameIndex);
|
||||
|
@ -48,6 +61,8 @@ void AnimationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desire
|
|||
void AnimationPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) {
|
||||
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animationSettings, url, QString, setURL);
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::copyFromScriptValue() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animationSettings, fps, float, _animationLoop->setFPS);
|
||||
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animationSettings, frameIndex, float, _animationLoop->setFrameIndex);
|
||||
|
@ -84,6 +99,9 @@ bool AnimationPropertyGroup::appendToEditPacket(OctreePacketData* packetData,
|
|||
bool successPropertyFits = true;
|
||||
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, getURL());
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::appendToEditPacket() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, _animationLoop->getFPS());
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, _animationLoop->getFrameIndex());
|
||||
|
@ -114,6 +132,9 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF
|
|||
bool overwriteLocalData = true;
|
||||
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_URL, QString, setURL);
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::decodeFromEditPacket() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, _animationLoop->setFPS);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, _animationLoop->setFrameIndex);
|
||||
|
@ -175,6 +196,8 @@ EntityPropertyFlags AnimationPropertyGroup::getChangedProperties() const {
|
|||
void AnimationPropertyGroup::getProperties(EntityItemProperties& properties) const {
|
||||
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(AnimationSettings, URL, getURL);
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::getProperties() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(AnimationSettings, FPS, _animationLoop->getFPS);
|
||||
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(AnimationSettings, FrameIndex, _animationLoop->getFrameIndex);
|
||||
|
@ -201,8 +224,10 @@ bool AnimationPropertyGroup::setProperties(const EntityItemProperties& propertie
|
|||
|
||||
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(AnimationSettings, URL, url, setURL);
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::setProperties() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
qDebug() << "AnimationPropertyGroup::setProperties() -- apply new properties to our associated AnimationLoop";
|
||||
//qDebug() << "AnimationPropertyGroup::setProperties() -- apply new properties to our associated AnimationLoop";
|
||||
|
||||
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(AnimationSettings, FPS, fps, _animationLoop->setFPS);
|
||||
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(AnimationSettings, FrameIndex, frameIndex, _animationLoop->setFrameIndex);
|
||||
|
@ -252,6 +277,8 @@ void AnimationPropertyGroup::appendSubclassData(OctreePacketData* packetData, En
|
|||
|
||||
bool successPropertyFits = true;
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::appendSubclassData() url:" << getURL();
|
||||
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, getURL());
|
||||
if (_animationLoop) {
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, getFPS());
|
||||
|
@ -282,9 +309,12 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char
|
|||
const unsigned char* dataAt = data;
|
||||
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_URL, QString, setURL);
|
||||
|
||||
//qDebug() << "AnimationPropertyGroup::readEntitySubclassDataFromBuffer() url:" << getURL();
|
||||
|
||||
if (_animationLoop) {
|
||||
// apply new properties to our associated AnimationLoop
|
||||
qDebug() << "AnimationPropertyGroup::readEntitySubclassDataFromBuffer() -- apply new properties to our associated AnimationLoop";
|
||||
//qDebug() << "AnimationPropertyGroup::readEntitySubclassDataFromBuffer() -- apply new properties to our associated AnimationLoop";
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, _animationLoop->setFPS);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, _animationLoop->setFrameIndex);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, _animationLoop->setRunning);
|
||||
|
|
|
@ -91,7 +91,10 @@ public:
|
|||
DEFINE_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, StartAutomatically, startAutomatically, bool); // was animationSettings.startAutomatically
|
||||
|
||||
public:
|
||||
void associateWithAnimationLoop(AnimationLoop* animationLoop) { _animationLoop = animationLoop; }
|
||||
void associateWithAnimationLoop(AnimationLoop* animationLoop) {
|
||||
qDebug() << "associateWithAnimationLoop() this:" << this << "animationLoop:" << animationLoop;
|
||||
_animationLoop = animationLoop;
|
||||
}
|
||||
private:
|
||||
AnimationLoop* _animationLoop = nullptr;
|
||||
};
|
||||
|
|
|
@ -35,15 +35,15 @@ EntityItemPointer ModelEntityItem::factory(const EntityItemID& entityID, const E
|
|||
ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||
EntityItem(entityItemID)
|
||||
{
|
||||
_animationProperties.associateWithAnimationLoop(&_animationLoop);
|
||||
_animationLoop.setResetOnRunning(false);
|
||||
|
||||
_type = EntityTypes::Model;
|
||||
setProperties(properties);
|
||||
_lastAnimated = usecTimestampNow();
|
||||
_jointMappingCompleted = false;
|
||||
_lastKnownFrameIndex = -1;
|
||||
_color[0] = _color[1] = _color[2] = 0;
|
||||
|
||||
_animationProperties.associateWithAnimationLoop(&_animationLoop);
|
||||
_animationLoop.setResetOnRunning(false);
|
||||
}
|
||||
|
||||
EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredProperties) const {
|
||||
|
@ -62,6 +62,8 @@ EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredP
|
|||
}
|
||||
|
||||
bool ModelEntityItem::setProperties(const EntityItemProperties& properties) {
|
||||
qDebug() << "ModelEntityItem::setProperties() id:" << getEntityItemID();
|
||||
|
||||
bool somethingChanged = false;
|
||||
somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class
|
||||
|
||||
|
@ -215,7 +217,7 @@ void ModelEntityItem::mapJoints(const QStringList& modelJointNames) {
|
|||
return;
|
||||
}
|
||||
|
||||
AnimationPointer myAnimation = getAnimation(_animationURL);
|
||||
AnimationPointer myAnimation = getAnimation(_animationProperties.getURL());
|
||||
if (myAnimation && myAnimation->isLoaded()) {
|
||||
QStringList animationJointNames = myAnimation->getJointNames();
|
||||
|
||||
|
@ -236,7 +238,7 @@ const QVector<glm::quat>& ModelEntityItem::getAnimationFrame(bool& newFrame) {
|
|||
return _lastKnownFrameData;
|
||||
}
|
||||
|
||||
AnimationPointer myAnimation = getAnimation(_animationURL); // FIXME: this could be optimized
|
||||
AnimationPointer myAnimation = getAnimation(_animationProperties.getURL()); // FIXME: this could be optimized
|
||||
if (myAnimation && myAnimation->isLoaded()) {
|
||||
|
||||
const QVector<FBXAnimationFrame>& frames = myAnimation->getFramesReference(); // NOTE: getFrames() is too heavy
|
||||
|
@ -282,6 +284,7 @@ void ModelEntityItem::update(const quint64& now) {
|
|||
if (getAnimationIsPlaying()) {
|
||||
float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND;
|
||||
_lastAnimated = now;
|
||||
qDebug() << "ModelEntityItem::update() calling _animationLoop.simulate(deltaTime);";
|
||||
_animationLoop.simulate(deltaTime);
|
||||
} else {
|
||||
_lastAnimated = now;
|
||||
|
@ -334,7 +337,7 @@ void ModelEntityItem::setCompoundShapeURL(const QString& url) {
|
|||
|
||||
void ModelEntityItem::setAnimationURL(const QString& url) {
|
||||
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
|
||||
_animationURL = url;
|
||||
_animationProperties.setURL(url);
|
||||
}
|
||||
|
||||
void ModelEntityItem::setAnimationFrameIndex(float value) {
|
||||
|
@ -411,7 +414,7 @@ void ModelEntityItem::setAnimationSettings(const QString& value) {
|
|||
setAnimationStartAutomatically(startAutomatically);
|
||||
}
|
||||
|
||||
_animationSettings = value;
|
||||
//_animationSettings = value;
|
||||
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
|
||||
}
|
||||
|
||||
|
@ -425,47 +428,6 @@ void ModelEntityItem::setAnimationFPS(float value) {
|
|||
_animationLoop.setFPS(value);
|
||||
}
|
||||
|
||||
QString ModelEntityItem::getAnimationSettings() const {
|
||||
// the animations setting is a JSON string that may contain various animation settings.
|
||||
// if it includes fps, frameIndex, or running, those values will be parsed out and
|
||||
// will over ride the regular animation settings
|
||||
QString value = _animationSettings;
|
||||
|
||||
QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8());
|
||||
QJsonObject settingsAsJsonObject = settingsAsJson.object();
|
||||
QVariantMap settingsMap = settingsAsJsonObject.toVariantMap();
|
||||
|
||||
QVariant fpsValue(getAnimationFPS());
|
||||
settingsMap["fps"] = fpsValue;
|
||||
|
||||
QVariant frameIndexValue(getAnimationFrameIndex());
|
||||
settingsMap["frameIndex"] = frameIndexValue;
|
||||
|
||||
QVariant runningValue(getAnimationIsPlaying());
|
||||
settingsMap["running"] = runningValue;
|
||||
|
||||
QVariant firstFrameValue(getAnimationFirstFrame());
|
||||
settingsMap["firstFrame"] = firstFrameValue;
|
||||
|
||||
QVariant lastFrameValue(getAnimationLastFrame());
|
||||
settingsMap["lastFrame"] = lastFrameValue;
|
||||
|
||||
QVariant loopValue(getAnimationLoop());
|
||||
settingsMap["loop"] = loopValue;
|
||||
|
||||
QVariant holdValue(getAnimationHold());
|
||||
settingsMap["hold"] = holdValue;
|
||||
|
||||
QVariant startAutomaticallyValue(getAnimationStartAutomatically());
|
||||
settingsMap["startAutomatically"] = startAutomaticallyValue;
|
||||
|
||||
settingsAsJsonObject = QJsonObject::fromVariantMap(settingsMap);
|
||||
QJsonDocument newDocument(settingsAsJsonObject);
|
||||
QByteArray jsonByteArray = newDocument.toJson(QJsonDocument::Compact);
|
||||
QString jsonByteString(jsonByteArray);
|
||||
return jsonByteString;
|
||||
}
|
||||
|
||||
// virtual
|
||||
bool ModelEntityItem::shouldBePhysical() const {
|
||||
return EntityItem::shouldBePhysical() && getShapeType() != SHAPE_TYPE_NONE;
|
||||
|
|
|
@ -65,10 +65,6 @@ public:
|
|||
static const QString DEFAULT_COMPOUND_SHAPE_URL;
|
||||
const QString& getCompoundShapeURL() const { return _compoundShapeURL; }
|
||||
|
||||
bool hasAnimation() const { return !_animationURL.isEmpty(); }
|
||||
static const QString DEFAULT_ANIMATION_URL;
|
||||
const QString& getAnimationURL() const { return _animationURL; }
|
||||
|
||||
void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); }
|
||||
void setColor(const xColor& value) {
|
||||
_color[RED_INDEX] = value.red;
|
||||
|
@ -84,10 +80,13 @@ public:
|
|||
// Animation related items...
|
||||
const AnimationPropertyGroup& getAnimationProperties() const { return _animationProperties; }
|
||||
|
||||
bool hasAnimation() const { return !_animationProperties.getURL().isEmpty(); }
|
||||
static const QString DEFAULT_ANIMATION_URL;
|
||||
const QString& getAnimationURL() const { return _animationProperties.getURL(); }
|
||||
void setAnimationURL(const QString& url);
|
||||
|
||||
static const float DEFAULT_ANIMATION_FRAME_INDEX;
|
||||
void setAnimationFrameIndex(float value);
|
||||
void setAnimationSettings(const QString& value);
|
||||
|
||||
static const bool DEFAULT_ANIMATION_IS_PLAYING;
|
||||
void setAnimationIsPlaying(bool value);
|
||||
|
@ -117,7 +116,6 @@ public:
|
|||
bool getAnimationIsPlaying() const { return _animationLoop.isRunning(); }
|
||||
float getAnimationFrameIndex() const { return _animationLoop.getFrameIndex(); }
|
||||
float getAnimationFPS() const { return _animationLoop.getFPS(); }
|
||||
QString getAnimationSettings() const;
|
||||
|
||||
static const QString DEFAULT_TEXTURES;
|
||||
const QString& getTextures() const { return _textures; }
|
||||
|
@ -126,7 +124,10 @@ public:
|
|||
virtual bool shouldBePhysical() const;
|
||||
|
||||
static void cleanupLoadedAnimations();
|
||||
|
||||
|
||||
private:
|
||||
void setAnimationSettings(const QString& value); // only called for old bitstream format
|
||||
|
||||
protected:
|
||||
QVector<glm::quat> _lastKnownFrameData;
|
||||
int _lastKnownFrameIndex;
|
||||
|
@ -142,11 +143,6 @@ protected:
|
|||
AnimationPropertyGroup _animationProperties;
|
||||
AnimationLoop _animationLoop;
|
||||
|
||||
// FIXME - delete these
|
||||
QString _animationURL;
|
||||
QString _animationSettings;
|
||||
|
||||
|
||||
QString _textures;
|
||||
ShapeType _shapeType = SHAPE_TYPE_NONE;
|
||||
|
||||
|
|
Loading…
Reference in a new issue