diff --git a/QtMeshViewer/Header/GeometryEngine.h b/QtMeshViewer/Header/GeometryEngine.h index ee9580c..f3bf36f 100644 --- a/QtMeshViewer/Header/GeometryEngine.h +++ b/QtMeshViewer/Header/GeometryEngine.h @@ -25,10 +25,10 @@ private: QVector m_textures; QVector m_drawList; - void loadFile(const char* filePath); void loadTexture(const char* filePath); public: + void loadFile(const char* filePath); void drawGeometry(QOpenGLShaderProgram *program); }; diff --git a/QtMeshViewer/Header/MainWindow.h b/QtMeshViewer/Header/MainWindow.h index 49e2d43..a4a5302 100644 --- a/QtMeshViewer/Header/MainWindow.h +++ b/QtMeshViewer/Header/MainWindow.h @@ -13,4 +13,10 @@ public: private: Ui::MainWindowClass* ui; + +private slots: + void openFile(); + void aboutFile(); + void aboutTool(); + }; diff --git a/QtMeshViewer/Header/OglViewerWidget.h b/QtMeshViewer/Header/OglViewerWidget.h index 45a291f..47d26f5 100644 --- a/QtMeshViewer/Header/OglViewerWidget.h +++ b/QtMeshViewer/Header/OglViewerWidget.h @@ -40,6 +40,7 @@ protected: void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; + void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE; void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; void initializeGL() Q_DECL_OVERRIDE; @@ -49,6 +50,9 @@ protected: private: void initShaders(); +public: + void openFile(const char* filePath); + }; diff --git a/QtMeshViewer/Source/GeometryEngine.cpp b/QtMeshViewer/Source/GeometryEngine.cpp index bfd83da..2d1717e 100644 --- a/QtMeshViewer/Source/GeometryEngine.cpp +++ b/QtMeshViewer/Source/GeometryEngine.cpp @@ -15,7 +15,7 @@ GeometryEngine::GeometryEngine() m_indexBuf.create(); // Initializes cube geometry and transfers it to VBOs - loadFile("..\\Release\\Msh\\triClothMan.msh"); + loadFile("..\\Release\\Msh\\ic_helmet.msh"); } GeometryEngine::~GeometryEngine() @@ -50,21 +50,22 @@ void GeometryEngine::loadFile(const char* filePath) textureNames = file.getTextureNames(); // collect data - unsigned int offsetCount(0); + unsigned int indexOffset(0); + unsigned int vertexOffset(0); for (auto& modelIterator : *models) { for (auto& segmentIterator : modelIterator->segmList) { // get draw information DrawInformation new_info; - new_info.offset = offsetCount; + new_info.offset = indexOffset; new_info.size = segmentIterator->indices.size(); new_info.textureIndex = segmentIterator->textureIndex; new_info.modelMatrix = modelIterator->m4x4Translation; // add offset to indices for (auto& it : segmentIterator->indices) - it += new_info.offset; + it += vertexOffset; // save data vertexData += segmentIterator->vertices; @@ -72,7 +73,8 @@ void GeometryEngine::loadFile(const char* filePath) m_drawList.push_back(new_info); // update offset - offsetCount += new_info.size; + indexOffset += new_info.size; + vertexOffset += segmentIterator->vertices.size(); } } diff --git a/QtMeshViewer/Source/MainWindow.cpp b/QtMeshViewer/Source/MainWindow.cpp index 5f6e92b..ed963de 100644 --- a/QtMeshViewer/Source/MainWindow.cpp +++ b/QtMeshViewer/Source/MainWindow.cpp @@ -1,6 +1,10 @@ #include "..\Header\MainWindow.h" #include "..\Header\OglViewerWidget.h" #include +#include +#include + +#define WINDOW_NAME "Mesh Viewer" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -8,19 +12,54 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); + setWindowTitle(WINDOW_NAME); + setWindowIcon(QIcon(":/images/icon.ico")); + + ui->statusBar->showMessage("pre-alpha"); + + ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile); + ui->mainToolBar->addAction("About File", this, &MainWindow::aboutFile); + ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool); + QSurfaceFormat format; format.setDepthBufferSize(24); QSurfaceFormat::setDefaultFormat(format); setCentralWidget(new OglViewerWidget(this)); - setWindowIcon(QIcon(":/images/icon.ico")); - setWindowTitle("Mesh Viewer"); - ui->statusBar->showMessage("pre-alpha"); } - MainWindow::~MainWindow() { delete ui; +} + +void MainWindow::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, "Open File", "../Release/Msh", "Mesh (*.msh)"); + dynamic_cast(centralWidget())->openFile(fileName.toStdString().c_str()); +} + +void MainWindow::aboutFile() +{ + QMessageBox* dialog = new QMessageBox(QMessageBox::Information, + WINDOW_NAME, + "When i find some time, i'll add some information about\nthe file in the detailed text", + QMessageBox::StandardButton::Close, + this, + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + dialog->setDetailedText("This is the cool detailed text\n"); + dialog->exec(); +} + +void MainWindow::aboutTool() +{ + QMessageBox* dialog = new QMessageBox(QMessageBox::Question, + WINDOW_NAME, + "This is the Pre-Alpha version of my Mesh Viewer\nCheck the detailed information", + QMessageBox::StandardButton::Close, + this, + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + dialog->setDetailedText("left mouse - rotate\nright mouse - move\nscroll - zoom\nspace - reset view\nesc - close"); + dialog->exec(); } \ No newline at end of file diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp index aab0310..ad77b63 100644 --- a/QtMeshViewer/Source/OglViewerWidget.cpp +++ b/QtMeshViewer/Source/OglViewerWidget.cpp @@ -1,6 +1,8 @@ #include "..\Header\OglViewerWidget.h" #include +#include +#include #include #include @@ -16,6 +18,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) : { setFocus(); m_translation.setZ(DEFAULT_Z_DISTANCE); + setAcceptDrops(true); } OglViewerWidget::~OglViewerWidget() @@ -89,6 +92,11 @@ void OglViewerWidget::wheelEvent(QWheelEvent *e) update(); } +void OglViewerWidget::dropEvent(QDropEvent * e) +{ + std::cout << e->mimeData()->text().toStdString() << std::endl; +} + void OglViewerWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Space) @@ -96,6 +104,10 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e) m_rotation = QQuaternion(); m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE }; } + else if (e->key() == Qt::Key_Escape) + { + parentWidget()->close(); + } update(); } @@ -103,7 +115,7 @@ void OglViewerWidget::initializeGL() { initializeOpenGLFunctions(); - glClearColor(0, 0, 0, 1); + glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f); initShaders(); @@ -174,4 +186,9 @@ void OglViewerWidget::initShaders() ///////////////////////////////////////////////////////////////////////// -// public functions \ No newline at end of file +// public functions + +void OglViewerWidget::openFile(const char * filePath) +{ + m_dataEngine->loadFile(filePath); +} \ No newline at end of file diff --git a/README.md b/README.md index f3c76d0..8699ba0 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,14 @@ Feel free to use my code the way you like. But remember i used some public libra licence, too. ### To Do -- rotation problem -- cloth not working correctly +- center and normalize +- open file while runtime does not work +- drag and drop does not work +- tga with alpha cannot be opened +- multi polygons not correctly triangulated +- 5+ polygons => corrupted file - optional display bones, shadow, collision,... - integrate into a software: --> gui open file ( + drag and drop), -> list all msh under a directory, -> display shadows, -> display colisions,