Crates.io | sheep |
lib.rs | sheep |
version | 0.3.0 |
source | src |
created_at | 2019-07-13 21:50:32.122453 |
updated_at | 2019-08-18 12:30:07.220913 |
description | Modular and lightweight spritesheet packing library |
homepage | https://amethyst.rs/ |
repository | https://github.com/amethyst/sheep |
max_upload_size | |
id | 148851 |
size | 85,597 |
sheep
(Spritesheet packer) is a lightweight and modular library used to create spritesheets. It aims to impose as little restrictions as possible on the usage of its API so that it can be used in asset pipelines.
The project is in heavy development and the API might change a few times until we reach a stable version, but the general flow of inputting bytes and receiving metadata and a byte vec will remain the same.
To use the CLI, simply install it with cargo:
cargo install sheep_cli
Usagen hints are provided. To see all options, simply run the command with no arguments. Options can be passed to the packers using the --options
flag, as space separated key=value
pairs.
By default, the maxrects
packer will be used, see packers for more information.
Example:
sheep pack --options max_width=1024 max_height=1024 sprites/*.png
If you want to use the CLI from source, simple clone the repo and run cargo run -- ...
. For an example on how to use the library directly, please see the simple_pack
example in the sheep/examples
directory.
Packer
and Format
Sheep achieves its modularity by letting you choose the implementation it will use for packing the sprites and encoding the metadata. Right now, two common packing algorithms are provided (SimplePacker
and MaxrectsPacker
, see packers), as well as the data format used by the amethyst engine (AmethystFormat
). There will be more in the future, however, you can also choose your own packing algorithm and format:
Packer
pub struct MyPacker;
impl Packer for MyPacker {
fn pack(sprites: &[SpriteData]) -> PackerResult {
// Spritedata contains an id for the sprite to reference back
// to it, and the dimensions of the sprite.
// The expected output is the dimensions of the resulting spritesheet,
// as well as all the anchors for the sprites (i.e. their positions).
PackerResult { dimensions, anchors }
}
}
Format
pub struct MyFormat;
// This is the format that will be output by encode, and you'll probably want
// to serialize later.
#[derive(Serialize)]
pub struct Foo {}
impl Format for AmethystFOrmat {
type Data = Foo;
fn encode(dimensions: (u32, u32), sprites: &[SpriteAnchor]) -> Self::Data {
// Encode the spritesheet dimensions and sprite positions into
// your chosen data format here.
Foo {}
}
}
impl
sTo use custom packers or formatters, simply pass them as type parameters when calling the functions:
let sprite_sheet = sheep::pack::<MyPacker>(sprites, 4);
let meta = sheep::encode::<MyFormat>(&sprite_sheet);
Right now, there are two implementations to choose from:
Implementation of the maxrects sprite packing algorithm. The paper and original implementation used as a reference for this can be found here. This algorithm should yield optimal results in most scenarios.
A naive implementation that will sort the sprites by area and then pack them all into a single texture. This won't scale very well since you can't limit the maximum size of the resulting sprite sheet, but can be quicker than maxrects in simple scenarios.
Here are the planned features for sheep
:
sheep
is dual licensed under MIT and Apache, see COPYING
.