public static Mesh CreateAntialiasing(List <List <Vector2> > inputShapes, Color colorA, float width, ClosePathRule closePath = ClosePathRule.NEVER)
        {
            if (inputShapes == null || inputShapes.Count == 0)
            {
                return(null);
            }

            Color colorB = new Color(colorA.r, colorA.g, colorA.b, 0f);

            if (inputShapes.Count > 1)
            {
                CombineInstance[] combineInstances = new CombineInstance[inputShapes.Count];
                for (int i = 0; i < inputShapes.Count; i++)
                {
                    combineInstances[i]      = new CombineInstance();
                    combineInstances[i].mesh = SVGMeshUtils.VectorLine(inputShapes[i].ToArray(), colorA, colorB, width, width * 0.5f, closePath);
                }

                Mesh mesh = new Mesh();
                mesh.CombineMeshes(combineInstances, true, false);
                return(mesh);
            }
            else
            {
                return(SVGMeshUtils.VectorLine(inputShapes[0].ToArray(), colorA, colorB, width, width * 0.5f, closePath));
            }
        }
        public static Mesh CreateStrokeSimple(List <List <Vector2> > inputShapes, SVGPaintable paintable, ClosePathRule closePath = ClosePathRule.NEVER)
        {
            if (inputShapes == null || inputShapes.Count == 0 || paintable == null || paintable.strokeWidth <= 0f)
            {
                return(null);
            }

            AddInputShape(inputShapes);

            Color color = GetStrokeColor(paintable);

            float strokeWidth = paintable.strokeWidth;

            if (inputShapes.Count > 1)
            {
                CombineInstance[] combineInstances = new CombineInstance[inputShapes.Count];
                for (int i = 0; i < inputShapes.Count; i++)
                {
                    combineInstances[i]      = new CombineInstance();
                    combineInstances[i].mesh = SVGMeshUtils.VectorLine(inputShapes[i].ToArray(), color, color, strokeWidth, 0f, closePath);
                }

                Mesh mesh = new Mesh();
                mesh.CombineMeshes(combineInstances, true, false);
                return(mesh);
            }
            else
            {
                return(SVGMeshUtils.VectorLine(inputShapes[0].ToArray(), color, color, strokeWidth, 0f, closePath));
            }
        }
Exemple #3
0
 /*
  * public static Mesh CreateAntialiasing(List<List<Vector2>> paths, Color color, float antialiasingWidth, bool isStroke = false, ClosePathRule closePath = ClosePathRule.NEVER)
  * {
  *  if(SVGAssetImport.antialiasingWidth <= 0f) return null;
  *  return SVGSimplePath.CreateAntialiasing(paths, color, antialiasingWidth, closePath);
  * }
  */
 private static void UpdateMesh(Mesh mesh, SVGFill svgFill)
 {
     if (svgFill.fillType == FILL_TYPE.GRADIENT && svgFill.gradientColors != null)
     {
         SVGMeshUtils.ChangeMeshUV2(mesh, new Vector2(svgFill.gradientColors.index, (int)svgFill.gradientType));
     }
     else
     {
         SVGMeshUtils.ChangeMeshColor(mesh, svgFill.color);
     }
 }
Exemple #4
0
    void OnDrawGizmos()
    {
        MeshFilter meshFilter = GetComponent <MeshFilter>();

        if (meshFilter != null && meshFilter.sharedMesh != null)
        {
            Matrix4x4 oldMatrix = Gizmos.matrix;
            Gizmos.matrix = transform.localToWorldMatrix;
            UnityEditor.Handles.matrix = transform.localToWorldMatrix;

            if (meshFilter != null && meshFilter.sharedMesh != null)
            {
                Mesh      sharedMesh = meshFilter.sharedMesh;
                Vector3[] vertices   = sharedMesh.vertices;
                int[]     triangles  = sharedMesh.triangles;

                /*
                 * Edge[] edges = SVGMeshUtils.BuildManifoldEdges(vertices, triangles);
                 *
                 * for(int i = 1; i < edges.Length; i++)
                 * {
                 *  Gizmos.DrawLine(vertices[edges[i].vertexIndex[0]],
                 *                  vertices[edges[i].vertexIndex[1]]);
                 *  UnityEditor.Handles.Label(vertices[edges[i].vertexIndex[0]], i.ToString());
                 * }
                 */

                List <int[]> paths = SVGMeshUtils.BuildManifoldPoints(vertices, triangles);
                for (int i = 0; i < paths.Count; i++)
                {
                    Vector3 lastPoint = vertices[paths[i][0]];
                    Vector3 currentPoint;
                    for (int j = 0; j < paths[i].Length; j++)
                    {
                        currentPoint = vertices[paths[i][j]];
                        Gizmos.DrawLine(lastPoint, currentPoint);
                        UnityEditor.Handles.Label(currentPoint, i.ToString() + "_" + j.ToString());
                        lastPoint = currentPoint;
                    }
                }
            }

            Gizmos.matrix = oldMatrix;
        }
    }
        public static void MeshSplit(SVGMesh mesh, Vector2 origin, Vector2 direction)
        {
            Mesh inputMesh = new Mesh();

            inputMesh.vertices  = mesh.vertices;
            inputMesh.triangles = mesh.triangles;
            inputMesh.colors32  = mesh.colors;
            inputMesh.uv        = (Vector2[])mesh.uvs;
            inputMesh.uv2       = (Vector2[])mesh.uvs2;

            MeshSplit(inputMesh, origin, direction);
            SVGMeshUtils.AutoWeldVertices(inputMesh, 0f);

            mesh.vertices  = inputMesh.vertices;
            mesh.triangles = inputMesh.triangles;
            mesh.colors    = inputMesh.colors32;
            mesh.uvs       = inputMesh.uv;
            mesh.uvs2      = inputMesh.uv2;
        }
Exemple #6
0
        public static bool CreateAntialiasing(List <List <Vector2> > inputShapes, out SVGShape svgShape, Color colorA, float width, ClosePathRule closePath = ClosePathRule.NEVER)
        {
            svgShape = new SVGShape();
            if (inputShapes == null || inputShapes.Count == 0)
            {
                return(false);
            }

            Color colorB = new Color(colorA.r, colorA.g, colorA.b, 0f);

            if (inputShapes.Count > 1)
            {
                List <SVGShape> shapes = new List <SVGShape>();
                SVGShape        currentLayer;
                for (int i = 0; i < inputShapes.Count; i++)
                {
                    if (SVGMeshUtils.VectorLine(inputShapes[i].ToArray(), out currentLayer, colorA, colorB, width, width * 0.5f, closePath))
                    {
                        shapes.Add(currentLayer);
                    }
                }
                if (shapes.Count > 0)
                {
                    svgShape = SVGShape.MergeShapes(shapes);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(SVGMeshUtils.VectorLine(inputShapes[0].ToArray(), out svgShape, colorA, colorB, width, width * 0.5f, closePath));
            }
        }
Exemple #7
0
        /*
         * public static Mesh CreateStrokeMesh(List<Vector2> inputShapes, SVGPaintable paintable, ClosePathRule closePath = ClosePathRule.NEVER)
         * {
         *  if(inputShapes == null || inputShapes.Count == 0 || paintable == null || paintable.strokeWidth <= 0f)
         *      return null;
         *
         *  return CreateStrokeMesh(new List<List<Vector2>>(){inputShapes}, paintable, closePath);
         * }
         *
         * public static Mesh CreateStrokeMesh(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.StrokeMesh(segments, paintable.strokeWidth, GetStrokeColor(paintable), GetStrokeLineJoin(paintable.strokeLineJoin), GetStrokeLineCap(paintable.strokeLineCap), paintable.miterLimit, paintable.dashArray, paintable.dashOffset, closePath, SVGGraphics.roundQuality);
         * }
         */
        /*
         * public static Mesh CreateStrokeSimple(SVGPaintable paintable, ClosePathRule closePath = ClosePathRule.NEVER)
         * {
         *  return CreateStrokeSimple(new List<List<Vector2>>(){new List<Vector2>(SVGGraphics.position_buffer.ToArray())}, paintable, closePath);
         * }
         */
        public static Mesh CreateStrokeSimple(List <List <Vector2> > inputShapes, SVGPaintable paintable, ClosePathRule closePath = ClosePathRule.NEVER)
        {
            if (inputShapes == null || inputShapes.Count == 0 || paintable == null || paintable.strokeWidth <= 0f)
            {
                return(null);
            }

            AddInputShape(inputShapes);

            Color color = GetStrokeColor(paintable);

            float strokeWidth = paintable.strokeWidth;

            if (inputShapes.Count > 1)
            {
                CombineInstance[] combineInstances = new CombineInstance[inputShapes.Count];
                for (int i = 0; i < inputShapes.Count; i++)
                {
                    combineInstances[i] = new CombineInstance();
                    SVGShape svgLayer = new SVGShape();
                    if (SVGMeshUtils.VectorLine(inputShapes[i].ToArray(), out svgLayer, color, color, strokeWidth, 0f, closePath))
                    {
                        Mesh      localMesh     = new Mesh();
                        int       totalVertices = svgLayer.vertices.Length;
                        Vector3[] vertices      = new Vector3[totalVertices];
                        for (int j = 0; j < totalVertices; j++)
                        {
                            vertices[j] = svgLayer.vertices[j];
                        }
                        localMesh.vertices       = vertices;
                        localMesh.triangles      = svgLayer.triangles;
                        localMesh.colors32       = svgLayer.colors;
                        combineInstances[i].mesh = localMesh;
                    }
                }

                Mesh mesh = new Mesh();
                mesh.CombineMeshes(combineInstances, true, false);
                return(mesh);
            }
            else
            {
                SVGShape svgLayer = new SVGShape();
                if (SVGMeshUtils.VectorLine(inputShapes[0].ToArray(), out svgLayer, color, color, strokeWidth, 0f, closePath))
                {
                    Mesh      localMesh     = new Mesh();
                    int       totalVertices = svgLayer.vertices.Length;
                    Vector3[] vertices      = new Vector3[totalVertices];
                    for (int j = 0; j < totalVertices; j++)
                    {
                        vertices[j] = svgLayer.vertices[j];
                    }
                    localMesh.vertices  = vertices;
                    localMesh.triangles = svgLayer.triangles;
                    localMesh.colors32  = svgLayer.colors;

                    return(localMesh);
                }
                return(null);
            }
        }
Exemple #8
0
        // Mesh has changed
        void InitMesh()
        {
//            Debug.Log("InitMesh");
            if (_vectorGraphics == null)
            {
                _lastVectorGraphics = null;
                Clear();
            }
            else
            {
                if (useLayers)
                {
                    _layers = _vectorGraphics.layersClone;

                    if (_mesh == null)
                    {
                        _mesh           = new Mesh();
                        _mesh.hideFlags = HideFlags.DontSave;
                    }
                    else
                    {
                        _mesh.Clear();
                    }

                    _mesh.name            = _vectorGraphics.name + " Instance " + _mesh.GetInstanceID();
                    meshFilter.sharedMesh = _mesh;
                }
                else
                {
                    CleanMesh();
                    if (_sharedMesh != _vectorGraphics.sharedMesh)
                    {
                        _sharedMesh = _vectorGraphics.sharedMesh;
                    }
                    if (useSharedMesh)
                    {
                        if (meshFilter.sharedMesh != _sharedMesh)
                        {
                            meshFilter.sharedMesh = _sharedMesh;
                        }
                    }
                    else
                    {
                        if (_mesh == null)
                        {
                            _mesh           = new Mesh();
                            _mesh.hideFlags = HideFlags.DontSave;
                        }
                        else
                        {
                            _mesh.Clear();
                        }

                        SVGMeshUtils.Fill(_vectorGraphics.sharedMesh, _mesh);
                        _mesh.name += " Instance " + _mesh.GetInstanceID();
                        if (meshFilter.sharedMesh != _mesh)
                        {
                            meshFilter.sharedMesh = _mesh;
                        }
                    }
                }
            }
        }