Destroying nodes (solved)... Procedural terrains

Hi,



I’m new to this forum and just started to play with jmonkeyengine for a week or two now. I really like it, and it makes much easier to create things I have in my mind.



Right now I’m about to write some codes to create endless terrains based on pluggable noise and fractal functions. Everything seems to work fine, but I have some bugs, and do not know how to solve them.


  1. I’m creating a 3x3 grid of neighbouring terrain tiles, where the user is always on the center. I’ve read on the forums that there are similar solutions already done, so this proves that the concept itself is viable. When I’m moving around I’m shifting the grid when neccessary, and to save memory I’m trying to disconnect tiles far behind the user. I can see on the console, that the nodes were detached, but I can soon get a “java.lang.OutOfMemoryError: Direct buffer memory” exception. I know that I can always raise this value, but I cannot raise it infinitely as the camera is moving along. As I’m adding physics to the scene, I found out one bug being I didn’t detach the node in question from the bulletAppState, and after fixing that I can get farther, but the error still persists. The code is:



    [java]

    private void removeTile(final String name) {

    ProceduralTerrain node = (ProceduralTerrain) this.getChild(name);

    if (node != null) {

    this.bulletAppState.getPhysicsSpace().remove(node.physicsControl);

    this.detachChild(node);

    node.detachAllChildren();

    }

    }

    [/java]



    Where ProceduralTerrain is just a descendant of TerrainQuad that is filled from a fractal function, and maintains a reference to its physicsControl data. Is there anything I’m doing wrong?


  2. The slowest part of switching to the next center location is when I’m adding the new terrain tiles. Calculating the heightmap is fast enough, but creating the TerrainQuads and adding them to the bulletAppState is stopping the application for a while. Can I create them in a separate thread, or is there any other way to speed it up?



    Thanks in advance



    Anthyon

ok… problem one solved… I’ve miscalculated the corner tile coordinates when trying to remove them, so I got some of them remaining, and eating up memory.



now the main problem is, is there a way to create TerrainQuads in another thread, so the game doesn’t stop for seconds?



Thanks,



Anthyon

1 Like

As far as I know, there’s no built in way to do that. But you can load them on another thread if you are careful and do not add them to the scene graph on that thread. You can create all kinds of geometry on another thread but you have to add it to the scene graph on the lwgl thread… the same one update is called on.

1 Like

I have found some hints on how to do this, but the results were still questionable… Tried out to create my own mesh out of the generated heightmap data, and though it was much faster, I’m facing another problem: to add physics to a mesh i seem to have to have it created as Mode.Triangles, as the converter wants to fill TriangleCount * 3 indexes. And of course TriangleStrips have much less (TriangleCount + 2). Do I have to create a list version out of the strips, or can I feed the collisionmesh with stripdata as well? (I could not find any docs yet on thisd particular question)

done… I have just created my own custom shape from generated data, and it’s working perfectly. An infinite procedural terrain with pluggable noise basis functions. :slight_smile:



In the next step I will try to map textures based on height + temperature + humidity maps instead of alphamap… Hope it will work out :slight_smile:



If anyone is interested, I’m willing to share the code after some cleanup…



Anyway, thanks for this great engine :slight_smile:

please share your code so we all can learn from. specially your “procedural terrain with pluggable noise basis functions” sounds interesting to me :slight_smile:

anthyon said:
done... I have just created my own custom shape from generated data, and it's working perfectly. An infinite procedural terrain with pluggable noise basis functions. :)

In the next step I will try to map textures based on height + temperature + humidity maps instead of alphamap... Hope it will work out :)

If anyone is interested, I'm willing to share the code after some cleanup...

Anyway, thanks for this great engine :)

Sounds good, think theres any chance to build that into TerraMonkey?

I’ll clean up the code, write some comments, then share the code…



I think it can be integrated with TerraMonkey, but as I’m still just learning to use the engine, I’ll need some help doing so. :slight_smile:

Awesome, start a topic in the TerraMonkey group, although @Sploreg is on vacation right now, he’ll get a mail about it.

Done… I have uploaded the code as well, so I’m awating all the critics and improvement options you find :slight_smile:

1 Like

Great, thanks :slight_smile: