public static List <SplineVertexData> ToEvenSplinePointArray(Spline spline, int count) { count = Mathf.Max(count, 2); if (count == 2) { return(new List <SplineVertexData> { new SplineVertexData(spline.GetPoint(0f), spline.GetNormal(0f), spline.GetDirection(0)), new SplineVertexData(spline.GetPoint(1f), spline.GetNormal(1f), spline.GetDirection(1)) }); } return(SplineUtils.ToEvenSplinePointArray(spline, spline.GetLength() / (float)(count - 1))); }
public static List <Vector3> ToEvenPointArray(Spline spline, int count) { count = Mathf.Max(count, 2); if (count == 2) { return(new List <Vector3> { spline.GetPoint(0f), spline.GetPoint(1f) }); } return(SplineUtils.ToEvenPointArray(spline, spline.GetLength() / (float)(count - 1), false)); }
private void UpdateMesh() { List <SplineVertexData> List = SplineUtils.ToEvenSplinePointArray(this.Spline ? this.Spline : base.GetComponent <Spline>(), this.Segments + 1); List <Vector3> List2 = new List <Vector3>(); List <int> List3 = new List <int>(); new List <Vector3>(); for (int i = 0; i < List.Count; i++) { Vector3 Vector = Vector3.zero; if (this.Spline.Closed) { if (i == 0 || i == List.Count - 1) { Vector = this.Spline.GetDirection(0); } else if (i < List.Count - 1) { Vector += List[i + 1].point - List[i].point; } if (i > 0) { Vector += List[i].point - List[i - +1].point; } } Vector.Normalize(); Vector = Vector3.Cross(List[i].normal, Vector); Vector.Normalize(); bool Closed = this.Spline.Closed && i == List.Count - 1; if (!Closed) { List2.Add(base.transform.InverseTransformPoint(List[i].point + Vector * this.Width / 2f)); } if (i > 0) { if (Closed) { List3.Add(List2.Count - 2); List3.Add(List2.Count - 1); List3.Add(0); } } else { List3.Add(List2.Count - 3); List3.Add(List2.Count - 2); List3.Add(List2.Count - 1); } if (i > 0) { if (Closed) { List3.Add(List2.Count - 1); List3.Add(1); List3.Add(0); } } else { List3.Add(List2.Count - 1); List3.Add(List2.Count - 2); List3.Add(List2.Count - 3); } this.Mesh.SetVertices(List2); this.Mesh.SetTriangles(List3, 0); this.Mesh.RecalculateNormals(); if (this.InvertFaces) { for (int n = 0; n < this.Mesh.normals.Length; n++) { this.Mesh.normals[n] *= -1f; } } this.Mesh.RecalculateTangents(); this.Mesh.RecalculateBounds(); } }