/**
  * recursively visit the subgraph and unbatch geometries
  *
  * @param s
  */
 private void unbatchSubGraph(Spatial s) {
   if (s instanceof Node) {
     for (Spatial sp : ((Node) s).getChildren()) {
       unbatchSubGraph(sp);
     }
   } else if (s instanceof Geometry) {
     Geometry g = (Geometry) s;
     if (g.isBatched()) {
       g.unBatch();
     }
   }
 }
  private void gatherGeomerties(Map<Material, List<Geometry>> map, Spatial n, boolean rebatch) {

    if (n instanceof Geometry) {

      if (!isBatch(n) && n.getBatchHint() != BatchHint.Never) {
        Geometry g = (Geometry) n;
        if (!g.isBatched() || 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;
        }
        gatherGeomerties(map, child, rebatch);
      }
    }
  }