Height map not working?

So my terrain is flat and i cant figure out why.



[java]AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager.loadTexture(

"Textures/terrain/heightmap/base_height_map.png");

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

heightmap.load();



int patchSize = 65;

terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());



terrain.setMaterial(mat_terrain);

terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2f, 1f, 2f);

rootNode.attachChild(terrain);[/java]



I wanted to have it be 1024x1024 and had the 513 as a 1025 but it didnt work. So i made the file smaller to 512x512 and it didnt work either.



Could it be that my image is too dark? The lightest shade of grey i have is 50% (0% being black and 100% being white)

image lightest you have 50%, but trully 25% is the lightest, because you scale “(2f, 1f, 2f)”, where middle value is height(if im not wrong scale work for height too).



but even 25%, it should not be flat…



show the image. also other fragments of code can be wrong, who knows.

1 Like

http://imgur.com/5L6y8



That should be the image, unless i totally botched uploading it.



As far as i can tell, that bit of code is all that governs the height.



[java]@Override

public void simpleInitApp()

{

//sets up physics

bulletAppState = new BulletAppState();

stateManager.attach(bulletAppState);



//sets up player movement

flyCam.setMoveSpeed(100);

initKeys();



setUpLight(); //adds in the lights

initCrossHairs(); //sets up the crosshairs on the screen

initSky(); //adds in the skybox



mat_terrain = new Material(assetManager,

"Common/MatDefs/Terrain/Terrain.j3md");



mat_terrain.setTexture("Alpha", assetManager.loadTexture(

"Textures/terrain/terrain_textures/alphamap.png"));



Texture grass = assetManager.loadTexture(

"Textures/terrain/terrain_textures/grass.jpg");

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex1", grass);

mat_terrain.setFloat("Tex1Scale", 64f);



Texture dirt = assetManager.loadTexture(

"Textures/terrain/terrain_textures/dirt.jpg");

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex2", dirt);

mat_terrain.setFloat("Tex2Scale", 64f);



Texture rock = assetManager.loadTexture(

"Textures/terrain/terrain_textures/rock.jpg");

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture("Tex3", rock);

mat_terrain.setFloat("Tex3Scale", 64f);



AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager.loadTexture(

"Textures/terrain/heightmap/base_height_map.png");

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

heightmap.load();



int patchSize = 65;

terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());



terrain.setMaterial(mat_terrain);

terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2f, 1f, 2f);

rootNode.attachChild(terrain);



//LOD set up

List<Camera> cameras = new ArrayList<Camera>();

cameras.add(getCamera());

TerrainLodControl control = new TerrainLodControl(terrain, cameras);

terrain.addControl(control);



com.jme3.bullet.collision.shapes.CollisionShape terrainShape =

CollisionShapeFactory.createMeshShape((Node) terrain);

landscape = new RigidBodyControl(terrainShape, 0);

terrain.addControl(landscape);



CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);

player = new CharacterControl(capsuleShape, 0.05f);

player.setJumpSpeed(20);

player.setFallSpeed(30);

player.setGravity(30);

player.setPhysicsLocation(new Vector3f(-10, 10, 10));



bulletAppState.getPhysicsSpace().add(terrain);

bulletAppState.getPhysicsSpace().add(player);

}[/java]



Thats my entire simpleInitApp() method. The only other weird thing with this is that bit of code:



[java] com.jme3.bullet.collision.shapes.CollisionShape terrainShape =

CollisionShapeFactory.createMeshShape((Node) terrain);

landscape = new RigidBodyControl(terrainShape, 0);

terrain.addControl(landscape);[/java]



It kept giving me errors about incompatible types because Terrain is a TerrainQuad and right there its coverting it?



I bet thats whats messing it up.



I just changed it to



[java]CollisionShape terrainShape =

CollisionShapeFactory.createMeshShape((Node) terrain);

landscape = new RigidBodyControl(terrainShape, 0);

terrain.addControl(landscape);[/java]



But no dice yet… hmmmm…

i have no so many time to play with it, but this is what you can do:


  • create JME Test project(this one with JME tests): SDK → New Project → JME3 → JME3 Tests.
  • copy JME TerrainTest.java in jme3test.terrain package into your project.
  • run it with your image(just change images dir in TerrainTest.java).



    if it will work - then you miss something in code, if not, then image is wrong.
1 Like

Listen to oxplay, it is probably the height scale is way to low for your dark image, crank it up to 128f and see what happens.