From cd4ea4b34f6a53699e62d8138ec731e7d2c94400 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 7 Aug 2014 13:13:37 -0700 Subject: [PATCH] more animation work --- examples/editModels.js | 2 ++ interface/src/entities/EntityTreeRenderer.cpp | 8 +++++--- libraries/entities/src/EntityTree.cpp | 19 +++++++++++++++++-- libraries/entities/src/ModelEntityItem.cpp | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index d0029ad2b5..dc4e73d1f2 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -1609,6 +1609,7 @@ function handeMenuEvent(menuItem){ array.push({ label: "Animation URL:", value: properties.animationURL }); array.push({ label: "Animation is playing:", value: properties.animationIsPlaying }); array.push({ label: "Animation FPS:", value: properties.animationFPS }); + array.push({ label: "Animation Frame:", value: properties.animationFrameIndex }); } array.push({ label: "X:", value: properties.position.x.toFixed(decimals) }); array.push({ label: "Y:", value: properties.position.y.toFixed(decimals) }); @@ -1634,6 +1635,7 @@ function handeMenuEvent(menuItem){ properties.animationURL = array[index++].value; properties.animationIsPlaying = array[index++].value; properties.animationFPS = array[index++].value; + properties.animationFrameIndex = array[index++].value; } properties.position.x = array[index++].value; properties.position.y = array[index++].value; diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index 74bf9376f6..ae8e892434 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -315,9 +315,11 @@ void EntityTreeRenderer::renderEntityTypeModel(EntityItem* entity, RenderArgs* a entityItem->mapJoints(modelJointNames); } - QVector frameData = entityItem->getAnimationFrame(); - for (int i = 0; i < frameData.size(); i++) { - model->setJointState(i, true, frameData[i]); + if (entityItem->jointsMapped()) { + QVector frameData = entityItem->getAnimationFrame(); + for (int i = 0; i < frameData.size(); i++) { + model->setJointState(i, true, frameData[i]); + } } } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 33312037ae..4b8c47464a 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -1078,7 +1078,16 @@ if (childAt) { } void EntityTree::changeEntityState(EntityItem* const entity, EntityItem::SimuationState oldState, EntityItem::SimuationState newState) { - if (oldState != newState) { + +qDebug() << "EntityTree::changeEntityState()...."; +qDebug() << " oldState:" << oldState; +qDebug() << " newState:" << newState; + +qDebug() << "EntityTree::changeEntityState() BEFORE...."; +qDebug() << " _changingEntities:" << _changingEntities; +qDebug() << " _movingEntities:" << _movingEntities; + + //if (oldState != newState) { switch (oldState) { case EntityItem::Changing: _changingEntities.removeAll(entity); @@ -1103,7 +1112,13 @@ void EntityTree::changeEntityState(EntityItem* const entity, EntityItem::Simuati default: break; } - } + //} + +qDebug() << "EntityTree::changeEntityState() AFTER...."; +qDebug() << " _changingEntities:" << _changingEntities; +qDebug() << " _movingEntities:" << _movingEntities; + + } void EntityTree::update() { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 7cded0697c..25aedc88ed 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -33,6 +33,8 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityI qDebug() << "ModelEntityItem::ModelEntityItem() calling setProperties()"; setProperties(properties); qDebug() << "ModelEntityItem::ModelEntityItem() getModelURL()=" << getModelURL(); + + _animationFrameIndex = 0.0f; } EntityItemProperties ModelEntityItem::getProperties() const { @@ -840,6 +842,18 @@ QVector ModelEntityItem::getAnimationFrame() { if (frameCount > 0) { int animationFrameIndex = (int)glm::floor(_animationFrameIndex) % frameCount; + + if (animationFrameIndex < 0 || animationFrameIndex > frameCount) { + qDebug() << "ModelEntityItem::getAnimationFrame()...."; + qDebug() << " frame index out of bounds...."; + qDebug() << " _animationFrameIndex=" << _animationFrameIndex; + qDebug() << " frameCount=" << frameCount; + qDebug() << " animationFrameIndex=" << animationFrameIndex; + animationFrameIndex = 0; + } + +//qDebug() << "ModelEntityItem::getAnimationFrame().... _animationFrameIndex=" << _animationFrameIndex << "frameCount=" << frameCount << "animationFrameIndex=" << animationFrameIndex; + QVector rotations = frames[animationFrameIndex].rotations; frameData.resize(_jointMapping.size()); for (int j = 0; j < _jointMapping.size(); j++) {