texture-atlas
v0.2.1
Published
atlaspack rewritten in TypeScript
Downloads
4
Maintainers
Readme
texture-atlas
atlaspack rewritten in TypeScript with some API changes.
API changes
Most of this API changes are meant to promote type consistency.
Use ES6 module
// Import module
// es6
import { Atlas } from 'texture-atlas';
// commonjs
const Atlas = require('texture-atlas').Atlas;
// Create an instance
const canvas = getCanvasElementSomehow();
const atlas = new Atlas(canvas);
No factory function
Create an instance using new
operator.
new Atlas(canvas[, options])
canvas
HTMLCanvasElement A canvas element to store atlas.options
Objecttilepad
Boolean If true, each packed image pads itself with a tiled pattern of itself. Useful for avoiding texture bleeding when mipmapping.
Atlas#pack(id, drawable)
id
string texture id. used byAtlas#uv
andAtlas#uv2
.drawable
HTMLImageElement | HTMLCanvasElement texture image.Altas#pack
returnsnull
on failure.
Atlas#expand(id, drawable)
id
string texture id. used byAtlas#uv
andAtlas#uv2
.drawable
HTMLImageElement | HTMLCanvasElement texture image.Altas#expand
does not return a new Atlas instance. It mutates the calling instance.
Atlas#uv()
Atlas#uv
does not receive any parameter. It usesaltas.canvas
width and height.
Atlas#uv2()
Atlas#uv2
returns uv inFloat32Array
format. ( shape = [4, 2], stride = [2, 1] )
const uv1 = atlas.uv()['my_awesome_uv'];
const uv2 = atlas.uv2()['my_awesome_uv'];
assert(uv1[0][0] === uv2[0]);
assert(uv1[0][1] === uv2[1]);
assert(uv1[1][0] === uv2[2]);
assert(uv1[1][1] === uv2[3]);
assert(uv1[2][0] === uv2[4]);
assert(uv1[2][1] === uv2[5]);
assert(uv1[3][0] === uv2[6]);
assert(uv1[3][1] === uv2[7]);
Atlas#json
Atlas#json
has been removed.
Atlas#_debug
Atlas#_debug
has been moved intoutils
namespace.
import { debug } from 'texture-atlas/lib/utils';
debug(atlas);
install
$ npm install texture-atlas
Development
Build
$ npm run build
$ npm run build:watch
Test
$ npm test
Run example
$ npm run start:example
Credits
Kyle Robinson Young (@shama) for code from atlaspack
License
MIT