/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package jme3test.helloworld;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.renderer.Camera;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
import com.jme3.terrain.heightmap.HillHeightMap; // for exercise 2
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import java.util.ArrayList;
import java.util.List;
/**
*
-
@author Steve
*/
public class HelloTerrain extends SimpleApplication{
private TerrainQuad terrain;
Material mat_terrain;
public static void main(String[] args){
HelloTerrain app=new HelloTerrain();
app.start();
}
@Override
public void simpleInitApp(){
flyCam.setMoveSpeed(50);
mat_terrain=new Material(assetManager,
“Common/MatDefs/Terrain/Terrain.j3md”);
mat_terrain.setTexture(“Alpha”, assetManager.loadTexture(
“Textures/Terrain/splat/alphamap.png”));
Texture grass =assetManager.loadTexture(
“Textures/Terrain/splat/grass.jpg”);
grass.setWrap(WrapMode.Repeat);
mat_terrain.setTexture(“Tex1”, grass);
mat_terrain.setFloat(“Tex1Scale”, 64f);
Texture dirt=assetManager.loadTexture(
“Textures/Terrain/splat/dirt.jpg”);
dirt.setWrap(WrapMode.Repeat);
mat_terrain.setTexture(“Tex2”, dirt);
mat_terrain.setFloat(“Tex2Scale”, 32f);
Texture rock=assetManager.loadTexture(
“Textures/Terrain/splat/road.jpg”);
rock.setWrap(WrapMode.Repeat);
mat_terrain.setTexture(“Tex3”, rock);
mat_terrain.setFloat(“Tex3Scale”, 128f);
AbstractHeightMap heightmap=null;
Texture heightMapImage=assetManager.loadTexture(
“Textures/Terrain/splat/mountains512.png”);
//error right here
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);
TerrainLodControl control =new TerrainLodControl(terrain,getCamera());
terrain.addControl(control);
}
}
Above is the code for HelloTerrain that I have written
I have a problem when when trying to create an ImageBasedHeightMap. My problem is that the constructor is looking for a java.awt.Image but the tutorial for HelloTerrain has code that returns a com.jme3.texture.Image. Is there an error in my code? Do I need to create a java.awt.Image?
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_terrain
This is the tutorial I followed