This is a project for the course A.I. for VideoGames at the University of Milan, A.Y. 2021/2022, M.Sc. in Computer Science. The aim of the project is to implement a Lindenmayer system for the procedural generation of trees using discrete distributions (pseudo-random integers) to enhance the believability of the project.
The Lindenmayer system was introduced and developed in 1968 (University of Utrecht) by Aristid Lindenmayer, a Hungarian theoretical biologist and botanist. A Lindenmayer system is a parallel rewriting system and a type of formal grammar. It is composed by :
- Axiom symbol, from which to begin the construction.
- Alphabet of symbols.
- Collection of production rules that expands each symbol into a larger one (rewriting system).
This kind of system was used by his creator to describe the behavior of plants and cells to model the growth processes of plan development. L-system can be used also to generate self-similar fractals, this is due to the structure of the rules that leads to self-similarity and thereby, fractal-like forms.
The development of the project was feasible thanks to the following tools :
- The project is developed on Unity 2019.4.13f1
- As a consequence, the language is C#
- Microsoft Visual C++ 2019
- Git and GitHub
- Overleaf (for the drafting report)
- ScreenToGif (gif files in
/gifs
)
For the external assets I have created a folder called Import, which is placed under
the directory Assets/Import
(it is ignored with his relative meta file).
- Hand Painted Grass Texture
- Bark Textures (PBR) - Volume One
- Leaf.png
- Hand Painted Seamless Wood Texture Vol - 6
Once the project is opened in Unity, you have to open the scene in Assets/Scenes/MainScene.unity
. After the scene is loaded you have just to click on "Origin" GameObject (in Hierarchy) to display the main settings available in the Inspector.
By pressing the Play button, you will be enabled to run the MainScene and move freely from a first-person point of view. You will be able to move your position as The in-game usable hotkeys are the following :
- The W, A, S, and D keys for stepping into the forward, left, right and backward directions.
- With CTRL you move upward (on the positive Z axis).
- With the space bar you move downward (on the negative Z axis).
- With SHIFT you can speed up the movement in the directions.
Once the application is started, it is possible to play with the Inspector to make changes occur on the running application (not all the fields are editable when the game is running). If any of the following three fields are changed, a tree regeneration is triggered.
The application produces always a random tree using pseudo-random numbers for the orientation of branches and roots. Both the angles and the directions of the branches are chosen randomly basing the decision on a user-defined random seed (so that it is possible to reproduce the same pseudo-random tree).
Currently, the inspector you see in the .gif files is outdated, there are some new functionalities that have been added, like :
- Random seed
- Roots sets
There are four predefined models (or sets) to use, they are editable only if the "Free Editing" flag is checked, otherwise they won't change (and will be restored to the precedent model/set whenever you click on something else).
- Now there are also two models for the roots.
The overall tree iterations (number of derivations) and segment lengths (both branches and roots) are editable through a slider that works on the discrete interval [1,6], for the iterations, and on the continuous interval [0.01,1.0] for the branch length.
Without checking this flag is not possible to make the "real-time" editing of the predefined set.
- Now there is also the possibility to free-style edit the root set.
In the Hierarchy panel, the items are organized in a tree structure way, where the origin contains the whole tree subdivided into two children between branches and roots. These two objects respectively contain all generated branches and roots as children, with the main difference given by the fact that some of the branches got leaves, and those are children of the terminal branches.
Bugs:
- Handle better the swap between the free edit and the predefined samples
Possible features:
- Add fruits
- New grammars
- Try with more than one rule
- Enables/disables the randomness.