Exemple #1
0
    void Start()
    {
        meshGenerator = new MeshGenerator();
        //Randomize generation numbers
        maxGenerations = Random.Range(2, maxGenerations + 1);

        // Look up so we rotate the tree structure
        transform.Rotate(Vector3.right * -90.0f);
        // Rules can be applied in an inspector, once game is started all information is
        // taken from an editor
        if (ruleChars != null)
        {
            ruleset = new Rule[ruleChars.Length];
            for (int i = 0; i < ruleChars.Length; i++)
            {
                ruleset[i] = new Rule(ruleChars[i], ruleStrings[i]);
            }
        }
        // Create the L-System and a new Turtle
        lsystem = new LSystem(axiom, ruleset);
        turtle  = new Turtle(width, treeRoundness, lsystem.GetAlphabet(),
                             length, turn, pitch, roll, gameObject, widthRatio, lengthRatio);

        // Generate the alphabet n(generations) times
        for (int i = 0; i < maxGenerations; i++)
        {
            lsystem.Generate();
        }
        // Save current transform position & rotation
        Vector3    currentP = transform.position;
        Quaternion currentR = transform.rotation;

        // Generate the alphabet & pass it to the turtle
        turtle.SetAlphabet(lsystem.GetAlphabet());
        turtle.GenerateSkeleton();

        transform.position = currentP;
        transform.rotation = currentR;

        // Get vector arrays & render the tree
        GetTreeBranches();
        DestroyTree();
        RenderTree();
        if (hasLeaves)
        {
            MakeLeaves();
        }
    }