From 65049c3fe74f6a27bcbbdad1d7cd91a4675cd07b Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sat, 13 Jan 2024 13:23:32 +0100 Subject: [PATCH] Allow configuring the maximum width for atlas import (cherry picked from commit 8b3c12d8df5bc8964e8037a0cc0cb4d38d764a20) --- doc/classes/ProjectSettings.xml | 3 +++ editor/import/resource_importer_texture_atlas.cpp | 9 ++++++++- editor/register_editor_types.cpp | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 08435e1de8d..b29c9458067 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -878,6 +878,9 @@ If [code]true[/code], text resources are converted to a binary format on export. This decreases file sizes and speeds up loading slightly. [b]Note:[/b] If [member editor/export/convert_text_resources_to_binary] is [code]true[/code], [method @GDScript.load] will not be able to return the converted files in an exported project. Some file paths within the exported PCK will also change, such as [code]project.godot[/code] becoming [code]project.binary[/code]. If you rely on run-time loading of files present within the PCK, set [member editor/export/convert_text_resources_to_binary] to [code]false[/code]. + + The maximum width to use when importing textures as an atlas. The value will be rounded to the nearest power of two when used. Use this to prevent imported textures from growing too large in the other direction. + diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index d437f23740c..d1f366feecd 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -31,6 +31,7 @@ #include "resource_importer_texture_atlas.h" #include "atlas_import_failed.xpm" +#include "core/config/project_settings.h" #include "core/io/file_access.h" #include "core/io/image_loader.h" #include "core/io/resource_saver.h" @@ -276,9 +277,15 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file idx++; } + const int max_width = (int)GLOBAL_GET("editor/import/atlas_max_width"); + //pack the charts int atlas_width, atlas_height; - EditorAtlasPacker::chart_pack(charts, atlas_width, atlas_height); + EditorAtlasPacker::chart_pack(charts, atlas_width, atlas_height, max_width); + + if (atlas_height > max_width * 2) { + WARN_PRINT(vformat(TTR("%s: Atlas texture significantly larger on one axis (%d), consider changing the `editor/import/atlas_max_width` Project Setting to allow a wider texture, making the result more even in size."), p_group_file, atlas_height)); + } //blit the atlas Ref new_atlas = Image::create_empty(atlas_width, atlas_height, false, Image::FORMAT_RGBA8); diff --git a/editor/register_editor_types.cpp b/editor/register_editor_types.cpp index 9a667d57758..08ea83e133f 100644 --- a/editor/register_editor_types.cpp +++ b/editor/register_editor_types.cpp @@ -272,6 +272,8 @@ void register_editor_types() { GLOBAL_DEF("editor/import/reimport_missing_imported_files", true); GLOBAL_DEF("editor/import/use_multiple_threads", true); + GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/import/atlas_max_width", PROPERTY_HINT_RANGE, "128,8192,1,or_greater"), 2048); + GLOBAL_DEF("editor/export/convert_text_resources_to_binary", true); GLOBAL_DEF("editor/version_control/plugin_name", "");