GetRadiusAtTime() public method

public GetRadiusAtTime ( TreeNode node, float t, bool includeModifications ) : float
node TreeNode
t float
includeModifications bool
return float
Beispiel #1
0
        //
        // Computes the surface angle deviation, from the splines orientation.. Funky stuff!
        // ! In degrees !
        public float GetSurfaceAngleAtTime(float time)
        {
            if (spline == null)
            {
                return(0.0f);
            }
            float angle = 0.0f;

            Vector3 pos0 = spline.GetPositionAtTime(time);
            float   rad0 = group.GetRadiusAtTime(this, time, false);

            if (time < 0.5f)
            {
                float difPos = (spline.GetPositionAtTime(time + 0.01f) - pos0).magnitude;
                float difRad = group.GetRadiusAtTime(this, time + 0.01f, false) - rad0;
                angle = Mathf.Atan2(difRad, difPos);
            }
            else
            {
                float disPos = (pos0 - spline.GetPositionAtTime(time - 0.01f)).magnitude;
                float difRad = rad0 - group.GetRadiusAtTime(this, time - 0.01f, false);
                angle = Mathf.Atan2(difRad, disPos);
            }

            return(angle * Mathf.Rad2Deg);
        }
Beispiel #2
0
        public static List <float> GetAdaptiveSamples(TreeGroup group, TreeNode node, float adaptiveQuality)
        {
            List <float> list = new List <float>();

            if (node.spline == null)
            {
                return(list);
            }
            float num = 1f - node.capRange;

            SplineNode[] array = node.spline.GetNodes();
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].time >= node.breakOffset)
                {
                    list.Add(node.breakOffset);
                    break;
                }
                if (array[i].time > num)
                {
                    list.Add(num);
                    break;
                }
                list.Add(array[i].time);
            }
            list.Sort();
            if (list.Count < 2)
            {
                return(list);
            }
            float num2 = 1f;

            if (group.GetType() == typeof(TreeGroupBranch))
            {
                num2 = ((TreeGroupBranch)group).radius;
            }
            float num3 = Mathf.Lerp(0.999f, 0.99999f, adaptiveQuality);
            float num4 = Mathf.Lerp(0.5f, 0.985f, adaptiveQuality);
            float num5 = Mathf.Lerp(0.3f * num2, 0.1f * num2, adaptiveQuality);
            int   num6 = 200;
            int   j    = 0;

            while (j < list.Count - 1)
            {
                for (int k = j; k < list.Count - 1; k++)
                {
                    Quaternion rotationAtTime  = node.spline.GetRotationAtTime(list[k]);
                    Quaternion rotationAtTime2 = node.spline.GetRotationAtTime(list[k + 1]);
                    Vector3    lhs             = rotationAtTime * Vector3.up;
                    Vector3    rhs             = rotationAtTime2 * Vector3.up;
                    Vector3    lhs2            = rotationAtTime * Vector3.right;
                    Vector3    rhs2            = rotationAtTime2 * Vector3.right;
                    Vector3    lhs3            = rotationAtTime * Vector3.forward;
                    Vector3    rhs3            = rotationAtTime2 * Vector3.forward;
                    float      radiusAtTime    = group.GetRadiusAtTime(node, list[k], true);
                    float      radiusAtTime2   = group.GetRadiusAtTime(node, list[k + 1], true);
                    bool       flag            = false;
                    if (Vector3.Dot(lhs, rhs) < num4)
                    {
                        flag = true;
                    }
                    if (Vector3.Dot(lhs2, rhs2) < num4)
                    {
                        flag = true;
                    }
                    if (Vector3.Dot(lhs3, rhs3) < num4)
                    {
                        flag = true;
                    }
                    if (Mathf.Abs(radiusAtTime - radiusAtTime2) > num5)
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        num6--;
                        if (num6 > 0)
                        {
                            float item = (list[k] + list[k + 1]) * 0.5f;
                            list.Insert(k + 1, item);
                            break;
                        }
                    }
                    j = k + 1;
                }
            }
            for (int l = 0; l < list.Count - 2; l++)
            {
                Vector3 positionAtTime  = node.spline.GetPositionAtTime(list[l]);
                Vector3 positionAtTime2 = node.spline.GetPositionAtTime(list[l + 1]);
                Vector3 positionAtTime3 = node.spline.GetPositionAtTime(list[l + 2]);
                float   radiusAtTime3   = group.GetRadiusAtTime(node, list[l], true);
                float   radiusAtTime4   = group.GetRadiusAtTime(node, list[l + 1], true);
                float   radiusAtTime5   = group.GetRadiusAtTime(node, list[l + 2], true);
                Vector3 normalized      = (positionAtTime2 - positionAtTime).normalized;
                Vector3 normalized2     = (positionAtTime3 - positionAtTime).normalized;
                bool    flag2           = false;
                if (Vector3.Dot(normalized, normalized2) >= num3)
                {
                    flag2 = true;
                }
                if (Mathf.Abs(radiusAtTime3 - radiusAtTime4) > num5)
                {
                    flag2 = false;
                }
                if (Mathf.Abs(radiusAtTime4 - radiusAtTime5) > num5)
                {
                    flag2 = false;
                }
                if (flag2)
                {
                    list.RemoveAt(l + 1);
                    l--;
                }
            }
            if (node.capRange > 0f)
            {
                int num7 = 1 + Mathf.CeilToInt(node.capRange * 16f * adaptiveQuality);
                for (int m = 0; m < num7; m++)
                {
                    float f    = (float)(m + 1) / (float)num7 * 3.14159274f * 0.5f;
                    float num8 = Mathf.Sin(f);
                    float num9 = num + node.capRange * num8;
                    if (num9 < node.breakOffset)
                    {
                        list.Add(num9);
                    }
                }
                list.Sort();
            }
            if (1f <= node.breakOffset)
            {
                if (list[list.Count - 1] < 1f)
                {
                    list.Add(1f);
                }
                else
                {
                    list[list.Count - 1] = 1f;
                }
            }
            return(list);
        }
Beispiel #3
0
		public static List<float> GetAdaptiveSamples(TreeGroup group, TreeNode node, float adaptiveQuality)
		{
			List<float> list = new List<float>();
			if (node.spline == null)
			{
				return list;
			}
			float num = 1f - node.capRange;
			SplineNode[] array = node.spline.GetNodes();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].time >= node.breakOffset)
				{
					list.Add(node.breakOffset);
					break;
				}
				if (array[i].time > num)
				{
					list.Add(num);
					break;
				}
				list.Add(array[i].time);
			}
			list.Sort();
			if (list.Count < 2)
			{
				return list;
			}
			float num2 = 1f;
			if (group.GetType() == typeof(TreeGroupBranch))
			{
				num2 = ((TreeGroupBranch)group).radius;
			}
			float num3 = Mathf.Lerp(0.999f, 0.99999f, adaptiveQuality);
			float num4 = Mathf.Lerp(0.5f, 0.985f, adaptiveQuality);
			float num5 = Mathf.Lerp(0.3f * num2, 0.1f * num2, adaptiveQuality);
			int num6 = 200;
			int j = 0;
			while (j < list.Count - 1)
			{
				for (int k = j; k < list.Count - 1; k++)
				{
					Quaternion rotationAtTime = node.spline.GetRotationAtTime(list[k]);
					Quaternion rotationAtTime2 = node.spline.GetRotationAtTime(list[k + 1]);
					Vector3 lhs = rotationAtTime * Vector3.up;
					Vector3 rhs = rotationAtTime2 * Vector3.up;
					Vector3 lhs2 = rotationAtTime * Vector3.right;
					Vector3 rhs2 = rotationAtTime2 * Vector3.right;
					Vector3 lhs3 = rotationAtTime * Vector3.forward;
					Vector3 rhs3 = rotationAtTime2 * Vector3.forward;
					float radiusAtTime = group.GetRadiusAtTime(node, list[k], true);
					float radiusAtTime2 = group.GetRadiusAtTime(node, list[k + 1], true);
					bool flag = false;
					if (Vector3.Dot(lhs, rhs) < num4)
					{
						flag = true;
					}
					if (Vector3.Dot(lhs2, rhs2) < num4)
					{
						flag = true;
					}
					if (Vector3.Dot(lhs3, rhs3) < num4)
					{
						flag = true;
					}
					if (Mathf.Abs(radiusAtTime - radiusAtTime2) > num5)
					{
						flag = true;
					}
					if (flag)
					{
						num6--;
						if (num6 > 0)
						{
							float item = (list[k] + list[k + 1]) * 0.5f;
							list.Insert(k + 1, item);
							break;
						}
					}
					j = k + 1;
				}
			}
			for (int l = 0; l < list.Count - 2; l++)
			{
				Vector3 positionAtTime = node.spline.GetPositionAtTime(list[l]);
				Vector3 positionAtTime2 = node.spline.GetPositionAtTime(list[l + 1]);
				Vector3 positionAtTime3 = node.spline.GetPositionAtTime(list[l + 2]);
				float radiusAtTime3 = group.GetRadiusAtTime(node, list[l], true);
				float radiusAtTime4 = group.GetRadiusAtTime(node, list[l + 1], true);
				float radiusAtTime5 = group.GetRadiusAtTime(node, list[l + 2], true);
				Vector3 normalized = (positionAtTime2 - positionAtTime).normalized;
				Vector3 normalized2 = (positionAtTime3 - positionAtTime).normalized;
				bool flag2 = false;
				if (Vector3.Dot(normalized, normalized2) >= num3)
				{
					flag2 = true;
				}
				if (Mathf.Abs(radiusAtTime3 - radiusAtTime4) > num5)
				{
					flag2 = false;
				}
				if (Mathf.Abs(radiusAtTime4 - radiusAtTime5) > num5)
				{
					flag2 = false;
				}
				if (flag2)
				{
					list.RemoveAt(l + 1);
					l--;
				}
			}
			if (node.capRange > 0f)
			{
				int num7 = 1 + Mathf.CeilToInt(node.capRange * 16f * adaptiveQuality);
				for (int m = 0; m < num7; m++)
				{
					float f = (float)(m + 1) / (float)num7 * 3.14159274f * 0.5f;
					float num8 = Mathf.Sin(f);
					float num9 = num + node.capRange * num8;
					if (num9 < node.breakOffset)
					{
						list.Add(num9);
					}
				}
				list.Sort();
			}
			if (1f <= node.breakOffset)
			{
				if (list[list.Count - 1] < 1f)
				{
					list.Add(1f);
				}
				else
				{
					list[list.Count - 1] = 1f;
				}
			}
			return list;
		}
Beispiel #4
0
 public static List<float> GetAdaptiveSamples(TreeGroup group, TreeNode node, float adaptiveQuality)
 {
     List<float> list = new List<float>();
     if (node.spline != null)
     {
         float item = 1f - node.capRange;
         SplineNode[] nodes = node.spline.GetNodes();
         for (int i = 0; i < nodes.Length; i++)
         {
             if (nodes[i].time >= node.breakOffset)
             {
                 list.Add(node.breakOffset);
                 break;
             }
             if (nodes[i].time > item)
             {
                 list.Add(item);
                 break;
             }
             list.Add(nodes[i].time);
         }
         list.Sort();
         if (list.Count < 2)
         {
             return list;
         }
         float radius = 1f;
         if (group.GetType() == typeof(TreeGroupBranch))
         {
             radius = ((TreeGroupBranch) group).radius;
         }
         float num4 = Mathf.Lerp(0.999f, 0.99999f, adaptiveQuality);
         float num5 = Mathf.Lerp(0.5f, 0.985f, adaptiveQuality);
         float num6 = Mathf.Lerp(0.3f * radius, 0.1f * radius, adaptiveQuality);
         int num7 = 200;
         int num8 = 0;
         while (num8 < (list.Count - 1))
         {
             for (int k = num8; k < (list.Count - 1); k++)
             {
                 Quaternion rotationAtTime = node.spline.GetRotationAtTime(list[k]);
                 Quaternion quaternion2 = node.spline.GetRotationAtTime(list[k + 1]);
                 Vector3 lhs = (Vector3) (rotationAtTime * Vector3.up);
                 Vector3 rhs = (Vector3) (quaternion2 * Vector3.up);
                 Vector3 vector3 = (Vector3) (rotationAtTime * Vector3.right);
                 Vector3 vector4 = (Vector3) (quaternion2 * Vector3.right);
                 Vector3 vector5 = (Vector3) (rotationAtTime * Vector3.forward);
                 Vector3 vector6 = (Vector3) (quaternion2 * Vector3.forward);
                 float num10 = group.GetRadiusAtTime(node, list[k], true);
                 float num11 = group.GetRadiusAtTime(node, list[k + 1], true);
                 bool flag = false;
                 if (Vector3.Dot(lhs, rhs) < num5)
                 {
                     flag = true;
                 }
                 if (Vector3.Dot(vector3, vector4) < num5)
                 {
                     flag = true;
                 }
                 if (Vector3.Dot(vector5, vector6) < num5)
                 {
                     flag = true;
                 }
                 if (Mathf.Abs((float) (num10 - num11)) > num6)
                 {
                     flag = true;
                 }
                 if (flag)
                 {
                     num7--;
                     if (num7 > 0)
                     {
                         float num12 = (list[k] + list[k + 1]) * 0.5f;
                         list.Insert(k + 1, num12);
                         continue;
                     }
                 }
                 num8 = k + 1;
             }
         }
         for (int j = 0; j < (list.Count - 2); j++)
         {
             Vector3 positionAtTime = node.spline.GetPositionAtTime(list[j]);
             Vector3 vector8 = node.spline.GetPositionAtTime(list[j + 1]);
             Vector3 vector9 = node.spline.GetPositionAtTime(list[j + 2]);
             float num14 = group.GetRadiusAtTime(node, list[j], true);
             float num15 = group.GetRadiusAtTime(node, list[j + 1], true);
             float num16 = group.GetRadiusAtTime(node, list[j + 2], true);
             Vector3 vector12 = vector8 - positionAtTime;
             Vector3 normalized = vector12.normalized;
             Vector3 vector13 = vector9 - positionAtTime;
             Vector3 vector11 = vector13.normalized;
             bool flag2 = false;
             if (Vector3.Dot(normalized, vector11) >= num4)
             {
                 flag2 = true;
             }
             if (Mathf.Abs((float) (num14 - num15)) > num6)
             {
                 flag2 = false;
             }
             if (Mathf.Abs((float) (num15 - num16)) > num6)
             {
                 flag2 = false;
             }
             if (flag2)
             {
                 list.RemoveAt(j + 1);
                 j--;
             }
         }
         if (node.capRange > 0f)
         {
             int num17 = 1 + Mathf.CeilToInt((node.capRange * 16f) * adaptiveQuality);
             for (int m = 0; m < num17; m++)
             {
                 float f = ((((float) (m + 1)) / ((float) num17)) * 3.141593f) * 0.5f;
                 float num20 = Mathf.Sin(f);
                 float num21 = item + (node.capRange * num20);
                 if (num21 < node.breakOffset)
                 {
                     list.Add(num21);
                 }
             }
             list.Sort();
         }
         if (1f <= node.breakOffset)
         {
             if (list[list.Count - 1] < 1f)
             {
                 list.Add(1f);
                 return list;
             }
             list[list.Count - 1] = 1f;
         }
     }
     return list;
 }