2021-11-18 14:58:01 +00:00
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include <QDebug>
|
|
|
|
#include "mesh_generator.h"
|
|
|
|
#include "cut_face_preview.h"
|
|
|
|
|
|
|
|
MeshGenerator::MeshGenerator(dust3d::Snapshot *snapshot) :
|
|
|
|
dust3d::MeshGenerator(snapshot)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MeshGenerator::~MeshGenerator()
|
|
|
|
{
|
|
|
|
for (auto &it: m_partPreviewImages)
|
|
|
|
delete it.second;
|
|
|
|
for (auto &it: m_partPreviewMeshes)
|
|
|
|
delete it.second;
|
|
|
|
delete m_resultMesh;
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:54:49 +00:00
|
|
|
ModelMesh *MeshGenerator::takePartPreviewMesh(const dust3d::Uuid &partId)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
2022-09-23 15:54:49 +00:00
|
|
|
ModelMesh *resultMesh = m_partPreviewMeshes[partId];
|
2021-11-18 14:58:01 +00:00
|
|
|
m_partPreviewMeshes[partId] = nullptr;
|
|
|
|
return resultMesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage *MeshGenerator::takePartPreviewImage(const dust3d::Uuid &partId)
|
|
|
|
{
|
|
|
|
QImage *image = m_partPreviewImages[partId];
|
|
|
|
m_partPreviewImages[partId] = nullptr;
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:54:49 +00:00
|
|
|
MonochromeMesh *MeshGenerator::takeWireframeMesh()
|
|
|
|
{
|
|
|
|
return m_wireframeMesh.release();
|
|
|
|
}
|
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
void MeshGenerator::process()
|
|
|
|
{
|
|
|
|
QElapsedTimer countTimeConsumed;
|
|
|
|
countTimeConsumed.start();
|
|
|
|
|
|
|
|
generate();
|
|
|
|
|
|
|
|
if (nullptr != m_object)
|
2022-09-23 15:54:49 +00:00
|
|
|
m_resultMesh = new ModelMesh(*m_object);
|
2021-11-18 14:58:01 +00:00
|
|
|
|
|
|
|
for (const auto &partId: m_generatedPreviewImagePartIds) {
|
|
|
|
auto it = m_generatedPartPreviews.find(partId);
|
|
|
|
if (it == m_generatedPartPreviews.end())
|
|
|
|
continue;
|
|
|
|
m_partPreviewImages[partId] = buildCutFaceTemplatePreviewImage(it->second.cutTemplate);
|
|
|
|
}
|
|
|
|
for (const auto &partId: m_generatedPreviewPartIds) {
|
|
|
|
auto it = m_generatedPartPreviews.find(partId);
|
|
|
|
if (it == m_generatedPartPreviews.end())
|
|
|
|
continue;
|
2022-09-23 15:54:49 +00:00
|
|
|
m_partPreviewMeshes[partId] = new ModelMesh(it->second.vertices,
|
2021-11-18 14:58:01 +00:00
|
|
|
it->second.triangles,
|
|
|
|
it->second.vertexNormals,
|
|
|
|
it->second.color,
|
|
|
|
it->second.metalness,
|
|
|
|
it->second.roughness);
|
|
|
|
}
|
2022-09-23 15:54:49 +00:00
|
|
|
|
|
|
|
if (nullptr != m_object)
|
|
|
|
m_wireframeMesh = std::make_unique<MonochromeMesh>(*m_object);
|
2021-11-18 14:58:01 +00:00
|
|
|
|
|
|
|
qDebug() << "The mesh generation took" << countTimeConsumed.elapsed() << "milliseconds";
|
|
|
|
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:54:49 +00:00
|
|
|
ModelMesh *MeshGenerator::takeResultMesh()
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
2022-09-23 15:54:49 +00:00
|
|
|
ModelMesh *resultMesh = m_resultMesh;
|
2021-11-18 14:58:01 +00:00
|
|
|
m_resultMesh = nullptr;
|
|
|
|
return resultMesh;
|
|
|
|
}
|
|
|
|
|