Reusing FloatBuffers for multiple objects

I'm currently in Progress of creating my own terrain implementation. Partly for research, partly because I need some specific behaviour that's not found in the terrain blocks.



When working on it I went tru several stages…



(1) Naive attempt. Just create a single large TriMesh.

(2) Create multiple Terrain Patches (aka. Pages) that snug together and can be culled individually using separate Vertices

(3) Create one huge Terraino object with all the FloatBuffers and create separate TerrainPatches that just index vertices of the FloatBuffers



My personal rating follows…



(1) Dead simple to implement. Doesn't scale at all. Dead end.

(2) Kinda difficult to get the code which manages the heightmap and normals right as you always need to take extra care of the vertices at the edges of two neighbor patches. This was in fact the reason for me to look at other alternatives as it just feels ugly to write code which consists of more special cases than actual logic.

(3) Almost as dead simple to implement as (1), allows culling like (2), implementation is a straight forward - you can just modify the vertices in the upper terrain object and all patches will be rendered correctly automagically.



3 sounds very promising so far, but I found a serious glitch which gives me some headaches. When checking the scene with the DebuggingGameState I see a lot of unused vertices. Every single terrain patch comes with all vertices instead of sharing one larger VBO across all patches. After some keyboard chewing I realized that I hadn't told jME that I want to share the vertices, normals and texture coords across all terrain patches. So far so good… how to tell jME to do so…



I'm not too familar with the jME codebase yet, but after looking at the sources of TriMesh and Geometry it seams that I have to change the way the batches are created/used. Maybe some engine coder can point me to the right direction where to look. Maybe the entire idea is just nonsense and I should stick to good 'ol (2) which works without any VBO hacks. The few extra vertices don't hurt and the engine rewards you with automagic bounding box calculation, culling, etc.



To summarize the thing I'm trying to reach:

  • One VBO each for Vertices, Normals and TextureCoords
  • One index buffer for every patch



    And for the OSS lovers - yes, it'll be released under BSD license as soon as I'm happy with the code myself. I just don't like sharing code which is horribly broken. :wink:

look at llama continous terrain - google earth style - walk a world

…and implements the stuff described above.



edit: http://www.jmonkeyengine.com/jmeforum/index.php?topic=5170.0

would be interesting to see the benchmarks of this when its ready