Example #1
0
        public static YulanTree Create(Transform parent, Vector3 start, int intensity, float length, float angle, int smoothstep, Transform cam, Vector3 sun, float sunIntensity, Sprite leaf)
        {
            GameObject o = new GameObject("YulanTree");

            o.transform.SetParent(parent, false);

            YulanTree yulan = o.AddComponent <YulanTree>();

            yulan.intensity = intensity;
            yulan.length    = length;
            yulan.angle     = angle;

            yulan.sun          = sun;
            yulan.sunIntensity = sunIntensity;

            yulan.transform.SetParent(parent, false);
            yulan.smoothstep = smoothstep;

            yulan.root = Branch.Create(yulan, parent.transform.up, length, angle, cam.right);
            yulan.leaf = leaf;

            yulan.branches.Add(yulan.root);

            yulan.top = start;

            return(yulan);
        }
Example #2
0
        // trunk
        public static Branch Create(YulanTree tree, Vector3 direction, float length, float angle, Vector3 normal)
        {
            GameObject o = new GameObject("0_root");
            Branch     b = o.AddComponent <Branch>();

            o.transform.SetParent(tree.transform, false);

            b.level  = 0;
            b.parent = null;
            b.child  = new List <Branch>();
            b.sprig  = new List <Branch>();
            b.leaf   = new List <LeafBud>();
            b.pos    = tree.transform.position;
            b.dir    = direction;
            b.length = length;
            b.tree   = tree;
            b.angle  = angle;
            b.color  = Color.white;
            b.weight = 1;
            b.normal = normal;

            if (b.tree.sunIntensity > 0)
            {
                b.weight *= (0.5f + Mathf.Pow(Mathf.Cos(Vector3.Angle(b.dir, b.tree.sun * (-1f)) / 2.0f * Mathf.PI / 180.0f), b.tree.sunIntensity));
            }
            o.transform.position = b.pos;
            o.transform.LookAt(b.pos + b.dir);

            b.smoothsteps = new Vector3[b.tree.smoothstep + 1];
            b.smoothsteps = b.CalcSmoothStep(ref b.smoothsteps, Vector3.forward, b.normal, 1);



            return(b);
        }
Example #3
0
        public void Generate()
        {
            if (tree != null)
            {
                Destroy(tree.gameObject);
            }

            tree = YulanTree.Create(this.transform, Vector3.zero, this.intensity, this.length, this.angle, 7, this.cam.transform, this.sun.forward, this.sunIntensity, this.leaf);

            tree.MakeTree(this.child, this.sprig);


            tree.Shaking(wind, 0.5f, 50f);

            Debug.Log("cam.right:" + this.cam.transform.right);
        }