Fix UV coords

master
Jeremy HU 2022-10-30 10:39:57 +11:00
parent 9ad0c92e4b
commit c87c4482c1
1 changed files with 10 additions and 6 deletions

View File

@ -43,6 +43,7 @@ void UvMapPacker::pack()
std::vector<std::pair<float, float>> chartSizes(m_partTriangleUvs.size()); std::vector<std::pair<float, float>> chartSizes(m_partTriangleUvs.size());
for (size_t i = 0; i < m_partTriangleUvs.size(); ++i) { for (size_t i = 0; i < m_partTriangleUvs.size(); ++i) {
const auto& part = m_partTriangleUvs[i]; const auto& part = m_partTriangleUvs[i];
//dust3dDebug << "part.width:" << part.width << "part.height:" << part.height;
chartSizes[i] = { part.width, part.height }; chartSizes[i] = { part.width, part.height };
} }
@ -73,22 +74,25 @@ void UvMapPacker::pack()
layout.width = width; layout.width = width;
layout.height = height; layout.height = height;
} }
auto partWidth = part.width;
auto partHeight = part.height;
if (flipped) { if (flipped) {
for (auto& it : part.localUv) { for (auto& it : part.localUv) {
std::swap(it.second[0][0], it.second[0][1]); std::swap(it.second[0][0], it.second[0][1]);
std::swap(it.second[1][0], it.second[1][1]); std::swap(it.second[1][0], it.second[1][1]);
std::swap(it.second[2][0], it.second[2][1]); std::swap(it.second[2][0], it.second[2][1]);
} }
std::swap(partWidth, partHeight);
} }
for (const auto& it : part.localUv) { for (const auto& it : part.localUv) {
layout.globalUv.insert({ it.first, layout.globalUv.insert({ it.first,
std::array<Vector2, 3> { std::array<Vector2, 3> {
Vector2(left + (it.second[0].x() * width) / m_packedTextureSize, Vector2((left * m_packedTextureSize + it.second[0].x() * partWidth) / m_packedTextureSize,
top + (it.second[0].y() * height) / m_packedTextureSize), (top * m_packedTextureSize + it.second[0].y() * partHeight) / m_packedTextureSize),
Vector2(left + (it.second[1].x() * width) / m_packedTextureSize, Vector2((left * m_packedTextureSize + it.second[1].x() * partWidth) / m_packedTextureSize,
top + (it.second[1].y() * height) / m_packedTextureSize), (top * m_packedTextureSize + it.second[1].y() * partHeight) / m_packedTextureSize),
Vector2(left + (it.second[2].x() * width) / m_packedTextureSize, Vector2((left * m_packedTextureSize + it.second[2].x() * partWidth) / m_packedTextureSize,
top + (it.second[2].y() * height) / m_packedTextureSize) } }); (top * m_packedTextureSize + it.second[2].y() * partHeight) / m_packedTextureSize) } });
} }
m_packedLayouts.emplace_back(layout); m_packedLayouts.emplace_back(layout);
} }