Terrain Grid Not Firing Attach Event

I had the terrain grid working at one point so it attached new terrain to the grid as the camera moved. My app extends SimpleApplication and I use Application.cam.

Within SimpleApplication.simpleInitApp() I setup my objects and this is the code used to setup the Terrain.

The attach fires initially to draw the screen. Camera moves around fine but, as I approach the edge of the terrain nothing fires to add the next tile.

I have reorganized the code from the example into more objects for the app I am building. I am thinking I have broken something with the order of events or am causing something to cause this side effects.

I have confirmed that with in SimpleApplication.simpleUpdate(…) the camera object is the same object that I added to the lod controller.

Where should I put break points in TerrainMonkey to see how the Log controller is failing me?


terrain = new TerrainGrid("terrain", patchSize, maxVisibleSize, new ImageTileLoader(assetManager, new Namer() {

public String getName(int x, int y) {

System.out.println("Getting image tile for " + x + "" + y + ".");

return "Scenes/Terrain/terrain
" + x + "" + y + ".png";



terrain.addListener(new TerrainGridListener() {

public void gridMoved(Vector3f newCenter) {


public void tileAttached(Vector3f cell, TerrainQuad quad) {

Texture alpha = null;

try {

alpha = assetManager.loadTexture("Scenes/Terrain/alpha
" + (int)cell.x+ "" + (int)cell.y + ".png");

} catch (Exception e) {

System.out.println("Using default alpha map for " + cell.x + "
" + cell.y + ".");

alpha = assetManager.loadTexture("Scenes/Terrain/alpha_default.png");


quad.getMaterial().setTexture("AlphaMap", alpha);


public void tileDetached(Vector3f cell, TerrainQuad quad) {

float[] heightMap = quad.getHeightMap();

Object obj = quad.getMaterial().getTextureParam("AlphaMap");




TerrainLodControl control = new TerrainGridLodControl(this.terrain, graphicTheater.getTheaterCamera().getCamera());

control.setLodCalculator(new DistanceLodCalculator(65, 2.7f)); // patch size, and a multiplier



terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2.5f, 0.5f, 2.5f);



Stable or nightly? And please use the java tags fo code.

Stable. Pulled down an update through the ide about a month ago. Not sure where to find the exact version and build.

I did put a break point in TerrainGridLodControl.updateLog(…). I found teh cam vector is [0,100,0] every time, which is my initial location. I modify the vector and it does draw the terrain, but then unexpected things occur.

so, it does appear that when I moved my code around I have broken my terrain setup. Not sure exactly to find out what in the terrain grid is holding on to this old location.

Also, this is the constructor I call for SimpleApplication.


super(new StatsAppState(), new DebugKeysAppState());


Make sure you aren’t sharing the camera references everywhere, and if you have cloned them, to see where those cloned copies are going. The TerrainGridLodControl expects the real reference to the camera in order to track when to load in new tiles.

I found the problem. When I move left and right the terrain grids are attached and detached with the camera movement. When I move forward and back the terrain does not work correctly.

After looking into it I was using the zoom code, which I think I copied from FlyByCamera. I changed it to use moveCamera(…) code.


1 Like