Using a programatic tile


I am trying to build tiles programatically which includes attributes like color, transparency, and unique text. The tiles are layed out in a grid so I was thinking I could implement the TerrainGridTileLoader. When the getTerrainQuadAt method is called, I instantiate a TerrainQuad and attach a node to it that has the geometry. I think this is incorrect since its not displaying.

Is it possible to change the geometry for TerrainQuad since I don’t want to load images or assets from a file? Do I need to extend TerrainQuad? Any hints would be great. Thank you for your time.

Here is a video of the cells in the grid that I am able to render. Note, the reason for wanting to use TerraMonkey is to auto-load tiles at deeper resolutions. The video only shows resolutions of 1 and 3 level where the number of tiles in each level is 6*9^level

Here is the code that I am trying:

[java] @Override

public TerrainQuad getTerrainQuadAt(Vector3f location) {

System.out.println("GetTerrainQuad at "+location+" patchsize = "+patchSize+" quadsize = "+quadSize);

TerrainQuad q = new TerrainQuad("Quad" + location,patchSize, quadSize,null);

Cell cell = new Cell("N","N"+location.x,true);


Spatial spatial = (Spatial)cell;

return (TerrainQuad)spatial;[/java]

Where Cell is


public Cell (String prefix, String suid, boolean isActive){

this.suid = suid;

// initialize the asset manager if its not already


// create the mesh & geometry - the base of the cell

mesh = new Quad(width,width);

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

setColor(prefix, mat,!isActive);

shape = new Geometry(suid,mesh);




shape.setLocalTranslation(-1halfWidth, -1halfWidth, 0);


// create a border around the quads

Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

mat2.setColor("Color", ColorRGBA.Black);

Geometry outline = new Geometry("outline",mesh);


Texture tex = assetManager.loadTexture("Textures/border.png");



mat2.setTexture("ColorMap", tex);




outline.setLocalTranslation(-1halfWidth, -1halfWidth, 0.01f);


// create the text

BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");

BitmapText text = new BitmapText(font, false);



text.setBox(new Rectangle(0,0,width,width));





Node textNode = new Node();


textNode.setLocalTranslation(-1*halfWidth, halfWidth, 0.05f);



It seems that AssetTileLoader should hold the answer … but what am I doing differently then …

[java]public TerrainQuad getTerrainQuadAt(Vector3f location) {

String modelName = assetPath + “/” + name + “" + Math.round(location.x) + "” + Math.round(location.y) + “_” + Math.round(location.z) + “.j3o”;

Logger.getLogger(this.getClass().getName()).log(Level.INFO, “Load terrain grid tile: {0}”, modelName);

TerrainQuad quad = null;

try {

quad = (TerrainQuad) manager.loadModel(modelName);

} catch (Exception e) {


return quad;


From com.jme3.terrain.geomipmapTerrainGrid line 153

[java] } else if (gridTileLoader != null) {

q = gridTileLoader.getTerrainQuadAt(quadCell);

// only clone the material to the quad if it doesn’t have a material of its own

if(q.getMaterial()==null) q.setMaterial(material.clone());

log.log(Level.FINE, “Loaded TerrainQuad {0} from TerrainQuadGrid”, q.getName());


I think the line q.getMaterial() might be a problem since getTerrainQuadAt is returning a node that has been cast to a spatial then to a TerrainQuad as has been done in the AssetTileLoader. Thoughts?

After further investigation, the following line seems to halt execution without any errors …

[java]TerrainQuad q = new TerrainQuad(“Quad” + location,patchSize, quadSize,null);[/java]

Any ideas of what might be causes this? I attempted to debug but I couldn’t step into the constructor (it seems to fail before the constructor).

I found the problem. After reading through the source, I found this statement:

[java] if (!FastMath.isPowerOfTwo(quadSize - 1)) {

throw new RuntimeException("size given: " + quadSize + " Terrain quad sizes may only be (2^N + 1)");[/java]

I was using 64! I switched to using 65 and it now works!