Accept padding and gap parameters when loading a bevy image.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
Many 2d grid based tilesets consolidate textures into a single image atlas. These images are often laid out in a grid format with sometimes gaps between tiles and padding between the edge of the image and the textures themselves. Ie:

Bevy currently has no way of configuring images on load to support textures laid out in this way and thus when loading textures like this they require manual preperation for bevy.
## What solution would you like?
Modify what is currently the [`create_stacked_array_from_2d_grid` method of image](https://github.com/bevyengine/bevy/blob/2002a188e0e106eacf56b854dfaff4eca8839584/crates/bevy_image/src/image.rs#L1433) to accept parameters for gap and padding and have these be factored into the new image creation step of the method.
I'm also proposing to remove the `RowSize` and `RowCount` variants from the [`ImageArrayLayout`](https://github.com/bevyengine/bevy/blob/2002a188e0e106eacf56b854dfaff4eca8839584/crates/bevy_image/src/image_loader.rs#L105) enum to have users always set vertically arranged textures through the `GridSize` and `GridCount` varients instead. IMO this is a simpler and easier to understand. This change is breaking, and would require a few examples to be updated.
With the submission of the change, the `ImageArrayLayout` enum be renamed to `ImageLayout` and could look like this
```rust
pub enum ImageLayout {
GridCount {
columns: u32,
rows: u32,
gap: u32, // Has default 0
padding: ImageLayoutPadding
},
GridSize {
tile_width_pixels: u32,
tile_height_pixels: u32,
gap: u32, // Has default 0
padding: ImageLayoutPadding
},
}
// All have default of 0
pub struct ImageLayoutPadding {
top: u32,
bottom: u32,
right: u32,
left: u32
}
```
## What alternative(s) have you considered?
`RowSize` and `RowCount` refactoring change don't need to happen.
## Additional context
- Builds on [this issue](https://github.com/bevyengine/bevy/pull/24132#event-25311000571)
Contributor guide
Assessment
This issue has not been assessed yet.