Skip to content

Instantly share code, notes, and snippets.

@ethereumdegen
Last active September 20, 2023 00:56
Show Gist options
  • Save ethereumdegen/f028b1072f8d91ccd8972bf846b4e189 to your computer and use it in GitHub Desktop.
Save ethereumdegen/f028b1072f8d91ccd8972bf846b4e189 to your computer and use it in GitHub Desktop.
Trying to load image from within a zip file with bevy 0.12-dev -- seems i cannot
/*
Trying to load an image from within a zip file with bevy 0.12-dev -- seems i cannot
*/
impl AssetLoader for TerrainPackLoader {
type Asset = TerrainPack;
type Settings = ();
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a (),
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<TerrainPack, anyhow::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let cursor = Cursor::new(bytes);
let archive = ZipArchive::new(cursor).unwrap();
let color_texture_reader = archive.by_name("color_texture.png")?;
let height_texture_reader = archive.by_name("height_texture.png")?;
let albedo_texture_reader = archive.by_name("albedo_texture.png")?;
//THIS IS AN ERROR BECAUSE LOAD ONLY TAKES A STRING NOT A READER SADLY
let mut color_texture = load_context.load( color_texture_reader );
let terrain_pack = TerrainPack{
color_texture,
height_texture ,
albedo_texture ,
};
Ok(terrain_pack)
})
}
//MAKE SURE THIS IS RIGHT
fn extensions(&self) -> &[&str] {
&["mappack"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment