/// <summary> /// Builds a mesh from a spline (2D), taking interpolated points based on curvation angle /// </summary> /// <param name="spline">the spline to use</param> /// <param name="ignoreAxis">the axis to ignore (0=x,1=y,2=z)</param> /// <param name="close">True to create a mesh with triangles, False to create a vertex line mesh</param> /// <param name="angleDiff">the curvation angle used to interpolate points</param> public static Mesh CreateSplineMesh(CurvySpline spline, int ignoreAxis, bool close, float angleDiff) { float tf = 0; int dir = 1; List <Vector3> verts = new List <Vector3>(); verts.Add(spline.Transform.worldToLocalMatrix.MultiplyPoint3x4(spline.Interpolate(0))); while (tf < 1) { verts.Add(spline.Transform.worldToLocalMatrix.MultiplyPoint3x4(spline.MoveByAngle(ref tf, ref dir, angleDiff, CurvyClamping.Clamp, 0.005f))); } return(buildSplineMesh(verts.ToArray(), ignoreAxis, !close)); }
/// <summary> /// Builds a mesh from a spline (2D), taking interpolated points based on curvation angle /// </summary> /// <param name="spline">the spline to use</param> /// <param name="ignoreAxis">the axis to ignore (0=x,1=y,2=z)</param> /// <param name="close">True to create a mesh with triangles, False to create a vertex line mesh</param> /// <param name="angleDiff">the curvation angle used to interpolate points</param> public static Mesh CreateSplineMesh(CurvySpline spline, int ignoreAxis, bool close, float angleDiff) { float tf = 0; int dir = 1; List<Vector3> verts = new List<Vector3>(); verts.Add(spline.Transform.worldToLocalMatrix.MultiplyPoint3x4(spline.Interpolate(0))); while (tf < 1) { verts.Add(spline.Transform.worldToLocalMatrix.MultiplyPoint3x4(spline.MoveByAngle(ref tf, ref dir, angleDiff, CurvyClamping.Clamp, 0.005f))); } return buildSplineMesh(verts.ToArray(), ignoreAxis, !close); }
void Prepare() { #if UNITY_EDITOR mPerfWatch.Reset(); mPerfWatch.Start(); #endif if (Spline && StartMesh && ExtrusionParameter > 0) { StartMeshInfo = new MeshInfo(StartMesh, true, false); if (EndMesh) { EndMeshInfo = new MeshInfo(EndMesh, false, true); } else { EndMeshInfo = new MeshInfo(StartMesh, false, true); } // Calculate Steps float tf = FromTF; mSegmentInfo.Clear(); FromTF = Mathf.Clamp01(FromTF); ToTF = Mathf.Max(FromTF, Mathf.Clamp01(ToTF)); Vector3 scale; if (FromTF != ToTF) { switch (Extrusion) { case MeshExtrusion.FixedF: while (tf < ToTF) { scale = getScale(tf); mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale)); tf += ExtrusionParameter; } break; case MeshExtrusion.FixedDistance: float d = Spline.TFToDistance(FromTF); tf = Spline.DistanceToTF(d); while (tf < ToTF) { scale = getScale(tf); mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, d, scale)); d += ExtrusionParameter; tf = Spline.DistanceToTF(d); } break; case MeshExtrusion.Adaptive: while (tf < ToTF) { scale = getScale(tf); mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale)); int dir = 1; Spline.MoveByAngle(ref tf, ref dir, ExtrusionParameter, CurvyClamping.Clamp, 0.001f); } break; } if (!Mathf.Approximately(tf, ToTF)) { tf = ToTF; } scale = getScale(tf); mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale)); } } #if UNITY_EDITOR mPerfWatch.Stop(); DebugPerfPrepare = mPerfWatch.ElapsedTicks / (double)System.TimeSpan.TicksPerMillisecond; mPerfWatch.Reset(); #endif }