add exe icon,

signal-slot for openFile,
resetView on openFile,
cleanup when open a new file,
triangulate quad poly now correctly, more not working, bug from previous version,
next:
fix 5,6,.. triangulation,
triClothMan, IC Helmet, still buggy,
This commit is contained in:
Anakin 2017-01-02 12:21:32 +01:00
parent 0735ef996d
commit fa8808fea8
9 changed files with 54 additions and 30 deletions

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "..\Header\FileInterface.h" #include "..\Header\FileInterface.h"
#include <QObject>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
@ -13,8 +14,10 @@ struct DrawInformation {
QMatrix4x4 modelMatrix; QMatrix4x4 modelMatrix;
}; };
class GeometryEngine : protected QOpenGLFunctions class GeometryEngine : public QObject, protected QOpenGLFunctions
{ {
Q_OBJECT
public: public:
GeometryEngine(); GeometryEngine();
virtual ~GeometryEngine(); virtual ~GeometryEngine();
@ -26,9 +29,14 @@ private:
QVector<DrawInformation> m_drawList; QVector<DrawInformation> m_drawList;
void loadTexture(const char* filePath); void loadTexture(const char* filePath);
void clearData();
public: public slots:
void loadFile(const char* filePath); void loadFile(const char* filePath);
void drawGeometry(QOpenGLShaderProgram *program); void drawGeometry(QOpenGLShaderProgram *program);
signals:
void requestResetView();
}; };

View File

@ -19,4 +19,6 @@ private slots:
void aboutFile(); void aboutFile();
void aboutTool(); void aboutTool();
signals:
void loadFile(const char*);
}; };

View File

@ -50,9 +50,7 @@ protected:
private: private:
void initShaders(); void initShaders();
public: private slots:
void openFile(const char* filePath); void resetView();
}; };

View File

@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "icon.ico"

View File

@ -10,23 +10,12 @@ GeometryEngine::GeometryEngine()
{ {
initializeOpenGLFunctions(); initializeOpenGLFunctions();
// Generate 2 VBOs loadFile("..\\Release\\Msh\\4-Poly.msh");
m_arrayBuf.create();
m_indexBuf.create();
// Initializes cube geometry and transfers it to VBOs
loadFile("..\\Release\\Msh\\ic_helmet.msh");
} }
GeometryEngine::~GeometryEngine() GeometryEngine::~GeometryEngine()
{ {
m_arrayBuf.destroy(); clearData();
m_indexBuf.destroy();
for (auto it : m_textures)
delete it;
m_textures.clear();
m_drawList.clear();
} }
@ -35,6 +24,14 @@ GeometryEngine::~GeometryEngine()
void GeometryEngine::loadFile(const char* filePath) void GeometryEngine::loadFile(const char* filePath)
{ {
// cleanup old stuff and recreate buffers
clearData();
m_arrayBuf.create();
m_indexBuf.create();
//reset view
emit requestResetView();
try try
{ {
//TODO normalize //TODO normalize
@ -134,12 +131,28 @@ void GeometryEngine::loadTexture(const char* filePath)
m_textures.push_back(new_texture); m_textures.push_back(new_texture);
} }
void GeometryEngine::clearData()
{
if (m_arrayBuf.isCreated())
m_arrayBuf.destroy();
if (m_indexBuf.isCreated())
m_indexBuf.destroy();
for (auto it : m_textures)
delete it;
m_textures.clear();
m_drawList.clear();
}
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public functions // public functions
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program) void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
{ {
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
return;
// Setup // Setup
// Tell OpenGL which VBOs to use // Tell OpenGL which VBOs to use
m_arrayBuf.bind(); m_arrayBuf.bind();

View File

@ -26,7 +26,6 @@ MainWindow::MainWindow(QWidget *parent)
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
setCentralWidget(new OglViewerWidget(this)); setCentralWidget(new OglViewerWidget(this));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -37,7 +36,7 @@ MainWindow::~MainWindow()
void MainWindow::openFile() void MainWindow::openFile()
{ {
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "../Release/Msh", "Mesh (*.msh)"); QString fileName = QFileDialog::getOpenFileName(this, "Open File", "../Release/Msh", "Mesh (*.msh)");
dynamic_cast<OglViewerWidget*>(centralWidget())->openFile(fileName.toStdString().c_str()); emit loadFile(fileName.toStdString().c_str());
} }
void MainWindow::aboutFile() void MainWindow::aboutFile()

View File

@ -476,7 +476,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
for (unsigned int tri = 0; tri < tmp_multiPolySize - 2; tri++) for (unsigned int tri = 0; tri < tmp_multiPolySize - 2; tri++)
// ..calculate the edge indices // ..calculate the edge indices
for (int triEdge = 0; triEdge < 3; triEdge++) for (int triEdge = 0; triEdge < 3; triEdge++)
new_segment->indices.push_back((GLuint)(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))); new_segment->indices.push_back((GLuint)tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]);
} }
else else
{ {

View File

@ -1,5 +1,5 @@
#include "..\Header\OglViewerWidget.h" #include "..\Header\OglViewerWidget.h"
#include "..\Header\MainWindow.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QDropEvent> #include <QDropEvent>
#include <QMimeData> #include <QMimeData>
@ -19,6 +19,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) :
setFocus(); setFocus();
m_translation.setZ(DEFAULT_Z_DISTANCE); m_translation.setZ(DEFAULT_Z_DISTANCE);
setAcceptDrops(true); setAcceptDrops(true);
} }
OglViewerWidget::~OglViewerWidget() OglViewerWidget::~OglViewerWidget()
@ -101,14 +102,12 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
{ {
if (e->key() == Qt::Key_Space) if (e->key() == Qt::Key_Space)
{ {
m_rotation = QQuaternion(); resetView();
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
} }
else if (e->key() == Qt::Key_Escape) else if (e->key() == Qt::Key_Escape)
{ {
parentWidget()->close(); parentWidget()->close();
} }
update();
} }
void OglViewerWidget::initializeGL() void OglViewerWidget::initializeGL()
@ -126,6 +125,8 @@ void OglViewerWidget::initializeGL()
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
m_dataEngine = new GeometryEngine; m_dataEngine = new GeometryEngine;
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
} }
@ -186,9 +187,11 @@ void OglViewerWidget::initShaders()
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public functions // private slots
void OglViewerWidget::openFile(const char * filePath) void OglViewerWidget::resetView()
{ {
m_dataEngine->loadFile(filePath); m_rotation = QQuaternion();
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
update();
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

After

Width:  |  Height:  |  Size: 256 KiB