Showing the changes to interface/src/Application.cpp (1 of 4 files). Show all
Unified · Split
| @@ -62,7 +62,6 @@ · 61 unmodified lines | |||
| 62 | #include <GlowEffect.h> | 62 | #include <GlowEffect.h> |
| 63 | #include <HFActionEvent.h> | 63 | #include <HFActionEvent.h> |
| 64 | #include <HFBackEvent.h> | 64 | #include <HFBackEvent.h> |
| 65 | #include <LocalVoxelsList.h> | ||
| 66 | #include <LogHandler.h> | 65 | #include <LogHandler.h> |
| 67 | #include <MainWindow.h> | 66 | #include <MainWindow.h> |
| 68 | #include <NetworkAccessManager.h> | 67 | #include <NetworkAccessManager.h> |
| @@ -151,15 +150,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 82 unmodified lines | |||
| 151 | _frameCount(0), | 150 | _frameCount(0), |
| 152 | _fps(60.0f), | 151 | _fps(60.0f), |
| 153 | _justStarted(true), | 152 | _justStarted(true), |
| 154 | _voxelImportDialog(NULL), | ||
| 155 | _voxelImporter(), | ||
| 156 | _importSucceded(false), | ||
| 157 | _sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard), | ||
| 158 | _entities(true, this, this), | 153 | _entities(true, this, this), |
| 159 | _entityCollisionSystem(), | 154 | _entityCollisionSystem(), |
| 160 | _entityClipboardRenderer(false, this, this), | 155 | _entityClipboardRenderer(false, this, this), |
| 161 | _entityClipboard(), | 156 | _entityClipboard(), |
| 162 | _wantToKillLocalVoxels(false), | ||
| 163 | _viewFrustum(), | 157 | _viewFrustum(), |
| 164 | _lastQueriedViewFrustum(), | 158 | _lastQueriedViewFrustum(), |
| 165 | _lastQueriedTime(usecTimestampNow()), | 159 | _lastQueriedTime(usecTimestampNow()), |
| @@ -177,7 +171,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 11 unmodified lines | |||
| 177 | _audio(), | 171 | _audio(), |
| 178 | _enableProcessVoxelsThread(true), | 172 | _enableProcessVoxelsThread(true), |
| 179 | _octreeProcessor(), | 173 | _octreeProcessor(), |
| 180 | _voxelHideShowThread(&_voxels), | ||
| 181 | _packetsPerSecond(0), | 174 | _packetsPerSecond(0), |
| 182 | _bytesPerSecond(0), | 175 | _bytesPerSecond(0), |
| 183 | _nodeBoundsDisplay(this), | 176 | _nodeBoundsDisplay(this), |
| @@ -275,8 +268,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 91 unmodified lines | |||
| 275 | connect(nodeList, &NodeList::nodeAdded, this, &Application::nodeAdded); | 268 | connect(nodeList, &NodeList::nodeAdded, this, &Application::nodeAdded); |
| 276 | connect(nodeList, &NodeList::nodeKilled, this, &Application::nodeKilled); | 269 | connect(nodeList, &NodeList::nodeKilled, this, &Application::nodeKilled); |
| 277 | connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer))); | 270 | connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer))); |
| 278 | connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer))); | ||
| 279 | connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer))); | ||
| 280 | connect(nodeList, &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID); | 271 | connect(nodeList, &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID); |
| 281 | connect(nodeList, &NodeList::limitOfSilentDomainCheckInsReached, nodeList, &NodeList::reset); | 272 | connect(nodeList, &NodeList::limitOfSilentDomainCheckInsReached, nodeList, &NodeList::reset); |
| 282 | 273 | ||
| @@ -313,10 +304,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 30 unmodified lines | |||
| 313 | _settings = new QSettings(this); | 304 | _settings = new QSettings(this); |
| 314 | _numChangedSettings = 0; | 305 | _numChangedSettings = 0; |
| 315 | 306 | ||
| 316 | // Check to see if the user passed in a command line option for loading a local | ||
| 317 | // Voxel File. | ||
| 318 | _voxelsFilename = getCmdOption(argc, constArgv, "-i"); | ||
| 319 | |||
| 320 | #ifdef _WIN32 | 307 | #ifdef _WIN32 |
| 321 | WSADATA WsaData; | 308 | WSADATA WsaData; |
| 322 | int wsaresult = WSAStartup(MAKEWORD(2,2), &WsaData); | 309 | int wsaresult = WSAStartup(MAKEWORD(2,2), &WsaData); |
| @@ -327,8 +314,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 4 unmodified lines | |||
| 327 | << NodeType::VoxelServer << NodeType::EntityServer | 314 | << NodeType::VoxelServer << NodeType::EntityServer |
| 328 | << NodeType::MetavoxelServer); | 315 | << NodeType::MetavoxelServer); |
| 329 | 316 | ||
| 330 | // connect to the packet sent signal of the _voxelEditSender and the _entityEditSender | 317 | // connect to the packet sent signal of the _entityEditSender |
| 331 | connect(&_voxelEditSender, &VoxelEditPacketSender::packetSent, this, &Application::packetSent); | ||
| 332 | connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent); | 318 | connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent); |
| 333 | 319 | ||
| 334 | // move the silentNodeTimer to the _nodeThread | 320 | // move the silentNodeTimer to the _nodeThread |
| @@ -373,8 +359,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 38 unmodified lines | |||
| 373 | 359 | ||
| 374 | // initialization continues in initializeGL when OpenGL context is ready | 360 | // initialization continues in initializeGL when OpenGL context is ready |
| 375 | 361 | ||
| 376 | // Tell our voxel edit sender about our known jurisdictions | 362 | // Tell our entity edit sender about our known jurisdictions |
| 377 | _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions); | ||
| 378 | _entityEditSender.setServerJurisdictions(&_entityServerJurisdictions); | 363 | _entityEditSender.setServerJurisdictions(&_entityServerJurisdictions); |
| 379 | 364 | ||
| 380 | // For now we're going to set the PPS for outbound packets to be super high, this is | 365 | // For now we're going to set the PPS for outbound packets to be super high, this is |
| @@ -386,9 +371,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 5 unmodified lines | |||
| 386 | 371 | ||
| 387 | _overlays.init(glCanvas.data()); // do this before scripts load | 372 | _overlays.init(glCanvas.data()); // do this before scripts load |
| 388 | 373 | ||
| 389 | LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); | ||
| 390 | LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); | ||
| 391 | |||
| 392 | _runningScriptsWidget->setRunningScripts(getRunningScripts()); | 374 | _runningScriptsWidget->setRunningScripts(getRunningScripts()); |
| 393 | connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); | 375 | connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); |
| 394 | 376 | ||
| @@ -446,9 +428,6 @@ Application::~Application() { · 51 unmodified lines | |||
| 446 | // make sure we don't call the idle timer any more | 428 | // make sure we don't call the idle timer any more |
| 447 | delete idleTimer; | 429 | delete idleTimer; |
| 448 | 430 | ||
| 449 | _sharedVoxelSystem.changeTree(new VoxelTree); | ||
| 450 | delete _voxelImportDialog; | ||
| 451 | |||
| 452 | // let the avatar mixer know we're out | 431 | // let the avatar mixer know we're out |
| 453 | MyAvatar::sendKillAvatar(); | 432 | MyAvatar::sendKillAvatar(); |
| 454 | 433 | ||
| @@ -467,11 +446,8 @@ Application::~Application() { · 12 unmodified lines | |||
| 467 | _audio.thread()->wait(); | 446 | _audio.thread()->wait(); |
| 468 | 447 | ||
| 469 | _octreeProcessor.terminate(); | 448 | _octreeProcessor.terminate(); |
| 470 | _voxelHideShowThread.terminate(); | ||
| 471 | _voxelEditSender.terminate(); | ||
| 472 | _entityEditSender.terminate(); | 449 | _entityEditSender.terminate(); |
| 473 | 450 | ||
| 474 | VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown | ||
| 475 | Menu::getInstance()->deleteLater(); | 451 | Menu::getInstance()->deleteLater(); |
| 476 | 452 | ||
| 477 | _myAvatar = NULL; | 453 | _myAvatar = NULL; |
| @@ -481,9 +457,6 @@ void Application::saveSettings() { · 3 unmodified lines | |||
| 481 | Menu::getInstance()->saveSettings(); | 457 | Menu::getInstance()->saveSettings(); |
| 482 | _rearMirrorTools->saveSettings(_settings); | 458 | _rearMirrorTools->saveSettings(_settings); |
| 483 | 459 | ||
| 484 | if (_voxelImportDialog) { | ||
| 485 | _voxelImportDialog->saveSettings(_settings); | ||
| 486 | } | ||
| 487 | _settings->sync(); | 460 | _settings->sync(); |
| 488 | _numChangedSettings = 0; | 461 | _numChangedSettings = 0; |
| 489 | } | 462 | } |
| @@ -568,14 +541,8 @@ void Application::initializeGL() { · 78 unmodified lines | |||
| 568 | 541 | ||
| 569 | // create thread for parsing of voxel data independent of the main network and rendering threads | 542 | // create thread for parsing of voxel data independent of the main network and rendering threads |
| 570 | _octreeProcessor.initialize(_enableProcessVoxelsThread); | 543 | _octreeProcessor.initialize(_enableProcessVoxelsThread); |
| 571 | _voxelEditSender.initialize(_enableProcessVoxelsThread); | ||
| 572 | _voxelHideShowThread.initialize(_enableProcessVoxelsThread); | ||
| 573 | _entityEditSender.initialize(_enableProcessVoxelsThread); | 544 | _entityEditSender.initialize(_enableProcessVoxelsThread); |
| 574 | 545 | ||
| 575 | if (_enableProcessVoxelsThread) { | ||
| 576 | qDebug("Voxel parsing thread created."); | ||
| 577 | } | ||
| 578 | |||
| 579 | // call our timer function every second | 546 | // call our timer function every second |
| 580 | QTimer* timer = new QTimer(this); | 547 | QTimer* timer = new QTimer(this); |
| 581 | connect(timer, SIGNAL(timeout()), SLOT(timer())); | 548 | connect(timer, SIGNAL(timeout()), SLOT(timer())); |
| @@ -797,10 +764,6 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) · 215 unmodified lines | |||
| 797 | 764 | ||
| 798 | void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { | 765 | void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { |
| 799 | foreach(NodeType_t type, destinationNodeTypes) { | 766 | foreach(NodeType_t type, destinationNodeTypes) { |
| 800 | // Intercept data to voxel server when voxels are disabled | ||
| 801 | if (type == NodeType::VoxelServer && !Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { | ||
| 802 | continue; | ||
| 803 | } | ||
| 804 | 767 | ||
| 805 | // Perform the broadcast for one type | 768 | // Perform the broadcast for one type |
| 806 | int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(packet, NodeSet() << type); | 769 | int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(packet, NodeSet() << type); |
| @@ -812,7 +775,6 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod · 5 unmodified lines | |||
| 812 | case NodeType::AvatarMixer: | 775 | case NodeType::AvatarMixer: |
| 813 | channel = BandwidthMeter::AVATARS; | 776 | channel = BandwidthMeter::AVATARS; |
| 814 | break; | 777 | break; |
| 815 | case NodeType::VoxelServer: | ||
| 816 | case NodeType::EntityServer: | 778 | case NodeType::EntityServer: |
| 817 | channel = BandwidthMeter::VOXELS; | 779 | channel = BandwidthMeter::VOXELS; |
| 818 | break; | 780 | break; |
| @@ -1093,11 +1055,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 274 unmodified lines | |||
| 1093 | Menu::getInstance()->triggerOption(MenuOption::DisplayFrustum); | 1055 | Menu::getInstance()->triggerOption(MenuOption::DisplayFrustum); |
| 1094 | } | 1056 | } |
| 1095 | break; | 1057 | break; |
| 1096 | case Qt::Key_V: | ||
| 1097 | if (isShifted) { | ||
| 1098 | Menu::getInstance()->triggerOption(MenuOption::Voxels); | ||
| 1099 | } | ||
| 1100 | break; | ||
| 1101 | case Qt::Key_P: | 1058 | case Qt::Key_P: |
| 1102 | Menu::getInstance()->triggerOption(MenuOption::FirstPerson); | 1059 | Menu::getInstance()->triggerOption(MenuOption::FirstPerson); |
| 1103 | break; | 1060 | break; |
| @@ -1442,7 +1399,7 @@ void Application::dropEvent(QDropEvent *event) { · 338 unmodified lines | |||
| 1442 | void Application::sendPingPackets() { | 1399 | void Application::sendPingPackets() { |
| 1443 | QByteArray pingPacket = NodeList::getInstance()->constructPingPacket(); | 1400 | QByteArray pingPacket = NodeList::getInstance()->constructPingPacket(); |
| 1444 | controlledBroadcastToNodes(pingPacket, NodeSet() | 1401 | controlledBroadcastToNodes(pingPacket, NodeSet() |
| 1445 | << NodeType::VoxelServer << NodeType::EntityServer | 1402 | << NodeType::EntityServer |
| 1446 | << NodeType::AudioMixer << NodeType::AvatarMixer | 1403 | << NodeType::AudioMixer << NodeType::AvatarMixer |
| 1447 | << NodeType::MetavoxelServer); | 1404 | << NodeType::MetavoxelServer); |
| 1448 | } | 1405 | } |
| @@ -1588,63 +1545,10 @@ void Application::setEnableVRMode(bool enableVRMode) { · 139 unmodified lines | |||
| 1588 | resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); | 1545 | resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); |
| 1589 | } | 1546 | } |
| 1590 | 1547 | ||
| 1591 | void Application::setRenderVoxels(bool voxelRender) { | ||
| 1592 | _voxelEditSender.setShouldSend(voxelRender); | ||
| 1593 | if (!voxelRender) { | ||
| 1594 | doKillLocalVoxels(); | ||
| 1595 | } | ||
| 1596 | } | ||
| 1597 | |||
| 1598 | void Application::setLowVelocityFilter(bool lowVelocityFilter) { | 1548 | void Application::setLowVelocityFilter(bool lowVelocityFilter) { |
| 1599 | SixenseManager::getInstance().setLowVelocityFilter(lowVelocityFilter); | 1549 | SixenseManager::getInstance().setLowVelocityFilter(lowVelocityFilter); |
| 1600 | } | 1550 | } |
| 1601 | 1551 | ||
| 1602 | void Application::doKillLocalVoxels() { | ||
| 1603 | _wantToKillLocalVoxels = true; | ||
| 1604 | } | ||
| 1605 | |||
| 1606 | void Application::removeVoxel(glm::vec3 position, | ||
| 1607 | float scale) { | ||
| 1608 | VoxelDetail voxel; | ||
| 1609 | voxel.x = position.x / TREE_SCALE; | ||
| 1610 | voxel.y = position.y / TREE_SCALE; | ||
| 1611 | voxel.z = position.z / TREE_SCALE; | ||
| 1612 | voxel.s = scale / TREE_SCALE; | ||
| 1613 | _voxelEditSender.sendVoxelEditMessage(PacketTypeVoxelErase, voxel); | ||
| 1614 | |||
| 1615 | // delete it locally to see the effect immediately (and in case no voxel server is present) | ||
| 1616 | _voxels.getTree()->deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); | ||
| 1617 | } | ||
| 1618 | |||
| 1619 | |||
| 1620 | void Application::makeVoxel(glm::vec3 position, | ||
| 1621 | float scale, | ||
| 1622 | unsigned char red, | ||
| 1623 | unsigned char green, | ||
| 1624 | unsigned char blue, | ||
| 1625 | bool isDestructive) { | ||
| 1626 | VoxelDetail voxel; | ||
| 1627 | voxel.x = position.x / TREE_SCALE; | ||
| 1628 | voxel.y = position.y / TREE_SCALE; | ||
| 1629 | voxel.z = position.z / TREE_SCALE; | ||
| 1630 | voxel.s = scale / TREE_SCALE; | ||
| 1631 | voxel.red = red; | ||
| 1632 | voxel.green = green; | ||
| 1633 | voxel.blue = blue; | ||
| 1634 | PacketType message = isDestructive ? PacketTypeVoxelSetDestructive : PacketTypeVoxelSet; | ||
| 1635 | _voxelEditSender.sendVoxelEditMessage(message, voxel); | ||
| 1636 | |||
| 1637 | // create the voxel locally so it appears immediately | ||
| 1638 | _voxels.getTree()->createVoxel(voxel.x, voxel.y, voxel.z, voxel.s, | ||
| 1639 | voxel.red, voxel.green, voxel.blue, | ||
| 1640 | isDestructive); | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel) { | ||
| 1644 | return glm::vec3((mouseVoxel.x + mouseVoxel.s / 2.0f) * TREE_SCALE, (mouseVoxel.y + mouseVoxel.s / 2.0f) * TREE_SCALE, | ||
| 1645 | (mouseVoxel.z + mouseVoxel.s / 2.0f) * TREE_SCALE); | ||
| 1646 | } | ||
| 1647 | |||
| 1648 | bool Application::mouseOnScreen() const { | 1552 | bool Application::mouseOnScreen() const { |
| 1649 | if (OculusManager::isConnected()) { | 1553 | if (OculusManager::isConnected()) { |
| 1650 | GLCanvas::SharedPointer glCanvas = DependencyManager::get<GLCanvas>(); | 1554 | GLCanvas::SharedPointer glCanvas = DependencyManager::get<GLCanvas>(); |
| @@ -1728,88 +1632,6 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa · 77 unmodified lines | |||
| 1728 | return true; | 1632 | return true; |
| 1729 | } | 1633 | } |
| 1730 | 1634 | ||
| 1731 | bool Application::sendVoxelsOperation(OctreeElement* element, void* extraData) { | ||
| 1732 | VoxelTreeElement* voxel = (VoxelTreeElement*)element; | ||
| 1733 | SendVoxelsOperationArgs* args = (SendVoxelsOperationArgs*)extraData; | ||
| 1734 | if (voxel->isColored()) { | ||
| 1735 | const unsigned char* nodeOctalCode = voxel->getOctalCode(); | ||
| 1736 | unsigned char* codeColorBuffer = NULL; | ||
| 1737 | int codeLength = 0; | ||
| 1738 | int bytesInCode = 0; | ||
| 1739 | int codeAndColorLength; | ||
| 1740 | |||
| 1741 | // If the newBase is NULL, then don't rebase | ||
| 1742 | if (args->newBaseOctCode) { | ||
| 1743 | codeColorBuffer = rebaseOctalCode(nodeOctalCode, args->newBaseOctCode, true); | ||
| 1744 | codeLength = numberOfThreeBitSectionsInCode(codeColorBuffer); | ||
| 1745 | bytesInCode = bytesRequiredForCodeLength(codeLength); | ||
| 1746 | codeAndColorLength = bytesInCode + SIZE_OF_COLOR_DATA; | ||
| 1747 | } else { | ||
| 1748 | codeLength = numberOfThreeBitSectionsInCode(nodeOctalCode); | ||
| 1749 | bytesInCode = bytesRequiredForCodeLength(codeLength); | ||
| 1750 | codeAndColorLength = bytesInCode + SIZE_OF_COLOR_DATA; | ||
| 1751 | codeColorBuffer = new unsigned char[codeAndColorLength]; | ||
| 1752 | memcpy(codeColorBuffer, nodeOctalCode, bytesInCode); | ||
| 1753 | } | ||
| 1754 | |||
| 1755 | // copy the colors over | ||
| 1756 | codeColorBuffer[bytesInCode + RED_INDEX] = voxel->getColor()[RED_INDEX]; | ||
| 1757 | codeColorBuffer[bytesInCode + GREEN_INDEX] = voxel->getColor()[GREEN_INDEX]; | ||
| 1758 | codeColorBuffer[bytesInCode + BLUE_INDEX] = voxel->getColor()[BLUE_INDEX]; | ||
| 1759 | getInstance()->_voxelEditSender.queueVoxelEditMessage(PacketTypeVoxelSetDestructive, | ||
| 1760 | codeColorBuffer, codeAndColorLength); | ||
| 1761 | |||
| 1762 | delete[] codeColorBuffer; | ||
| 1763 | } | ||
| 1764 | return true; // keep going | ||
| 1765 | } | ||
| 1766 | |||
| 1767 | void Application::exportVoxels(const VoxelDetail& sourceVoxel) { | ||
| 1768 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | ||
| 1769 | QString suggestedName = desktopLocation.append("/voxels.svo"); | ||
| 1770 | |||
| 1771 | QString fileNameString = QFileDialog::getSaveFileName(DependencyManager::get<GLCanvas>().data(), | ||
| 1772 | tr("Export Voxels"), suggestedName, | ||
| 1773 | tr("Sparse Voxel Octree Files (*.svo)")); | ||
| 1774 | QByteArray fileNameAscii = fileNameString.toLocal8Bit(); | ||
| 1775 | const char* fileName = fileNameAscii.data(); | ||
| 1776 | |||
| 1777 | VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); | ||
| 1778 | if (selectedNode) { | ||
| 1779 | VoxelTree exportTree; | ||
| 1780 | getVoxelTree()->copySubTreeIntoNewTree(selectedNode, &exportTree, true); | ||
| 1781 | exportTree.writeToSVOFile(fileName); | ||
| 1782 | } | ||
| 1783 | |||
| 1784 | // restore the main window's active state | ||
| 1785 | _window->activateWindow(); | ||
| 1786 | } | ||
| 1787 | |||
| 1788 | void Application::importVoxels() { | ||
| 1789 | _importSucceded = false; | ||
| 1790 | |||
| 1791 | if (!_voxelImportDialog) { | ||
| 1792 | _voxelImportDialog = new VoxelImportDialog(_window); | ||
| 1793 | _voxelImportDialog->loadSettings(_settings); | ||
| 1794 | } | ||
| 1795 | |||
| 1796 | if (!_voxelImportDialog->exec()) { | ||
| 1797 | qDebug() << "Import succeeded." << endl; | ||
| 1798 | _importSucceded = true; | ||
| 1799 | } else { | ||
| 1800 | qDebug() << "Import failed." << endl; | ||
| 1801 | if (_sharedVoxelSystem.getTree() == _voxelImporter.getVoxelTree()) { | ||
| 1802 | _sharedVoxelSystem.killLocalVoxels(); | ||
| 1803 | _sharedVoxelSystem.changeTree(&_clipboard); | ||
| 1804 | } | ||
| 1805 | } | ||
| 1806 | |||
| 1807 | // restore the main window's active state | ||
| 1808 | _window->activateWindow(); | ||
| 1809 | |||
| 1810 | emit importDone(); | ||
| 1811 | } | ||
| 1812 | |||
| 1813 | bool Application::importEntities(const QString& filename) { | 1635 | bool Application::importEntities(const QString& filename) { |
| 1814 | _entityClipboard.eraseAllOctreeElements(); | 1636 | _entityClipboard.eraseAllOctreeElements(); |
| 1815 | bool success = _entityClipboard.readFromSVOFile(filename.toLocal8Bit().constData()); | 1637 | bool success = _entityClipboard.readFromSVOFile(filename.toLocal8Bit().constData()); |
| @@ -1823,71 +1645,6 @@ void Application::pasteEntities(float x, float y, float z) { · 7 unmodified lines | |||
| 1823 | _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); | 1645 | _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); |
| 1824 | } | 1646 | } |
| 1825 | 1647 | ||
| 1826 | void Application::cutVoxels(const VoxelDetail& sourceVoxel) { | ||
| 1827 | copyVoxels(sourceVoxel); | ||
| 1828 | deleteVoxelAt(sourceVoxel); | ||
| 1829 | } | ||
| 1830 | |||
| 1831 | void Application::copyVoxels(const VoxelDetail& sourceVoxel) { | ||
| 1832 | // switch to and clear the clipboard first... | ||
| 1833 | _sharedVoxelSystem.killLocalVoxels(); | ||
| 1834 | if (_sharedVoxelSystem.getTree() != &_clipboard) { | ||
| 1835 | _clipboard.eraseAllOctreeElements(); | ||
| 1836 | _sharedVoxelSystem.changeTree(&_clipboard); | ||
| 1837 | } | ||
| 1838 | |||
| 1839 | // then copy onto it if there is something to copy | ||
| 1840 | VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); | ||
| 1841 | if (selectedNode) { | ||
| 1842 | getVoxelTree()->copySubTreeIntoNewTree(selectedNode, _sharedVoxelSystem.getTree(), true); | ||
| 1843 | _sharedVoxelSystem.forceRedrawEntireTree(); | ||
| 1844 | } | ||
| 1845 | } | ||
| 1846 | |||
| 1847 | void Application::pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination) { | ||
| 1848 | // Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to | ||
| 1849 | // the server as an set voxel message, this will also rebase the voxels to the new location | ||
| 1850 | SendVoxelsOperationArgs args; | ||
| 1851 | args.newBaseOctCode = octalCodeDestination; | ||
| 1852 | _sharedVoxelSystem.getTree()->recurseTreeWithOperation(sendVoxelsOperation, &args); | ||
| 1853 | |||
| 1854 | // Switch back to clipboard if it was an import | ||
| 1855 | if (_sharedVoxelSystem.getTree() != &_clipboard) { | ||
| 1856 | _sharedVoxelSystem.killLocalVoxels(); | ||
| 1857 | _sharedVoxelSystem.changeTree(&_clipboard); | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | _voxelEditSender.releaseQueuedMessages(); | ||
| 1861 | } | ||
| 1862 | |||
| 1863 | void Application::pasteVoxels(const VoxelDetail& sourceVoxel) { | ||
| 1864 | unsigned char* calculatedOctCode = NULL; | ||
| 1865 | VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); | ||
| 1866 | |||
| 1867 | // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the | ||
| 1868 | // voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a | ||
| 1869 | // target octalCode for where the user is pointing. | ||
| 1870 | const unsigned char* octalCodeDestination; | ||
| 1871 | if (selectedNode) { | ||
| 1872 | octalCodeDestination = selectedNode->getOctalCode(); | ||
| 1873 | } else { | ||
| 1874 | octalCodeDestination = calculatedOctCode = pointToVoxel(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); | ||
| 1875 | } | ||
| 1876 | |||
| 1877 | pasteVoxelsToOctalCode(octalCodeDestination); | ||
| 1878 | |||
| 1879 | if (calculatedOctCode) { | ||
| 1880 | delete[] calculatedOctCode; | ||
| 1881 | } | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | void Application::nudgeVoxelsByVector(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) { | ||
| 1885 | VoxelTreeElement* nodeToNudge = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); | ||
| 1886 | if (nodeToNudge) { | ||
| 1887 | _voxels.getTree()->nudgeSubTree(nodeToNudge, nudgeVec, _voxelEditSender); | ||
| 1888 | } | ||
| 1889 | } | ||
| 1890 | |||
| 1891 | void Application::initDisplay() { | 1648 | void Application::initDisplay() { |
| 1892 | glEnable(GL_BLEND); | 1649 | glEnable(GL_BLEND); |
| 1893 | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); | 1650 | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); |
| @@ -1898,23 +1655,6 @@ void Application::initDisplay() { · 4 unmodified lines | |||
| 1898 | } | 1655 | } |
| 1899 | 1656 | ||
| 1900 | void Application::init() { | 1657 | void Application::init() { |
| 1901 | _sharedVoxelSystemViewFrustum.setPosition(glm::vec3(TREE_SCALE / 2.0f, | ||
| 1902 | TREE_SCALE / 2.0f, | ||
| 1903 | 3.0f * TREE_SCALE / 2.0f)); | ||
| 1904 | _sharedVoxelSystemViewFrustum.setNearClip(TREE_SCALE / 2.0f); | ||
| 1905 | _sharedVoxelSystemViewFrustum.setFarClip(3.0f * TREE_SCALE / 2.0f); | ||
| 1906 | _sharedVoxelSystemViewFrustum.setFieldOfView(90.0f); | ||
| 1907 | _sharedVoxelSystemViewFrustum.setOrientation(glm::quat()); | ||
| 1908 | _sharedVoxelSystemViewFrustum.calculate(); | ||
| 1909 | _sharedVoxelSystem.setViewFrustum(&_sharedVoxelSystemViewFrustum); | ||
| 1910 | |||
| 1911 | VoxelTreeElement::removeUpdateHook(&_sharedVoxelSystem); | ||
| 1912 | |||
| 1913 | // Cleanup of the original shared tree | ||
| 1914 | _sharedVoxelSystem.init(); | ||
| 1915 | |||
| 1916 | _voxelImportDialog = new VoxelImportDialog(_window); | ||
| 1917 | |||
| 1918 | _environment.init(); | 1658 | _environment.init(); |
| 1919 | 1659 | ||
| 1920 | DependencyManager::get<DeferredLightingEffect>()->init(this); | 1660 | DependencyManager::get<DeferredLightingEffect>()->init(this); |
| @@ -1987,16 +1727,11 @@ void Application::init() { · 66 unmodified lines | |||
| 1987 | // fire off an immediate domain-server check in now that settings are loaded | 1727 | // fire off an immediate domain-server check in now that settings are loaded |
| 1988 | NodeList::getInstance()->sendDomainServerCheckIn(); | 1728 | NodeList::getInstance()->sendDomainServerCheckIn(); |
| 1989 | 1729 | ||
| 1990 | // Set up VoxelSystem after loading preferences so we can get the desired max voxel count | ||
| 1991 | _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels()); | ||
| 1992 | _voxels.setDisableFastVoxelPipeline(false); | ||
| 1993 | _voxels.init(); | ||
| 1994 | |||
| 1995 | _entities.init(); | 1730 | _entities.init(); |
| 1996 | _entities.setViewFrustum(getViewFrustum()); | 1731 | _entities.setViewFrustum(getViewFrustum()); |
| 1997 | 1732 | ||
| 1998 | EntityTree* entityTree = _entities.getTree(); | 1733 | EntityTree* entityTree = _entities.getTree(); |
| 1999 | _entityCollisionSystem.init(&_entityEditSender, entityTree, _voxels.getTree(), &_audio, &_avatarManager); | 1734 | _entityCollisionSystem.init(&_entityEditSender, entityTree, NULL, &_audio, &_avatarManager); |
| 2000 | entityTree->setSimulation(&_entityCollisionSystem); | 1735 | entityTree->setSimulation(&_entityCollisionSystem); |
| 2001 | 1736 | ||
| 2002 | // connect the _entityCollisionSystem to our script engine's EntityScriptingInterface | 1737 | // connect the _entityCollisionSystem to our script engine's EntityScriptingInterface |