Learning Based 2D Irregular Shape Packing

Zeshi Yang, Zherong Pan, Manyi Li, Kui Wu, Xifeng Gao

TL;DR

Packing irregular 2D shapes into a tight space is a classic NP-hard problem that usually forces a trade-off between speed and efficiency. This paper introduces a learning-assisted pipeline that hierarchically groups UV patches into "super-patches" using reinforcement learning and deep neural policies. The result is a system that consistently outperforms industry-standard heuristics, achieving a 5–10% higher packing ratio while maintaining linear time scaling for complex models.

What Problem Does This Paper Address?

In computer graphics, 3D models are "unwrapped" into 2D patches (UV mapping) so that textures can be painted onto them. To save memory and improve rendering performance, these 2D patches must be packed as tightly as possible into a single square image called a texture atlas.

This is the 2D irregular shape packing problem. It is notoriously difficult because you have to decide both the order in which you pack hundreds of shapes and the optimal position and rotation for each one. Current industry tools usually rely on "greedy" heuristics (like the "Tetris" algorithm) which are fast but leave a lot of wasted empty space. On the other hand, global optimization methods that try to find the perfect fit are too slow to handle the hundreds of patches found in modern game assets.

Methods

The authors propose a hierarchical "divide and conquer" approach that breaks the massive packing problem into manageable chunks. Their pipeline consists of two main stages:

  1. Near-Rectangular Patch Generation: Instead of packing everything at once, the system identifies small subsets of patches that can be combined into a nearly rectangular "super-patch."
    • High-level Group Selector (HSN): A network that predicts which groups of patches will pack well together.
  2. Low-level Sorter (LSN) & Pose (LPN) Networks: Once a group is picked, these networks determine the best sequence to pack them and their initial rough positions/rotations. These are trained using Deep Reinforcement Learning (DDQN).
  3. Local Optimization: A numerical "squeezer" fine-tunes the poses to ensure no overlaps and maximum tightness.
  4. Super-Patch Assembly: Once the irregular shapes are turned into neat super-patches, the problem becomes a simpler "bin-packing" task. The system assembles these blocks, performs a final joint optimization to "squish" everything together, and then uses a scanline algorithm to fill any remaining tiny gaps with the smallest leftover patches.

Datasets

The researchers evaluated their method on three distinct datasets derived from 3D models:

  • Building: 86 man-made architectural models with sharp, geometric features.
  • Object: 81 models of daily items with smoother, organic shapes.
  • General: 221 diverse models from the Thingi10k repository, representing a wide variety of topological complexities.

The models were trained on one dataset and tested on others to prove the "zero-shot" generalization capability of the neural networks.

Key Insights and Ideas

  • Hierarchy is Key: The most significant "aha moment" is that you don't need a global brain to solve the whole puzzle. By training a network to recognize "good groups" (super-patches), the complexity of the problem scales linearly rather than exponentially.
  • Learning Intuition: Traditional algorithms use fixed rules (like "put the biggest piece first"). By using Reinforcement Learning, the LSN and LPN learn a "spatial intuition" for how shapes fit together, allowing them to find clever configurations that human-designed heuristics miss.
  • The "Super-Patch" Proxy: Treating a cluster of irregular shapes as a single rectangular unit simplifies the final assembly stage immensely without sacrificing much density, as the internal gaps are already minimized by the low-level networks.

Key Results

  • Higher Density: The method achieved a 5% to 10% improvement in packing ratio (the percentage of the atlas covered by patches) compared to baselines like XAtlas, NFP-Heuristic, and the Sander et al. algorithm.
  • Scalability: The computational cost scales linearly with the number of patches. In a test with 784 charts, the method was significantly faster than exact NFP (No-Fit Polygon) methods while producing much tighter results.
  • Generalization: A model trained on the "General" dataset performed nearly as well on "Building" and "Object" datasets, suggesting the networks learn fundamental geometric packing principles rather than just memorizing specific shapes.

Limitations and Future Work

While efficient, the method is currently slower than XAtlas (the fastest industry baseline) due to the overhead of running neural network inferences. The authors note that the "hole-filling" stage, currently implemented in Python, is a bottleneck that could be optimized with C++.

Additionally, the current action space for the AI doesn't easily allow it to place a small patch inside a hole of a larger, donut-shaped patch during the initial stages. The authors suggest that future versions could use more advanced architectures, like diffusion models or transformers, to handle even more complex spatial relationships and further bridge the gap between speed and perfection.

Summary updated

BibTeX
@article{yang2023learning,
  author = {Zeshi Yang and Zherong Pan and Manyi Li and Kui Wu and Xifeng Gao},
  title = {{Learning Based 2D Irregular Shape Packing}},
  journal = {ACM Trans. Graphics},
  year = {2023},
  url = {https://openreview.net/forum?id=MMv0FqzCvK},
}
Figure