public static void makeLods(Collection<Geometry> geometries, Mesh outMesh) {
        // Determine number of LOD levels required.
        int lodLevels = Integer.MAX_VALUE;
        for (Geometry g : geometries) {
            lodLevels = Math.min(lodLevels, g.getMesh().getNumLodLevels());
        }
        if (lodLevels == Integer.MAX_VALUE || lodLevels == 0) {
            // No LOD on any of the meshes.
            return;
        }
        
        // Sizes of the final LOD index buffers for each level.
        int[] lodSize = null;
        for (Geometry g : geometries) {
            if (lodLevels == 0) {
                lodLevels = g.getMesh().getNumLodLevels();
            }
            if (lodSize == null) {
                lodSize = new int[lodLevels];
            }
            for (int i = 0; i < lodLevels; i++) {
                 lodSize[i] += g.getMesh().getLodLevel(i).getData().limit();
            }
        }

        // final LOD buffers for each LOD level.
        int[][] lodData = new int[lodLevels][];
        for (int i = 0; i < lodLevels; i++) {
            lodData[i] = new int[lodSize[i]];
        }
        VertexBuffer[] lods = new VertexBuffer[lodLevels];
        int bufferPos[] = new int[lodLevels];
        int numOfVertices = 0;


        int[] indexPos = new int[lodLevels];
        for (Geometry g : geometries) {
            numOfVertices = g.getVertexCount();
            for (int i = 0; i < lodLevels; i++) {
                boolean isShortBuffer = g.getMesh().getLodLevel(i).getFormat() == VertexBuffer.Format.UnsignedShort;
                if(isShortBuffer){
                    ShortBuffer buffer = (ShortBuffer) g.getMesh().getLodLevel(i).getDataReadOnly();
                    for (int j = 0; j < buffer.limit(); j++) {
                        lodData[i][bufferPos[i]] = (buffer.get()& 0xffff) + indexPos[i];
                        bufferPos[i]++;
                    }
                }else{
                    IntBuffer buffer = (IntBuffer) g.getMesh().getLodLevel(i).getDataReadOnly();
                    for (int j = 0; j < buffer.limit(); j++) {
                        lodData[i][bufferPos[i]] = buffer.get() + indexPos[i];
                        bufferPos[i]++;
                    }
                }
                indexPos[i] += numOfVertices;
            }

        }
        for (int i = 0; i < lodLevels; i++) {
            lods[i] = new VertexBuffer(Type.Index);
            lods[i].setupData(Usage.Dynamic, 1, Format.UnsignedInt, BufferUtils.createIntBuffer(lodData[i]));
        }
        outMesh.setLodLevels(lods);
    }
Merges all geometries in the collection into
the output mesh. Creates a new material using the TextureAtlas.

@param geometries the geometries to merge
@param outMesh a Mesh to receive the geometries
jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java