Hi, think this might be related to previous post
http://mojomonkeycoding.com/jmeforum/viewtopic.php?t=817&highlight=terrainpage
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();
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
/**
* builds the trimesh.
*
* @see com.jme.app.SimpleGame#initGame()
*/
protected void simpleInitGame() {
display.setTitle("Terrain Bug ?!?!");
rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
fpsNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
DirectionalLight dl = new DirectionalLight();
dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
dl.setDirection(new Vector3f(1, -0.5f, 1));
dl.setEnabled(true);
lightState.attach(dl);
cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);
cam.update();
camNode = new CameraNode("Camera Node", cam);
camNode.setLocalTranslation(new Vector3f(0, 250, -20));
camNode.updateWorldData(0);
input = new NodeHandler(this, camNode, properties.getRenderer());
rootNode.attachChild(camNode);
input.setKeySpeed(150f);
input.setMouseSpeed(1f);
display.getRenderer().setBackgroundColor(new ColorRGBA(0.5f,0.5f,1.0f,1));
CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
cs.setEnabled(true);
rootNode.setRenderState(cs);
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);
rootNode.attachChild(tb);
}
/** * 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
cam.setLocation(loc);
cam.update();
}
}
PS forgive the massive import list, but while I've cut the code right down I couldn't be bothered to trim those !!