From e34619a60559687a509b2171d24fc208a12d93ac Mon Sep 17 00:00:00 2001 From: Ninni Pipping Date: Wed, 24 May 2023 10:08:25 +0200 Subject: [PATCH] [3.x] Bounds fixes in `TextureAtlas` import --- editor/editor_atlas_packer.cpp | 2 +- editor/import/resource_importer_texture_atlas.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/editor/editor_atlas_packer.cpp b/editor/editor_atlas_packer.cpp index d9a919c8001..dfb1e8bcd51 100644 --- a/editor/editor_atlas_packer.cpp +++ b/editor/editor_atlas_packer.cpp @@ -105,7 +105,7 @@ void EditorAtlasPacker::chart_pack(Vector &charts, int &r_width, int &r_h Ref src_bitmap; src_bitmap.instance(); - src_bitmap->create(aabb.size / divide_by); + src_bitmap->create(Size2(Math::ceil(aabb.size.x / (real_t)divide_by), Math::ceil(aabb.size.y / (real_t)divide_by))); int w = src_bitmap->get_size().width; int h = src_bitmap->get_size().height; diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 2540ff610b9..4adbb1c2193 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -96,7 +96,8 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St return OK; } -static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_transposed, Ref p_image, const Ref &p_src_image) { +// FIXME: Rasterization has issues, see https://github.com/godotengine/godot/issues/68350#issuecomment-1305610290 +static void _plot_triangle(Vector2 *p_vertices, const Vector2 &p_offset, bool p_transposed, Ref p_image, const Ref &p_src_image) { int width = p_image->get_width(); int height = p_image->get_height(); int src_width = p_src_image->get_width(); @@ -106,8 +107,8 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr int y[3]; for (int j = 0; j < 3; j++) { - x[j] = vertices[j].x; - y[j] = vertices[j].y; + x[j] = p_vertices[j].x; + y[j] = p_vertices[j].y; } // sort the points vertically @@ -129,7 +130,7 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr double dx_low = double(x[2] - x[1]) / (y[2] - y[1] + 1); double xf = x[0]; double xt = x[0] + dx_upper; // if y[0] == y[1], special case - int max_y = MIN(y[2], height - p_offset.y - 1); + int max_y = MIN(y[2], p_transposed ? (width - p_offset.x - 1) : (height - p_offset.y - 1)); for (int yi = y[0]; yi < max_y; yi++) { if (yi >= 0) { for (int xi = (xf > 0 ? int(xf) : 0); xi < (xt <= src_width ? xt : src_width); xi++) { @@ -246,7 +247,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file Ref bit_map; bit_map.instance(); bit_map->create_from_image_alpha(image); - Vector> polygons = bit_map->clip_opaque_to_polygons(Rect2(0, 0, image->get_width(), image->get_height())); + Vector> polygons = bit_map->clip_opaque_to_polygons(Rect2(Vector2(), image->get_size())); for (int j = 0; j < polygons.size(); j++) { EditorAtlasPacker::Chart chart;