# LSystem Thingy

Hey all! Here’s a fiddle I did involving some light LSystem stuff.

http://www.steveswink.com/Unity/LSystemTest1.html

Would love feedback on how to further optimize. I’ve capped the number of trees you can make at 8 or so because the frame rate drops dramatically past that (you can adjust it in the project itself if you want.) Also, I’m just instantiating a bunch of objects and meshcombining them, which is dog slow. I’d like to build the mesh by hand, ideally with an adjustable number of segments per tree point (to make the branches adjustably round) but haven’t the time to really dig in on that at the moment. That said, any references/ideas would be most welcome. I am teh nub sauce at programming. I’m looking at you cblarsen!

53628–1943–\$lsystem1_137.zip (9.92 MB)

To be more specific, I have a ‘TreePoint’ class which stores a position, rotation, array of children, and parent (other tree points.) I’m trying to figure out how to create vertices encircling each TreePoint in my treeDraw array (also taking into account TreePoint.rotation so that they’re oriented properly) and then sew them together with triangles as the points get created.

Any references or insight here would be much appreciated :). I don’t quite understand how mesh.vertices, mesh.uv, and mesh.triangles are correlated. I fiddled with the procedural project a bit and created a growing mesh strip. I’m not quite sure how to sort out a rounded tree trunk though.

Thanks!

-Steve

This is really nice! I haven’t looked at the code, but I’ll take a look at it when I can

sweet - thanks for sharing ; )

Basically there are vertices, say N of them in total. Each vertex has a position, and optionally UV, color, normal and so on. So mesh.vertices[0] is the first vertex, mesh.normals[0] would be this vertex’ normal etc. So far all these arrays are the same size.

Finally there’s a mesh.triangles array, with three numbers for each triangle. Thus the size of this array should be always dividable by three. The three numbers in each triangle are: which vertices go into this triangle.

Now a picture is worth many more words than I’ve written so far… (hey, this does not even look too bad for programmer’s art :roll:)

Here’s one segment of a “cylinder”. Cylinder has 5 vertices in each ring, one segment is 10 vertices. One more ring would add only 5 vertices though, as it would connect to already existing ring. I wrote the triangle array, with colors indicating several triangles.

Of course there are many ways to write a triangle array, where the result would look exactly the same (I could have listed triangles in different order for example).

One note: in each triangle, the vertices have to be listed in consistent order. I always forget which one is correct, I think they should be listed clockwise when looking at the triangle “from front”. The picture uses clockwise order.

I made a proof of concept tree generator in Unity a while ago that does cylinders. Feel free to check it out: http://yogware.bluegillstudios.com/TreeTest.zip

That’s a fantastic description Aras, thanks so much! That makes perfect sense. I’ll build this out when I have time (teach all day on Fridays.) Awesome, thanks again!