dust3d/application/sources/mesh_generator.cc

82 lines
2.2 KiB
C++
Raw Normal View History

#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)
{
2022-09-23 15:54:49 +00:00
ModelMesh *resultMesh = m_partPreviewMeshes[partId];
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();
}
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);
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,
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);
qDebug() << "The mesh generation took" << countTimeConsumed.elapsed() << "milliseconds";
emit finished();
}
2022-09-23 15:54:49 +00:00
ModelMesh *MeshGenerator::takeResultMesh()
{
2022-09-23 15:54:49 +00:00
ModelMesh *resultMesh = m_resultMesh;
m_resultMesh = nullptr;
return resultMesh;
}