From 942958c4f1dfec227ebdee0df30605f67f766845 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 9 Aug 2015 16:07:56 -0700 Subject: [PATCH 1/2] only setJointState() if animation frame actually changed --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 9 ++++++--- libraries/entities/src/ModelEntityItem.cpp | 4 +++- libraries/entities/src/ModelEntityItem.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 6d2ff30d4b..eed908e429 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -275,9 +275,12 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } if (jointsMapped()) { - auto frameData = getAnimationFrame(); - for (int i = 0; i < frameData.size(); i++) { - _model->setJointState(i, true, frameData[i]); + bool newFrame; + auto frameData = getAnimationFrame(newFrame); + if (newFrame) { + for (int i = 0; i < frameData.size(); i++) { + _model->setJointState(i, true, frameData[i]); + } } } } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 362f5dc72a..4c03f4a7da 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -218,7 +218,8 @@ void ModelEntityItem::mapJoints(const QStringList& modelJointNames) { } } -const QVector& ModelEntityItem::getAnimationFrame() { +const QVector& ModelEntityItem::getAnimationFrame(bool& newFrame) { + newFrame = false; if (!hasAnimation() || !_jointMappingCompleted) { return _lastKnownFrameData; @@ -238,6 +239,7 @@ const QVector& ModelEntityItem::getAnimationFrame() { if (animationFrameIndex != _lastKnownFrameIndex) { _lastKnownFrameIndex = animationFrameIndex; + newFrame = true; const QVector& rotations = frames[animationFrameIndex].rotations; diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index e3d42e6b2c..950a95bae2 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -106,7 +106,7 @@ public: float getAnimationLastFrame() const { return _animationLoop.getLastFrame(); } void mapJoints(const QStringList& modelJointNames); - const QVector& getAnimationFrame(); + const QVector& getAnimationFrame(bool& newFrame); bool jointsMapped() const { return _jointMappingCompleted; } bool getAnimationIsPlaying() const { return _animationLoop.isRunning(); } From 668778cfd99c5372e2f571302fcc4293d5b4c081 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 9 Aug 2015 16:55:43 -0700 Subject: [PATCH 2/2] optimize JointState::setRotationInConstrainedFrameInternal() to short cut cases where targetRotation matches previous targetRotation --- libraries/animation/src/JointState.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/animation/src/JointState.cpp b/libraries/animation/src/JointState.cpp index 3682837719..1253dc4649 100644 --- a/libraries/animation/src/JointState.cpp +++ b/libraries/animation/src/JointState.cpp @@ -244,11 +244,13 @@ void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float p } void JointState::setRotationInConstrainedFrameInternal(const glm::quat& targetRotation) { - glm::quat parentRotation = computeParentRotation(); - _rotationInConstrainedFrame = targetRotation; - _transformChanged = true; - // R' = Rp * Rpre * r' * Rpost - _rotation = parentRotation * _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; + if (_rotationInConstrainedFrame != targetRotation) { + glm::quat parentRotation = computeParentRotation(); + _rotationInConstrainedFrame = targetRotation; + _transformChanged = true; + // R' = Rp * Rpre * r' * Rpost + _rotation = parentRotation * _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; + } } void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation) {