Procedural trees

Just wanted to show you what I ported to Unity in a day.

Two “trees”

I wrote the original code a couple of years ago in C++
and back then it took me at least a week to write and debug. It is hard for an old assembler-coder to admit this, but this GUI-scripting thingamabob is really cool.

I can think of lots of things to improve about the trees, but I just wanted to show you anyway.

Funky!
AC

So, these trees are all generated from code? Neat!

Those look like good ol’ L-system trees which would be code generated… (am I right? do I win anything? :wink: :P) Good stuff, keep us posted on how things progress!

@Targos: Thank you.

@Moldorma:
Yes generated from code. I make them in the Start() function by creating a new mesh. And I call mesh.Optimize() on them, which makes them run quite smoothly on my 1Ghz G4

@HiggyB:
I had not heard of L-trees before. But now that you mentioned them I googled them and found the math behind it to be very similar. I basically reinvented the same thing.
So maybe you win the honor of knowing more about the subject that me :slight_smile:

I looked at L-system too, and was pretty impressed, and dumbfounded at the same time. It was over my head swiftly.

Will you be collaborating with the Unitree posse and maybe show us the recipe?
AC

L-systems are a great way of doing procedural elements like this and it’s awesome that you (Carsten) managed to stumble upon the same recipe on your own. Good stuff! And I definitely recommend that you share your thoughts with the Unitree folks as Targos hinted at, it would seem you have some good insight to offer given that you’re going through some similar exercises.

I was thinking that it would be really awesome to get a unity tree making script that let you create trees in the Unity editor and save as .obj for later use.

This would be a first step in achieving that goal.

@Targos:If by recipe, you mean the code, you can have what I have done so far. There are installation instructions in the header

It still needs lots of improvements before it is useful in practice, but you can play around with the controls in the inspector, to get a feel for how it works. Be careful about setting recursion level too high.

@HiggyB
Joachim Ante knows that I am doing this. It was his suggestion, that I ported my this to Unity. I believe he is one of the main persons behind UniTree?

Anyway I am not going to join the UniTree project right now, I may still improve the tree generator, but I also have to get back to my main project, which doesn’t really need large landscapes or trees. At least I haven’t thought of where they would fit in yet :slight_smile:

Edit: forgot the actual code the first time :sweat_smile:

31713–1151–$dynamictreebuild_959.js (6.78 KB)

There are a few folks working on the UniTree project, here’s the site URL in case you don’t have it handy:

http://unify.bluegillweb.com/unitree/

Naturally we all understand that you have other commitments to handle first (your main project), we were just making the suggestion to join the UniTree project in case it struck your fancy. Either way, thanks for sharing your work!

Nice one! this should go in the Wiki!

Hi again.

I made an updated version with support for texturing. You can specify (to some degree) how the the texture in the first material should be mapped onto the tree. The second material is assumed to be something that looks like a leaf, and is simply mapped onto a little rectangle. As you can see from the example, I have room for improvement in the texture drawing department.

New version of script included.

About the wiki - well when I get less lazy, i might figure out how to do that. (No, don’t tell me, I just need to get less lazy)

32010--1167--$redandgreentree_443.jpg
32010–1168–$dynamictreebuild_157.js (9.79 KB)

That looks really cool! I had in my head a long time ago an idea that one could create a system that lets you create a structure for the tree eg. I first make a procedural trunk and specify parameters for it, then I add on small alpha channel branches on points specified before (the ends of solid geometry branches) then I add leaf polygons onto those alpha mapped branches (probably the alpha mapped branches are prefabs with transform children for positions and rotations at which the leaves should be instantiated) then the whole thing is cleaned up and combined into one mesh.

Not asking you to make such a system but just putting forth the idea I had. This looks like a great start as far as procedural tree generation !

Have you looked at the tree gen script for maya?
It’s a free download that some Russian dude just wrote.

http://www.highend3d.com/maya/downloads/mel_scripts/modeling/misc/Tree-Generator-1729.html

The idea is basically, generate trunks, generate branches, then it places leaves based on a prefab you provide.

It isn’t perfect, it takes about 5-10 trees before you get one you like, but it allows you to redo any phase, or start over, and its pretty fast.

Here is an oak tree I made in about 30 minutes (most of that time was remaking iterations of trees)

I’m not sure if any of this code would be useful, but maybe it is worth looking at. Sadly I can’t take credit for this amazing script, but maybe you can improve on it :smile:

32026--1170--$oak_609.jpg

Sounds a lot like the blender LSystem script I Have been using. All of my trees on the Unitrees page of the wiki are generated with it.

Yeah, i just substitute branches or whatever for leaves, and it does a great job of creating game ready trees.

Beats the heck out of hand placing leaves…

I just hate making branch textures that much that I find myself more willing to place leaves then make textures.

Carsten if you missed it…

http://forum.unity3d.com/viewtopic.php?t=4726

check out what polytropoi did with your script. cool stuff.

Thanks for the tip Pete. Yes cool little forest he made.

Here is the venerable L-System script (in a Blend file) to which Higgy and Yoggy and others have referred: http://greenpriest.com/lsystem.blend Brian, you might find this useful, if you ever find yourself w/out Maya at hand :slight_smile: But hopefully Carsten will adapt some of the techniques expand his awesome script: stem and branch curvature and spin, multipoint leaves, overall LOD, etc… It’s python, I think, but still.

I can’t wait to see how this thing evolves. The Unitree goals LOD and animation might be easier to accomplish using this script as a basis; i.e. gen multiple versions w/ different recursion values, and use culling or something to show the right one, depending on distance. I’m also wonder if there’s a way to use the techniques in the grass script w/ these procedural prefabs, to “paint” a distribution of them.

I think what this script needs most is a way to prevent me generating too many branches. A default override of some sort.

This is really good work btw.
AC