diff --git a/libraries/animation/src/AnimSkeleton.cpp b/libraries/animation/src/AnimSkeleton.cpp index 908b4eb1d3..6e71ef0184 100644 --- a/libraries/animation/src/AnimSkeleton.cpp +++ b/libraries/animation/src/AnimSkeleton.cpp @@ -54,6 +54,7 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) { } _clusterBindMatrixOriginalValues.push_back(dummyClustersList); } + //dump(false); } AnimSkeleton::AnimSkeleton(const std::vector& joints, const QMap 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 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 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 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& joints, const QMap jointOffsets) { _joints = joints; @@ -266,22 +345,15 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector& 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); diff --git a/libraries/animation/src/AnimSkeleton.h b/libraries/animation/src/AnimSkeleton.h index bcbfe628c7..5581976d74 100644 --- a/libraries/animation/src/AnimSkeleton.h +++ b/libraries/animation/src/AnimSkeleton.h @@ -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; diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 0c30a7696f..1675ea8e90 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -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); } diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index e5435a9a8c..14e97a5bf9 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -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; } } } diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp index 36e37dd3d4..a97ba4bf4b 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp @@ -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; } diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 2e43573ec2..3ddcd75255 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -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; }