protected override void BuildMeshComponents() { Vector2 center = MeshHelper.GetCenter(SplinePoints); for (int i = 0; i < SplinePoints.Length; i++) { SplinePoints[i] -= center; } var points = CatmullRomSpline.GetPoints(MeshHelper.ConvertVec2ToVec3(SplinePoints), Resolution); if (MinArea.HasValue) { points = SplineSimplification.Simplify(points, MinArea.Value, true, false); } Vertices = points.ToArray(); var connections = Triangulation.TriangulationToInt3(new List <Vector2>(MeshHelper.ConvertVec3ToVec2(Vertices))); Triangles = new int[connections.Count * 3]; for (int i = 0; i < connections.Count; i++) { Triangles[i * 3 + 0] = connections[i].A; Triangles[i * 3 + 1] = connections[i].B; Triangles[i * 3 + 2] = connections[i].C; } UVs = MeshHelper.UVUnwrap(Vertices); }
protected override void BuildMeshComponents() { var points = CatmullRomSpline.GetPoints(MeshHelper.ConvertVec2ToVec3(SplinePoints), Resolution); if (MinArea.HasValue) { points = SplineSimplification.Simplify(points, MinArea.Value, true, false); } Vertices = points.ToArray(); CenterShift = MeshHelper.GetCenter(Vertices); for (int i = 0; i < Vertices.Length; i++) { Vertices[i] -= CenterShift; } Triangles = new int[Vertices.Length * 3]; for (int i = 0; i < Vertices.Length; i++) { Triangles[i * 3 + 0] = 0; Triangles[i * 3 + 1] = i; Triangles[i * 3 + 2] = (i + 1) % Vertices.Length; } UVs = MeshHelper.UVUnwrap(Vertices); }
public override void UpdateCollider() { if (UseDoubleCollider) { C_PC2D.points = MeshHelper.ConvertVec3ToVec2(Vertices); } else { C_EC2D.points = CatmullRomSpline.GetPoints(SplinePoints, Resolution, false).ToArray(); } }
protected override void BuildMeshComponents() { List <Vector2> curvePoints = CatmullRomSpline.GetPoints(SplinePoints, Resolution, false); if (MinArea.HasValue) { curvePoints = SplineSimplification.Simplify(curvePoints, MinArea.Value, true, false); } int len = curvePoints.Count; if (len <= 1) { return; } List <Vector2> leftCurvePoints = new List <Vector2>(); List <Vector2> rightCurvePoints = new List <Vector2>(); // first vertex { Vector2 dir = (curvePoints[1] - curvePoints[0]).normalized; dir = new Vector2(-dir.y, dir.x) * Width; leftCurvePoints.Add(curvePoints[0] - dir); rightCurvePoints.Add(curvePoints[0] + dir); } // second to last - 1 vertices for (int i = 1; i < len - 1; i++) { float leftAngle = Mathf.Atan2(curvePoints[i].y - curvePoints[i - 1].y, curvePoints[i].x - curvePoints[i - 1].x) * Mathf.Rad2Deg + 90; float rightAngle = Mathf.Atan2(curvePoints[i + 1].y - curvePoints[i].y, curvePoints[i + 1].x - curvePoints[i].x) * Mathf.Rad2Deg + 90; float middleAngle = leftAngle + Mathf.DeltaAngle(leftAngle, rightAngle) * 0.5f; Vector2 dir = new Vector2(Mathf.Cos(middleAngle * Mathf.Deg2Rad), Mathf.Sin(middleAngle * Mathf.Deg2Rad)) * Width; leftCurvePoints.Add(curvePoints[i] - dir); rightCurvePoints.Add(curvePoints[i] + dir); } // last vertex { Vector2 dir = (curvePoints[len - 2] - curvePoints[len - 1]).normalized; dir = new Vector2(-dir.y, dir.x) * Width; leftCurvePoints.Add(curvePoints[len - 1] + dir); rightCurvePoints.Add(curvePoints[len - 1] - dir); } Vertices = new Vector3[leftCurvePoints.Count * 2]; for (int i = 0; i < leftCurvePoints.Count; i++) { Vertices[i * 2] = leftCurvePoints[i]; Vertices[i * 2 + 1] = rightCurvePoints[i]; } Triangles = new int[(leftCurvePoints.Count - 1) * 6]; // number of quads * 6 int triangleIndex = 0; for (int i = 0; i < leftCurvePoints.Count - 1; i++) { int ii = i * 2; Triangles[triangleIndex++] = ii; Triangles[triangleIndex++] = ii + 1; Triangles[triangleIndex++] = ii + 3; Triangles[triangleIndex++] = ii; Triangles[triangleIndex++] = ii + 3; Triangles[triangleIndex++] = ii + 2; } }