From a39a7e23564fe3b380b9ae493aa1d4b757d09e1c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 31 Jul 2014 01:13:17 -0700 Subject: [PATCH] Update exportModels implementation --- interface/src/Application.cpp | 22 +++++++++++++++++----- interface/src/Application.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e85d44a901..e469cc7535 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1506,19 +1506,31 @@ struct SendVoxelsOperationArgs { const unsigned char* newBaseOctCode; }; -void Application::exportModels(const QString& filename, float x, float y, float z, float scale) { - ModelTreeElement* selectedNode = _models.getTree()->getModelAt(x, y, z, scale); - if (selectedNode) { - qDebug() << "Exporting models doing it!" << filename; +bool Application::exportModels(const QString& filename, float x, float y, float z, float scale) { + QVector models; + _models.getTree()->findModelsInCube(AACube(glm::vec3(x / (float)TREE_SCALE, y / (float)TREE_SCALE, z / (float)TREE_SCALE), scale / (float)TREE_SCALE), models); + if (models.size() > 0) { + glm::vec3 root(x, y, z); ModelTree exportTree; - _models.getTree()->copySubTreeIntoNewTree(selectedNode, &exportTree, true); + + for (int i = 0; i < models.size(); i++) { + ModelItemProperties properties; + ModelItemID id = models.at(i)->getModelItemID(); + id.isKnownID = false; + properties.copyFromModelItem(*models.at(i)); + properties.setPosition(properties.getPosition() - root); + exportTree.addModel(id, properties); + } + exportTree.writeToSVOFile(filename.toLocal8Bit().constData()); } else { qDebug() << "No models were selected"; + return false; } // restore the main window's active state _window->activateWindow(); + return true; } bool Application::sendVoxelsOperation(OctreeElement* element, void* extraData) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 756cb7dff7..44a93f5d7b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -316,7 +316,7 @@ public slots: void packetSent(quint64 length); void pasteModels(float x, float y, float z); - void exportModels(const QString& filename, float x, float y, float z, float scale); + bool exportModels(const QString& filename, float x, float y, float z, float scale); void importModels(const QString& filename); void importVoxels(); // doesn't include source voxel because it goes to clipboard