bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.71k stars 3.53k forks source link

Support bundling assets #606

Open emosenkis opened 4 years ago

emosenkis commented 4 years ago

The code that loads a PNG file into a Texture seems to be tightly coupled with the AssetServer's system for loading from the filesystem. It would be good to be able to use include_bytes! to bundle the file content but still take advantage of Bevy's support for loading assets of various types. It would be sufficient to add a method such as:

fn read_asset<P: AsRef<Path>, R: Read>(path: P, reader: R) -> HandleId { ... }

or even:

fn load_in_memory_asset<P: AsRef<Path>>(path: P, data: &[u8]) -> HandleId { ... }
emosenkis commented 3 years ago

I published a little crate that supports inline assets using only Bevy's public API (as of the current latest commit, at least): bevy_prototype_inline_assets. You can see it in action in budgers (WIP).

gilescope commented 1 year ago

include_str! for shaders would be nice too. - update: https://github.com/bevyengine/bevy/blob/92ba6224b9b66eb779683603e7022e421511dfe5/crates/bevy_asset/src/assets.rs#L388 looks good for shaders.

nicopap commented 1 year ago

What's the difference between the proposed solution and load_internal_asset!? It sounds like the requested feature now exists in bevy.

mockersf commented 1 year ago

load_internal_asset depends on the asset loader exposing a usable API, which it doesn't have too. For example it's not possible to use with the gltf loader