Added LOD to preview + Shared voxelSystem for reduced memory consumption

This commit is contained in:
atlante45 2013-08-29 17:59:36 -07:00
parent 7d9d36a66e
commit 1dc8d8dd0c
10 changed files with 227 additions and 104 deletions

View file

@ -82,7 +82,7 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
// Startup optimistically with small jitter buffer that
// will start playback on the second received audio packet.
static const float CLIPBOARD_TREE_SCALE = 1.0f;
static const float SHARED_VOXEL_SYSTEM_TREE_SCALE = 1.0f;
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
fprintf(stdout, "%s", message.toLocal8Bit().constData());
@ -97,7 +97,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_frameCount(0),
_fps(120.0f),
_justStarted(true),
_clipboard(CLIPBOARD_TREE_SCALE),
_voxelImporter(_window),
_wantToKillLocalVoxels(false),
_audioScope(256, 200, true),
@ -1207,15 +1206,6 @@ void Application::exportVoxels() {
void Application::importVoxels() {
if (_voxelImporter.exec()) {
qDebug("[DEBUG] Import succedded.\n");
if (_voxelImporter.getImportIntoClipboard()) {
_clipboard.killLocalVoxels();
_voxelImporter.getVoxelSystem()->copySubTreeIntoNewTree(
_voxelImporter.getVoxelSystem()->getVoxelAt(0, 0, 0, 1),
&_clipboard,
true);
_voxelImporter.reset();
}
} else {
qDebug("[DEBUG] Import failed.\n");
}
@ -1230,13 +1220,17 @@ void Application::cutVoxels() {
}
void Application::copyVoxels() {
// switch to and clear the clipboard first...
_sharedVoxelSystem.killLocalVoxels();
if (_sharedVoxelSystem.getTree() != &_clipboard) {
_clipboard.eraseAllVoxels();
_sharedVoxelSystem.changeTree(&_clipboard);
}
// then copy onto it if there is something to copy
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
if (selectedNode) {
// clear the clipboard first...
_clipboard.killLocalVoxels();
// then copy onto it
_voxels.copySubTreeIntoNewTree(selectedNode, &_clipboard, true);
_voxels.copySubTreeIntoNewTree(selectedNode, &_sharedVoxelSystem, true);
}
}
@ -1257,12 +1251,13 @@ void Application::pasteVoxels() {
args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
}
if (_voxelImporter.getImportWaiting()) {
_voxelImporter.getVoxelSystem()->recurseTreeWithOperation(sendVoxelsOperation, &args);
_voxelImporter.reset();
} else {
_clipboard.recurseTreeWithOperation(sendVoxelsOperation, &args);
_sharedVoxelSystem.getTree()->recurseTreeWithOperation(sendVoxelsOperation, &args);
if (_sharedVoxelSystem.getTree() != &_clipboard) {
_sharedVoxelSystem.killLocalVoxels();
_sharedVoxelSystem.changeTree(&_clipboard);
}
_voxelEditSender.flushQueue();
if (calculatedOctCode) {
@ -1304,10 +1299,21 @@ void Application::initDisplay() {
void Application::init() {
_voxels.init();
_clipboard.init();
_clipboardViewFrustum.setKeyholeRadius(1000.0f);
_clipboardViewFrustum.calculate();
_clipboard.setViewFrustum(&_clipboardViewFrustum);
_sharedVoxelSystemViewFrustum.setPosition(glm::vec3(TREE_SCALE / 2.0f,
TREE_SCALE / 2.0f,
3.0f * TREE_SCALE / 2.0f));
_sharedVoxelSystemViewFrustum.setNearClip(TREE_SCALE / 2.0f);
_sharedVoxelSystemViewFrustum.setFarClip(3.0f * TREE_SCALE / 2.0f);
_sharedVoxelSystemViewFrustum.setFieldOfView(90);
_sharedVoxelSystemViewFrustum.setOrientation(glm::quat());
_sharedVoxelSystemViewFrustum.calculate();
_sharedVoxelSystem.setViewFrustum(&_sharedVoxelSystemViewFrustum);
_sharedVoxelSystem.init();
VoxelTree* tmpTree = _sharedVoxelSystem.getTree();
_sharedVoxelSystem.changeTree(&_clipboard);
delete tmpTree;
_voxelImporter.init();
_environment.init();
@ -1318,6 +1324,7 @@ void Application::init() {
_headMouseX = _mouseX = _glWidget->width() / 2;
_headMouseY = _mouseY = _glWidget->height() / 2;
QCursor::setPos(_headMouseX, _headMouseY);
_myAvatar.init();
_myAvatar.setPosition(START_LOCATION);
@ -1325,7 +1332,6 @@ void Application::init() {
_myCamera.setModeShiftRate(1.0f);
_myAvatar.setDisplayingLookatVectors(false);
QCursor::setPos(_headMouseX, _headMouseY);
OculusManager::connect();
if (OculusManager::isConnected()) {
@ -2225,15 +2231,11 @@ void Application::displaySide(Camera& whichCamera) {
glTranslatef(_mouseVoxel.x * TREE_SCALE,
_mouseVoxel.y * TREE_SCALE,
_mouseVoxel.z * TREE_SCALE);
glScalef(_mouseVoxel.s * TREE_SCALE,
_mouseVoxel.s * TREE_SCALE,
_mouseVoxel.s * TREE_SCALE);
glScalef(_mouseVoxel.s,
_mouseVoxel.s,
_mouseVoxel.s);
if (_voxelImporter.getImportWaiting()) {
_voxelImporter.getVoxelSystem()->render(true);
} else {
_clipboard.render(true);
}
_sharedVoxelSystem.render(true);
glPopMatrix();
}

View file

@ -112,6 +112,8 @@ public:
Camera* getCamera() { return &_myCamera; }
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
VoxelSystem* getVoxels() { return &_voxels; }
VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; }
VoxelTree* getClipboard() { return &_clipboard; }
Environment* getEnvironment() { return &_environment; }
SerialInterface* getSerialHeadSensor() { return &_serialHeadSensor; }
Webcam* getWebcam() { return &_webcam; }
@ -238,10 +240,11 @@ private:
Stars _stars;
VoxelSystem _voxels;
VoxelSystem _clipboard; // if I copy/paste
ViewFrustum _clipboardViewFrustum;
VoxelSystem _voxels;
VoxelTree _clipboard; // if I copy/paste
VoxelImporter _voxelImporter;
VoxelSystem _sharedVoxelSystem;
ViewFrustum _sharedVoxelSystemViewFrustum;
QByteArray _voxelsFilename;
bool _wantToKillLocalVoxels;

View file

@ -34,9 +34,9 @@ const float FIELD_OF_VIEW = 60.0f;
class GLWidget : public QGLWidget {
public:
GLWidget(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL);
GLWidget(QWidget* parent = NULL);
void setDraw(bool draw) {_draw = draw;}
void setTargetCenter(glm::vec3 targetCenter) {_targetCenter = targetCenter;}
void setTargetCenter(glm::vec3 targetCenter) { _targetCenter = targetCenter; }
protected:
virtual void initializeGL();
@ -61,9 +61,8 @@ private:
int _mouseY;
};
GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)
GLWidget::GLWidget(QWidget *parent)
: QGLWidget(parent, Application::getInstance()->getGLWidget()),
_voxelSystem(voxelSystem),
_draw(false),
_a(0.0f),
_h(VERTICAL_ANGLE),
@ -71,6 +70,7 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)
_pressed(false),
_mouseX(0),
_mouseY(0) {
_voxelSystem = Application::getInstance()->getSharedVoxelSystem();
}
void GLWidget::initializeGL() {
@ -110,7 +110,7 @@ void GLWidget::paintGL() {
UP_VECT.x, UP_VECT.y, UP_VECT.z);
if (_draw && _voxelSystem) {
if (_draw) {
glBegin(GL_LINES);
glColor3d(1, 1 ,1);
glVertex3d(0, 0, 0);
@ -134,11 +134,109 @@ void GLWidget::paintGL() {
glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 );
glEnd();
glScalef(1.0f / TREE_SCALE, 1.0f / TREE_SCALE, 1.0f / TREE_SCALE);
_voxelSystem->render(false);
ViewFrustum& viewFrustum = *Application::getInstance()->getSharedVoxelSystem()->getViewFrustum();
glm::vec3 position = viewFrustum.getOffsetPosition();
glm::vec3 direction = viewFrustum.getOffsetDirection();
glm::vec3 up = viewFrustum.getOffsetUp();
glm::vec3 right = viewFrustum.getOffsetRight();
// Calculate the origin direction vectors
glm::vec3 lookingAt = position + (direction * 0.2f);
glm::vec3 lookingAtUp = position + (up * 0.2f);
glm::vec3 lookingAtRight = position + (right * 0.2f);
glBegin(GL_LINES);
// Looking At = white
glColor3d(1.0f, 1.0f, 1.0f);
glVertex3d(position.x, position.y, position.z);
glVertex3d(lookingAt.x, lookingAt.y, lookingAt.z);
// Looking At Up = purple
glColor3d(1.0f, 0.0f, 1.0f);
glVertex3d(position.x, position.y, position.z);
glVertex3d(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z);
// Looking At Right = cyan
glColor3d(0.0f, 1.0f, 1.0f);
glVertex3d(position.x, position.y, position.z);
glVertex3d(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z);
// Drawing the bounds of the frustum
// viewFrustum.getNear plane - bottom edge
glColor3d(1.0f, 0.0f, 0.0f);
glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
// viewFrustum.getNear plane - top edge
glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
// viewFrustum.getNear plane - right edge
glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
// viewFrustum.getNear plane - left edge
glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
// viewFrustum.getFar plane - bottom edge
glColor3d(0.0f, 1.0f, 0.0f); // GREEN!!!
glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
// viewFrustum.getFar plane - top edge
glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
// viewFrustum.getFar plane - right edge
glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
// viewFrustum.getFar plane - left edge
glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
// RIGHT PLANE IS CYAN
// right plane - bottom edge - viewFrustum.getNear to distant
glColor3d(0.0f, 1.0f, 1.0f);
glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
// right plane - top edge - viewFrustum.getNear to distant
glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
// LEFT PLANE IS BLUE
// left plane - bottom edge - viewFrustum.getNear to distant
glColor3d(0.0f, 0.0f, 1.0f);
glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
// left plane - top edge - viewFrustum.getNear to distant
glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
glEnd();
// Draw the keyhole
float keyholeRadius = viewFrustum.getKeyholeRadius();
if (keyholeRadius > 0.0f) {
glPushMatrix();
glColor3d(1.0f, 1.0f, 0.0f);
glTranslatef(position.x, position.y, position.z); // where we actually want it!
glutWireSphere(keyholeRadius, 20, 20);
glPopMatrix();
}
}
}
void GLWidget::mousePressEvent(QMouseEvent* event) {
_pressed = true;
_mouseX = event->globalX();
@ -158,14 +256,13 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event) {
_pressed = false;
}
ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)
ImportDialog::ImportDialog(QWidget *parent)
: QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),
_importButton (IMPORT_BUTTON_NAME, this),
_clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),
_previewBox (PREVIEW_CHECKBOX_STRING, this),
_previewBar (this),
_glPreview (new GLWidget(this, voxelSystem)) {
_glPreview (new GLWidget(this)) {
setOption(QFileDialog::DontUseNativeDialog, true);
setFileMode(QFileDialog::ExistingFile);
setViewMode(QFileDialog::Detail);
@ -188,15 +285,18 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
connect(&_glTimer, SIGNAL(timeout()), SLOT(timer()));
connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
}
ImportDialog::~ImportDialog() {
delete _glPreview;
}
void ImportDialog::init() {
VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
}
void ImportDialog::import() {
_importButton.setDisabled(true);
_clipboardImportBox.setDisabled(true);

View file

@ -23,15 +23,16 @@ class GLWidget;
class ImportDialog : public QFileDialog {
Q_OBJECT
public:
ImportDialog(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL);
ImportDialog(QWidget* parent = NULL);
~ImportDialog();
void init();
void reset();
bool getWantPreview() const { return _previewBox.isChecked(); }
QString getCurrentFile() const { return _currentFile; }
bool getImportIntoClipboard() const { return _clipboardImportBox.isChecked(); }
void reset();
signals:
void previewToggled(bool);
void accepted();

View file

@ -7,29 +7,24 @@
//
#include <VoxelImporter.h>
#include <Application.h>
#include <QFileInfo>
#include <QThreadPool>
static const int IMPORT_SYSTEM_SCALE = 1.0f;
static const int MAX_VOXELS_PER_IMPORT = 2000000;
class ImportTask : public QObject, public QRunnable {
public:
ImportTask(VoxelSystem* voxelSystem, const QString &filename);
ImportTask(const QString &filename);
void run();
private:
VoxelSystem* _voxelSystem;
QString _filename;
QString _filename;
};
VoxelImporter::VoxelImporter(QWidget* parent)
: QObject(parent),
_voxelSystem(IMPORT_SYSTEM_SCALE, MAX_VOXELS_PER_IMPORT),
_initialized(false),
_importWaiting(false),
_importDialog(parent, &_voxelSystem),
_voxelTree(true),
_importDialog(parent),
_currentTask(NULL),
_nextTask(NULL) {
@ -38,6 +33,10 @@ VoxelImporter::VoxelImporter(QWidget* parent)
connect(&_importDialog, SIGNAL(accepted()), SLOT(import()));
}
void VoxelImporter::init() {
_importDialog.init();
}
VoxelImporter::~VoxelImporter() {
if (_nextTask) {
delete _nextTask;
@ -46,16 +45,15 @@ VoxelImporter::~VoxelImporter() {
if (_currentTask) {
disconnect(_currentTask, 0, 0, 0);
_voxelSystem.cancelImport();
_voxelTree.cancelImport();
_currentTask = NULL;
}
}
void VoxelImporter::reset() {
_voxelSystem.killLocalVoxels();
_voxelTree.eraseAllVoxels();
_importDialog.reset();
_filename = "";
_importWaiting = false;
if (_nextTask) {
delete _nextTask;
@ -63,17 +61,11 @@ void VoxelImporter::reset() {
}
if (_currentTask) {
_voxelSystem.cancelImport();
_voxelTree.cancelImport();
}
}
int VoxelImporter::exec() {
if (!_initialized) {
_voxelSystem.init();
_importViewFrustum.calculate();
_voxelSystem.setViewFrustum(&_importViewFrustum);
_initialized = true;
}
reset();
int ret = _importDialog.exec();
@ -82,7 +74,15 @@ int VoxelImporter::exec() {
reset();
} else {
_importDialog.reset();
_importWaiting = true;
if (_importDialog.getImportIntoClipboard()) {
VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
voxelSystem->copySubTreeIntoNewTree(voxelSystem->getTree()->rootNode,
Application::getInstance()->getClipboard(),
true);
voxelSystem->changeTree(Application::getInstance()->getClipboard());
}
}
return ret;
@ -102,11 +102,11 @@ int VoxelImporter::preImport() {
delete _nextTask;
}
_nextTask = new ImportTask(&_voxelSystem, _filename);
_nextTask = new ImportTask(_filename);
connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask()));
if (_currentTask != NULL) {
_voxelSystem.cancelImport();
_voxelTree.cancelImport();
} else {
launchTask();
}
@ -138,12 +138,12 @@ int VoxelImporter::import() {
delete _nextTask;
}
_nextTask = new ImportTask(&_voxelSystem, _filename);
_nextTask = new ImportTask(_filename);
connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask()));
connect(_nextTask, SIGNAL(destroyed()), &_importDialog, SLOT(accept()));
if (_currentTask != NULL) {
_voxelSystem.cancelImport();
_voxelTree.cancelImport();
} else {
launchTask();
}
@ -153,28 +153,36 @@ int VoxelImporter::import() {
void VoxelImporter::launchTask() {
if (_nextTask != NULL) {
_voxelSystem.killLocalVoxels();
_currentTask = _nextTask;
_nextTask = NULL;
if (Application::getInstance()->getSharedVoxelSystem()->getTree() != &_voxelTree) {
Application::getInstance()->getSharedVoxelSystem()->changeTree(&_voxelTree);
}
QThreadPool::globalInstance()->start(_currentTask);
} else {
_currentTask = NULL;
}
}
ImportTask::ImportTask(VoxelSystem* voxelSystem, const QString &filename)
: _voxelSystem(voxelSystem),
_filename(filename) {
ImportTask::ImportTask(const QString &filename)
: _filename(filename) {
}
void ImportTask::run() {
VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
voxelSystem->killLocalVoxels();
if (_filename.endsWith(".png", Qt::CaseInsensitive)) {
_voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data());
voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data());
} else if (_filename.endsWith(".svo", Qt::CaseInsensitive)) {
_voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data());
voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data());
} else if (_filename.endsWith(".schematic", Qt::CaseInsensitive)) {
_voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data());
voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data());
} else {
qDebug("[ERROR] Invalid file extension.\n");
}
voxelSystem->getTree()->reaverageVoxelColors(voxelSystem->getTree()->rootNode);
}

View file

@ -22,11 +22,11 @@ class VoxelImporter : public QObject {
public:
VoxelImporter(QWidget* parent = NULL);
~VoxelImporter();
void init();
void reset();
bool getImportWaiting() const { return _importWaiting; }
VoxelSystem* getVoxelSystem() { return &_voxelSystem; }
bool getImportIntoClipboard() const { return _importDialog.getImportIntoClipboard(); }
VoxelTree* getVoxelTree() { return &_voxelTree; }
public slots:
int exec();
@ -37,14 +37,10 @@ private slots:
void launchTask();
private:
VoxelSystem _voxelSystem;
ViewFrustum _importViewFrustum;
bool _initialized;
bool _importWaiting;
VoxelTree _voxelTree;
ImportDialog _importDialog;
QString _filename;
QString _filename;
ImportTask* _currentTask;
ImportTask* _nextTask;

View file

@ -420,7 +420,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
bool shouldRender = false; // assume we don't need to render it
// if it's colored, we might need to render it!
shouldRender = node->calculateShouldRender(_viewFrustum);
node->setShouldRender(shouldRender);
// let children figure out their renderness
if (!node->isLeaf()) {
@ -631,6 +631,18 @@ void VoxelSystem::init() {
_perlinModulateProgram->release();
}
void VoxelSystem::changeTree(VoxelTree* newTree) {
disconnect(_tree, 0, this, 0);
_tree = newTree;
_tree->setDirtyBit();
connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float)));
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
setupNewVoxelsForDrawing();
}
void VoxelSystem::updateFullVBOs() {
updateVBOSegment(0, _voxelsInReadArrays);

View file

@ -43,6 +43,8 @@ public:
void simulate(float deltaTime) { };
void render(bool texture);
void changeTree(VoxelTree* newTree);
VoxelTree* getTree() const {return _tree;}
ViewFrustum* getViewFrustum() const {return _viewFrustum;}
void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;}
unsigned long getVoxelsUpdated() const {return _voxelsUpdated;};
@ -93,6 +95,7 @@ public:
virtual void nodeDeleted(VoxelNode* node);
virtual void nodeAdded(Node* node);
virtual void nodeKilled(Node* node);
void setupNewVoxelsForDrawing();
signals:
void importSize(float x, float y, float z);
@ -120,8 +123,7 @@ protected:
VoxelTree* _tree;
glm::vec3 computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const;
void setupNewVoxelsForDrawing();
virtual void updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& startVertex,
float voxelScale, const nodeColor& color);

View file

@ -423,6 +423,7 @@ void ViewFrustum::printDebugDetails() const {
qDebug("_right=%f,%f,%f\n", _right.x, _right.y, _right.z );
qDebug("_fieldOfView=%f\n", _fieldOfView);
qDebug("_aspectRatio=%f\n", _aspectRatio);
qDebug("_keyHoleRadius=%f\n", _keyholeRadius);
qDebug("_nearClip=%f\n", _nearClip);
qDebug("_farClip=%f\n", _farClip);
qDebug("_eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z );

View file

@ -1581,7 +1581,6 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
bool VoxelTree::readFromSVOFile(const char* fileName) {
std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
if(file.is_open()) {
emit importSize(1.0f, 1.0f, 1.0f);
emit importProgress(0);
@ -1607,9 +1606,7 @@ bool VoxelTree::readFromSVOFile(const char* fileName) {
}
bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) {
emit importSize(1.0f, 1.0f, 1.0f);
emit importProgress(0);
int minAlpha = INT_MAX;
QImage pngImage = QImage(filename);
@ -1624,6 +1621,8 @@ bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) {
while (maxSize > scale) {scale *= 2;}
float size = 1.0f / scale;
emit importSize(size * pngImage.width(), 1.0f, size * pngImage.height());
QRgb pixel;
int minNeighborhoodAlpha;
@ -1692,14 +1691,13 @@ bool VoxelTree::readFromSchematicFile(const char *fileName) {
while (max > scale) {scale *= 2;}
float size = 1.0f / scale;
int create = 1;
int red = 128, green = 128, blue = 128;
int count = 0;
emit importSize(size * schematics.getWidth(),
size * schematics.getHeight(),
size * schematics.getLength());
emit importProgress(0);
int create = 1;
int red = 128, green = 128, blue = 128;
int count = 0;
for (int y = 0; y < schematics.getHeight(); ++y) {
for (int z = 0; z < schematics.getLength(); ++z) {