Search in sources :

Example 1 with Tile

use of org.rajawali3d.materials.textures.TexturePacker.Tile in project Rajawali by Rajawali.

the class Object3D method setAtlasTile.

/**
	 * Maps the (x,y) coordinates of <code>tileName</code> in <code>atlas</code>
	 * to the TextureCoordinates of this BaseObject3D
	 *
	 * @param tileName
	 * @param atlas
	 */
public void setAtlasTile(String tileName, TextureAtlas atlas) {
    Tile tile = atlas.getTileNamed(tileName);
    FloatBuffer fb = this.getGeometry().getTextureCoords();
    for (int i = 0; i < fb.capacity(); i++) {
        double uvIn = fb.get(i);
        double uvOut;
        if (i % 2 == 0)
            uvOut = (uvIn * (tile.width / atlas.getWidth())) + tile.x / atlas.getWidth();
        else
            uvOut = (uvIn * (tile.height / atlas.getHeight())) + tile.y / atlas.getHeight();
        fb.put(i, (float) uvOut);
    }
    mGeometry.changeBufferData(mGeometry.getTexCoordBufferInfo(), fb, 0);
}
Also used : Tile(org.rajawali3d.materials.textures.TexturePacker.Tile) FloatBuffer(java.nio.FloatBuffer)

Aggregations

FloatBuffer (java.nio.FloatBuffer)1 Tile (org.rajawali3d.materials.textures.TexturePacker.Tile)1