2020-04-07 23:15:20 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QGuiApplication>
|
2020-04-02 10:39:57 +00:00
|
|
|
#include "normalanddepthmapsgenerator.h"
|
|
|
|
|
|
|
|
NormalAndDepthMapsGenerator::NormalAndDepthMapsGenerator(ModelWidget *modelWidget)
|
|
|
|
{
|
|
|
|
m_viewPortSize = QSize(modelWidget->widthInPixels(),
|
|
|
|
modelWidget->heightInPixels());
|
|
|
|
m_normalMapRender = createOfflineRender(modelWidget, 1);
|
|
|
|
m_depthMapRender = createOfflineRender(modelWidget, 2);
|
|
|
|
}
|
|
|
|
|
2020-04-07 23:15:20 +00:00
|
|
|
void NormalAndDepthMapsGenerator::updateMesh(Model *mesh)
|
2020-04-02 10:39:57 +00:00
|
|
|
{
|
|
|
|
if (nullptr == mesh) {
|
|
|
|
m_normalMapRender->updateMesh(nullptr);
|
|
|
|
m_depthMapRender->updateMesh(nullptr);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-07 23:15:20 +00:00
|
|
|
m_normalMapRender->updateMesh(new Model(*mesh));
|
2020-04-02 10:39:57 +00:00
|
|
|
m_depthMapRender->updateMesh(mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NormalAndDepthMapsGenerator::setRenderThread(QThread *thread)
|
|
|
|
{
|
2020-04-07 23:15:20 +00:00
|
|
|
m_normalMapRender->setRenderThread(thread);
|
|
|
|
m_depthMapRender->setRenderThread(thread);
|
2020-04-02 10:39:57 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 23:15:20 +00:00
|
|
|
ModelOffscreenRender *NormalAndDepthMapsGenerator::createOfflineRender(ModelWidget *modelWidget, int purpose)
|
2020-04-02 10:39:57 +00:00
|
|
|
{
|
2020-04-07 23:15:20 +00:00
|
|
|
ModelOffscreenRender *offlineRender = new ModelOffscreenRender(modelWidget->format());
|
2020-04-02 10:39:57 +00:00
|
|
|
offlineRender->setXRotation(modelWidget->xRot());
|
|
|
|
offlineRender->setYRotation(modelWidget->yRot());
|
|
|
|
offlineRender->setZRotation(modelWidget->zRot());
|
2020-04-13 13:25:04 +00:00
|
|
|
offlineRender->setEyePosition(modelWidget->eyePosition());
|
2020-04-15 14:05:04 +00:00
|
|
|
offlineRender->setMoveToPosition(modelWidget->moveToPosition());
|
2020-04-02 10:39:57 +00:00
|
|
|
offlineRender->setRenderPurpose(purpose);
|
|
|
|
return offlineRender;
|
|
|
|
}
|
|
|
|
|
|
|
|
NormalAndDepthMapsGenerator::~NormalAndDepthMapsGenerator()
|
|
|
|
{
|
|
|
|
delete m_normalMapRender;
|
|
|
|
delete m_depthMapRender;
|
|
|
|
delete m_normalMap;
|
|
|
|
delete m_depthMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NormalAndDepthMapsGenerator::generate()
|
|
|
|
{
|
|
|
|
m_normalMap = new QImage(m_normalMapRender->toImage(m_viewPortSize));
|
|
|
|
m_depthMap = new QImage(m_depthMapRender->toImage(m_viewPortSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NormalAndDepthMapsGenerator::process()
|
|
|
|
{
|
|
|
|
generate();
|
2020-04-07 23:15:20 +00:00
|
|
|
m_normalMapRender->setRenderThread(QGuiApplication::instance()->thread());
|
|
|
|
m_depthMapRender->setRenderThread(QGuiApplication::instance()->thread());
|
|
|
|
this->moveToThread(QGuiApplication::instance()->thread());
|
2020-04-02 10:39:57 +00:00
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage *NormalAndDepthMapsGenerator::takeNormalMap()
|
|
|
|
{
|
|
|
|
QImage *normalMap = m_normalMap;
|
|
|
|
m_normalMap = nullptr;
|
|
|
|
return normalMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage *NormalAndDepthMapsGenerator::takeDepthMap()
|
|
|
|
{
|
|
|
|
QImage *depthMap = m_depthMap;
|
|
|
|
m_depthMap = nullptr;
|
|
|
|
return depthMap;
|
|
|
|
}
|