From 391b62ed32aca3b48f00b6ce85b71debaee5f9fd Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 5 Jun 2013 10:34:41 -0700 Subject: [PATCH 1/5] Make sure we don't hear back from replies after we've cleared them. --- interface/src/AvatarVoxelSystem.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/interface/src/AvatarVoxelSystem.cpp b/interface/src/AvatarVoxelSystem.cpp index 46a4212239..c50cb5b8a7 100644 --- a/interface/src/AvatarVoxelSystem.cpp +++ b/interface/src/AvatarVoxelSystem.cpp @@ -79,6 +79,7 @@ void AvatarVoxelSystem::loadVoxelsFromURL(const QUrl& url) { // cancel any current download if (_voxelReply != 0) { delete _voxelReply; + _voxelReply = 0; } killLocalVoxels(); @@ -196,17 +197,11 @@ void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 return; } - // XXXBHG - I don't know why this can happen, but when I was testing this, I used a dropbox URL - // and it resulted in a case where the bytesTotal == bytesReceived, but the _voxelReply was NULL - // which needless to say caused crashes below. I've added this quick guard to protect against - // this case, but it probably should be investigated. - if (!_voxelReply) { - return; - } - QByteArray entirety = _voxelReply->readAll(); + _voxelReply->disconnect(this); _voxelReply->deleteLater(); _voxelReply = 0; + _tree->readBitstreamToTree((unsigned char*)entirety.data(), entirety.size(), WANT_COLOR, NO_EXISTS_BITS); setupNewVoxelsForDrawing(); } @@ -214,6 +209,7 @@ void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 void AvatarVoxelSystem::handleVoxelReplyError() { printLog("%s\n", _voxelReply->errorString().toAscii().constData()); + _voxelReply->disconnect(this); _voxelReply->deleteLater(); _voxelReply = 0; } From 69dd4ff59bfa90b545657331a36e4f9923893cda Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 5 Jun 2013 13:08:17 -0700 Subject: [PATCH 2/5] Improved rotation computation. --- interface/src/Avatar.cpp | 4 +++- interface/src/Skeleton.cpp | 4 +++- interface/src/Skeleton.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index d8178ca643..ed4102f522 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1082,7 +1082,9 @@ void Avatar::updateBodyBalls(float deltaTime) { if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL || length < SMALL_SPRING_LENGTH) { _bodyBall[b].rotation = orientation * _skeleton.joint[_bodyBall[b].parentJoint].absoluteBindPoseRotation; } else { - _bodyBall[b].rotation = rotationBetween(jointDirection, springVector) * orientation; + glm::vec3 parentDirection = _bodyBall[ _skeleton.joint[b].parent ].rotation * JOINT_DIRECTION; + _bodyBall[b].rotation = rotationBetween(parentDirection, springVector) * + _bodyBall[ _skeleton.joint[b].parent ].rotation; } } } diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index b3720c8869..92dba252a1 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -118,7 +118,9 @@ void Skeleton::initialize() { } else { joint[b].absoluteBindPosePosition = joint[ joint[b].parent ].absoluteBindPosePosition + joint[b].bindPosePosition; - joint[b].absoluteBindPoseRotation = rotationBetween(JOINT_DIRECTION, joint[b].bindPosePosition); + glm::vec3 parentDirection = joint[ joint[b].parent ].absoluteBindPoseRotation * JOINT_DIRECTION; + joint[b].absoluteBindPoseRotation = rotationBetween(parentDirection, joint[b].bindPosePosition) * + joint[ joint[b].parent ].absoluteBindPoseRotation; } } } diff --git a/interface/src/Skeleton.h b/interface/src/Skeleton.h index b5a7cee0ba..e98c2e7b12 100644 --- a/interface/src/Skeleton.h +++ b/interface/src/Skeleton.h @@ -42,7 +42,7 @@ enum AvatarJointID NUM_AVATAR_JOINTS }; -const glm::vec3 JOINT_DIRECTION = glm::vec3(1.0f, 0.0f, 0.0f); +const glm::vec3 JOINT_DIRECTION = glm::vec3(0.0f, 1.0f, 0.0f); class Skeleton { public: From a4aa8e7bde88ceb046c624a6af30f03d00e85148 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 5 Jun 2013 14:55:49 -0700 Subject: [PATCH 3/5] Basic sharing of the avatar voxel URLs. --- avatar-mixer/src/main.cpp | 11 ++++++ interface/src/Application.cpp | 54 ++++++++++++++++++++++++++-- interface/src/AvatarVoxelSystem.cpp | 9 +++-- interface/src/AvatarVoxelSystem.h | 7 ++-- libraries/shared/src/PacketHeaders.h | 1 + 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index caa9f609ce..0398a597fc 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -105,6 +105,17 @@ int main(int argc, const char* argv[]) { agentList->getAgentSocket()->send(agentAddress, broadcastPacket, currentBufferPosition - broadcastPacket); + break; + case PACKET_HEADER_AVATAR_VOXEL_URL: + // grab the agent ID from the packet + unpackAgentId(packetData + 1, &agentID); + + // let everyone else know about the update + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + if (agent->getActiveSocket() && agent->getAgentID() != agentID) { + agentList->getAgentSocket()->send(agent->getActiveSocket(), packetData, receivedBytes); + } + } break; case PACKET_HEADER_DOMAIN: // ignore the DS packet, for now agents are added only when they communicate directly with us diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f5f2085995..d70a1840ba 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -983,6 +983,44 @@ void Application::terminate() { } } +static void sendAvatarVoxelURLMessage(const QUrl& url) { + uint16_t ownerID = AgentList::getInstance()->getOwnerID(); + if (ownerID == UNKNOWN_AGENT_ID) { + return; // we don't yet know who we are + } + QByteArray message; + message.append(PACKET_HEADER_AVATAR_VOXEL_URL); + message.append((const char*)&ownerID, sizeof(ownerID)); + message.append(url.toEncoded()); + + AgentList::getInstance()->broadcastToAgents((unsigned char*)message.data(), message.size(), &AGENT_TYPE_AVATAR_MIXER, 1); +} + +static void processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataBytes) { + // skip the header + packetData++; + dataBytes--; + + // read the agent id + uint16_t agentID = *(uint16_t*)packetData; + packetData += sizeof(agentID); + dataBytes -= sizeof(agentID); + + // make sure the agent exists + Agent* agent = AgentList::getInstance()->agentWithID(agentID); + if (!agent || !agent->getLinkedData()) { + return; + } + Avatar* avatar = static_cast(agent->getLinkedData()); + if (!avatar->isInitialized()) { + return; // wait until initialized + } + QUrl url = QUrl::fromEncoded(QByteArray::fromRawData((char*)packetData, dataBytes)); + + // invoke the set URL function on the simulate/render thread + QMetaObject::invokeMethod(avatar->getVoxels(), "setVoxelURL", Q_ARG(QUrl, url)); +} + void Application::editPreferences() { QDialog dialog(_glWidget); dialog.setWindowTitle("Interface Preferences"); @@ -1006,7 +1044,8 @@ void Application::editPreferences() { } QUrl url(avatarURL->text()); _settings->setValue("avatarURL", url); - _myAvatar.getVoxels()->loadVoxelsFromURL(url); + _myAvatar.getVoxels()->setVoxelURL(url); + sendAvatarVoxelURLMessage(url); } void Application::pair() { @@ -1507,7 +1546,9 @@ void Application::init() { _myCamera.setModeShiftRate(1.0f); _myAvatar.setDisplayingLookatVectors(false); - _myAvatar.getVoxels()->loadVoxelsFromURL(_settings->value("avatarURL").toUrl()); + QUrl avatarURL = _settings->value("avatarURL").toUrl(); + _myAvatar.getVoxels()->setVoxelURL(avatarURL); + sendAvatarVoxelURLMessage(avatarURL); QCursor::setPos(_headMouseX, _headMouseY); @@ -1599,6 +1640,12 @@ void Application::updateAvatar(float deltaTime) { const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; AgentList::getInstance()->broadcastToAgents(broadcastString, endOfBroadcastStringWrite - broadcastString, broadcastReceivers, sizeof(broadcastReceivers)); + + // once in a while, send my voxel url + const float AVATAR_VOXEL_URL_SEND_INTERVAL = 1.0f; // seconds + if (shouldDo(AVATAR_VOXEL_URL_SEND_INTERVAL, deltaTime)) { + sendAvatarVoxelURLMessage(_myAvatar.getVoxels()->getVoxelURL()); + } } // If I'm in paint mode, send a voxel out to VOXEL server agents. @@ -2435,6 +2482,9 @@ void* Application::networkReceive(void* args) { app->_incomingPacket, bytesReceived); break; + case PACKET_HEADER_AVATAR_VOXEL_URL: + processAvatarVoxelURLMessage(app->_incomingPacket, bytesReceived); + break; default: AgentList::getInstance()->processAgentData(&senderAddress, app->_incomingPacket, bytesReceived); break; diff --git a/interface/src/AvatarVoxelSystem.cpp b/interface/src/AvatarVoxelSystem.cpp index c50cb5b8a7..ef2066d69e 100644 --- a/interface/src/AvatarVoxelSystem.cpp +++ b/interface/src/AvatarVoxelSystem.cpp @@ -8,7 +8,6 @@ #include #include -#include #include @@ -24,6 +23,9 @@ const int BONE_ELEMENTS_PER_VOXEL = BONE_ELEMENTS_PER_VERTEX * VERTICES_PER_VOXE AvatarVoxelSystem::AvatarVoxelSystem(Avatar* avatar) : VoxelSystem(AVATAR_TREE_SCALE, MAX_VOXELS_PER_AVATAR), _avatar(avatar), _voxelReply(0) { + + // we may have been created in the network thread, but we live in the main thread + moveToThread(Application::getInstance()->thread()); } AvatarVoxelSystem::~AvatarVoxelSystem() { @@ -75,7 +77,7 @@ void AvatarVoxelSystem::removeOutOfView() { // no-op for now } -void AvatarVoxelSystem::loadVoxelsFromURL(const QUrl& url) { +void AvatarVoxelSystem::setVoxelURL(const QUrl& url) { // cancel any current download if (_voxelReply != 0) { delete _voxelReply; @@ -84,6 +86,9 @@ void AvatarVoxelSystem::loadVoxelsFromURL(const QUrl& url) { killLocalVoxels(); + // remember the URL + _voxelURL = url; + // handle "file://" urls... if (url.isLocalFile()) { QString pathString = url.path(); diff --git a/interface/src/AvatarVoxelSystem.h b/interface/src/AvatarVoxelSystem.h index 3894fd75b9..cf297c25f4 100644 --- a/interface/src/AvatarVoxelSystem.h +++ b/interface/src/AvatarVoxelSystem.h @@ -10,6 +10,7 @@ #define __interface__AvatarVoxelSystem__ #include +#include #include "VoxelSystem.h" @@ -17,7 +18,6 @@ const int BONE_ELEMENTS_PER_VERTEX = 4; typedef GLubyte BoneIndices[BONE_ELEMENTS_PER_VERTEX]; class QNetworkReply; -class QUrl; class Avatar; @@ -33,7 +33,8 @@ public: virtual void removeOutOfView(); - void loadVoxelsFromURL(const QUrl& url); + Q_INVOKABLE void setVoxelURL(const QUrl& url); + const QUrl& getVoxelURL() const { return _voxelURL; } protected: @@ -55,6 +56,8 @@ private: Avatar* _avatar; + QUrl _voxelURL; + GLubyte* _readBoneIndicesArray; GLfloat* _readBoneWeightsArray; GLubyte* _writeBoneIndicesArray; diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index ea9f5f9fcf..3e6f2ba152 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -27,6 +27,7 @@ const PACKET_HEADER PACKET_HEADER_ERASE_VOXEL = 'E'; const PACKET_HEADER PACKET_HEADER_VOXEL_DATA = 'V'; const PACKET_HEADER PACKET_HEADER_VOXEL_DATA_MONOCHROME = 'v'; const PACKET_HEADER PACKET_HEADER_BULK_AVATAR_DATA = 'X'; +const PACKET_HEADER PACKET_HEADER_AVATAR_VOXEL_URL = 'U'; const PACKET_HEADER PACKET_HEADER_TRANSMITTER_DATA_V2 = 'T'; const PACKET_HEADER PACKET_HEADER_ENVIRONMENT_DATA = 'e'; const PACKET_HEADER PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L'; From b9e2e26ab10a906ba553dc1ef8069b81d278b98c Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 5 Jun 2013 14:59:08 -0700 Subject: [PATCH 4/5] Don't restart the download when we're given the same URL. --- interface/src/AvatarVoxelSystem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/AvatarVoxelSystem.cpp b/interface/src/AvatarVoxelSystem.cpp index ef2066d69e..8a7708587f 100644 --- a/interface/src/AvatarVoxelSystem.cpp +++ b/interface/src/AvatarVoxelSystem.cpp @@ -78,6 +78,11 @@ void AvatarVoxelSystem::removeOutOfView() { } void AvatarVoxelSystem::setVoxelURL(const QUrl& url) { + // don't restart the download if it's the same URL + if (_voxelURL == url) { + return; + } + // cancel any current download if (_voxelReply != 0) { delete _voxelReply; From 6c3425a642358446375275d33898ac5bb02b7f8a Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 5 Jun 2013 15:39:37 -0700 Subject: [PATCH 5/5] Fix for URL decoding. --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d70a1840ba..ce176b9acf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1015,7 +1015,7 @@ static void processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataB if (!avatar->isInitialized()) { return; // wait until initialized } - QUrl url = QUrl::fromEncoded(QByteArray::fromRawData((char*)packetData, dataBytes)); + QUrl url = QUrl::fromEncoded(QByteArray((char*)packetData, dataBytes)); // invoke the set URL function on the simulate/render thread QMetaObject::invokeMethod(avatar->getVoxels(), "setVoxelURL", Q_ARG(QUrl, url));