XNA Creators Club Online
Page 1 of 2 (32 items) 1 2 Next >
Sort Posts: Previous Next

XNA Procedural Trees

Last post 11-20-2007 11:12 AM by Klasker. 31 replies.
  • 11-02-2007 5:23 PM

    XNA Procedural Trees

    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):
    1. Add the FeldthausTrees project to your solution.
    2. Add a reference to FeldthausTrees in your main project (right-click on References in the solution explorer)
    3. Add the tree profiles (XML files found in Content/Trees), to somewhere in your Content folder.
    4. Select the XML files, open Properties, and set "Copy to destination folder" to "Copy if newer".
    5. Add the textures. Set the bark textures' content processor to "XNA - Texture (mipmapped)". Leave the leaf texture at "XNA - Sprite".
    6. In your code, create a ParticleCloudSystem during LoadGraphicsContent.
    7. Create a TreeGenerator for each tree profile you want to use.
    8. Use GenerateTreeMesh to generate a tree.
    9. Set TreeMesh.Trunk.Projection to the projection matrix.
    10. 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.
  • 11-02-2007 5:41 PM In reply to

    Re: XNA Procedural Trees

    I feel humbled yet again.  That is simply amazing!  Thanks for the amazingly generous share!
  • 11-03-2007 4:39 AM In reply to

    Re: XNA Procedural Trees

    Wow thats some fantastic work right there.

    Good job.   

  • 11-03-2007 8:01 AM In reply to

    Re: XNA Procedural Trees

    ...You could make money off of that, you know.
  • 11-03-2007 3:36 PM In reply to

    Re: XNA Procedural Trees

    Wow. That's fabulous. This is when the "community" side of the "XNA community" comes through... when people provide stuff as cool as that for free. Gives me a warm, glowy feeling inside.

    Pandemonium, an occasionally updated blog about my game, XNA, games development, and the games industry; XapParse, a parser for XAP (XACT) files
  • 11-03-2007 6:07 PM In reply to

    Re: XNA Procedural Trees

    Very nice. Thanks for sharing this.
  • 11-05-2007 3:55 PM In reply to

    Re: XNA Procedural Trees

    This looks really cool - I don't think I've seen a tree component yet. Yay!

    If you feel so inclined CodePlex is a very easy site to use for adding Wiki-Style tutorials, screenshots, releases, source code, etc... Pretty much everything you have in this post.

  • 11-05-2007 4:09 PM In reply to

    Re: XNA Procedural Trees

    In the words of the immortal Keanu...  "Whoaa!"

    Nicely done.

    Twin Cities XNA User Group - http://www.twincitiesxnausergroup.com
  • 11-05-2007 4:10 PM In reply to

    Re: XNA Procedural Trees

    Hot Stuff!

    I haven't looked deeper into it yet: Does this support (hardware | shader) instancing, or does it output some sort of Model file? If the latter, then that'd be fine, too.
  • 11-05-2007 5:03 PM In reply to

    Re: XNA Procedural Trees

    I'm not sure what you mean by instancing. It does not output any file - by generating a tree you get a TreeModel object, with the tree's mesh and its leaves, ready for rendering. If you look at the example I think you will easily find your answer, though.
  • 11-06-2007 3:32 AM In reply to

    Re: XNA Procedural Trees

    it Works very well, good job,

    but if vou want to make it work in france (like me ) replace all "."  by "," in all xml files....


    thanks



    Lead Programmer in a Game Company (EdenGames)
  • 11-06-2007 12:49 PM In reply to

    Re: XNA Procedural Trees

    Wow, this is just what i have been lokking for :D. I just have one problem. After adding your trees to my game, all my models and terrain started to look funny. I think this part of your shader creates the problem

    AlphaTestEnable = false;

    AlphaBlendEnable = true;

    BlendOp = Add;

    DestBlend = InvSrcAlpha;

    SrcBlend = SrcAlpha;

    CullMode = None;

    ZWriteEnable = false;

    How can this be fixed?

  • 11-06-2007 12:56 PM In reply to

    Re: XNA Procedural Trees

    Just enable the depth buffer again and disable alpha blending in your component's draw code.
  • 11-06-2007 1:59 PM In reply to