public Branch(Branch parent, int childcount, float weight) { this.parent = parent; this.level = parent.level + 1; this.child = new List <Branch>(); this.sprig = new List <Branch>(); this.angle = parent.angle; this.length = parent.length; this.tree = parent.tree; //this.color = parent.color; this.color = Color.white; this.smoothsteps = new Vector3[this.tree.smoothstep + 1]; this.pos = parent.pos + parent.dir; //this.dir = Quaternion.Euler(0.0f, 0.0f, (-1 * (angle / 2.0f) + (this.angle / (childcount - 1) * parent.child.Count))) * (parent.dir) * weight; this.dir = Quaternion.Euler(0.0f, 0.0f, (-1 * (angle / 2.0f))) * (parent.dir); this.dir = this.WorldDir(this, childcount); this.weight = weight; if (this.tree.sunIntensity > 0) { this.weight *= (0.5f + Mathf.Pow(Mathf.Cos(Vector3.Angle(this.dir, this.tree.sun * (-1f)) / 2.0f * Mathf.PI / 180.0f), this.tree.sunIntensity)); } this.dir = this.dir.normalized * this.length * this.weight; this.smoothsteps = CalcSmoothStep(ref this.smoothsteps, this.dir, this.parent.dir, 1); //this.dir = Quaternuion }
// trunk public Branch(YulanTree tree, Vector3 direction, float length, float angle, Vector3 normal) { this.level = 0; this.parent = null; this.child = new List <Branch>(); this.sprig = new List <Branch>(); this.pos = Vector3.zero; this.dir = direction; this.length = length; this.tree = tree; this.angle = angle; this.color = Color.white; this.weight = 1; this.smoothsteps = new Vector3[this.tree.smoothstep + 1]; this.smoothsteps = CalcSmoothStep(ref this.smoothsteps, this.dir, normal, 1); }
public void Generate() { tree = new YulanTree(this.transform, Vector3.zero, this.intensity, this.length, this.angle, 7, this.cam.transform, this.sun.forward, this.sunIntensity); tree.MakeTree(this.child, this.sprig); }