Problems creating terrain & water

hello,



i've got a small extraxt from a project here im just working on.





UserInterface.java

package test;


import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;


public class UserInterface
{
   // CONSTANTS
   // --- Empty
   


   // OBJECTS
   // --- Game
   StandardGame jmeStandardGame;
   
   // --- States
   EnvironmentGamestate enviroment;
   
   

   // PROPERTIES
   // --- Empty
   


   // METHODS
   // --- Constructor
   public UserInterface()
   {
      jmeStandardGame = new StandardGame("Game");
      try{GameSettingsPanel.prompt(jmeStandardGame.getSettings());}catch (InterruptedException e1){}
      jmeStandardGame.start();
   }
   
   
   
   // --- CreateEnvironment
   public void createEnvironment()
   {
      enviroment = new EnvironmentGamestate(jmeStandardGame);
      GameStateManager.getInstance().attachChild(enviroment);
      enviroment.setActive(true);
   }



   // --- Main-Method
   public static void main(String[] args)
   {
      UserInterface ui = new UserInterface();
      ui.createEnvironment();
   }
}




EnvironmentGameState.java

package test;


import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Callable;

import javax.swing.ImageIcon;

import jmetest.effects.water.TestProjectedWater;

import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.MouseInputListener;
import com.jme.math.FastMath;
import com.jme.math.Plane;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.Renderer;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.renderer.pass.RenderPass;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.Spatial;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.scene.Spatial.TextureCombineMode;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.TextureManager;
import com.jmex.effects.water.ProjectedGrid;
import com.jmex.effects.water.WaterHeightGenerator;
import com.jmex.effects.water.WaterRenderPass;
import com.jmex.game.StandardGame;
import com.jmex.game.state.CameraGameStateDefaultCamera;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.ImageBasedHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;


public class EnvironmentGamestate extends CameraGameStateDefaultCamera
{
   // CONSTANTS
   // --- Camera
   private static final float camSpeed = 3f;
   private static final float camMaxWinkel = 40;
   private static final float camMinWinkel = 5;
   private static final float camMaxZoom = -1500f;
   private static final float camMinZoom = -500f;
   
   // --- Sichtweite
   private static final float farPlane = 10000f;
   


   // OBJECTS
   // --- Program
   private StandardGame jmeStandardGame;
   private DisplaySystem jmeDisplay = DisplaySystem.getDisplaySystem();
   
   // --- Enviroment
   private Skybox skybox;
   private Node reflectedNode;
   private TerrainBlock terrainBlock;
   
   private Node waterNode;
   private Quad waterQuad;
   private WaterRenderPass waterEffectRenderPass;
   private ProjectedGrid projectedGrid;
   private BasicPassManager waterPassManager;
   
   // --- Camera
   private Camera cam;
   private CameraNode camNode;
   private Node camPivot;
   


   // PROPERTIES
   // --- Camera
   private float camZoomIn = 0;
   private boolean camSpin = false;
   
   

   // METHODS
   // --- Constructor
   public EnvironmentGamestate(StandardGame _jmeStandardGame)
   {
      super("Enviroment");
      

      jmeStandardGame = _jmeStandardGame;
      

      reflectedNode = new Node("Reflected Node");
      getRootNode().attachChild(reflectedNode);
      

      setupCamConfig();
      
      setupCtrl();
      
      createSkybox();
      
      createTerrain();
      
      createWater();
      
      getRootNode().updateRenderState();
   }
   
   

   // --- Setup the Camera
   private void setupCamConfig()
   {
      DisplaySystem.getDisplaySystem().getRenderer().getCamera().setFrustumPerspective(45.0f, DisplaySystem.getDisplaySystem().getWidth() / DisplaySystem.getDisplaySystem().getHeight(), 1, farPlane);
      
      cam = jmeDisplay.getRenderer().getCamera();
      
      camNode = new CameraNode("CamNode", cam);
      
      camPivot = new Node();
      camPivot.setLocalTranslation(new Vector3f(200f, 130f, 200f));
      camPivot.attachChild(camNode);
      camPivot.getLocalRotation().fromAngles(20 * FastMath.DEG_TO_RAD, 45 * FastMath.DEG_TO_RAD, 0);
      camNode.setLocalTranslation(new Vector3f(0f, 0f, -1000f));
      getRootNode().attachChild(camPivot);
      
      cam.setLocation(new Vector3f(50, 100, 50));
   }
   
   

   // --- Setup the Game-Control
   private void setupCtrl()
   {
      // Input & Keybindings
      MouseInput.get().addListener(new MouseInputListener()
      {
         //Camera
         @Override
         public void onButton(int button, boolean pressed, int x, int y)
         {
            if ((button == 1) && pressed)
            {
               camSpin = true;
            }
            else if (button == 1)
            {
               camSpin = false;
            }
         }
         
         @Override
         public void onMove(int xDelta, int yDelta, int newX, int newY)
         {
            
         }
         
         @Override
         public void onWheel(int wheelDelta, int x, int y)
         {
            camZoomIn += wheelDelta;
         }
      });
      
      KeyBindingManager.getKeyBindingManager().set("up", KeyInput.KEY_UP);
      KeyBindingManager.getKeyBindingManager().set("dn", KeyInput.KEY_DOWN);
      KeyBindingManager.getKeyBindingManager().set("lt", KeyInput.KEY_LEFT);
      KeyBindingManager.getKeyBindingManager().set("rt", KeyInput.KEY_RIGHT);
      
      //Escape
      KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
   }
   
   

   // --- Skybox erstellen
   private void createSkybox()
   {
      skybox = new Skybox("GameSkybox", 10, 10, 10);
      
      String dir = "jmetest/data/skybox1/";
      Texture skyNorth = TextureManager.loadTexture(TestProjectedWater.class.getClassLoader().getResource(dir + "1.jpg"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      Texture skySouth = TextureManager.loadTexture(TestProjectedWater.class.getClassLoader().getResource(dir + "3.jpg"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      Texture skyEast = TextureManager.loadTexture(TestProjectedWater.class.getClassLoader().getResource(dir + "2.jpg"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      Texture skyWest = TextureManager.loadTexture(TestProjectedWater.class.getClassLoader().getResource(dir + "4.jpg"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      Texture skyUp = TextureManager.loadTexture(TestProjectedWater.class.getClassLoader().getResource(dir + "6.jpg"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      Texture skyDown = TextureManager.loadTexture(TestProjectedWater.class.getClassLoader().getResource(dir + "5.jpg"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
      
      skybox.setTexture(Skybox.Face.North, skyNorth);
      skybox.setTexture(Skybox.Face.South, skySouth);
      skybox.setTexture(Skybox.Face.East, skyEast);
      skybox.setTexture(Skybox.Face.West, skyWest);
      skybox.setTexture(Skybox.Face.Up, skyUp);
      skybox.setTexture(Skybox.Face.Down, skyDown);
      
      try
      {
         GameTaskQueueManager.getManager().update(new Callable<Object>()
         {
            public Object call() throws Exception
            {
               skybox.preloadTextures();
               return null;
            }
         }).get();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      
      CullState skyboxCullState = jmeDisplay.getRenderer().createCullState();
      skyboxCullState.setCullFace(CullState.Face.None);
      skyboxCullState.setEnabled(true);
      skybox.setRenderState(skyboxCullState);
      
      ZBufferState skyboxBufferState = jmeDisplay.getRenderer().createZBufferState();
      skyboxBufferState.setEnabled(false);
      skybox.setRenderState(skyboxBufferState);
      
      FogState skyboxFogState = jmeDisplay.getRenderer().createFogState();
      skyboxFogState.setEnabled(false);
      skybox.setRenderState(skyboxFogState);
      
      skybox.setLightCombineMode(Spatial.LightCombineMode.Off);
      skybox.setCullHint(Spatial.CullHint.Never);
      skybox.setTextureCombineMode(TextureCombineMode.Replace);
      skybox.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      skybox.updateRenderState();
      
      reflectedNode.attachChild(skybox);
   }
   
   
   
   // --- Terrain erstellen
   private void createTerrain()
   {
      URL grayScale = null;
      try
      {
         grayScale = new URL("file:C:\Users\Philipp\Documents\Programme\Eigene Programme\Java\3D Tests\src\onlinegame\HeightMap.jpg");
      }
      catch(MalformedURLException e)
      {
         e.printStackTrace();
      }
      
      ImageBasedHeightMap heightMap = new ImageBasedHeightMap(new ImageIcon(grayScale).getImage());
      
      Vector3f terrainScale = new Vector3f(64, 2, 64);
      terrainBlock = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale, heightMap.getHeightMap(), new Vector3f(0, -10, 0));
      
      // tb.setTrisPerPixel( 0.5f);
      // terrainBlock.setDistanceTolerance( 1.0f);
      terrainBlock.setDetailTexture(1, 16);
      terrainBlock.setModelBound(new BoundingBox());
      terrainBlock.updateModelBound();
      terrainBlock.setLocalTranslation(new Vector3f(0, 0, 0));
      
      // Texturen laden
      ImageIcon sandTexture = null;
      ImageIcon grassTexture = null;
      
      Callable<Object> preloadSandTexture = new Callable<Object>()
      {
         public Object call() throws Exception
         {
            return new ImageIcon(new URL("file:C:\Users\Philipp\Documents\Programme\Eigene Programme\Java\3D Tests\src\onlinegame\sand.jpg"));
         }
      };
      Callable<Object> preloadGrassTexture = new Callable<Object>()
      {
         public Object call() throws Exception
         {
            return new ImageIcon(new URL("file:C:\Users\Philipp\Documents\Programme\Eigene Programme\Java\3D Tests\src\onlinegame\grass.jpg"));
         }
      };
      try
      {
         sandTexture = (ImageIcon) GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(preloadSandTexture).get();
         grassTexture = (ImageIcon) GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(preloadGrassTexture).get();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      
      
      // Generieren der Textur
      ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap);
      pt.addTexture(sandTexture, 0, 0, 50);
      pt.addTexture(grassTexture, 0, 50, 300);
      
      pt.createTexture(64);
      
      
      TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      //ts.setEnabled(true);
      
      Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(), Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, true);
      t1.setStoreTexture(true);
      ts.setTexture(t1, 0);
      
      
      terrainBlock.setRenderState(ts);
      
      
      reflectedNode.attachChild(terrainBlock);
   }
   
   

   // --- Wasseroberfl

does really nobody have a clue what is wrong here?? or is just nobody's interested?



well … could maybe somebody show me an example in which terrain and projected Water are being used together in one app using StandardGame ??



thanks a lot,

Fellkneul

Could it be that your BasicPassManager isn't attach do anything? Try it to extend your class from SimplePassGame.

good point, i'll try that out