boxpack2d.py - how does it work?

could anyone give a short description of how the box packing algorithm of boxpack2d.py works?

I ported this to C and now its a accessed from Blender.Geometry so the py script isnt needed anymore

Algo is fairly simple - adds boxes largest to smallest and keeps trying to pack into the bottom left hand corner. it sorts the available attach locations in a way that results in a square.

thanks for your answer! :slight_smile:

does the c version do exactly the same only faster?

where did you learn about box packing or did you invent the algorithm completely yourself?

what is the attach location?

C does the same, lots faster, and its a bit easier to read also,
google boxpack2d.c for the C one. koders has it.
the algo is one I worked out, tho it seemed the most obvious way to do it, so not sure its that original. At the time I couldnt find any oss boxpackers like this. as well as needing to place UV’s efficiently on a texture. - Ctrl+P in the UV View now.

Attach locations or verts are from the placed boxes, whenever a box is placed at adds 3 verts to the vert list, and flags the quaderents of the verts that are inside the box, so those areas are not tested.

1 Like

thanks! i will look into the c version but i think it will take a few days before i fully understand it. :stuck_out_tongue:

you did a great job on the box packer and smart projections!

btw. what is the point of lightmap uvpack? in my tests smart projections always worked better for baking lightmaps.

Re Lightmap pack…

Yes, projections can often work better, but in some cases projections can waist a large ammount of texture space. with really good island merging it maye be possible to make this less of a problem, but that is reallllly slow.

With some practice cases I was only getting ~60% texture efficiency because of wall rims. - some intelligent island breaking could be good here.

Anyhow lightmap uvpack gives very predictable results all the time. and guarantees you dont get lots of space waisted. - if you see artifacts, increase the margin.