public static IntMap<IrMesh> splitByMaterial(IrMesh mesh) {
        IntMap<List<IrPolygon>> materialToPolyList = new IntMap<>();
        for (IrPolygon polygon : mesh.polygons) {
            int materialIndex = -1;
            for (IrVertex vertex : polygon.vertices) {
                if (vertex.material == null) {
                    continue;
                }
                if (materialIndex == -1) {
                    materialIndex = vertex.material;
                } else if (materialIndex != vertex.material) {
                    throw new UnsupportedOperationException("Multiple materials "
                                                 + "assigned to the same polygon");
                }
            }
            List<IrPolygon> polyList = materialToPolyList.get(materialIndex);
            if (polyList == null) {
                polyList = new ArrayList<IrPolygon>();
                materialToPolyList.put(materialIndex, polyList);
            }
            polyList.add(polygon);
        }
        IntMap<IrMesh> materialToMesh = new IntMap<>();
        for (IntMap.Entry<List<IrPolygon>> entry : materialToPolyList) {
            int key = entry.getKey();
            List<IrPolygon> polygons = entry.getValue();
            if (polygons.size() > 0) {
                IrMesh newMesh = new IrMesh();
                newMesh.polygons = new IrPolygon[polygons.size()];
                polygons.toArray(newMesh.polygons);
                materialToMesh.put(key, newMesh);
            }
        }
        return materialToMesh;
    }
Separate mesh with multiple materials into multiple meshes each with 
one material each.

Polygons without a material will be added to key = -1.

@param mesh the input IrMesh (not null)
@return a new IntMap containing the resulting meshes
jme3-plugins/src/main/java/com/jme3/scene/plugins/IrUtils.java