diff options
Diffstat (limited to 'editor/editor_atlas_packer.cpp')
-rw-r--r-- | editor/editor_atlas_packer.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/editor/editor_atlas_packer.cpp b/editor/editor_atlas_packer.cpp index d17b3bba4f..68abeb2cda 100644 --- a/editor/editor_atlas_packer.cpp +++ b/editor/editor_atlas_packer.cpp @@ -31,14 +31,12 @@ #include "editor_atlas_packer.h" void EditorAtlasPacker::_plot_triangle(Ref<BitMap> p_bitmap, Vector2i *vertices) { - int width = p_bitmap->get_size().width; int height = p_bitmap->get_size().height; int x[3]; int y[3]; for (int j = 0; j < 3; j++) { - x[j] = vertices[j].x; y[j] = vertices[j].y; } @@ -71,26 +69,25 @@ void EditorAtlasPacker::_plot_triangle(Ref<BitMap> p_bitmap, Vector2i *vertices) } for (int xi = (xf < width ? int(xf) : width - 1); xi >= (xt > 0 ? xt : 0); xi--) { - p_bitmap->set_bit(Point2(xi, yi), true); } } xf += dx_far; - if (yi < y[1]) + if (yi < y[1]) { xt += dx_upper; - else + } else { xt += dx_low; + } } } -void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_height, int p_atlas_max_size, int p_cell_resolution) { +void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_height, int p_atlas_max_size, int p_cell_resolution) { int divide_by = MIN(64, p_cell_resolution); Vector<PlottedBitmap> bitmaps; int max_w = 0; for (int i = 0; i < charts.size(); i++) { - const Chart &chart = charts[i]; //generate aabb @@ -100,7 +97,6 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h const Vector2 *vertices = chart.vertices.ptr(); for (int j = 0; j < vertex_count; j++) { - if (j == 0) { aabb.position = vertices[j]; } else { @@ -118,7 +114,6 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h //plot triangles, using divisor for (int j = 0; j < chart.faces.size(); j++) { - Vector2i v[3]; for (int k = 0; k < 3; k++) { Vector2 vtx = chart.vertices[chart.faces[j].vertex[k]]; @@ -163,13 +158,14 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h bool found_pixel = false; for (int lx = x - 1; lx < x + 2 && !found_pixel; lx++) { for (int ly = y - 1; ly < y + 2 && !found_pixel; ly++) { - int px = lx - 1; - if (px < 0 || px >= w) + if (px < 0 || px >= w) { continue; + } int py = ly - 1; - if (py < 0 || py >= h) + if (py < 0 || py >= h) { continue; + } if (src_bitmap->get_bit(Vector2(px, py))) { found_pixel = true; @@ -177,7 +173,6 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h } } if (found_pixel) { - if (transpose) { if (x > top_heights[y]) { top_heights.write[y] = x; @@ -231,7 +226,6 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h int *atlas_ptr = heights.ptrw(); for (int i = 0; i < bitmaps.size(); i++) { - int best_height = 0x7FFFFFFF; int best_height_offset = -1; int w = bitmaps[i].top_heights.size(); @@ -240,11 +234,9 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h const int *bottom_heights = bitmaps[i].bottom_heights.ptr(); for (int j = 0; j < atlas_w - w; j++) { - int height = 0; for (int k = 0; k < w; k++) { - int pixmap_h = bottom_heights[k]; if (pixmap_h == -1) { continue; //no pixel here, anything is fine |