How Define an Area to set terrain with TerraMonkey

Hello all,



I try to do my own terrain Editor with JMonkey and i’ve finish to create the method to set the height of terrain with the mouse. But i’ve a problem take a look at this picture:





As you can see the terrain is modified but i’ve want to modify my terrain with a circle like this(Just one point is modified):



Do you have any solution or indication to do this ? (i use the procedure (terrain.setHeight(); → TerrainQuad))



(My aim is to create something like this: )

Hello, to edit heightmap with circle you need:

  1. get point on terrain.
  2. set your radius to handle more terrain.
  3. create method or look somewhere how to loop throught all those points and change height.



    That’s my cent :slight_smile:



    P.S.: i’m very sorry for my english, i know my gramma is awfull.

Ok but how can i set my radius ?

Umm…if i remmember good it’s like this:



when you clicked on terrain you’ve got Vector3f, so if your radius is set to for example 5 it needs array of Vectors from main Vector3f like loop throught until if((Vector3f.getX() + 5) == Vector3f.getX()). i don’t know if you understood. i’ll try to search for this function in my old map editor.

you choose it. Imagine you have a pt x,y on plane.





for (i=x-radius; i<x+radius; i++) {

for (j=y-radius; j<y+radius; j++) {

if (FastMarh.sqr(x-i)+FastMath.sqr(y-j) <= FastMath.sqr(radius)) {

//do elevate the terrain in (i,j)

}

}

}

Ok good ! This method work ;).



But the performance is affected. My computer shows 4 fps for a radius of 7. This is your normal method uses an algorithm as those used in image processing with a table operations. A method as that of the brush in paint application is more appropriate. But how can I do this ?



Gemad I do not understand what you want to say. If you could find this function it would help me a lot :slight_smile:

Unfortunately, optimizing the performance requires directly editing the underlying FloatBuffers on a patch-by-patch basis. You want to traverse the TerrainQuads down until you find the TerrainPatch(es) that need editing, edit their heightmaps, then update the mesh position buffer with the data from the heightmaps once after you’ve set every value in the heightmap that needed to be changed (currently this happens with every setHeight call). This could be done without changing the current API, but it would be a big hack.



Instead, (@Sploreg) the setHeight and adjustHeight functions in TerrainPatch should probably be changed so that the position and normal buffers are not regenerated from the geomap until the update() function is called. This way, you can make call setHeight multiple times in between two frames, without recreating a 65x65x3 = 12k buffer ~40 times for that radius 7 circle.

dpwhittaker said:
Instead, (@Sploreg) the setHeight and adjustHeight functions in TerrainPatch should probably be changed so that the position and normal buffers are not regenerated from the geomap until the update() function is called.


Totally agree

If I understand the terrain updates his geometry every time I displace a point while he should be update when I finished changing all the points coordinates.

Do you know the date where this function will be change ? Or something to edit the heightmap Directly ?

no idea of the date, the idea just arisen. Changing the whole heightmap might force you to rebuild the whole terrain, which is probably not desired.

There is a radius terrain editing tool in JMP. It is still in development but works decently. As dpwhittaker pointed out, there are some performance improvements that are needed in regards to re-calculating the normal values, so they aren’t done after every point change. I haven’t updated that yet as it would require changing the Terrain api slightly, and I want to find the least awkward of changing it.

Give the editor in jmp a try, or even look at the code in the TerrainEditor extension to see how it is done.



If you have any editing tools you would like to contribute, we would love to include them! And I would be willing to help you out along the way to getting them working. We need a flatten terrain tool, a roughen terrain tool, and any other tool that might be useful for modifying terrain height.

I realized that the method was much more complex than what I thought. I will look before asking questions above.