I have tried to create a flat terrain using the TerrainBlock and MidPointHeightMap which sort of works OK (I am not sure how else I can create a flat terrain)

      heightMap = new MidPointHeightMap(256, 1.9f); 
      Vector3f vector3f = new Vector3f(40F, 1.0F, 40F);
      tbloc = new TerrainBlock("FlatTerrain", heightMap.getSize(),
vector3f, heightMap.getHeightMap(), new Vector3f(0, 0, 0), false);

Then I add a box to it using

       locBox1 = new Vector3f(100,tbloc.getHeight(100,300),300);
TextureState boxTex = display.getRenderer().getTextureState();
       Texture tr = TextureManager.loadTexture(
                HandTrain.class.getClassLoader().getResource("data/crate.jpg"), Texture.MM_LINEAR,
                Texture.FM_LINEAR, true);
       box1.setModelBound(new BoundingBox());

The problem is, every time I run the code the box seems to appear in a different place. Does anybody know whats happening?

Do you mean a different height each time? Seems due to the heightmap you are using. If you want a truly flat one, why not just create one with image height map using a solid black image?

Well, all I am after is flat terrain which has a texture but I like the terrain to have a fairly large size.

why not just create one with image height map using a solid black image?

Do you mean using ImageBasedHeightMap(someImage)? Do you know if I can produce a reasonably large terrain with this?

You could probably create a large one simply by making your own height array and passing that in.

How do you pass a height array to ImageBasedHeightMap?


You don’t need to use the jME supplied terrain generation tools (like MidPointHeightMap). They’re just there for your convinience. You can create a height map (basically just an array of ints) however you want.

That is, the TerrainBlock constructor just takes an int[] as one of the arguments, not the actual derivative of AbstractHeightMap.


  // Specify the size of the terrain and setup the int[]
int terrainSize = 128;
int[] terrainMap = new int[terrainSize * terrainSize];

  // Optionally, initialize the height map to whatever
  //   height you want.  Java's default for int[] creation
  //   is '0'.
int elevation = 3;
for(int i = 0; i < terrainMap.length; i++) {
    terrainMap[i] = elevation;

  // Now, create the TerrainBlock.
  // (This is from the code in a previous post.. I don't
  //    remember off-hand all the TerrainBlock arguments.)
Vector3f vector3f = new Vector3f(40F, 1.0F, 40F);
TerrainBlock tbloc = new TerrainBlock("FlatTerrain", terrainSize, vector3f, terrainMap, new Vector3f(0, 0, 0), false);

The above code should generate a flat terrain of height '3'.

Hope this helps.


Thanks for the direction, I will test this today. If I was going to add a texture to this how do I go about it? The only thing I know at the moment is to create a node (say terrainNode) of which TerrainBlock is a child and then create a Texture and TextureState (say ts) and finally


Is this the right way of doing it?

You can set the render state of the terrain block itself.


no need to create the seperate node.