Avatar::getJointRotation and getJointTranslation is thread-safe

It can be called from script with minimal blocking,
because it inspects a copy of the joint values from the Rig, which is updated atomically.
This copy occurs in Rig::updateAnimations()
This commit is contained in:
Anthony J. Thibault 2015-12-04 16:16:17 -08:00
parent ba001ef4b0
commit 7abfc93ff9
3 changed files with 9 additions and 13 deletions

View file

@ -857,18 +857,12 @@ QVector<glm::quat> Avatar::getJointRotations() const {
} }
glm::quat Avatar::getJointRotation(int index) const { glm::quat Avatar::getJointRotation(int index) const {
if (QThread::currentThread() != thread()) {
return AvatarData::getJointRotation(index);
}
glm::quat rotation; glm::quat rotation;
_skeletonModel.getJointRotation(index, rotation); _skeletonModel.getJointRotation(index, rotation);
return rotation; return rotation;
} }
glm::vec3 Avatar::getJointTranslation(int index) const { glm::vec3 Avatar::getJointTranslation(int index) const {
if (QThread::currentThread() != thread()) {
return AvatarData::getJointTranslation(index);
}
glm::vec3 translation; glm::vec3 translation;
_skeletonModel.getJointTranslation(index, translation); _skeletonModel.getJointTranslation(index, translation);
return translation; return translation;

View file

@ -300,7 +300,7 @@ void Rig::clearJointAnimationPriority(int index) {
void Rig::setJointTranslation(int index, bool valid, const glm::vec3& translation, float priority) { void Rig::setJointTranslation(int index, bool valid, const glm::vec3& translation, float priority) {
if (isIndexValid(index)) { if (isIndexValid(index)) {
if (valid) { if (valid) {
assert(_overrideFlags.size() == _internalPoseSet._overridePoses.size()); assert(_internalPoseSet._overrideFlags.size() == _internalPoseSet._overridePoses.size());
_internalPoseSet._overrideFlags[index] = true; _internalPoseSet._overrideFlags[index] = true;
_internalPoseSet._overridePoses[index].trans = translation; _internalPoseSet._overridePoses[index].trans = translation;
} }
@ -364,8 +364,9 @@ bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const
} }
bool Rig::getJointRotation(int jointIndex, glm::quat& rotation) const { bool Rig::getJointRotation(int jointIndex, glm::quat& rotation) const {
if (isIndexValid(jointIndex)) { QReadLocker readLock(&_externalPoseSetLock);
rotation = _internalPoseSet._relativePoses[jointIndex].rot; if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._relativePoses.size()) {
rotation = _externalPoseSet._relativePoses[jointIndex].rot;
return true; return true;
} else { } else {
return false; return false;
@ -373,8 +374,9 @@ bool Rig::getJointRotation(int jointIndex, glm::quat& rotation) const {
} }
bool Rig::getJointTranslation(int jointIndex, glm::vec3& translation) const { bool Rig::getJointTranslation(int jointIndex, glm::vec3& translation) const {
if (isIndexValid(jointIndex)) { QReadLocker readLock(&_externalPoseSetLock);
translation = _internalPoseSet._relativePoses[jointIndex].trans; if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._relativePoses.size()) {
translation = _externalPoseSet._relativePoses[jointIndex].trans;
return true; return true;
} else { } else {
return false; return false;

View file

@ -127,10 +127,10 @@ public:
// if rotation is identity, result will be in rig space // if rotation is identity, result will be in rig space
bool getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const; bool getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const;
// geometry space // geometry space (thread-safe)
bool getJointRotation(int jointIndex, glm::quat& rotation) const; bool getJointRotation(int jointIndex, glm::quat& rotation) const;
// geometry space // geometry space (thread-safe)
bool getJointTranslation(int jointIndex, glm::vec3& translation) const; bool getJointTranslation(int jointIndex, glm::vec3& translation) const;
// legacy // legacy