[SOLVED] Allow to set generate mips for a texture in the j3m file


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?


Example code:

public class TestMipMap extends SimpleApplication {

    J3MExporter j3MExporter = new J3MExporter();

    public static void main(String[] args) {
        TestMipMap test = new TestMipMap();
    public void simpleInitApp() {

    private void exportMaterial() {
        TextureKey key = new TextureKey("Common/Textures/MissingTexture.png");
        Texture tex = assetManager.loadTexture(key);

        Material material = new Material(assetManager, Materials.PBR);
        material.setTexture("BaseColorMap", tex);

        try {
            j3MExporter.save(material, new File(".../assets/Materials/mat.j3m"));
        } catch (IOException e) {


    private void loadMaterial() {
        Material material = assetManager.loadMaterial("Materials/mat.j3m");
        TextureKey key = (TextureKey) material.getTextureParam("BaseColorMap").getTextureValue().getKey();
        System.out.println("isGenerateMip=" + key.isGenerateMips());

what if this is dds with own mipmaps? etc? im not sure. also curious.

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.

1 Like

AFAIK wrap mode, flipY, min and mag filters are supported.

BaseColorMap : Flip WrapRepeat_S WrapRepeat_T MagNearest MinNearestNoMipMaps "Materials/mat-6/BaseColor-2.png"

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.

Mmmm… that may be new. My experience with this particular issue is like 8 years old now.

Perhaps when the features were added to the parser, they were not also added to the exporter.

By the way, in case of a misunderstanding! I do not mean to export mips with texture.

I mean to add a keyword in j3m i.e “Mips” to let the user enable/disable mips generation in j3m.

Just like we are doing for flip and min filter and mag filter.

Something like this:

Material mat-6 : Common/MatDefs/Light/PBRLighting.j3md {

    MaterialParameters {
      BaseColorMap : Mips "Materials/image.png"


Why do you need something like this?

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.

I got confused along the way. Is it that j3m doesn’t support a Mips option or that the exporter just doesn’t write it?

Either way, I think all texture key options should probably be supported if it’s easy.


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.

Or make it NoMips instead of Mips. Default to true.

1 Like


The engine will not generate mipmaps if you use a MinFilter that doesn’t require mipmaps and you can set it from the material.

Seems it does.

setGenerateMips is set to true by default regardless of MinFilter type. Unless I am getting something wrong here.

I think he means that even if you set generate mips to true, if the texture doesn’t need it then they won’t be generated.

I cannot confirm or deny as I haven’t looked at the code. Just interpreting.

1 Like

Yes, this is the code that tells opengl to generate mipmaps

The value in the texture key is used here

And the code that sets the texture options (included minfilter) in the mat loader is here

So the texture key value is just to set the default min filter to trilinear basically.

1 Like

Ah, I see. Thanks for the help.

Edit: Changed topic to SOLVED.