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!

 

Mar 03

A Video!

Made a quick video to show that this is progressing, almost at clean and optimize stage!

Once the class is stable I’ll be moving on to a World Editor for it. Should be fun 🙂

Thanks!