ndarray-bin-pack
v1.0.2
Published
bin-pack an array of rectangles into an atlas
Downloads
7
Maintainers
Readme
ndarray-bin-pack
A simple bin-packer for a list of ndarray objects. Guesses depth and dtype from the first ndarray object.
Can be used for packing 2D sprites into a single texture atlas.
var pack = require('ndarray-bin-pack')
//pack a list of ndarrays
var atlas = pack(boxes)
console.log(atlas.bins)
// [ { position, shape }, { position, shape } ]
console.log(atlas.array)
// ndarray for the whole atlas
console.log(atlas.array.shape)
// size of final atlas
The input array must have a length greater than zero.
See demo/index.js for an example application.
Usage
atlas = pack(ndarrays)
Bin-packs the list of ndarrays
(must be a non-empty list) into a single atlas.
The return value is:
{
array: array, //the ndarray for the whole atlas
bins: [
{ position: [x, y], shape: [w, h, d] },
... etc
]
}
Where bins
is parallel to the array that was provided as input.
License
MIT, see LICENSE.md for details.