Ejemplo n.º 1
0
        void makeBranches()
        {
            float lenA  = INfiniDyForestC.lower_length_by * Instances.transform.localScale.y;
            float radiA = INfiniDyForestC.lower_radi_by * Instances.transform.localScale.x;

            int count_to = 1;

            if (Level == 0)
            {
                count_to = INfiniDyForestC.Height_levels;
            }
            Transform previous = TreeHolder.transform;

            for (int k = 0; k < count_to; k++)
            {
                //reduce radius by height
                if (!INfiniDyForestC.Use_height)
                {
                    Height_Level = k;
                }
                else
                {
                    if (Level == 0 & INfiniDyForestC.Height_levels > 1)
                    {
                        Height_Level = k;
                    }
                }


                float Radi_min = INfiniDyForestC.Min_Max_Radi.x;
                if (Height_Level > 0)
                {
                    Radi_min = Radi_min * (0.99f - (Height_Level * INfiniDyForestC.Height_reduce));
                }

                if (radiA < Radi_min)
                {
                }
                else
                {
                    if (Height_Level > 0)
                    {
                        lenA  = lenA * (0.99f - (Height_Level * INfiniDyForestC.Height_reduce));
                        radiA = radiA * (0.99f - (Height_Level * INfiniDyForestC.Height_reduce));
                    }

                    Branch_List = new List <INfiniDyGrass>();

                    GameObject Instance = new GameObject();

                    //parent to height segments if height > 0
                    if (!INfiniDyForestC.Decouple_from_bark)
                    {
                        if (Height_Level == 0)
                        {
                            Instance.transform.parent = previous;
                            previous = Instance.transform;
                        }
                        else
                        {
                            Instance.transform.parent = previous;
                            previous = Instance.transform;
                        }
                    }
                    else
                    {
                        Instance.transform.parent = previous;
                    }

                    Instance.transform.localPosition    = Vector3.zero;
                    Instance.transform.localEulerAngles = Vector3.zero;
                    Instance.name = "Node";

                    if (Height_Level > 0 & Level < 2)
                    {
                    }

                    Instance.transform.Translate(0, Instances.transform.localPosition.y * 2, 0);

                    //CHANGES - Added the below if
                    if (k > 0 & Level < 1)
                    {
                        Instance.transform.position = Instance.transform.position + (INfiniDyForestC.Height_offset * 1) + new Vector3(0, k * INfiniDyForestC.Height_separation, 0);
                    }

                    if (Height_Level > 0 & Level < 1)
                    {
                        Instance.transform.Rotate(INfiniDyForestC.Level1Decline * (Height_Level + 1), 0, INfiniDyForestC.Level1Decline * (Height_Level + 1));
                    }

                    int child_count = (int)(Random.Range(INfiniDyForestC.Min_Max_Branching.x, INfiniDyForestC.Min_Max_Branching.y) / (1));

                    //v1.2 - max branches per level
                    if (Level > 0 & INfiniDyForestC.Max_branches_per_level.Count >= Level)
                    {
                        child_count = (int)(Random.Range(INfiniDyForestC.Min_Max_Branching.x, INfiniDyForestC.Max_branches_per_level[Level - 1]) / (1));
                    }

                    for (int i = 0; i < child_count; i++)
                    {
                        INfiniDyGrass childTree = new INfiniDyGrass();
                        childTree.INfiniDyForestC = INfiniDyForestC;
                        Branch_List.Add(childTree);

                        if (INfiniDyForestOBJ != null)
                        {
                            childTree.INfiniDyForestC = INfiniDyForestOBJ.GetComponent(typeof(INfiniDyGrassField)) as INfiniDyGrassField;
                        }
                        childTree.Level        = Level + 1;
                        childTree.Height_Level = Height_Level;
                        childTree.generateTree(radiA, lenA, Color.blue, Vector3.zero + new Vector3(0, k * INfiniDyForestC.Height_separation, 0), Instance);
                    }


                    if (Level > INfiniDyForestC.Leaf_level_min_max.x & Level < INfiniDyForestC.Leaf_level_min_max.y & (!INfiniDyForestC.Use_height | (INfiniDyForestC.Use_height & Height_Level > INfiniDyForestC.Leaf_height_min_max.x & Height_Level < INfiniDyForestC.Leaf_height_min_max.y)))
                    {
                        for (int j = 0; j < INfiniDyForestC.Leaves_per_branch; j++)
                        {
                            INfiniDyForestC.Registered_Leaves.Add(Instance.transform.position + Instance.transform.up.normalized * INfiniDyForestC.Leaf_dist_factor * (j + 1) * Instance.transform.localScale.y);

                            INfiniDyForestC.Registered_Leaves_Rot.Add(Quaternion.Slerp(Instance.transform.rotation, Quaternion.AngleAxis(Random.Range(-270, 270), Instance.transform.right.normalized + new Vector3(Random.Range(-270, 270), Random.Range(-270, 270), Random.Range(-270, 270))), 0.5f));
                            INfiniDyForestC.Leaf_belongs_to_branch.Add(INfiniDyForestC.Registered_Brances.Count - 1);
                        }
                    }
                    if (Level > 1)
                    {
                    }

                    //CHANGES 1 (1 to 0 !!!!)
                    if (Level > 0)
                    {
                        Instances.transform.localScale = Instances.transform.localScale / INfiniDyForestC.Growth_start_div;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void makeBranches()
        {
            float lenA  = INfiniDyForestC.lower_length_by * Instances.transform.localScale.y;
            float radiA = INfiniDyForestC.lower_radi_by   * Instances.transform.localScale.x;

            int count_to=1;
            if(Level == 0){
                count_to = INfiniDyForestC.Height_levels;
            }
            Transform previous = TreeHolder.transform;
            for(int k=0;k<count_to;k++){

                //reduce radius by height
                if(!INfiniDyForestC.Use_height){
                    Height_Level = k;
                }else{
                    if(Level == 0 & INfiniDyForestC.Height_levels > 1){
                        Height_Level = k;
                    }
                }

                float Radi_min = INfiniDyForestC.Min_Max_Radi.x;
                if(Height_Level>0){
                    Radi_min = Radi_min *(0.99f-(Height_Level*INfiniDyForestC.Height_reduce));
                }

                if(radiA < Radi_min){

                }else{

                    if(Height_Level>0){
                        lenA  = lenA *(0.99f-(Height_Level*INfiniDyForestC.Height_reduce));
                        radiA = radiA*(0.99f-(Height_Level*INfiniDyForestC.Height_reduce));
                    }

                    Branch_List = new List<INfiniDyGrass>();

                    GameObject Instance = new GameObject();

                    //parent to height segments if height > 0
                    if(!INfiniDyForestC.Decouple_from_bark){
                        if(Height_Level == 0){
                            Instance.transform.parent = previous;
                            previous = Instance.transform;
                        }else{
                            Instance.transform.parent = previous;
                            previous = Instance.transform;
                        }
                    }else{
                        Instance.transform.parent = previous;
                    }

                    Instance.transform.localPosition = Vector3.zero;
                    Instance.transform.localEulerAngles= Vector3.zero;
                    Instance.name = "Node";

                    if(Height_Level > 0 & Level < 2){
                    }

                    Instance.transform.Translate(0,Instances.transform.localPosition.y*2,0);

                    //CHANGES - Added the below if
                    if(k > 0 & Level < 1){
                        Instance.transform.position = Instance.transform.position + (INfiniDyForestC.Height_offset*1) + new Vector3(0,k*INfiniDyForestC.Height_separation,0);
                    }

                    if(Height_Level > 0 & Level < 1){
                        Instance.transform.Rotate(INfiniDyForestC.Level1Decline*(Height_Level+1),0,INfiniDyForestC.Level1Decline*(Height_Level+1));
                    }

                    int child_count = (int)(Random.Range(INfiniDyForestC.Min_Max_Branching.x,INfiniDyForestC.Min_Max_Branching.y)/(1));

                    //v1.2 - max branches per level
                    if(Level > 0 & INfiniDyForestC.Max_branches_per_level.Count >= Level){
                        child_count = (int)(Random.Range(INfiniDyForestC.Min_Max_Branching.x,INfiniDyForestC.Max_branches_per_level[Level-1])/(1));
                    }

                    for(int i = 0; i < child_count; i++)
                    {
                        INfiniDyGrass childTree = new INfiniDyGrass();
                        childTree.INfiniDyForestC = INfiniDyForestC;
                        Branch_List.Add(childTree);

                        if(INfiniDyForestOBJ != null){
                            childTree.INfiniDyForestC = INfiniDyForestOBJ.GetComponent(typeof(INfiniDyGrassField)) as INfiniDyGrassField;
                        }
                        childTree.Level = Level+1;
                        childTree.Height_Level = Height_Level;
                        childTree.generateTree(radiA,lenA,Color.blue,Vector3.zero+new Vector3(0,k*INfiniDyForestC.Height_separation,0), Instance);
                    }

                    if(Level > INfiniDyForestC.Leaf_level_min_max.x & Level < INfiniDyForestC.Leaf_level_min_max.y &  (!INfiniDyForestC.Use_height | (INfiniDyForestC.Use_height & Height_Level > INfiniDyForestC.Leaf_height_min_max.x & Height_Level < INfiniDyForestC.Leaf_height_min_max.y))  ){
                        for (int j=0;j<INfiniDyForestC.Leaves_per_branch;j++){

                            INfiniDyForestC.Registered_Leaves.Add (Instance.transform.position + Instance.transform.up.normalized*INfiniDyForestC.Leaf_dist_factor*(j+1)*Instance.transform.localScale.y);

                            INfiniDyForestC.Registered_Leaves_Rot.Add(Quaternion.Slerp(Instance.transform.rotation, Quaternion.AngleAxis(Random.Range(-270,270),Instance.transform.right.normalized+new Vector3(Random.Range(-270,270),Random.Range(-270,270),Random.Range(-270,270))),0.5f));
                            INfiniDyForestC.Leaf_belongs_to_branch.Add(INfiniDyForestC.Registered_Brances.Count-1);
                        }
                    }
                    if(Level > 1){

                    }

                    //CHANGES 1 (1 to 0 !!!!)
                    if(Level > 0){
                        Instances.transform.localScale = Instances.transform.localScale/INfiniDyForestC.Growth_start_div;
                    }
                }
            }
        }