I am following the heightmap tutorial on this site and wanted to extend it to get a bit more practice.
I would like to reload the heightmap every e.g. 10 seconds, so that I can have paint.net open for editing and can ‘simultaniously’ see the new heightmap in my sample application.
I tried to do this by overriding the ’ update’ method of the application and call reloadTerrain() from there, but it does not seem to work.
(I know that the approach below is quite inefficient, but I just started out on it)
private void reloadTerrain() {
assetManager.clearCache(); // clearing cache as mointain image might have changed
AbstractHeightMap heightmap = null;
Texture heightMapImage = assetManager.loadTexture(
"Textures/Terrain/splat/mountains512.png");
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
heightmap.load();
int patchSize = 65;
rootNode.detachAllChildren(); // detach the old terrain and further below we add the new terrain
terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());
/** 4. We give the terrain its material, position & scale it, and attach it. */
terrain.setMaterial(mat_terrain);
terrain.setLocalTranslation(0, -100, 0);
terrain.setLocalScale(2f, 1f, 2f);
rootNode.attachChild(terrain);
}