Home

Awesome

L-Systems in Unity

L-System is a rewriting system used mainly to model the development of plants. L-Systems in Unity enables you to rapidly create plants in your Unity games.


Getting Started

Add LSystemExecutor to a game object in your scene. Set a L-System definition (e.g., "Assets/Defs/3D Tree 1.txt") and rendering properties. Start the game.

	// 3D Tree 1.txt

	axiom=F
	angle=22.5
	number of derivations=3

	F=(1)F[-&^F][^++&F]||F[--&^F][+&F]

LSystemExecutor in object inspector

3D tree


Advanced Usage

L-System processing is divided into three phases: parsing, derivation and interpretation. L-System on Unity's API map each phase to a static class.


Parsing

Method:

LSystemParser.Parse()

Input:

Output:

Example:

	string axiom;
	float angle;
	int derivations;
	Dictionary<string, List<Production>> productions;
	LSystemParser.Parse(
			file.text,
			out axiom,
			out angle,
			out derivations,
			out productions);

Derivation

Method:

LSystemDeriver.Derive()

Input:

Output:

Example:

	string moduleString;
	LSystemDeriver.Derive(
			axiom,
			angle,
			derivations,
			rules,
			out moduleString);

Interpretation

Method:

LSystemInterpreter.Interpret()

Input:

Output:

Example:

	GameObject leaves, trunk;
	LSystemInterpreter.Interpret(
			segmentAxialSamples,
			segmentRadialSamples,
			segmentWidth,
			segmentHeight,
			leafSize,
			leafAxialDensity,
			leafRadialDensity,
			useFoliage,
			narrowBranches,
			leafMaterial,
			trunkMaterial,
			angle,
			moduleString,
			out leaves,
			out trunk);