first cut at export and import of voxels

This commit is contained in:
ZappoMan 2013-05-28 19:00:02 -07:00
parent 7aebbe3047
commit d1d2e75143
7 changed files with 68 additions and 8 deletions

View file

@ -32,6 +32,7 @@
#include <QShortcut>
#include <QTimer>
#include <QtDebug>
#include <QFileDialog>
#include <PairingHandler.h>
#include <AgentTypes.h>
@ -853,7 +854,10 @@ void Application::idle() {
// red indicates deletion
_mouseVoxel.red = 255;
_mouseVoxel.green = _mouseVoxel.blue = 0;
} else if (_selectVoxelMode->isChecked()) {
// yellow indicates deletion
_mouseVoxel.red = _mouseVoxel.green = 255;
_mouseVoxel.blue = 0;
} else { // _addVoxelMode->isChecked() || _colorVoxelMode->isChecked()
QColor paintColor = _voxelPaintColor->data().value<QColor>();
_mouseVoxel.red = paintColor.red();
@ -1136,6 +1140,35 @@ void Application::chooseVoxelPaintColor() {
// restore the main window's active state
_window->activateWindow();
}
void Application::exportVoxels() {
QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), "~/voxels.hio2",
tr("High Fidelity Voxel Files (*.hio2)"));
QByteArray fileNameAscii = fileNameString.toAscii();
const char* fileName = fileNameAscii.data();
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
printf("exportVoxels() fileName: %s _mouseVoxel: %f,%f,%f-%f \n", fileName,
_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
if (selectedNode) {
selectedNode->printDebugDetails("selected voxel");
}
_voxels.writeToFileV2(fileName,selectedNode);
}
void Application::importVoxels() {
QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), "~", tr("High Fidelity Voxel Files (*.hio2)"));
QByteArray fileNameAscii = fileNameString.toAscii();
const char* fileName = fileNameAscii.data();
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
printf("importVoxels() fileName: %s _mouseVoxel: %f,%f,%f-%f \n", fileName,
_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
if (selectedNode) {
selectedNode->printDebugDetails("selected voxel");
}
// not yet supported!!!
_voxels.readFromFileV2(fileName,selectedNode);
}
void Application::initMenu() {
QMenuBar* menuBar = new QMenuBar();
@ -1202,6 +1235,9 @@ void Application::initMenu() {
(_colorVoxelMode = voxelMenu->addAction(
"Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_3))->setCheckable(true);
_voxelModeActions->addAction(_colorVoxelMode);
(_selectVoxelMode = voxelMenu->addAction(
"Select Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_8))->setCheckable(true);
_voxelModeActions->addAction(_selectVoxelMode);
voxelMenu->addAction("Place Voxel", this, SLOT(addVoxelInFrontOfAvatar()), Qt::Key_4);
voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), Qt::Key_5);
@ -1212,6 +1248,8 @@ void Application::initMenu() {
_voxelPaintColor->setData(paintColor);
_voxelPaintColor->setIcon(createSwatchIcon(paintColor));
(_destructiveAddVoxel = voxelMenu->addAction("Create Voxel is Destructive"))->setCheckable(true);
voxelMenu->addAction("Export Voxels", this, SLOT(exportVoxels()), Qt::CTRL | Qt::Key_E);
voxelMenu->addAction("Import Voxels", this, SLOT(importVoxels()), Qt::CTRL | Qt::Key_I);
QMenu* frustumMenu = menuBar->addMenu("Frustum");
(_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);

View file

@ -99,7 +99,9 @@ private slots:
void decreaseVoxelSize();
void increaseVoxelSize();
void chooseVoxelPaintColor();
void exportVoxels();
void importVoxels();
private:
void initMenu();
@ -155,6 +157,7 @@ private:
QAction* _addVoxelMode; // Whether add voxel mode is enabled
QAction* _deleteVoxelMode; // Whether delete voxel mode is enabled
QAction* _colorVoxelMode; // Whether color voxel mode is enabled
QAction* _selectVoxelMode; // Whether select voxel mode is enabled
QAction* _voxelPaintColor; // The color with which to paint voxels
QAction* _destructiveAddVoxel; // when doing voxel editing do we want them to be destructive
QAction* _frustumOn; // Whether or not to display the debug view frustum

View file

@ -70,6 +70,18 @@ void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer)
setupNewVoxelsForDrawing();
}
void VoxelSystem::writeToFileV2(const char* filename, VoxelNode* node) const {
_tree->writeToFileV2(filename, node);
}
bool VoxelSystem::readFromFileV2(const char* filename, VoxelNode* node) {
bool result = _tree->readFromFileV2(filename, node);
if (result) {
setupNewVoxelsForDrawing();
}
return result;
}
long int VoxelSystem::getVoxelsCreated() {
return _tree->voxelsCreated;
}

View file

@ -44,6 +44,8 @@ public:
void setViewerAvatar(Avatar *newViewerAvatar) { _viewerAvatar = newViewerAvatar; };
void setCamera(Camera* newCamera) { _camera = newCamera; };
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
void writeToFileV2(const char* filename, VoxelNode* node) const;
bool readFromFileV2(const char* filename, VoxelNode* node);
long int getVoxelsCreated();
long int getVoxelsColored();

View file

@ -1105,7 +1105,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
return bytesAtThisLevel;
}
bool VoxelTree::readFromFileV2(const char* fileName) {
bool VoxelTree::readFromFileV2(const char* fileName, VoxelNode* node) {
std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
if(file.is_open()) {
printLog("loading file %s...\n", fileName);
@ -1126,7 +1126,7 @@ bool VoxelTree::readFromFileV2(const char* fileName) {
return false;
}
void VoxelTree::writeToFileV2(const char* fileName) const {
void VoxelTree::writeToFileV2(const char* fileName, VoxelNode* node) const {
std::ofstream file(fileName, std::ios::out|std::ios::binary);
@ -1134,7 +1134,12 @@ void VoxelTree::writeToFileV2(const char* fileName) const {
printLog("saving to file %s...\n", fileName);
VoxelNodeBag nodeBag;
nodeBag.insert(rootNode);
// If we were given a specific node, start from there, otherwise start from root
if (node) {
nodeBag.insert(node);
} else {
nodeBag.insert(rootNode);
}
static unsigned char outputBuffer[MAX_VOXEL_PACKET_SIZE - 1]; // save on allocs by making this static
int bytesWritten = 0;

View file

@ -91,8 +91,8 @@ public:
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);
// these will read/write files that match the wireformat, excluding the 'V' leading
void writeToFileV2(const char* filename) const;
bool readFromFileV2(const char* filename);
void writeToFileV2(const char* filename, VoxelNode* node = NULL) const;
bool readFromFileV2(const char* filename, VoxelNode* node = NULL);
unsigned long getVoxelCount();

View file

@ -517,7 +517,7 @@ int main(int argc, const char * argv[]) {
const char* INPUT_FILE = "-i";
const char* voxelsFilename = getCmdOption(argc, argv, INPUT_FILE);
if (voxelsFilename) {
randomTree.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
randomTree.readFromFileV2(voxelsFilename);
}
// Check to see if the user passed in a command line option for setting packet send rate