/// <summary> /// Create the vertices of hose mesh. /// </summary> /// <param name="curve"></param> /// <param name="segments"></param> /// <param name="differ"></param> /// <param name="isSeal">Is seal at both ends of hose?</param> /// <returns>Vertices array.</returns> protected Vector3[] CreateVertices(IMonoCurve curve, int segments, float differ, bool isSeal = false) { var vertices = new List <Vector3>(); for (int i = 0; i < segments - 1; i++) { var len = differ * i; var node = curve.LocalEvaluate(len); var tangent = (curve.LocalEvaluate(len + differ) - node); vertices.AddRange(MeshBuildUtility.BuildPolygonVertices(polygon, radius, node, Quaternion.LookRotation(tangent))); } var lastNode = curve.LocalEvaluate(curve.Length); var lastTangent = (lastNode - curve.LocalEvaluate(curve.Length - differ)); vertices.AddRange(MeshBuildUtility.BuildPolygonVertices(polygon, radius, lastNode, Quaternion.LookRotation(lastTangent))); if (isSeal) { var polygonVertices = polygon + 1; vertices.Add(curve.LocalEvaluate(0)); vertices.AddRange(vertices.GetRange(0, polygonVertices)); var lastPolygonStart = polygonVertices * (segments - 1); vertices.Add(lastNode); vertices.AddRange(vertices.GetRange(lastPolygonStart, polygonVertices)); } return(vertices.ToArray()); }
/// <summary> /// Rebuild renderer base curve. /// </summary> /// <param name="curve"></param> public override void Rebuild(IMonoCurve curve) { if (curve == null || curve.Length == 0) { Segments = 0; lineRenderer.SetVertexCount(0); return; } Segments = MonoCurveUtility.GetSegmentCount(curve, segment, out float differ) + 1; lineRenderer.SetVertexCount(Segments); for (int i = 0; i < Segments; i++) { lineRenderer.SetPosition(i, curve.LocalEvaluate(i * differ)); } }