diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 64288effc4..bf4e2bb65b 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -176,15 +176,10 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector& fingerJoin float proportion = fingerIndices.size() / (float)fingerJointIndices.size(); for (int i = 0; i < fingerJointIndices.size(); i++) { int fingerIndex = fingerIndices.at(roundf(i * proportion)).index; - glm::vec3 fingerVector = palm.getFingers()[fingerIndex].getTipPosition() - - palm.getFingers()[fingerIndex].getRootPosition(); - int fingerJointIndex = fingerJointIndices.at(i); int fingertipJointIndex = fingertipJointIndices.at(i); - glm::vec3 jointVector = extractTranslation(geometry.joints.at(fingertipJointIndex).bindTransform) - - extractTranslation(geometry.joints.at(fingerJointIndex).bindTransform); - - setJointRotation(fingerJointIndex, rotationBetween(palmRotation * jointVector, fingerVector) * palmRotation, true); + setJointPosition(fingertipJointIndex, palm.getFingers()[fingerIndex].getTipPosition(), + fingerJointIndex, true, -palm.getNormal()); } } diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index ac60f98af7..ac6f2c4c47 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -584,7 +584,8 @@ bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind) return true; } -bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex, const glm::vec3& alignment) { +bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex, + bool allIntermediatesFree, const glm::vec3& alignment) { if (jointIndex == -1 || _jointStates.isEmpty()) { return false; } @@ -605,7 +606,7 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int last for (int j = 1; freeLineage.at(j - 1) != lastFreeIndex; j++) { int index = freeLineage.at(j); const FBXJoint& joint = geometry.joints.at(index); - if (!joint.isFree) { + if (!(joint.isFree || allIntermediatesFree)) { continue; } JointState& state = _jointStates[index]; @@ -625,7 +626,8 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int last glm::vec3 projectedCenterOfMass = glm::cross(jointVector, glm::cross(positionSum / (j - 1.0f) - jointPosition, jointVector)); glm::vec3 projectedAlignment = glm::cross(jointVector, glm::cross(worldAlignment, jointVector)); - if (glm::length(projectedCenterOfMass) > EPSILON && glm::length(projectedAlignment) > EPSILON) { + const float LENGTH_EPSILON = 0.001f; + if (glm::length(projectedCenterOfMass) > LENGTH_EPSILON && glm::length(projectedAlignment) > LENGTH_EPSILON) { applyRotationDelta(index, rotationBetween(projectedCenterOfMass, projectedAlignment)); } } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index d1068bf0d6..44ac7971a5 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -144,7 +144,7 @@ protected: bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const; bool setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex = -1, - const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f)); + bool allIntermediatesFree = false, const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f)); bool setJointRotation(int jointIndex, const glm::quat& rotation, bool fromBind = false); /// Restores the indexed joint to its default position.