Hi!
I've tried using ImageBasedHeightMap to generate height map for my terrain.
I've used the same image several times, and every time the result of my effort has been absolutely different …
Is something wrong with ImageBasedHeightMap class, is it natural that it doesn't consider the given image much, or do I simply have a mistake somewhere else in the code ???
kamykadze said:
or do I simply have a mistake somewhere else in the code ????
Most likely. Can you just make a very simple test with TerrainBlock, no textures, in a SimpleGame subclass and check if the problem occurs with that? If so, you can post your test code, so we can see what's wrong with it. If everything's fine in the test, you can compare it to your original code yourself :)
ImageBasedHeightMap heightMap=null;
try {
heightMap = new ImageBasedHeightMap(ImageIO.read(SimpleGameNauka.class.getClassLoader()
.getResourceAsStream("probagry/img/mapa_wys_lol.jpg")));
} catch (IOException ex) {
ex.printStackTrace();
}
Vector3f terrainScale = new Vector3f(5f, 1f, 5f);
TerrainBlock tb = new TerrainBlock("Teren", heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(-640, 0, -640), false);
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
Well, this is the piece of code responsible for generating my terrain. Can't figure out what can be wrong with it.
PS.
My image is 256x256 pixels...
That code is fine, and it should work perfectly when copied it into a plain SimpleGame subclass. Just try it, to be sure! If you still get varying results with that, there's something broken with your local jME version, latest cvs works fine for me.
But I think it is more likely that your problem is in a different place in your code - maybe you never add this TerrainBlock to your scene, but instead a random generated one the code for which you thought you had long deleted? Or the random generated one is just higher than the image based one, so that you never see the latter?
You haven't described yet what "absolutely different" specifically means in this case - does it look like some random noise, or more like one of the heightmap generators that come with jME? Could it be that someting shifts pixels from your image? Is the heightmap scaled or rotated or otherwise transformed?
The "jpg" file format is a "lossy" image format. Which means it will be different each time you save it, depending how the compression algorithm choose to compress it. Use a lossless file format like PNG, or even better, use the RAW file format for terrain heightmaps.
does it change every time you load it (pretty much impossible)
or does it change every time you save it (why would you do that?)
Yep, I've just found a mistake somewhere else in the code. :mrgreen:
Everything is okey now, thanks a lot for your support