From 471a324bb3e0923a1f8285b23d10f4e67522d12a Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 11 Aug 2019 22:27:02 +0930 Subject: [PATCH] Add UV island padding --- thirdparty/simpleuv/simpleuv/chartpacker.cpp | 14 ++++++++------ thirdparty/simpleuv/simpleuv/chartpacker.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/thirdparty/simpleuv/simpleuv/chartpacker.cpp b/thirdparty/simpleuv/simpleuv/chartpacker.cpp index 73b5b4a2..022ee3bd 100644 --- a/thirdparty/simpleuv/simpleuv/chartpacker.cpp +++ b/thirdparty/simpleuv/simpleuv/chartpacker.cpp @@ -34,10 +34,12 @@ bool ChartPacker::tryPack(float textureSize) if (m_tryNum > 50) { //qDebug() << "Try the " << m_tryNum << "nth times pack with factor:" << m_textureSizeFactor << " size:" << width << "x" << height; } + float paddingSize = m_paddingSize * width; + float paddingSize2 = paddingSize + paddingSize; for (const auto &chartSize: m_chartSizes) { maxRectsSize r; - r.width = chartSize.first * m_floatToIntFactor; - r.height = chartSize.second * m_floatToIntFactor; + r.width = chartSize.first * m_floatToIntFactor + paddingSize2; + r.height = chartSize.second * m_floatToIntFactor + paddingSize2; //qDebug() << " :chart " << r.width << "x" << r.height; rects.push_back(r); } @@ -71,10 +73,10 @@ bool ChartPacker::tryPack(float textureSize) const auto &result = bestResult[i]; const auto &rect = rects[i]; auto &dest = m_result[i]; - std::get<0>(dest) = (float)result.left / width; - std::get<1>(dest) = (float)result.top / height; - std::get<2>(dest) = (float)rect.width / width; - std::get<3>(dest) = (float)rect.height / height; + std::get<0>(dest) = (float)(result.left + paddingSize) / width; + std::get<1>(dest) = (float)(result.top + paddingSize) / height; + std::get<2>(dest) = (float)(rect.width - paddingSize2) / width; + std::get<3>(dest) = (float)(rect.height - paddingSize2) / height; std::get<4>(dest) = result.rotated; //qDebug() << "result[" << i << "]:" << std::get<0>(dest) << std::get<1>(dest) << std::get<2>(dest) << std::get<3>(dest) << std::get<4>(dest); } diff --git a/thirdparty/simpleuv/simpleuv/chartpacker.h b/thirdparty/simpleuv/simpleuv/chartpacker.h index e17f722f..99838099 100644 --- a/thirdparty/simpleuv/simpleuv/chartpacker.h +++ b/thirdparty/simpleuv/simpleuv/chartpacker.h @@ -20,11 +20,12 @@ private: std::vector> m_chartSizes; std::vector> m_result; - float m_initialAreaGuessFactor = 1.05; + float m_initialAreaGuessFactor = 1.1; float m_textureSizeGrowFactor = 0.01; float m_floatToIntFactor = 10000; size_t m_tryNum = 0; float m_textureSizeFactor = 1.0; + float m_paddingSize = 0.001; size_t m_maxTryNum = 100; };