A LITTLE LESS EMPTY SPACE
3D bin packing in JavaScript
Build a load, explore the arrangement, and inspect every box with 3dbinpackingjs.
The arrangement
Calculate to see your load
Preparing example…
Inspect a box
02 / EXPLORELoad breakdown
Unpacked items
View text report
ABOUT 3DBINPACKINGJS
How does 3D bin packing work?
3D bin packing arranges rectangular boxes inside a container while trying to use its available volume. 3dbinpackingjs provides a single-container JavaScript packing heuristic and this interactive demo.
Enter the container dimensions, add box sizes and quantities, and choose a rotation rule for each box type. Calculate the arrangement, rotate the 3D view, and select a box to inspect its position and dimensions. Export the result as JSON or save the view as a PNG image. Calculations run locally in your browser.
The solver uses an EB-AFIT layer-based heuristic, ported from wknechtel/3d-bin-pack. It explores container-axis variants and candidate layers to find a high-volume arrangement. It does not guarantee the optimal packing.
Use the JavaScript bin-packing API
The standalone API works in Node.js through CommonJS or ES modules, and in a browser without a bundler. TypeScript declarations are included. From a repository checkout:
const { pack } = require('./pack.js');
const result = pack({
container: { width: 4, height: 3, depth: 2 },
items: [{
id: 'carton', width: 2, height: 3, depth: 4,
quantity: 1, rotation: 'upright'
}]
});
console.log(result.placements);
console.log(result.utilization); // 1 (100%)
See the API documentation and input format, performance and packing-quality benchmarks, or report a reproducible problem.
Common questions
Which box rotations are supported?
Free rotation permits all width, height, and depth permutations. Upright keeps the original height on the Y axis and permits width/depth swaps. Fixed preserves all three original axes.
Which measurement units should I use?
Use one consistent unit for every container and box dimension. For example, enter every dimension in millimeters. Quantities must be positive whole numbers.
Does a geometric fit guarantee a stable load?
No. The solver checks geometric fit, not weight, balance, box strength, or physical stability. Optional downward settling closes vertical gaps without changing packed volume. Base-contact diagnostics identify absent or partial contact, but even full base contact is not a stability certificate. Treat the visualization as a geometric arrangement, not a validated loading plan.
Can I install this package from npm?
The repository currently provides code for use from a checkout; it is not an npm release. Upstream licensing remains unresolved. Read the license status and provenance before adopting or redistributing the code.