secnot / rectpack

Python 2D rectangle packing library
Apache License 2.0
465 stars 104 forks source link

Add weights for objects, and limit the total weight in a bin #1

Open samwyse opened 7 years ago

samwyse commented 7 years ago

From time to time, I have a number of STL files that I would like to 3D print. It was simple enough to read a bill of materials and pack objects into a bin the size of my printer's bed. However, my printer's software is limited to about a million triangles in an object description, and my bins are regularly containing five times that many. I need to tweak the packing algorithms to account for this. Any advice would be appreciated.

secnot commented 7 years ago

I would just print over the full table in several batches to circunvent the triangle limitation.

If that doesn't work create a new packer that keeps track of free triangles for each bin, and modify add_rect to ignore bins where there aren't enough triangles for the rectangle being packed. This solution could end with a lot of wasted space depending on bin size and triangle limit.

You could then reuse this wasted space and create new bins to continue packing. Guillotine algorithm keeps track of unused space in self._sections, so it wouldn't be too hard. In the end you would also end printing in several batches (hopefully a few less).

If you want to design a new algorithm/heuristic that takes into account both the rectangle size and its weight, you need a new fitness function to decide which rectangle is the best for the bin. I don't think it's worth the effort.