HeightMap in Float[] export to Image

Hey JME-Com!
I search now for quite a bit to say I realy dont know what to do.
What I try is to export the Heightmap of my Terrain (which I created in Terramonkey),
to recreate it in Blender and create a Model which fits into the terrain as a Ground (to also make it visible from bottom).
The forum helped me to get the HeightMap in Float[] format

Spatial terrainH = myHomeNode.getChild(0);
Terrain helpT = (Terrain) terrainh ;
float[] heightmapF  =  helpT.getHeightMap();

I know that their a Classes like HeightMap who help get Pictures into the Float[] format, but is this process also inverseable ? To get a Picture out of the Floats ?
Thanks in advance

It’s clearly reversible but as I’m at work right now I don’t have any ready code to give you.
BUT … I don’t understand what you are trying to achieve.
a terrain by definition IS a ground …
You want to make it visible from below ? Just do that with “Culling”

My approach would be to convert your floats to a 8bit value someway.
Then just use a bufferedimage and setRGB() for each pixel on it.
The more problematic part would be to defince properly that both jme and blender interpret black and white with the same absolute height difference.

Sry its hard to describe in a other language xP
What I want is a Model which looks like a floating island(like in Avatar f.e.).
But because of Textures Store Problems I want to create a Terrain with terramonkey and do the part which you see when you look at the island from bottom with Blender. (so the floating island is in two parts)
When I got the Heightmap from the Terrain in Blender as a Model its easy to create the other part and then load it ingame at the same position. (my thought)

I dont think I need the exact same map size to encase the terrain in Blender.
The Length of float[] heightmapF is 263169 so its just a 513x513 picture where every pixel got a % of blackness or ?

Thx for the fast awnsers :smiley:

@serokon : ok now I see … I wouldn’t do it this way but I’ll just suppose you have good reasons to achieve what you want to do the way you want to do it.

How I would create a heightmap from a terrain :

Start by creating an Image of a certain size, size let’s say (size_x, size_y).
You then want to iterate through all pixels in this image :

for (int x = 0 ; x < size_x ; x++) {
    for (int y = 0 ; y < size_y ; y++) {
        // here you are at pixel (x,y)
        // for this pixel (x,y), just compute the "real" terrain position according to its size
        // for example, pixel (10,10) in the image may have a position of (3.23,3.23) in your terrain
        //        pixel (20,20) may have a position of (6.46,6.46)
        // let's say this real terrain position is (terrain_x, terrain_z)
        // all you need to do is :
        // terrain.getHeight(new Vector2f(terrain_x,terrain_z));
        // from this height you then compute a color following a math function that fits your needs
        // then put this pixel in your image
// here you have your image. All you need to do is write it to a file.

Please correct me if I’m wrong or if you have a better way.

jep you now exactly what I mean.
I also got already the points and its hights in a Float Array (with 513x513 entrys).
Now I just need to make Funktion with the Float input and a color output :stuck_out_tongue:

//Edit: okay their we go

Spatial terrainH = myHomeNode.getChild(0);
Terrain helpT = (Terrain) terrainh ;
float[] heightmapF  =  helpT.getHeightMap();
 double p = Math.sqrt(heightmapf.length);
       int q = (int) p;
       int counter = 0;
   BufferedImage image = new BufferedImage(q,q,BufferedImage.TYPE_INT_RGB);
    for (int x = 0 ; x < q ; x++) {
for (int y = 0 ; y < q ; y++) {
  // System.out.println(heightmapf[counter]);
 double value = 0;
   value = Math.round(heightmapf[counter]); // Ergebnis: 1.23
   int qq = (int) value; // OR int qq = 255- (int) value;
    image.setRGB(x, y, new Color (qq,qq,qq).getRGB());
  counter = counter+1;
    File outputfile = new File("saved.png");
    try {
        ImageIO.write(image, "png", outputfile);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);