cosmetic to MainWindow,
drop does not work for widget, fixed offset problem, add esc key
This commit is contained in:
parent
dca6e61c4b
commit
0735ef996d
|
@ -25,10 +25,10 @@ private:
|
||||||
QVector<QOpenGLTexture*> m_textures;
|
QVector<QOpenGLTexture*> m_textures;
|
||||||
QVector<DrawInformation> m_drawList;
|
QVector<DrawInformation> m_drawList;
|
||||||
|
|
||||||
void loadFile(const char* filePath);
|
|
||||||
void loadTexture(const char* filePath);
|
void loadTexture(const char* filePath);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void loadFile(const char* filePath);
|
||||||
void drawGeometry(QOpenGLShaderProgram *program);
|
void drawGeometry(QOpenGLShaderProgram *program);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindowClass* ui;
|
Ui::MainWindowClass* ui;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void openFile();
|
||||||
|
void aboutFile();
|
||||||
|
void aboutTool();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
||||||
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
||||||
void wheelEvent(QWheelEvent *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 keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void initializeGL() Q_DECL_OVERRIDE;
|
void initializeGL() Q_DECL_OVERRIDE;
|
||||||
|
@ -49,6 +50,9 @@ protected:
|
||||||
private:
|
private:
|
||||||
void initShaders();
|
void initShaders();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void openFile(const char* filePath);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ GeometryEngine::GeometryEngine()
|
||||||
m_indexBuf.create();
|
m_indexBuf.create();
|
||||||
|
|
||||||
// Initializes cube geometry and transfers it to VBOs
|
// Initializes cube geometry and transfers it to VBOs
|
||||||
loadFile("..\\Release\\Msh\\triClothMan.msh");
|
loadFile("..\\Release\\Msh\\ic_helmet.msh");
|
||||||
}
|
}
|
||||||
|
|
||||||
GeometryEngine::~GeometryEngine()
|
GeometryEngine::~GeometryEngine()
|
||||||
|
@ -50,21 +50,22 @@ void GeometryEngine::loadFile(const char* filePath)
|
||||||
textureNames = file.getTextureNames();
|
textureNames = file.getTextureNames();
|
||||||
|
|
||||||
// collect data
|
// collect data
|
||||||
unsigned int offsetCount(0);
|
unsigned int indexOffset(0);
|
||||||
|
unsigned int vertexOffset(0);
|
||||||
for (auto& modelIterator : *models)
|
for (auto& modelIterator : *models)
|
||||||
{
|
{
|
||||||
for (auto& segmentIterator : modelIterator->segmList)
|
for (auto& segmentIterator : modelIterator->segmList)
|
||||||
{
|
{
|
||||||
// get draw information
|
// get draw information
|
||||||
DrawInformation new_info;
|
DrawInformation new_info;
|
||||||
new_info.offset = offsetCount;
|
new_info.offset = indexOffset;
|
||||||
new_info.size = segmentIterator->indices.size();
|
new_info.size = segmentIterator->indices.size();
|
||||||
new_info.textureIndex = segmentIterator->textureIndex;
|
new_info.textureIndex = segmentIterator->textureIndex;
|
||||||
new_info.modelMatrix = modelIterator->m4x4Translation;
|
new_info.modelMatrix = modelIterator->m4x4Translation;
|
||||||
|
|
||||||
// add offset to indices
|
// add offset to indices
|
||||||
for (auto& it : segmentIterator->indices)
|
for (auto& it : segmentIterator->indices)
|
||||||
it += new_info.offset;
|
it += vertexOffset;
|
||||||
|
|
||||||
// save data
|
// save data
|
||||||
vertexData += segmentIterator->vertices;
|
vertexData += segmentIterator->vertices;
|
||||||
|
@ -72,7 +73,8 @@ void GeometryEngine::loadFile(const char* filePath)
|
||||||
m_drawList.push_back(new_info);
|
m_drawList.push_back(new_info);
|
||||||
|
|
||||||
// update offset
|
// update offset
|
||||||
offsetCount += new_info.size;
|
indexOffset += new_info.size;
|
||||||
|
vertexOffset += segmentIterator->vertices.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#include "..\Header\MainWindow.h"
|
#include "..\Header\MainWindow.h"
|
||||||
#include "..\Header\OglViewerWidget.h"
|
#include "..\Header\OglViewerWidget.h"
|
||||||
#include <QSurfaceFormat>
|
#include <QSurfaceFormat>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
#define WINDOW_NAME "Mesh Viewer"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
@ -8,19 +12,54 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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;
|
QSurfaceFormat format;
|
||||||
format.setDepthBufferSize(24);
|
format.setDepthBufferSize(24);
|
||||||
QSurfaceFormat::setDefaultFormat(format);
|
QSurfaceFormat::setDefaultFormat(format);
|
||||||
|
|
||||||
setCentralWidget(new OglViewerWidget(this));
|
setCentralWidget(new OglViewerWidget(this));
|
||||||
|
|
||||||
setWindowIcon(QIcon(":/images/icon.ico"));
|
|
||||||
setWindowTitle("Mesh Viewer");
|
|
||||||
ui->statusBar->showMessage("pre-alpha");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::openFile()
|
||||||
|
{
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "../Release/Msh", "Mesh (*.msh)");
|
||||||
|
dynamic_cast<OglViewerWidget*>(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();
|
||||||
}
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
#include "..\Header\OglViewerWidget.h"
|
#include "..\Header\OglViewerWidget.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QDropEvent>
|
||||||
|
#include <QMimeData>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -16,6 +18,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) :
|
||||||
{
|
{
|
||||||
setFocus();
|
setFocus();
|
||||||
m_translation.setZ(DEFAULT_Z_DISTANCE);
|
m_translation.setZ(DEFAULT_Z_DISTANCE);
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
OglViewerWidget::~OglViewerWidget()
|
OglViewerWidget::~OglViewerWidget()
|
||||||
|
@ -89,6 +92,11 @@ void OglViewerWidget::wheelEvent(QWheelEvent *e)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OglViewerWidget::dropEvent(QDropEvent * e)
|
||||||
|
{
|
||||||
|
std::cout << e->mimeData()->text().toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||||
{
|
{
|
||||||
if (e->key() == Qt::Key_Space)
|
if (e->key() == Qt::Key_Space)
|
||||||
|
@ -96,6 +104,10 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||||
m_rotation = QQuaternion();
|
m_rotation = QQuaternion();
|
||||||
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
||||||
}
|
}
|
||||||
|
else if (e->key() == Qt::Key_Escape)
|
||||||
|
{
|
||||||
|
parentWidget()->close();
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +115,7 @@ void OglViewerWidget::initializeGL()
|
||||||
{
|
{
|
||||||
initializeOpenGLFunctions();
|
initializeOpenGLFunctions();
|
||||||
|
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f);
|
||||||
|
|
||||||
initShaders();
|
initShaders();
|
||||||
|
|
||||||
|
@ -174,4 +186,9 @@ void OglViewerWidget::initShaders()
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public functions
|
// public functions
|
||||||
|
|
||||||
|
void OglViewerWidget::openFile(const char * filePath)
|
||||||
|
{
|
||||||
|
m_dataEngine->loadFile(filePath);
|
||||||
|
}
|
|
@ -13,11 +13,14 @@ Feel free to use my code the way you like. But remember i used some public libra
|
||||||
licence, too.
|
licence, too.
|
||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
- rotation problem
|
- center and normalize
|
||||||
- cloth not working correctly
|
- 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,...
|
- optional display bones, shadow, collision,...
|
||||||
- integrate into a software:
|
- integrate into a software:
|
||||||
-> gui open file ( + drag and drop),
|
|
||||||
-> list all msh under a directory,
|
-> list all msh under a directory,
|
||||||
-> display shadows,
|
-> display shadows,
|
||||||
-> display colisions,
|
-> display colisions,
|
||||||
|
|
Loading…
Reference in New Issue