Edit Terrain Texture

I have been working on a level editor. I now need to change the texture of points on the terrain. I tried to figure it out and ended up with this which does not appear to work.


public void changeTexture(Vector3f location, float radius) {

Material material = terrain.getMaterial(location);

Texture texture = (Texture) material.getTextureParam("AlphaMap").getValue();

Image image = texture.getImage();

List<ByteBuffer> data = image.getData();

System.out.println("data size: " + data.size());



Can someone point me to the code used in the terra monkey IDE plugin or point me in the right direction?


sdk code is there.

look into tools/PaintTerrainToolAction.java (manipulatePixel method)

they use:

[java]ByteBuffer buf = image.getData(0); [/java]

to get image data. Buffer contains ordered bytes for each channel (order is defined by image format).

And don’t forget to rewind data after edit.