public static Node optimize(Node scene, boolean useLods) {
        ArrayList<Geometry> geoms = new ArrayList<>();

        gatherGeoms(scene, geoms);

        List<Geometry> batchedGeoms = makeBatches(geoms, useLods);
        for (Geometry geom : batchedGeoms) {
            scene.attachChild(geom);
        }

        for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) {
            Geometry geometry = it.next();
            geometry.removeFromParent();
        }

        // Since the scene is returned unaltered the transform must be reset
        scene.setLocalTransform(Transform.IDENTITY);

        return scene;
    }
Optimizes a scene by combining Geometry with the same material.
All Geometries found in the scene are detached from their parent and
a new Node containing the optimized Geometries is attached.
@param scene The scene to optimize
@param useLods true if you want the resulting geometry to keep lod information
@return The newly created optimized geometries attached to a node
jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java