From bf328c853206300217beebdfc066c4c07f8b2927 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Mon, 15 Jul 2013 16:07:50 -0700 Subject: [PATCH 1/3] Improved import system copying to clipboard --- interface/src/Application.cpp | 47 ++++++----------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 27dac142c9..df6ea65bc2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1410,10 +1410,9 @@ void Application::importVoxels() { _glWidget, tr("Import Voxels"), desktopLocation, tr("Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)")); - QByteArray fileNameAscii = fileNameString.toAscii(); - const char* fileName = fileNameAscii.data(); - - VoxelTree importVoxels; + const char* fileName = fileNameString.toAscii().data(); + + _clipboardTree.eraseAllVoxels(); if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { QImage pngImage = QImage(fileName); if (pngImage.height() != pngImage.width()) { @@ -1429,43 +1428,11 @@ void Application::importVoxels() { pixels = reinterpret_cast(tmp.constBits()); } - importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height()); + _clipboardTree.readFromSquareARGB32Pixels(pixels, pngImage.height()); } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) { - importVoxels.readFromSVOFile(fileName); - } else { - importVoxels.readFromSchematicFile(fileName); - } - - VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); - - // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to - // the server as an set voxel message, this will also rebase the voxels to the new location - unsigned char* calculatedOctCode = NULL; - SendVoxelsOperationArgs args; - - int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE); - - unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader]; - *sequenceAt = 0; - args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence - - // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the - // voxel size/position details. - if (selectedNode) { - args.newBaseOctCode = selectedNode->getOctalCode(); - } else { - args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); - } - - importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args); - - // If we have voxels left in the packet, then send the packet - if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) { - controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); - } - - if (calculatedOctCode) { - delete[] calculatedOctCode; + _clipboardTree.readFromSVOFile(fileName); + } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) { + _clipboardTree.readFromSchematicFile(fileName); } // restore the main window's active state From d3f40033f9381fdc02d240c2be7e0df1cadf9f77 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Jul 2013 16:17:08 -0700 Subject: [PATCH 2/3] fix the node ID unpack for avatar data --- avatar-mixer/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index f2fd031526..497797d2e8 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -97,7 +97,7 @@ int main(int argc, const char* argv[]) { switch (packetData[0]) { case PACKET_TYPE_HEAD_DATA: // grab the node ID from the packet - unpackNodeId(packetData + 1, &nodeID); + unpackNodeId(packetData + numBytesForPacketHeader(packetData), &nodeID); // add or update the node in our list avatarNode = nodeList->addOrUpdateNode(nodeAddress, nodeAddress, NODE_TYPE_AGENT, nodeID); From 7f6009bb4a50fbcca80f1e4e2b85ab521ab628d6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Jul 2013 16:25:09 -0700 Subject: [PATCH 3/3] make randIntInRange inclusive on the max side --- animation-server/src/main.cpp | 2 +- libraries/shared/src/SharedUtil.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index 126216ea9b..7b909b4e11 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -434,7 +434,7 @@ void sendDanceFloor() { for (int i = 0; i < DANCE_FLOOR_WIDTH; i++) { for (int j = 0; j < DANCE_FLOOR_LENGTH; j++) { - int randomColorIndex = randIntInRange( -(DANCE_FLOOR_COLORS), (DANCE_FLOOR_COLORS + 1)); + int randomColorIndex = randIntInRange(-DANCE_FLOOR_COLORS, DANCE_FLOOR_COLORS); ::danceFloorColors[i][j] = randomColorIndex; ::danceFloorLights[i][j] = ::danceFloorPosition + glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE); diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 3fa7295d90..eb46458b2c 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -40,7 +40,7 @@ float randFloat () { } int randIntInRange (int min, int max) { - return min + (rand() % (max - min)); + return min + (rand() % ((max + 1) - min)); } float randFloatInRange (float min,float max) { @@ -48,7 +48,7 @@ float randFloatInRange (float min,float max) { } unsigned char randomColorValue(int miniumum) { - return miniumum + (rand() % (255 - miniumum)); + return miniumum + (rand() % (256 - miniumum)); } bool randomBoolean() {