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

Custom Atlas loading #27

Closed
Droggelbecher opened this issue Nov 12, 2024 · 6 comments · May be fixed by #28
Closed

Custom Atlas loading #27

Droggelbecher opened this issue Nov 12, 2024 · 6 comments · May be fixed by #28

Comments

@Droggelbecher
Copy link

I would like to bundle all my assets with my binary file and for that use the embedded_asset! macro. This works fine for the skeleton and .atlas for which I call the asset loader myself, however it seems bevy_spine assumes that the actual atlas png is a file on disk which isnt the case for me.

Is there any way to customize how that png is loaded so I can use my own method?

@jabuwu
Copy link
Owner

jabuwu commented Nov 12, 2024

This is a bit awkward, because I don't think Bevy has support for this. A similar problem exists with gltf files. Loading a gltf file results in other files being loaded, but if the gltf file was an embedded asset, Bevy still tries to load these other files from disk.

It would be possible to do, but if your goal is to embed all assets, then I recommend using bevy_embedded_assets with PluginMode::ReplaceDefault, which will do this for you automagically.

The issue with using embedded_asset! is that you will also need to manually embed all the images, and then bevy_spine would need to provide some mechanism for adjusting the texture path. It's doable, but I think it's a hassle to manually add each texture as an embedded asset.

Adding an option to adjust Spine texture paths is a feature we should probably implement regardless.

@Droggelbecher
Copy link
Author

Hey thanks for the quick reply, I didn't know about bevy_embedded_assets, will check it out for sure, maybe it solves my problem completely.

In the meanwhile maybe you can help me understand better why this doesnt work in the first place.
I have at this stage a proc macro that calls embedded_asset! for every file in my asset directory so having everything preloaded is not an issue.
I'm just confused why bevy and/or bevy_spine end up looking at the file system in the first place.

I load the atlas using a URL like embedded://path/to/animation.atlas in which say animation.png is referenced. I would have assumed that bevy_spine (or rusty spine, not sure where the magic happens?) just changes the path from embedded://path/to/animation.atlas to embedded://path/to/animation.png by naively replacing the final component of the path.

This should in most cases be what user wants if you build on the assumption that the .png`s and the .atlas files live not only in the same directory (you are already assuming that) but also in the same filesystem. Can you clarify what actually happens?

@jabuwu
Copy link
Owner

jabuwu commented Nov 13, 2024

The asset loading in bevy_spine was written before assets could be loaded from multiple sources, so I'm not too familiar with how it works. I decided to check gltf files so I could steal their implementation, but since they didn't work, I assumed Bevy probably didn't have any way to differentiate.

It turns out there is, and I believe this is all we need: #28

@Droggelbecher
Copy link
Author

Indeed bevy_embedded_assets solved my problem quite well, thanks again for the pointer :) Would ofc still be cool to see bevy_spine allowing to load the pngs from the same place as the atlas file :)
From my side feel free to close this at your volition.

@jabuwu
Copy link
Owner

jabuwu commented Nov 18, 2024

Could you try pulling in the PR #28? If it works, I will merge it.

@Droggelbecher
Copy link
Author

Sorry, had a lot going on, looks good to me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants