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:
parent
0735ef996d
commit
fa8808fea8
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "..\Header\FileInterface.h"
|
||||
#include <QObject>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLBuffer>
|
||||
@ -13,8 +14,10 @@ struct DrawInformation {
|
||||
QMatrix4x4 modelMatrix;
|
||||
};
|
||||
|
||||
class GeometryEngine : protected QOpenGLFunctions
|
||||
class GeometryEngine : public QObject, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeometryEngine();
|
||||
virtual ~GeometryEngine();
|
||||
@ -26,9 +29,14 @@ private:
|
||||
QVector<DrawInformation> m_drawList;
|
||||
|
||||
void loadTexture(const char* filePath);
|
||||
void clearData();
|
||||
|
||||
public:
|
||||
public slots:
|
||||
void loadFile(const char* filePath);
|
||||
void drawGeometry(QOpenGLShaderProgram *program);
|
||||
|
||||
signals:
|
||||
void requestResetView();
|
||||
|
||||
};
|
||||
|
||||
|
@ -19,4 +19,6 @@ private slots:
|
||||
void aboutFile();
|
||||
void aboutTool();
|
||||
|
||||
signals:
|
||||
void loadFile(const char*);
|
||||
};
|
||||
|
@ -50,9 +50,7 @@ protected:
|
||||
private:
|
||||
void initShaders();
|
||||
|
||||
public:
|
||||
void openFile(const char* filePath);
|
||||
|
||||
|
||||
private slots:
|
||||
void resetView();
|
||||
};
|
||||
|
||||
|
1
QtMeshViewer/Resources/prgmExeIcon.rc
Normal file
1
QtMeshViewer/Resources/prgmExeIcon.rc
Normal file
@ -0,0 +1 @@
|
||||
IDI_ICON1 ICON DISCARDABLE "icon.ico"
|
@ -10,23 +10,12 @@ GeometryEngine::GeometryEngine()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
// Generate 2 VBOs
|
||||
m_arrayBuf.create();
|
||||
m_indexBuf.create();
|
||||
|
||||
// Initializes cube geometry and transfers it to VBOs
|
||||
loadFile("..\\Release\\Msh\\ic_helmet.msh");
|
||||
loadFile("..\\Release\\Msh\\4-Poly.msh");
|
||||
}
|
||||
|
||||
GeometryEngine::~GeometryEngine()
|
||||
{
|
||||
m_arrayBuf.destroy();
|
||||
m_indexBuf.destroy();
|
||||
|
||||
for (auto it : m_textures)
|
||||
delete it;
|
||||
m_textures.clear();
|
||||
m_drawList.clear();
|
||||
clearData();
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +24,14 @@ GeometryEngine::~GeometryEngine()
|
||||
|
||||
void GeometryEngine::loadFile(const char* filePath)
|
||||
{
|
||||
// cleanup old stuff and recreate buffers
|
||||
clearData();
|
||||
m_arrayBuf.create();
|
||||
m_indexBuf.create();
|
||||
|
||||
//reset view
|
||||
emit requestResetView();
|
||||
|
||||
try
|
||||
{
|
||||
//TODO normalize
|
||||
@ -134,12 +131,28 @@ void GeometryEngine::loadTexture(const char* filePath)
|
||||
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
|
||||
|
||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||
{
|
||||
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
|
||||
return;
|
||||
|
||||
// Setup
|
||||
// Tell OpenGL which VBOs to use
|
||||
m_arrayBuf.bind();
|
||||
|
@ -26,7 +26,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
setCentralWidget(new OglViewerWidget(this));
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -37,7 +36,7 @@ MainWindow::~MainWindow()
|
||||
void MainWindow::openFile()
|
||||
{
|
||||
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()
|
||||
|
@ -476,7 +476,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
for (unsigned int tri = 0; tri < tmp_multiPolySize - 2; tri++)
|
||||
// ..calculate the edge indices
|
||||
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
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "..\Header\OglViewerWidget.h"
|
||||
|
||||
#include "..\Header\MainWindow.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
@ -19,6 +19,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) :
|
||||
setFocus();
|
||||
m_translation.setZ(DEFAULT_Z_DISTANCE);
|
||||
setAcceptDrops(true);
|
||||
|
||||
}
|
||||
|
||||
OglViewerWidget::~OglViewerWidget()
|
||||
@ -101,14 +102,12 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Space)
|
||||
{
|
||||
m_rotation = QQuaternion();
|
||||
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
||||
resetView();
|
||||
}
|
||||
else if (e->key() == Qt::Key_Escape)
|
||||
{
|
||||
parentWidget()->close();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void OglViewerWidget::initializeGL()
|
||||
@ -126,6 +125,8 @@ void OglViewerWidget::initializeGL()
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
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 |
Loading…
Reference in New Issue
Block a user