I’ve managed to put together the sources for the terrain engine I release a demo for in this thread:
http://www.jmonkeyengine.com/jmeforum/index.php?topic=2979
The source can be downloaded here:
jME Terra
The latest source is in SVN over at Google Code:
see the development thread:
http://www.jmonkeyengine.com/jmeforum/index.php?topic=5170.0
It’s under the GPL for now, when it becomes more stable it’ll become LGPL or BSD (like jME).
As of 0.0.5 the license is now LGPL.
I normally wouldn’t have released this without more polishing, but I don’t have always have enough time to work on it, so I thought it’d better release it. Because of this there are still some silly bugs, most noteably:
- do not attempt to change the scale of the terrain (except the build-in heightscale as used in the tests).
- do not attempt to add a TerraView anywhere other than at (0,0,0).
- lack of a solution for terrain following.
- lack of a decent logging structure.
- lack of documentation.
- occasional stuttering during loading.
General Package structure:
org.llama.jmex.terra : everything terrain related.
org.llama.jmex.task: another uncompleted project of mine this project uses, a framework for executing tasks in jME to do background loading and such.
org.llama.test: The tests.
For now I'll just discuss the tests, later I'll add a section to this thread about the general structure of the code, and one on how to import some real world height data (there are converters for 2 formats included in the source) to make really big maps with ease
First test is ViewJMEXTest. This is basically the demo as seen in the topic mentioned above. So see that topic for the command line properties you can use. Textures are now off by default and can be enabled with enable:textures, and there is also enable:sample2 sample4 sample6 and sample8 for multisampling the scene. For the rest some default values changed a bit from the 0.0.3 test, and height above the terrain is now counted for calculating LOD distances.
The second test is SaveJMEXTest. This has the same command line parameters as ViewJMEXTest, but is meant to create map files for loading your world from disk. It's a console app that will ask you to enter some info in the console.
First is the file name, files will be saved in the current directory (if you launch from Eclipse this is your workspace dir) but you can gave a relative or absolute path in from of the file name. eg. "mymap" or "res/hillmap/myhillmap" or "/bla/blamap"
Next the "Number of blocks to fit in a map". A world consists of several square maps (each map is 1 file) overlapped by several blocks (the pieces of the geometry). I'll explain this better later on, but a good value would be 2 or 3. (The block size is specified through the command line parameters as explained, by default it is 128, so 2 would make a separate file for each 256x256 block).
If everything goes well your map will now be compressed and written to disk.
With ViewMapFileTest you can open this or other maps you've saved. It takes roughly the same command line parameters as ViewJMEXTest with some differences:
[enable:novbo:textures:etc. (see demo readme or thread)]
filename (will prompt you on the console if not given)
block size (typically be the same as when you saved, will prompt if not given)
Number of blocks to fit in a map (block size * this value MUST be the size of a map file, so typically the same as when you saved. however you could eg. change blocksize from 128 to 64 and this value from 2 to 4, will prompt if not given)
memorymapping 0 (default) to disable, 1 to enable. (Memory mapping does not load a file, but instead maps it to memory, potentially reducing disk usage)
fogstart
fogend (both like in the demo, for where fog begins and ends. Fogend is also the drawing distance)
render distance (distance at which geometry is created)
decompression distance (NOT in the demo! distance at which heightmap data is decompressed)
loading distance (distance at which compressed heigthmap data is loaded from disk/memorymapped)
lod levels (like in the demo, several values at which the next LOD level will begin)
So I hope this will give those who want to the chance to play around with this work a bit. If anyone wants to port code over from TerrainPage to TerraManager so people can do terrain following it'd be most welcome. Other things too of course. The code will still change a lot in my local copy, but if anyone contributes something I'll do my best to work it into my code. On my own TODO right now:
- fix the "bugs" listed above (espc. the stuttering)
- introduce gradual loading: right now maps and geometry are always loaded at full detail, Even if for the current LOD this is not really needed. By reordering way data is stored in the map files and geometry buffers (first low detail, then added higher detail) loading can be done in stages as you get closer.
- pluggable system for creating geometry.
- refactor some of the weirder parts of the source (like TerraView)
- optimize LOD.
and in the longer term:
- dynamic texture splat maps.
- normalmaps or lightmaps instead of normals.
- morphing.
And finally, in TerraData.java there is a method sferaNormals() that makes better normals than the default ones. In line 109 change buildNormals() to sferaNormals() to enable this. It looks better but has a problem with seams (the line between two block), that the default method does not have. As you can guess this method was contributed by Sfera :)