diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 913f22be18..f4f9d6fb69 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -97,9 +97,6 @@ void Agent::run() { // setup an Avatar for the script to use AvatarData scriptedAvatar; - // match the scripted avatar's UUID to the DataServerScriptingInterface UUID - scriptedAvatar.setUUID(_scriptEngine.getDataServerScriptingInterface().getUUID()); - // give this AvatarData object to the script engine _scriptEngine.setAvatarData(&scriptedAvatar, "Avatar"); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b59893a10e..268df17ffd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3913,6 +3913,11 @@ void Application::setMenuShortcutsEnabled(bool enabled) { void Application::attachNewHeadToNode(Node* newNode) { if (newNode->getLinkedData() == NULL) { newNode->setLinkedData(new Avatar(newNode)); + + // new UUID requires mesh and skeleton request to data-server + DataServerClient::getValuesForKeysAndUUID(QStringList() << DataServerKey::FaceMeshURL << DataServerKey::SkeletonURL, + newNode->getUUID(), Application::getInstance()->getProfile()); + } } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 30de5b1e2a..7705a5d03e 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -345,20 +345,11 @@ int Avatar::parseData(unsigned char* sourceBuffer, int numBytes) { // change in position implies movement glm::vec3 oldPosition = _position; - // change in UUID requires mesh and skeleton request to data-server - - QUuid oldUuid = _uuid; - int bytesRead = AvatarData::parseData(sourceBuffer, numBytes); const float MOVE_DISTANCE_THRESHOLD = 0.001f; _moving = glm::distance(oldPosition, _position) > MOVE_DISTANCE_THRESHOLD; - if (oldUuid != _uuid && !_uuid.isNull()) { - DataServerClient::getValuesForKeysAndUUID(QStringList() << DataServerKey::FaceMeshURL << DataServerKey::SkeletonURL, - _uuid, Application::getInstance()->getProfile()); - } - return bytesRead; } diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 89ce750d68..dfd06daa4a 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -48,8 +48,8 @@ QString Profile::getUserString() const { void Profile::setUUID(const QUuid& uuid) { _uuid = uuid; - // when the UUID is changed we need set it appropriately on our avatar instance - Application::getInstance()->getAvatar()->setUUID(_uuid); + // when the UUID is changed we need set it appropriately on the NodeList instance + NodeList::getInstance()->setOwnerUUID(uuid); } void Profile::setFaceModelURL(const QUrl& faceModelURL) { @@ -156,19 +156,15 @@ void Profile::processDataServerResponse(const QString& userString, const QString Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[i])); } else { // mesh URL for a UUID, find avatar in our list - - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { - Avatar* avatar = (Avatar *) node->getLinkedData(); - - if (avatar->getUUID() == QUuid(userString)) { - qDebug() << "Changing mesh to" << valueList[i] << "for avatar with UUID" - << uuidStringWithoutCurlyBraces(avatar->getUUID()); - - QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(), - "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); - } - } + SharedNodePointer matchingNode = NodeList::getInstance()->nodeWithUUID(QUuid(userString)); + if (matchingNode && matchingNode->getType() == NODE_TYPE_AGENT) { + qDebug() << "Changing mesh to" << valueList[i] << "for avatar with UUID" + << uuidStringWithoutCurlyBraces(matchingNode->getUUID()); + + Avatar* avatar = (Avatar *) matchingNode->getLinkedData(); + + QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(), + "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); } } } else if (keyList[i] == DataServerKey::SkeletonURL) { @@ -177,18 +173,15 @@ void Profile::processDataServerResponse(const QString& userString, const QString Application::getInstance()->getProfile()->setSkeletonModelURL(QUrl(valueList[i])); } else { // skeleton URL for a UUID, find avatar in our list - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { - Avatar* avatar = (Avatar *) node->getLinkedData(); - - if (avatar->getUUID() == QUuid(userString)) { - qDebug() << "Changing skeleton to" << valueList[i] << "for avatar with UUID" - << uuidStringWithoutCurlyBraces(avatar->getUUID()); - - QMetaObject::invokeMethod(&avatar->getSkeletonModel(), "setURL", - Q_ARG(QUrl, QUrl(valueList[i]))); - } - } + SharedNodePointer matchingNode = NodeList::getInstance()->nodeWithUUID(QUuid(userString)); + if (matchingNode && matchingNode->getType() == NODE_TYPE_AGENT) { + qDebug() << "Changing skeleton to" << valueList[i] << "for avatar with UUID" + << uuidStringWithoutCurlyBraces(matchingNode->getUUID()); + + Avatar* avatar = (Avatar *) matchingNode->getLinkedData(); + + QMetaObject::invokeMethod(&avatar->getSkeletonModel(), + "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); } } } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position && diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 35e6c37e96..a0dea1743e 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -24,7 +24,6 @@ static const float fingerVectorRadix = 4; // bits of precision when converting f AvatarData::AvatarData(Node* owningNode) : NodeData(owningNode), - _uuid(), _handPosition(0,0,0), _bodyYaw(-90.0), _bodyPitch(0.0), @@ -69,10 +68,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { _handData = new HandData(this); } - // UUID - QByteArray uuidByteArray = _uuid.toRfc4122(); - memcpy(destinationBuffer, uuidByteArray.constData(), uuidByteArray.size()); - destinationBuffer += uuidByteArray.size(); + // pack the NodeList owner UUID + destinationBuffer += NodeList::getInstance()->packOwnerUUID(destinationBuffer); // Body world position memcpy(destinationBuffer, &_position, sizeof(float) * 3); @@ -180,11 +177,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // push past the node session UUID sourceBuffer += NUM_BYTES_RFC4122_UUID; - - // user UUID - _uuid = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID)); - sourceBuffer += NUM_BYTES_RFC4122_UUID; - + // Body world position memcpy(&_position, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 0005d1eb11..ac0d198fc9 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -82,9 +82,6 @@ public: int getBroadcastData(unsigned char* destinationBuffer); int parseData(unsigned char* sourceBuffer, int numBytes); - QUuid& getUUID() { return _uuid; } - void setUUID(const QUuid& uuid) { _uuid = uuid; } - // Body Rotation float getBodyYaw() const { return _bodyYaw; } void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } @@ -137,8 +134,6 @@ public: } protected: - QUuid _uuid; - glm::vec3 _position; glm::vec3 _handPosition; diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index f33137a092..f37f2b48dc 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -642,6 +642,12 @@ void NodeList::sendAssignment(Assignment& assignment) { assignmentServerSocket->getPort()); } +int NodeList::packOwnerUUID(unsigned char* packetData) { + QByteArray rfcUUID = _ownerUUID.toRfc4122(); + memcpy(packetData, rfcUUID.constData(), rfcUUID.size()); + return rfcUUID.size(); +} + int NodeList::fillPingPacket(unsigned char* buffer) { int numHeaderBytes = populateTypeAndVersion(buffer, PACKET_TYPE_PING); uint64_t currentTime = usecTimestampNow(); diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index b5e27564b1..9ac6c5970c 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -96,6 +96,8 @@ public: void setAssignmentServerSocket(const HifiSockAddr& serverSocket) { _assignmentServerSocket = serverSocket; } void sendAssignment(Assignment& assignment); + + int packOwnerUUID(unsigned char* packetData); int fillPingPacket(unsigned char* buffer); int fillPingReplyPacket(unsigned char* pingBuffer, unsigned char* replyBuffer); diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index 83dbf4654f..e3659a3e7d 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -20,7 +20,7 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) { return 2; case PACKET_TYPE_HEAD_DATA: - return 15; + return 16; case PACKET_TYPE_OCTREE_STATS: return 2;