Search Unity

Unity Vector Graphics Preview Package

Discussion in '2D Experimental Preview' started by rustum, May 4, 2018.

  1. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    There is no easy way to do this. The resulting asset won't necessarily have the same coordinates as the SVG file since some conversion may be done to fit in Unity's coordinate system.

    One way to do it is to try to test if the point is in one of the triangulated shapes. It was discussed in the past: https://forum.unity.com/threads/vector-graphics-preview-package.529845/page-13#post-4597357
     
    KTS95SL and PlanarBit like this.
  2. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    What's the current state of the package? It's around 3 years and it's still in preview. Seems like development on this is a little bit dead?
    Is any sort of animation supported yet? Can I create something like this health bar with the current state of the package?
    https://codepen.io/justinryder/pen/OwzBVG
     
    PlanarBit and JonPQ like this.
  3. KTS95SL

    KTS95SL

    Joined:
    Apr 30, 2020
    Posts:
    7
    Is that worked for you?
     
  4. KTS95SL

    KTS95SL

    Joined:
    Apr 30, 2020
    Posts:
    7
    I am using shapes like flower petals. Is that possible with shapes like flower petals as they don't have indices?
     
  5. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    95
    @mcoted3d I've noticed that TessellateScene() and VectorUtils.BuildSprite() take quite a while to build a sprite... sometimes over half a second for a largish .svg. even with a pre-filtered scene file to only generate sub nodes separately it still takes long enough for a noticeable pause or frame-rate hitch ... do you know if these functions can be threaded / run in the background please?
     
  6. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    95
    the shapes are all curves in svg, but when unity imports them, it converts them to triangle meshes, based on the import quality settings, it builds more or less dense triangle meshes.
     
    KTS95SL likes this.
  7. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    The tessellation methods are all static with no side effects, so it's safe to call them from a different thread. (Ideally we would use the job system for the tessellation, that's planned for the future).

    Once the scene is tessellated, you'll have to create the Sprite on the main thread though.
     
    JonPQ likes this.
  8. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    Development on this package has slowed as we are trying to consolidate all the vector graphics needs across Unity (especially regarding the UI Toolkit framework). We will be able to get out of preview once we are done with this refactoring. I can't provide an ETA unfortunately.

    We don't support CSS transitions or Javascript-style animations. But, the vector graphics API allows you to generate shapes dynamically by C# code, which would allow you to make something like the example you provided.
     
    stychu likes this.
  9. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    95
    Thank you !
     
  10. kulnor

    kulnor

    Joined:
    May 23, 2016
    Posts:
    7
    Used the Vector Graphics 2.0.0-preview.14 in a project a little while ago and noticed it is no longer available under preview. Was planning to publish assets leveraging it, but may not be a safe thing to do. What is the current and future state of the project? This is a great package with tremendous potential!
     
  11. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    It is available, but the Package Manager window doesn't show preview packages by default anymore. You can change that in the Project Settings. See this thread for details:
    https://forum.unity.com/threads/visibility-changes-for-preview-packages-in-2020-1.910880/

    Even though the package has been stable for a while, we are not yet ready to remove the preview tag. Some changes to the package might be necessary to improve the compatibility of the vector graphics package with the other tools provided by Unity (in particular, UI Toolkit has heavy requirements regarding vector graphics).
     
    Skjalg and PlanarBit like this.
  12. kulnor

    kulnor

    Joined:
    May 23, 2016
    Posts:
    7
    Thanks for the feedback. So looks I can generally assume the project will continue to me further developer and maintained for the foreseeable future? This is a very useful package, will do what I can to contribute.
     
  13. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    Yes, our plan is to bring the package to verified status later.
     
    Noisecrime and JonPQ like this.
  14. xqtr123

    xqtr123

    Joined:
    Jun 7, 2014
    Posts:
    20
    Hi!
    I want to be able to change target resolution based on which device is used but can't find an example. How do you change the target resolution in runtime?
     
  15. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    95
    You can load the SVG file via script... then have your own quality settings exposed in inspector variables, or in a scriptable object.
    the main trick was to rename the .svg file, as .bytes instead. Then you can load it as a text/data file

    define a TextAsset variable, assign your .bytes file to that,
    then load it using something like this...

    Code (CSharp):
    1.     private SVGParser.SceneInfo loadSVG()
    2.     {
    3.         using (var reader = new StringReader(TextAssetToLoad.text))
    4.         {
    5.             return SVGParser.ImportSVG(reader);
    6.         }
    7.     }
    That gives you a sceneInfo object...

    You can use VectorUtils to setup your custom settings....
    var geometry = VectorUtils.TessellationOptions tess = new VectorUtils.TessellationOptions();

    then Tesselate the scene and build your sprite or texture...
    VectorUtils.TessellateScene(scene, tess);

    var sprite = VectorUtils.BuildSprite(geometry, .......)
     
  16. SimplyVideoJordan

    SimplyVideoJordan

    Joined:
    Mar 25, 2021
    Posts:
    1
    Thought I would share some small, probably unconventional feedback.

    Firstly, thanks for making this amazing package. Works straight out the box like magic.

    Literally my only problem with it (unfortunately) is that because it's a preview package, depending on it in any production-ready asset/plugin (such as the one my company is about to release) means transitively our asset is a preview "package," which gives the extended impression what we're delivering is something that is in alpha/beta and/or could potentially have major faults you would associate with said beta product. And all we're doing is using this one package so we can use svg icons, a super small, basic use case. As a result, we've basically had to batch convert all svgs to pngs and re-import icons across the project before we could release it.

    So that's just a very small feedback. Super appreciative of the work over the years though, brilliant stuff. But I thought I would just mention just in case it's one of the types of user outcomes at the moment you're not aware of. Just because of the preview packages in use warning, it will potentially limit the amount of users you have testing and feeding back on this (despite just how stable this package appears to be in certain use cases).

    Cheers,
     
    Last edited: Mar 25, 2021
  17. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    We completely understand. Hopefully the package will be out of preview soon, but we have some major refactor to do first, most of them related to antialiasing and UI Toolkit integration. Once this is done and we've made a few iterations with our users, we will be in good shape to get out of preview. I can't provide and ETA unfortunately.

    Thanks for the feedback!
     
    SimplyVideoJordan likes this.
  18. Schodemeiss

    Schodemeiss

    Joined:
    Jan 4, 2018
    Posts:
    43
    Where do I post a bug for this package? It has a hidden dependency on "com.unity.modules.unitywebrequestwww". It trips up if you have that modules disabled in your project.
     
  19. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    Hello, you can file a regular bug (Help > Report a Bug...), thank you!
     
    Schodemeiss likes this.
  20. Schodemeiss

    Schodemeiss

    Joined:
    Jan 4, 2018
    Posts:
    43
    No problem, have done exactly that. I don't think it's an urgent issue, but it's nice to make sure our dependency tree's are accurate - especially in what I imagine will be quite a popular package.
     
    mcoted3d likes this.
  21. JiriAtanasovsky

    JiriAtanasovsky

    Joined:
    Jan 18, 2021
    Posts:
    7
    Hello,

    first thank you for this excellent package.

    Is it possible to use imported svg as sprite with Sprite Shape Profile? When I tried, I got error...
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.U2D.SpriteShapeGenerator.TransferSprites (Unity.Collections.NativeArray`1[UnityEngine.U2D.SpriteShapeGenerator+JobSpriteInfo]& spriteInfos, UnityEngine.Sprite[] sprites, System.Int32 maxCount) (at Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Runtime/SpriteShapeGenerator.cs:580)
    3. UnityEngine.U2D.SpriteShapeGenerator.PrepareSprites (UnityEngine.Sprite[] edgeSprites, UnityEngine.Sprite[] cornerSprites) (at Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Runtime/SpriteShapeGenerator.cs:599)
    4. UnityEngine.U2D.SpriteShapeGenerator.Prepare (UnityEngine.U2D.SpriteShapeController controller, UnityEngine.U2D.SpriteShapeParameters shapeParams, System.Int32 maxArrayCount, Unity.Collections.NativeArray`1[T] shapePoints, Unity.Collections.NativeArray`1[T] metaData, UnityEngine.U2D.AngleRangeInfo[] angleRanges, UnityEngine.Sprite[] segmentSprites, UnityEngine.Sprite[] cornerSprites, System.Boolean UseUTess) (at Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Runtime/SpriteShapeGenerator.cs:2484)
    5. UnityEngine.U2D.SpriteShapeController.ScheduleBake () (at Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Runtime/SpriteShapeController.cs:709)
    6. UnityEngine.U2D.SpriteShapeController.BakeMesh () (at Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Runtime/SpriteShapeController.cs:447)
    7. UnityEngine.U2D.SpriteShapeController.OnWillRenderObject () (at Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Runtime/SpriteShapeController.cs:416)
    8. UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal(RenderPipelineAsset, IntPtr, List`1, AtomicSafetyHandle)
     
  22. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    Hi!

    Quick question:

    I have a diamond sprite that I need to scale to say 50 to cover the screen. Using a texture it looks blurry on the edges.

    Screen Shot 2021-04-05 at 5.01.16 PM.png

    I decided to try and fix this with an svg. However, I am sure I am doing something wrong. It looks even worst.

    Screen Shot 2021-04-05 at 5.01.36 PM.png

    The only thing that makes it look better is making the texture size to around 2000.

    Screen Shot 2021-04-05 at 5.01.30 PM.png

    Screen Shot 2021-04-05 at 5.01.26 PM.png

    Is setting the texture size to 2000 the way to go? I feel like this would be bad for performance? Is there a setting I am missing so that no matter the scale, the svg will look good?

    Or am I completely off base and that isn't how svgs work?

    Thanks!
     
  23. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    I'm pretty sure SpriteShapes requires texture sprites to work with. I don't think SVG assets imported as "Vector Sprite" will work, but you may have some luck if you import them as "Textured Sprites".
     
  24. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    From your import settings, I see that you imported your SVG as a "Textured Sprite", this essentially converts to the SVG to a texture, which won't solve your issue.

    Try to import your SVG as a "Vector Sprite" instead, which will give you a sprite that can scale indefinitely. If you have aliasing issues, you'll have to turn on MSAA.
     
  25. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    That make sense, thanks!
     
  26. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    63
    How can I load svg into il2cpp runtime?
    when called, it throws an error VectorUtils.BuildSprite due to reflection


    Code (CSharp):
    1.    // The Sprite.Create(Rect, Vector2, float, Texture2D) method is internal. Using reflection
    2.             // until it becomes public.
    3.             var spriteCreateMethod = typeof(Sprite).GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic, Type.DefaultBinder, new Type[] { typeof(Rect), typeof(Vector2), typeof(float), typeof(Texture2D) }, null);
    4.             var sprite = spriteCreateMethod.Invoke(null, new object[] { rect, pivot, svgPixelsPerUnit, texture }) as Sprite;
     
  27. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    We'll have to move this method to another assembly that's whitelisted for internal access. Can you please file a bug (Help > Report a Bug...), we'll try to get that sorted promptly.
     
  28. StephenW

    StephenW

    Joined:
    Mar 29, 2016
    Posts:
    77
    I haven't had time to read all these pages yet, however, I loaded up unity 2020.3 and I can not long see the Vector Graphics preview package, even after I tick the box to display previews.
    The manual also shows it is not anywhere to be found in Unity 2020
    https://docs.unity3d.com/2020.1/Documentation/Manual/pack-preview.html

    I did have a 2019 project which I updated to 2020 and it took the package with it, but it's nowhere to be found if I start a new 2020 project.

    Any ideas?

    Thanks
     
  29. XxTorionxX

    XxTorionxX

    Joined:
    Feb 6, 2020
    Posts:
    1
    This Package Isn't Supported In Unity 2020.1.x And Above! Will We See Support In The Future (Because I Have A Game That Uses SVG File's & Once 2019.4 LTS End's, I'm Probably Gonna Have To Convert Them All To PNG's And It Won't Look Good!)
     
  30. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    There were changes in the visibility of packages. This package won't show in the Package Manager Window because it is considered "experimental". It is still supported, and you can install it by clicking the "+" sign and manually adding a git package with the name "com.unity.vectorgraphics".

    The package will be visible in the Package Manager Window once we commit to a pre-release version.

    https://forum.unity.com/threads/new-package-lifecycle-taking-effect-in-2021-1.1045201/
     
    StephenW likes this.
  31. StephenW

    StephenW

    Joined:
    Mar 29, 2016
    Posts:
    77
    Thanks very much for the info, it worked great.
     
  32. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    196
    Hi guys!
    @mcoted3d

    Ellipse (only) contour does transforming.
    Why?



    Code:
    Code (CSharp):
    1.  
    2. foreach (Shape s in pNode.Shapes)
    3. {
    4.     Scene scene = new Scene() {Root = pNode};
    5.     // mesh
    6.     List<VectorUtils.Geometry> gms = VectorUtils.TessellateScene(scene, tessOptions);
    7.     // outline
    8.     List<Vector2> contour = new List<Vector2>();
    9.     if (s.Contours != null && s.Contours.Length > 0)
    10.     {
    11.         BezierContour bezierContour = s.Contours[0];
    12.         IEnumerable<BezierSegment> segments =
    13.             VectorUtils.SegmentsInPath(bezierContour.Segments, bezierContour.Closed);
    14.    
    15.         foreach (BezierSegment pathSeg in segments)
    16.         {
    17.             int kSegmentSubdivisions = 8;
    18.             for (int i = 0; i < kSegmentSubdivisions; ++i)
    19.             {
    20.                 float t = (float) i / kSegmentSubdivisions;
    21.                 var p = VectorUtils.Eval(pathSeg, t);
    22.                 contour.Add(new Vector2(p.x, p.y));
    23.             }
    24.         }
    25.     }
    26. }
    27.  

    SVG:
    Code (Boo):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
    3. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    4. <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
    5.      viewBox="0 0 1024 768" enable-background="new 0 0 1024 768" xml:space="preserve">
    6.     <g>
    7.  
    8.         <ellipse transform="matrix(-0.985 -0.1725 0.1725 -0.985 851.6964 1205.0658)" fill="#3B1682" cx="478.2" cy="565.5" rx="10.6" ry="37.3"/>
    9.     </g>
    10. </svg>
    11.  
    Code (c#):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System.IO;
    6. using Unity.VectorGraphics;
    7.  
    8. public  class SVGImport : MonoBehaviour
    9. {
    10.     [SerializeField]
    11.     private TextAsset test;
    12.  
    13.     private void Start()
    14.     {
    15.         Load(test.text);
    16.     }
    17.  
    18.     void Load(string pData)
    19.     {
    20.         VectorUtils.TessellationOptions tessOptions = new VectorUtils.TessellationOptions()
    21.         {
    22.             StepDistance = 100f,
    23.             MaxCordDeviation = 0.5f,
    24.             MaxTanAngleDeviation = 0.15f,
    25.             SamplingStepSize = 0.15f
    26.         };
    27.  
    28.         // Dynamically import the SVG data, and tessellate the resulting vector scene.
    29.         SVGParser.SceneInfo sceneInfo = SVGParser.ImportSVG(new StringReader(pData));
    30.  
    31.         void FillFromGeometry(List<VectorUtils.Geometry> pGeometry, GameObject node, Rect bounds)
    32.         {
    33.             Mesh _mesh = new Mesh();
    34.             VectorUtils.FillMesh(_mesh, pGeometry, 100, true);
    35.  
    36.             Mesh mesh =  new Mesh();
    37.             mesh.vertices = _mesh.vertices;
    38.             mesh.triangles = _mesh.triangles;
    39.  
    40.             node.GetComponent<MeshFilter>().mesh = mesh;
    41.  
    42.         }
    43.  
    44.         void FillContour(List<Vector2> contour)
    45.         {
    46.             LineRenderer ren = GetComponent<LineRenderer>();
    47.             ren.positionCount = contour.Count;
    48.             for (int i = contour.Count - 1; i >= 0; i--)
    49.             {
    50.                 ren.SetPosition(i, contour[i] / 100f);
    51.             }
    52.         }
    53.  
    54.         void AddMi(SceneNode pNode)
    55.         {
    56.             if (pNode.Children != null)
    57.             {
    58.                 foreach (SceneNode node in pNode.Children)
    59.                 {
    60.                     AddMi(node);
    61.                 }
    62.             }
    63.  
    64.             if (pNode.Shapes != null)
    65.             {
    66.                 foreach (Shape s in pNode.Shapes)
    67.                 {
    68.                     Scene scene = new Scene() {Root = pNode};
    69.                     // mesh
    70.                     List<VectorUtils.Geometry> gms = VectorUtils.TessellateScene(scene, tessOptions);
    71.  
    72.                     // outline
    73.                     List<Vector2> contour = new List<Vector2>();
    74.                     if (s.Contours != null && s.Contours.Length > 0)
    75.                     {
    76.                         BezierContour bezierContour = s.Contours[0];
    77.                         IEnumerable<BezierSegment> segments =
    78.                             VectorUtils.SegmentsInPath(bezierContour.Segments, bezierContour.Closed);
    79.  
    80.                         foreach (BezierSegment pathSeg in segments)
    81.                         {
    82.                             int kSegmentSubdivisions = 8;
    83.                             for (int i = 0; i < kSegmentSubdivisions; ++i)
    84.                             {
    85.                                 float t = (float) i / kSegmentSubdivisions;
    86.                                 var p = VectorUtils.Eval(pathSeg, t);
    87.                                 contour.Add(new Vector2(p.x, p.y));
    88.                             }
    89.                         }
    90.                     }
    91.                
    92.                     if (gms != null && gms.Count > 0 && contour.Count > 0)
    93.                     {
    94.                         Color color = Color.white;
    95.                         Rect bounds = Rect.zero;
    96.  
    97.                         foreach (VectorUtils.Geometry g in gms)
    98.                         {
    99.                             if (g.Fill != null)
    100.                             {
    101.                                 color = g.Color;
    102.                             }
    103.  
    104.                             bounds = g.UnclippedBounds;
    105.                         }
    106.  
    107.                         FillFromGeometry(gms, gameObject, bounds);
    108.                         FillContour(contour);
    109.                     }
    110.  
    111.  
    112.                 }
    113.            
    114.  
    115.             }
    116.         }
    117.  
    118.         AddMi(sceneInfo.Scene.Root);
    119.     }
    120. }
    121.  
     
    Last edited: Apr 29, 2021
  33. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    217
    Hello @mcoted3d

    I'm trying to load an SVG and then create a texture from it in order to create a jpg file. Load the svg seems to works and then I can create a Sprite using VectorUtils.BuildSprite like in the repo samples. With that sprite I noticed that:
    • if I set that sprite to a SpriteRenderer then the "SVG content" will be displayed as expected
    • if I sent that sprite to an Image sprite property, then nothing will be displayed
    • if I try to access that sprite texture property, then an error occurred because it's null
    Because I really need a texture in order to use "ImageConversion.EncodeToJPG" I decided to give "VectorUtils.GenerateAtlas" a try but the result it's null and I don't know why.

    So my question is : is it possible to generate a texture from a loaded SVG, if yes how ? If not, is there a way to generate a jpg file from a loaded SVG ?

    Thanks
     
    Last edited: Apr 22, 2021
    StephenW likes this.
  34. StephenW

    StephenW

    Joined:
    Mar 29, 2016
    Posts:
    77
    Click on the svg image in the project folder
    Go to the inspector
    Click on Generated Asset Type
    Change to Textured Sprite
    upload_2021-4-27_21-47-29.png
     
  35. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    217
    Thanks @StephenW but I'm loading the SVF from a string and then tesselate it using
    Code (CSharp):
    1. VectorUtils.TessellateScene
    so I don't think I can access those import settings at runtime.
     
    StephenW likes this.
  36. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    You can use VectorUtils.RenderSpriteToTexture2D()
    https://docs.unity3d.com/Packages/c...yEngine_Material_System_Int32_System_Boolean_

    Be careful with the material that you use when using this method, if the sprite has gradients or embedded textures, you want to use a material with the "Unlit/VectorGradient" shader. Otherwise, you can use "Unlit/Vector".

    Hope this helps!
     
  37. Dev_Sebas

    Dev_Sebas

    Joined:
    Jul 10, 2014
    Posts:
    18
    Hello @mcoted3d

    I have posted an issues over the GitHub, but I'm also posting over here. So, I'm using the sample code (SVGRuntimeLoad.cs), it works perfectly on Unity editor. But, if I build for iOS (did not tried Android) on 2020 or newer it crashes with the following result.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object. at Unity.VectorGraphics.VectorUtils.BuildSprite (System.Collections.Generic.List1[T] geoms, UnityEngine.Rect rect, System.Single svgPixelsPerUnit, Unity.VectorGraphics.VectorUtils+Alignment alignment, UnityEngine.Vector2 customPivot, System.UInt16 gradientResolution, System.Boolean flipYAxis) [0x00000] in <00000000000000000000000000000000>:0
    2. at DataManager.ProcessSVGImage (System.String svgData, EntityIcon entityIcon) [0x00000] in <00000000000000000000000000000000>:0
    3. at System.Action1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0 at RestWebClient+<HttpGet>d__3.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
    I read Vector Graphics Package is a experimental package, but this is an essencial tool for many developers. It works on 2019 builds, but not with 2020 or newer. Is there an explication for this behaviour? Whats the roadmap on this feature? Please provide some feedback.

    Thanks in advance,
    Sebastião Rocha
     
    Starburst999 likes this.
  38. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    217
    Thanks @mcoted3d,
    What I want is to convert the texture to a JPG file and then write that file into disk. So I won't directly use the generated texture to display something on screen.
     
  39. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
  40. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    217
    Yes. But for that I need a texture to pass-in as argument. First time I thought the texture property of the sprite generated by VectorUtils.BuildSprite could do the job until I found it is always null. I'll try RenderSpriteToTexture2D and I hope I'll have more luck !
     
  41. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    Yes, Vector Sprites are sometimes "textureless" to get the infinite resolution. It should work by baking it with RenderSpriteToTexture2D.
     
  42. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    217
    Hello @mcoted3d ,

    First of all thank you, VectorUtils.RenderSpriteToTexture2D works as expected !
    Now I would like to load, import and tesselate svg files from a Task but after some tests it seems neither "SVGParser.ImportSVG" or "VectorUtils.TessellateScene" work when called from something like Task.Run(...).

    Is that normal ? Is there a way to thread that part ? I imagine that building the sprite and drawing the sprite to a texture won't work on a thread but I though parsing and tessellate should, right ?

    Thanks
     
  43. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    That's correct. Building the sprite + rendering should be done on the main thread. You can however thread the SVG parsing and tessellation parts.

    Calling the SVGParser.ImportSVG() with default value will cause issues because it will call Screen.dpi, which cannot be called outside the main thread. A solution is to provide it as an argument:

    Code (CSharp):
    1.         List<VectorUtils.Geometry> geoms = null;
    2.         var dpi = Screen.dpi;
    3.         var task = Task.Run(() => {
    4.             // Dynamically import the SVG data, and tessellate the resulting vector scene.
    5.             var sceneInfo = SVGParser.ImportSVG(new StringReader(svg), ViewportOptions.DontPreserve, dpi);
    6.             geoms = VectorUtils.TessellateScene(sceneInfo.Scene, tessOptions);
    7.         });
    8.         task.Wait();
    9.  
     
    Last edited: May 3, 2021
  44. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    217
    Ho ho, nice trick. Thank you.
     
  45. BlackHoleTracer

    BlackHoleTracer

    Joined:
    Jan 23, 2014
    Posts:
    7
    Hi! Very like to use this cool package!
    There is some small problem.
    In Unity 2020 we can see number of vertices and size of tessellated sprite on svg-preview:
    upload_2021-5-3_19-10-59.png
    E.g. this tessellated image contains 684 vertices.
    New Unity versions (2021.1.4f1, 2021.1.5f1) do not display this information:
    upload_2021-5-3_19-16-0.png

    It's very important information to optimize performance. Where can I get that values without code? Now I'm using editor script and can only find out number of vertices though:
    sprite.vertices.Length


    Thanks.
     
  46. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    Something might have changed recently regarding the preview information. Can you please file a bug (Help > Report a Bug...) and we'll have a look. Thanks!
     
  47. BlackHoleTracer

    BlackHoleTracer

    Joined:
    Jan 23, 2014
    Posts:
    7
    I reported a bug (Case 1333565). Thanks!
     
  48. icesid

    icesid

    Joined:
    May 24, 2019
    Posts:
    10
    Maybe I am doing something wrong, but from 2021 versions in URP projects I am getting some shader warnings and svg image is not rendering. Tested in 2021.1.2f1, 2021.1.3f1 and 2021.1.6f1.

    Capture.PNG
     
  49. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    682
    These warnings shouldn't prevent the SVG assets from rendering. It could help to reimport your asset (make sure they are in "UI SVGImage" asset type) and reinstantiate them in the hierarchy.

    In all cases, it wouldn't hurt to file a bug report: Help > Report a Bug...
     
  50. icesid

    icesid

    Joined:
    May 24, 2019
    Posts:
    10
    I figured out I was missing canvas renderer. It is not added automatically like when you add standard image from context menu. Maybe it's a bug, I don't know, anyway, thanks for help.
     
unityunity