TerrainQuad setHeight performance

In our city building games we manipulate large parts of the height-map. For example you can build a predefined hill or river. The shape data of this river is stored in 1000’s of height-map points. (using less points is unfortunately not an option for our “serious” games)



We used to call TerrainPage/Quad.setHeight() several times to manipulate the height-map and thus create the river. However in JME3 each call to setHeight forces the setHeight in TerrainPatch to update its VertexBuffer for the LOD geomap. This is of-course a good thing, but makes the method to slow for realtime gaming when called several times.



Is it possible to delay this update until after setting the height of several height-map points at once? For example adding a setHeight method that uses a parameter with a list of coordinates and heights instead of just one point?

That might be an option, I will look into it today.

Yes I agree, there could a method for example for updating points in a radius or a box with a given “function(x,y)”

Here are some preliminary speed results of the changes I am making. You will now be able to pass in a list of coordinates and corresponding height values and they will be updated in bulk. I will commit the changes this evening.



Old setHeight():

Modified 3207 points, took: 206 ms

Modified 3207 points, took: 191 ms

Modified 3207 points, took: 179 ms

Modified 3207 points, took: 142 ms

Modified 3207 points, took: 136 ms

Modified 3207 points, took: 135 ms

Modified 3207 points, took: 136 ms

Modified 3207 points, took: 138 ms

Modified 3207 points, took: 147 ms

Modified 3207 points, took: 138 ms

Modified 3207 points, took: 138 ms

Modified 3207 points, took: 136 ms

Modified 3207 points, took: 137 ms



New setHeight():

Modified 3207 points, took: 18 ms

Modified 3207 points, took: 14 ms

Modified 3207 points, took: 10 ms

Modified 3207 points, took: 4 ms

Modified 3207 points, took: 3 ms

Modified 3206 points, took: 2 ms

Modified 3206 points, took: 3 ms

Modified 3207 points, took: 1 ms

Modified 3206 points, took: 1 ms

Modified 3207 points, took: 1 ms

Modified 3207 points, took: 1 ms

Modified 3207 points, took: 0 ms

Modified 3207 points, took: 1 ms

Modified 3207 points, took: 1 ms

1 Like

Thanks @Sploreg, your preliminary result look very promising and the solution for our game! The list parameter is also the best option for us. Tomorrow is a busy day at a conference, but I will certainly give it a try this weekend.

Cheers,

Maxim

Ok it is committed.

Check out TerrainTestModifyHeight to see what it does as an example.

I have changed our code to work with the new method parameters and the results are perfect. Thxs @Sploreg !

No problem :slight_smile: