diff --git a/engine/src/tools/jme3tools/optimize/TextureAtlas.java b/engine/src/tools/jme3tools/optimize/TextureAtlas.java index f752d7d5b..9a9329e15 100644 --- a/engine/src/tools/jme3tools/optimize/TextureAtlas.java +++ b/engine/src/tools/jme3tools/optimize/TextureAtlas.java @@ -57,7 +57,46 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - * + * TextureAtlas allows combining multiple textures to one texture atlas. + *

After the TextureAtlas has been created with a certain size, textures can be added for + * freely chosen "map names". The textures are automatically placed on the atlas map and the + * image data is stored in a byte array for each map name. Later each map can be retrieved as + * a Texture to be used further in materials.

+ *

The texture asset key name for each tile as well as its location inside the atlas is stored + * and a texture with an existing key name is not added more than once to the atlas. You can access + * the information for each texture or geometries texture via helper methods.

+ *

For each texture name you can also adapt a set of texture coordinates of a mesh or geometry + * to point at the new locations of the texture inside the atlas if the geometries texture + * exists inside the atlas.

+ *

Note that models that use texture coordinates out of the 0-1 range (repeating/wrapping textures) + * will not work correctly as their new coordinates leak into other parts of the atlas and thus display + * other textures instead of repeating the texture.

+ * + *

Usage examples

+ * Create one geometry out of several geometries that are loaded from a j3o file: + *
+ * Node scene = assetManager.loadModel("Scenes/MyScene.j3o");
+ * Geometry geom = TextureAtlas.makeAtlasBatch(scene);
+ * rootNode.attachChild(geom);
+ * 
+ * Create a texture atlas and change the texture coordinates of one geometry: + *
+ * Node scene = assetManager.loadModel("Scenes/MyScene.j3o");
+ * //either auto-create from node:
+ * TextureAtlas atlas = TextureAtlas.createAtlas(scene);
+ * //or create manually by adding textures or geometries with textures
+ * TextureAtlas atlas = new TextureAtlas(1024,1024);
+ * atlas.addTexture(myTexture, "DiffuseMap");
+ * atlas.addGeometry(myGeometry);
+ * //create material and set texture
+ * Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
+ * mat.setTexture("DiffuseMap", atlas.getAtlasTexture("DiffuseMap"));
+ * //change one geometry to use atlas, apply texture coordinates and replace material.
+ * Geometry geom = scene.getChild("MyGeometry");
+ * atlas.applyCoords(geom);
+ * geom.setMaterial(mat);
+ *