Presenting
XNA Procedural Trees, a natural tree generator for XNA.
Download is at bottom of post, but first some screenshots.




The four screenshots above show the four different
tree profiles I am providing. A tree profile is an XML file with information about how to generate a random tree. The trees a generated using a profile and a random seed, making for an endless amount of possible tree models.
The leaves you see on the trees are a kind of billboard - on the willow (lower right screenshot) they are axis-aligned, and on the others they are free. Leaves are also part of the tree profile. Wind blowing against the leaves is not supported, but I have it in mind for a future release.
The code is freely available under the
MIT License, which means that you can do almost anything you like with the code.
Since XNA does not have its own scene graph, implementing it general enough for everyone to use it has a bit of a challenge, but you shouldn't have problems using it once you understand how the classes are structured. The supplied TreeDemo application is a great point of reference for seeing how to use it.
How to use XNA Procedural Trees in your project (only a partial reminder list):
- Add the FeldthausTrees project to your solution.
- Add a reference to FeldthausTrees in your main project (right-click on References in the solution explorer)
- Add the tree profiles (XML files found in Content/Trees), to somewhere in your Content folder.
- Select the XML files, open Properties, and set "Copy to destination folder" to "Copy if newer".
-
Add the textures. Set the bark textures' content processor to "XNA -
Texture (mipmapped)". Leave the leaf texture at "XNA - Sprite".
- In your code, create a ParticleCloudSystem during LoadGraphicsContent.
- Create a TreeGenerator for each tree profile you want to use.
- Use GenerateTreeMesh to generate a tree.
- Set TreeMesh.Trunk.Projection to the projection matrix.
- Use TreeMesh.Trunk.Draw and TreeMesh.Leaves.Draw to draw the tree.
For those interested in creating their own tree profiles, I wrote a
small tutorial you can use, and the XML format is not that hard to guess by looking at the existing profiles. If you do make a new tree profile, I would be very happy if you would post it here for everyone to see :)
Comments are more than welcome. I hope this was the right forum to post in - none of the others seemed to fit this kind of post.