A gravity-aware 3D spatial packing system that places multiple cuboid items inside a fixed-size container using deterministic heuristics. It ensures non-overlap, physical support, boundary compliance, and visually validates correctness through 3D rendering.
- Overview
- Features
- Folder Structure
- How to Run Locally
- Flow & Design Decisions
- Mermaid Flow Diagram
- Packing Strategy & Placement Logic
- Validation & Correctness
- Visualization
- Challenges & Trade-Offs
This project implements a 3D spatial packing system that places a set of cuboid items inside a fixed-size container (100 × 100 × 100).
The system respects gravity, prevents collisions, avoids floating objects, and ensures all items remain within container boundaries.
The solution follows a deterministic, rule-based approach rather than probabilistic or ML-based optimization, making it transparent, explainable, and easy to validate.
- Gravity-aware 3D placement
- Collision-free packing using AABB checks
- Deterministic heuristic-based strategy
- Layer-by-layer spatial placement
- Full boundary validation
- 3D visualization for proof of correctness
part2/
│
├── data/
│ └── Item_List.json
│
├── main.py
└── README.md
pip install open3d numpypython3 main.pyThe script will:
- Load item data
- Compute valid placements
- Validate constraints
- Launch a 3D visualization window
The system is designed around physical correctness first, followed by reasonable space utilization.
- Deterministic heuristics over optimization algorithms
- Height-aware item ordering to prevent future blockage
- Gravity enforced via support checks
- Simple, explainable placement rules
This ensures the system remains debuggable, extensible, and verifiable.
flowchart TD
A[Load Item_List.json] --> B[Normalize Item Dimensions]
B --> C[Sort Items by Height and Volume]
C --> D[Initialize Container & Z-Levels]
D --> E[Select Next Item]
E --> F[Scan Valid Z-Levels]
F --> G[Scan X-Y Positions]
G --> H{Within Container?}
H -- No --> G
H -- Yes --> I{Collision Check}
I -- Fail --> G
I -- Pass --> J{Support Check}
J -- Fail --> G
J -- Pass --> K[Place Item]
K --> L[Update Z-Levels]
L --> E
E -->|All Items Placed| M[Validation]
M --> N[3D Visualization]
- Items are sorted primarily by height, then by volume
- Taller items are placed earlier to avoid blocking future layers
- Smaller items naturally fill remaining gaps
For each item:
- Iterate over valid Z-levels
- Scan X–Y positions within container bounds
- Check collision using AABB logic
- Verify gravity support
- Place item and update environment state
After placement:
- Confirms all items are placed
- Ensures no item exceeds container limits
- Computes maximum height used
- Asserts physical validity
Example output:
Total boxes placed: 20 / 20
Maximum height used: 60 / 100
Packing validation successful
The final packing result is visualized using Open3D:
- Container rendered as a wireframe cube
- Each item rendered as a colored cuboid
- Allows camera rotation and zoom
- Serves as visual proof of correctness
- Packing is not globally optimal (NP-hard problem)
- Heuristic prioritizes correctness over maximal density
- Deterministic approach chosen for clarity and explainability