MasDennis/Rajawali — pull request #782 by Davhed (2013-05-22 18:42:11+00:00)
Title: RFC: Texture packing

Well here we go!

Overview

The new class `TextureAtlas` is a collection of bitmaps, texture names, and texture coordinates.

`TexturePacker` is a utility to pack a group of textures into atlas "pages". Additional pages are created when the current page has no more space. The packing technique uses a "minimal heuristic" approach since research shows a small improvement in efficiency when additional (very complicated) heuristics are employed.

Packing

To pack textures you have a couple of options:

From Assets
You can create a new atlas from files in the `assets` folder, or any sub-folder therein.

`TextureAtlas mAtlas = new TexturePacker(mContext).packTexturesFromAssets(1024, 1024, 0, false, "atlas");`

The parameters are: int atlasWidth, int atlasHeight, int Padding, boolean useCompression, string SubFolder

From Resources
If you prefer to use resources you can bundle them up into an array and pack them.

`TextureAtlas mAtlas = new TexturePacker(mContext).packTexturesFromAssets(1024, 1024, 0, false, resIDs);`

The parameters are: int atlasWidth, int altasHeight, int padding, boolean useCompresison, int[] resourceIDs

Compression is not currently supported, so the flag is for future expansion (promised by @AndrewJo :smile: ).

Retrieval

Once packed you will need to be able to retrieve textures for use on your objects. To most simply achieve this I have added the functionality to `BaseObject3D`. This allows the developer to retrieve the target texture very simply.

`BaseObject3D.setAtlasTile("myTexture", mAtlas);`

Parameters are: string originalTextureName, TextureAtlas targetAtlas

This function also scales/transforms the object UVs to correspond to the textures position on the atlas page.

I think that pretty much covers it. I look forward to your input and feedback.