Have managed to load a large height-map image and generate a “mini-map” of it and setup the map generation menu:
As the screenshot shows, the original file is 8192×8192 pixels, in 16-bit gray-scale.
Also populated drop-down boxes to select the “world” size in tiles across and the size of each tile, also there is a list to set the maximum height of the generated world. All in “world units”
Next is to link the drop down boxes to change the “pixels to unit” scale value and also to lock the sliders on the left to keep each one less than the one below it (they are there to set the height percentage for painting the one to four textures based on the terrains height during tile generation)
Some visible progress on the terrain editor program, after bitching with Nifty-Gui I think I’m getting the hang of it. just piecing the menus together and adding code functions to them, once they’re all done the real work can begin.
Here’s some screenshots so far:
File Loading screen for loading tilesets or images/textures:
The tile-set generator screen (left image pairs for initial height-based textures are diffuse&normal pairs, large right-hand image will show a scaled version of the users heightmap image): Until next update!
Another Video. Same camera path as previous posted video but this time a small addition to the code was added to test the Action Hooks for Tile Attached and Tile Detached.
terrainTiler = new TerrainTiler(cam, 32, uJars, 1, tileDir, this);
terrainTiler.setGridSize(5); // grid can be 3,5,7 or 9. Defaults to 3
terrainTiler.addActionHandler(new TerrainTilerAction() {
public synchronized void tileAttached(Vector3f center, TerrainQuad tile) {
System.out.println("Adding trees to tile: "+tile.getName());
float tx = tile.getLocalTranslation().x;
float tz = tile.getLocalTranslation().z;
int tsize = terrainTiler.getTileSize()*terrainTiler.getTileScale();
int num = new Random().nextInt(20)+20;
for (int i=0; i<num; i++) {
float x = tx - tsize/2 + new Random().nextFloat()*tsize;
float z = tz - tsize/2 + new Random().nextFloat()*tsize;
float h = terrainTiler.getHeight(new Vector2f(x,z));
if (h > 100f & h < 300f) {
String id = tile.getName()+i;
tree.setLocalTranslation(x, h, z);
tree.setName(id);
treeList.put(id, tree.clone());
rootNode.attachChild(treeList.get(id));
}
}
}
public synchronized void tileDetached(Vector3f center, TerrainQuad tile) {
System.out.println("Removing Trees from tile: "+tile.getName());
Iterator it = treeList.keySet().iterator();
while (it.hasNext()) {
String id = (String) it.next();
if (id.startsWith(tile.getName())) {
rootNode.detachChild(treeList.get(id));
treeList.remove(id);
}
}
}
});
terrainTiler.setEnabled(true);
rootNode.attachChild(terrainTiler);
Pretty quick and dirty but does the test, “tree” is a Spatial that is a pre-loaded model. The tree model is a very ugly tree imported from a Blender file I found from a quick “free model” search. “treeList” is a ConcurrentHashMap for storing the trees created so it can remove them later. The code throws a random number of trees into the list, provided its location is within a set altitude range. When the tile is detached it finds the trees with the tile ID and removes them.
Next is to test the terrain editing/modifying functions.
My TerrainTiler class is now finalized as far as functions go, I’m now ready to make it a plugin for jME’s SDK for consideration in to the community collection.
Here’s another video showing a nice 4 min fly-over using the latest code. Still a bit plain – needs better textures and objects like trees etc would make it a nice demo.. sooon… 😉
Had a major headache in the tiler routine that was causing a big memory leak, still needs to be properly sorted but it’s not leaking at the moment. Still not sure if it was my code or the engine library I’m using. Sort it eventually.
Terrain generation has started coming together, still needs more work but here’s an early screenshot for progress. Needs seam welding between the tiles and better smoothing routines but its a start. Gives me something to work on.
The TerrainTiler class library is now progressing very well. Not loading actual tiles yet just random color HillHeightMaps but it’s working and quite flexible: so far I’ve tested a 3×3 grid and a 5×5 grid (shown below) Â code also allows 7×7 and 9×9, i’ll test these later, getting late here.
Tomorrow I’ll tackle loading actual terrains with textures and finish off a few functions.
Code is up on GoogleCode so others can look at or test it, currently it’s a project for jMonkeyEngine SDK so you can load the whole project into the SDK and just run it.
Getting progress on the TerrainTiler routine, still need to break it out into its own class and give it threading but it is working and frame rates are still good.
Terraforming tools are also coming together nicely, currently I can smooth the whole visible terrain, paint it with different textures, scale the textures and swap them out for others.
My planning is to have 4 textures per tile but each tile can have 4 of however many textures I decide to have available, this way each tile stays simple but I can have a vast array of different textures to suit the varying type of areas across the map. Also this allows me to put a lot of detail in such as normals/glow/specular maps as I need without breaking the limits of the older graphics cards.
And here are some pics to look at as words are boring 🙂
(The small oval is my “Player” (no pretty models yet, mechanics first). I use the player to test the physics of the terrain for issues as I go. The dome is the tool, adjustable in size.)