cache the jointnames and indexes from FBXGeometry for out-of-thread access

This commit is contained in:
Seth Alves 2017-07-06 14:02:59 -07:00
parent 18b7e6aecd
commit 0ac8f6efa3
2 changed files with 18 additions and 29 deletions

View file

@ -1009,48 +1009,25 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const {
} }
int Avatar::getJointIndex(const QString& name) const { int Avatar::getJointIndex(const QString& name) const {
/* if (QThread::currentThread() != thread()) { QReadLocker readLock(&_jointIndicesCacheLock);
int result; if (_jointIndicesCache.contains(name)) {
BLOCKING_INVOKE_METHOD(const_cast<Avatar*>(this), "getJointIndex", return _jointIndicesCache[name];
Q_RETURN_ARG(int, result), Q_ARG(const QString&, name));
return result;
} */
int result = getFauxJointIndex(name);
if (result != -1) {
return result;
} }
return _skeletonModel->isActive() ? _skeletonModel->getFBXGeometry().getJointIndex(name) : -1; return -1;
} }
QStringList Avatar::getJointNames() const { QStringList Avatar::getJointNames() const {
/* if (QThread::currentThread() != thread()) { QReadLocker readLock(&_jointIndicesCacheLock);
QStringList result; return _jointIndicesCache.keys();
BLOCKING_INVOKE_METHOD(const_cast<Avatar*>(this), "getJointNames",
Q_RETURN_ARG(QStringList, result));
return result;
}*/
return _skeletonModel->isActive() ? _skeletonModel->getFBXGeometry().getJointNames() : QStringList();
} }
glm::vec3 Avatar::getJointPosition(int index) const { glm::vec3 Avatar::getJointPosition(int index) const {
/* if (QThread::currentThread() != thread()) {
glm::vec3 position;
BLOCKING_INVOKE_METHOD(const_cast<Avatar*>(this), "getJointPosition",
Q_RETURN_ARG(glm::vec3, position), Q_ARG(const int, index));
return position;
}*/
glm::vec3 position; glm::vec3 position;
_skeletonModel->getJointPositionInWorldFrame(index, position); _skeletonModel->getJointPositionInWorldFrame(index, position);
return position; return position;
} }
glm::vec3 Avatar::getJointPosition(const QString& name) const { glm::vec3 Avatar::getJointPosition(const QString& name) const {
/* if (QThread::currentThread() != thread()) {
glm::vec3 position;
BLOCKING_INVOKE_METHOD(const_cast<Avatar*>(this), "getJointPosition",
Q_RETURN_ARG(glm::vec3, position), Q_ARG(const QString&, name));
return position;
}*/
glm::vec3 position; glm::vec3 position;
_skeletonModel->getJointPositionInWorldFrame(getJointIndex(name), position); _skeletonModel->getJointPositionInWorldFrame(getJointIndex(name), position);
return position; return position;
@ -1071,6 +1048,14 @@ void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
} }
void Avatar::setModelURLFinished(bool success) { void Avatar::setModelURLFinished(bool success) {
{
QWriteLocker writeLock(&_jointIndicesCacheLock);
_jointIndicesCache.clear();
if (_skeletonModel && _skeletonModel->isActive()) {
_jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices;
}
}
if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) { if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) {
const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts
if (_skeletonModel->getResourceDownloadAttemptsRemaining() <= 0 || if (_skeletonModel->getResourceDownloadAttemptsRemaining() <= 0 ||

View file

@ -267,6 +267,10 @@ protected:
virtual void maybeUpdateSessionDisplayNameFromTransport(const QString& sessionDisplayName) override { _sessionDisplayName = sessionDisplayName; } // don't use no-op setter! virtual void maybeUpdateSessionDisplayNameFromTransport(const QString& sessionDisplayName) override { _sessionDisplayName = sessionDisplayName; } // don't use no-op setter!
SkeletonModelPointer _skeletonModel; SkeletonModelPointer _skeletonModel;
QHash<QString, int> _jointIndicesCache;
mutable QReadWriteLock _jointIndicesCacheLock;
glm::vec3 _skeletonOffset; glm::vec3 _skeletonOffset;
std::vector<std::shared_ptr<Model>> _attachmentModels; std::vector<std::shared_ptr<Model>> _attachmentModels;
std::vector<std::shared_ptr<Model>> _attachmentsToRemove; std::vector<std::shared_ptr<Model>> _attachmentsToRemove;