private static Texture getMaterialTexture(Geometry geometry, String mapName) {
        Material mat = geometry.getMaterial();
        if (mat == null || mat.getParam(mapName) == null || !(mat.getParam(mapName) instanceof MatParamTexture)) {
            return null;
        }
        MatParamTexture param = (MatParamTexture) mat.getParam(mapName);
        Texture texture = param.getTextureValue();
        if (texture == null) {
            return null;
        }
        return texture;


    }
Creates one geometry out of the given root spatial and merges all single
textures into one texture of the given size.
@param spat The root spatial of the scene to batch
@param mgr An asset manager that can be used to create the material.
@param atlasSize A size for the atlas texture, it has to be large enough to hold all single textures.
@return A new geometry that uses the generated texture atlas and merges all meshes of the root spatial, null if the atlas cannot be created because not all textures fit.
jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java