Raw Terrain Loading

EDIT FIXED : I thought the size argument pretained to the size to set it to. My Bad :}





First off, this is based off the example code. This works if I let the original

heightMap made by the fault fractal. Then I save it, (RAW), and load the Raw using the RawHeightMap loader. Nothing pops up saying either that its loaded successfully or not ( Like it should ), and it blanks out my whole screen (my UI). And the screen is blank. Also, before loading it, I manually add the .raw to the filename so that the heightmap loader loads it.



//FaultFractalHeightMap heightMap = new FaultFractalHeightMap(257, 32, 0, 255,
//  0.75f);
//heightMap.save("rawtest");
//heightMap.unloadHeightMap();


/*RawHeightMap Load*/
heightMap2 = new RawHeightMap("rawtest.raw", 3);

Vector3f terrainScale = new Vector3f(10,1,10);
heightMap2.setHeightScale( 0.001f);
TerrainPage tb = new TerrainPage("Terrain", 33, heightMap2.getSize(), terrainScale,
                               heightMap2.getHeightMap(), false);

tb.setDetailTexture(1, 16);

ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap2);
pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader().getResource(
  "jmetest/data/texture/grass.jpg")), -128, 0, 128);
pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader().getResource(
  "jmetest/data/texture/dirt.jpg")), 0, 128, 255);
pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader().getResource(
  "jmetest/data/texture/highest.jpg")), 128, 255, 384);

pt.createTexture(512);

TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
Texture t1 = TextureManager.loadTexture(
  pt.getImageIcon().getImage(),
  Texture.MM_LINEAR_LINEAR,
  Texture.FM_LINEAR,
  true);
ts.setTexture(t1, 0);

Texture t2 = TextureManager.loadTexture(TestTerrain.class.getClassLoader().
                                      getResource(
  "jmetest/data/texture/Detail.jpg"),
                                      Texture.MM_LINEAR_LINEAR,
                                      Texture.FM_LINEAR);
ts.setTexture(t2, 1);
t2.setWrap(Texture.WM_WRAP_S_WRAP_T);

t1.setApply(Texture.AM_COMBINE);
t1.setCombineFuncRGB(Texture.ACF_MODULATE);
t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t1.setCombineScaleRGB(1.0f);

t2.setApply(Texture.AM_COMBINE);
t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t2.setCombineScaleRGB(1.0f);
tb.setRenderState(ts);

FogState fs = display.getRenderer().createFogState();
fs.setDensity(0.5f);
fs.setEnabled(true);
fs.setColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f));
fs.setEnd(1000);
fs.setStart(500);
fs.setDensityFunction(FogState.DF_LINEAR);
fs.setApplyFunction(FogState.AF_PER_VERTEX);
tb.setRenderState(fs);
rootNode.attachChild(tb);

Hi! By notstarting a new thread on the same topic, I will post in here: I am a beginner to this nice engine and just finished some tutorials - however I am also stuck on the .raw problem. I exported a heightmap (it should be a 1024x1024) from terragen in .raw format and tried to import this heightmap into JME like the HelloTerrain.java using the same method


private void homeGrownHeightMap() {
        // The map for our terrain. Each value is a height on the terrain
        int[] map = new int[]{
            1, 2, 3, 4,
            2, 1, 2, 3,
            3, 2, 1, 2,
            4, 3, 2, 1
        };
        // Create a terrain block. Our integer height values will
        // scale on the map 2x larger x,
        // and 2x larger z. Our map's origin will be the regular
        // origin, and it won't create an
        // AreaClodMesh from it.
        TerrainBlock tb = new TerrainBlock("block", 4,
                new Vector3f(2, 1, 2),
                map,
                new Vector3f(0, 0, 0),
                false);
        // Give the terrain a bounding box.
        tb.setModelBound(new BoundingBox());
        tb.updateModelBound();
        // Attach the terrain TriMesh to our rootNode
        //rootNode.attachChild(tb);//TODO: uncomment this line to enable it
    }


Now I just replaced some values and tried to import my grayscale .raw Image like that:

URL grayscale = HelloTerrain.class.getClassLoader().getResource("heightmap.raw");

RawHeightMap rhm = new RawHeightMap(grayscale,1,1,false);
int[] map2 = rhm.getHeightMap();

TerrainBlock tb = new TerrainBlock(
              "block2",
               rhm.getSize(),
               new Vector3f(1,1,1),
               map2,
               new Vector3f(0, 0, 0),
               false);



However there seems to be something missing or an error at the value "rhm.getSize()" receiving a "java.lang.IndexOutOfBoundsException: -3"  :? Anyone knows what I am doing wrong here?