Optimize render view port
- Fix the bad performance of view port manipulation - Allow to view the mesh inside - Fix environment light not enabled in image export - Fix wireframe not follow the view port setting in image exportmaster
parent
29b7f13460
commit
420a5997ea
|
@ -49,13 +49,6 @@
|
||||||
#include "fileforever.h"
|
#include "fileforever.h"
|
||||||
#include "documentsaver.h"
|
#include "documentsaver.h"
|
||||||
|
|
||||||
int DocumentWindow::m_modelRenderWidgetInitialX = 16;
|
|
||||||
int DocumentWindow::m_modelRenderWidgetInitialY = 16;
|
|
||||||
int DocumentWindow::m_modelRenderWidgetInitialSize = 128;
|
|
||||||
int DocumentWindow::m_skeletonRenderWidgetInitialX = DocumentWindow::m_modelRenderWidgetInitialX + DocumentWindow::m_modelRenderWidgetInitialSize + 16;
|
|
||||||
int DocumentWindow::m_skeletonRenderWidgetInitialY = DocumentWindow::m_modelRenderWidgetInitialY;
|
|
||||||
int DocumentWindow::m_skeletonRenderWidgetInitialSize = DocumentWindow::m_modelRenderWidgetInitialSize;
|
|
||||||
|
|
||||||
int DocumentWindow::m_autoRecovered = false;
|
int DocumentWindow::m_autoRecovered = false;
|
||||||
|
|
||||||
LogBrowser *g_logBrowser = nullptr;
|
LogBrowser *g_logBrowser = nullptr;
|
||||||
|
@ -327,14 +320,19 @@ DocumentWindow::DocumentWindow() :
|
||||||
//connect(containerWidget, &GraphicsContainerWidget::containerSizeChanged, this, &DocumentWindow::updateInfoWidgetPosition);
|
//connect(containerWidget, &GraphicsContainerWidget::containerSizeChanged, this, &DocumentWindow::updateInfoWidgetPosition);
|
||||||
|
|
||||||
m_modelRenderWidget = new ModelWidget(containerWidget);
|
m_modelRenderWidget = new ModelWidget(containerWidget);
|
||||||
|
m_modelRenderWidget->setMoveAndZoomByWindow(false);
|
||||||
|
m_modelRenderWidget->move(0, 0);
|
||||||
m_modelRenderWidget->setAttribute(Qt::WA_TransparentForMouseEvents);
|
m_modelRenderWidget->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
m_modelRenderWidget->setMinimumSize(DocumentWindow::m_modelRenderWidgetInitialSize, DocumentWindow::m_modelRenderWidgetInitialSize);
|
|
||||||
m_modelRenderWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
||||||
m_modelRenderWidget->move(DocumentWindow::m_modelRenderWidgetInitialX, DocumentWindow::m_modelRenderWidgetInitialY);
|
|
||||||
m_modelRenderWidget->setMousePickRadius(m_document->mousePickRadius());
|
m_modelRenderWidget->setMousePickRadius(m_document->mousePickRadius());
|
||||||
if (!Preferences::instance().toonShading())
|
if (!Preferences::instance().toonShading())
|
||||||
m_modelRenderWidget->toggleWireframe();
|
m_modelRenderWidget->toggleWireframe();
|
||||||
m_modelRenderWidget->enableEnvironmentLight();
|
m_modelRenderWidget->enableEnvironmentLight();
|
||||||
|
m_modelRenderWidget->disableCullFace();
|
||||||
|
m_modelRenderWidget->setEyePosition(QVector3D(0.0, 0.0, -4.0));
|
||||||
|
m_modelRenderWidget->setMoveToPosition(QVector3D(-0.5, -0.5, 0.0));
|
||||||
|
|
||||||
|
connect(containerWidget, &GraphicsContainerWidget::containerSizeChanged,
|
||||||
|
m_modelRenderWidget, &ModelWidget::canvasResized);
|
||||||
|
|
||||||
connect(m_modelRenderWidget, &ModelWidget::mouseRayChanged, m_document,
|
connect(m_modelRenderWidget, &ModelWidget::mouseRayChanged, m_document,
|
||||||
[=](const QVector3D &nearPosition, const QVector3D &farPosition) {
|
[=](const QVector3D &nearPosition, const QVector3D &farPosition) {
|
||||||
|
@ -752,18 +750,18 @@ DocumentWindow::DocumentWindow() :
|
||||||
|
|
||||||
m_viewMenu = menuBar()->addMenu(tr("&View"));
|
m_viewMenu = menuBar()->addMenu(tr("&View"));
|
||||||
|
|
||||||
auto isModelSitInVisibleArea = [](ModelWidget *modelWidget) {
|
//auto isModelSitInVisibleArea = [](ModelWidget *modelWidget) {
|
||||||
QRect parentRect = QRect(QPoint(0, 0), modelWidget->parentWidget()->size());
|
// QRect parentRect = QRect(QPoint(0, 0), modelWidget->parentWidget()->size());
|
||||||
return parentRect.contains(modelWidget->geometry().center());
|
// return parentRect.contains(modelWidget->geometry().center());
|
||||||
};
|
//};
|
||||||
|
|
||||||
m_resetModelWidgetPosAction = new QAction(tr("Show Model"), this);
|
//m_resetModelWidgetPosAction = new QAction(tr("Show Model"), this);
|
||||||
connect(m_resetModelWidgetPosAction, &QAction::triggered, [=]() {
|
//connect(m_resetModelWidgetPosAction, &QAction::triggered, [=]() {
|
||||||
if (!isModelSitInVisibleArea(m_modelRenderWidget)) {
|
// if (!isModelSitInVisibleArea(m_modelRenderWidget)) {
|
||||||
m_modelRenderWidget->move(DocumentWindow::m_modelRenderWidgetInitialX, DocumentWindow::m_modelRenderWidgetInitialY);
|
// m_modelRenderWidget->move(DocumentWindow::m_modelRenderWidgetInitialX, DocumentWindow::m_modelRenderWidgetInitialY);
|
||||||
}
|
// }
|
||||||
});
|
//});
|
||||||
m_viewMenu->addAction(m_resetModelWidgetPosAction);
|
//m_viewMenu->addAction(m_resetModelWidgetPosAction);
|
||||||
|
|
||||||
m_toggleWireframeAction = new QAction(tr("Toggle Wireframe"), this);
|
m_toggleWireframeAction = new QAction(tr("Toggle Wireframe"), this);
|
||||||
connect(m_toggleWireframeAction, &QAction::triggered, [=]() {
|
connect(m_toggleWireframeAction, &QAction::triggered, [=]() {
|
||||||
|
@ -800,9 +798,9 @@ DocumentWindow::DocumentWindow() :
|
||||||
});
|
});
|
||||||
m_viewMenu->addAction(m_toggleUvCheckAction);
|
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));
|
||||||
});
|
//});
|
||||||
|
|
||||||
m_windowMenu = menuBar()->addMenu(tr("&Window"));
|
m_windowMenu = menuBar()->addMenu(tr("&Window"));
|
||||||
|
|
||||||
|
@ -2160,6 +2158,11 @@ void DocumentWindow::exportImageToFilename(const QString &filename)
|
||||||
offlineRender->setYRotation(m_modelRenderWidget->yRot());
|
offlineRender->setYRotation(m_modelRenderWidget->yRot());
|
||||||
offlineRender->setZRotation(m_modelRenderWidget->zRot());
|
offlineRender->setZRotation(m_modelRenderWidget->zRot());
|
||||||
offlineRender->setEyePosition(m_modelRenderWidget->eyePosition());
|
offlineRender->setEyePosition(m_modelRenderWidget->eyePosition());
|
||||||
|
offlineRender->setMoveToPosition(m_modelRenderWidget->moveToPosition());
|
||||||
|
if (m_modelRenderWidget->isWireframeVisible())
|
||||||
|
offlineRender->enableWireframe();
|
||||||
|
if (m_modelRenderWidget->isEnvironmentLightEnabled())
|
||||||
|
offlineRender->enableEnvironmentLight();
|
||||||
offlineRender->setRenderPurpose(0);
|
offlineRender->setRenderPurpose(0);
|
||||||
QImage *normalMap = new QImage();
|
QImage *normalMap = new QImage();
|
||||||
QImage *depthMap = new QImage();
|
QImage *depthMap = new QImage();
|
||||||
|
|
|
@ -180,7 +180,7 @@ private:
|
||||||
QAction *m_colorizeAsAutoAction;
|
QAction *m_colorizeAsAutoAction;
|
||||||
|
|
||||||
QMenu *m_viewMenu;
|
QMenu *m_viewMenu;
|
||||||
QAction *m_resetModelWidgetPosAction;
|
//QAction *m_resetModelWidgetPosAction;
|
||||||
QAction *m_toggleWireframeAction;
|
QAction *m_toggleWireframeAction;
|
||||||
QAction *m_toggleUvCheckAction;
|
QAction *m_toggleUvCheckAction;
|
||||||
QAction *m_toggleRotationAction;
|
QAction *m_toggleRotationAction;
|
||||||
|
@ -220,12 +220,6 @@ private:
|
||||||
|
|
||||||
AutoSaver *m_autoSaver = nullptr;
|
AutoSaver *m_autoSaver = nullptr;
|
||||||
public:
|
public:
|
||||||
static int m_modelRenderWidgetInitialX;
|
|
||||||
static int m_modelRenderWidgetInitialY;
|
|
||||||
static int m_modelRenderWidgetInitialSize;
|
|
||||||
static int m_skeletonRenderWidgetInitialX;
|
|
||||||
static int m_skeletonRenderWidgetInitialY;
|
|
||||||
static int m_skeletonRenderWidgetInitialSize;
|
|
||||||
static int m_autoRecovered;
|
static int m_autoRecovered;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,11 @@ void ModelMeshBinder::enableEnvironmentLight()
|
||||||
m_environmentLightEnabled = true;
|
m_environmentLightEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModelMeshBinder::isEnvironmentLightEnabled()
|
||||||
|
{
|
||||||
|
return m_environmentLightEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
Model *ModelMeshBinder::fetchCurrentMesh()
|
Model *ModelMeshBinder::fetchCurrentMesh()
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_meshMutex);
|
QMutexLocker lock(&m_meshMutex);
|
||||||
|
@ -262,7 +267,7 @@ void ModelMeshBinder::paint(ModelShaderProgram *program)
|
||||||
program->setUniformValue(program->environmentSpecularMapIdLoc(), 4);
|
program->setUniformValue(program->environmentSpecularMapIdLoc(), 4);
|
||||||
program->setUniformValue(program->toonNormalMapIdLoc(), 5);
|
program->setUniformValue(program->toonNormalMapIdLoc(), 5);
|
||||||
program->setUniformValue(program->toonDepthMapIdLoc(), 6);
|
program->setUniformValue(program->toonDepthMapIdLoc(), 6);
|
||||||
if (m_showWireframes) {
|
if (m_showWireframe) {
|
||||||
if (m_renderEdgeVertexCount > 0) {
|
if (m_renderEdgeVertexCount > 0) {
|
||||||
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge);
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge);
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
|
@ -392,19 +397,19 @@ void ModelMeshBinder::cleanup()
|
||||||
m_toonDepthMap = nullptr;
|
m_toonDepthMap = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelMeshBinder::showWireframes()
|
void ModelMeshBinder::showWireframe()
|
||||||
{
|
{
|
||||||
m_showWireframes = true;
|
m_showWireframe = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelMeshBinder::hideWireframes()
|
void ModelMeshBinder::hideWireframe()
|
||||||
{
|
{
|
||||||
m_showWireframes = false;
|
m_showWireframe = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelMeshBinder::isWireframesVisible()
|
bool ModelMeshBinder::isWireframeVisible()
|
||||||
{
|
{
|
||||||
return m_showWireframes;
|
return m_showWireframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelMeshBinder::enableCheckUv()
|
void ModelMeshBinder::enableCheckUv()
|
||||||
|
|
|
@ -18,12 +18,13 @@ public:
|
||||||
void initialize();
|
void initialize();
|
||||||
void paint(ModelShaderProgram *program);
|
void paint(ModelShaderProgram *program);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void showWireframes();
|
void showWireframe();
|
||||||
void hideWireframes();
|
void hideWireframe();
|
||||||
bool isWireframesVisible();
|
bool isWireframeVisible();
|
||||||
void enableCheckUv();
|
void enableCheckUv();
|
||||||
void disableCheckUv();
|
void disableCheckUv();
|
||||||
void enableEnvironmentLight();
|
void enableEnvironmentLight();
|
||||||
|
bool isEnvironmentLightEnabled();
|
||||||
bool isCheckUvEnabled();
|
bool isCheckUvEnabled();
|
||||||
void reloadMesh();
|
void reloadMesh();
|
||||||
void fetchCurrentToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
|
void fetchCurrentToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
|
||||||
|
@ -35,7 +36,7 @@ private:
|
||||||
int m_renderEdgeVertexCount = 0;
|
int m_renderEdgeVertexCount = 0;
|
||||||
int m_renderToolVertexCount = 0;
|
int m_renderToolVertexCount = 0;
|
||||||
bool m_newMeshComing = false;
|
bool m_newMeshComing = false;
|
||||||
bool m_showWireframes = false;
|
bool m_showWireframe = false;
|
||||||
bool m_hasTexture = false;
|
bool m_hasTexture = false;
|
||||||
QOpenGLTexture *m_texture = nullptr;
|
QOpenGLTexture *m_texture = nullptr;
|
||||||
bool m_hasNormalMap = false;
|
bool m_hasNormalMap = false;
|
||||||
|
|
|
@ -58,6 +58,16 @@ void ModelOffscreenRender::setEyePosition(const QVector3D &eyePosition)
|
||||||
m_eyePosition = eyePosition;
|
m_eyePosition = eyePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelOffscreenRender::setMoveToPosition(const QVector3D &moveToPosition)
|
||||||
|
{
|
||||||
|
m_moveToPosition = moveToPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelOffscreenRender::enableWireframe()
|
||||||
|
{
|
||||||
|
m_isWireframeVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelOffscreenRender::setRenderPurpose(int purpose)
|
void ModelOffscreenRender::setRenderPurpose(int purpose)
|
||||||
{
|
{
|
||||||
m_renderPurpose = purpose;
|
m_renderPurpose = purpose;
|
||||||
|
@ -68,6 +78,11 @@ void ModelOffscreenRender::setToonShading(bool toonShading)
|
||||||
m_toonShading = toonShading;
|
m_toonShading = toonShading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelOffscreenRender::enableEnvironmentLight()
|
||||||
|
{
|
||||||
|
m_isEnvironmentLightEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelOffscreenRender::updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap)
|
void ModelOffscreenRender::updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap)
|
||||||
{
|
{
|
||||||
delete m_normalMap;
|
delete m_normalMap;
|
||||||
|
@ -124,7 +139,12 @@ QImage ModelOffscreenRender::toImage(const QSize &size)
|
||||||
ModelShaderProgram *program = new ModelShaderProgram(isCoreProfile);
|
ModelShaderProgram *program = new ModelShaderProgram(isCoreProfile);
|
||||||
ModelMeshBinder meshBinder;
|
ModelMeshBinder meshBinder;
|
||||||
meshBinder.initialize();
|
meshBinder.initialize();
|
||||||
meshBinder.hideWireframes();
|
if (m_isWireframeVisible)
|
||||||
|
meshBinder.showWireframe();
|
||||||
|
else
|
||||||
|
meshBinder.hideWireframe();
|
||||||
|
if (m_isEnvironmentLightEnabled)
|
||||||
|
meshBinder.enableEnvironmentLight();
|
||||||
if (nullptr != m_normalMap && nullptr != m_depthMap) {
|
if (nullptr != m_normalMap && nullptr != m_depthMap) {
|
||||||
meshBinder.updateToonNormalAndDepthMaps(m_normalMap, m_depthMap);
|
meshBinder.updateToonNormalAndDepthMaps(m_normalMap, m_depthMap);
|
||||||
m_normalMap = nullptr;
|
m_normalMap = nullptr;
|
||||||
|
@ -135,7 +155,7 @@ QImage ModelOffscreenRender::toImage(const QSize &size)
|
||||||
m_context->functions()->glEnable(GL_BLEND);
|
m_context->functions()->glEnable(GL_BLEND);
|
||||||
m_context->functions()->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
m_context->functions()->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
m_context->functions()->glEnable(GL_DEPTH_TEST);
|
m_context->functions()->glEnable(GL_DEPTH_TEST);
|
||||||
m_context->functions()->glEnable(GL_CULL_FACE);
|
//m_context->functions()->glEnable(GL_CULL_FACE);
|
||||||
#ifdef GL_LINE_SMOOTH
|
#ifdef GL_LINE_SMOOTH
|
||||||
m_context->functions()->glEnable(GL_LINE_SMOOTH);
|
m_context->functions()->glEnable(GL_LINE_SMOOTH);
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,6 +166,7 @@ QImage ModelOffscreenRender::toImage(const QSize &size)
|
||||||
world.rotate(m_zRot / 16.0f, 0, 0, 1);
|
world.rotate(m_zRot / 16.0f, 0, 0, 1);
|
||||||
|
|
||||||
projection.setToIdentity();
|
projection.setToIdentity();
|
||||||
|
projection.translate(m_moveToPosition.x(), m_moveToPosition.y(), m_moveToPosition.z());
|
||||||
projection.perspective(45.0f, GLfloat(size.width()) / size.height(), 0.01f, 100.0f);
|
projection.perspective(45.0f, GLfloat(size.width()) / size.height(), 0.01f, 100.0f);
|
||||||
|
|
||||||
camera.setToIdentity();
|
camera.setToIdentity();
|
||||||
|
|
|
@ -20,8 +20,11 @@ public:
|
||||||
void setYRotation(int angle);
|
void setYRotation(int angle);
|
||||||
void setZRotation(int angle);
|
void setZRotation(int angle);
|
||||||
void setEyePosition(const QVector3D &eyePosition);
|
void setEyePosition(const QVector3D &eyePosition);
|
||||||
|
void setMoveToPosition(const QVector3D &moveToPosition);
|
||||||
void setRenderPurpose(int purpose);
|
void setRenderPurpose(int purpose);
|
||||||
void setRenderThread(QThread *thread);
|
void setRenderThread(QThread *thread);
|
||||||
|
void enableWireframe();
|
||||||
|
void enableEnvironmentLight();
|
||||||
void updateMesh(Model *mesh);
|
void updateMesh(Model *mesh);
|
||||||
void updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
|
void updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
|
||||||
void setToonShading(bool toonShading);
|
void setToonShading(bool toonShading);
|
||||||
|
@ -31,6 +34,7 @@ private:
|
||||||
int m_yRot = 0;
|
int m_yRot = 0;
|
||||||
int m_zRot = 0;
|
int m_zRot = 0;
|
||||||
QVector3D m_eyePosition;
|
QVector3D m_eyePosition;
|
||||||
|
QVector3D m_moveToPosition;
|
||||||
int m_renderPurpose = 0;
|
int m_renderPurpose = 0;
|
||||||
QOpenGLContext *m_context = nullptr;
|
QOpenGLContext *m_context = nullptr;
|
||||||
QOpenGLFramebufferObject *m_renderFbo = nullptr;
|
QOpenGLFramebufferObject *m_renderFbo = nullptr;
|
||||||
|
@ -38,6 +42,8 @@ private:
|
||||||
QImage *m_normalMap = nullptr;
|
QImage *m_normalMap = nullptr;
|
||||||
QImage *m_depthMap = nullptr;
|
QImage *m_depthMap = nullptr;
|
||||||
bool m_toonShading = false;
|
bool m_toonShading = false;
|
||||||
|
bool m_isWireframeVisible = false;
|
||||||
|
bool m_isEnvironmentLightEnabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -61,6 +61,18 @@ const QVector3D &ModelWidget::eyePosition()
|
||||||
return m_eyePosition;
|
return m_eyePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QVector3D &ModelWidget::moveToPosition()
|
||||||
|
{
|
||||||
|
return m_moveToPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelWidget::setEyePosition(const QVector3D &eyePosition)
|
||||||
|
{
|
||||||
|
m_eyePosition = eyePosition;
|
||||||
|
emit eyePositionChanged(m_eyePosition);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void ModelWidget::reRender()
|
void ModelWidget::reRender()
|
||||||
{
|
{
|
||||||
emit renderParametersChanged();
|
emit renderParametersChanged();
|
||||||
|
@ -174,13 +186,24 @@ void ModelWidget::initializeGL()
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelWidget::disableCullFace()
|
||||||
|
{
|
||||||
|
m_enableCullFace = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelWidget::setMoveToPosition(const QVector3D &moveToPosition)
|
||||||
|
{
|
||||||
|
m_moveToPosition = moveToPosition;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelWidget::paintGL()
|
void ModelWidget::paintGL()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
if (m_enableCullFace)
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
#ifdef GL_LINE_SMOOTH
|
#ifdef GL_LINE_SMOOTH
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
#endif
|
#endif
|
||||||
|
@ -227,12 +250,18 @@ void ModelWidget::paintGL()
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelWidget::updateProjectionMatrix()
|
||||||
|
{
|
||||||
|
m_projection.setToIdentity();
|
||||||
|
m_projection.translate(m_moveToPosition.x(), m_moveToPosition.y(), m_moveToPosition.z());
|
||||||
|
m_projection.perspective(45.0f, GLfloat(width()) / height(), 0.01f, 100.0f);
|
||||||
|
}
|
||||||
|
|
||||||
void ModelWidget::resizeGL(int w, int h)
|
void ModelWidget::resizeGL(int w, int h)
|
||||||
{
|
{
|
||||||
m_widthInPixels = w * window()->devicePixelRatio();
|
m_widthInPixels = w * window()->devicePixelRatio();
|
||||||
m_heightInPixels = h * window()->devicePixelRatio();
|
m_heightInPixels = h * window()->devicePixelRatio();
|
||||||
m_projection.setToIdentity();
|
updateProjectionMatrix();
|
||||||
m_projection.perspective(45.0f, GLfloat(w) / h, 0.01f, 100.0f);
|
|
||||||
emit renderParametersChanged();
|
emit renderParametersChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,19 +280,29 @@ std::pair<QVector3D, QVector3D> ModelWidget::screenPositionToMouseRay(const QPoi
|
||||||
|
|
||||||
void ModelWidget::toggleWireframe()
|
void ModelWidget::toggleWireframe()
|
||||||
{
|
{
|
||||||
if (m_meshBinder.isWireframesVisible())
|
if (m_meshBinder.isWireframeVisible())
|
||||||
m_meshBinder.hideWireframes();
|
m_meshBinder.hideWireframe();
|
||||||
else
|
else
|
||||||
m_meshBinder.showWireframes();
|
m_meshBinder.showWireframe();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModelWidget::isWireframeVisible()
|
||||||
|
{
|
||||||
|
return m_meshBinder.isWireframeVisible();
|
||||||
|
}
|
||||||
|
|
||||||
void ModelWidget::enableEnvironmentLight()
|
void ModelWidget::enableEnvironmentLight()
|
||||||
{
|
{
|
||||||
m_meshBinder.enableEnvironmentLight();
|
m_meshBinder.enableEnvironmentLight();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModelWidget::isEnvironmentLightEnabled()
|
||||||
|
{
|
||||||
|
return m_meshBinder.isEnvironmentLightEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
void ModelWidget::toggleRotation()
|
void ModelWidget::toggleRotation()
|
||||||
{
|
{
|
||||||
if (nullptr != m_rotationTimer) {
|
if (nullptr != m_rotationTimer) {
|
||||||
|
@ -329,6 +368,11 @@ bool ModelWidget::inputMouseReleaseEventFromOtherWidget(QMouseEvent *event)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelWidget::canvasResized()
|
||||||
|
{
|
||||||
|
resize(parentWidget()->size());
|
||||||
|
}
|
||||||
|
|
||||||
bool ModelWidget::inputMouseMoveEventFromOtherWidget(QMouseEvent *event)
|
bool ModelWidget::inputMouseMoveEventFromOtherWidget(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QPoint pos = convertInputPosFromOtherWidget(event);
|
QPoint pos = convertInputPosFromOtherWidget(event);
|
||||||
|
@ -349,10 +393,27 @@ bool ModelWidget::inputMouseMoveEventFromOtherWidget(QMouseEvent *event)
|
||||||
(m_moveStarted && (event->buttons() & Qt::LeftButton))) {
|
(m_moveStarted && (event->buttons() & Qt::LeftButton))) {
|
||||||
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
|
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
|
||||||
if (m_moveStarted) {
|
if (m_moveStarted) {
|
||||||
QRect rect = m_moveStartGeometry;
|
if (m_moveAndZoomByWindow) {
|
||||||
QPoint posInParent = mapToParent(pos);
|
QPoint posInParent = mapToParent(pos);
|
||||||
rect.translate(posInParent.x() - m_moveStartPos.x(), posInParent.y() - m_moveStartPos.y());
|
QRect rect = m_moveStartGeometry;
|
||||||
setGeometry(rect);
|
rect.translate(posInParent.x() - m_moveStartPos.x(), posInParent.y() - m_moveStartPos.y());
|
||||||
|
setGeometry(rect);
|
||||||
|
} else {
|
||||||
|
m_moveToPosition.setX(m_moveToPosition.x() + (float)2 * dx / width());
|
||||||
|
m_moveToPosition.setY(m_moveToPosition.y() + (float)2 * -dy / height());
|
||||||
|
if (m_moveToPosition.x() < -1.0)
|
||||||
|
m_moveToPosition.setX(-1.0);
|
||||||
|
if (m_moveToPosition.x() > 1.0)
|
||||||
|
m_moveToPosition.setX(1.0);
|
||||||
|
if (m_moveToPosition.y() < -1.0)
|
||||||
|
m_moveToPosition.setY(-1.0);
|
||||||
|
if (m_moveToPosition.y() > 1.0)
|
||||||
|
m_moveToPosition.setY(1.0);
|
||||||
|
updateProjectionMatrix();
|
||||||
|
emit moveToPositionChanged(m_moveToPosition);
|
||||||
|
emit renderParametersChanged();
|
||||||
|
update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setXRotation(m_xRot + 8 * dy);
|
setXRotation(m_xRot + 8 * dy);
|
||||||
|
@ -394,22 +455,34 @@ bool ModelWidget::inputWheelEventFromOtherWidget(QWheelEvent *event)
|
||||||
|
|
||||||
void ModelWidget::zoom(float delta)
|
void ModelWidget::zoom(float delta)
|
||||||
{
|
{
|
||||||
QMargins margins(delta, delta, delta, delta);
|
if (m_moveAndZoomByWindow) {
|
||||||
if (0 == m_modelInitialHeight) {
|
QMargins margins(delta, delta, delta, delta);
|
||||||
m_modelInitialHeight = height();
|
if (0 == m_modelInitialHeight) {
|
||||||
} else {
|
m_modelInitialHeight = height();
|
||||||
float ratio = (float)height() / m_modelInitialHeight;
|
} else {
|
||||||
if (ratio <= m_minZoomRatio) {
|
float ratio = (float)height() / m_modelInitialHeight;
|
||||||
if (delta < 0)
|
if (ratio <= m_minZoomRatio) {
|
||||||
return;
|
if (delta < 0)
|
||||||
} else if (ratio >= m_maxZoomRatio) {
|
return;
|
||||||
if (delta > 0)
|
} else if (ratio >= m_maxZoomRatio) {
|
||||||
return;
|
if (delta > 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
setGeometry(geometry().marginsAdded(margins));
|
||||||
|
emit renderParametersChanged();
|
||||||
|
update();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
m_eyePosition += QVector3D(0, 0, m_eyePosition.z() * (delta > 0 ? -0.1 : 0.1));
|
||||||
|
if (m_eyePosition.z() < -15)
|
||||||
|
m_eyePosition.setZ(-15);
|
||||||
|
else if (m_eyePosition.z() > -0.1)
|
||||||
|
m_eyePosition.setZ(-0.1);
|
||||||
|
emit eyePositionChanged(m_eyePosition);
|
||||||
|
emit renderParametersChanged();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
setGeometry(geometry().marginsAdded(margins));
|
|
||||||
emit renderParametersChanged();
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelWidget::setMousePickTargetPositionInModelSpace(QVector3D position)
|
void ModelWidget::setMousePickTargetPositionInModelSpace(QVector3D position)
|
||||||
|
@ -467,6 +540,11 @@ void ModelWidget::enableMousePicking(bool enabled)
|
||||||
m_mousePickingEnabled = enabled;
|
m_mousePickingEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelWidget::setMoveAndZoomByWindow(bool byWindow)
|
||||||
|
{
|
||||||
|
m_moveAndZoomByWindow = byWindow;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelWidget::mousePressEvent(QMouseEvent *event)
|
void ModelWidget::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
inputMousePressEventFromOtherWidget(event);
|
inputMousePressEventFromOtherWidget(event);
|
||||||
|
|
|
@ -24,6 +24,11 @@ signals:
|
||||||
void mouseReleased();
|
void mouseReleased();
|
||||||
void addMouseRadius(float radius);
|
void addMouseRadius(float radius);
|
||||||
void renderParametersChanged();
|
void renderParametersChanged();
|
||||||
|
void xRotationChanged(int angle);
|
||||||
|
void yRotationChanged(int angle);
|
||||||
|
void zRotationChanged(int angle);
|
||||||
|
void eyePositionChanged(const QVector3D &eyePosition);
|
||||||
|
void moveToPositionChanged(const QVector3D &moveToPosition);
|
||||||
public:
|
public:
|
||||||
ModelWidget(QWidget *parent = 0);
|
ModelWidget(QWidget *parent = 0);
|
||||||
~ModelWidget();
|
~ModelWidget();
|
||||||
|
@ -39,12 +44,17 @@ public:
|
||||||
void updateMesh(Model *mesh);
|
void updateMesh(Model *mesh);
|
||||||
void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions);
|
void setGraphicsFunctions(SkeletonGraphicsFunctions *graphicsFunctions);
|
||||||
void toggleWireframe();
|
void toggleWireframe();
|
||||||
|
bool isWireframeVisible();
|
||||||
void toggleRotation();
|
void toggleRotation();
|
||||||
void toggleUvCheck();
|
void toggleUvCheck();
|
||||||
void enableEnvironmentLight();
|
void enableEnvironmentLight();
|
||||||
|
bool isEnvironmentLightEnabled();
|
||||||
void enableMove(bool enabled);
|
void enableMove(bool enabled);
|
||||||
void enableZoom(bool enabled);
|
void enableZoom(bool enabled);
|
||||||
void enableMousePicking(bool enabled);
|
void enableMousePicking(bool enabled);
|
||||||
|
void setMoveAndZoomByWindow(bool byWindow);
|
||||||
|
void disableCullFace();
|
||||||
|
void setMoveToPosition(const QVector3D &moveToPosition);
|
||||||
bool inputMousePressEventFromOtherWidget(QMouseEvent *event);
|
bool inputMousePressEventFromOtherWidget(QMouseEvent *event);
|
||||||
bool inputMouseMoveEventFromOtherWidget(QMouseEvent *event);
|
bool inputMouseMoveEventFromOtherWidget(QMouseEvent *event);
|
||||||
bool inputWheelEventFromOtherWidget(QWheelEvent *event);
|
bool inputWheelEventFromOtherWidget(QWheelEvent *event);
|
||||||
|
@ -58,15 +68,13 @@ public slots:
|
||||||
void setXRotation(int angle);
|
void setXRotation(int angle);
|
||||||
void setYRotation(int angle);
|
void setYRotation(int angle);
|
||||||
void setZRotation(int angle);
|
void setZRotation(int angle);
|
||||||
|
void setEyePosition(const QVector3D &eyePosition);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void zoom(float delta);
|
void zoom(float delta);
|
||||||
void setMousePickTargetPositionInModelSpace(QVector3D position);
|
void setMousePickTargetPositionInModelSpace(QVector3D position);
|
||||||
void setMousePickRadius(float radius);
|
void setMousePickRadius(float radius);
|
||||||
void reRender();
|
void reRender();
|
||||||
signals:
|
void canvasResized();
|
||||||
void xRotationChanged(int angle);
|
|
||||||
void yRotationChanged(int angle);
|
|
||||||
void zRotationChanged(int angle);
|
|
||||||
protected:
|
protected:
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void paintGL() override;
|
void paintGL() override;
|
||||||
|
@ -80,6 +88,7 @@ public:
|
||||||
int yRot();
|
int yRot();
|
||||||
int zRot();
|
int zRot();
|
||||||
const QVector3D &eyePosition();
|
const QVector3D &eyePosition();
|
||||||
|
const QVector3D &moveToPosition();
|
||||||
private:
|
private:
|
||||||
int m_xRot;
|
int m_xRot;
|
||||||
int m_yRot;
|
int m_yRot;
|
||||||
|
@ -107,7 +116,11 @@ private:
|
||||||
QTimer *m_rotationTimer = nullptr;
|
QTimer *m_rotationTimer = nullptr;
|
||||||
int m_widthInPixels = 0;
|
int m_widthInPixels = 0;
|
||||||
int m_heightInPixels = 0;
|
int m_heightInPixels = 0;
|
||||||
|
QVector3D m_moveToPosition;
|
||||||
|
bool m_moveAndZoomByWindow = true;
|
||||||
|
bool m_enableCullFace = true;
|
||||||
std::pair<QVector3D, QVector3D> screenPositionToMouseRay(const QPoint &screenPosition);
|
std::pair<QVector3D, QVector3D> screenPositionToMouseRay(const QPoint &screenPosition);
|
||||||
|
void updateProjectionMatrix();
|
||||||
public:
|
public:
|
||||||
static int m_defaultXRotation;
|
static int m_defaultXRotation;
|
||||||
static int m_defaultYRotation;
|
static int m_defaultYRotation;
|
||||||
|
|
|
@ -34,6 +34,7 @@ ModelOffscreenRender *NormalAndDepthMapsGenerator::createOfflineRender(ModelWidg
|
||||||
offlineRender->setYRotation(modelWidget->yRot());
|
offlineRender->setYRotation(modelWidget->yRot());
|
||||||
offlineRender->setZRotation(modelWidget->zRot());
|
offlineRender->setZRotation(modelWidget->zRot());
|
||||||
offlineRender->setEyePosition(modelWidget->eyePosition());
|
offlineRender->setEyePosition(modelWidget->eyePosition());
|
||||||
|
offlineRender->setMoveToPosition(modelWidget->moveToPosition());
|
||||||
offlineRender->setRenderPurpose(purpose);
|
offlineRender->setRenderPurpose(purpose);
|
||||||
return offlineRender;
|
return offlineRender;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue