public static List <List <Vector2> > GetClipPath(SVGMatrix matrix, SVGPolygonElement svgElement) { List <Vector2> path = GetPath(matrix, svgElement); if (path == null || path.Count == 0) { return(null); } List <List <Vector2> > clipPath = new List <List <Vector2> >(); if (svgElement.paintable.IsFill()) { clipPath.Add(path); } if (svgElement.paintable.IsStroke()) { List <StrokeSegment[]> segments = new List <StrokeSegment[]>() { SVGSimplePath.GetSegments(path) }; List <List <Vector2> > strokePath = SVGLineUtils.StrokeShape(segments, svgElement.paintable.strokeWidth, Color.black, SVGSimplePath.GetStrokeLineJoin(svgElement.paintable.strokeLineJoin), SVGSimplePath.GetStrokeLineCap(svgElement.paintable.strokeLineCap), svgElement.paintable.miterLimit, svgElement.paintable.dashArray, svgElement.paintable.dashOffset, ClosePathRule.ALWAYS, SVGGraphics.roundQuality); if (strokePath != null && strokePath.Count > 0) { clipPath.AddRange(strokePath); } } return(clipPath); }
static void CreateStroke(SVGRectElement svgElement) { string name = svgElement.attrList.GetValue("id"); if (string.IsNullOrEmpty(name)) { name = "Rectangle Stroke "; } List <List <Vector2> > stroke = SVGSimplePath.CreateStroke(SVGGraphics.position_buffer, svgElement.paintable, ClosePathRule.ALWAYS); if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0) { stroke = SVGGeom.ClipPolygon(stroke, svgElement.paintable.clipPathList); } Mesh antialiasingMesh; Mesh mesh = SVGLineUtils.TessellateStroke(stroke, SVGSimplePath.GetStrokeColor(svgElement.paintable), out antialiasingMesh); if (mesh == null) { return; } mesh.name = name; SVGGraphics.AddMesh(new SVGMesh(mesh, svgElement.paintable.svgFill, svgElement.paintable.opacity)); if (antialiasingMesh != null) { SVGFill svgFill = svgElement.paintable.svgFill.Clone(); svgFill.blend = FILL_BLEND.ALPHA_BLENDED; SVGGraphics.AddMesh(new SVGMesh(antialiasingMesh, svgFill, svgElement.paintable.opacity)); } }
public List <List <Vector2> > GetClipPath() { List <List <Vector2> > path = GetPath(); if (path == null || path.Count == 0 || path[0] == null || path[0].Count == 0) { return(null); } List <List <Vector2> > clipPath = new List <List <Vector2> >(); if (paintable.IsFill()) { clipPath.Add(path[0]); } if (paintable.IsStroke()) { List <StrokeSegment[]> segments = new List <StrokeSegment[]>() { SVGSimplePath.GetSegments(path[0]) }; List <List <Vector2> > strokePath = SVGLineUtils.StrokeShape(segments, paintable.strokeWidth, Color.black, SVGSimplePath.GetStrokeLineJoin(paintable.strokeLineJoin), SVGSimplePath.GetStrokeLineCap(paintable.strokeLineCap), paintable.miterLimit, paintable.dashArray, paintable.dashOffset, ClosePathRule.NEVER, SVGGraphics.roundQuality); if (strokePath != null && strokePath.Count > 0) { clipPath.AddRange(strokePath); } } return(clipPath); }
protected virtual void RenderStroke() { int pointsLength = points.Length; int pointsLengthMinusOne = pointsLength - 1; StrokeSegment[] segments = new StrokeSegment[pointsLengthMinusOne]; for (int i = 0; i < pointsLengthMinusOne; i++) { segments[i] = new StrokeSegment(points[i].GetPosition(), points[i + 1].GetPosition()); } meshFilter.sharedMesh = SVGLineUtils.StrokeMesh(segments, width, color, lineJoin, lineCap, mitterLimit, dashArray, dashOffset, closeLine, roundQuality); }
protected virtual void PrepareForRendering(Mesh sharedMesh, bool force) { if (sharedMesh == null) { return; } SVGPath[] shape = svgShape.shape; if (shape != null && shape.Length > 0) { int[][] submeshes = new int[sharedMesh.subMeshCount][]; int subMeshCount = sharedMesh.subMeshCount; int i, j; for (i = 0; i < subMeshCount; i++) { submeshes[i] = sharedMesh.GetTriangles(i); } Mesh[] meshes = new Mesh[shape.Length + 1]; for (i = 0; i < shape.Length; i++) { int pointsLength = shape[i].points.Length - 1; StrokeSegment[] segments = new StrokeSegment[pointsLength]; for (j = 0; j < pointsLength; j++) { segments[j] = new StrokeSegment(shape[i].points[j], shape[i].points[j + 1]); } meshes[i] = SVGLineUtils.StrokeMesh(segments, width, color, lineJoin, lineCap, mitterLimit, dashArray, dashOffset, closeLine, roundQuality); } CombineInstance[] combineInstances = new CombineInstance[meshes.Length]; for (i = 0; i < meshes.Length; i++) { combineInstances[i].mesh = meshes[i]; } sharedMesh.CombineMeshes(combineInstances, false, false); } }
public static List <List <Vector2> > CreateStroke(List <List <Vector2> > inputShapes, SVGPaintable paintable, ClosePathRule closePath = ClosePathRule.NEVER) { if (inputShapes == null || inputShapes.Count == 0 || paintable == null || paintable.strokeWidth <= 0f) { return(null); } List <StrokeSegment[]> segments = new List <StrokeSegment[]>(); for (int i = 0; i < inputShapes.Count; i++) { if (inputShapes[i] == null || inputShapes[i].Count < 2) { continue; } segments.Add(GetSegments(inputShapes[i])); } return(SVGLineUtils.StrokeShape(segments, paintable.strokeWidth, Color.black, GetStrokeLineJoin(paintable.strokeLineJoin), GetStrokeLineCap(paintable.strokeLineCap), paintable.miterLimit, paintable.dashArray, paintable.dashOffset, closePath, SVGGraphics.roundQuality)); }