mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 15:38:00 +02:00
first cut at export and import of voxels
This commit is contained in:
parent
7aebbe3047
commit
d1d2e75143
7 changed files with 68 additions and 8 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <PairingHandler.h>
|
#include <PairingHandler.h>
|
||||||
|
|
||||||
#include <AgentTypes.h>
|
#include <AgentTypes.h>
|
||||||
|
@ -853,7 +854,10 @@ void Application::idle() {
|
||||||
// red indicates deletion
|
// red indicates deletion
|
||||||
_mouseVoxel.red = 255;
|
_mouseVoxel.red = 255;
|
||||||
_mouseVoxel.green = _mouseVoxel.blue = 0;
|
_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()
|
} else { // _addVoxelMode->isChecked() || _colorVoxelMode->isChecked()
|
||||||
QColor paintColor = _voxelPaintColor->data().value<QColor>();
|
QColor paintColor = _voxelPaintColor->data().value<QColor>();
|
||||||
_mouseVoxel.red = paintColor.red();
|
_mouseVoxel.red = paintColor.red();
|
||||||
|
@ -1136,6 +1140,35 @@ void Application::chooseVoxelPaintColor() {
|
||||||
// restore the main window's active state
|
// restore the main window's active state
|
||||||
_window->activateWindow();
|
_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() {
|
void Application::initMenu() {
|
||||||
QMenuBar* menuBar = new QMenuBar();
|
QMenuBar* menuBar = new QMenuBar();
|
||||||
|
@ -1202,6 +1235,9 @@ void Application::initMenu() {
|
||||||
(_colorVoxelMode = voxelMenu->addAction(
|
(_colorVoxelMode = voxelMenu->addAction(
|
||||||
"Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_3))->setCheckable(true);
|
"Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_3))->setCheckable(true);
|
||||||
_voxelModeActions->addAction(_colorVoxelMode);
|
_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("Place Voxel", this, SLOT(addVoxelInFrontOfAvatar()), Qt::Key_4);
|
||||||
voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), Qt::Key_5);
|
voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), Qt::Key_5);
|
||||||
|
@ -1212,6 +1248,8 @@ void Application::initMenu() {
|
||||||
_voxelPaintColor->setData(paintColor);
|
_voxelPaintColor->setData(paintColor);
|
||||||
_voxelPaintColor->setIcon(createSwatchIcon(paintColor));
|
_voxelPaintColor->setIcon(createSwatchIcon(paintColor));
|
||||||
(_destructiveAddVoxel = voxelMenu->addAction("Create Voxel is Destructive"))->setCheckable(true);
|
(_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");
|
QMenu* frustumMenu = menuBar->addMenu("Frustum");
|
||||||
(_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
|
(_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
|
||||||
|
|
|
@ -99,7 +99,9 @@ private slots:
|
||||||
void decreaseVoxelSize();
|
void decreaseVoxelSize();
|
||||||
void increaseVoxelSize();
|
void increaseVoxelSize();
|
||||||
void chooseVoxelPaintColor();
|
void chooseVoxelPaintColor();
|
||||||
|
void exportVoxels();
|
||||||
|
void importVoxels();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initMenu();
|
void initMenu();
|
||||||
|
@ -155,6 +157,7 @@ private:
|
||||||
QAction* _addVoxelMode; // Whether add voxel mode is enabled
|
QAction* _addVoxelMode; // Whether add voxel mode is enabled
|
||||||
QAction* _deleteVoxelMode; // Whether delete voxel mode is enabled
|
QAction* _deleteVoxelMode; // Whether delete voxel mode is enabled
|
||||||
QAction* _colorVoxelMode; // Whether color 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* _voxelPaintColor; // The color with which to paint voxels
|
||||||
QAction* _destructiveAddVoxel; // when doing voxel editing do we want them to be destructive
|
QAction* _destructiveAddVoxel; // when doing voxel editing do we want them to be destructive
|
||||||
QAction* _frustumOn; // Whether or not to display the debug view frustum
|
QAction* _frustumOn; // Whether or not to display the debug view frustum
|
||||||
|
|
|
@ -70,6 +70,18 @@ void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer)
|
||||||
setupNewVoxelsForDrawing();
|
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() {
|
long int VoxelSystem::getVoxelsCreated() {
|
||||||
return _tree->voxelsCreated;
|
return _tree->voxelsCreated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
void setViewerAvatar(Avatar *newViewerAvatar) { _viewerAvatar = newViewerAvatar; };
|
void setViewerAvatar(Avatar *newViewerAvatar) { _viewerAvatar = newViewerAvatar; };
|
||||||
void setCamera(Camera* newCamera) { _camera = newCamera; };
|
void setCamera(Camera* newCamera) { _camera = newCamera; };
|
||||||
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
|
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 getVoxelsCreated();
|
||||||
long int getVoxelsColored();
|
long int getVoxelsColored();
|
||||||
|
|
|
@ -1105,7 +1105,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
|
||||||
return bytesAtThisLevel;
|
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);
|
std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
|
||||||
if(file.is_open()) {
|
if(file.is_open()) {
|
||||||
printLog("loading file %s...\n", fileName);
|
printLog("loading file %s...\n", fileName);
|
||||||
|
@ -1126,7 +1126,7 @@ bool VoxelTree::readFromFileV2(const char* fileName) {
|
||||||
return false;
|
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);
|
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);
|
printLog("saving to file %s...\n", fileName);
|
||||||
|
|
||||||
VoxelNodeBag nodeBag;
|
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
|
static unsigned char outputBuffer[MAX_VOXEL_PACKET_SIZE - 1]; // save on allocs by making this static
|
||||||
int bytesWritten = 0;
|
int bytesWritten = 0;
|
||||||
|
|
|
@ -91,8 +91,8 @@ public:
|
||||||
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);
|
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);
|
||||||
|
|
||||||
// these will read/write files that match the wireformat, excluding the 'V' leading
|
// these will read/write files that match the wireformat, excluding the 'V' leading
|
||||||
void writeToFileV2(const char* filename) const;
|
void writeToFileV2(const char* filename, VoxelNode* node = NULL) const;
|
||||||
bool readFromFileV2(const char* filename);
|
bool readFromFileV2(const char* filename, VoxelNode* node = NULL);
|
||||||
|
|
||||||
unsigned long getVoxelCount();
|
unsigned long getVoxelCount();
|
||||||
|
|
||||||
|
|
|
@ -517,7 +517,7 @@ int main(int argc, const char * argv[]) {
|
||||||
const char* INPUT_FILE = "-i";
|
const char* INPUT_FILE = "-i";
|
||||||
const char* voxelsFilename = getCmdOption(argc, argv, INPUT_FILE);
|
const char* voxelsFilename = getCmdOption(argc, argv, INPUT_FILE);
|
||||||
if (voxelsFilename) {
|
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
|
// Check to see if the user passed in a command line option for setting packet send rate
|
||||||
|
|
Loading…
Reference in a new issue