diff --git a/application/application.pro b/application/application.pro index 0d96e57b..98a4716a 100644 --- a/application/application.pro +++ b/application/application.pro @@ -201,14 +201,14 @@ HEADERS += sources/theme.h SOURCES += sources/theme.cc HEADERS += sources/toolbar_button.h SOURCES += sources/toolbar_button.cc -HEADERS += sources/uv_preview_image_generator.h -SOURCES += sources/uv_preview_image_generator.cc HEADERS += sources/turnaround_loader.h SOURCES += sources/turnaround_loader.cc HEADERS += sources/updates_check_widget.h SOURCES += sources/updates_check_widget.cc HEADERS += sources/updates_checker.h SOURCES += sources/updates_checker.cc +HEADERS += sources/uv_map_generator.h +SOURCES += sources/uv_map_generator.cc HEADERS += sources/version.h INCLUDEPATH += third_party/QtWaitingSpinner SOURCES += third_party/QtWaitingSpinner/waitingspinnerwidget.cpp diff --git a/application/sources/uv_map_generator.cc b/application/sources/uv_map_generator.cc new file mode 100644 index 00000000..45e59a74 --- /dev/null +++ b/application/sources/uv_map_generator.cc @@ -0,0 +1,54 @@ +#include "uv_map_generator.h" +#include "image_forever.h" +#include + +UvMapGenerator::UvMapGenerator(std::unique_ptr object, std::unique_ptr snapshot) + : m_object(std::move(object)) + , m_snapshot(std::move(snapshot)) +{ +} + +void UvMapGenerator::process() +{ + generate(); + emit finished(); +} + +std::unique_ptr UvMapGenerator::takeObject() +{ + return std::move(m_object); +} + +void UvMapGenerator::generate() +{ + if (nullptr == m_object) + return; + + if (nullptr == m_snapshot) + return; + + m_mapPacker = std::make_unique(); + + for (const auto& partIt : m_snapshot->parts) { + const auto& colorImageIdIt = partIt.second.find("colorImageId"); + if (colorImageIdIt == partIt.second.end()) + continue; + auto imageId = dust3d::Uuid(colorImageIdIt->second); + const QImage* image = ImageForever::get(imageId); + if (nullptr == image) + continue; + const auto& findUvs = m_object->partTriangleUvs.find(dust3d::Uuid(partIt.first)); + if (findUvs == m_object->partTriangleUvs.end()) + continue; + dust3d::UvMapPacker::Part part; + part.id = imageId; + part.width = image->width(); + part.height = image->height(); + part.localUv = findUvs->second; + m_mapPacker->addPart(part); + } + + m_mapPacker->pack(); + + // TODO: +} diff --git a/application/sources/uv_map_generator.h b/application/sources/uv_map_generator.h new file mode 100644 index 00000000..6afceeff --- /dev/null +++ b/application/sources/uv_map_generator.h @@ -0,0 +1,27 @@ +#ifndef DUST3D_APPLICATION_UV_MAP_GENERATOR_H_ +#define DUST3D_APPLICATION_UV_MAP_GENERATOR_H_ + +#include +#include +#include +#include +#include + +class UvMapGenerator : public QObject { + Q_OBJECT +public: + UvMapGenerator(std::unique_ptr object, std::unique_ptr snapshot); + void generate(); + std::unique_ptr takeObject(); +signals: + void finished(); +public slots: + void process(); + +private: + std::unique_ptr m_object; + std::unique_ptr m_snapshot; + std::unique_ptr m_mapPacker; +}; + +#endif diff --git a/application/sources/uv_preview_image_generator.cc b/application/sources/uv_preview_image_generator.cc deleted file mode 100644 index 3160c583..00000000 --- a/application/sources/uv_preview_image_generator.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include "uv_preview_image_generator.h" - -const size_t UvPreviewImageGenerator::m_uvImageSize = 1024; - -UvPreviewImageGenerator::UvPreviewImageGenerator(std::vector>&& faceUvs) - : m_faceUvs(faceUvs) -{ -} - -std::unique_ptr UvPreviewImageGenerator::takePreviewImage() -{ - return std::move(m_previewImage); -} - -void UvPreviewImageGenerator::generate() -{ - m_previewImage = std::make_unique(m_uvImageSize, m_uvImageSize, QImage::Format_ARGB32); - m_previewImage->fill(Qt::white); - // TODO: -} - -void UvPreviewImageGenerator::process() -{ - generate(); - emit finished(); -} diff --git a/application/sources/uv_preview_image_generator.h b/application/sources/uv_preview_image_generator.h deleted file mode 100644 index 5c36fd0c..00000000 --- a/application/sources/uv_preview_image_generator.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef DUST3D_APPLICATION_UV_PREVIEW_IMAGE_GENERATOR_H_ -#define DUST3D_APPLICATION_UV_PREVIEW_IMAGE_GENERATOR_H_ - -#include -#include -#include -#include -#include - -class UvPreviewImageGenerator : public QObject { - Q_OBJECT -public: - UvPreviewImageGenerator(std::vector>&& faceUvs); - std::unique_ptr takePreviewImage(); - void generate(); -signals: - void finished(); -public slots: - void process(); - -private: - std::vector> m_faceUvs; - std::unique_ptr m_previewImage; - static const size_t m_uvImageSize; -}; - -#endif