LMPacker fix
This commit is contained in:
@@ -68,7 +68,7 @@ Atlas* AtlasBuilder::build(uint extrusion) {
|
|||||||
vector<rectangle> rects = packer.getResult();
|
vector<rectangle> rects = packer.getResult();
|
||||||
for (uint i = 0; i < entries.size(); i++) {
|
for (uint i = 0; i < entries.size(); i++) {
|
||||||
const rectangle& rect = rects[i];
|
const rectangle& rect = rects[i];
|
||||||
const atlasentry& entry = entries[i];
|
const atlasentry& entry = entries[rect.idx];
|
||||||
uint x = rect.x;
|
uint x = rect.x;
|
||||||
uint y = rect.y;
|
uint y = rect.y;
|
||||||
uint w = rect.width;
|
uint w = rect.width;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ inline int getPackerScore(rectangle& rect) {
|
|||||||
|
|
||||||
LMPacker::LMPacker(const uint32_t sizes[], size_t length) {
|
LMPacker::LMPacker(const uint32_t sizes[], size_t length) {
|
||||||
for (unsigned int i = 0; i < length/2; i++) {
|
for (unsigned int i = 0; i < length/2; i++) {
|
||||||
rectangle rect(0, 0, (int)sizes[i * 2], (int)sizes[i * 2 + 1]);
|
rectangle rect(i, 0, 0, (int)sizes[i * 2], (int)sizes[i * 2 + 1]);
|
||||||
rects.push_back(rect);
|
rects.push_back(rect);
|
||||||
}
|
}
|
||||||
sort(rects.begin(), rects.end(), [](rectangle a, rectangle b) {
|
sort(rects.begin(), rects.end(), [](rectangle a, rectangle b) {
|
||||||
@@ -50,7 +50,7 @@ bool LMPacker::build(uint32_t width, uint32_t height,
|
|||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < rects.size(); i++) {
|
for (unsigned int i = 0; i < rects.size(); i++) {
|
||||||
rectangle& rect = rects[i];
|
rectangle& rect = rects[i];
|
||||||
rect = rectangle(0, 0, rect.width, rect.height);
|
rect = rectangle(rect.idx, 0, 0, rect.width, rect.height);
|
||||||
rect.width += extension * 2;
|
rect.width += extension * 2;
|
||||||
rect.height += extension * 2;
|
rect.height += extension * 2;
|
||||||
if (mpix > 1) {
|
if (mpix > 1) {
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ struct rectangle {
|
|||||||
int height;
|
int height;
|
||||||
int extX = 0;
|
int extX = 0;
|
||||||
int extY = 0;
|
int extY = 0;
|
||||||
|
uint idx;
|
||||||
|
|
||||||
rectangle(int x, int y, int width, int height)
|
rectangle(uint idx, int x, int y, int width, int height)
|
||||||
: x(x), y(y), width(width), height(height){
|
: idx(idx), x(x), y(y), width(width), height(height){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user