ndarray-bin-pack

1.0.2 • Public • Published

ndarray-bin-pack

unstable

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

NPM

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.

Package Sidebar

Install

npm i ndarray-bin-pack

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • mattdesl