Merge pull request #10963 from sethalves/fix-sort-joints

put result of Avatar::getJointNames back in index-order
This commit is contained in:
Andrew Meadows 2017-07-13 12:44:32 -07:00 committed by GitHub
commit 4f75558b49

View file

@ -1050,7 +1050,34 @@ int Avatar::getJointIndex(const QString& name) const {
QStringList Avatar::getJointNames() const {
QStringList result;
withValidJointIndicesCache([&]() {
result = _modelJointIndicesCache.keys();
// find out how large the vector needs to be
int maxJointIndex = -1;
QHashIterator<QString, int> k(_modelJointIndicesCache);
while (k.hasNext()) {
k.next();
int index = k.value();
if (index > maxJointIndex) {
maxJointIndex = index;
}
}
// iterate through the hash and put joint names
// into the vector at their indices
QVector<QString> resultVector(maxJointIndex+1);
QHashIterator<QString, int> i(_modelJointIndicesCache);
while (i.hasNext()) {
i.next();
int index = i.value();
resultVector[index] = i.key();
}
// convert to QList and drop out blanks
result = resultVector.toList();
QMutableListIterator<QString> j(result);
while (j.hasNext()) {
QString jointName = j.next();
if (jointName.isEmpty()) {
j.remove();
}
}
});
return result;
}