2020-10-15 10:06:28 +00:00
|
|
|
#include <QDebug>
|
2021-11-18 14:58:01 +00:00
|
|
|
#include "part_preview_images_generator.h"
|
2020-10-15 10:06:28 +00:00
|
|
|
#include "theme.h"
|
|
|
|
|
2022-09-23 15:54:49 +00:00
|
|
|
void PartPreviewImagesGenerator::addPart(const dust3d::Uuid &partId, ModelMesh *previewMesh, bool isCutFace)
|
2020-10-15 10:06:28 +00:00
|
|
|
{
|
|
|
|
m_partPreviews.insert({partId, {previewMesh, isCutFace}});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PartPreviewImagesGenerator::process()
|
|
|
|
{
|
|
|
|
generate();
|
|
|
|
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
std::map<dust3d::Uuid, QImage> *PartPreviewImagesGenerator::takePartImages()
|
2020-10-15 10:06:28 +00:00
|
|
|
{
|
2021-11-18 14:58:01 +00:00
|
|
|
std::map<dust3d::Uuid, QImage> *partImages = m_partImages;
|
2020-10-15 10:06:28 +00:00
|
|
|
m_partImages = nullptr;
|
|
|
|
return partImages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PartPreviewImagesGenerator::generate()
|
|
|
|
{
|
|
|
|
delete m_partImages;
|
2021-11-18 14:58:01 +00:00
|
|
|
m_partImages = new std::map<dust3d::Uuid, QImage>;
|
2020-10-15 10:06:28 +00:00
|
|
|
|
|
|
|
m_offscreenRender->setZRotation(0);
|
|
|
|
m_offscreenRender->setEyePosition(QVector3D(0, 0, -4.0));
|
|
|
|
for (auto &it: m_partPreviews) {
|
|
|
|
if (it.second.isCutFace) {
|
|
|
|
m_offscreenRender->setXRotation(0);
|
|
|
|
m_offscreenRender->setYRotation(0);
|
|
|
|
} else {
|
|
|
|
m_offscreenRender->setXRotation(30 * 16);
|
|
|
|
m_offscreenRender->setYRotation(-45 * 16);
|
|
|
|
}
|
|
|
|
m_offscreenRender->updateMesh(it.second.mesh);
|
|
|
|
it.second.mesh = nullptr;
|
|
|
|
(*m_partImages)[it.first] = m_offscreenRender->toImage(QSize(Theme::partPreviewImageSize, Theme::partPreviewImageSize));
|
|
|
|
}
|
|
|
|
}
|