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

Allow TextureAtlasBuilder in AssetLoader #11548

Merged

Conversation

KirmesBude
Copy link
Contributor

Objective

Allow TextureAtlasBuilder in AssetLoader.
Fixes #2987

Solution

  • TextureAtlasBuilder no longer hold just AssetIds that are used to retrieve the actual image data in finish, but &Image instead.
  • TextureAtlasBuilder now required AssetId only optionally (and it is only used to retrieve the index from the AssetId in TextureAtlasLayout),

Issues

  • The issue mentioned here TextureAtlasBuilder now respects insertion order #11474 (comment) now also extends to the actual atlas texture. In short: Calling add_texture multiple times for the same texture will lead to duplicate image data in the atlas texture and additional indices.
    If you provide an AssetId we can probably do something to de-duplicate the entries while keeping insertion order (suggestions welcome on how exactly). But if you don't then we are out of luck (unless we can and want to hash the image, which I do not think we want).

Changelog

Changed

  • TextureAtlasBuilder add_texture can be called without providing an AssetId
  • TextureAtlasBuilder finish no longer takes Assets and no longer returns a Handle

Migration Guide

  • For add_texture you need to wrap your AssetId in Some
  • finish now returns the atlas texture image directly instead of a handle. Provide the atlas texture to add on Assets to get a Handle

@matiqo15 matiqo15 added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide labels Jan 26, 2024
@alice-i-cecile
Copy link
Member

@doonv, want to take a look at this one too? And lemme know if you'd like org membership so you can triage things/I can request your review directly.

@alice-i-cecile
Copy link
Member

@B-Reif @adtennant I'd be interested in your opinions too.

Comment on lines 31 to 32
/// Collection of textures and their size to be packed into an atlas
textures_to_place: Vec<(AssetId<Image>, Extent3d)>,
textures_to_place: Vec<(Option<AssetId<Image>>, &'a Image)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc comment should be updated

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jan 27, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 27, 2024
Merged via the queue into bevyengine:main with commit 3851679 Jan 27, 2024
23 checks passed
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
# Objective

Allow TextureAtlasBuilder in AssetLoader.
Fixes bevyengine#2987

## Solution

- TextureAtlasBuilder no longer hold just AssetIds that are used to
retrieve the actual image data in `finish`, but &Image instead.
- TextureAtlasBuilder now required AssetId only optionally (and it is
only used to retrieve the index from the AssetId in TextureAtlasLayout),

## Issues

- The issue mentioned here
bevyengine#11474 (comment)
now also extends to the actual atlas texture. In short: Calling
add_texture multiple times for the same texture will lead to duplicate
image data in the atlas texture and additional indices.
If you provide an AssetId we can probably do something to de-duplicate
the entries while keeping insertion order (suggestions welcome on how
exactly). But if you don't then we are out of luck (unless we can and
want to hash the image, which I do not think we want).

---

## Changelog

### Changed
- TextureAtlasBuilder `add_texture` can be called without providing an
AssetId
- TextureAtlasBuilder `finish` no longer takes Assets<Image> and no
longer returns a Handle<Image>

## Migration Guide

- For `add_texture` you need to wrap your AssetId in Some
- `finish` now returns the atlas texture image directly instead of a
handle. Provide the atlas texture to `add` on Assets<Texture> to get a
Handle<Image>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework TextureAtlasBuilder APIs for asset loaders
4 participants