Fix texture generator when no image specified
parent
a1825549bc
commit
aa057af886
|
@ -97,20 +97,31 @@ void UvMapGenerator::packUvs()
|
||||||
m_mapPacker = std::make_unique<dust3d::UvMapPacker>();
|
m_mapPacker = std::make_unique<dust3d::UvMapPacker>();
|
||||||
|
|
||||||
for (const auto& partIt : m_snapshot->parts) {
|
for (const auto& partIt : m_snapshot->parts) {
|
||||||
|
dust3d::Uuid imageId;
|
||||||
|
dust3d::Color color;
|
||||||
|
double width = 1.0;
|
||||||
|
double height = 1.0;
|
||||||
|
const auto& colorIt = partIt.second.find("color");
|
||||||
|
if (colorIt != partIt.second.end()) {
|
||||||
|
color = dust3d::Color(colorIt->second);
|
||||||
|
}
|
||||||
const auto& colorImageIdIt = partIt.second.find("colorImageId");
|
const auto& colorImageIdIt = partIt.second.find("colorImageId");
|
||||||
if (colorImageIdIt == partIt.second.end())
|
if (colorImageIdIt != partIt.second.end()) {
|
||||||
continue;
|
imageId = dust3d::Uuid(colorImageIdIt->second);
|
||||||
auto imageId = dust3d::Uuid(colorImageIdIt->second);
|
const QImage* image = ImageForever::get(imageId);
|
||||||
const QImage* image = ImageForever::get(imageId);
|
if (nullptr != image) {
|
||||||
if (nullptr == image)
|
width = image->width();
|
||||||
continue;
|
height = image->height();
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto& findUvs = m_object->partTriangleUvs.find(dust3d::Uuid(partIt.first));
|
const auto& findUvs = m_object->partTriangleUvs.find(dust3d::Uuid(partIt.first));
|
||||||
if (findUvs == m_object->partTriangleUvs.end())
|
if (findUvs == m_object->partTriangleUvs.end())
|
||||||
continue;
|
continue;
|
||||||
dust3d::UvMapPacker::Part part;
|
dust3d::UvMapPacker::Part part;
|
||||||
part.id = imageId;
|
part.id = imageId;
|
||||||
part.width = image->width();
|
part.color = color;
|
||||||
part.height = image->height();
|
part.width = width;
|
||||||
|
part.height = height;
|
||||||
part.localUv = findUvs->second;
|
part.localUv = findUvs->second;
|
||||||
m_mapPacker->addPart(part);
|
m_mapPacker->addPart(part);
|
||||||
}
|
}
|
||||||
|
@ -132,25 +143,30 @@ void UvMapGenerator::generateTextureColorImage()
|
||||||
colorTexturePainter.setPen(Qt::NoPen);
|
colorTexturePainter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
for (const auto& layout : m_mapPacker->packedLayouts()) {
|
for (const auto& layout : m_mapPacker->packedLayouts()) {
|
||||||
const QImage* image = image = ImageForever::get(layout.id);
|
|
||||||
if (nullptr == image) {
|
|
||||||
dust3dDebug << "Find image failed:" << layout.id.toString();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QPixmap brushPixmap;
|
QPixmap brushPixmap;
|
||||||
if (layout.flipped) {
|
if (layout.id.isNull()) {
|
||||||
auto scaledImage = image->scaled(QSize(layout.height * UvMapGenerator::m_textureSize,
|
brushPixmap = QPixmap(layout.width * UvMapGenerator::m_textureSize, layout.height * UvMapGenerator::m_textureSize);
|
||||||
layout.width * UvMapGenerator::m_textureSize));
|
brushPixmap.fill(QColor(QString::fromStdString(layout.color.toString())));
|
||||||
QPoint center = scaledImage.rect().center();
|
|
||||||
QMatrix matrix;
|
|
||||||
matrix.translate(center.x(), center.y());
|
|
||||||
matrix.rotate(90);
|
|
||||||
auto rotatedImage = scaledImage.transformed(matrix).mirrored(true, false);
|
|
||||||
brushPixmap = QPixmap::fromImage(rotatedImage);
|
|
||||||
} else {
|
} else {
|
||||||
auto scaledImage = image->scaled(QSize(layout.width * UvMapGenerator::m_textureSize,
|
const QImage* image = ImageForever::get(layout.id);
|
||||||
layout.height * UvMapGenerator::m_textureSize));
|
if (nullptr == image) {
|
||||||
brushPixmap = QPixmap::fromImage(scaledImage);
|
dust3dDebug << "Find image failed:" << layout.id.toString();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (layout.flipped) {
|
||||||
|
auto scaledImage = image->scaled(QSize(layout.height * UvMapGenerator::m_textureSize,
|
||||||
|
layout.width * UvMapGenerator::m_textureSize));
|
||||||
|
QPoint center = scaledImage.rect().center();
|
||||||
|
QMatrix matrix;
|
||||||
|
matrix.translate(center.x(), center.y());
|
||||||
|
matrix.rotate(90);
|
||||||
|
auto rotatedImage = scaledImage.transformed(matrix).mirrored(true, false);
|
||||||
|
brushPixmap = QPixmap::fromImage(rotatedImage);
|
||||||
|
} else {
|
||||||
|
auto scaledImage = image->scaled(QSize(layout.width * UvMapGenerator::m_textureSize,
|
||||||
|
layout.height * UvMapGenerator::m_textureSize));
|
||||||
|
brushPixmap = QPixmap::fromImage(scaledImage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
colorTexturePainter.drawPixmap(layout.left * UvMapGenerator::m_textureSize,
|
colorTexturePainter.drawPixmap(layout.left * UvMapGenerator::m_textureSize,
|
||||||
layout.top * UvMapGenerator::m_textureSize,
|
layout.top * UvMapGenerator::m_textureSize,
|
||||||
|
|
|
@ -105,6 +105,7 @@ void UvMapPacker::pack()
|
||||||
auto& flipped = std::get<4>(result);
|
auto& flipped = std::get<4>(result);
|
||||||
//dust3dDebug << "left:" << left << "top:" << top << "width:" << width << "height:" << height << "flipped:" << flipped;
|
//dust3dDebug << "left:" << left << "top:" << top << "width:" << width << "height:" << height << "flipped:" << flipped;
|
||||||
Layout layout;
|
Layout layout;
|
||||||
|
layout.color = part.color;
|
||||||
layout.id = part.id;
|
layout.id = part.id;
|
||||||
layout.flipped = flipped;
|
layout.flipped = flipped;
|
||||||
if (flipped) {
|
if (flipped) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define DUST3D_UV_MAP_PACKER_H_
|
#define DUST3D_UV_MAP_PACKER_H_
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <dust3d/base/color.h>
|
||||||
#include <dust3d/base/position_key.h>
|
#include <dust3d/base/position_key.h>
|
||||||
#include <dust3d/base/uuid.h>
|
#include <dust3d/base/uuid.h>
|
||||||
#include <dust3d/base/vector2.h>
|
#include <dust3d/base/vector2.h>
|
||||||
|
@ -37,6 +38,7 @@ class UvMapPacker {
|
||||||
public:
|
public:
|
||||||
struct Part {
|
struct Part {
|
||||||
Uuid id;
|
Uuid id;
|
||||||
|
Color color;
|
||||||
double width = 0.0;
|
double width = 0.0;
|
||||||
double height = 0.0;
|
double height = 0.0;
|
||||||
std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>> localUv;
|
std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>> localUv;
|
||||||
|
@ -44,6 +46,7 @@ public:
|
||||||
|
|
||||||
struct Layout {
|
struct Layout {
|
||||||
Uuid id;
|
Uuid id;
|
||||||
|
Color color;
|
||||||
double left = 0.0;
|
double left = 0.0;
|
||||||
double top = 0.0;
|
double top = 0.0;
|
||||||
double width = 0.0;
|
double width = 0.0;
|
||||||
|
|
Loading…
Reference in New Issue