First post here on the forums so please bear with me
I'm using jME2.1, but may eventually migrate to jME3. The idea I have is to dynamically modify terrain, to simulate digging, pot holes, craters etc. (mainly digging). I was thinking of using a heightmap to generate the initial terrain and then modifying that. For example when a character digs a hole, I'd remove a 1m2 area, keeping it square for simplicity for now.
Is this possible with heightmaps, to modify the generated TerrainBlock/TriMesh? If so, this is likely to get messy as more holes are dug and more 'empty' squares appear in the terrain. Also, I would need to create terrain underneath the heightmap dynamically, perhaps either as a number of heightmaps layered or just creating Quads as I go.
Anyone have any thoughts on this? I'm sure dynamic terrain modification is a wish for many developers, but none of the threads I've read seem to have it solved.
it would have taken you just as long to try than to type the post…
Just give it a go, make sure you update the geometric state after you have modified it
That's the thing, I'm not really sure where to start. I have some code (based on the tutorials) for creation of a heightmap. I then have my simpleUpdate() method in which i do:
List<Spatial> children = rootNode.getChildren();
I then get the child TerrainBlock (casting it). I'm then not sure what to use on my TerrainBlock object to remove an inner part of it. Or should I destroy it and create new Spatials that represent the area around the newly dug hole (seems harder)? So I guess I'm looking for a .setToBlank(int x, int y) method on a TerrainBlock/TriMesh/Geometry(obviously if there is such a thing it wont have that name).
Would modifying the vertexes and indices arrays be along the right lines?
for a quick stab, try the setHeight(x,z) on terrainpage/block, then do an updateGeometric state, from there you can determine an efficient approach for your project *( updateGeometricState is expensive )