Since Version 1.3.0 Panda3d has a built-in terrain renderer, so another teerain algorithm is probably not needed. Anyway, ThomasEgi pointed me (https://discourse.panda3d.org/viewtopic.php?p=9875&highlight=#9875) to then Ranger MkII demo by Andras Balogh, which looks quite impressive (http://web.interware.hu/bandi/ranger.html).
Ranger MkII uses an improved SOAR (stateless one-pass adaptive refinement) algorithm. The complete terrain mesh is created new every frame, and high-resolution refinement is done only inside the camera frustum, while areas outside the frustum are left at low-resolution.
I have done a small python extension wrapping up code from the Ranger MkII algorithm and adapting it so it can be used from Panda3d. Most of the code is copied 1:1 from the original Ranger MkII sources. I’m not sure if there is need for such an extension, but I still want to share it.
The extension is compiled on WindowsXP using the VC Toolkit 2003 compiler (7.1) and having Platform SDK (R2) installed. It is linked against the official Panda3d 1.3.2 distribution and the downloaded thirdparty dependencies. The code is still alpha at best, and there are many rough edges. For example there are no checks for possible problems, like removing the terrain node path and then calling update again, or unloading in general.
Screenshot (wireframe mode): (240k)
Extension source code: (84k)
Demo (win32 binaries): (2.8M)
The extension is windows only for now. I have tried to move as much code as possible from proprietary libraries to Panda ( libpng -> Panda PNMImage, writing to OpenGL vertex/index buffers -> Panda GeomVertexData/GeomTristrips), but there is still one thing that is windows-only: The way memory mapped files are handled.
On linux using mmap( ) in <sys/mman.h> should do the same, and what I think is the right linux code is included in the sources ( switching with #ifdef WIN32 … #else between windows and linux ). But I don’t have a LINUX machine available, so I could not test if it works. I think someone with C++ knowledge on linux is able to fix this within one or two hours.
Usage and demo:
There is no documentation included either, so I give a very short overview here. For a working example please have a look at demo.py in the binary demo. The demo has two cameras and allows to switch between them using F4. Refinement is done for the refinement camera obviously, while the observer camera allows to have a look at the refinement result from another point of view.
import soarx # setup soarx.setMapBits( 10 ) soarx.setBaseBits( 6 ) soarx.setDetailBits( 6 ) soarx.setHorizontalResolution( 160.0 ) soarx.setVerticalResolution( 0.1 ) soarx.setVerticalBias( 0 ) soarx.setDetailVerticalResolution( 0.0012 ) soarx.setCameraNP( cameraNP ) soarx.setLens( lens ) soarx.init( terrainNP ) soarx.build( ) soarx.load( 'models/ranger/' ) # once a frame soarx.update( )
Calling build( ) is required only once and takes a few moments before it returns. It will process the base elevation map and create a number of png images and two data files. The data files contain everything the SOARX algorithm needs to create a terrain mesh. The png images can be used for shading the terrain (normals, lighting, bump maps, …). The demo contains only a very simple shader.
MapBits, BaseBits, DetailBits:
- BaseBits is the dimension of the heightmap. 10 means 1025x1025 pixels (2^10+1).
- MapBits is the dimension of the effectively rendered terrain. The demo has 16 BaseBits, which is a map with about 65000 x 65000 vertices!
- DetailBits is the dimension of a “detail” elevation map that fills the gaps between the base map vertices.
I am quite new to C++ programming, and I would be interested in feedback if the extension runs on other windows machines (missing dll’s and so on), or if anybody is able to compile it on a linux box. Oh, and please don’t fall on your back and laugh if you see that I am using a batch file for the build process