Friday, July 25, 2008

L-Systems in 3D (lines)

It's been WAY too long since I updated this, I'd like to say I've been doing more important things like saving the world or something, but nope, nothing.  I've spent most of my free time addicted to a game called Oblivion, it's a great game.  I guess you could say I have been doing some good by saving the good citizens of Cyrodiil.  Although... that's not strictly true, I murdered a good few of them.  To make it seem like I wasn't just playing a game all the time let's just say I was doing research...

I'll be away from the XBox while I'm back in Ireland so I decided to pick up where I left off so I migrated the L-System stuff I had in the WPF test project over to my DirectX project.  It was pretty easy, here's the fractal plant in 2D but in the DirectX app.

lsystemFractalPlantInDX

I then wrote a turtle-graphics class that would traverse the L-System's result and draw in 3D.  The result is still pretty flat because it's just lines and a picture doesn't really do it justice, so I uploaded a video to show what it looks like:

I'm not sure what I should do next... but I think I'll have a go at making the 3D turtle graphics construct a polygon model from the L-System output instead of a line-model.  It doesn't get me any closer to procedural cities but it'd be cool to have procedural trees.

3 comments:

Patrick said...

The tree already looks pretty good in 3D. Too bad DirectX doesn't have an easy way to change the line width. Maybe you could try drawing a a series of point sprites for each branch. Although that might hurt performance more than actual polygons. I have no idea!

Any plan how how you are going to handle leaves? (I know, that is a completely different beast!)

John Leonard said...

I've been racking my brains on how to do 3D trees (like not just lines) - I think it's going to be really messy, I found a good book online though which might have some hints (algorithmic beauty of plants).

As for leaves -- I don't know how but I completely forgot about them! Yeah they'll be a nightmare poly-count wise... I wonder if I just make a textured blob that sits over the trees would that look ok... maybe I'll just make my game winter all the time :)

Patrick said...

There is a procedural tree generator that someone wrote for XNA. You may be able to learn some stuff from it since MDX is so similar to XNA. I haven't used it myself.


http://www.codeplex.com/XNATrees


They use billboards to draw the leaves.