I’m trying to extract the embedded materials from my terrains to save them for editing purposes, but I am getting this error when I try to save a material that has a TextureArray. It consistently works fine for any terrain material that does not have texture array matParams, so I am assuming that is the cause.
Here is the error that happens when calling j3mExporter.save(terrainMaterial, savePath); to save a material with a texture array:
I tried to find the J3MExporter class on github to take a look at the line of code throwing the error, but couldn’t find it in the materials package I expected it to be based in its package declaration.
It looks like the null error is due to the material’s TextureArrays having a null AssetKey when the material is being saved.
This line specifically:
Is it possible to save an entire Texture Array in some other format like DDS (i think?) that supports multiple image layers? I tried saving as standard PNG just to try it, but did not expect it to work since all png/jpg saving methods with JME I’ve seen save a single image, wheras the TextureArray contains a list of images that need saved to a single asset key.
Or is it just better to recreate the TextureArray at run time and avoid saving/loading any TextureArrays? This is what I’m currently doing, and going this route I could just bypass the null error in my original post by saving a blank string as the asset key for any TextureParams that are actually Texture Arrays.
Sorry for bumping my own thread, but I’m curious if anyone has any input on the best way to go forward with ‘saving’ a material with a texture array
I have 3 ideas so far:
Avoid saving the texture array, and set a blank texture key in the material and just recreate it on launch by my own means
Make a PR to J3MExporter to append all of the texture keys within the TextureArray into a single concatenated string, and have the J3MExporter load and recreate the TextureArray using these texture keys
Make a PR that tries to save the texture array in an image format that supports multipe image layers.
Number 3 sounds easiest but I have no clue how to properly save/load formats other than single image png/jpg types so I’m leaning towards number 2. But number 2 would also recreate a new texture array for every material, even if the texture arrays are identical.
I would like to hear some input from others before I attempt to add code to a class within the core engine.
Sounds good, when I get a chance I will submit a PR saving the texture array to j3o.
It’s looking like I will want to make a PR to the J3MExporter class I linked, and also to the read method of the Material class.
Specifically, I will add an if statement at this line to check if the MatParamTexture is of VarType TextureArray, and if so I will make it then read / write the mat param for the texture array as a normal j3o file instead.