Add check UV

master
Jeremy Hu 2019-08-10 07:57:26 +09:30
parent a6b9ac7bf1
commit 13db7ee97b
11 changed files with 68 additions and 4 deletions

View File

@ -366,6 +366,10 @@ Tips:
<source>Paint brush</source> <source>Paint brush</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Toggle UV Check</source>
<translation>UV</translation>
</message>
</context> </context>
<context> <context>
<name>ExportPreviewWidget</name> <name>ExportPreviewWidget</name>

View File

@ -20,6 +20,7 @@
<file>resources/hexagon.png</file> <file>resources/hexagon.png</file>
<file>resources/heptagon.png</file> <file>resources/heptagon.png</file>
<file>resources/userdefined.png</file> <file>resources/userdefined.png</file>
<file>resources/checkuv.png</file>
<file>shaders/default.vert</file> <file>shaders/default.vert</file>
<file>shaders/default.frag</file> <file>shaders/default.frag</file>
<file>shaders/default.core.vert</file> <file>shaders/default.core.vert</file>

BIN
resources/checkuv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -651,6 +651,12 @@ DocumentWindow::DocumentWindow() :
m_modelRenderWidget->toggleWireframe(); m_modelRenderWidget->toggleWireframe();
}); });
m_viewMenu->addAction(m_toggleWireframeAction); m_viewMenu->addAction(m_toggleWireframeAction);
m_toggleUvCheckAction = new QAction(tr("Toggle UV Check"), this);
connect(m_toggleUvCheckAction, &QAction::triggered, [=]() {
m_modelRenderWidget->toggleUvCheck();
});
m_viewMenu->addAction(m_toggleUvCheckAction);
connect(m_viewMenu, &QMenu::aboutToShow, [=]() { connect(m_viewMenu, &QMenu::aboutToShow, [=]() {
m_resetModelWidgetPosAction->setEnabled(!isModelSitInVisibleArea(m_modelRenderWidget)); m_resetModelWidgetPosAction->setEnabled(!isModelSitInVisibleArea(m_modelRenderWidget));

View File

@ -154,6 +154,7 @@ private:
QMenu *m_viewMenu; QMenu *m_viewMenu;
QAction *m_resetModelWidgetPosAction; QAction *m_resetModelWidgetPosAction;
QAction *m_toggleWireframeAction; QAction *m_toggleWireframeAction;
QAction *m_toggleUvCheckAction;
QAction *m_showMotionsListAction; QAction *m_showMotionsListAction;
QMenu *m_windowMenu; QMenu *m_windowMenu;

View File

@ -32,6 +32,19 @@ void ModelMeshBinder::updateMesh(MeshLoader *mesh)
} }
} }
void ModelMeshBinder::reloadMesh()
{
MeshLoader *mesh = nullptr;
{
QMutexLocker lock(&m_newMeshMutex);
if (nullptr == m_mesh)
return;
mesh = new MeshLoader(*m_mesh);
}
if (nullptr != mesh)
updateMesh(mesh);
}
void ModelMeshBinder::initialize() void ModelMeshBinder::initialize()
{ {
m_vaoTriangle.create(); m_vaoTriangle.create();
@ -63,8 +76,16 @@ void ModelMeshBinder::paint(ModelShaderProgram *program)
m_hasTexture = nullptr != m_mesh->textureImage(); m_hasTexture = nullptr != m_mesh->textureImage();
delete m_texture; delete m_texture;
m_texture = nullptr; m_texture = nullptr;
if (m_hasTexture) if (m_hasTexture) {
m_texture = new QOpenGLTexture(*m_mesh->textureImage()); if (m_checkUvEnabled) {
static QImage *s_checkUv = nullptr;
if (nullptr == s_checkUv)
s_checkUv = new QImage(":/resources/checkuv.png");
m_texture = new QOpenGLTexture(*s_checkUv);
} else {
m_texture = new QOpenGLTexture(*m_mesh->textureImage());
}
}
m_hasNormalMap = nullptr != m_mesh->normalMapImage(); m_hasNormalMap = nullptr != m_mesh->normalMapImage();
delete m_normalMap; delete m_normalMap;
@ -253,3 +274,18 @@ bool ModelMeshBinder::isWireframesVisible()
{ {
return m_showWireframes; return m_showWireframes;
} }
void ModelMeshBinder::enableCheckUv()
{
m_checkUvEnabled = true;
}
void ModelMeshBinder::disableCheckUv()
{
m_checkUvEnabled = false;
}
bool ModelMeshBinder::isCheckUvEnabled()
{
return m_checkUvEnabled;
}

View File

@ -20,6 +20,10 @@ public:
void showWireframes(); void showWireframes();
void hideWireframes(); void hideWireframes();
bool isWireframesVisible(); bool isWireframesVisible();
void enableCheckUv();
void disableCheckUv();
bool isCheckUvEnabled();
void reloadMesh();
private: private:
MeshLoader *m_mesh = nullptr; MeshLoader *m_mesh = nullptr;
MeshLoader *m_newMesh = nullptr; MeshLoader *m_newMesh = nullptr;
@ -37,6 +41,7 @@ private:
bool m_hasAmbientOcclusionMap = false; bool m_hasAmbientOcclusionMap = false;
QOpenGLTexture *m_metalnessRoughnessAmbientOcclusionMap = nullptr; QOpenGLTexture *m_metalnessRoughnessAmbientOcclusionMap = nullptr;
bool m_toolEnabled = false; bool m_toolEnabled = false;
bool m_checkUvEnabled = false;
private: private:
QOpenGLVertexArrayObject m_vaoTriangle; QOpenGLVertexArrayObject m_vaoTriangle;
QOpenGLBuffer m_vboTriangle; QOpenGLBuffer m_vboTriangle;

View File

@ -194,7 +194,6 @@ std::pair<QVector3D, QVector3D> ModelWidget::screenPositionToMouseRay(const QPoi
auto viewPort = QRect(0, 0, width(), height()); auto viewPort = QRect(0, 0, width(), height());
auto nearPosition = nearScreen.unproject(modelView, m_projection, viewPort); auto nearPosition = nearScreen.unproject(modelView, m_projection, viewPort);
auto farPosition = farScreen.unproject(modelView, m_projection, viewPort); auto farPosition = farScreen.unproject(modelView, m_projection, viewPort);
qDebug() << "near:" << nearPosition << "far:" << farPosition << "x:" << x << "y:" << y;
return std::make_pair(nearPosition, farPosition); return std::make_pair(nearPosition, farPosition);
} }
@ -207,6 +206,16 @@ void ModelWidget::toggleWireframe()
update(); update();
} }
void ModelWidget::toggleUvCheck()
{
if (m_meshBinder.isCheckUvEnabled())
m_meshBinder.disableCheckUv();
else
m_meshBinder.enableCheckUv();
m_meshBinder.reloadMesh();
update();
}
bool ModelWidget::inputMousePressEventFromOtherWidget(QMouseEvent *event) bool ModelWidget::inputMousePressEventFromOtherWidget(QMouseEvent *event)
{ {
bool shouldStartMove = false; bool shouldStartMove = false;

View File

@ -33,6 +33,7 @@ public:
void updateMesh(MeshLoader *mesh); void updateMesh(MeshLoader *mesh);
void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions); void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions);
void toggleWireframe(); void toggleWireframe();
void toggleUvCheck();
void enableMove(bool enabled); void enableMove(bool enabled);
void enableZoom(bool enabled); void enableZoom(bool enabled);
void enableMousePicking(bool enabled); void enableMousePicking(bool enabled);

View File

@ -83,7 +83,7 @@ void UvUnwrapper::splitPartitionToIslands(const std::vector<size_t> &group, std:
continue; continue;
if (segmentByNormal) { if (segmentByNormal) {
if (dotProduct(m_mesh.faceNormals[findOppositeFaceResult->second], if (dotProduct(m_mesh.faceNormals[findOppositeFaceResult->second],
m_mesh.faceNormals[index]) < m_segmentDotProductThreshold) { m_mesh.faceNormals[m_segmentPreferMorePieces ? indexInGroup : index]) < m_segmentDotProductThreshold) {
continue; continue;
} }
} }

View File

@ -60,6 +60,7 @@ private:
float m_segmentDotProductThreshold = 0.00; float m_segmentDotProductThreshold = 0.00;
float m_texelSizePerUnit = 1.0; float m_texelSizePerUnit = 1.0;
float m_resultTextureSize = 0; float m_resultTextureSize = 0;
bool m_segmentPreferMorePieces = false;
}; };
} }