Aug 02

Tiled Terrain Editor update

Greetings,

Apologies for taking so long at this, available time has not been good and I’ve been doing a lot of experimenting and learning as I go. So far I have Image tile generation running and the menu system for the rest of it going.

I’ve uploaded the current code state to a new svn repository here:

https://code.google.com/p/radanz-game-code/source/browse/#svn/TiledTerrainEditor

You’ll need the library pngj added to the jMonkeyEngine SDK to compile it or download the compiled dist.zip file here

So far the menu works but the only real function working is: “Generate New Terrain” > “From HeightMap Image” > load any 16-bit Gray-scale PNG image > “Generate” > “Create Image Tiles”.

Only 16-bit Gray-scale png images are supported at the moment, any size, I have two test maps, one small at 1024*1024 and one very large at 8192*8192. The image is loaded one strip of tiles at a time so very large maps can be processed with exceeding memory requirements.

You can choose how many tiles to generate in both directions and the base image map will be scaled and interpolated as required, both bigger and smaller. Number of tiles is 8 minimum to 4096 maximum in each direction. Tile size selectable from 256 to 2048. PNG images will then be created and saved into the selected location under a new directory of the entered name (optional) with the file name: tilexxxxyyyy.png

Not much use for my terraintiler library at this stage but those who use jMe’s TerrainGrid will be able to use the generated tiles right away. Code to load the tiles like this:

        assetManager.registerLocator("path/to/tiles", FileLocator.class);
        this.terrain = new TerrainGrid("terrain", 65, 513, 
                           new ImageTileLoader(assetManager, new Namer() {

            public String getName(int x, int y) {
                String fileName = String.format("tile%04d%04d.png", x, y);
                return fileName;
            }
        }));

Next I’ll be working on the ‘j3o’ tile generation for my terraintiler library using textures that can be loaded on the generation screen. More on that later.

Any comments of the code so far would be very appreciated.

Cheers.

Jul 14

MapGenerator Menu

Quick update,

Have managed to load a large height-map image and generate a “mini-map” of it and setup the map generation menu:

MapGenerator

 

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)

Cheers

Jul 11

TiledTerrain Editor

Hi all.

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:

java 2013-07-11 20-57-06-23

 

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):
java 2013-07-11 20-57-22-60Until next update!

Cheers.

Mar 16

Further Testing of the TerrainTiler

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.

Thanks.

Mar 13

TerrainTiler class finalised

Hi again,

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… πŸ˜‰

Enjoy!

 

Feb 12

TerrainTiler library progress!

Hello again.

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.

Thanks for reading!

TerrainTiler-1 TerrainTiler-2

Nov 15

TerrainTiler

That was quick πŸ˜€

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.)

Until next time!

Splat Painting

Different Textures per Tile

LoD on terrain

 

 

Nov 12

Update

Hi again,

Quick update, not much has changed visually but I’ve had to rework the terrain code, well I’ve gone back to an older version I was working on and fixed it. Why? because the terraingrid function of jMonkeyEngine wasn’t working out, sure it was fast and easy but it was also very memory hungry, like I managed to clock up over 7GB of memory just wandering around the terrain. Sorry, no, not going to work.

So back on to my own TerrainTiler code, I’ve managed to bring its speed back up to at least equal to that of terraingrid. Which is impressive as terraingrid was only 2×2 visible tiles active (and 12+ cached <= the memory issue) where as my tiler routine is a 3×3 patch of visible tiles (no cache, new tiles saved to disk for later re-use). So my code gives me more visible ground and distance so less chance of a player seeing the landscape “popping” into existence as they wander around but still allows for a very large terrain.

edit: My routine is still using the jMonkeyengine TerrainQuads for each tile but they are treated individually and loaded in and out as the player moves, where as the built in TerrainGrid is 4 quads loaded as one and swapped in/out as the camera moves.

I’m very happy I managed to get that code working, now just trying to fix the terra-forming code to suit the new routine. Being a pita but I’ll work it out. Once I get those sorted and can tidy up and modify my terrain I’ll be able to post some more pics.

Until next time! Thanks for reading!