public static GameObject CreateMeshFromBezier(BezierCurve bezierCurve, Transform transform, MentalMath.AxisSpace space, bool debugMode = false) { if (bezierCurve == null || bezierCurve.Curve == null || bezierCurve.Curve.Count == 0) { return(null); } List <Vector3> list = new List <Vector3>(); int bezierPointCount = bezierCurve.bezierPointCount; for (int i = 1; i <= bezierPointCount; i++) { list.Add(bezierCurve.Curve.GetPoint((float)i / (float)bezierPointCount, true, Vector3.zero)); } if (list.Count <= 0) { return(null); } return(MeshTool.CreateMeshFromPolygon(list, transform, space, debugMode)); }
public static GameObject CreateMeshStrip(List <Vector3> vertices, Transform transform, bool debugMode = false) { MeshTool.MeshObject meshObject = MeshTool.InitTransformForMesh(transform); List <Vector2> list = new List <Vector2>(); for (int i = 0; i < vertices.Count; i++) { list.Add(new Vector2(vertices[i].x, vertices[i].y)); } List <int> list2 = new List <int>(); for (int j = 0; j < vertices.Count - 2; j++) { list2.Add(j); if (j % 2 == 0) { list2.Add(j + 2); list2.Add(j + 1); } else { list2.Add(j + 1); list2.Add(j + 2); } } if (!debugMode) { Mesh mesh = new Mesh(); mesh.name = transform.name; mesh.vertices = vertices.ToArray(); mesh.uv = list.ToArray(); mesh.triangles = list2.ToArray(); mesh.RecalculateNormals(); meshObject.mf.sharedMesh = mesh; } return(meshObject.parent); }
public void CreateMesh() { this.bezierCurve = base.GetComponent <BezierCurve>(); if (this.bezierCurve == null) { return; } if (this.polygon != null) { this.DeleteMesh(); } this.polygon = MeshTool.CreateMeshFromBezier(this.bezierCurve, base.transform, MentalMath.AxisSpace.XY, false); if (this.mainMaterial != null) { this.polygon.GetComponent <MeshRenderer>().sharedMaterial = this.mainMaterial; } if (this.secondMaterial != null) { GameObject gameObject = new GameObject("Border"); gameObject.transform.SetParent(this.polygon.transform); gameObject.transform.localPosition = Vector3.forward * 0.25f; gameObject.transform.localScale = Vector3.one; BezierCurve bezierCurve = gameObject.AddComponent <BezierCurve>(); bezierCurve.bezierPointCount = this.bezierCurve.bezierPointCount; bezierCurve.loop = this.bezierCurve.loop; bezierCurve.Curve = new Bezier(); for (int i = 0; i < this.bezierCurve.Curve.Count; i++) { BezierNode bezierNode = bezierCurve.Curve.AddNode(this.bezierCurve.Curve[i].Position, this.bezierCurve.Curve[i].ForwardTangent, this.bezierCurve.Curve[i].BackwardTangent); bezierNode.ForwardTangentType = this.bezierCurve.Curve[i].ForwardTangentType; bezierNode.BackwardTangentType = this.bezierCurve.Curve[i].BackwardTangentType; } this.borderPolygon = MeshTool.CreateMeshStripFromBezier(bezierCurve, gameObject.transform, MentalMath.AxisSpace.XY, this.borderWidth, false); this.borderPolygon.GetComponent <MeshRenderer>().sharedMaterial = this.secondMaterial; } }
public static GameObject CreateMeshFromPolygon(List <Vector3> vertices, Transform transform, MentalMath.AxisSpace space, bool debugMode = false) { MeshTool.MeshObject meshObject = MeshTool.InitTransformForMesh(transform); if (debugMode) { for (int i = 0; i < vertices.Count; i++) { } } List <Vector2> list = new List <Vector2>(); for (int j = 0; j < vertices.Count; j++) { list.Add(new Vector2(vertices[j].x, vertices[j].y)); } List <int> list2 = new List <int>(); bool[] array = new bool[vertices.Count]; for (int k = 0; k < array.Length; k++) { array[k] = true; } int num = 0; int num2 = 1; int num3 = 2; int l = vertices.Count; int num4 = l * 10; while (l > 0) { num4--; if (num4 < 0) { break; } bool flag = true; for (int m = 0; m < vertices.Count; m++) { if (num != m && num2 != m && num3 != m) { if (MentalMath.PointInTriangle(vertices[m], vertices[num], vertices[num2], vertices[num3], MentalMath.AxisSpace.XY)) { flag = false; break; } } } if (flag) { Vector3 a = vertices[num2] - vertices[num]; Vector3 tangent = a + (vertices[num3] - vertices[num2]); Vector3 counterClockwiseNormal = MentalMath.GetCounterClockwiseNormal(tangent, space); float num5 = Vector3.Angle(-a, counterClockwiseNormal); flag = (num5 > 90f); } if (!flag) { num = num2; num2 = num3; } else { if (debugMode) { Vector3 vector = transform.position + Vector3.up * 3f; } list2.Add(num); list2.Add(num2); list2.Add(num3); l--; if (l <= 2) { if (debugMode) { } break; } array[num2] = false; num2 = num3; } int num6 = num2; int num7 = vertices.Count; while (num2 == num3) { num7--; if (num7 < 0) { break; } num6++; if (num6 >= vertices.Count) { num6 = 0; } if (array[num6] && num != num6 && num2 != num6) { if (debugMode) { } num3 = num6; break; } } } if (!debugMode) { Mesh mesh = new Mesh(); mesh.name = transform.name; mesh.vertices = vertices.ToArray(); mesh.uv = list.ToArray(); mesh.triangles = list2.ToArray(); mesh.RecalculateNormals(); meshObject.mf.sharedMesh = mesh; } return(meshObject.parent); }