Texture atlases should use atlas layouts, not atlas indices #15365
Labels
A-Rendering
Drawing game state to the screen
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
D-Modest
A "normal" level of difficulty; suitable for simple features or challenging fixes
S-Ready-For-Implementation
This issue is ready for an implementation PR. Go for it!
X-Contentious
There are nontrivial implications that should be thought through
IMO, the way we generate atlases is flawed and wrongly encourages using atlas indices. This is particularly apparent when dealing with sprite animations: have an atlas with two sprite-sheets (gabe and alice) with identical animations (10 frame). You have to hard-code that gabe animation goes from 0-9 and alice from 10-19 which is stupid, both go from 0-9 in their local space!
Instead of using atlas indices we should be encouraging atlas layouts:
asset_server.load("atlas.sprites")
would return the atlas image,asset_server.load("atlas.sprite#gabe")
would return gabe's layout andasset_server.load("atlas_sprite#gabe/walk")
would return gabe's animation (wouldn't that be neat?)Working with atlas layouts right now is a bit annoying though, you need to build your atlas, keep the image handles -which sucks when building a spritesheet from other spritesheets- alive (if it drops the handle will not be the same as in the layout, oops!), grab the index, find the next sprite index (or hard-code the number), grab a slice of the rects then build and add your layouts to the asset server. AtlasBuilder is this way because of #2987.
Now, what i would do:
AtlasBuilder<None>
andAtlasBuilder<AssetState>
that would be built like so:AtlasBuilder<'a, None>.with_asset_server(self, server: &AssetServer) -> AtlasBuilder<'a, AssetState>
.AtlasBuilder<'a, AssetState>
would have a methodlayout(&'a mut self) -> LayoutBuilder<'a>
. LayoutBuilder would have the usual add_texture operations like AtlasBuilder, but on build() it would create aHandle<AtlasLayout>
, store it in AtlasBuilder and return it to the user.AtlasBuilder<'a, AssetState>.build() -> (Handle<AtlasLayout>, Handle<Image>)
would do the same as now and add the proper rects to all theHandle<AtlasLayout>
.This is a rough sketch and I'm sure i missed things, but it would look something like this:
Originally posted by @s-puig in #15344 (comment)
The text was updated successfully, but these errors were encountered: