This is a screenshot of the demo. In the demo, 7 rectangles are fed to three different rectangle packers. The results from these packers are then rendered using different colors. The set of red rectangles (top left) is unpacked.
Installation is the same as any other Godot plugin from GitHub.
I recommend using a git submodule to clone:
cd your_project/addons
git submodule add https://github.com/kibble-cabal/rect-pack-2d.git rect_pack_2d
git submodule update --init
Otherwise, you can:
- Clone the normal way
cd your_project/addons
git clone https://github.com/kibble-cabal/rect-pack-2d.git rect_pack_2d
- Download a ZIP file
I have also provided the cleaned
branch, which removes README.md
, screenshot.png
, icon_grey.png
, and the demo
folder.
Feel free to use either of these commands instead, if you'd like:
# Using submodules
cd your_project/addons
git submodule add -b cleaned https://github.com/kibble-cabal/rect-pack-2d.git rect_pack_2d
git submodule update --init
# Cloning
cd your_project/addons
git clone -b cleaned https://github.com/kibble-cabal/rect-pack-2d.git rect_pack_2d
extends Node2D
func _draw() -> void:
var packer := RectPack2D.new()
var rects: Array[Rect2] = [
Rect2(0, 0, 100, 100),
Rect2(100, 100, 150, 50),
Rect2(200, 200, 25, 100)
]
var output := packer.pack(rects)
for rect in output.get_rects():
draw_rect(rect, Color(randf(), randf(), randf()))
You can also check out the demo
folder for a more complex example.
- Nested grids, to remove the empty spaces
- Reordering (by size, shape, etc.) to pack more intuitively and tightly