diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e80665b0f7..51766fbafc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -82,7 +82,6 @@ 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; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { fprintf(stdout, "%s", message.toLocal8Bit().constData()); @@ -97,7 +96,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), @@ -238,6 +236,8 @@ Application::~Application() { NodeList::getInstance()->removeHook(&_voxels); NodeList::getInstance()->removeHook(this); + _sharedVoxelSystem.changeTree(new VoxelTree); + delete Menu::getInstance(); delete _oculusProgram; @@ -1215,15 +1215,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"); } @@ -1238,13 +1229,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); } } @@ -1265,12 +1260,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) { @@ -1312,10 +1308,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(); @@ -1326,6 +1333,7 @@ void Application::init() { _headMouseX = _mouseX = _glWidget->width() / 2; _headMouseY = _mouseY = _glWidget->height() / 2; + QCursor::setPos(_headMouseX, _headMouseY); _myAvatar.init(); _myAvatar.setPosition(START_LOCATION); @@ -1333,7 +1341,6 @@ void Application::init() { _myCamera.setModeShiftRate(1.0f); _myAvatar.setDisplayingLookatVectors(false); - QCursor::setPos(_headMouseX, _headMouseY); OculusManager::connect(); if (OculusManager::isConnected()) { @@ -2233,15 +2240,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(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 7ad64ca707..dfb6079e81 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -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; diff --git a/interface/src/ImportDialog.cpp b/interface/src/ImportDialog.cpp index 9c6653cc8a..eea090dfbd 100644 --- a/interface/src/ImportDialog.cpp +++ b/interface/src/ImportDialog.cpp @@ -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,11 @@ 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); } } - void GLWidget::mousePressEvent(QMouseEvent* event) { _pressed = true; _mouseX = event->globalX(); @@ -158,14 +158,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 +187,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); diff --git a/interface/src/ImportDialog.h b/interface/src/ImportDialog.h index f3c1934760..35102dfe4c 100644 --- a/interface/src/ImportDialog.h +++ b/interface/src/ImportDialog.h @@ -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(); diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index d9c1bd928f..4082bc87ef 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -125,9 +125,15 @@ void SerialInterface::initializePort(char* portname) { tcflush(_serialDescriptor, TCIOFLUSH); // this disables streaming so there's no garbage data on reads - write(_serialDescriptor, "SD\n", 3); + if (write(_serialDescriptor, "SD\n", 3) != 3) { + qDebug("Failed.\n"); + return; + } char result[4]; - read(_serialDescriptor, result, 4); + if (read(_serialDescriptor, result, 4) != 4) { + qDebug("Failed.\n"); + return; + } tty_set_file_descriptor(_serialDescriptor); mpu_init(0); diff --git a/interface/src/VoxelImporter.cpp b/interface/src/VoxelImporter.cpp index ef4eeafc4b..b3ca39bbb0 100644 --- a/interface/src/VoxelImporter.cpp +++ b/interface/src/VoxelImporter.cpp @@ -7,29 +7,24 @@ // #include +#include #include #include -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); } diff --git a/interface/src/VoxelImporter.h b/interface/src/VoxelImporter.h index 9b25adcee0..a84955f2c9 100644 --- a/interface/src/VoxelImporter.h +++ b/interface/src/VoxelImporter.h @@ -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; diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index d12d97a5da..2ff8f57bc5 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -429,7 +429,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()) { @@ -646,6 +646,18 @@ void VoxelSystem::init() { _initialized = true; } +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); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index fa4266d30a..5ac5310b76 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -40,13 +40,15 @@ public: int parseData(unsigned char* sourceBuffer, int numBytes); virtual void init(); - void simulate(float deltaTime) { }; + void simulate(float deltaTime) { } void render(bool texture); - ViewFrustum* getViewFrustum() const {return _viewFrustum;} - void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} - unsigned long getVoxelsUpdated() const {return _voxelsUpdated;} - unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;} + 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; } + unsigned long getVoxelsRendered() const { return _voxelsInReadArrays; } void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void writeToSVOFile(const char* filename, VoxelNode* node) const; @@ -118,10 +120,11 @@ protected: float _treeScale; int _maxVoxels; VoxelTree* _tree; + + void setupNewVoxelsForDrawing(); 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); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 0a811e2d48..34f4d5caa4 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -514,7 +514,9 @@ float MyAvatar::getBallRenderAlpha(int ball, bool lookingInMirror) const { void MyAvatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON) { - // Dont display body + // Dont display body, only the hand + _hand.render(lookingInMirror); + return; } diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 207057e244..2ae71ec21c 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -8,9 +8,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm set(TARGET_NAME avatars) +find_package(Qt5Script REQUIRED) + include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) +qt5_use_modules(${TARGET_NAME} Script) + include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} ${ROOT_DIR}) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index f12608f5dd..a35dc49ec0 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -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 ); diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 188b85c0de..22830cb48d 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -24,50 +24,50 @@ const float DEFAULT_KEYHOLE_RADIUS = 3.0f; class ViewFrustum { public: // setters for camera attributes - void setPosition (const glm::vec3& p) { _position = p; }; - void setOrientation (const glm::quat& orientationAsQuaternion); + void setPosition(const glm::vec3& p) { _position = p; } + void setOrientation(const glm::quat& orientationAsQuaternion); // getters for camera attributes - const glm::vec3& getPosition() const { return _position; }; - const glm::quat& getOrientation() const { return _orientation; }; - const glm::vec3& getDirection() const { return _direction; }; - const glm::vec3& getUp() const { return _up; }; - const glm::vec3& getRight() const { return _right; }; + const glm::vec3& getPosition() const { return _position; } + const glm::quat& getOrientation() const { return _orientation; } + const glm::vec3& getDirection() const { return _direction; } + const glm::vec3& getUp() const { return _up; } + const glm::vec3& getRight() const { return _right; } // setters for lens attributes - void setFieldOfView ( float f ) { _fieldOfView = f; }; - void setAspectRatio ( float a ) { _aspectRatio = a; }; - void setNearClip ( float n ) { _nearClip = n; }; - void setFarClip ( float f ) { _farClip = f; }; - void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; }; - void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; }; + void setFieldOfView(float f) { _fieldOfView = f; } + void setAspectRatio(float a) { _aspectRatio = a; } + void setNearClip(float n) { _nearClip = n; } + void setFarClip(float f) { _farClip = f; } + void setEyeOffsetPosition(const glm::vec3& p) { _eyeOffsetPosition = p; } + void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; } // getters for lens attributes - float getFieldOfView() const { return _fieldOfView; }; - float getAspectRatio() const { return _aspectRatio; }; - float getNearClip() const { return _nearClip; }; - float getFarClip() const { return _farClip; }; - const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }; - const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation;}; + float getFieldOfView() const { return _fieldOfView; } + float getAspectRatio() const { return _aspectRatio; } + float getNearClip() const { return _nearClip; } + float getFarClip() const { return _farClip; } + const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; } + const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; } - const glm::vec3& getOffsetPosition() const { return _offsetPosition; }; - const glm::vec3& getOffsetDirection() const { return _offsetDirection;}; - const glm::vec3& getOffsetUp() const { return _offsetUp; }; - const glm::vec3& getOffsetRight() const { return _offsetRight; }; + const glm::vec3& getOffsetPosition() const { return _offsetPosition; } + const glm::vec3& getOffsetDirection() const { return _offsetDirection; } + const glm::vec3& getOffsetUp() const { return _offsetUp; } + const glm::vec3& getOffsetRight() const { return _offsetRight; } - const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; - const glm::vec3& getFarTopRight() const { return _farTopRight; }; - const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }; - const glm::vec3& getFarBottomRight() const { return _farBottomRight; }; + const glm::vec3& getFarTopLeft() const { return _farTopLeft; } + const glm::vec3& getFarTopRight() const { return _farTopRight; } + const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; } + const glm::vec3& getFarBottomRight() const { return _farBottomRight; } - const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }; - const glm::vec3& getNearTopRight() const { return _nearTopRight; }; - const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; - const glm::vec3& getNearBottomRight() const { return _nearBottomRight;}; + const glm::vec3& getNearTopLeft() const { return _nearTopLeft; } + const glm::vec3& getNearTopRight() const { return _nearTopRight; } + const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; } + const glm::vec3& getNearBottomRight() const { return _nearBottomRight; } // get/set for keyhole attribute - void setKeyholeRadius(float keyholdRadius) { _keyholeRadius = keyholdRadius; }; - float getKeyholeRadius() const { return _keyholeRadius; }; + void setKeyholeRadius(float keyholdRadius) { _keyholeRadius = keyholdRadius; } + float getKeyholeRadius() const { return _keyholeRadius; } void calculate(); @@ -81,7 +81,7 @@ public: // some frustum comparisons bool matches(const ViewFrustum& compareTo, bool debug = false) const; - bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); }; + bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); } void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index d4927a293a..22b0f55b46 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1526,7 +1526,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); @@ -1552,15 +1551,15 @@ 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); - for (int x = 0; x < pngImage.width() * pngImage.height(); ++x) { - minAlpha = std::min(qAlpha(pngImage.color(x)) , minAlpha); + for (int i = 0; i < pngImage.width(); ++i) { + for (int j = 0; j < pngImage.height(); ++j) { + minAlpha = std::min(qAlpha(pngImage.pixel(i, j)) , minAlpha); + } } int maxSize = std::max(pngImage.width(), pngImage.height()); @@ -1569,6 +1568,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; @@ -1637,14 +1638,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) {