Sunday, September 25, 2011

Rendering plants, trees, forest. ngPlant.

ngPlant (http://ngplant.sourceforge.net/) is an open source plant modeling software and I wanted to check how to use it and how it performs. Downloaded ngPlant source from http://sourceforge.net/projects/ngplant/files/ngplant/0.9.8/ngplant-0.9.8.tar.gz/download.

ngPlant license:
"
ngPlant is a Free Software project. ngPlant modeling tool and ngpshot utility are distributed under the terms of the GNU General Public License (GPL). Software libraries (libngpcore, libngput and pywrapper) which may be used in another projects are distributed under the terms of the BSD License.
"
Checked the code; to generate models (ngPlant documentation uses the term "instantiate") and render a group of (different) trees of the same species, I would need libngpcore and maybe libngput. "Maybe libngput" as some of the code seems already existing in oolongengine code.
BSD license (libngpcore and libngput) means that code is OK to statically link to and use in iPhone apps. GPL license for ngpview and ngpshow prohibits reusing their rendering implementation in iPhone or N9 (non GPL) applications. Anyway, checked the code and since it is fixed pipeline desktop OpenGL code using GLX and GLEW, I could not use it as is anyway.
In short, I could reuse loading from ngp files and instantiating tree mash models but needed to write rendering.

Compiling went OK with no bigger problems - there is dependency to GLX in p3dglmemcntx.cpp (and .h). Removed them one and png backend from compilation. Next was to write OpenGL ES 2.0 renderring for ngPlant and include it's physics. First, I took example elm.ngp available on Yorik's plant making tutorial. There is also a plant library available here. Thanks Yorik.

Anyway,... elm.ngp. With tens of thousands of triangles, the tree model was a bit heavy to render - so decided to simplify it a bit: removed few branches and did not even want to display leaves in this scene (term billboards used in ngPlant). Elm tree was too big comparing to the rest of the scene, so scaled it down when rendering. I've positioned the tree so that the ball would, after hitting boxes, bounce off it. Here is the result: