Way too many terrain vertices - How can I reduce them?


I am using jMonkey’s ImageBasedHeightMap class to load a Heightmap, and I am then creating a new TerrainQuad from this heightmap:

Texture heightMapImage = manager.loadTexture(file);
    heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
    int patchSize = 256;
terrain = new TerrainQuad("Map", patchSize, 513, heightmap.getHeightMap());

The problem is that the terrain has far too many vertices. As I am loading 12 * 12 (144) chunks in total, this is amounting to be quite a lot of vertices.

Take a look at this picture:

The vertex count there is far, far, too high. That same terrain could easily be approximated without much visual loss with less than a quarter of the vertices shown in that picture.

I understand that the terrain is split up into x vertices no matter if it is flat, hilly, or whatever. This is not what I’m asking for - I’m asking how I can just flat-out reduce the vertex count in the terrain for everything.

(Even my powerful PC can’t cope with 10 million vertices)

I am aware that I could export smaller heightmaps, load smaller terrain quads, and then scale them up. Unfortunately, this is not possible due to quirks of the world generator that I use, and JME does not let heightmaps be larger than the TerrainQuads, and the setSize() method on the ImageBasedHeightMap class seems to be useless for this purpose.

Yes, I do have LOD on the terrain, but it doesn’t seem to help much.


(Note: I managed to duplicate the same terrain in Java & LWJGL with just 512 vertices per chunk, and it still looked fine. No LOD algorithms either)

In your case, what might work out better is custom genrated and decimated meshes as tiles. Maybe in a low and a high variant, and just load them when near enough. Smaller gaps at the boraders are easily hidden, by lowering the last vertice a bit.

Luckily, it is possible for me to use the terrain generator I use (L3DT) to export meshes.

How can I create a TerrainQuad from an OBJ model (or similar file format)?

Ah L3DT, in that case export obj and convert to j3o to improve performance at runtime.

I had written down from a few years ago:
Coordinate System : XZ plane, Y UP
Face winding CW(DirectX)
Origin at center: false
At least that worked for me back a few years I’m not sure how valid this still is.

You should be using PerspectiveLodCalculator to compute LOD levels for terrain. It is the most efficient algorithm available. You can specify a quality level too, letting you change the quality / performance tradeoff.

Yay, I now have a terrain loaded from OBJ meshes and only about 800 vertices each.


Only problem is, I can’t work out how to make the PerspectiveLodCalculator work on the Spatial that is my terrain. Could someone help me with that?

PerspectiveLodCalculator is designed to work with the jME terrain system, like the code you posted in your first post. You can’t use it on regular meshes.