soimy / maxrects-packer

A max rectangle 2d bin packer npm-module for packing glyphs or images into multiple sprite-sheet/atlas

Home Page:https://soimy.github.io/maxrects-packer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow rotation

ksesong opened this issue · comments

Thanks for the library! Is there any plans to allow rotation of the rects to pack more in a given bin?

@ksesong Is it OK to just allow 0 or 90-degree rotation in packing? I'll be working on this soon

Yes, this was what I had in mind, and it should cover most situations.

Done via 7e914bc
@ksesong Can you do some test and report back?

I did some testing, and it does work in my situation (which is quite basic to be honest, so I can't talk about more complex scenarios). Thanks!
I would also mention in the description how you expect the rect to be rotated if rot is true (-90 degrees centered around the top-right corner).

@ksesong For the rects in the bin, only width, height, rot(boolean) is given as results. CW/CCW will have the same width \ height so that decision is yours when you actually composite your altas.

Take a lot at these code as an example:
https://github.com/soimy/msdf-bmfont-xml/blob/f1e5b6c58712a2461d150da015af3939863c3f42/index.js#L199-L204

      bin.rects.forEach(rect => {
        if (rect.data.imageData) {
          if (rect.rot) {
            rect.data.imageData.rotate(90);
          }
          img.composite(rect.data.imageData, rect.x, rect.y);
      }