mkeblx / domtex

DOM elements to WebGL textures
MIT License
3 stars 0 forks source link

Texture atlasing #19

Open mkeblx opened 6 years ago

mkeblx commented 6 years ago

Already init'd a basic test impl.

Next steps:

mkeblx commented 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

mkeblx commented 6 years ago

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.

mkeblx commented 6 years ago

Add option for adding border pixels, if find needed. https://gamedev.stackexchange.com/questions/61796/sprite-sheet-textures-picking-up-edges-of-adjacent-texture

mkeblx commented 6 years ago

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;
mkeblx commented 6 years ago

An existing solution can use/adapt: https://github.com/krzysztof-o/spritesheet.js/