From c6ca0af7b257ef95992b975d1e4c5007b2bf8a59 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 11 Nov 2018 14:30:13 +0000 Subject: [PATCH] fixed rectpacker --- WickedEngine/wiRectPacker.cpp | 44 ++++++----------------------------- WickedEngine/wiRectPacker.h | 8 ++----- WickedEngine/wiVersion.cpp | 2 +- 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/WickedEngine/wiRectPacker.cpp b/WickedEngine/wiRectPacker.cpp index cda9247dd..45c204a76 100644 --- a/WickedEngine/wiRectPacker.cpp +++ b/WickedEngine/wiRectPacker.cpp @@ -3,8 +3,6 @@ #include #include -#define RECTPACK_DISABLE_FLIP // I don't care for now and it complicate things - using namespace std; namespace wiRectPacker @@ -101,25 +99,13 @@ namespace wiRectPacker if (id) return 0; int f = img.fits(rect_xywh(rc)); -#ifdef RECTPACK_DISABLE_FLIP switch (f) { case 0: return 0; - case 1: img.flipped = false; break; - case 2: img.flipped = false; break; - case 3: id = true; img.flipped = false; return this; - case 4: id = true; img.flipped = false; return this; + case 1: break; + case 2: id = true; return this; } -#else - switch (f) { - case 0: return 0; - case 1: img.flipped = false; break; - case 2: img.flipped = true; break; - case 3: id = true; img.flipped = false; return this; - case 4: id = true; img.flipped = true; return this; - } -#endif - int iw = (img.flipped ? img.h : img.w), ih = (img.flipped ? img.w : img.h); + int iw = img.w, ih = img.h; if (rc.w() - iw > rc.h() - ih) { c[0].set(rc.l, rc.t, rc.l + iw, rc.b); @@ -223,11 +209,6 @@ namespace wiRectPacker v[i]->x = ret->rc.l; v[i]->y = ret->rc.t; - if (v[i]->flipped) { - v[i]->flipped = false; - v[i]->flip(); - } - clip_x = std::max(clip_x, ret->rc.r); clip_y = std::max(clip_y, ret->rc.b); @@ -235,8 +216,6 @@ namespace wiRectPacker } else { unsucc.push_back(v[i]); - - v[i]->flipped = false; } } @@ -282,10 +261,8 @@ namespace wiRectPacker rect_wh::rect_wh(int w, int h) : w(w), h(h) {} int rect_wh::fits(const rect_wh& r) const { - if (w == r.w && h == r.h) return 3; - if (h == r.w && w == r.h) return 4; + if (w == r.w && h == r.h) return 2; if (w <= r.w && h <= r.h) return 1; - if (h <= r.w && w <= r.h) return 2; return 0; } @@ -351,15 +328,8 @@ namespace wiRectPacker } - rect_xywhf::rect_xywhf(const rect_ltrb& rr) : rect_xywh(rr), flipped(false) {} - rect_xywhf::rect_xywhf(int x, int y, int width, int height) : rect_xywh(x, y, width, height), flipped(false) {} - rect_xywhf::rect_xywhf() : flipped(false) {} - - void rect_xywhf::flip() { -#ifndef RECTPACK_DISABLE_FLIP - flipped = !flipped; - std::swap(w, h); -#endif - } + rect_xywhf::rect_xywhf(const rect_ltrb& rr) : rect_xywh(rr) {} + rect_xywhf::rect_xywhf(int x, int y, int width, int height) : rect_xywh(x, y, width, height) {} + rect_xywhf::rect_xywhf() {} } diff --git a/WickedEngine/wiRectPacker.h b/WickedEngine/wiRectPacker.h index 2cfdf7477..a3cd24af1 100644 --- a/WickedEngine/wiRectPacker.h +++ b/WickedEngine/wiRectPacker.h @@ -9,7 +9,6 @@ 1. rect_xywhf - structure representing your rectangle object members: int x, y, w, h; -bool flipped; 2. bin - structure representing resultant bin object 3. bool pack(rect_xywhf* const * v, int n, int max_side, std::std::vector& bins) - actual packing function @@ -29,9 +28,8 @@ then for each bin iterate through its rectangles, typecast each one to your own to the array representing your texture atlas to the place specified by the rectangle, then finally upload it with glTexImage2D. Algorithm doesn't create any new rectangles. -You just pass an array of pointers - rectangles' x/y/w/h/flipped are modified in place. +You just pass an array of pointers - rectangles' x/y/w/h are modified in place. There is a vector of pointers for every resultant bin to let you know which ones belong to the particular bin. -The algorithm may swap the w and h fields for the sake of better fitting, the flag "flipped" will be set to true whenever this occurs. For description how to tune the algorithm and how it actually works see the .cpp file. @@ -49,7 +47,7 @@ namespace wiRectPacker rect_wh(const rect_xywh&); rect_wh(int w = 0, int h = 0); int w, h, area(), perimeter(), - fits(const rect_wh& bigger) const; // 0 - no, 1 - yes, 2 - flipped, 3 - perfectly, 4 perfectly flipped + fits(const rect_wh& bigger) const; // 0 - no, 1 - yes, 2 - perfectly }; // rectangle implementing left/top/right/bottom behaviour @@ -75,8 +73,6 @@ namespace wiRectPacker rect_xywhf(const rect_ltrb&); rect_xywhf(int x, int y, int width, int height); rect_xywhf(); - void flip(); - bool flipped; }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 613e7f0d4..ec65b71e1 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 22; // minor bug fixes, alterations, refactors, updates - const int revision = 14; + const int revision = 15; long GetVersion()