瀏覽代碼

Merge pull request #87145 from AThousandShips/atlas_fix_size

Allow configuring the maximum width for atlas import
Rémi Verschelde 1 年之前
父節點
當前提交
3834fb432e

+ 3 - 0
doc/classes/ProjectSettings.xml

@@ -898,6 +898,9 @@
 			If [code]true[/code], text resources are converted to a binary format on export. This decreases file sizes and speeds up loading slightly.
 			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].
 			[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].
 		</member>
 		</member>
+		<member name="editor/import/atlas_max_width" type="int" setter="" getter="" default="2048">
+			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.
+		</member>
 		<member name="editor/import/reimport_missing_imported_files" type="bool" setter="" getter="" default="true">
 		<member name="editor/import/reimport_missing_imported_files" type="bool" setter="" getter="" default="true">
 		</member>
 		</member>
 		<member name="editor/import/use_multiple_threads" type="bool" setter="" getter="" default="true">
 		<member name="editor/import/use_multiple_threads" type="bool" setter="" getter="" default="true">

+ 8 - 1
editor/import/resource_importer_texture_atlas.cpp

@@ -31,6 +31,7 @@
 #include "resource_importer_texture_atlas.h"
 #include "resource_importer_texture_atlas.h"
 
 
 #include "atlas_import_failed.xpm"
 #include "atlas_import_failed.xpm"
+#include "core/config/project_settings.h"
 #include "core/io/file_access.h"
 #include "core/io/file_access.h"
 #include "core/io/image_loader.h"
 #include "core/io/image_loader.h"
 #include "core/io/resource_saver.h"
 #include "core/io/resource_saver.h"
@@ -276,9 +277,15 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
 		idx++;
 		idx++;
 	}
 	}
 
 
+	const int max_width = (int)GLOBAL_GET("editor/import/atlas_max_width");
+
 	//pack the charts
 	//pack the charts
 	int atlas_width, atlas_height;
 	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
 	//blit the atlas
 	Ref<Image> new_atlas = Image::create_empty(atlas_width, atlas_height, false, Image::FORMAT_RGBA8);
 	Ref<Image> new_atlas = Image::create_empty(atlas_width, atlas_height, false, Image::FORMAT_RGBA8);

+ 2 - 0
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/reimport_missing_imported_files", true);
 	GLOBAL_DEF("editor/import/use_multiple_threads", 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/export/convert_text_resources_to_binary", true);
 
 
 	GLOBAL_DEF("editor/version_control/plugin_name", "");
 	GLOBAL_DEF("editor/version_control/plugin_name", "");