Hallo everybody,
As explained in an earlier post I am creating a terrain based on real GPS data. One idea I had is that if I have an image of the terrain and that JME generate the terrain (heightmap) based on the image.
Is this possible ?
Or can I only place an image as a texture onto a generated terrainpage ?
cheers,
Clemens
There is a class called ImageBasedHeightMap, try that one
yeah normen is correct check Hello Terrain in jME 2 for a test class which uses the grayscale from an image to create terrain structures white is highest point black is lowest
private void complexTerrain() {
// This grayscale image will be our terrain
URL grayScale=HelloTerrain.class.getClassLoader().getResource("jmetest/data/texture/bubble.jpg");
// These will be the textures of our terrain.
URL waterImage=HelloTerrain.class.getClassLoader().getResource("jmetest/data/texture/water.png");
URL dirtImage=HelloTerrain.class.getClassLoader().getResource("jmetest/data/texture/dirt.jpg");
URL highest=HelloTerrain.class.getClassLoader().getResource("jmetest/data/texture/highest.jpg");
// Create an image height map based on the gray scale of our image.
ImageBasedHeightMap ib=new ImageBasedHeightMap(
new ImageIcon(grayScale).getImage()
);
// Create a terrain block from the image's grey scale
TerrainBlock tb=new TerrainBlock("image icon",ib.getSize(),
new Vector3f(.5f,.05f,.5f),ib.getHeightMap(),
new Vector3f(0,0,0));
// Create an object to generate textured terrain from the image based height map.
ProceduralTextureGenerator pg=new ProceduralTextureGenerator(ib);
// Look like water from height 0-60 with the strongest "water look" at 30
pg.addTexture(new ImageIcon(waterImage),0,30,60);
// Look like dirt from height 40-120 with the strongest "dirt look" at 80
pg.addTexture(new ImageIcon(dirtImage),40,80,120);
// Look like highest (pure white) from height 110-256 with the strongest "white look" at 130
pg.addTexture(new ImageIcon(highest),110,130,256);
// Tell pg to create a texture from the ImageIcon's it has recieved.
pg.createTexture(256);
TextureState ts=display.getRenderer().createTextureState();
// Load the texture and assign it.
ts.setTexture(
TextureManager.loadTexture(
pg.getImageIcon().getImage(),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear,
true
)
);
tb.setRenderState(ts);
// Give the terrain a bounding box
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
// Move the terrain in front of the camera
tb.setLocalTranslation(new Vector3f(0,0,-50));
// Attach the terrain to our rootNode.
rootNode.attachChild(tb);
}
Thank you allot I will try that out if it is working with a photo as well.
cheers,
Clemens