debugging name mapping code

This commit is contained in:
amantley 2018-11-19 17:40:43 -08:00
parent fd9c05ce80
commit 1fd03102c5
5 changed files with 43 additions and 13 deletions

View file

@ -23,6 +23,8 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) {
for (auto& joint : hfmModel.joints) {
joints.push_back(joint);
}
_fbxToHifiJointNameMapping = hfmModel.fbxToHifiJointNameMapping;
buildSkeletonFromJoints(joints, hfmModel.jointRotationOffsets);
// we make a copy of the inverseBindMatrices in order to prevent mutating the model bind pose
@ -59,7 +61,16 @@ AnimSkeleton::AnimSkeleton(const std::vector<HFMJoint>& joints, const QMap<int,
}
int AnimSkeleton::nameToJointIndex(const QString& jointName) const {
auto itr = _jointIndicesByName.find(jointName);
if (getFBXToHifiJointNameMapping().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();
}
if (_jointIndicesByName.end() != itr) {
return itr.value();
}
@ -120,8 +131,18 @@ std::vector<int> AnimSkeleton::getChildrenOfJoint(int jointIndex) const {
return result;
}
const QString& AnimSkeleton::getJointName(int jointIndex) const {
return _joints[jointIndex].name;
const QString AnimSkeleton::getJointName(int jointIndex) const {
QString jointName = _joints[jointIndex].name;
QMapIterator<QString, QString> i(_fbxToHifiJointNameMapping);
while (i.hasNext()) {
i.next();
if (i.value() == _joints[jointIndex].name) {
jointName = i.key();
break;
}
}
return jointName; //;_joints[jointIndex].name;
}
AnimPose AnimSkeleton::getAbsolutePose(int jointIndex, const AnimPoseVec& relativePoses) const {
@ -245,9 +266,9 @@ 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 != "Spine" &&
_joints[i].name != "Spine1" && _joints[i].name != "Spine2" &&
_joints[i].name != "Neck" && _joints[i].name != "Head" &&
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")) {
// HACK: we don't want to mirror some joints so we remember their indices
@ -327,7 +348,7 @@ std::vector<int> AnimSkeleton::lookUpJointIndices(const std::vector<QString>& jo
for (auto& name : jointNames) {
int index = nameToJointIndex(name);
if (index == -1) {
qWarning(animation) << "AnimSkeleton::lookUpJointIndices(): could not find bone with named " << name;
qWarning(animation) << "AnimSkeleton::lookUpJointIndices(): could not find bone with name " << name;
}
result.push_back(index);
}

View file

@ -27,7 +27,7 @@ public:
explicit AnimSkeleton(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
int nameToJointIndex(const QString& jointName) const;
const QString& getJointName(int jointIndex) const;
const QString getJointName(int jointIndex) const;
int getNumJoints() const;
int getChainDepth(int jointIndex) const;
@ -64,6 +64,7 @@ public:
std::vector<int> lookUpJointIndices(const std::vector<QString>& jointNames) const;
const HFMCluster getClusterBindMatricesOriginalValues(const int meshIndex, const int clusterIndex) const { return _clusterBindMatrixOriginalValues[meshIndex][clusterIndex]; }
const QMap<QString, QString> getFBXToHifiJointNameMapping() const { return _fbxToHifiJointNameMapping; }
protected:
void buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
@ -79,6 +80,7 @@ protected:
std::vector<int> _mirrorMap;
QHash<QString, int> _jointIndicesByName;
std::vector<std::vector<HFMCluster>> _clusterBindMatrixOriginalValues;
QMap<QString, QString> _fbxToHifiJointNameMapping;
// no copies
AnimSkeleton(const AnimSkeleton&) = delete;

View file

@ -420,7 +420,12 @@ static const uint32_t MAX_JOINT_NAME_WARNING_COUNT = 100;
int Rig::indexOfJoint(const QString& jointName) const {
if (_animSkeleton) {
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]);
result = _animSkeleton->nameToJointIndex(jointName);
}
// This is a content error, so we should issue a warning.
if (result < 0 && _jointNameWarningCount < MAX_JOINT_NAME_WARNING_COUNT) {

View file

@ -1438,18 +1438,20 @@ int Avatar::getJointIndex(const QString& name) const {
if (_modelJointIndicesCache.contains(name)) {
result = _modelJointIndicesCache[name] - 1;
if (_skeletonModel && _skeletonModel->isActive()) {
qCDebug(avatars_renderer) << "the other head id is this" << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"];
qCDebug(avatars_renderer) << "joint indices cache " << name << " " << _modelJointIndicesCache[name];
// qCDebug(avatars_renderer) << "the other head id is this" << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"];
// qCDebug(avatars_renderer) << "joint indices cache " << name << " " << _modelJointIndicesCache[name];
if (_modelJointIndicesCache.contains(_skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"])) {
qCDebug(avatars_renderer) << "joint alternate name " << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"] << " " << _modelJointIndicesCache[_skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"]];
// qCDebug(avatars_renderer) << "joint alternate name " << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"] << " " << _modelJointIndicesCache[_skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"]];
}
}
} else {
// doesn't contain name.
qCDebug(avatars_renderer) << "name is not here";
if (_skeletonModel && _skeletonModel->isActive()) {
if (_modelJointIndicesCache.contains(_skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"])) {
qCDebug(avatars_renderer) << "the other head id is this" << _skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"] << " " << _modelJointIndicesCache[_skeletonModel->getHFMModel().fbxToHifiJointNameMapping["Head"]];;
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;
}
}
}

View file

@ -425,7 +425,7 @@ QMap<QString, QString> getJointNameMapping(const QVariantHash& mapping) {
for (auto itr = jointNames.begin(); itr != jointNames.end(); itr++) {
qCDebug(modelformat) << "found a joint mapping field key " << itr.key() << " value " << itr.value().toString();
fbxToHifiJointNameMap.insert(itr.key(), itr.value().toString());
qCDebug(modelformat) << "the mapped key (Head) has a value of " << fbxToHifiJointNameMap[itr.key()];
qCDebug(modelformat) << "the mapped key " << itr.key() << " has a value of " << fbxToHifiJointNameMap[itr.key()];
}
}