Beginning Terrain Editing

hello, i’m a beginner with python and panda… i’m not a complete beginner, i’ve had some c++ experience and also some previous python experience, but i havent worked with python in a while… getting back into it now…

i was wondering if there was any way to create a terrain that is able to be modified during the program running… like if i was to run a cursor over the ground, and have it change the level of the land wherever that cursor goes…

or if i have a bulldozer model, to have the terrain land be modified by the bulldozers movement…

on the XYZ axis, i’m not sure which one is the verticle axis, but i’ll just call it Z for now… i want each gridpoint that makes up the terrain to be able to be moved on the Z (verticle) axis… so that when a bulldozer moves, it builds up the Z ahead of its shovel or scoop or whatever, and wherever it goes, it leaves a trail by moving the gridpoints down a little bit on the Z axis under the bulldozer…

that way, there would be a recessed trail wherever the bulldozer has been, and it will be building up the dirt ahead of its scoop…

anybody understand what i mean?

anyway, i’m just wondering how to do something like this…

if anyone knows, or can point me in the right direction, i would appreciate it.

many many ways to solve a problem, as usual. if you dont want to use shaders (like vertex shaders) you have to fall back on manipulating vertex data. which is described in the manual.
http://www.panda3d.org/manual/index.php/Modifying_existing_geometry_data

i dont mind using vertex shaders… is that another way to do what i would like to do?

Your idea boils down to modifying the vertex data of your terrain. Whether you do that on the CPU side on the GPU side is up to you.

Neither terrain system that Panda3d supports out of the box handles dynamic editing of the final terrain mesh. (Aside from LOD decimation.) You can, however, modify the source heightmap and then have either re-generate their polygonal representation. But, this is really not something meant for realtime usage. ie: Might work fine for a level editor, but not so well for your bulldozer-pushing-terrain example. Also, since these heightmap->mesh phases are usually costly in CPU time, they are limited to only when necessary, so any modifications you make won’t show up immediately.

On the other side of things, you are able to modify the final mesh that this step creates however you want, using the two methods that Thomas mentioned – Either as a post-process on the CPU side (GeomVertexWriter manipulations) or on the GPU side with a vertex shader. But neither will “play along” with the LOD decimation that the terrain supports; You’ll have to apply your changes after either the GMT or Tessellator generates their final mesh, otherwise it will be overwritten when the next re-generate occurs.

If you want this to happen rapidly, for realtime usage, you might consider rolling your own terrain system that assumes dynamic editing from the start.

Also, consider the use of geometry shaders, which can be helpful to leave trails of dirt like you’re talking about - as with deforming the vertices of a heightmap you’ll probably get funny stuff with LOD, and texturing.