From a441c73f5596ae456a9da956ee563a3cf12b452b Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 15 Apr 2018 20:48:54 +0800 Subject: [PATCH] Add rendered model wireframe toggle action inside view mesh --- src/modelmeshbinder.cpp | 9 +++++++-- src/modelmeshbinder.h | 12 +++++++----- src/modelwidget.cpp | 29 +++++++++++++++++------------ src/modelwidget.h | 10 +++++----- src/skeletondocumentwindow.cpp | 8 +++++++- src/skeletondocumentwindow.h | 1 + 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/modelmeshbinder.cpp b/src/modelmeshbinder.cpp index 81092da2..93f7e2b4 100644 --- a/src/modelmeshbinder.cpp +++ b/src/modelmeshbinder.cpp @@ -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; +} diff --git a/src/modelmeshbinder.h b/src/modelmeshbinder.h index ee15af0f..d65aa735 100644 --- a/src/modelmeshbinder.h +++ b/src/modelmeshbinder.h @@ -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 diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index d4fa0347..90221178 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -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(); } } diff --git a/src/modelwidget.h b/src/modelwidget.h index 308dfd18..51c892e8 100644 --- a/src/modelwidget.h +++ b/src/modelwidget.h @@ -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 diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index de5a3cf1..0269650b 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -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); diff --git a/src/skeletondocumentwindow.h b/src/skeletondocumentwindow.h index f3bcc044..5d04a291 100644 --- a/src/skeletondocumentwindow.h +++ b/src/skeletondocumentwindow.h @@ -83,6 +83,7 @@ private: QMenu *m_viewMenu; QAction *m_resetModelWidgetPosAction; QAction *m_showDebugDialogAction; + QAction *m_toggleWireframeAction; QMenu *m_helpMenu; QAction *m_viewSourceAction;