Fix joint indexing when duplicated joint on skeleton

This commit is contained in:
luiscuenca 2019-08-15 14:53:30 -07:00
parent f02b76fed0
commit 2ef1c6458a
No known key found for this signature in database
GPG key ID: 2387ECD129A6961D

View file

@ -71,14 +71,7 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
auto& jointRotationOffsets = output.edit1(); auto& jointRotationOffsets = output.edit1();
auto& jointIndices = output.edit2(); auto& jointIndices = output.edit2();
bool newJointRot = false;
static const QString JOINT_ROTATION_OFFSET2_FIELD = "jointRotationOffset2";
QVariantHash fstHashMap = mapping; QVariantHash fstHashMap = mapping;
if (fstHashMap.contains(JOINT_ROTATION_OFFSET2_FIELD)) {
newJointRot = true;
} else {
newJointRot = false;
}
// Get joint renames // Get joint renames
auto jointNameMapping = getJointNameMapping(mapping); auto jointNameMapping = getJointNameMapping(mapping);
@ -87,10 +80,26 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
jointsOut.push_back(jointIn); jointsOut.push_back(jointIn);
auto& jointOut = jointsOut.back(); auto& jointOut = jointsOut.back();
if (!newJointRot) { auto jointNameMapKey = jointNameMapping.key(jointIn.name);
auto jointNameMapKey = jointNameMapping.key(jointIn.name); if (jointNameMapping.contains(jointNameMapKey)) {
if (jointNameMapping.contains(jointNameMapKey)) { jointOut.name = jointNameMapKey;
jointOut.name = jointNameMapKey; }
// Make sure that joint name is unique
if (jointIndices.contains(jointOut.name)) {
// The joint name is duplicated. Most likely a mesh joint.
auto duplicatedJointData = jointIndices.find(jointOut.name);
int duplicatedJointIndex = duplicatedJointData.value();
auto& duplicatedJoint = jointsOut[duplicatedJointIndex];
QString existJointName = jointOut.name;
qCDebug(model_baker) << "Joint already exist. Renaming joint: " << existJointName;
// One of the joints could be a mesh joint. Locate it and change its name.
if (!jointOut.isSkeletonJoint) {
jointOut.name = existJointName + "_mesh";
} else {
duplicatedJoint.name = existJointName + "_mesh";
jointIndices.remove(jointOut.name);
jointIndices.insert(duplicatedJoint.name, duplicatedJointIndex);
} }
} }
jointIndices.insert(jointOut.name, (int)jointsOut.size()); jointIndices.insert(jointOut.name, (int)jointsOut.size());
@ -107,27 +116,5 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
qCDebug(model_baker) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset; qCDebug(model_baker) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset;
} }
} }
if (newJointRot) {
for (auto& jointOut : jointsOut) {
auto jointNameMapKey = jointNameMapping.key(jointOut.name);
int mappedIndex = jointIndices.value(jointOut.name);
if (jointNameMapping.contains(jointNameMapKey)) {
// delete and replace with hifi name
jointIndices.remove(jointOut.name);
jointOut.name = jointNameMapKey;
jointIndices.insert(jointOut.name, mappedIndex);
} else {
// nothing mapped to this fbx joint name
if (jointNameMapping.contains(jointOut.name)) {
// but the name is in the list of hifi names is mapped to a different joint
int extraIndex = jointIndices.value(jointOut.name);
jointIndices.remove(jointOut.name);
jointOut.name = "";
jointIndices.insert(jointOut.name, extraIndex);
}
}
}
}
} }
} }