From 78a900c8661a8565557af37f0726ddfbed76011a Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 30 Jul 2015 17:01:48 -0700 Subject: [PATCH] Prototype blend. Just equal weighting for now. --- libraries/animation/src/AnimationHandle.cpp | 4 +++- libraries/animation/src/AnimationHandle.h | 2 ++ libraries/animation/src/JointState.cpp | 5 +++-- libraries/animation/src/JointState.h | 2 +- libraries/animation/src/Rig.cpp | 7 +++++-- libraries/animation/src/Rig.h | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libraries/animation/src/AnimationHandle.cpp b/libraries/animation/src/AnimationHandle.cpp index e8ac6e0a10..605fb25f1c 100644 --- a/libraries/animation/src/AnimationHandle.cpp +++ b/libraries/animation/src/AnimationHandle.cpp @@ -176,7 +176,9 @@ void AnimationHandle::applyFrame(float frameIndex) { safeMix(floorFrame.rotations.at(i), ceilFrame.rotations.at(i), frameFraction), - _priority); + _priority, + false, + _mix); } } } diff --git a/libraries/animation/src/AnimationHandle.h b/libraries/animation/src/AnimationHandle.h index 5d39682a0a..42e564944e 100644 --- a/libraries/animation/src/AnimationHandle.h +++ b/libraries/animation/src/AnimationHandle.h @@ -63,6 +63,7 @@ public: void setPriority(float priority); float getPriority() const { return _priority; } + void setMix(float mix) { _mix = mix; } void setMaskedJoints(const QStringList& maskedJoints); const QStringList& getMaskedJoints() const { return _maskedJoints; } @@ -119,6 +120,7 @@ private: QString _role; QUrl _url; float _priority; + float _mix; QStringList _maskedJoints; QVector _jointMappings; diff --git a/libraries/animation/src/JointState.cpp b/libraries/animation/src/JointState.cpp index 8f14342e80..3682837719 100644 --- a/libraries/animation/src/JointState.cpp +++ b/libraries/animation/src/JointState.cpp @@ -232,12 +232,13 @@ glm::quat JointState::computeVisibleParentRotation() const { return _visibleRotation * glm::inverse(_fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation); } -void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain) { +void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain, float mix) { if (priority >= _animationPriority || _animationPriority == 0.0f) { if (constrain && _constraint) { _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); } - setRotationInConstrainedFrameInternal(targetRotation); + auto rotation = (mix == 1.0f) ? targetRotation : safeMix(getRotationInConstrainedFrame(), targetRotation, mix); + setRotationInConstrainedFrameInternal(rotation); _animationPriority = priority; } } diff --git a/libraries/animation/src/JointState.h b/libraries/animation/src/JointState.h index f15590e5f2..93bf83d2c4 100644 --- a/libraries/animation/src/JointState.h +++ b/libraries/animation/src/JointState.h @@ -84,7 +84,7 @@ public: /// NOTE: the JointState's model-frame transform/rotation are NOT updated! void setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain = false); - void setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain = false); + void setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain = false, float mix = 1.0f); void setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation); const glm::quat& getRotationInConstrainedFrame() const { return _rotationInConstrainedFrame; } const glm::quat& getVisibleRotationInConstrainedFrame() const { return _visibleRotationInConstrainedFrame; } diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 15f3dd65ec..8406b61d12 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -390,7 +390,10 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos } void Rig::updateAnimations(float deltaTime, glm::mat4 parentTransform) { + int nAnimationsSoFar = 0; foreach (const AnimationHandlePointer& handle, _runningAnimations) { + handle->setMix(1.0f / ++nAnimationsSoFar); + handle->setPriority(1.0); handle->simulate(deltaTime); } @@ -640,13 +643,13 @@ glm::vec3 Rig::getJointDefaultTranslationInConstrainedFrame(int jointIndex) { return _jointStates[jointIndex].getDefaultTranslationInConstrainedFrame(); } -glm::quat Rig::setJointRotationInConstrainedFrame(int jointIndex, glm::quat targetRotation, float priority, bool constrain) { +glm::quat Rig::setJointRotationInConstrainedFrame(int jointIndex, glm::quat targetRotation, float priority, bool constrain, float mix) { glm::quat endRotation; if (jointIndex == -1 || _jointStates.isEmpty()) { return endRotation; } JointState& state = _jointStates[jointIndex]; - state.setRotationInConstrainedFrame(targetRotation, priority, constrain); + state.setRotationInConstrainedFrame(targetRotation, priority, constrain, mix); endRotation = state.getRotationInConstrainedFrame(); return endRotation; } diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index 2af61bfded..52db16826a 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -139,7 +139,7 @@ public: glm::quat setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority, bool constrain = false); glm::vec3 getJointDefaultTranslationInConstrainedFrame(int jointIndex); glm::quat setJointRotationInConstrainedFrame(int jointIndex, glm::quat targetRotation, - float priority, bool constrain = false); + float priority, bool constrain = false, float mix = 1.0f); glm::quat getJointDefaultRotationInParentFrame(int jointIndex); void updateVisibleJointStates();