Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I did not find a question on these lines yet, correct me if I'm wrong.

Trees (and fauna in general) are common in games. Due to their nature, they are a good candidate for procedural generation.

There's SpeedTree, of course, if you can afford it; as far as I can tell, it doesn't provide the possibility of generating your tree meshes at runtime. Then there's SnappyTree, an online webgl based tree generator based on the proctree.js which is some ~500 lines of javascript.

One could use either of above (or some other tree generator I haven't stumbled upon) to create a few dozen tree meshes beforehand - or model them from scratch in a 3d modeller - and then randomly mirror/scale them for a few more variants..

But I'd rather have a free, linkable tree mesh generator.

Possible solutions:

  • Port proctree.js to c++ and deal with the open source license (doesn't seem to be gpl, so could be doable; the author may also be willing to co-operate to make the license even more free).
  • Roll my own based on L-systems.
  • Don't bother, just use offline generated trees.
  • Use some other method I haven't found yet.
share|improve this question
5  
For rolling your own, I'd recommend the book 'the algorithmic beauty of plants' by Prusinkiewicz and Lindenmeyer, which is available at algorithmicbotany.org/papers/#abop. The book and the site also list a lot of research papers on the generation of virtual botany. –  sarahm Dec 15 '12 at 1:11
    
I have created an online tool called 3DFlora with WebGL. It has more than 80 parameters and let you download the results as an obj file. You can create almost any kind of plants with it. Checkit it out here: 3dflora.sina-s.com –  user2002741 Jul 24 at 21:50

5 Answers 5

up vote 8 down vote accepted
+50

I've done a fair bit of work in this area, although most of my demos are older:

(flash 2010)
http://genesisbbs.com/appstem.html (click and drag mouse)
http://genesisbbs.com/appstem2.html
(directX 2006)
http://vimeo.com/5206795

I highly encourage you to roll your own, if you are doing this for fun. You will almost certainly need to work with Quaternions. Understanding them is very hard, but you don't need to go too deep to use them. Think of a quaternion as a vector with an extra component: rotation. If you want your plants to twist and turn as they grow, they will need quaternions.

Other things to learn:
Lichtenberg Figures
Laplacian Growth
Voronoi Diagrams
Nearest Neighbor algorithms (google them)

I (personally) would discourage the use of L-Systems, other than to perhaps dictate a grammar for what grows where, i.e. [seed -> [root] / [trunk->branch->[flower/leaf]]. L systems are not good for responding to environmental stimuli like sunlight direction, gravity, obstacles, etc.

As for speed concerns, a single tree can be generated in realtime. For memory purposes and performance though, you will likely only want to generate a small set of trees and instance them a bit if you are dealing with forests.

Most existing tree generators are not that great (IMHO), besides the high-end ones used for Maya and such.

I also highly, highly recommend using voxels to generate the tree (then skin with a mesh if needed). The advantage of voxels is that you can easily simulate growth algorithms using things like Laplacian growth and various automata (not Conway's game of life, but other rules produce interesting results).

share|improve this answer

Personally I would probably start with pre-generated trees and only once I'd have a kick-ass forest rendering engine - complete with bushes, grass, mushrooms and stuff - would I start looking if I need more variable tree meshes.

That being said, you could take a look at ngPlant. It includes a GPL procedural tree modeler app, but the libraries that do all the heavy lifting are BSD licensed. It's written in C++.

For the forest rendering, there is (MIT licensed) Paged Geometry for Ogre rendering engine.

share|improve this answer

The main problem with procedural trees is not generating them, but rendering them all every frame at runtime. This is the reason you will see many identical trees in AAA games, it's not that they couldn't implement or write tech that created unique trees, it's that it would mean you'd have to cut out a load of other features for the game to run.

If you have many identical trees, you can rotate them and possibly scale them uniformly to make them look different from every angle, and since they are identical you can instance them in order to save precious milliseconds each frame.

Just thinking about this problem for a second, there might be a happy medium - how about you generate a few different tree parts, trunks, branches, leaves etc.. but ones that all fit together in modular ways, like tree lego. Then you could have many combinations and so some quite unique trees, but you could also instance all of the many parts for a faster running game.

share|improve this answer
    
Apart from the piecewise idea this answer doesn't really add anything new. –  Jari Komppa Dec 20 '12 at 12:39
2  
always nice when the OP is so appreciative. For a QandA site your post has a distinct lack of questions. Besides this answer directly addresses your bullet points. –  Asher Einhorn Dec 20 '12 at 18:43
    
Yeah, been there myself, apologies. –  Jari Komppa Dec 21 '12 at 17:01

I stumbled across tree[d] some time ago... I used it for only a small amount of time to test a project but that was only because I stopped development - the tool gives you a wide range of generator options to play with and, from what I remember, is quite fast. A link is below.

The downside is that it isn't a tree generator that you can incorporate. You'd have to pre-generate a few trees and then modify the data when placing them at run-time to tweak their uniqueness.

Best of all TreeD is free to use, and you can include the trees you make in your own projects, commercial or free, as long as they are not model packs, texture packs, 3D model generators, or texture generators.

share|improve this answer
    
Nice to see other free generators, even if it's in a library format. –  Jari Komppa Dec 22 '12 at 9:50

This is a neat little solution, and I have used it in a project and can tell you it is fast enough to gen trees on the fly why the game is running. It's certainly not detailed, but if you got rid of the billboards it could be pretty neat.

http://ltrees.codeplex.com/

share|improve this answer
    
Seems like a good solution for XNA users. –  Jari Komppa Dec 22 '12 at 9:49

protected by Byte56 Jul 24 at 22:59

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.