Greetings,
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
http://www.youtube.com/watch?v=x90qmNcx2U4
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);
cell.scale(quadSize/Cell.width);
Spatial spatial = (Spatial)cell;
return (TerrainQuad)spatial;[/java]
Where Cell is
[java]
public Cell (String prefix, String suid, boolean isActive){
this.suid = suid;
// initialize the asset manager if its not already
initAssetManager();
// 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.setMaterial(mat);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
shape.setQueueBucket(Bucket.Transparent);
shape.setLocalTranslation(-1halfWidth, -1halfWidth, 0);
attachChild(shape);
// 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);
outline.setMaterial(mat2);
Texture tex = assetManager.loadTexture("Textures/border.png");
//tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
//tex.setMagFilter(Texture.MagFilter.Nearest);
mat2.setTexture("ColorMap", tex);
mat2.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
outline.setMaterial(mat2);
outline.setQueueBucket(Bucket.Transparent);
outline.setLocalTranslation(-1halfWidth, -1halfWidth, 0.01f);
attachChild(outline);
// create the text
BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText text = new BitmapText(font, false);
text.setSize(width/6f);
text.setColor(ColorRGBA.White);
text.setBox(new Rectangle(0,0,width,width));
text.setVerticalAlignment(BitmapFont.VAlign.Center);
text.setAlignment(BitmapFont.Align.Center);
text.setText(suid);
text.setQueueBucket(Bucket.Translucent);
Node textNode = new Node();
textNode.attachChild(text);
textNode.setLocalTranslation(-1*halfWidth, halfWidth, 0.05f);
attachChild(textNode);
[/java]
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;
}[/java]
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());
}[/java]
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!