mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 17:53:32 +02:00
remapping is now able to work remains to clean up code and check for gotchas from old fst code
This commit is contained in:
parent
1fd03102c5
commit
572cdcd008
6 changed files with 110 additions and 30 deletions
|
@ -54,6 +54,7 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) {
|
|||
}
|
||||
_clusterBindMatrixOriginalValues.push_back(dummyClustersList);
|
||||
}
|
||||
//dump(false);
|
||||
}
|
||||
|
||||
AnimSkeleton::AnimSkeleton(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets) {
|
||||
|
@ -64,16 +65,18 @@ int AnimSkeleton::nameToJointIndex(const QString& jointName) const {
|
|||
|
||||
auto itr = _jointIndicesByName.find(jointName);
|
||||
|
||||
if (getFBXToHifiJointNameMapping().contains(jointName)) {
|
||||
qCDebug(animation) << "failing joint name is " << jointName;
|
||||
if (_fbxToHifiJointNameMapping.contains(jointName)) {
|
||||
//qCDebug(animation) << "failing joint name is " << jointName;
|
||||
itr = _jointIndicesByName.find(_fbxToHifiJointNameMapping[jointName]);
|
||||
qCDebug(animation) << "the alternate name for the joint " << jointName << " is " <<
|
||||
_fbxToHifiJointNameMapping[jointName] << " " << itr.value();
|
||||
//qCDebug(animation) << "the alternate name for the joint " << jointName << " is " <<
|
||||
//_fbxToHifiJointNameMapping[jointName] << " " << itr.value();
|
||||
}
|
||||
|
||||
if (_jointIndicesByName.end() != itr) {
|
||||
//qCDebug(animation) << "returning " << itr.value() << " for " << jointName;
|
||||
return itr.value();
|
||||
}
|
||||
//qCDebug(animation) << "returning -1 " << " for " << jointName;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -142,6 +145,7 @@ const QString AnimSkeleton::getJointName(int jointIndex) const {
|
|||
break;
|
||||
}
|
||||
}
|
||||
//qCDebug(animation) << "reverse lookup: returning " << jointName << " for " << jointIndex;
|
||||
return jointName; //;_joints[jointIndex].name;
|
||||
}
|
||||
|
||||
|
@ -215,6 +219,81 @@ void AnimSkeleton::mirrorAbsolutePoses(AnimPoseVec& poses) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool AnimSkeleton::checkNonMirrored(QString jointName) const {
|
||||
|
||||
//bool isNonMirrored = false;
|
||||
QMapIterator<QString, QString> i(_fbxToHifiJointNameMapping);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (i.value() == jointName) {
|
||||
// check for left right in the key
|
||||
if (i.key() != "Hips" && i.key() != "Spine" &&
|
||||
i.key() != "Spine1" && i.key() != "Spine2" &&
|
||||
i.key() != "Neck" && i.key() != "Head" &&
|
||||
!((i.key().startsWith("Left") || i.key().startsWith("Right")) &&
|
||||
i.key() != "LeftEye" && i.key() != "RightEye")) {
|
||||
//return true
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check the unmapped name
|
||||
if (jointName != "Hips" && jointName != "Spine" &&
|
||||
jointName != "Spine1" && jointName != "Spine2" &&
|
||||
jointName != "Neck" && jointName != "Head" &&
|
||||
!((jointName.startsWith("Left") || jointName.startsWith("Right")) &&
|
||||
jointName != "LeftEye" && jointName != "RightEye")) {
|
||||
//return true
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int AnimSkeleton::containsLeft(QString jointName) const {
|
||||
QMapIterator<QString, QString> i(_fbxToHifiJointNameMapping);
|
||||
int mirrorJointIndex = -1;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (i.value() == jointName) {
|
||||
// check for left right in the key
|
||||
if (i.key().startsWith("Left")) {
|
||||
QString mirrorJointName = QString(i.key()).replace(0, 4, "Right");
|
||||
mirrorJointIndex = nameToJointIndex(mirrorJointName);
|
||||
//return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jointName.startsWith("Left")) {
|
||||
QString mirrorJointName = QString(i.key()).replace(0, 4, "Right");
|
||||
mirrorJointIndex = nameToJointIndex(mirrorJointName);
|
||||
}
|
||||
return mirrorJointIndex;
|
||||
}
|
||||
|
||||
int AnimSkeleton::containsRight(QString jointName) const {
|
||||
QMapIterator<QString, QString> i(_fbxToHifiJointNameMapping);
|
||||
int mirrorJointIndex = -1;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (i.value() == jointName) {
|
||||
// check for left right in the key
|
||||
if (i.key().startsWith("Right")) {
|
||||
QString mirrorJointName = QString(i.key()).replace(0, 5, "Left");
|
||||
mirrorJointIndex = nameToJointIndex(mirrorJointName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jointName.startsWith("Right")) {
|
||||
QString mirrorJointName = QString(i.key()).replace(0, 5, "Left");
|
||||
mirrorJointIndex = nameToJointIndex(mirrorJointName);
|
||||
}
|
||||
return mirrorJointIndex;
|
||||
}
|
||||
|
||||
void AnimSkeleton::buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets) {
|
||||
|
||||
_joints = joints;
|
||||
|
@ -266,22 +345,15 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector<HFMJoint>& joints,
|
|||
_nonMirroredIndices.clear();
|
||||
_mirrorMap.reserve(_jointsSize);
|
||||
for (int i = 0; i < _jointsSize; i++) {
|
||||
if (_joints[i].name != "Hips" && _joints[i].name != _fbxToHifiJointNameMapping["Hips"] && _joints[i].name != "Spine" && _joints[i].name != _fbxToHifiJointNameMapping["Spine"] &&
|
||||
_joints[i].name != "Spine1" && _joints[i].name != _fbxToHifiJointNameMapping["Spine1"] && _joints[i].name != "Spine2" && _joints[i].name != _fbxToHifiJointNameMapping["Spine2"] &&
|
||||
_joints[i].name != "Neck" && _joints[i].name != _fbxToHifiJointNameMapping["Neck"] && _joints[i].name != "Head" && _joints[i].name != _fbxToHifiJointNameMapping["Head"] &&
|
||||
!((_joints[i].name.startsWith("Left") || _joints[i].name.startsWith("Right")) &&
|
||||
_joints[i].name != "LeftEye" && _joints[i].name != "RightEye")) {
|
||||
if (checkNonMirrored(_joints[i].name)) {
|
||||
// HACK: we don't want to mirror some joints so we remember their indices
|
||||
// so we can restore them after a future mirror operation
|
||||
_nonMirroredIndices.push_back(i);
|
||||
}
|
||||
int mirrorJointIndex = -1;
|
||||
if (_joints[i].name.startsWith("Left")) {
|
||||
QString mirrorJointName = QString(_joints[i].name).replace(0, 4, "Right");
|
||||
mirrorJointIndex = nameToJointIndex(mirrorJointName);
|
||||
} else if (_joints[i].name.startsWith("Right")) {
|
||||
QString mirrorJointName = QString(_joints[i].name).replace(0, 5, "Left");
|
||||
mirrorJointIndex = nameToJointIndex(mirrorJointName);
|
||||
mirrorJointIndex = containsLeft(_joints[i].name);
|
||||
if (mirrorJointIndex > -1) {
|
||||
mirrorJointIndex = containsRight(_joints[i].name);
|
||||
}
|
||||
if (mirrorJointIndex >= 0) {
|
||||
_mirrorMap.push_back(mirrorJointIndex);
|
||||
|
|
|
@ -56,6 +56,9 @@ public:
|
|||
void saveNonMirroredPoses(const AnimPoseVec& poses) const;
|
||||
void restoreNonMirroredPoses(AnimPoseVec& poses) const;
|
||||
|
||||
bool checkNonMirrored(QString jointName) const;
|
||||
int containsLeft(QString jointName) const;
|
||||
int containsRight(QString jointName) const;
|
||||
void mirrorRelativePoses(AnimPoseVec& poses) const;
|
||||
void mirrorAbsolutePoses(AnimPoseVec& poses) const;
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ int Rig::indexOfJoint(const QString& jointName) const {
|
|||
|
||||
int result = _animSkeleton->nameToJointIndex(jointName);
|
||||
if (_animSkeleton->getFBXToHifiJointNameMapping().contains(jointName)) {
|
||||
qCDebug(animation) << "the alternate name for the joint " << jointName << " is " << _animSkeleton->getFBXToHifiJointNameMapping()[jointName] << " " << _animSkeleton->nameToJointIndex(_animSkeleton->getFBXToHifiJointNameMapping()[jointName]);
|
||||
//qCDebug(animation) << "the alternate name for the joint " << jointName << " is " << _animSkeleton->getFBXToHifiJointNameMapping()[jointName] << " " << _animSkeleton->nameToJointIndex(_animSkeleton->getFBXToHifiJointNameMapping()[jointName]);
|
||||
result = _animSkeleton->nameToJointIndex(jointName);
|
||||
}
|
||||
|
||||
|
|
|
@ -1446,12 +1446,12 @@ int Avatar::getJointIndex(const QString& name) const {
|
|||
}
|
||||
} else {
|
||||
// doesn't contain name.
|
||||
qCDebug(avatars_renderer) << "name is not here";
|
||||
//qCDebug(avatars_renderer) << "name is not here";
|
||||
if (_skeletonModel && _skeletonModel->isActive()) {
|
||||
|
||||
if (_modelJointIndicesCache.contains(_skeletonModel->getHFMModel().fbxToHifiJointNameMapping[name])) {
|
||||
result = _modelJointIndicesCache[_skeletonModel->getHFMModel().fbxToHifiJointNameMapping[name]] - 1;
|
||||
qCDebug(avatars_renderer) << "joint " << name << " remapped to " << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping[name] << result;
|
||||
// qCDebug(avatars_renderer) << "joint " << name << " remapped to " << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping[name] << result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -317,6 +317,7 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco
|
|||
}
|
||||
|
||||
glm::vec3 SkeletonModel::getDefaultEyeModelPosition() const {
|
||||
//qCDebug(avatars_renderer) << "default eye model position " << _defaultEyeModelPosition;
|
||||
return _owningAvatar->getModelScale() * _defaultEyeModelPosition;
|
||||
}
|
||||
|
||||
|
|
|
@ -485,7 +485,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString&
|
|||
QString jointNeckName = processID(getString(joints.value("jointNeck", "jointNeck")));
|
||||
QString jointRootName = processID(getString(joints.value("jointRoot", "jointRoot")));
|
||||
QString jointLeanName = processID(getString(joints.value("jointLean", "jointLean")));
|
||||
QString jointHeadName = processID(getString(joints.value("jointHead", "jointHead")));
|
||||
QString jointHeadName = "Head";// processID(getString(joints.value("jointHead", "jointHead")));
|
||||
QString jointLeftHandName = processID(getString(joints.value("jointLeftHand", "jointLeftHand")));
|
||||
QString jointRightHandName = processID(getString(joints.value("jointRightHand", "jointRightHand")));
|
||||
QString jointEyeLeftID;
|
||||
|
@ -534,6 +534,8 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString&
|
|||
HFMModel& hfmModel = *hfmModelPtr;
|
||||
|
||||
hfmModel.originalURL = url;
|
||||
hfmModel.fbxToHifiJointNameMapping.clear();
|
||||
hfmModel.fbxToHifiJointNameMapping = getJointNameMapping(mapping);
|
||||
|
||||
float unitScaleFactor = 1.0f;
|
||||
glm::vec3 ambientColor;
|
||||
|
@ -602,34 +604,34 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString&
|
|||
hifiGlobalNodeID = id;
|
||||
}
|
||||
|
||||
if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye") {
|
||||
if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye" || (hfmModel.fbxToHifiJointNameMapping.contains(jointEyeLeftName) && (name == hfmModel.fbxToHifiJointNameMapping[jointEyeLeftName]))) {
|
||||
jointEyeLeftID = getID(object.properties);
|
||||
|
||||
} else if (name == jointEyeRightName || name == "EyeR" || name == "joint_Reye") {
|
||||
} else if (name == jointEyeRightName || name == "EyeR" || name == "joint_Reye" || (hfmModel.fbxToHifiJointNameMapping.contains(jointEyeRightName) && (name == hfmModel.fbxToHifiJointNameMapping[jointEyeRightName]))) {
|
||||
jointEyeRightID = getID(object.properties);
|
||||
|
||||
} else if (name == jointNeckName || name == "NeckRot" || name == "joint_neck") {
|
||||
} else if (name == jointNeckName || name == "NeckRot" || name == "joint_neck" || (hfmModel.fbxToHifiJointNameMapping.contains(jointNeckName) && (name == hfmModel.fbxToHifiJointNameMapping[jointNeckName]))) {
|
||||
jointNeckID = getID(object.properties);
|
||||
|
||||
} else if (name == jointRootName) {
|
||||
} else if (name == jointRootName || (hfmModel.fbxToHifiJointNameMapping.contains(jointRootName) && (name == hfmModel.fbxToHifiJointNameMapping[jointRootName]))) {
|
||||
jointRootID = getID(object.properties);
|
||||
|
||||
} else if (name == jointLeanName) {
|
||||
jointLeanID = getID(object.properties);
|
||||
|
||||
} else if (name == jointHeadName) {
|
||||
} else if ((name == jointHeadName) || (hfmModel.fbxToHifiJointNameMapping.contains(jointHeadName) && (name == hfmModel.fbxToHifiJointNameMapping[jointHeadName]))) {
|
||||
jointHeadID = getID(object.properties);
|
||||
|
||||
} else if (name == jointLeftHandName || name == "LeftHand" || name == "joint_L_hand") {
|
||||
} else if (name == jointLeftHandName || name == "LeftHand" || name == "joint_L_hand" || (hfmModel.fbxToHifiJointNameMapping.contains(jointLeftHandName) && (name == hfmModel.fbxToHifiJointNameMapping[jointLeftHandName]))) {
|
||||
jointLeftHandID = getID(object.properties);
|
||||
|
||||
} else if (name == jointRightHandName || name == "RightHand" || name == "joint_R_hand") {
|
||||
} else if (name == jointRightHandName || name == "RightHand" || name == "joint_R_hand" || (hfmModel.fbxToHifiJointNameMapping.contains(jointRightHandName) && (name == hfmModel.fbxToHifiJointNameMapping[jointRightHandName]))) {
|
||||
jointRightHandID = getID(object.properties);
|
||||
|
||||
} else if (name == "LeftToe" || name == "joint_L_toe" || name == "LeftToe_End") {
|
||||
} else if (name == "LeftToe" || name == "joint_L_toe" || name == "LeftToe_End" || (hfmModel.fbxToHifiJointNameMapping.contains("LeftToe") && (name == hfmModel.fbxToHifiJointNameMapping["LeftToe"]))) {
|
||||
jointLeftToeID = getID(object.properties);
|
||||
|
||||
} else if (name == "RightToe" || name == "joint_R_toe" || name == "RightToe_End") {
|
||||
} else if (name == "RightToe" || name == "joint_R_toe" || name == "RightToe_End" || (hfmModel.fbxToHifiJointNameMapping.contains("RightToe") && (name == hfmModel.fbxToHifiJointNameMapping["RightToe"]))) {
|
||||
jointRightToeID = getID(object.properties);
|
||||
}
|
||||
|
||||
|
@ -1839,14 +1841,16 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString&
|
|||
QString jointName = itr.key();
|
||||
glm::quat rotationOffset = itr.value();
|
||||
int jointIndex = hfmModel.getJointIndex(jointName);
|
||||
if (hfmModel.fbxToHifiJointNameMapping.contains(jointName)) {
|
||||
jointIndex = hfmModel.getJointIndex(hfmModel.fbxToHifiJointNameMapping[jointName]);
|
||||
}
|
||||
if (jointIndex != -1) {
|
||||
hfmModel.jointRotationOffsets.insert(jointIndex, rotationOffset);
|
||||
}
|
||||
qCDebug(modelformat) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset;
|
||||
}
|
||||
|
||||
hfmModel.fbxToHifiJointNameMapping.clear();
|
||||
hfmModel.fbxToHifiJointNameMapping = getJointNameMapping(mapping);
|
||||
|
||||
|
||||
return hfmModelPtr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue