Terrain & Skybox

I've got a problem that completely baffles me.

I use JME 0.10, and i didn't compile it myself, i just downloaded the compiled code for it.

I just started working with JME and made this program to test out terrain and skybox stuff:



package jmetest;

import java.net.URL;
import javax.swing.ImageIcon;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.util.TextureManager;
import com.jme.scene.Skybox;
import com.jme.scene.state.*;
import com.jme.system.*;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.MidPointHeightMap;
import com.jmex.terrain.util.ImageBasedHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;

public class SkyTerrainTest extends SimpleGame {
   Skybox skybox;

    public static void main(String[] args) {
        SkyTerrainTest app = new SkyTerrainTest();
        app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }

    protected void simpleInitGame() {
        // Create the sky & the ground
        Terrain();
        Skybox();
    }
   
    private void Skybox() {
        skybox = new Skybox("skybox", 200, 200, 200);

      Texture north = TextureManager.loadTexture(
                  SkyTerrainTest.class.getClassLoader().getResource(
                  "jmetest/north.jpg"),
                  Texture.MM_LINEAR,
                  Texture.FM_LINEAR);
      Texture south = TextureManager.loadTexture(
                  SkyTerrainTest.class.getClassLoader().getResource(
                  "jmetest/south.jpg"),
                  Texture.MM_LINEAR,
                  Texture.FM_LINEAR);
      Texture east = TextureManager.loadTexture(
                  SkyTerrainTest.class.getClassLoader().getResource(
                  "jmetest/east.jpg"),
               Texture.MM_LINEAR,
               Texture.FM_LINEAR);
      Texture west = TextureManager.loadTexture(
                  SkyTerrainTest.class.getClassLoader().getResource(
                  "jmetest/west.jpg"),
                  Texture.MM_LINEAR,
                  Texture.FM_LINEAR);
      Texture up = TextureManager.loadTexture(
                  SkyTerrainTest.class.getClassLoader().getResource(
                  "jmetest/top.jpg"),
                  Texture.MM_LINEAR,
                  Texture.FM_LINEAR);
      Texture down = TextureManager.loadTexture(
                  SkyTerrainTest.class.getClassLoader().getResource(
                  "jmetest/bottom.jpg"),
                  Texture.MM_LINEAR,
                  Texture.FM_LINEAR);

      skybox.setTexture(Skybox.NORTH, north);
      skybox.setTexture(Skybox.WEST, west);
      skybox.setTexture(Skybox.SOUTH, south);
      skybox.setTexture(Skybox.EAST, east);
      skybox.setTexture(Skybox.UP, up);
      skybox.setTexture(Skybox.DOWN, down);
      skybox.preloadTextures();
      skybox.getSide(Skybox.NORTH).setLightCombineMode(LightState.OFF);
      skybox.getSide(Skybox.SOUTH).setLightCombineMode(LightState.OFF);
      skybox.getSide(Skybox.WEST).setLightCombineMode(LightState.OFF);
      skybox.getSide(Skybox.EAST).setLightCombineMode(LightState.OFF);
      skybox.getSide(Skybox.UP).setLightCombineMode(LightState.OFF);
      skybox.getSide(Skybox.DOWN).setLightCombineMode(LightState.OFF);
      rootNode.attachChild(skybox);
   }
   
   private void Terrain() {
      MidPointHeightMap mph=new MidPointHeightMap(64,1.5f);
      // Create a terrain block from the created terrain map.
      TerrainBlock tb=new TerrainBlock("terrain",mph.getSize(),
         new Vector3f(1,.11f,1),
         mph.getHeightMap(),
         new Vector3f(0,-25,0),true);

        // These will be the textures of our terrain.
      URL waterImage=SkyTerrainTest.class.getClassLoader().
         getResource("jmetest/water.png");
      URL dirtImage=SkyTerrainTest.class.getClassLoader().
         getResource("jmetest/grassb.jpg");
      URL highest=SkyTerrainTest.class.getClassLoader().
         getResource("jmetest/highest.jpg");

      ProceduralTextureGenerator pg=new ProceduralTextureGenerator(mph);
      pg.addTexture(new ImageIcon(waterImage),0,30,60);
      pg.addTexture(new ImageIcon(dirtImage),40,80,120);
      pg.addTexture(new ImageIcon(highest),110,130,256);
      pg.createTexture(256);
      TextureState ts=display.getRenderer().createTextureState();

      ts.setTexture(TextureManager.loadTexture(
         pg.getImageIcon().getImage(),
         Texture.MM_LINEAR_LINEAR,
         Texture.FM_LINEAR,
         true));
         
      tb.setRenderState(ts);

      tb.setModelBound(new BoundingBox());
      tb.updateModelBound();

      tb.setLocalTranslation(new Vector3f(0,0,-50));

      rootNode.attachChild(tb);
   }
   
    protected void simpleUpdate () {
      skybox.setLocalTranslation(cam.getLocation());
   }
}



It compiles fine, but the only way i can get the skybox to render at all is if i comment out the call to Terrain(), and the skybox responds to lighting if i don't individually set the quads it's made up of to not do that. So, getting the lighting thing out of the way, i either have terrain and no sky or an empty skybox.

I also just noticed, my username was meant to be rootbeerbandit348, not the way it is now with the t and i transposed, how could i fix that?

Fixed, your name. This required a password reset, which has been e-mailed to you.

Aside from the images not being in the places your code says, the code worked fine for me (after I editted the image locations).  I was also able to remove your LightState.OFF lines with no problem.



Perhaps the version of jME you downloaded is out of date?  I am using CVS myself.



Here's the cleaned up version:


package jmetest;

import java.net.URL;

import javax.swing.ImageIcon;

import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.scene.Skybox;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.MidPointHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;

public class SkyTerrainTest extends SimpleGame {
    Skybox skybox;

    public static void main(String[] args) {
        SkyTerrainTest app = new SkyTerrainTest();
        app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }

    protected void simpleInitGame() {
        // Create the sky & the ground
        Terrain();
        Skybox();
    }

    private void Skybox() {
        skybox = new Skybox("skybox", 200, 200, 200);

        Texture north = TextureManager.loadTexture(SkyTerrainTest.class
                .getClassLoader().getResource("jmetest/data/texture/north.jpg"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);
        Texture south = TextureManager.loadTexture(SkyTerrainTest.class
                .getClassLoader().getResource("jmetest/data/texture/south.jpg"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);
        Texture east = TextureManager.loadTexture(SkyTerrainTest.class
                .getClassLoader().getResource("jmetest/data/texture/east.jpg"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);
        Texture west = TextureManager.loadTexture(SkyTerrainTest.class
                .getClassLoader().getResource("jmetest/data/texture/west.jpg"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);
        Texture up = TextureManager.loadTexture(SkyTerrainTest.class
                .getClassLoader().getResource("jmetest/data/texture/top.jpg"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);
        Texture down = TextureManager.loadTexture(SkyTerrainTest.class
                .getClassLoader().getResource("jmetest/data/texture/bottom.jpg"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);

        skybox.setTexture(Skybox.NORTH, north);
        skybox.setTexture(Skybox.WEST, west);
        skybox.setTexture(Skybox.SOUTH, south);
        skybox.setTexture(Skybox.EAST, east);
        skybox.setTexture(Skybox.UP, up);
        skybox.setTexture(Skybox.DOWN, down);
        skybox.preloadTextures();
        rootNode.attachChild(skybox);
    }

    private void Terrain() {
        MidPointHeightMap mph = new MidPointHeightMap(64, 1.5f);
        // Create a terrain block from the created terrain map.
        TerrainBlock tb = new TerrainBlock("terrain", mph.getSize(),
                new Vector3f(1, .11f, 1), mph.getHeightMap(), new Vector3f(0,
                        -30, 0), false);  // Note: set to false because no real gain for true.

        // These will be the textures of our terrain.
        URL waterImage = SkyTerrainTest.class.getClassLoader().getResource(
                "jmetest/data/texture/water.png");
        URL dirtImage = SkyTerrainTest.class.getClassLoader().getResource(
                "jmetest/data/texture/grassb.png");
        URL highest = SkyTerrainTest.class.getClassLoader().getResource(
                "jmetest/data/texture/highest.jpg");

        ProceduralTextureGenerator pg = new ProceduralTextureGenerator(mph);
        pg.addTexture(new ImageIcon(waterImage), 0, 30, 60);
        pg.addTexture(new ImageIcon(dirtImage), 40, 80, 120);
        pg.addTexture(new ImageIcon(highest), 110, 130, 256);
        pg.createTexture(256);
        TextureState ts = display.getRenderer().createTextureState();

        ts.setTexture(TextureManager.loadTexture(pg.getImageIcon().getImage(),
                Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, true));
        tb.setRenderState(ts);

        tb.setModelBound(new BoundingBox());
        tb.updateModelBound();

        rootNode.attachChild(tb);
    }

    protected void simpleUpdate() {
        skybox.setLocalTranslation(cam.getLocation());
    }
}

I've just downloaded the nightly build and used it with the cleaned up code you posted, and it worked… better, but not quite right.



I can only see the skybox if i'm facing in the right direction, which changes when i move.



EDIT:



WOW!

I just realize whats happening!

When the bounding box for the terrian is in view, the skybox doesn't render, but you can still see it when you hit 'b' and 't'

Hmm, can anyone else replicate this?  It works fine for me.  Maybe you still have old jars in your cp somewhere?

I've checked the classpath, i have the correct stuff.

PLEASE someone help me, i'll have to use another engine if i can't get any help.

Works perfectly for me with the latest cvs.



However, the skybox doesn't look right using 0.10 (which seems to just be a 0.10 issue in general).

Go the main page. There’s two links there, nightly builds and the wiki. Nightly builds almost work the same as the release jars, except they’re much more up up to date. On the wiki you can find some tuturials on using CVS, that means you can update the source code for jME to the latest version with your IDE any time you want.

@Llama: he already said he tried with nightlys :slight_smile:

irrisor said:

@Llama: he already said he tried with nightlys :)


Then is it possible that graphics drivers are a problem?

Might be your drivers… :?

Works fine for me just as you posted it.

I just had a friend try out the program with the nightly build and he got the same results i did, just slower framerate because of his slower processor.

Which platform are you running this with?

Can you gives some specs as well?

My computer:

    Windows XP Home Edition 2002, Service Pack 2

    Intel Pentium 4 CPU 2.66 GHz

    256 MB RAM

    NVIDIA GeForce FX 5200

    Desktop



All I know about my friend's Computer:

    Windows XP Pro

    Laptop

Still sounds like a library issue.  I recall SkyBox at one time had a render order issue.  What is the date on the files inside your "nightly jar"?

Your build is the same as mine, except I have a lot more RAM.



Try building from the CVS.

Did your console logs something like this:



[…]

12.12.2006 21:39:47 com.jme.app.BaseSimpleGame initSystem

INFO: jME version 0.11 beta

[…]



Dec 12, 2006 3:43:23 PM com.jme.app.BaseSimpleGame initSystem

INFO: jME version 0.11 beta

Dec 12, 2006 3:43:23 PM com.jme.app.BaseSimpleGame initSystem

INFO: Running on: nv4_disp

Driver version: 6.14.1.4354

You do know that when you start up, the terrain is not visible (not in front of you anyhow) until you turn the camera to the right?



I've uploaded a windows launchable binary of this test here:  http://www.renanse.com/jme/skytest.zip  (sorry, too lazy to webstart it)  Try that out and see if you still have the same issue.  If you do, it must be a system issue, or you just don't understand what the test is supposed to look like.  :slight_smile:

That ran exactly as mine did, I could see the terrain when I turned the camera a bit, but I nevers saw the skybox, then I turn until the terrain is not in view at all and toggle the wireframe view or something an suddenly the sky is back. I look back toward the terrain and the second the bounds for the terrain come back into view my skybox dissapears. Then I can look back the other way and it comes back.