Add rendered model wireframe toggle action inside view mesh

master
Jeremy Hu 2018-04-15 20:48:54 +08:00
parent 44a8ca6351
commit a441c73f55
6 changed files with 44 additions and 25 deletions

View File

@ -5,11 +5,11 @@
#include "ds3file.h"
ModelMeshBinder::ModelMeshBinder() :
m_mesh(nullptr),
m_renderTriangleVertexCount(0),
m_renderEdgeVertexCount(0),
m_mesh(NULL),
m_meshUpdated(false),
m_showWireframes(true)
m_showWireframes(false)
{
}
@ -135,3 +135,8 @@ void ModelMeshBinder::hideWireframes()
{
m_showWireframes = false;
}
bool ModelMeshBinder::isWireframesVisible()
{
return m_showWireframes;
}

View File

@ -18,17 +18,19 @@ public:
void cleanup();
void showWireframes();
void hideWireframes();
bool isWireframesVisible();
private:
Mesh *m_mesh;
int m_renderTriangleVertexCount;
int m_renderEdgeVertexCount;
bool m_meshUpdated;
bool m_showWireframes;
private:
QOpenGLVertexArrayObject m_vaoTriangle;
QOpenGLBuffer m_vboTriangle;
QOpenGLVertexArrayObject m_vaoEdge;
QOpenGLBuffer m_vboEdge;
Mesh *m_mesh;
QMutex m_meshMutex;
int m_renderTriangleVertexCount;
int m_renderEdgeVertexCount;
bool m_meshUpdated;
bool m_showWireframes;
};
#endif

View File

@ -12,14 +12,14 @@
bool ModelWidget::m_transparent = true;
ModelWidget::ModelWidget(QWidget *parent)
: QOpenGLWidget(parent),
m_xRot(-30 * 16),
m_yRot(45 * 16),
m_zRot(0),
m_program(nullptr),
m_moveStarted(false),
m_graphicsFunctions(NULL)
ModelWidget::ModelWidget(QWidget *parent) :
QOpenGLWidget(parent),
m_xRot(-30 * 16),
m_yRot(45 * 16),
m_zRot(0),
m_program(nullptr),
m_moveStarted(false),
m_graphicsFunctions(NULL)
{
// --transparent causes the clear color to be transparent. Therefore, on systems that
// support it, the widget will become transparent apart from the logo.
@ -172,6 +172,15 @@ void ModelWidget::resizeGL(int w, int h)
m_proj.perspective(45.0f, GLfloat(w) / h, 0.01f, 100.0f);
}
void ModelWidget::toggleWireframe()
{
if (m_meshBinder.isWireframesVisible())
m_meshBinder.hideWireframes();
else
m_meshBinder.showWireframes();
update();
}
void ModelWidget::mousePressEvent(QMouseEvent *event)
{
if (!m_moveStarted && m_graphicsFunctions && m_graphicsFunctions->mousePress(event))
@ -182,8 +191,6 @@ void ModelWidget::mousePressEvent(QMouseEvent *event)
m_moveStartPos = mapToParent(event->pos());
m_moveStartGeometry = geometry();
m_moveStarted = true;
m_meshBinder.hideWireframes();
update();
}
}
}
@ -194,8 +201,6 @@ void ModelWidget::mouseReleaseEvent(QMouseEvent *event)
m_graphicsFunctions->mouseRelease(event);
if (m_moveStarted) {
m_moveStarted = false;
m_meshBinder.showWireframes();
update();
}
}

View File

@ -27,7 +27,7 @@ public:
void updateMesh(Mesh *mesh);
void exportMeshAsObj(const QString &filename);
void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions);
void toggleWireframe();
public slots:
void setXRotation(int angle);
void setYRotation(int angle);
@ -53,22 +53,22 @@ public:
int xRot();
int yRot();
int zRot();
private:
int m_xRot;
int m_yRot;
int m_zRot;
ModelShaderProgram *m_program;
bool m_moveStarted;
SkeletonGraphicsFunctions *m_graphicsFunctions;
private:
QPoint m_lastPos;
ModelMeshBinder m_meshBinder;
ModelShaderProgram *m_program;
QMatrix4x4 m_proj;
QMatrix4x4 m_camera;
QMatrix4x4 m_world;
static bool m_transparent;
bool m_moveStarted;
QPoint m_moveStartPos;
QRect m_moveStartGeometry;
SkeletonGraphicsFunctions *m_graphicsFunctions;
};
#endif

View File

@ -137,7 +137,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
containerWidget->setMinimumSize(400, 400);
m_modelWidget = new ModelWidget(containerWidget);
m_modelWidget->setMinimumSize(256, 256);
m_modelWidget->setMinimumSize(128, 128);
m_modelWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_modelWidget->move(16, 16);
m_modelWidget->setGraphicsFunctions(graphicsWidget);
@ -290,6 +290,12 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
});
m_viewMenu->addAction(m_resetModelWidgetPosAction);
m_toggleWireframeAction = new QAction(tr("Toggle Wireframe"), this);
connect(m_toggleWireframeAction, &QAction::triggered, [=]() {
m_modelWidget->toggleWireframe();
});
m_viewMenu->addAction(m_toggleWireframeAction);
m_showDebugDialogAction = new QAction(tr("Show Debug Dialog"), this);
connect(m_showDebugDialogAction, &QAction::triggered, g_logBrowser, &LogBrowser::showDialog);
m_viewMenu->addAction(m_showDebugDialogAction);

View File

@ -83,6 +83,7 @@ private:
QMenu *m_viewMenu;
QAction *m_resetModelWidgetPosAction;
QAction *m_showDebugDialogAction;
QAction *m_toggleWireframeAction;
QMenu *m_helpMenu;
QAction *m_viewSourceAction;