Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] added optional cropping for texture atlas importer #52652

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion editor/import/resource_importer_texture_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ String ResourceImporterTextureAtlas::get_preset_name(int p_idx) const {
void ResourceImporterTextureAtlas::get_import_options(List<ImportOption> *r_options, int p_preset) const {
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "atlas_file", PROPERTY_HINT_SAVE_FILE, "*.png"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_mode", PROPERTY_HINT_ENUM, "Region,Mesh2D"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "crop_to_region"), false));
}

String ResourceImporterTextureAtlas::get_option_group_file() const {
Expand Down Expand Up @@ -203,6 +204,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
ERR_CONTINUE(err != OK);

pack_data.image = image;
pack_data.is_cropped = options["crop_to_region"];

int mode = options["import_mode"];

Expand Down Expand Up @@ -325,7 +327,10 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
atlas_texture.instance();
atlas_texture->set_atlas(cache);
atlas_texture->set_region(Rect2(offset, pack_data.region.size));
atlas_texture->set_margin(Rect2(pack_data.region.position, Size2(pack_data.image->get_width(), pack_data.image->get_height()) - pack_data.region.size));

if (!pack_data.is_cropped) {
atlas_texture->set_margin(Rect2(pack_data.region.position, pack_data.image->get_size() - pack_data.region.size));
}

texture = atlas_texture;
} else {
Expand Down
1 change: 1 addition & 0 deletions editor/import/resource_importer_texture_atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ResourceImporterTextureAtlas : public ResourceImporter {

struct PackData {
Rect2 region;
bool is_cropped;
bool is_mesh;
Vector<int> chart_pieces; //one for region, many for mesh
Vector<Vector<Vector2>> chart_vertices; //for mesh
Expand Down