/* * public static List<Vector2> QuadraticCurve(Vector2 p1, Vector2 p2, Vector2 p3) { * return new List<Vector2>(SVGBezier.AdaptiveCubicCurve(SVGGraphics.vpm, p1, p2, p2, p3)); * } */ public static List <Vector2> QuadraticCurve(Vector2 p1, Vector2 p2, Vector2 p3) { var cP2 = p1 + (2f / 3f) * (p2 - p1); var cP3 = p3 + (2f / 3f) * (p2 - p3); return(new List <Vector2>(SVGBezier.AdaptiveCubicCurve(SVGGraphics.vpm, p1, cP2, cP3, p3))); }
public static void Bezier(float precision, Vector2 start, Vector2 handle0, Vector2 handle1, Vector2 end, bool showIndexes = false) { List <Vector2> points; points = SVGBezier.AdaptiveCubicCurve(precision, start, handle0, handle1, end); int pointsCount = points.Count; if (pointsCount <= 1) { return; } Vector3 lastPoint = Vector2.zero, currentPoint = Vector2.zero; lastPoint = points[0]; for (int i = 1; i < pointsCount; i++) { currentPoint.x = points[i].x; currentPoint.y = points[i].y; Handles.DrawLine(currentPoint, lastPoint); lastPoint = currentPoint; if (showIndexes) { Handles.Label(currentPoint, " " + i.ToString()); } } }
public static List <Vector2> CubicCurve(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) { return(new List <Vector2>(SVGBezier.AdaptiveCubicCurve(SVGGraphics.vpm, p1, p2, p3, p4))); }
protected virtual void UpdateCollider() { if (svgRenderer == null) { svgRenderer = GetComponent <SVGRenderer>(); } if (polygonCollider2D == null) { polygonCollider2D = GetComponent <PolygonCollider2D>(); } if (svgRenderer.vectorGraphics == null || svgRenderer.vectorGraphics.colliderShape == null || svgRenderer.vectorGraphics.colliderShape.Length == 0) { polygonCollider2D.pathCount = 0; polygonCollider2D.points = null; } else { SVGPath[] colliderShape = svgRenderer.vectorGraphics.colliderShape; polygonCollider2D.pathCount = 0; if (_quality < 1f) { Bounds bounds = svgRenderer.vectorGraphics.bounds; float finQuality = _quality; if (finQuality < 0.001f) { finQuality = 0.001f; } precision = Mathf.Max(bounds.size.x, bounds.size.y) / finQuality; if (precision < 0.001f) { precision = 0.001f; } precision *= 0.05f; } List <Vector2[]> optimisedPaths = new List <Vector2[]>(); Vector2[] points; for (int i = 0; i < colliderShape.Length; i++) { if (_quality < 1f) { points = SVGBezier.Optimise(colliderShape[i].points, precision); } else { points = (Vector2[])colliderShape[i].points.Clone(); } //bool clockwiseWinding = SVGGeomUtils.IsWindingClockWise(points); if (_offset != 0f) { points = SVGGeomUtils.OffsetVerts(points, _offset); } if (points != null && points.Length > 2) { optimisedPaths.Add(points); } } if (optimisedPaths.Count > 0) { polygonCollider2D.pathCount = optimisedPaths.Count; for (int i = 0; i < optimisedPaths.Count; i++) { polygonCollider2D.SetPath(i, optimisedPaths[i]); } } } }