0.2.1 • Published 9 years ago
texture-atlas v0.2.1
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])
canvasHTMLCanvasElement A canvas element to store atlas.optionsObjecttilepadBoolean If true, each packed image pads itself with a tiled pattern of itself. Useful for avoiding texture bleeding when mipmapping.
Atlas#pack(id, drawable)
idstring texture id. used byAtlas#uvandAtlas#uv2.drawableHTMLImageElement | HTMLCanvasElement texture image.Altas#packreturnsnullon failure.
Atlas#expand(id, drawable)
idstring texture id. used byAtlas#uvandAtlas#uv2.drawableHTMLImageElement | HTMLCanvasElement texture image.Altas#expanddoes not return a new Atlas instance. It mutates the calling instance.
Atlas#uv()
Atlas#uvdoes not receive any parameter. It usesaltas.canvaswidth and height.
Atlas#uv2()
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#jsonhas been removed.
Atlas#_debug
Atlas#_debughas been moved intoutilsnamespace.
import { debug } from 'texture-atlas/lib/utils';
debug(atlas);install
$ npm install texture-atlasDevelopment
Build
$ npm run build
$ npm run build:watchTest
$ npm testRun example
$ npm run start:exampleCredits
Kyle Robinson Young (@shama) for code from atlaspack
License
MIT