Open mkeblx opened 6 years ago
Rectangle packing is a well known algorithm area, investigate further for better packing besides current vertical layout. https://www.codeproject.com/Articles/210979/Fast-optimizing-rectangle-packing-algorithm-for-bu
Note that this is somewhat mitigated by what I think will be main use case of using a template that elements laid out somewhat compactly.
Also, if do a suitable atlas packing, can pull out algo into a separate package that handles composition.
Add option for adding border pixels, if find needed. https://gamedev.stackexchange.com/questions/61796/sprite-sheet-textures-picking-up-edges-of-adjacent-texture
Output stats on atlas utilization:
var totalArea = atlas.width*atlas.height;
var usedArea = 0;
for (var i = 0; i < textures.length; i++) {
var texture = textures[i];
usedArea += texture.width*texture.height;
}
var percent = usedArea/totalArea;
An existing solution can use/adapt: https://github.com/krzysztof-o/spritesheet.js/
Already init'd a basic test impl.
Next steps: