mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 02:47:50 +02:00
Finger IK, take two.
This commit is contained in:
parent
3e4c5f84ed
commit
76d8bd0a9c
3 changed files with 8 additions and 11 deletions
|
@ -176,15 +176,10 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJoin
|
||||||
float proportion = fingerIndices.size() / (float)fingerJointIndices.size();
|
float proportion = fingerIndices.size() / (float)fingerJointIndices.size();
|
||||||
for (int i = 0; i < fingerJointIndices.size(); i++) {
|
for (int i = 0; i < fingerJointIndices.size(); i++) {
|
||||||
int fingerIndex = fingerIndices.at(roundf(i * proportion)).index;
|
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 fingerJointIndex = fingerJointIndices.at(i);
|
||||||
int fingertipJointIndex = fingertipJointIndices.at(i);
|
int fingertipJointIndex = fingertipJointIndices.at(i);
|
||||||
glm::vec3 jointVector = extractTranslation(geometry.joints.at(fingertipJointIndex).bindTransform) -
|
setJointPosition(fingertipJointIndex, palm.getFingers()[fingerIndex].getTipPosition(),
|
||||||
extractTranslation(geometry.joints.at(fingerJointIndex).bindTransform);
|
fingerJointIndex, true, -palm.getNormal());
|
||||||
|
|
||||||
setJointRotation(fingerJointIndex, rotationBetween(palmRotation * jointVector, fingerVector) * palmRotation, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -584,7 +584,8 @@ bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind)
|
||||||
return true;
|
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()) {
|
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
||||||
return false;
|
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++) {
|
for (int j = 1; freeLineage.at(j - 1) != lastFreeIndex; j++) {
|
||||||
int index = freeLineage.at(j);
|
int index = freeLineage.at(j);
|
||||||
const FBXJoint& joint = geometry.joints.at(index);
|
const FBXJoint& joint = geometry.joints.at(index);
|
||||||
if (!joint.isFree) {
|
if (!(joint.isFree || allIntermediatesFree)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
JointState& state = _jointStates[index];
|
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::vec3 projectedCenterOfMass = glm::cross(jointVector,
|
||||||
glm::cross(positionSum / (j - 1.0f) - jointPosition, jointVector));
|
glm::cross(positionSum / (j - 1.0f) - jointPosition, jointVector));
|
||||||
glm::vec3 projectedAlignment = glm::cross(jointVector, glm::cross(worldAlignment, 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));
|
applyRotationDelta(index, rotationBetween(projectedCenterOfMass, projectedAlignment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ protected:
|
||||||
bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const;
|
bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const;
|
||||||
|
|
||||||
bool setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex = -1,
|
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);
|
bool setJointRotation(int jointIndex, const glm::quat& rotation, bool fromBind = false);
|
||||||
|
|
||||||
/// Restores the indexed joint to its default position.
|
/// Restores the indexed joint to its default position.
|
||||||
|
|
Loading…
Reference in a new issue