mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
Merge pull request #6854 from sethalves/access-avatar-parent-id-from-js
Access avatar parent information from js
This commit is contained in:
commit
58a7528b68
10 changed files with 90 additions and 27 deletions
|
@ -1230,3 +1230,33 @@ void Avatar::updatePalms() {
|
||||||
_leftPalmPositionCache.set(getUncachedLeftPalmPosition());
|
_leftPalmPositionCache.set(getUncachedLeftPalmPosition());
|
||||||
_rightPalmPositionCache.set(getUncachedRightPalmPosition());
|
_rightPalmPositionCache.set(getUncachedRightPalmPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Avatar::setParentID(const QUuid& parentID) {
|
||||||
|
if (!isMyAvatar()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool success;
|
||||||
|
Transform beforeChangeTransform = getTransform(success);
|
||||||
|
SpatiallyNestable::setParentID(parentID);
|
||||||
|
if (success) {
|
||||||
|
setTransform(beforeChangeTransform, success);
|
||||||
|
if (!success) {
|
||||||
|
qDebug() << "Avatar::setParentID failed to reset avatar's location.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Avatar::setParentJointIndex(quint16 parentJointIndex) {
|
||||||
|
if (!isMyAvatar()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool success;
|
||||||
|
Transform beforeChangeTransform = getTransform(success);
|
||||||
|
SpatiallyNestable::setParentJointIndex(parentJointIndex);
|
||||||
|
if (success) {
|
||||||
|
setTransform(beforeChangeTransform, success);
|
||||||
|
if (!success) {
|
||||||
|
qDebug() << "Avatar::setParentJointIndex failed to reset avatar's location.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -167,6 +167,12 @@ public:
|
||||||
using SpatiallyNestable::setOrientation;
|
using SpatiallyNestable::setOrientation;
|
||||||
virtual void setOrientation(const glm::quat& orientation) override;
|
virtual void setOrientation(const glm::quat& orientation) override;
|
||||||
|
|
||||||
|
// these call through to the SpatiallyNestable versions, but they are here to expose these to javascript.
|
||||||
|
Q_INVOKABLE virtual const QUuid getParentID() const { return SpatiallyNestable::getParentID(); }
|
||||||
|
Q_INVOKABLE virtual void setParentID(const QUuid& parentID);
|
||||||
|
Q_INVOKABLE virtual quint16 getParentJointIndex() const { return SpatiallyNestable::getParentJointIndex(); }
|
||||||
|
Q_INVOKABLE virtual void setParentJointIndex(quint16 parentJointIndex);
|
||||||
|
|
||||||
// NOT thread safe, must be called on main thread.
|
// NOT thread safe, must be called on main thread.
|
||||||
glm::vec3 getUncachedLeftPalmPosition() const;
|
glm::vec3 getUncachedLeftPalmPosition() const;
|
||||||
glm::quat getUncachedLeftPalmRotation() const;
|
glm::quat getUncachedLeftPalmRotation() const;
|
||||||
|
|
|
@ -134,7 +134,7 @@ glm::vec3 AvatarMotionState::getObjectGravity() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
const QUuid& AvatarMotionState::getObjectID() const {
|
const QUuid AvatarMotionState::getObjectID() const {
|
||||||
return _avatar->getSessionUUID();
|
return _avatar->getSessionUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
virtual glm::vec3 getObjectAngularVelocity() const override;
|
virtual glm::vec3 getObjectAngularVelocity() const override;
|
||||||
virtual glm::vec3 getObjectGravity() const override;
|
virtual glm::vec3 getObjectGravity() const override;
|
||||||
|
|
||||||
virtual const QUuid& getObjectID() const override;
|
virtual const QUuid getObjectID() const override;
|
||||||
|
|
||||||
virtual QUuid getSimulatorID() const override;
|
virtual QUuid getSimulatorID() const override;
|
||||||
|
|
||||||
|
|
|
@ -216,15 +216,14 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) {
|
||||||
setAtBit(bitItems, IS_EYE_TRACKER_CONNECTED);
|
setAtBit(bitItems, IS_EYE_TRACKER_CONNECTED);
|
||||||
}
|
}
|
||||||
// referential state
|
// referential state
|
||||||
bool success;
|
QUuid parentID = getParentID();
|
||||||
SpatiallyNestablePointer parent = getParentPointer(success);
|
if (!parentID.isNull()) {
|
||||||
if (parent && success) {
|
|
||||||
setAtBit(bitItems, HAS_REFERENTIAL);
|
setAtBit(bitItems, HAS_REFERENTIAL);
|
||||||
}
|
}
|
||||||
*destinationBuffer++ = bitItems;
|
*destinationBuffer++ = bitItems;
|
||||||
|
|
||||||
if (parent) {
|
if (!parentID.isNull()) {
|
||||||
QByteArray referentialAsBytes = parent->getID().toRfc4122();
|
QByteArray referentialAsBytes = parentID.toRfc4122();
|
||||||
memcpy(destinationBuffer, referentialAsBytes.data(), referentialAsBytes.size());
|
memcpy(destinationBuffer, referentialAsBytes.data(), referentialAsBytes.size());
|
||||||
destinationBuffer += referentialAsBytes.size();
|
destinationBuffer += referentialAsBytes.size();
|
||||||
memcpy(destinationBuffer, &_parentJointIndex, sizeof(_parentJointIndex));
|
memcpy(destinationBuffer, &_parentJointIndex, sizeof(_parentJointIndex));
|
||||||
|
@ -492,10 +491,12 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
||||||
// avatar's SkeletonModel might fall into the CPU expensive part of Model::updateClusterMatrices() when otherwise it
|
// avatar's SkeletonModel might fall into the CPU expensive part of Model::updateClusterMatrices() when otherwise it
|
||||||
// would not have required it. However, we know we can update many simultaneously animating avatars, and most
|
// would not have required it. However, we know we can update many simultaneously animating avatars, and most
|
||||||
// avatars will be moving constantly anyway, so I don't think we need to worry.
|
// avatars will be moving constantly anyway, so I don't think we need to worry.
|
||||||
if (getBodyYaw() != yaw || getBodyPitch() != pitch || getBodyRoll() != roll) {
|
glm::quat currentOrientation = getLocalOrientation();
|
||||||
|
glm::vec3 newEulerAngles(pitch, yaw, roll);
|
||||||
|
glm::quat newOrientation = glm::quat(glm::radians(newEulerAngles));
|
||||||
|
if (currentOrientation != newOrientation) {
|
||||||
_hasNewJointRotations = true;
|
_hasNewJointRotations = true;
|
||||||
glm::vec3 eulerAngles(pitch, yaw, roll);
|
setLocalOrientation(newOrientation);
|
||||||
setLocalOrientation(glm::quat(glm::radians(eulerAngles)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// scale
|
// scale
|
||||||
|
|
|
@ -177,7 +177,7 @@ public:
|
||||||
|
|
||||||
virtual bool isMyAvatar() const { return false; }
|
virtual bool isMyAvatar() const { return false; }
|
||||||
|
|
||||||
const QUuid& getSessionUUID() const { return getID(); }
|
const QUuid getSessionUUID() const { return getID(); }
|
||||||
|
|
||||||
glm::vec3 getHandPosition() const;
|
glm::vec3 getHandPosition() const;
|
||||||
void setHandPosition(const glm::vec3& handPosition);
|
void setHandPosition(const glm::vec3& handPosition);
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
virtual glm::vec3 getObjectGravity() const override { return _entity->getGravity(); }
|
virtual glm::vec3 getObjectGravity() const override { return _entity->getGravity(); }
|
||||||
virtual glm::vec3 getObjectLinearVelocityChange() const override;
|
virtual glm::vec3 getObjectLinearVelocityChange() const override;
|
||||||
|
|
||||||
virtual const QUuid& getObjectID() const override { return _entity->getID(); }
|
virtual const QUuid getObjectID() const override { return _entity->getID(); }
|
||||||
|
|
||||||
virtual quint8 getSimulationPriority() const override;
|
virtual quint8 getSimulationPriority() const override;
|
||||||
virtual QUuid getSimulatorID() const override;
|
virtual QUuid getSimulatorID() const override;
|
||||||
|
|
|
@ -128,7 +128,7 @@ public:
|
||||||
virtual glm::vec3 getObjectAngularVelocity() const = 0;
|
virtual glm::vec3 getObjectAngularVelocity() const = 0;
|
||||||
virtual glm::vec3 getObjectGravity() const = 0;
|
virtual glm::vec3 getObjectGravity() const = 0;
|
||||||
|
|
||||||
virtual const QUuid& getObjectID() const = 0;
|
virtual const QUuid getObjectID() const = 0;
|
||||||
|
|
||||||
virtual quint8 getSimulationPriority() const { return 0; }
|
virtual quint8 getSimulationPriority() const { return 0; }
|
||||||
virtual QUuid getSimulatorID() const = 0;
|
virtual QUuid getSimulatorID() const = 0;
|
||||||
|
|
|
@ -25,6 +25,37 @@ SpatiallyNestable::SpatiallyNestable(NestableType nestableType, QUuid id) :
|
||||||
_transform.setRotation(glm::quat());
|
_transform.setRotation(glm::quat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QUuid SpatiallyNestable::getID() const {
|
||||||
|
QUuid result;
|
||||||
|
_idLock.withReadLock([&] {
|
||||||
|
result = _id;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpatiallyNestable::setID(const QUuid& id) {
|
||||||
|
_idLock.withWriteLock([&] {
|
||||||
|
_id = id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const QUuid SpatiallyNestable::getParentID() const {
|
||||||
|
QUuid result;
|
||||||
|
_idLock.withReadLock([&] {
|
||||||
|
result = _parentID;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpatiallyNestable::setParentID(const QUuid& parentID) {
|
||||||
|
_idLock.withWriteLock([&] {
|
||||||
|
if (_parentID != parentID) {
|
||||||
|
_parentID = parentID;
|
||||||
|
_parentKnowsMe = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Transform SpatiallyNestable::getParentTransform(bool& success) const {
|
Transform SpatiallyNestable::getParentTransform(bool& success) const {
|
||||||
Transform result;
|
Transform result;
|
||||||
SpatiallyNestablePointer parent = getParentPointer(success);
|
SpatiallyNestablePointer parent = getParentPointer(success);
|
||||||
|
@ -40,14 +71,15 @@ Transform SpatiallyNestable::getParentTransform(bool& success) const {
|
||||||
|
|
||||||
SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) const {
|
SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) const {
|
||||||
SpatiallyNestablePointer parent = _parent.lock();
|
SpatiallyNestablePointer parent = _parent.lock();
|
||||||
|
QUuid parentID = getParentID(); // used for its locking
|
||||||
|
|
||||||
if (!parent && _parentID.isNull()) {
|
if (!parent && parentID.isNull()) {
|
||||||
// no parent
|
// no parent
|
||||||
success = true;
|
success = true;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent && parent->getID() == _parentID) {
|
if (parent && parent->getID() == parentID) {
|
||||||
// parent pointer is up-to-date
|
// parent pointer is up-to-date
|
||||||
if (!_parentKnowsMe) {
|
if (!_parentKnowsMe) {
|
||||||
parent->beParentOfChild(getThisPointer());
|
parent->beParentOfChild(getThisPointer());
|
||||||
|
@ -72,7 +104,7 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
|
||||||
success = false;
|
success = false;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
_parent = parentFinder->find(_parentID, success);
|
_parent = parentFinder->find(parentID, success);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +115,7 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
|
||||||
_parentKnowsMe = true;
|
_parentKnowsMe = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent || _parentID.isNull()) {
|
if (parent || parentID.isNull()) {
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
success = false;
|
success = false;
|
||||||
|
@ -104,13 +136,6 @@ void SpatiallyNestable::forgetChild(SpatiallyNestablePointer newChild) const {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatiallyNestable::setParentID(const QUuid& parentID) {
|
|
||||||
if (_parentID != parentID) {
|
|
||||||
_parentID = parentID;
|
|
||||||
_parentKnowsMe = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpatiallyNestable::setParentJointIndex(quint16 parentJointIndex) {
|
void SpatiallyNestable::setParentJointIndex(quint16 parentJointIndex) {
|
||||||
_parentJointIndex = parentJointIndex;
|
_parentJointIndex = parentJointIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ public:
|
||||||
SpatiallyNestable(NestableType nestableType, QUuid id);
|
SpatiallyNestable(NestableType nestableType, QUuid id);
|
||||||
virtual ~SpatiallyNestable() { }
|
virtual ~SpatiallyNestable() { }
|
||||||
|
|
||||||
virtual const QUuid& getID() const { return _id; }
|
virtual const QUuid getID() const;
|
||||||
virtual void setID(const QUuid& id) { _id = id; }
|
virtual void setID(const QUuid& id);
|
||||||
|
|
||||||
virtual QUuid getParentID() const { return _parentID; }
|
virtual const QUuid getParentID() const;
|
||||||
virtual void setParentID(const QUuid& parentID);
|
virtual void setParentID(const QUuid& parentID);
|
||||||
|
|
||||||
virtual quint16 getParentJointIndex() const { return _parentJointIndex; }
|
virtual quint16 getParentJointIndex() const { return _parentJointIndex; }
|
||||||
|
@ -145,6 +145,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable ReadWriteLockable _transformLock;
|
mutable ReadWriteLockable _transformLock;
|
||||||
|
mutable ReadWriteLockable _idLock;
|
||||||
Transform _transform; // this is to be combined with parent's world-transform to produce this' world-transform.
|
Transform _transform; // this is to be combined with parent's world-transform to produce this' world-transform.
|
||||||
mutable bool _parentKnowsMe { false };
|
mutable bool _parentKnowsMe { false };
|
||||||
bool _isDead { false };
|
bool _isDead { false };
|
||||||
|
|
Loading…
Reference in a new issue