I'm extending the terrain quad with resources from various tutorials and have the following code:
public class WorldTerrain extends TerrainQuad {
public static final String NAME = "terrain";
public static final int PATCH_SIZE = 9;
public static final int TOTAL_SIZE = 33;
private static Vector3f spawnLocation = new Vector3f(13, 3, 16);
private Material mat_terrain;
private void loadText(AssetManager assetManager) {
/**
* 1. Create terrain material and load four textures into it.
*/
mat_terrain = new Material(assetManager,
"Common/MatDefs/Terrain/Terrain.j3md");
/**
* 1.1) Add ALPHA map (for red-blue-green coded splat textures)
*/
mat_terrain.setTexture("Alpha", assetManager.loadTexture(
"Textures/Terrain/splat/alphamap.png"));
/**
* 1.2) Add GRASS texture into the red layer (Tex1).
*/
Texture grass = assetManager.loadTexture(
"Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex1", grass);
mat_terrain.setFloat("Tex1Scale", 64f);
/**
* 1.3) Add DIRT texture into the green layer (Tex2)
*/
Texture dirt = assetManager.loadTexture(
"Textures/GrassRocky.png");
dirt.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex2", dirt);
mat_terrain.setFloat("Tex2Scale", 32f);
/**
* 1.4) Add ROAD texture into the blue layer (Tex3)
*/
Texture rock = assetManager.loadTexture(
"Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex3", rock);
mat_terrain.setFloat("Tex3Scale", 128f);
}
private static float[] generateHeightMap(AssetManager assetManager) {
AbstractHeightMap heightmap = null;
try {
heightmap = new HillHeightMap(1024, 100, 2, 10, 1);
} catch (Exception ex) {
Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
}
return heightmap.getHeightMap();
}
public static Vector3f getSpawnLocation() {
return spawnLocation;
}
public WorldTerrain(Interface app) {
super(NAME, PATCH_SIZE, TOTAL_SIZE, generateHeightMap(app.getAssetManager()));
loadText(app.getAssetManager());
setMaterial(mat_terrain);
setModelBound(new BoundingBox());
setLocalTranslation(32f, 0f, 32f);
List<Camera> cameras = new ArrayList<Camera>();
cameras.add(app.getCamera());
RigidBodyControl landscape = new RigidBodyControl(0.0f);
addControl(landscape);
and the interface:
public class Interface extends SimpleApplication {
private TerrainQuad terrain;
Material mat_terrain;
public static void main(String[] args) {
Interface app = new Interface();
app.start();
}
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(50);
terrain = new WorldTerrain(this);
rootNode.attachChild(terrain);
}
This gives the following result: as you can see large parts of the terrain are not rendering (ignore the weird mountains those are only tests). If I move the camera around these holes move around suggesting it's a rendering problem in the terrain. Anybody who knows how to fix?