I created this tool in summer 2020 with WebGL and Typescript. The goal was to create a fast, easy, and art-directable foliage generator. The demo can be found here.
L-Systems
To create the tree, I used L-Systems, a form of recursive language expansion. We draw the tree based on a string of characters, each of which is mapped to a specific drawing function. This string of characters is expanded recursively from an initial axiom, based on a set of predefined expansion rules. I explored L-Systems previously in my Ink Minecraft project, where I created rivers and trees in the context of a 3D Array of blocks. Here, I had much more freedom in terms of geometry and functionality, as I could use meshes and custom geometry as part of my drawing functions.
Geometry
Trunks and Stems
The trunk of the tree is composed of several cylindrical segments stacked together. In order to prevent discontinuities, I created a custom cylinder class that allows the user to specify the transformations of the two faces on the cylinder. This lets us align contiguous cylinder faces to prevent obvious breaks between geometry. The difference can be seen below, with the regular cylinders on the left and the new cylinders on the right:
The cylinder class also allows the user to specify the number of divisions within the cylinder, giving the user a way to control poly-count and levels of detail.
Leaves
Originally, I had modeled flowers to sprout on the trees. However, I soon realized that loading even simple models into the mesh resulted in high poly-counts after enough recursion. After doing some research into other foliage tools, I instead opted to create leaves by generating simple planes and applying an alpha mask to them with a leaf texture. This proved to be a much more simple and useful technique for realistic generation.
Parameters
The tool allows the user to specify a wide variety of parameters, such as recursion depth, tree height, rotational noise, and leaf size. I also plan on introducing more parameters as I update the textures and geometry to allow for greater amounts of artistic variation. Below are some examples of some tree variations and their respective parameters.