Yet another finger attempt.

This commit is contained in:
Andrzej Kapolka 2013-11-07 16:14:23 -08:00
parent c3049d4378
commit a29dfe9c63
4 changed files with 54 additions and 30 deletions

View file

@ -62,12 +62,15 @@ void SkeletonModel::simulate(float deltaTime) {
} else if (leftPalmIndex == rightPalmIndex) { } else if (leftPalmIndex == rightPalmIndex) {
// right hand only // right hand only
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, hand.getPalms()[leftPalmIndex]); applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, geometry.rightFingertipJointIndices,
hand.getPalms()[leftPalmIndex]);
restoreLeftHandPosition(HAND_RESTORATION_RATE); restoreLeftHandPosition(HAND_RESTORATION_RATE);
} else { } else {
applyPalmData(geometry.leftHandJointIndex, geometry.leftFingerJointIndices, hand.getPalms()[leftPalmIndex]); applyPalmData(geometry.leftHandJointIndex, geometry.leftFingerJointIndices, geometry.leftFingertipJointIndices,
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, hand.getPalms()[rightPalmIndex]); hand.getPalms()[leftPalmIndex]);
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, geometry.rightFingertipJointIndices,
hand.getPalms()[rightPalmIndex]);
} }
} }
@ -131,7 +134,8 @@ bool operator<(const IndexValue& firstIndex, const IndexValue& secondIndex) {
return firstIndex.value < secondIndex.value; return firstIndex.value < secondIndex.value;
} }
void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJointIndices, PalmData& palm) { void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJointIndices,
const QVector<int>& fingertipJointIndices, PalmData& palm) {
const FBXGeometry& geometry = _geometry->getFBXGeometry(); const FBXGeometry& geometry = _geometry->getFBXGeometry();
setJointPosition(jointIndex, palm.getPosition()); setJointPosition(jointIndex, palm.getPosition());
float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f; float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f;
@ -152,22 +156,19 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJoin
} }
qSort(fingerIndices.begin(), fingerIndices.end()); qSort(fingerIndices.begin(), fingerIndices.end());
// likewise with the joint indices and relative z
QVector<IndexValue> jointIndices;
foreach (int index, fingerJointIndices) {
glm::vec3 position = glm::inverse(_rotation) * extractTranslation(geometry.joints.at(index).bindTransform);
IndexValue indexValue = { index, position.z * -sign };
jointIndices.append(indexValue);
}
qSort(jointIndices.begin(), jointIndices.end());
// match them up as best we can // match them up as best we can
float proportion = fingerIndices.size() / (float)jointIndices.size(); float proportion = fingerIndices.size() / (float)fingerJointIndices.size();
for (int i = 0; i < jointIndices.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() - glm::vec3 fingerVector = palm.getFingers()[fingerIndex].getTipPosition() -
palm.getFingers()[fingerIndex].getRootPosition(); palm.getFingers()[fingerIndex].getRootPosition();
setJointRotation(jointIndices.at(i).index, rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), fingerVector) * palmRotation, true);
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);
} }
} }

View file

@ -28,7 +28,8 @@ public:
protected: protected:
void applyPalmData(int jointIndex, const QVector<int>& fingerJointIndices, PalmData& palm); void applyPalmData(int jointIndex, const QVector<int>& fingerJointIndices,
const QVector<int>& fingertipJointIndices, PalmData& palm);
/// Updates the state of the joint at the specified index. /// Updates the state of the joint at the specified index.
virtual void updateJointState(int index); virtual void updateJointState(int index);

View file

@ -726,6 +726,17 @@ void setTangents(FBXMesh& mesh, int firstIndex, int secondIndex) {
-glm::degrees(atan2f(-texCoordDelta.t, texCoordDelta.s)), normal) * glm::normalize(bitangent), normal); -glm::degrees(atan2f(-texCoordDelta.t, texCoordDelta.s)), normal) * glm::normalize(bitangent), normal);
} }
QVector<int> getIndices(const QVector<QString> ids, QVector<QString> modelIDs) {
QVector<int> indices;
foreach (const QString& id, ids) {
int index = modelIDs.indexOf(id);
if (index != -1) {
indices.append(index);
}
}
return indices;
}
FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) { FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) {
QHash<QString, ExtractedMesh> meshes; QHash<QString, ExtractedMesh> meshes;
QVector<ExtractedBlendshape> blendshapes; QVector<ExtractedBlendshape> blendshapes;
@ -749,6 +760,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QString jointRightHandName = processID(joints.value("jointRightHand", "jointRightHand").toString()); QString jointRightHandName = processID(joints.value("jointRightHand", "jointRightHand").toString());
QVariantList jointLeftFingerNames = joints.values("jointLeftFinger"); QVariantList jointLeftFingerNames = joints.values("jointLeftFinger");
QVariantList jointRightFingerNames = joints.values("jointRightFinger"); QVariantList jointRightFingerNames = joints.values("jointRightFinger");
QVariantList jointLeftFingertipNames = joints.values("jointLeftFingertip");
QVariantList jointRightFingertipNames = joints.values("jointRightFingertip");
QString jointEyeLeftID; QString jointEyeLeftID;
QString jointEyeRightID; QString jointEyeRightID;
QString jointNeckID; QString jointNeckID;
@ -757,8 +770,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QString jointHeadID; QString jointHeadID;
QString jointLeftHandID; QString jointLeftHandID;
QString jointRightHandID; QString jointRightHandID;
QStringList jointLeftFingerIDs; QVector<QString> jointLeftFingerIDs(jointLeftFingerNames.size());
QStringList jointRightFingerIDs; QVector<QString> jointRightFingerIDs(jointRightFingerNames.size());
QVector<QString> jointLeftFingertipIDs(jointLeftFingertipNames.size());
QVector<QString> jointRightFingertipIDs(jointRightFingertipNames.size());
QVariantHash blendshapeMappings = mapping.value("bs").toHash(); QVariantHash blendshapeMappings = mapping.value("bs").toHash();
QHash<QByteArray, QPair<int, float> > blendshapeIndices; QHash<QByteArray, QPair<int, float> > blendshapeIndices;
@ -815,6 +830,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
} else { } else {
name = getID(object.properties); name = getID(object.properties);
} }
int index;
if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye") { if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye") {
jointEyeLeftID = getID(object.properties); jointEyeLeftID = getID(object.properties);
@ -839,11 +855,17 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
} else if (name == jointRightHandName) { } else if (name == jointRightHandName) {
jointRightHandID = getID(object.properties); jointRightHandID = getID(object.properties);
} else if (jointLeftFingerNames.contains(name)) { } else if ((index = jointLeftFingerNames.indexOf(name)) != -1) {
jointLeftFingerIDs.append(getID(object.properties)); jointLeftFingerIDs[index] = getID(object.properties);
} else if (jointRightFingerNames.contains(name)) { } else if ((index = jointRightFingerNames.indexOf(name)) != -1) {
jointRightFingerIDs.append(getID(object.properties)); jointRightFingerIDs[index] = getID(object.properties);
} else if ((index = jointLeftFingertipNames.indexOf(name)) != -1) {
jointLeftFingertipIDs[index] = getID(object.properties);
} else if ((index = jointRightFingertipNames.indexOf(name)) != -1) {
jointRightFingertipIDs[index] = getID(object.properties);
} }
glm::vec3 translation; glm::vec3 translation;
glm::vec3 rotationOffset; glm::vec3 rotationOffset;
@ -1098,13 +1120,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
geometry.headJointIndex = modelIDs.indexOf(jointHeadID); geometry.headJointIndex = modelIDs.indexOf(jointHeadID);
geometry.leftHandJointIndex = modelIDs.indexOf(jointLeftHandID); geometry.leftHandJointIndex = modelIDs.indexOf(jointLeftHandID);
geometry.rightHandJointIndex = modelIDs.indexOf(jointRightHandID); geometry.rightHandJointIndex = modelIDs.indexOf(jointRightHandID);
geometry.leftFingerJointIndices = getIndices(jointLeftFingerIDs, modelIDs);
foreach (const QString& id, jointLeftFingerIDs) { geometry.rightFingerJointIndices = getIndices(jointRightFingerIDs, modelIDs);
geometry.leftFingerJointIndices.append(modelIDs.indexOf(id)); geometry.leftFingertipJointIndices = getIndices(jointLeftFingertipIDs, modelIDs);
} geometry.rightFingertipJointIndices = getIndices(jointRightFingertipIDs, modelIDs);
foreach (const QString& id, jointRightFingerIDs) {
geometry.rightFingerJointIndices.append(modelIDs.indexOf(id));
}
// extract the translation component of the neck transform // extract the translation component of the neck transform
if (geometry.neckJointIndex != -1) { if (geometry.neckJointIndex != -1) {

View file

@ -140,6 +140,9 @@ public:
QVector<int> leftFingerJointIndices; QVector<int> leftFingerJointIndices;
QVector<int> rightFingerJointIndices; QVector<int> rightFingerJointIndices;
QVector<int> leftFingertipJointIndices;
QVector<int> rightFingertipJointIndices;
glm::vec3 neckPivot; glm::vec3 neckPivot;
QVector<FBXAttachment> attachments; QVector<FBXAttachment> attachments;