private boolean addImage(Image image, String name, String mapName, String sourceTextureName) {
        if (rootMapName == null) {
            rootMapName = mapName;
        }
        if (sourceTextureName == null && !rootMapName.equals(mapName)) {
            throw new IllegalStateException("Atlas already has a master map called " + rootMapName + "."
                    + " Textures for new maps have to use a texture from the master map for their location.");
        }
        TextureAtlasTile location = locationMap.get(name);
        if (location != null) {
            //have location for texture
            if (!mapName.equals(mapNameMap.get(name))) {
                logger.log(Level.WARNING, "Same texture " + name + " is used in different maps! (" + mapName + " and " + mapNameMap.get(name) + "). Location will be based on location in " + mapNameMap.get(name) + "!");
                drawImage(image, location.getX(), location.getY(), mapName);
                return true;
            } else {
                return true;
            }
        } else if (sourceTextureName == null) {
            //need to make new tile
            Node node = root.insert(image);
            if (node == null) {
                return false;
            }
            location = node.location;
        } else {
            //got old tile to align to
            location = locationMap.get(sourceTextureName);
            if (location == null) {
                throw new IllegalStateException("Cannot find master map texture for " + name + ".");
            } else if (location.width != image.getWidth() || location.height != image.getHeight()) {
                throw new IllegalStateException(mapName + " " + name + " does not fit " + rootMapName + " tile size. Make sure all textures (diffuse, normal, specular) for one model are the same size.");
            }
        }
        mapNameMap.put(name, mapName);
        locationMap.put(name, location);
        drawImage(image, location.getX(), location.getY(), mapName);
        return true;
    }
Add a texture for a specific map name at the location of another existing texture (on the master map).
@param texture A texture to add to the atlas.
@param mapName A freely chosen map name that can be later retrieved as a Texture.
@param sourceTextureName Name of the master map used for the location.
jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java