public void Generate(Vector3[] path, float radius, float curve) { if (EnsureMeshFilter() == false) // No mesh filter attached { return; } mPath = path; mPathRect = new Rect(-radius, -radius, radius * 2f, radius * 2f); mCurve = curve; WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1); int origin = 0; foreach (UIVertex v in getVerices()) { origin = mesh.AddVertex(v); } for (int i = 0; i < mPath.Length; i++) { int prev = i - 1; if (prev < 0) { prev = mPath.Length - 1; } mesh.AddTringle(origin, i * Smoothing, prev * Smoothing); } for (int j = 1; j < Smoothing; j++) { int current = j; int prev = j - 1; for (int i = 0; i < mPath.Length; i++) { int prevI = i - 1; if (prevI < 0) { prevI = mPath.Length - 1; } int a = (i * Smoothing) + current; int b = (i * Smoothing) + prev; int c = (prevI * Smoothing) + current; int d = (prevI * Smoothing) + prev; mesh.AddTringle(c, b, a); mesh.AddTringle(b, c, d); } } Mesh newMesh = mesh.Generate(); newMesh.hideFlags = HideFlags.DontSave; newMesh.RecalculateNormals(); mFilter.sharedMesh = newMesh; ChartCommon.CleanMesh(newMesh, ref mCleanMesh); }
public void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth, float innerDepth) { WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1); float maxDepth = Mathf.Max(outerDepth, innerDepth); if (maxDepth <= 0f) { PieMesh.Generate2dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments); } else { PieMesh.Generate3dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments, outerDepth, innerDepth); } if (mCleanMesh != null) { mCleanMesh.Clear(); mesh.ApplyToMesh(mCleanMesh); MeshCollider collider = ChartCommon.EnsureComponent <MeshCollider>(gameObject); if (collider != null) { collider.sharedMesh = null; collider.sharedMesh = mCleanMesh; } } else { Mesh newMesh = mesh.Generate(); newMesh.hideFlags = HideFlags.DontSave; if (mFilter == null) { mFilter = GetComponent <MeshFilter>(); } mFilter.sharedMesh = newMesh; MeshCollider collider = ChartCommon.EnsureComponent <MeshCollider>(gameObject); if (collider != null) { collider.sharedMesh = newMesh; } ChartCommon.CleanMesh(newMesh, ref mCleanMesh); } }