private void Draw(SVGData svg) { DrawR(svg, A, D, B, R.x, true); DrawR(svg, B, A, C, R.y); DrawR(svg, C, B, D, R.z); DrawR(svg, D, C, A, R.w); }
private void Circle(SVGData svg, Vector2 c, float r) { for (var i = 0; i < 4; ++i) { var angle0 = Mathf.PI * 0.5f * (i + 0); var angle1 = Mathf.PI * 0.5f * (i + 1); var x0 = c.x + Mathf.Cos(angle0) * r; var y0 = c.y - Mathf.Sin(angle0) * r; var x1 = c.x + Mathf.Cos(angle1) * r; var y1 = c.y - Mathf.Sin(angle1) * r; var a = r * (4f / 3f) * Mathf.Tan((angle1 - angle0) / 4f); var inAngle = angle0 + Mathf.PI * 0.5f; var inX = x0 + Mathf.Cos(inAngle) * a; var inY = y0 - Mathf.Sin(inAngle) * a; var outAngle = angle1 - Mathf.PI * 0.5f; var outX = x1 + Mathf.Cos(outAngle) * a; var outY = y1 - Mathf.Sin(outAngle) * a; if (i == 0) { svg.Move(x0, y0); } svg.Curve(inX, inY, outX, outY, x1, y1); } }
public void GetContours(SVGData svg, List <List <Vector2> > data) { WorkBufferPool.Get(ref WorkVertices); var pen = Vector2.zero; var curves = svg.Curves; var l = curves.Count; for (var i = 0; i < l; ++i) { var curve = curves[i]; if (curve.IsMove) { EmitWorkVerticesIfNeeded(data); } else { FillBezier(pen, curve.InControl, curve.OutControl, curve.Position); } pen = curve.Position; } EmitWorkVerticesIfNeeded(data); WorkBufferPool.Release(ref WorkVertices); }
private void DrawLine(SVGData svg, Vector2 from, Vector2 to) { var r = 0.07f; var length = (to - from).magnitude; var angle = Mathf.Atan2(to.y - from.y, to.x - from.x); var matrix = new Matrix4x4(); matrix.SetTRS((Vector3)from, Quaternion.Euler(new Vector3(0f, 0f, angle * Mathf.Rad2Deg)), Vector3.one); var lineW = 1.7f; var interval = 0.2f; var s = 0f; for (;;) { var len = Mathf.Min(lineW, length - s); var a = new Vector2(s + len, r); var b = new Vector2(s, r); var c = new Vector2(s, -r); var d = new Vector2(s + len, -r); DrawR(svg, a, d, b, r, matrix, true); DrawR(svg, b, a, c, r, matrix); DrawR(svg, c, b, d, r, matrix); DrawR(svg, d, c, a, r, matrix); s += lineW + interval; if (s > length) { break; } } }
// Start is called before the first frame update void Start() { var mesh = GetComponent <SVGMesh>(); var svg = new SVGData(); svg.Path("M256.5,31.2L13.7,451.7h485.6L256.5,31.2z M232.9,180L336,410.7H129.8L232.9,180z"); mesh.Fill(svg); }
void Start() { HeadSVG = new SVGData(); TailSVG = new SVGData(); BodySVG = new SVGData(); Head = RandomField(); Tail = Head; }
public static void SvgPath(string svgPathString) { var origin = ApiManager.Instance.BrushPosition; SVGData svgData = new SVGData(); svgData.Path(svgPathString); SVGPolyline svgPolyline = new SVGPolyline(); svgPolyline.Fill(svgData); DrawStrokes.MultiPath2dToStrokes(svgPolyline.Polyline, origin, 0.01f, true); }
void Start() { SVG = new SVGData(); Mesh = GetComponent <SVGMesh>(); PrevA = A; PrevB = B; PrevC = C; PrevD = D; Render(); }
void Start() { Rects.Add(NewRect(r => { r.A = new Vector2(3f, 3f); r.B = new Vector2(-3f, 3f); r.C = new Vector2(-3f, -3f); r.D = new Vector2(3f, -3f); })); LineSVG = new SVGData(); }
// http://shspage.com/aijs/ private void Metaball(SVGData svg, Vector2 c1, float r1, Vector2 c2, float r2, float v) { if (r1 == 0f || r2 == 0f) { return; } var pi2 = Mathf.PI / 2f; var d = (c2 - c1).magnitude; var u1 = 0f; var u2 = 0f; if (d <= Mathf.Abs(r1 - r2)) { return; } else if (d < r1 + r2) { // case circles are overlapping u1 = Mathf.Acos((r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)); u2 = Mathf.Acos((r2 * r2 + d * d - r1 * r1) / (2 * r2 * d)); } var t1 = Mathf.Atan2(c2.y - c1.y, c2.x - c1.x); var t2 = Mathf.Acos((r1 - r2) / d); var t1a = t1 + u1 + (t2 - u1) * v; var t1b = t1 - u1 - (t2 - u1) * v; var t2a = t1 + Mathf.PI - u2 - (Mathf.PI - u2 - t2) * v; var t2b = t1 - Mathf.PI + u2 + (Mathf.PI - u2 - t2) * v; var p1a = PointOnCircle(c1, t1a, r1); var p1b = PointOnCircle(c1, t1b, r1); var p2a = PointOnCircle(c2, t2a, r2); var p2b = PointOnCircle(c2, t2b, r2); // define handle length by the distance between both ends of the curve to draw var handle_len_rate = 2; var d2 = Mathf.Min(v * handle_len_rate, (p2a - p1a).magnitude / (r1 + r2)); d2 *= Mathf.Min(1, d * 2 / (r1 + r2)); // case circles are overlapping r1 *= d2; r2 *= d2; svg.Move(p1a); svg.Curve(PointOnCircle(p1a, t1a - pi2, r1), PointOnCircle(p2a, t2a + pi2, r2), p2a); svg.Line(p2b); svg.Curve(PointOnCircle(p2b, t2b - pi2, r2), PointOnCircle(p1b, t1b + pi2, r1), p1b); svg.Line(p1a); }
public void GetContours() { var svg = new SVGData(); svg.Path(Fixtures.TwitterBirdPathCurve); var mesh = new MeshData(); BezierToVertex.Scale = 10f; BezierToVertex.GetContours(svg, mesh); Assert.That(mesh.Vertices, Is.EqualTo(Fixtures.TwitterBirdPathCurveVertices).Using(Vector3EqualityComparer.Instance)); Assert.That(mesh.Edges, Is.EqualTo(Fixtures.TwitterBirdPathCurveEdges)); }
internal void ParseSVGToPath(string urlToFile) { if (string.IsNullOrEmpty(urlToFile)) { return; } svgPaths.Clear(); svgClassesToShow.Clear(); svgParser parser = new svgParser(); SvgClass svg = parser.Parse(urlToFile); foreach (SvgPath svgPath in svg.SvgPath.Where(x => x.D.Length > 10)) { SVG = new SVGData(); SVG.Path(svgPath.D); Mesh.Fill(SVG); List <Coords> coordsForId = new List <Coords>(); float minX = Mesh.MeshData.Vertices.Min(x => x.x); float minY = Mesh.MeshData.Vertices.Min(y => y.y); float maxX = Mesh.MeshData.Vertices.Max(x => x.x); float maxY = Mesh.MeshData.Vertices.Max(y => y.y); float midX = (maxX - minX); float midY = (maxY - minY); for (int i = 0; i < Mesh.MeshData.Vertices.Count; i++) { Coords coord = new Coords { X = Mesh.MeshData.Vertices[i].x - midX, Y = Mesh.MeshData.Vertices[i].y - midY, Z = Mesh.MeshData.Vertices[i].z }; coordsForId.Add(coord); } if (svgPath.Class == null) { svgPath.Class = svgPath.Id; } else if (svgPath.Class.Length == 0) { svgPath.Class = svgPath.Id; } if (string.IsNullOrEmpty(svgPath.Class)) { svgPath.Class = (svgClassesToShow.Count + 1).ToString(); } CreateSVGClassObject(svgPath.Class); svgPaths.Add(svgPath.Class, coordsForId); svgClassesToShow.Add(svgPath.Class); } }
private void DrawR(SVGData svg, Vector2 p, Vector2 pPrev, Vector2 pNext, float r, Matrix4x4 matrix, bool first = false) { var angle0 = Mathf.Atan2(p.y - pNext.y, p.x - pNext.x); var angle1 = Mathf.Atan2(p.y - pPrev.y, p.x - pPrev.x); if (angle0 > angle1) { angle0 = angle0 - Mathf.PI * 2f; } var angleBetween = Mathf.Lerp(angle0, angle1, 0.5f); var cx = p.x - Mathf.Cos(angleBetween) * r * Mathf.Sqrt(2f); var cy = p.y - Mathf.Sin(angleBetween) * r * Mathf.Sqrt(2f); var x0 = cx + Mathf.Cos(angle0) * r; var y0 = cy + Mathf.Sin(angle0) * r; var x1 = cx + Mathf.Cos(angle1) * r; var y1 = cy + Mathf.Sin(angle1) * r; var a = r * (4f / 3f) * Mathf.Tan((angle1 - angle0) / 4f); var inAngle = angle0 + Mathf.PI * 0.5f; var inX = x0 + Mathf.Cos(inAngle) * a; var inY = y0 + Mathf.Sin(inAngle) * a; var outAngle = angle1 - Mathf.PI * 0.5f; var outX = x1 + Mathf.Cos(outAngle) * a; var outY = y1 + Mathf.Sin(outAngle) * a; var p0 = matrix.MultiplyPoint(new Vector3(x0, y0)); var p1 = matrix.MultiplyPoint(new Vector3(x1, y1)); var pIn = matrix.MultiplyPoint(new Vector3(inX, inY)); var pOut = matrix.MultiplyPoint(new Vector3(outX, outY)); if (first) { svg.Move(p0); } else { svg.Line(p0); } svg.Curve(pIn, pOut, p1); }
void Start() { SVG = new SVGData(); SVG.Path(SVG_PATH); // Debug.Log(SVG.Dump()); }
void Start() { SVG = new SVGData(); }
public static SVGData BuildWave(Rect bounds, float waveCenterY, float waveHorRadius, float waveVertRadius, float sideWidth) { var rect = bounds; var path = new SVGData(); var maskWidth = rect.width - sideWidth; path.Move(new Vector2(maskWidth - sideWidth, 0f - waveVertRadius * 2)); path.Line(new Vector2(0f, 0f - waveVertRadius * 2)); path.Line(new Vector2(0f, rect.height + waveVertRadius * 2)); path.Line(new Vector2(maskWidth, rect.height + waveVertRadius * 2)); var curveStartY = waveCenterY + waveVertRadius; path.Line(new Vector2(maskWidth, curveStartY)); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.1561501458f, curveStartY - waveVertRadius * 0.3322374268f), new Vector2(maskWidth, curveStartY - waveVertRadius * 0.1346194756f), new Vector2(maskWidth - waveHorRadius * 0.05341339583f, curveStartY - waveVertRadius * 0.2412779634f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.5012484792f, curveStartY - waveVertRadius * 0.5350576951f), new Vector2(maskWidth - waveHorRadius * 0.2361659167f, curveStartY - waveVertRadius * 0.4030805244f), new Vector2(maskWidth - waveHorRadius * 0.3305285625f, curveStartY - waveVertRadius * 0.4561193293f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.574934875f, curveStartY - waveVertRadius * 0.5689655122f), new Vector2(maskWidth - waveHorRadius * 0.515878125f, curveStartY - waveVertRadius * 0.5418222317f), new Vector2(maskWidth - waveHorRadius * 0.5664134792f, curveStartY - waveVertRadius * 0.5650349878f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.8774032292f, curveStartY - waveVertRadius * 0.7399037439f), new Vector2(maskWidth - waveHorRadius * 0.7283715208f, curveStartY - waveVertRadius * 0.6397387195f), new Vector2(maskWidth - waveHorRadius * 0.8086618958f, curveStartY - waveVertRadius * 0.6833456585f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius, curveStartY - waveVertRadius), new Vector2(maskWidth - waveHorRadius * 0.9653464583f, curveStartY - waveVertRadius * 0.8122605122f), new Vector2(maskWidth - waveHorRadius, curveStartY - waveVertRadius * 0.8936183659f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.8608411667f, curveStartY - waveVertRadius * 1.270484439f), new Vector2(maskWidth - waveHorRadius, curveStartY - waveVertRadius * 1.100142878f), new Vector2(maskWidth - waveHorRadius * 0.9595746667f, curveStartY - waveVertRadius * 1.1887991951f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.5291125625f, curveStartY - waveVertRadius * 1.4665102805f), new Vector2(maskWidth - waveHorRadius * 0.7852123333f, curveStartY - waveVertRadius * 1.3330544756f), new Vector2(maskWidth - waveHorRadius * 0.703382125f, curveStartY - waveVertRadius * 1.3795848049f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.5015305417f, curveStartY - waveVertRadius * 1.4802616098f), new Vector2(maskWidth - waveHorRadius * 0.5241858333f, curveStartY - waveVertRadius * 1.4689677195f), new Vector2(maskWidth - waveHorRadius * 0.505739125f, curveStartY - waveVertRadius * 1.4781625854f) ); path.CurveOther( new Vector2(maskWidth - waveHorRadius * 0.1541165417f, curveStartY - waveVertRadius * 1.687403f), new Vector2(maskWidth - waveHorRadius * 0.3187486042f, curveStartY - waveVertRadius * 1.5714239024f), new Vector2(maskWidth - waveHorRadius * 0.2332057083f, curveStartY - waveVertRadius * 1.6204116463f) ); path.CurveOther( new Vector2(maskWidth, curveStartY - waveVertRadius * 2f), new Vector2(maskWidth - waveHorRadius * 0.0509933125f, curveStartY - waveVertRadius * 1.774752061f), new Vector2(maskWidth, curveStartY - waveVertRadius * 1.8709256829f) ); path.Line(new Vector2(maskWidth, 0f - waveVertRadius * 2)); return(path); }
void Start() { Circle1SVG = new SVGData(); Circle2SVG = new SVGData(); MetaballSVG = new SVGData(); }