diff --git a/crates/packer/src/atlasset.rs b/crates/packer/src/atlasset.rs index 8481fa7..16d048b 100644 --- a/crates/packer/src/atlasset.rs +++ b/crates/packer/src/atlasset.rs @@ -205,16 +205,19 @@ impl AtlasSet { ) })?; - self.index.index.insert( - p.to_path_buf(), - SpriteAtlasImage { - atlas: atlas_idx as u32, - x: (x + self.image_margin) as f32 / self.texture_width as f32, - y: (y + self.image_margin) as f32 / self.texture_height as f32, - w: image_dim.0 as f32 / self.texture_width as f32, - h: image_dim.1 as f32 / self.texture_height as f32, - }, - ); + self.index + .path_map + .insert(p.to_path_buf(), self.index.index.len() as u32); + + self.index.index.push(SpriteAtlasImage { + true_size: image_dim, + idx: self.index.index.len() as u32, + atlas: atlas_idx as u32, + x: (x + self.image_margin) as f32 / self.texture_width as f32, + y: (y + self.image_margin) as f32 / self.texture_height as f32, + w: image_dim.0 as f32 / self.texture_width as f32, + h: image_dim.1 as f32 / self.texture_height as f32, + }); return Ok(atlas_idx); } diff --git a/crates/packer/src/lib.rs b/crates/packer/src/lib.rs index d385233..204ad7b 100644 --- a/crates/packer/src/lib.rs +++ b/crates/packer/src/lib.rs @@ -13,6 +13,12 @@ pub struct SpriteAtlasImage { /// This is an index in SpriteAtlas.atlas_list pub atlas: u32, + /// A globally unique, consecutively numbered index for this sprite + pub idx: u32, + + /// The size of this image, in pixels + pub true_size: (u32, u32), + /// x-position of this image /// (between 0 and 1, using wgpu texture coordinates) pub x: f32, @@ -35,7 +41,10 @@ pub struct SpriteAtlasImage { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct SpriteAtlas { /// The images in this atlas - pub index: HashMap, + pub index: Vec, + + /// Map paths to image indices + pub path_map: HashMap, /// The file names of the atlas textures we've generated pub atlas_list: Vec, @@ -45,7 +54,8 @@ impl SpriteAtlas { /// Make an empty [`SpriteAtlasIndex`] pub fn new() -> Self { Self { - index: HashMap::new(), + path_map: HashMap::new(), + index: Vec::new(), atlas_list: Vec::new(), } }