From 0fc33f575ffece93f0a928ba50523598c884e871 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 12 May 2014 14:07:54 -0700 Subject: [PATCH] moving frame advancement to update() --- libraries/models/src/ModelItem.cpp | 35 +++++++++++++++-------- libraries/models/src/ModelTreeElement.cpp | 5 ++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libraries/models/src/ModelItem.cpp b/libraries/models/src/ModelItem.cpp index 9dd1173259..f9b1092c84 100644 --- a/libraries/models/src/ModelItem.cpp +++ b/libraries/models/src/ModelItem.cpp @@ -283,6 +283,8 @@ int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftT dataAt += sizeof(_frameIndex); bytesRead += sizeof(_frameIndex); + qDebug() << "readModelDataFromBuffer()... _frameIndex=" << _frameIndex; + } else { qDebug() << "readModelDataFromBuffer()... this model didn't have animation details"; } @@ -695,16 +697,6 @@ void ModelItem::mapJoints(const QStringList& modelJointNames) { QVector ModelItem::getAnimationFrame() { QVector frameData; if (hasAnimation() && _jointMappingCompleted) { - - // only advance the frame index if we're playing - if (getIsAnimationPlaying()) { - quint64 now = usecTimestampNow(); - float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND; - _lastAnimated = now; - const float FRAME_RATE = 10.0f; - _frameIndex += deltaTime * FRAME_RATE; - } - Animation* myAnimation = getAnimation(_animationURL); QVector frames = myAnimation->getFrames(); int frameIndex = (int)std::floor(_frameIndex) % frames.size(); @@ -720,9 +712,28 @@ QVector ModelItem::getAnimationFrame() { return frameData; } -void ModelItem::update(const quint64& now) { - _lastUpdated = now; +void ModelItem::update(const quint64& updateTime) { + _lastUpdated = updateTime; setShouldDie(getShouldDie()); + +//qDebug() << "ModelItem::update() now=" << now; + + // only advance the frame index if we're playing + if (getIsAnimationPlaying()) { + + quint64 now = usecTimestampNow(); + float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND; +qDebug() << "ModelItem::update() now=" << now; +qDebug() << " updateTime=" << updateTime; +qDebug() << " _lastAnimated=" << _lastAnimated; +qDebug() << " deltaTime=" << deltaTime; + + _lastAnimated = now; + const float FRAME_RATE = 10.0f; + _frameIndex += deltaTime * FRAME_RATE; +qDebug() << " _frameIndex=" << _frameIndex; + + } } void ModelItem::copyChangedProperties(const ModelItem& other) { diff --git a/libraries/models/src/ModelTreeElement.cpp b/libraries/models/src/ModelTreeElement.cpp index 4edcdd3e92..e8b37c478b 100644 --- a/libraries/models/src/ModelTreeElement.cpp +++ b/libraries/models/src/ModelTreeElement.cpp @@ -102,10 +102,15 @@ bool ModelTreeElement::bestFitModelBounds(const ModelItem& model) const { } void ModelTreeElement::update(ModelTreeUpdateArgs& args) { +//qDebug() << "ModelTreeElement::update()..."; // update our contained models QList::iterator modelItr = _modelItems->begin(); while(modelItr != _modelItems->end()) { ModelItem& model = (*modelItr); + + // TODO: this _lastChanged isn't actually changing because we're not marking this element as changed. + // how do we want to handle this??? We really only want to consider an element changed when it is + // edited... not just animated... model.update(_lastChanged); // If the model wants to die, or if it's left our bounding box, then move it