Add UV island padding

master
Jeremy Hu 2019-08-11 22:27:02 +09:30
parent 877ef1ff4c
commit 471a324bb3
2 changed files with 10 additions and 7 deletions

View File

@ -34,10 +34,12 @@ bool ChartPacker::tryPack(float textureSize)
if (m_tryNum > 50) { if (m_tryNum > 50) {
//qDebug() << "Try the " << m_tryNum << "nth times pack with factor:" << m_textureSizeFactor << " size:" << width << "x" << height; //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) { for (const auto &chartSize: m_chartSizes) {
maxRectsSize r; maxRectsSize r;
r.width = chartSize.first * m_floatToIntFactor; r.width = chartSize.first * m_floatToIntFactor + paddingSize2;
r.height = chartSize.second * m_floatToIntFactor; r.height = chartSize.second * m_floatToIntFactor + paddingSize2;
//qDebug() << " :chart " << r.width << "x" << r.height; //qDebug() << " :chart " << r.width << "x" << r.height;
rects.push_back(r); rects.push_back(r);
} }
@ -71,10 +73,10 @@ bool ChartPacker::tryPack(float textureSize)
const auto &result = bestResult[i]; const auto &result = bestResult[i];
const auto &rect = rects[i]; const auto &rect = rects[i];
auto &dest = m_result[i]; auto &dest = m_result[i];
std::get<0>(dest) = (float)result.left / width; std::get<0>(dest) = (float)(result.left + paddingSize) / width;
std::get<1>(dest) = (float)result.top / height; std::get<1>(dest) = (float)(result.top + paddingSize) / height;
std::get<2>(dest) = (float)rect.width / width; std::get<2>(dest) = (float)(rect.width - paddingSize2) / width;
std::get<3>(dest) = (float)rect.height / height; std::get<3>(dest) = (float)(rect.height - paddingSize2) / height;
std::get<4>(dest) = result.rotated; 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); //qDebug() << "result[" << i << "]:" << std::get<0>(dest) << std::get<1>(dest) << std::get<2>(dest) << std::get<3>(dest) << std::get<4>(dest);
} }

View File

@ -20,11 +20,12 @@ private:
std::vector<std::pair<float, float>> m_chartSizes; std::vector<std::pair<float, float>> m_chartSizes;
std::vector<std::tuple<float, float, float, float, bool>> m_result; std::vector<std::tuple<float, float, float, float, bool>> m_result;
float m_initialAreaGuessFactor = 1.05; float m_initialAreaGuessFactor = 1.1;
float m_textureSizeGrowFactor = 0.01; float m_textureSizeGrowFactor = 0.01;
float m_floatToIntFactor = 10000; float m_floatToIntFactor = 10000;
size_t m_tryNum = 0; size_t m_tryNum = 0;
float m_textureSizeFactor = 1.0; float m_textureSizeFactor = 1.0;
float m_paddingSize = 0.001;
size_t m_maxTryNum = 100; size_t m_maxTryNum = 100;
}; };