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>
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.
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)
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.