private void gatherGeometries(Map<Material, List<Geometry>> map, Spatial n, boolean rebatch) {

        if (n instanceof Geometry) {

            if (!isBatch(n) && n.getBatchHint() != BatchHint.Never) {
                Geometry g = (Geometry) n;

                // Need to recalculate the max vert count whether we are rebatching this
                // particular geometry or not.
                if (maxVertCount < g.getVertexCount()) {
                    maxVertCount = g.getVertexCount();
                }

                if (!g.isGrouped() || rebatch) {
                    if (g.getMaterial() == null) {
                        throw new IllegalStateException("No material is set for Geometry: " + g.getName() + " please set a material before batching");
                    }
                    List<Geometry> list = map.get(g.getMaterial());
                    if (list == null) {
                        //trying to compare materials with the isEqual method
                        for (Map.Entry<Material, List<Geometry>> mat : map.entrySet()) {
                            if (g.getMaterial().contentEquals(mat.getKey())) {
                                list = mat.getValue();
                            }
                        }
                    }
                    if (list == null) {
                        list = new ArrayList<Geometry>();
                        map.put(g.getMaterial(), list);
                    }
                    g.setTransformRefresh();
                    list.add(g);
                }
            }

        } else if (n instanceof Node) {
            for (Spatial child : ((Node) n).getChildren()) {
                if (child instanceof BatchNode) {
                    continue;
                }
                gatherGeometries(map, child, rebatch);
            }
        }

    }
recursively visit the subgraph and unbatch geometries

@param s
jme3-core/src/main/java/com/jme3/scene/BatchNode.java