Using mountains512.png for 'endless terrain' (my problem: nothing shows up)

trying to get an example of edited code working in my own project, i tried to use ‘mountains512.png’ in stead of the stock zipfile (which doesn’t work for me, gives all-black & flat terrain) and also because i want to use my own custom HeightMapGrid later on.



No doubt i messed up, but i can’t pinpoint what, all i get is the background, no terrain. raycasting and wireframe overlays confirm no terrain is generated beneath me (player initially spawns 150 above the 0,0,0 position, called from it’s own function)



If you gentlemen could point out how i messed up and how to fix it, i’d be grateful.

Code:
private void initMap() { // Relevant materials are set in a separate initMaterials()
    AbstractHeightMap heightmap = null;
    Texture heightMapImage = assetManager.loadTexture(
            "Textures/Terrain/splat/mountains512.png");
    heightmap = new ImageBasedHeightMap(
            ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));
    heightmap.load();


    terrain = new TerrainGrid("terrain", 65, 513, new ImageBasedHeightMapGrid(assetManager, new Namer() {

        public String getName(int x, int y) {
            return "Textures/Terrain/splat/mountains512.png";
        }
    }));

    terrain.setMaterial(terrain_mat);
    this.terrain.setLocalTranslation(0, 0, 0);
    this.rootNode.attachChild(this.terrain);

    TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());
    control.setLodCalculator(new DistanceLodCalculator(257, 2.7f));
    this.terrain.addControl(control); 

    //CollisionShape terrainShape = CollisionShapeFactory.createMeshShape((Node) terrain);
    final BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);

    this.getCamera().setLocation(new Vector3f(0, 256, 0));


    terrain.addListener("physicsStartListener", new TerrainGridListener() {

        public void gridMoved(Vector3f newCenter) {
        }

        public Material tileLoaded(Material material, Vector3f cell) {
            return material;
        }

        public void tileAttached(Vector3f cell, TerrainQuad quad) {
            while (quad.getControl(RigidBodyControl.class) != null) {
                quad.removeControl(RigidBodyControl.class);
            }
            quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
            bulletAppState.getPhysicsSpace().add(quad);
        }

        public void tileDetached(Vector3f cell, TerrainQuad quad) {
            bulletAppState.getPhysicsSpace().remove(quad);
            quad.removeControl(RigidBodyControl.class);
        }
    });




    this.terrain.initialize(cam.getLocation());



}</div>

What version are you using?

TerrainGridTest in the latest svn version (from trunk) has a working zip file.

As for substituting the image with mountains512.png, the Grayscale16BitHeightMap is having issues loading it.



Hold off now, at least for the next week, on using that mountains512 image file directly. I am changing how the image heightmap works to remove the dependency on AWT.

1 Like

Thanks for the heads up, as for the version, i did a full update about 2-3 days ago, but its all 3.0Beta according to the ‘about jMonkey’ tab (i use a mac)



Is there any other file i could use, or method you’d advise ? (eventually i want to put my terrain ‘tiles’ in a MySQL DB, which is why i’m intending to make a custom MysqlHeightMapGrid, maybe even a similar sollution for the material maps)

If the svn path you are using is jmonkeyengine.googlecode.com/svn/trunk/ then you have the latest version.



What you plan to do is correct for loading in terrain tiles from mysql: subclassing TerrainGridTileLoader. Don’t subclass TerrainGrid itself, it’s just there to facilitate tile loading and seaming the edges up.

i’ve temporarily decided to use the following custom grid

Code:
public class CustomGrid implements HeightMapGrid { private HeightMap heightMap; private int size;
public CustomGrid(int size) {
    this.size = size - 1;
    
}



@Override
public HeightMap getHeightMapAt(Vector3f location) {
    try {
        this.heightMap = new MidpointDisplacementHeightMap(this.size, 0.5f, 0.5f);
        this.heightMap.load();
        
    } catch (Exception x) {
        //
    }
    //return heightMap;
    return this.heightMap;
}

public void setHeightMap(HeightMap input) {
    //this.heightMap = input;
}

@Override

public void setSize(int size) {
this.size = size - 1;
}

}


What should i change in the code posted below to make use of this, because
Code:
private void initMapGrid() {
    terrain_grid = new TerrainGrid(&quot;terrain&quot;, 65, 257, new CustomGrid( 257));

    terrain_grid.setMaterial(terrain_mat);
    this.terrain_grid.setLocalTranslation(0, 0, 0);
    this.rootNode.attachChild(this.terrain_grid);

    TerrainLodControl control = new TerrainLodControl(this.terrain_grid, getCamera());
    control.setLodCalculator(new DistanceLodCalculator(257, 2.7f));
    this.terrain_grid.addControl(control);

    //CollisionShape terrainShape = CollisionShapeFactory.createMeshShape((Node) terrain_grid);
    final BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);

    this.getCamera().setLocation(new Vector3f(0, 256, 0));


    terrain_grid.addListener(&quot;physicsStartListener&quot;, new TerrainGridListener() {

        public void gridMoved(Vector3f newCenter) {
        }

        public Material tileLoaded(Material material, Vector3f cell) {
            return material;
        }

        public void tileAttached(Vector3f cell, TerrainQuad quad) {
            while (quad.getControl(RigidBodyControl.class) != null) {
                quad.removeControl(RigidBodyControl.class);
            }
            quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain_grid.getLocalScale()), 0));
            bulletAppState.getPhysicsSpace().add(quad);
        }

        public void tileDetached(Vector3f cell, TerrainQuad quad) {
            bulletAppState.getPhysicsSpace().remove(quad);
            quad.removeControl(RigidBodyControl.class);
        }
    });

    this.terrain_grid.initialize(cam.getLocation());
}</div>

causes the following exception causes me to see no land/terrain and float in space :S
(a recurring motif in my bugs, i might add, lol )

Nevermind :S the bulletappstate/collisionShape was wrong, it works now :slight_smile:

The HeightMapGrid classes are deprecated in svn, theres been some changes to the TerrainGrid.

aaagh, just when i got things working :smiley:



i’ll stay on the documented path for now

Hmm, that is to say, there IS a landscape, but it’s utterly flat



[edit]

that too fixed with some tinkering.