Interactive terrain smoothing?

I’m trying to create a SimpleApplication that renders a TerrainQuad (using, say, FaultHeightMap and HeightBasedTerrain.j3md), then allows the user to iteratively “smooth” the entire heightmap by pressing a key. So I added an ActionListener that traps the keypress and smooths the heightMap (which I kept after generating my terrain, since there’s no way to create a new one given an array of floats). I also kept my TerrainQuad after I generated it, but I have no idea how to take this updated heightMap containing the new height values, and stick it into my existing TerrainQuad, and have it update the rendered scene. Can anyone help?

I took a look at TerrainTestModifyHeight, but it just updates specific values in the TerrainQuad (for which there is a specific method, adjustHeight, to do that). There is no corresponding method to update the entire heightMap.

EDIT: I may have put this in the wrong forum. Sorry about that.

How about you just call setHeight for each float in the buffer? Theres for loops for that.

You can also make a big array of height changes and pass that into the terrain using setHeight()

Yeah, but setHeight expects a matching list of coordinates and values as separate Lists of Vector2f and Float that describe a set of changed values. I just wondered if there was a more efficient way to change the entire heightmap at once, without boxing up my float[] array (Since it’s just going to be unboxed at the other end anyway :wink:

Thanks! I guess I’ll use setHeight()

EDIT: Nevermind, I think I understand why it is the way it is (this mechanism allows us to not assume that all the modified heights fall on existing xz coordinates, since setHeight takes float coordinates). It’s awesome!

Hmm… Okay, this is sort of working now (thanks guys!), but it looks like the generated TerrainQuad doesn’t use the same coordinate system, so setHeight is not expecting a list of Vector2f relative to the heightMap, but relative to the rendering origin coordinates for the terrain Spatial? Also, while I’m smoothing the entire heightMap, only one quarter of the terrain is actually being smoothed on render, so there’s definitely a mismatch between the heightMap xz values and the TerrainQuad’s setHeight Vector2f parameter…

Any ideas?

So, looking through the debug console, I see things like:

INFO: Child (terrainQuad1) attached to this node (terrain) INFO: Child (terrainQuad2) attached to this node (terrain) INFO: Child (terrainQuad3) attached to this node (terrain) INFO: Child (terrainQuad4) attached to this node (terrain)

Which I guess explains why it’s called a “quad”. Now I’m just trying to match up the coordinates on the Quad with the x,z indices in the HeightMap…

The terrain is not actually a heightmap, it’s just a mesh. The heightmap is just used to initially create that mesh. So the height values have to be passed in with coordinates and then they are matched up to the vertices of the mesh.

TerrainQuad is a quad tree. It gets divided up into TerrainPatches (the real geometry). This is for frustum culling so you don’t have 1 million polygons trying to render all the time.