TerrainBlocks - culling problem?

Hi, think this might be related to previous post


I have a problem where using TerrainBlocks the whole of the terrain disappears at certain camera angles. I managed to write a small piece of code using BasicGame that replicates the problem [see end of post].

The problem appears most evident when you follow the terrain and go over the crest of a hill. At that point if you use the mouse to roll the cam around the X-axis then the terrain will disappear and re-appear at the same points, repeatedly. You’ll actually see the tri-count halve, or drop to 0, as they’re culled away !

My gut feeling is that I’m hitting a page boundary which is actually visible but the render believes isn’t as it’s not taking my camera height into account.

import javax.swing.ImageIcon;
import java.net.URL;
import java.io.*;

import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.NodeHandler;
import com.jme.light.DirectionalLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.CameraNode;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.TextureState;
import com.jme.terrain.TerrainPage;
import com.jme.terrain.util.FaultFractalHeightMap;
import com.jme.terrain.util.MidPointHeightMap;
import com.jme.terrain.util.ProceduralTextureGenerator;
import com.jme.terrain.util.ParticleDepositionHeightMap;
import com.jme.terrain.util.RawHeightMap;
import com.jme.util.TextureManager;
import com.jme.renderer.Renderer;
import com.jme.scene.Skybox;
import com.jme.scene.Node;
import com.jme.scene.Controller;
import com.jme.sound.SoundAPIController;
import com.jme.sound.SoundPool;
import com.jme.sound.scene.ProgrammableSound;
import com.jme.sound.scene.SoundNode;
import com.jme.animation.JointController;
import com.jme.animation.KeyframeController;
import com.jme.scene.model.XMLparser.JmeBinaryReader;
import com.jme.scene.model.XMLparser.BinaryToXML;
import com.jme.scene.model.XMLparser.Converters.MaxToJme;
import com.jme.scene.model.XMLparser.Converters.ObjToJme;
import com.jme.scene.shape.Box;
import com.jme.math.Quaternion;
import com.jme.math.FastMath;
import com.jme.input.InputSystem;

public class terrainbug extends SimpleGame {

  TerrainPage tb;

  private CameraNode camNode;

  /** Simply an easy way to get at timer.getTimePerFrame(). */
  protected float tpf;

   * Entry point for the test,
   * @param args
  public static void main(String[] args) {
    terrainbug app = new terrainbug();

   * builds the trimesh.
   * @see com.jme.app.SimpleGame#initGame()
  protected void simpleInitGame() {
    display.setTitle("Terrain Bug ?!?!");

    DirectionalLight dl = new DirectionalLight();
    dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
    dl.setDirection(new Vector3f(1, -0.5f, 1));

    cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);

    camNode = new CameraNode("Camera Node", cam);
    camNode.setLocalTranslation(new Vector3f(0, 250, -20));
    input = new NodeHandler(this, camNode, properties.getRenderer());
    display.getRenderer().setBackgroundColor(new ColorRGBA(0.5f,0.5f,1.0f,1));

    CullState cs = display.getRenderer().createCullState();

    ParticleDepositionHeightMap heightMap = new ParticleDepositionHeightMap(64^2-1,2048,8,64,86,0.5f);
    Vector3f terrainScale = new Vector3f(30,1,30); // 1 pixel = 30m
    heightMap.setHeightScale( 1f);
    tb = new TerrainPage("Terrain", 33, heightMap.getSize(), terrainScale,
                                     heightMap.getHeightMap(), true);

    tb.setDetailTexture(1, 16);


  /** * Called every frame for rendering */
  protected void simpleRender() {
    Vector3f loc = new Vector3f( cam.getLocation() );
    loc.y=tb.getHeight(loc.x,loc.z)+15.0f; // set cam 15 above ground


PS forgive the massive import list, but while I've cut the code right down I couldn't be bothered to trim those !!

I had the same problem and was never able to solve it. I found that it happens most when you are tordes the top of an object looking up at a large angle at the top few vertexes. The problem is not limited to terrine. If this is a bug fixing in should be at the top of the todo list.

Thanks for the test case. I’ll take a look at it when I can.

It sounds like the bounding volumes for the terrain pages/terrain blocks are not being calculated correctly. Pressing ‘b’ will turn on boundings to see.

I’ll confirm this soon and see if I can tell what’s going on.

This is not an issue with terrain pages/terrain blocks, I get it with other objects in jme. When I have bounding on, the bonding also disappears with the objects. IT looks like bounding are being cuddled incorrectly. I know this happens with spheres, I do not know about the other volumes.

This is something that I have not seen, so if you are having this issue, make a test case to show it and I’ll see what the problem is.