Experimenting faster getters on Avatar for scripts

This commit is contained in:
Sam Gateau 2017-06-29 15:55:47 +02:00
parent 3a096381ce
commit f7a3b3a411
2 changed files with 22 additions and 13 deletions

View file

@ -404,8 +404,10 @@ void Rig::setJointRotation(int index, bool valid, const glm::quat& rotation, flo
} }
bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const { bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const {
if (isIndexValid(jointIndex)) { // if (isIndexValid(jointIndex)) {
position = (rotation * _internalPoseSet._absolutePoses[jointIndex].trans()) + translation; QReadLocker readLock(&_externalPoseSetLock);
if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) {
position = (rotation * _externalPoseSet._absolutePoses[jointIndex].trans()) + translation;
return true; return true;
} else { } else {
return false; return false;
@ -413,17 +415,24 @@ bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm:
} }
bool Rig::getJointPosition(int jointIndex, glm::vec3& position) const { bool Rig::getJointPosition(int jointIndex, glm::vec3& position) const {
/*
if (isIndexValid(jointIndex)) { if (isIndexValid(jointIndex)) {
position = _internalPoseSet._absolutePoses[jointIndex].trans(); position = _internalPoseSet._absolutePoses[jointIndex].trans();
return true; return true;
} else { } else {
return false; return false;
} }*/
return getAbsoluteJointTranslationInRigFrame(jointIndex, position);
} }
bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const { bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const {
if (isIndexValid(jointIndex)) { // if (isIndexValid(jointIndex)) {
result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot(); // result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot();
// return true;
QReadLocker readLock(&_externalPoseSetLock);
if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) {
result = rotation * _externalPoseSet._absolutePoses[jointIndex].rot();
return true; return true;
} else { } else {
return false; return false;

View file

@ -1008,12 +1008,12 @@ 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()) { /* if (QThread::currentThread() != thread()) {
int result; int result;
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointIndex", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointIndex", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(int, result), Q_ARG(const QString&, name)); Q_RETURN_ARG(int, result), Q_ARG(const QString&, name));
return result; return result;
} } */
int result = getFauxJointIndex(name); int result = getFauxJointIndex(name);
if (result != -1) { if (result != -1) {
return result; return result;
@ -1022,34 +1022,34 @@ int Avatar::getJointIndex(const QString& name) const {
} }
QStringList Avatar::getJointNames() const { QStringList Avatar::getJointNames() const {
if (QThread::currentThread() != thread()) { /* if (QThread::currentThread() != thread()) {
QStringList result; QStringList result;
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointNames", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointNames", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QStringList, result)); Q_RETURN_ARG(QStringList, result));
return result; return result;
} }*/
return _skeletonModel->isActive() ? _skeletonModel->getFBXGeometry().getJointNames() : QStringList(); 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()) { /* if (QThread::currentThread() != thread()) {
glm::vec3 position; glm::vec3 position;
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointPosition", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointPosition", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(glm::vec3, position), Q_ARG(const int, index)); Q_RETURN_ARG(glm::vec3, position), Q_ARG(const int, index));
return position; 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()) { /* if (QThread::currentThread() != thread()) {
glm::vec3 position; glm::vec3 position;
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointPosition", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(const_cast<Avatar*>(this), "getJointPosition", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(glm::vec3, position), Q_ARG(const QString&, name)); Q_RETURN_ARG(glm::vec3, position), Q_ARG(const QString&, name));
return position; return position;
} }*/
glm::vec3 position; glm::vec3 position;
_skeletonModel->getJointPositionInWorldFrame(getJointIndex(name), position); _skeletonModel->getJointPositionInWorldFrame(getJointIndex(name), position);
return position; return position;