/// <summary> /// Builds a mesh from a spline's approximation points (2D) /// </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="msh"></param> public static Mesh CreateSplineMesh(CurvySpline spline, int ignoreAxis, bool close, Mesh msh = null) { Vector3[] verts = spline.GetApproximation(true); if (spline.Closed) { CurvySplineSegment.Resize(ref verts, verts.Length - 1); } return(buildSplineMesh(verts, ignoreAxis, !close, msh)); }
/// <summary> /// Internal, don't call directly /// </summary> public void _InitializeControlPoint() { //mNextControlPoint = NextControlPoint; mStepSize = 1f / Spline.Granularity; mControlPointIndex = Spline.ControlPoints.IndexOf(this); Approximation = new Vector3[0]; ApproximationDistances = new float[0]; ApproximationUp = new Vector3[0]; ApproximationT = new Vector3[0]; if (UserValues.Length != Spline.UserValueSize) { CurvySplineSegment.Resize(ref UserValues, Spline.UserValueSize); } }
public MeshInfo(Mesh mesh, bool calculateLoops, bool mirror) { if (mirror) { mesh = MirrorMesh(mesh); } Vector3[] vt = mesh.vertices; Vector2[] uv = mesh.uv; int[] tri = mesh.triangles; // Fill data arrays Vertices = new Vector3[vt.Length]; UVs = new Vector2[uv.Length]; Triangles = new int[tri.Length]; vt.CopyTo(Vertices, 0); uv.CopyTo(UVs, 0); tri.CopyTo(Triangles, 0); if (calculateLoops) { // Build Edge Loops EdgeLoops = MeshHelper.BuildEdgeLoops(MeshHelper.BuildManifoldEdges(mesh)); // Fill Outline Data EdgeVertices = new Vector3[vt.Length]; EdgeUV = new Vector2[uv.Length]; int minIndex = int.MaxValue; int vertsUsed = 0; foreach (EdgeLoop loop in EdgeLoops) { for (int vi = 0; vi < loop.vertexCount; vi++) { EdgeVertices[vertsUsed + vi] = vt[loop.vertexIndex[vi]]; EdgeUV[vertsUsed + vi] = uv[loop.vertexIndex[vi]]; minIndex = Mathf.Min(minIndex, loop.vertexIndex[vi]); } vertsUsed += loop.vertexCount; } // modify EdgeLoops' indices (we need to address changed indices by omitting non-outlined edges foreach (EdgeLoop loop in EdgeLoops) { loop.ShiftIndices(-minIndex); } CurvySplineSegment.Resize(ref EdgeVertices, vertsUsed); CurvySplineSegment.Resize(ref EdgeUV, vertsUsed); } }