Modeling a tree, and (r)ambling through the woodsOctober 28th, 2007 by admin
After some fairly tedious work on my pine tree, I have something that doesn’t look half bad.
Unity’s restrictions for in-game trees require that each tree include a single mesh (for my non-gamer readers, a mesh is just a 3D object composed of triangles) using two textures: one for the bark and one for the foliage. Unfortunately, I didn’t know how to place two textures on a single mesh in Cheetah (my 3D modeling program). It is possible, and pretty easy to set up, but it took some time to figure it out.
Create the foliage
Armed with the requisite knowledge of Cheetah’s features, I set out in earnest to fill in my tree. The process I settled on ended up being fractal-ish in a way, which seems a fitting way to create a tree:
- First, I created a small group of six polygons that would act as a small branch and a group of pine needles.
- Then I duplicated this small branch 10 or 12 times along the bottom-most big branch on the tree. I scaled and rotated each copy so the foliage would feel random.
- Rather than repeat this process for each of the 20 or so branches, I just did it for the first three. This gave me three distinct sets of small branches (anybody confused yet?).
- Then I used those three branch sets to fill out the rest of the large branches, copying each set several times and moving/scaling it into position.
Remove (some of) the foliage
Another one of Unity’s guidelines for trees is to keep each one below 2,000 polygons. Alas, after my foliage frenzy, I was about 1K over the limit. Time to optimize. My first inclination was to remove some of the small branches that didn’t add much to the density of the foliage and wouldn’t be very visible from a distance. This activity, sad as it was to remove the pretty pine needles, didn’t get me far enough. How could I remove more polygons without thinning out my lush tree?
Finally it occurred to me that the branches near the top of my tree would never be seen up close. What’s more, the branch sets up there had been shrunk down to the point that the polygons wouldn’t be visible even if you were up close.
The solution, while probably obvious to you (if you’ve made it this far), seems poetic somehow. At the very top of the tree, the sets of branches aren’t much bigger than a single branch at the bottom of the tree, so I just removed four of the branch sets at the top and replaced them with single branches. The difference is nearly indistinguishable, and I eliminated several hundred polygons. Final polygon count: 1,970. Yeah, I’m kind of awesome.