When I export a material as j3m with setGenerateMips(false) in texture key, then if I load it, generateMips is set to true. Seems it is not saved in the j3m file and is generated by default when loading material:
Should we save generateMips state in j3m file so we won’t need to set it every time in code?
Edit:
Example code:
public class TestMipMap extends SimpleApplication {
J3MExporter j3MExporter = new J3MExporter();
public static void main(String[] args) {
TestMipMap test = new TestMipMap();
test.start();
}
@Override
public void simpleInitApp() {
exportMaterial();
loadMaterial();
}
private void exportMaterial() {
TextureKey key = new TextureKey("Common/Textures/MissingTexture.png");
key.setGenerateMips(false);
Texture tex = assetManager.loadTexture(key);
tex.setMagFilter(Texture.MagFilter.Nearest);
tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
Material material = new Material(assetManager, Materials.PBR);
material.setTexture("BaseColorMap", tex);
try {
j3MExporter.save(material, new File(".../assets/Materials/mat.j3m"));
} catch (IOException e) {
e.printStackTrace();
}
}
private void loadMaterial() {
Material material = assetManager.loadMaterial("Materials/mat.j3m");
TextureKey key = (TextureKey) material.getTextureParam("BaseColorMap").getTextureValue().getKey();
System.out.println("isGenerateMip=" + key.isGenerateMips());
}
}
As I recall, there are a lot of texture related things that you can’t set in a j3m like wrap modes and things.
In my real games where I need this externally configurable, I ended up using something other than j3m. It’s unfortunate but there is kind of a missing capability for these texture key add ons, I think.
From my Maud days, I recall that modifying a texture in JME and then writing it is tricky. Due to asset caching, what tends to happen is that the unmodified texture gets saved instead. I forget how I worked around that issue.
I mean when we want to disable mipmapping for an specific texture (because of possible artifacts on that texture (in my case gradient textures)) we should not need to generate them either. Generating them will be a waste then.
And doing this in j3m seems to be an easy way to do this.
It should be easy to add I guess. But I guess it will break existing j3m files that are using mipmapping by default. They will need to be updated to use the “Mips” keyword.