Flat terrain instead of hills

Hello, I’ve been trying to import an image-based heightmap, but the problem is that in-game it shows up as completely flat.



[java]private void createTerrain(String terrainFile) {

/** 1. Create terrain material and load four textures into it. */

Material mat_terrain = new Material(assetManager,

“Common/MatDefs/Terrain/Terrain.j3md”);

Texture grass = assetManager.loadTexture(

“Textures/Terrain/splat/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex1”, grass);

mat_terrain.setFloat(“Tex1Scale”, 64f);



AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager.loadTexture(“testimg.png”);



heightMapImage.getImage().setFormat(Format.RGB8);



//some debug code to see what the image looks like

try {

ImageIO.write(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), “png”, new File(“testimg.png”));

} catch (IOException e) {

e.printStackTrace();

}

heightmap = new ImageBasedHeightMap(heightMapImage.getImage());

heightmap.load();



System.out.println(Arrays.toString(heightmap.findMinMaxHeights()));



TerrainQuad terrain;

terrain = new TerrainQuad(“terrain”, 257, 257, heightmap.getScaledHeightMap());

terrain.setMaterial(mat_terrain);

rootNode.attachChild(terrain);



}[/java]



What the ImageIO gave me:





When I use a HillHeightMap, it suddenly does show up as a hilly terrain, so it is probably going wrong somewhere around heightmap.load()

what happens if you change:

terrain = new TerrainQuad(“terrain”, 257, 257, heightmap.getScaledHeightMap());

to

terrain = new TerrainQuad(“terrain”, 257, 257, heightmap.getHeightMap());

@Sploreg When you pass a null heightmap to terrainquad it’s generated as flat, maybe something similar is happening here?

yep that is true, but it looks like his code is passing in an actual heightmap.

Unless the posted code it not what he is using… @werner291, can you double check that when you create the terrain (new TerrainQuad…) that the heightmap being passed in is not null?

I’ve changed getScaledHeightMap() to getHeightMap(), and I’m shure that the heightmap isn’t null (after a long fight with the debug mode).



Something I’ve noticed: The heightmap isn’t exactly 0, but rather between 0 and 1, and although very hardly, some relief can be seen on the terrain. I’ll see if I can scale it somehow. Is heightmap scaling some new feature on JME3?



EDIT: YES! That was it! It wasn’t scaled. I’ve worked with terrain before, this is gotta be a new feature. I’ve notices other changes.



Can this be updated in the “hello terrain” tutorial? The changes I noticed: ImaeBasedHeightmap now uses Image instead of BufferedImage, and this heightmap scale variable. What my code looks like now:



[java]private void createTerrain(String heightMapFile) {

Material mat_terrain = new Material(assetManager,

“Common/MatDefs/Terrain/Terrain.j3md”);

Texture grass = assetManager.loadTexture(

“Textures/Terrain/splat/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex1”, grass);

mat_terrain.setFloat(“Tex1Scale”, 64f);



AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager.loadTexture(heightMapFile);



heightMapImage.getImage().setFormat(Format.RGB8);



heightmap = new ImageBasedHeightMap(heightMapImage.getImage());// <— NOTE CHANGE HERE (Image instead of BufferedImage!)

heightmap.setHeightScale(128); // <— NOTE CHANGE HERE!

heightmap.load();



TerrainQuad terrain;

terrain = new TerrainQuad(“terrain”, 257, 257, heightmap.getHeightMap());

terrain.setMaterial(mat_terrain);

rootNode.attachChild(terrain);



}[/java]

darn I thought that tutorial was up to date. I will change it now, sorry about that.