Edges in imagebasedheightmap, terrain

Hi!



I have a small problem with greyscale heightmaps.



If i try to load a imagebased heightmap, it works well. However, it looks like [see attachment].

Its not really smooth, it hasnt got soft edges! It looks to much like a staircase.

Is there any method to make the terrain more smooth and not edged?



I added one greyscale image im using, the other ones are similiar.



Heres the code:


package geomap;

import com.jme.app.AbstractGame.ConfigShowMode;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.AbstractHeightMap;
import com.jmex.terrain.util.ImageBasedHeightMap;
import java.net.URL;
import java.text.DecimalFormat;
import javax.swing.ImageIcon;

/**
 *
 * @author //
 */
public class LoadGeoMap extends SimpleGame {

    private final String filePath = "data/heightmap/germany/";

    @Override
    protected void simpleInitGame() {
        // Set the title of the frame.
        display.setTitle(getClass().getSimpleName());
        display.getRenderer().setBackgroundColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 1));

        for (int north = 45; north <= 46; north++) {
            for (int east = 5; east <= 10; east++) {
                addHeightMap(north, east);
            }
        }
        rootNode.setLocalTranslation(0, 0, 0);

        // Add a simple box
        Box b = new Box("NewBox", new Vector3f(0, 0, 0), new Vector3f(5, 5, 5));
        b.setRandomColors();
        // Remove lighting for rootNode so that it will use our basic colors.
        b.setLightCombineMode(Spatial.LightCombineMode.Off);
        rootNode.attachChild(b); // Put it in the scene graph





    }

    private void addHeightMap(Integer north, Integer east) {
        // Formatting strings.
        DecimalFormat dfNorth = new DecimalFormat("00");
        DecimalFormat dfEast = new DecimalFormat("00");
        String fileName = "de" + "N" + dfNorth.format(north) + "E" + dfEast.format(east) + ".png";
        String heightMapPath = filePath + fileName; // supply path to grayscale bitmap

        /* com.jmex.terrain.util.ImageBasedHeightMap -- good for custom landscapes */
        URL heightMapImg = LoadGeoMap.class.getResource(heightMapPath);
        // Check if url is valid.
        if (heightMapImg == null) {
            return;
        }
        System.out.println("Loading heightmap: " + heightMapPath);
        // Url is valid, create page and add it to the root.
        int heightMapSize = 513;
//        AbstractHeightMap map = new RawHeightMap(heightMapImg, heightMapSize, RawHeightMap.FORMAT_16BITBE, true);
        AbstractHeightMap map = new ImageBasedHeightMap(new ImageIcon(heightMapImg).getImage());
        Vector3f terrainScale = new Vector3f(1, 1f, 1);
        TerrainPage page = new TerrainPage(fileName, 33, map.getSize(), terrainScale, map.getHeightMap());
        page.setLocalTranslation((east - 5) * (heightMapSize - 1), 0, (north - 45) * -(heightMapSize - 1));
        rootNode.attachChild(page);
    }

    public static void main(String[] args) {
        LoadGeoMap app = new LoadGeoMap();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    } // end of main(String[] args)
}



Thanks for answers/links!

Try scaling it differently :wink:



Vector3f terrainScale = new Vector3f(1f, 0.1f, 1f);


  • Mikkel

Hey,

tried that, looks better now! See att.



However, now ive got some small holes between each terrainpage - is that a common effect?



And are there more ways to make the terrain smoother?



Thank you!