From 4754615159f5c4f554181d59e67cc367db2177c2 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 28 Jul 2015 12:34:10 -0700 Subject: [PATCH] Fix NPC animations. --- interface/src/avatar/SkeletonModel.cpp | 3 ++- libraries/animation/src/Rig.cpp | 5 +++-- libraries/animation/src/Rig.h | 5 ++++- libraries/render-utils/src/Model.cpp | 4 ++++ libraries/render-utils/src/Model.h | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 7b6fb85ae5..636e58c5a8 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -116,7 +116,8 @@ void SkeletonModel::updateClusterMatrices() { } void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { - _rig->simulateInternal(deltaTime, parentTransform, _owningAvatar->getPosition(), _owningAvatar->getVelocity(), _owningAvatar->getOrientation()); + _rig->computeMotionAnimationState(deltaTime, _owningAvatar->getPosition(), _owningAvatar->getVelocity(), _owningAvatar->getOrientation()); + Model::updateRig(deltaTime, parentTransform); } void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index d20abc58d6..0bd3f14096 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -341,7 +341,7 @@ glm::mat4 Rig::getJointVisibleTransform(int jointIndex) const { return maybeCauterizeHead(jointIndex).getVisibleTransform(); } -void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) { +void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) { if (_enableRig) { glm::vec3 front = worldRotation * IDENTITY_FRONT; @@ -374,8 +374,9 @@ void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm _isTurning = isTurning; _isIdle = isIdle; } +} - // update animations +void Rig::updateAnimations(float deltaTime, glm::mat4 parentTransform) { foreach (const AnimationHandlePointer& handle, _runningAnimations) { handle->simulate(deltaTime); } diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index 8b2fc10fa5..52d5866369 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -108,7 +108,10 @@ public: void setJointTransform(int jointIndex, glm::mat4 newTransform); glm::mat4 getJointVisibleTransform(int jointIndex) const; void setJointVisibleTransform(int jointIndex, glm::mat4 newTransform); - void simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation); + // Start or stop animations as needed. + void computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation); + // Regardless of who started the animations or how many, update the joints. + void updateAnimations(float deltaTime, glm::mat4 parentTransform); bool setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation, bool useRotation, int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority, const QVector& freeLineage, glm::mat4 parentTransform); diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index dd2d3369c8..92e49fdc55 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1326,6 +1326,10 @@ void Model::simulate(float deltaTime, bool fullUpdate) { } } +//virtual +void Model::updateRig(float deltaTime, glm::mat4 parentTransform) { + _rig->updateAnimations(deltaTime, parentTransform); +} void Model::simulateInternal(float deltaTime) { // update the world space transforms for all joints diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 27ef808ef0..83527969b2 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -269,7 +269,7 @@ protected: void snapToRegistrationPoint(); void simulateInternal(float deltaTime); - virtual void updateRig(float deltaTime, glm::mat4 parentTransform) {}; // Subclasses may be more interesting + virtual void updateRig(float deltaTime, glm::mat4 parentTransform); /// Updates the state of the joint at the specified index. virtual void updateJointState(int index);