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); }
#pragma warning disable 0672 #if !UNITY_2017_1_OR_NEWER protected override void OnPopulateMesh(Mesh m) { if (mPath == null) { m.Clear(); return; } WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1); foreach (UIVertex v in getVerices()) { mesh.AddVertex(v); } for (int i = 0; i < mPath.Length; i++) { int prev = i - 1; if (prev < 0) { prev = mPath.Length - 1; } mesh.AddTringle(prev, i, mPath.Length); } mesh.ApplyToMesh(m); }
public static void Generate3dMesh(WorldSpaceChartMesh mesh, float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth, float innerDepth) { float maxDepth = Mathf.Max(outerDepth, innerDepth); float bottom = maxDepth * 0.5f; float innerUp = bottom - innerDepth; float outerUp = bottom - outerDepth; //float halfDepth = maxDepth * 0.5f; float segmentAngle = angleSpan / segments; float currentAngle = startAngle; float segmenUv = 1f / segments; float currentUv = 0f; float cos = Mathf.Cos(currentAngle); float sin = Mathf.Sin(currentAngle); UIVertex innerV = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, innerUp), new Vector2(currentUv, 0f)); UIVertex outerV = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, outerUp), new Vector2(currentUv, 1f)); int currentInner = mesh.AddVertex(innerV); int currentOuter = mesh.AddVertex(outerV); int prevInnerVertex = mesh.AddVertex(innerV); int prevOuterVertex = mesh.AddVertex(outerV); int prevOpeningVertex = mesh.AddVertex(innerV); int prevClosingVertex = mesh.AddVertex(outerV); innerV.position.z = bottom; outerV.position.z = bottom; int currentInnerDeep = mesh.AddVertex(innerV); int currentOuterDeep = mesh.AddVertex(outerV); int prevInnerVertexDeep = mesh.AddVertex(innerV); int prevOuterVertexDeep = mesh.AddVertex(outerV); mesh.AddTringle(currentInner, currentOuter, currentOuterDeep); mesh.AddTringle(currentOuterDeep, currentInnerDeep, currentInner); int prevOpeningVertexDeep = mesh.AddVertex(innerV); int prevClosingVertexDeep = mesh.AddVertex(outerV); for (int i = 1; i <= segments; i++) { currentUv += segmenUv; currentAngle += segmentAngle; cos = Mathf.Cos(currentAngle); sin = Mathf.Sin(currentAngle); UIVertex innerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, innerUp), new Vector2(currentUv, 0f)); UIVertex outerVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, outerUp), new Vector2(currentUv, 1f)); int leftBottom = -1; int rightBottomAdded = -1; if (innerRadius > 0f) { rightBottomAdded = mesh.AddVertex(innerVertex); leftBottom = prevInnerVertex; } int leftTop = prevOuterVertex; int rightTop = mesh.AddVertex(outerVertex); int rightBottom = mesh.AddVertex(innerVertex); int rightTopAdded = mesh.AddVertex(outerVertex); innerVertex.position.z = bottom; outerVertex.position.z = bottom; int leftBottomDeep = -1; if (innerRadius > 0f) { leftBottomDeep = prevInnerVertexDeep; } int leftTopDeep = prevOuterVertexDeep; int rightTopDeep = mesh.AddVertex(outerVertex); int rightBottomDeep = mesh.AddVertex(innerVertex); int rightTopAddedDeep = mesh.AddVertex(outerVertex); mesh.AddTringle(rightBottom, rightTop, leftTop); mesh.AddTringle(leftTopDeep, rightTopDeep, rightBottomDeep); mesh.AddTringle(prevClosingVertexDeep, prevClosingVertex, rightTopAdded); mesh.AddTringle(rightTopAdded, rightTopAddedDeep, prevClosingVertexDeep); prevClosingVertex = rightTopAdded; prevClosingVertexDeep = rightTopAddedDeep; if (innerRadius > 0f) { int rightBottomAddedDeep = mesh.AddVertex(innerVertex); mesh.AddTringle(leftTop, leftBottom, rightBottom); mesh.AddTringle(rightBottomDeep, leftBottomDeep, leftTopDeep); mesh.AddTringle(rightBottomAdded, prevOpeningVertex, prevOpeningVertexDeep); mesh.AddTringle(prevOpeningVertexDeep, rightBottomAddedDeep, rightBottomAdded); prevOpeningVertexDeep = rightBottomAddedDeep; prevOpeningVertex = rightBottomAdded; } prevInnerVertex = rightBottom; prevOuterVertex = rightTop; prevInnerVertexDeep = rightBottomDeep; prevOuterVertexDeep = rightTopDeep; if (i == segments) { rightTopDeep = mesh.AddVertex(outerVertex); rightBottomDeep = mesh.AddVertex(innerVertex); innerVertex.position.z = innerUp; outerVertex.position.z = outerUp; rightTop = mesh.AddVertex(outerVertex); rightBottom = mesh.AddVertex(innerVertex); mesh.AddTringle(rightTopDeep, rightTop, rightBottom); mesh.AddTringle(rightBottom, rightBottomDeep, rightTopDeep); } } }