Add UV map generator

master
Jeremy HU 2022-10-25 22:31:44 +11:00
parent 5fc51c3b02
commit d991f0c532
5 changed files with 83 additions and 55 deletions

View File

@ -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

View File

@ -0,0 +1,54 @@
#include "uv_map_generator.h"
#include "image_forever.h"
#include <dust3d/uv/uv_map_packer.h>
UvMapGenerator::UvMapGenerator(std::unique_ptr<dust3d::Object> object, std::unique_ptr<dust3d::Snapshot> snapshot)
: m_object(std::move(object))
, m_snapshot(std::move(snapshot))
{
}
void UvMapGenerator::process()
{
generate();
emit finished();
}
std::unique_ptr<dust3d::Object> 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<dust3d::UvMapPacker>();
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:
}

View File

@ -0,0 +1,27 @@
#ifndef DUST3D_APPLICATION_UV_MAP_GENERATOR_H_
#define DUST3D_APPLICATION_UV_MAP_GENERATOR_H_
#include <QObject>
#include <dust3d/base/object.h>
#include <dust3d/base/snapshot.h>
#include <dust3d/uv/uv_map_packer.h>
#include <memory>
class UvMapGenerator : public QObject {
Q_OBJECT
public:
UvMapGenerator(std::unique_ptr<dust3d::Object> object, std::unique_ptr<dust3d::Snapshot> snapshot);
void generate();
std::unique_ptr<dust3d::Object> takeObject();
signals:
void finished();
public slots:
void process();
private:
std::unique_ptr<dust3d::Object> m_object;
std::unique_ptr<dust3d::Snapshot> m_snapshot;
std::unique_ptr<dust3d::UvMapPacker> m_mapPacker;
};
#endif

View File

@ -1,26 +0,0 @@
#include "uv_preview_image_generator.h"
const size_t UvPreviewImageGenerator::m_uvImageSize = 1024;
UvPreviewImageGenerator::UvPreviewImageGenerator(std::vector<std::vector<dust3d::Vector2>>&& faceUvs)
: m_faceUvs(faceUvs)
{
}
std::unique_ptr<QImage> UvPreviewImageGenerator::takePreviewImage()
{
return std::move(m_previewImage);
}
void UvPreviewImageGenerator::generate()
{
m_previewImage = std::make_unique<QImage>(m_uvImageSize, m_uvImageSize, QImage::Format_ARGB32);
m_previewImage->fill(Qt::white);
// TODO:
}
void UvPreviewImageGenerator::process()
{
generate();
emit finished();
}

View File

@ -1,27 +0,0 @@
#ifndef DUST3D_APPLICATION_UV_PREVIEW_IMAGE_GENERATOR_H_
#define DUST3D_APPLICATION_UV_PREVIEW_IMAGE_GENERATOR_H_
#include <QImage>
#include <QObject>
#include <dust3d/base/vector2.h>
#include <memory>
#include <vector>
class UvPreviewImageGenerator : public QObject {
Q_OBJECT
public:
UvPreviewImageGenerator(std::vector<std::vector<dust3d::Vector2>>&& faceUvs);
std::unique_ptr<QImage> takePreviewImage();
void generate();
signals:
void finished();
public slots:
void process();
private:
std::vector<std::vector<dust3d::Vector2>> m_faceUvs;
std::unique_ptr<QImage> m_previewImage;
static const size_t m_uvImageSize;
};
#endif