mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
parent
2c47116a3c
commit
9b992dddfc
1 changed files with 12 additions and 6 deletions
|
|
@ -29,6 +29,7 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
#include "editor_atlas.h"
|
#include "editor_atlas.h"
|
||||||
#include "print_string.h"
|
#include "print_string.h"
|
||||||
|
#include <cfloat>
|
||||||
|
|
||||||
struct _EditorAtlasWorkRect {
|
struct _EditorAtlasWorkRect {
|
||||||
|
|
||||||
|
|
@ -137,26 +138,31 @@ void EditorAtlas::fit(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result,
|
||||||
result.max_h = max_h;
|
result.max_h = max_h;
|
||||||
result.max_w = max_w;
|
result.max_w = max_w;
|
||||||
results.push_back(result);
|
results.push_back(result);
|
||||||
float efficiency = float(max_w * max_h) / float(next_power_of_2(max_w) * next_power_of_2(max_h));
|
float perimeter = (next_power_of_2(max_w) + max_h) * 2.f;
|
||||||
print_line("Processing atlas: width " + itos(w) + " ,height " + itos(max_h) + " ,efficiency " + rtos(efficiency));
|
print_line("Processing atlas: width " + itos(w) + " ,height " + itos(max_h) + " ,perimeter " + rtos(perimeter));
|
||||||
}
|
}
|
||||||
|
|
||||||
//find the result with the most efficiency
|
//find the result with the most efficiency
|
||||||
|
|
||||||
int best = -1;
|
int best = -1;
|
||||||
float max_eff = 0;
|
float min_perimeter = FLT_MAX;
|
||||||
|
|
||||||
for (int i = 0; i < results.size(); i++) {
|
for (int i = 0; i < results.size(); i++) {
|
||||||
|
|
||||||
float h = results[i].max_h;
|
float h = results[i].max_h;
|
||||||
float w = results[i].max_w;
|
float w = results[i].max_w;
|
||||||
float efficiency = float(w * h) / float(next_power_of_2(w) * next_power_of_2(h));
|
float perimeter = (next_power_of_2(w) + h) * 2.f;
|
||||||
if (efficiency > max_eff) {
|
if (perimeter < min_perimeter) {
|
||||||
best = i;
|
best = i;
|
||||||
max_eff = efficiency;
|
min_perimeter = perimeter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (best < 0) {
|
||||||
|
ERR_PRINT("Atlas processing failed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
r_result.resize(p_rects.size());
|
r_result.resize(p_rects.size());
|
||||||
|
|
||||||
for (int i = 0; i < p_rects.size(); i++) {
|
for (int i = 0; i < p_rects.size(); i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue