From 4360621dafa8fe8798eb9aaf9b030ed66fdcbbb3 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 7 Nov 2013 13:17:08 -0800 Subject: [PATCH] Adjustments to wrist rotations. --- interface/src/avatar/SkeletonModel.cpp | 5 +++-- interface/src/renderer/FBXReader.cpp | 9 +++++++-- interface/src/renderer/FBXReader.h | 1 + interface/src/renderer/Model.cpp | 10 ++++++---- interface/src/renderer/Model.h | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 46a2b6bda6..c9e9620361 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -136,10 +136,11 @@ bool operator<(const IndexValue& firstIndex, const IndexValue& secondIndex) { void SkeletonModel::applyPalmData(int jointIndex, const QVector& fingertipJointIndices, PalmData& palm) { setJointPosition(jointIndex, palm.getPosition()); - setJointRotation(jointIndex, rotationBetween(_rotation * IDENTITY_UP, palm.getNormal()) * _rotation); + setJointRotation(jointIndex, rotationBetween(_rotation * IDENTITY_UP, palm.getNormal()) * _rotation * + glm::angleAxis(90.0f, 0.0f, jointIndex == _geometry->getFBXGeometry().rightHandJointIndex ? 1.0f : -1.0f, 0.0f), true); // no point in continuing if there are no fingers - if (palm.getNumFingers() == 0) { + if (true || palm.getNumFingers() == 0) { return; } diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index dce41ba18f..f0ef5d91f3 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -1073,17 +1073,18 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) glm::quat combinedRotation = model.preRotation * model.rotation * model.postRotation; if (joint.parentIndex == -1) { joint.transform = geometry.offset * model.preTransform * glm::mat4_cast(combinedRotation) * model.postTransform; - joint.inverseBindRotation = glm::inverse(combinedRotation); + joint.inverseDefaultRotation = glm::inverse(combinedRotation); joint.distanceToParent = 0.0f; } else { const FBXJoint& parentJoint = geometry.joints.at(joint.parentIndex); joint.transform = parentJoint.transform * model.preTransform * glm::mat4_cast(combinedRotation) * model.postTransform; - joint.inverseBindRotation = glm::inverse(combinedRotation) * parentJoint.inverseBindRotation; + joint.inverseDefaultRotation = glm::inverse(combinedRotation) * parentJoint.inverseDefaultRotation; joint.distanceToParent = glm::distance(extractTranslation(parentJoint.transform), extractTranslation(joint.transform)); } + joint.inverseBindRotation = joint.inverseDefaultRotation; geometry.joints.append(joint); geometry.jointIndices.insert(model.name, geometry.joints.size() - 1); } @@ -1202,6 +1203,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) } fbxCluster.inverseBindMatrix = glm::inverse(cluster.transformLink) * modelTransform; extracted.mesh.clusters.append(fbxCluster); + + // override the bind rotation with the transform link + geometry.joints[fbxCluster.jointIndex].inverseBindRotation = + glm::inverse(extractRotation(cluster.transformLink)); } } diff --git a/interface/src/renderer/FBXReader.h b/interface/src/renderer/FBXReader.h index 8f3ec74ae9..218e1d3c27 100644 --- a/interface/src/renderer/FBXReader.h +++ b/interface/src/renderer/FBXReader.h @@ -53,6 +53,7 @@ public: glm::quat postRotation; glm::mat4 postTransform; glm::mat4 transform; + glm::quat inverseDefaultRotation; glm::quat inverseBindRotation; }; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 8c0bd69632..6eeca5cfd4 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -574,12 +574,13 @@ bool Model::getJointPosition(int jointIndex, glm::vec3& position) const { return true; } -bool Model::getJointRotation(int jointIndex, glm::quat& rotation) const { +bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind) const { if (jointIndex == -1 || _jointStates.isEmpty()) { return false; } rotation = _jointStates[jointIndex].combinedRotation * - _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation; + (fromBind ? _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation : + _geometry->getFBXGeometry().joints[jointIndex].inverseDefaultRotation); return true; } @@ -671,13 +672,14 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int last return true; } -bool Model::setJointRotation(int jointIndex, const glm::quat& rotation) { +bool Model::setJointRotation(int jointIndex, const glm::quat& rotation, bool fromBind) { if (jointIndex == -1 || _jointStates.isEmpty()) { return false; } JointState& state = _jointStates[jointIndex]; state.rotation = state.rotation * glm::inverse(state.combinedRotation) * rotation * - glm::inverse(_geometry->getFBXGeometry().joints.at(jointIndex).inverseBindRotation); + glm::inverse(fromBind ? _geometry->getFBXGeometry().joints.at(jointIndex).inverseBindRotation : + _geometry->getFBXGeometry().joints.at(jointIndex).inverseDefaultRotation); return true; } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index e05b8e007f..3a22045b6c 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -141,10 +141,10 @@ protected: virtual void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); bool getJointPosition(int jointIndex, glm::vec3& position) const; - bool getJointRotation(int jointIndex, glm::quat& rotation) const; + bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const; bool setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex = -1); - bool setJointRotation(int jointIndex, const glm::quat& rotation); + bool setJointRotation(int jointIndex, const glm::quat& rotation, bool fromBind = false); /// Restores the indexed joint to its default position. /// \param percent the percentage of the default position to apply (i.e., 0.25f to slerp one fourth of the way to