mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:35:08 +02:00
Merge pull request #9652 from sethalves/avatar-as-child-fixes
some fixes for when an avatar is a child of something else
This commit is contained in:
commit
f433347362
8 changed files with 42 additions and 38 deletions
|
@ -405,7 +405,7 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
otherNodeData->getLastReceivedSequenceNumber());
|
||||
|
||||
// determine if avatar is in view, to determine how much data to include...
|
||||
glm::vec3 otherNodeBoxScale = (otherNodeData->getPosition() - otherNodeData->getGlobalBoundingBoxCorner()) * 2.0f;
|
||||
glm::vec3 otherNodeBoxScale = (otherPosition - otherNodeData->getGlobalBoundingBoxCorner()) * 2.0f;
|
||||
AABox otherNodeBox(otherNodeData->getGlobalBoundingBoxCorner(), otherNodeBoxScale);
|
||||
bool isInView = nodeData->otherAvatarInView(otherNodeBox);
|
||||
|
||||
|
@ -431,7 +431,7 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
auto lastEncodeForOther = nodeData->getLastOtherAvatarEncodeTime(otherNode->getUUID());
|
||||
QVector<JointData>& lastSentJointsForOther = nodeData->getLastOtherAvatarSentJoints(otherNode->getUUID());
|
||||
bool distanceAdjust = true;
|
||||
glm::vec3 viewerPosition = nodeData->getPosition();
|
||||
glm::vec3 viewerPosition = myPosition;
|
||||
auto bytes = otherAvatar.toByteArray(detail, lastEncodeForOther, lastSentJointsForOther, distanceAdjust, viewerPosition, &lastSentJointsForOther);
|
||||
numAvatarDataBytes += avatarPacketList->write(bytes);
|
||||
|
||||
|
|
|
@ -1361,6 +1361,7 @@ void Avatar::setParentID(const QUuid& parentID) {
|
|||
if (!isMyAvatar()) {
|
||||
return;
|
||||
}
|
||||
QUuid initialParentID = getParentID();
|
||||
bool success;
|
||||
Transform beforeChangeTransform = getTransform(success);
|
||||
SpatiallyNestable::setParentID(parentID);
|
||||
|
@ -1369,6 +1370,9 @@ void Avatar::setParentID(const QUuid& parentID) {
|
|||
if (!success) {
|
||||
qCDebug(interfaceapp) << "Avatar::setParentID failed to reset avatar's location.";
|
||||
}
|
||||
if (initialParentID != parentID) {
|
||||
_parentChanged = usecTimestampNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ Line3DOverlay::~Line3DOverlay() {
|
|||
|
||||
glm::vec3 Line3DOverlay::getStart() const {
|
||||
bool success;
|
||||
glm::vec3 worldStart = localToWorld(_start, _parentID, _parentJointIndex, success);
|
||||
glm::vec3 worldStart = localToWorld(_start, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::getStart failed";
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ glm::vec3 Line3DOverlay::getStart() const {
|
|||
|
||||
glm::vec3 Line3DOverlay::getEnd() const {
|
||||
bool success;
|
||||
glm::vec3 worldEnd = localToWorld(_end, _parentID, _parentJointIndex, success);
|
||||
glm::vec3 worldEnd = localToWorld(_end, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::getEnd failed";
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ glm::vec3 Line3DOverlay::getEnd() const {
|
|||
|
||||
void Line3DOverlay::setStart(const glm::vec3& start) {
|
||||
bool success;
|
||||
_start = worldToLocal(start, _parentID, _parentJointIndex, success);
|
||||
_start = worldToLocal(start, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::setStart failed";
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ void Line3DOverlay::setStart(const glm::vec3& start) {
|
|||
|
||||
void Line3DOverlay::setEnd(const glm::vec3& end) {
|
||||
bool success;
|
||||
_end = worldToLocal(end, _parentID, _parentJointIndex, success);
|
||||
_end = worldToLocal(end, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::setEnd failed";
|
||||
}
|
||||
|
|
|
@ -257,8 +257,10 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
|
|||
// local position, and parent info only apply to avatars that are parented. The local position
|
||||
// and the parent info can change independently though, so we track their "changed since"
|
||||
// separately
|
||||
bool hasParentInfo = hasParent() && (sendAll || parentInfoChangedSince(lastSentTime));
|
||||
bool hasAvatarLocalPosition = hasParent() && (sendAll || tranlationChangedSince(lastSentTime));
|
||||
bool hasParentInfo = sendAll || parentInfoChangedSince(lastSentTime);
|
||||
bool hasAvatarLocalPosition = hasParent() && (sendAll ||
|
||||
tranlationChangedSince(lastSentTime) ||
|
||||
parentInfoChangedSince(lastSentTime));
|
||||
|
||||
bool hasFaceTrackerInfo = hasFaceTracker() && (sendAll || faceTrackerInfoChangedSince(lastSentTime));
|
||||
bool hasJointData = sendAll || !sendMinimum;
|
||||
|
@ -404,6 +406,18 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
|
|||
_additionalFlagsRateOutbound.increment(numBytes);
|
||||
}
|
||||
|
||||
if (hasParentInfo) {
|
||||
auto startSection = destinationBuffer;
|
||||
auto parentInfo = reinterpret_cast<AvatarDataPacket::ParentInfo*>(destinationBuffer);
|
||||
QByteArray referentialAsBytes = parentID.toRfc4122();
|
||||
memcpy(parentInfo->parentUUID, referentialAsBytes.data(), referentialAsBytes.size());
|
||||
parentInfo->parentJointIndex = getParentJointIndex();
|
||||
destinationBuffer += sizeof(AvatarDataPacket::ParentInfo);
|
||||
|
||||
int numBytes = destinationBuffer - startSection;
|
||||
_parentInfoRateOutbound.increment(numBytes);
|
||||
}
|
||||
|
||||
if (hasAvatarLocalPosition) {
|
||||
auto startSection = destinationBuffer;
|
||||
auto data = reinterpret_cast<AvatarDataPacket::AvatarLocalPosition*>(destinationBuffer);
|
||||
|
@ -417,18 +431,6 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
|
|||
_localPositionRateOutbound.increment(numBytes);
|
||||
}
|
||||
|
||||
if (hasParentInfo) {
|
||||
auto startSection = destinationBuffer;
|
||||
auto parentInfo = reinterpret_cast<AvatarDataPacket::ParentInfo*>(destinationBuffer);
|
||||
QByteArray referentialAsBytes = parentID.toRfc4122();
|
||||
memcpy(parentInfo->parentUUID, referentialAsBytes.data(), referentialAsBytes.size());
|
||||
parentInfo->parentJointIndex = _parentJointIndex;
|
||||
destinationBuffer += sizeof(AvatarDataPacket::ParentInfo);
|
||||
|
||||
int numBytes = destinationBuffer - startSection;
|
||||
_parentInfoRateOutbound.increment(numBytes);
|
||||
}
|
||||
|
||||
// If it is connected, pack up the data
|
||||
if (hasFaceTrackerInfo) {
|
||||
auto startSection = destinationBuffer;
|
||||
|
@ -882,7 +884,7 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
|
||||
sourceBuffer += sizeof(AvatarDataPacket::AdditionalFlags);
|
||||
|
||||
if (somethingChanged) {
|
||||
if (somethingChanged) {
|
||||
_additionalFlagsChanged = usecTimestampNow();
|
||||
}
|
||||
int numBytesRead = sourceBuffer - startSection;
|
||||
|
@ -890,8 +892,6 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
_additionalFlagsUpdateRate.increment();
|
||||
}
|
||||
|
||||
// FIXME -- make sure to handle the existance of a parent vs a change in the parent...
|
||||
//bool hasReferential = oneAtBit(bitItems, HAS_REFERENTIAL);
|
||||
if (hasParentInfo) {
|
||||
auto startSection = sourceBuffer;
|
||||
PACKET_READ_CHECK(ParentInfo, sizeof(AvatarDataPacket::ParentInfo));
|
||||
|
@ -902,9 +902,9 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
|
||||
auto newParentID = QUuid::fromRfc4122(byteArray);
|
||||
|
||||
if ((_parentID != newParentID) || (_parentJointIndex = parentInfo->parentJointIndex)) {
|
||||
_parentID = newParentID;
|
||||
_parentJointIndex = parentInfo->parentJointIndex;
|
||||
if ((getParentID() != newParentID) || (getParentJointIndex() != parentInfo->parentJointIndex)) {
|
||||
SpatiallyNestable::setParentID(newParentID);
|
||||
SpatiallyNestable::setParentJointIndex(parentInfo->parentJointIndex);
|
||||
_parentChanged = usecTimestampNow();
|
||||
}
|
||||
|
||||
|
@ -912,13 +912,8 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
_parentInfoRate.increment(numBytesRead);
|
||||
_parentInfoUpdateRate.increment();
|
||||
}
|
||||
else {
|
||||
// FIXME - this aint totally right, for switching to parent/no-parent
|
||||
_parentID = QUuid();
|
||||
}
|
||||
|
||||
if (hasAvatarLocalPosition) {
|
||||
assert(hasParent()); // we shouldn't have local position unless we have a parent
|
||||
auto startSection = sourceBuffer;
|
||||
|
||||
PACKET_READ_CHECK(AvatarLocalPosition, sizeof(AvatarDataPacket::AvatarLocalPosition));
|
||||
|
@ -930,7 +925,11 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
}
|
||||
return buffer.size();
|
||||
}
|
||||
setLocalPosition(position);
|
||||
if (hasParent()) {
|
||||
setLocalPosition(position);
|
||||
} else {
|
||||
qCWarning(avatars) << "received localPosition for avatar with no parent";
|
||||
}
|
||||
sourceBuffer += sizeof(AvatarDataPacket::AvatarLocalPosition);
|
||||
int numBytesRead = sourceBuffer - startSection;
|
||||
_localPositionRate.increment(numBytesRead);
|
||||
|
|
|
@ -1595,7 +1595,7 @@ void EntityItem::updatePosition(const glm::vec3& value) {
|
|||
}
|
||||
|
||||
void EntityItem::updateParentID(const QUuid& value) {
|
||||
if (_parentID != value) {
|
||||
if (getParentID() != value) {
|
||||
setParentID(value);
|
||||
_dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; // children are forced to be kinematic
|
||||
_dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar
|
||||
|
|
|
@ -56,7 +56,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
case PacketType::AvatarData:
|
||||
case PacketType::BulkAvatarData:
|
||||
case PacketType::KillAvatar:
|
||||
return static_cast<PacketVersion>(AvatarMixerPacketVersion::VariableAvatarData);
|
||||
return static_cast<PacketVersion>(AvatarMixerPacketVersion::AvatarAsChildFixes);
|
||||
case PacketType::MessagesData:
|
||||
return static_cast<PacketVersion>(MessageDataVersion::TextOrBinaryData);
|
||||
case PacketType::ICEServerHeartbeat:
|
||||
|
|
|
@ -224,7 +224,8 @@ enum class AvatarMixerPacketVersion : PacketVersion {
|
|||
SessionDisplayName,
|
||||
Unignore,
|
||||
ImmediateSessionDisplayNameUpdates,
|
||||
VariableAvatarData
|
||||
VariableAvatarData,
|
||||
AvatarAsChildFixes
|
||||
};
|
||||
|
||||
enum class DomainConnectRequestVersion : PacketVersion {
|
||||
|
|
|
@ -186,9 +186,6 @@ public:
|
|||
protected:
|
||||
const NestableType _nestableType; // EntityItem or an AvatarData
|
||||
QUuid _id;
|
||||
QUuid _parentID; // what is this thing's transform relative to?
|
||||
quint16 _parentJointIndex { INVALID_JOINT_INDEX }; // which joint of the parent is this relative to?
|
||||
|
||||
mutable SpatiallyNestableWeakPointer _parent;
|
||||
|
||||
virtual void beParentOfChild(SpatiallyNestablePointer newChild) const;
|
||||
|
@ -211,6 +208,9 @@ protected:
|
|||
quint64 _rotationChanged { 0 };
|
||||
|
||||
private:
|
||||
QUuid _parentID; // what is this thing's transform relative to?
|
||||
quint16 _parentJointIndex { INVALID_JOINT_INDEX }; // which joint of the parent is this relative to?
|
||||
|
||||
mutable ReadWriteLockable _transformLock;
|
||||
mutable ReadWriteLockable _idLock;
|
||||
mutable ReadWriteLockable _velocityLock;
|
||||
|
|
Loading…
Reference in a new issue