Comparing version 0.2.0 to 0.2.1
31
index.js
@@ -38,2 +38,3 @@ /* | ||
this._cache = []; | ||
this._uvcache = Object.create(null); | ||
} | ||
@@ -51,2 +52,3 @@ module.exports = function() { | ||
this._cache = []; | ||
this._uvcache = []; | ||
rect = this._toRect(rect); | ||
@@ -127,2 +129,31 @@ if (this.left !== null) { | ||
Atlas.prototype.uv = function() { | ||
var self = this; | ||
if (self._uvcache.length > 0) { | ||
return self._uvcache; | ||
} | ||
(function loop(atlas) { | ||
if (atlas.left !== null) { | ||
loop(atlas.left); | ||
loop(atlas.right); | ||
} else if (atlas.rect.name) { | ||
self._uvcache[atlas.rect.name] = [ | ||
[atlas.rect.x, atlas.rect.y], | ||
[atlas.rect.x + atlas.rect.w, atlas.rect.y], | ||
[atlas.rect.x + atlas.rect.w, atlas.rect.y + atlas.rect.h], | ||
[atlas.rect.x, atlas.rect.y + atlas.rect.h], | ||
].map(function(uv) { | ||
if (uv[0] !== 0) { | ||
uv[0] = uv[0] / self.rect.w; | ||
} | ||
if (uv[1] !== 0) { | ||
uv[1] = uv[1] / self.rect.h; | ||
} | ||
return uv; | ||
}); | ||
} | ||
}(self)); | ||
return self._uvcache; | ||
}; | ||
// if has an image and canvas, draw to the canvas as we go | ||
@@ -129,0 +160,0 @@ Atlas.prototype._ontoCanvas = function(node) { |
{ | ||
"name": "atlaspack", | ||
"description": "Pack rectangles (or images) into a rectangle (or canvas texture atlas).", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"homepage": "https://github.com/shama/atlaspack", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -127,2 +127,14 @@ # atlaspack | ||
#### `atlas.uv()` | ||
Returns an object with rect names as keys containing an array of UV mapping | ||
coordinates between 0-1 with TRBL: | ||
```js | ||
var uvmap = atlas.uv(); | ||
/* { | ||
TOP RIGHT BOTTOM LEFT | ||
'name': [ [0,0], [1,0], [1,1], [0,1] ], | ||
} */ | ||
``` | ||
### `atlaspack.Rect(x, y, w, h)` | ||
@@ -145,2 +157,3 @@ Creates a rectangle instance. | ||
## release history | ||
* 0.2.1 - Add uv method for uv coordinates. | ||
* 0.2.0 - Add expand and index methods. | ||
@@ -147,0 +160,0 @@ * 0.1.0 - initial release |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15010
284
163