I’m trying to change my terrain splatting dynamically. My code uses a single alpha map to encode the splat texture. I have generated code that can modify and save changes to a PNG file, but I’m not sure how to reload the file at runtime.
I would greatly appreciate any help.
I’m building my code up from the TerrainTestModifyHeight example.
I would like to add a function like this, that loads a new alpha map file “alphamap2.png” (at runtime).
private void UpdateTerrainTextureSplatting_atRuntime()
{
// terrain and matTerrain are global
matTerrain.setTexture(“AlphaMap”, assetManager.loadTexture(“Textures/Terrain/splat/alphamap2.png”));
terrain.updateModelBound();
}
Thanks.
will not update the terrain unless the filename has changed. When i change the filename on each update (toggle between 2 filenames), the new splat loads, each time.
You can also clear the cache which will let it reload every time.
…but really, can you see that changing an image, writing a file, and reloading the file again is going to be WAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY slower than simply modifying the image?
Trying to impement this, but I seem to be missing something:
I create the global:
Texture AlphaTexture;
and use it to set the alpha texture at start up:
AlphaTexture = assetManager.loadTexture(“Textures/AlphaMap.png”);
matTerrain.setTexture(“AlphaMap”, AlphaTexture);
Then in my update function I get the image from AlphaTexture and wrap it in an ImageRaster:
ImageRaster imageRaster = ImageRaster.create(AlphaTexture.getImage());
I then try to chagne some pixels. The code runs without errors, but nothing changes on the actual render:
I can’t remember the magic incantations off the top of my head… maybe mipmaps are on and need to be regenerated.
You could try calling setImage() on the texture again just to make things try to update. Maybe someone else remembers the proper magic. It must have been near-obvious when I did this before because I can’t remember. So there is hope…