Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    481
    Most of the features we don't support fall into the following categories:
    1) Animation features (tweens, etc.)
    2) Scripting features (e.g. Javascript integration)
    3) Filters (blurs, drop shadows, etc.)

    We don't have any plans to support the above features. There's a lot of demand for 3), but these usually require a post-process pass that doesn't fit well with our current pipeline.

    The other obvious missing feature is text support, which we will probably support eventually.

    Let me know if you have specific feature requests that I may have missed!
     
  2. Rosethornian

    Rosethornian

    Joined:
    Apr 26, 2018
    Posts:
    42
    The big one we need is (3).

    Is that *definitely* not going to be supported? We really need it.
     
  3. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    I cannot say it will never be supported, but there are limitations that prevents us from doing it in the short term.

    If you want to apply filters on SVG content today, there's probably a somewhat complicated workaround you can try. This is not using the filter tags from the SVG file, but instead, you could apply the filter manually:
    1) Extract the part of the vector scene you want to filter, and bake it in a Texture2D.
    2) Create a RenderTexture of the required output size
    3) Do a Graphics.Blit() of the Texture2D from 1) into the RenderTexture from 2), using an appropriate material that will do the filtering (e.g., a blur material).
    4) The RenderTexture will now have your filtered SVG content.

    Alternatively, you could draw the Texture2D from 1) in a camera that has a postprocess effect active (e.g., blur effect).

    I understand this is a complex system, but this is essentially what the SVG package would have to do to support SVG filters.

    Let me know if you have any questions!
     
    Last edited: Jan 24, 2020
  4. Rosethornian

    Rosethornian

    Joined:
    Apr 26, 2018
    Posts:
    42
    Thanks! I'll give it a try and let you know if I need any assistance.
     
  5. Miniced

    Miniced

    Joined:
    Aug 18, 2015
    Posts:
    9
    Hi, I've recently updated from Unity 2019.2 to 2019.3 and thus was required to also upgrade this package from 2.0.0-preview.4 to 2.0.0-preview.11.
    However, certain references I was using are now gone and I don't know what are the current replacement.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using Unity.Collections;
    5. using Unity.VectorGraphics.Editor;
    6. using UnityEditor;
    7. using UnityEngine;
    8. using UnityEngine.U2D;
    9.  
    10. public class SVGPostprocess : AssetPostprocessor
    11. {
    12.     private static readonly List<string> _savingAsset = new List<string>();
    13.  
    14.     static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    15.     {
    16.         foreach (string assetPath in importedAssets.Where(x => !_savingAsset.Any(y => y == x)))
    17.         {
    18.             //Unity.VectorGraphics.editor
    19.  
    20.             AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath);
    21.             if (!(assetImporter is SVGImporter)) return;
    22.             SVGImporter importer = assetImporter as SVGImporter;
    23.  
    24.             if (!(importer.targetObject is Sprite)) return;
    25.             Sprite sprite = importer.targetObject as Sprite;
    26.  
    27.             Vector2[] Verts = sprite.vertices;
    28.  
    29.             Vector2 min = new Vector2(Verts.Min(x => x.x), Verts.Min(y => y.y));
    30.             Vector2 max = new Vector2(Verts.Max(x => x.x), Verts.Max(y => y.y));
    31.  
    32.             NativeArray<Vector2> newUV = new NativeArray<Vector2>(Verts.Length, Allocator.Persistent);
    33.  
    34.             for (int i = 0; i < newUV.Length; ++i)
    35.                 newUV[i] = new Vector2((Verts[i].x - min.x) / (max.x - min.x), (Verts[i].y - min.y) / (max.y - min.y));
    36.  
    37.             sprite.SetVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord2, newUV);
    38.  
    39.             newUV.Dispose();
    40.  
    41.             _savingAsset.Add(assetPath);
    42.             AssetDatabase.ForceReserializeAssets(new string[] { assetPath });
    43.             _savingAsset.Remove(assetPath);
    44.         }
    45.     }
    46. }
    47.  
    For context, this is meant to generate the UVs for each SVG file imported so that I may use it with custom shaders. Unfortunately, Unity.VectorGraphics.Editor.SVGImporter no longer exists and thus I am seemly unable to parse the assetImporter as SVGImporter and use it as shown above.
     
  6. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    There was no API changes between 2.0.0-preview.4 and 2.0.0-preview.11. I'm guessing the package didn't import properly for some reason. A few things to try:
    • Remove/Reinstall the package from the Package Manager Window.
    • Delete the Library folder of your project to force a full re-import
    Let us know if you still have issues after that!
     
  7. Miniced

    Miniced

    Joined:
    Aug 18, 2015
    Posts:
    9
    Thanks. It seems like reopening the project this morning actually fixed it.
    Who knew?
    However, I wished it actually came without issues.
    You see, I've been using the method above to populate each SVG sprite's TexCoord2 with UV coordinates on import so that I may use those coordinates in my custom shaders. This worked all well for the longest time, but not anymore. While the method do fill them with the required UV, for whatever reason, it doesn't persist after shutting down the editor and reopening the project. I've tried to force reimport each SVG file many times and TexCoord2 will always end up not saving itself in the asset file for some reason.
     
  8. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    I've heard reports that the AssetPostprocessor callback were not triggering anymore. If that's the case for you, I would open a new bug (Help > Report a Bug...). This may be caused by the new asset database.
     
  9. Miniced

    Miniced

    Joined:
    Aug 18, 2015
    Posts:
    9
    It actually does work. Reimporting the asset do trigger the callback and as I said, it successfully fills the asset with the UV data. I'm able to make it work from there. The problem is that as soon as I close the project and reopen it, the coordinates are gone.
     
  10. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    I was able to reproduce, it's hard to tell why those UVs won't persist. I don't think it's an SVG specific issue though, it could be an AssetDatabase issue or a Sprite issue as well. I would still create a bug report so that the right team can have a look.
     
  11. Miniced

    Miniced

    Joined:
    Aug 18, 2015
    Posts:
    9
    Upon making various tests, I can confirm this hypothesis. I've made a new project in both Unity 2019.3 and 2019.2 and were able to reproduce the issue using a basic sprite in 2019.3 while the intended behaviour occurs in 2019.2. It was, in fact, not a SVG specific issue as I initially suspected. I've sent a bug report on it now. For now, as long as this issue doesn't get resolved, I'll be remaining with 2019.2 for my current project.

    Thanks for your help.
     
    mcoted3d likes this.
  12. Lemar76

    Lemar76

    Joined:
    Apr 6, 2015
    Posts:
    3
    What is missing to move it from preview to official package? Is there any ETA when this package isn't preview anymore?
     
  13. Rosethornian

    Rosethornian

    Joined:
    Apr 26, 2018
    Posts:
    42
    @mcoted3d WRT the SVGs that don't import due to having unsupported features, would it be possible to allow them to be imported but sans the unsupported features? Otherwise it requires manipulation of every problematic SVG file.
     
    andyz likes this.
  14. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    Yes, that's feasible. Can you please file a bug report so we can track this? (Help > Report a Bug...)
     
  15. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    1,305
    What is plan for this project, is it becoming a full package?

    As for drop shadows and even blurs, it is not that complex for static effects is it? You can render geometry to a rendertexture and apply a blur filter to create a texture plane.
     
  16. Rosethornian

    Rosethornian

    Joined:
    Apr 26, 2018
    Posts:
    42
    Done! Thanks.
     
  17. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    25
    Was wondering since a while why SVG imported as Vector Sprite vs Texture Sprite differ vastly in size (for all SVGs I have). Also, while relative size differences of different SVG are respected for Vector Sprites, all Texture Sprites are the same size.

    Digging a bit in SVGImporter.cs, I came to the conclusion importing SVG as "Textured Sprite": does not consider the original Sprite dimensions at all (input parameters to "Sprite.Create). A slight modification of the "GenerateTexturedSpriteAsset" method resolves this for me: now sprites imported as “Vector Sprite” and as “Texture Sprite” look identical, and relative differences between SVG are respected.

    Posting this here in case this “bug”(?) affects also others. Maybe my SVG files are weird, but no playing around with viewbox, height width etc specification in the SVG can fix it, but this here does:

    Code (CSharp):
    1. var ratio = tex.width / sprite.rect.width;
    2. var texturedSprite = Sprite.Create(tex, rect, pivot, SvgPixelsPerUnit* ratio, 0, TexturedSpriteMeshType, m_SpriteData.SpriteRect.border);
    (Moderators: can you delete the thread with the same post? I wanted to post here)
     
    Last edited: Feb 4, 2020
  18. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    The size of the sprite is driven by the "Pixels Per Unit" property. In the case of a vector sprite, the bounds of the SVG asset will be used as the reference size. When a textured sprite is used, the size of the texture is used as a reference instead. Let me know if that's unclear.
     
  19. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    25
    That is perfectly clear, and it is a bug, would you disagree?

    Definition of "unit" in "Pixels per Unit" is incoherent (and not intuitive):
    • "unit" for Vector Sprites are "SVG units" (that come from the SVG files)
    • "unit" for Textures Sprites are "Texture dimension units" (that comes from the input parameter and is applied to all SVG files"
    My proposed change "harmonizes the unit" (SVG units for both).

    I have seen a request to fix this somewhere in this thread here before, there was no response, maybe the issue it cause did not fully come across?

    Importing >200 sprites (all different size), difference right now:
    • Vector Sprites, all good, I can control with one parameter the size of all sprite, relative differences between SVGs are retained
    • Textured Sprites: I would have to set for each and every of the 200 SVG a different texture size to maintain the relative size of the SVG to eachother. Impossible, not going to do this. I would then at least expect that the texture size is linked to the sprite dimensions, so that it maintains the relative size. (e.g. texture pixels per SVG unit)
    Also, I expect no difference in appearance between "Vector Sprite", and "Textured Sprite". Please try to insert those 2 lines into GenerateTexturedSpriteAsset and let me know what you think.
     
    Last edited: Feb 5, 2020
  20. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    It was designed like that. My concern about using the SVG size to control the pixel per unit (PPU) setting was that this could lead to hard to predict resolutions. You could have a small texture that ends up filling the whole screen if the PPU is low. The inverse could happen as well, a large texture could be scaled down to a tiny sprite on screen.

    But you are making good arguments.

    I would feel uneasy about changing the behavior of the PPU setting for textured sprite since that would be a breaking change. However, we could add an additional option to adjust the PPU the way you proposed it.

    Alternatively, we could have an option to automatically compute the texture size from the SVG size (instead of having to enter a size manually). Maybe this could work for you as well. I think you could even try to do it automatically from an asset preprocessor, although that would require some work to get the SVG size.

    Let me know what you think!
     
  21. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    25
    Point understood, and Thank You for considering the feedback. First and foremost I think the SVG should be “in the driver seat” how large it is, this is what “width”, “height” “viewbox” are designed for. From spec: “The width attribute defines the horizontal length of an element in the user coordinate system.”

    Unity units is the coordinate system.

    And here I expect no difference between how I import the SVG.

    Intuitively, controlling now the “sharpness” of what is imported, I was thinking what I am controlling in the option field is “how many texture pixels are distributed over that given size” (texture sprite), or “how fine grained the mesh is over that given size” (vector sprite). I did not anticipate changes to the size itself. An option to make the importer behave like that would be great. Otherwise I would keep adding my 2 lines to new releases of the package for my project...least hassle for me (open source is awesome!)

    Adressing the example of huge sprite with 5 pixels, or the tiny sprite with 4096 pixels: so be it. If somebody designed a such SVG sizes, and the user configures such inappropriate PPU, bad choice, but at least it behaves consistently in terms of sprite units translate into Unity coordinate system units.
     
    Last edited: Feb 6, 2020
    mcoted3d likes this.
  22. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    140
    Tesselation options
    Code (CSharp):
    1.         VectorUtils.TessellationOptions tessOptions = new VectorUtils.TessellationOptions()
    2.         {
    3.             StepDistance = 100f,
    4.             MaxCordDeviation = 1f,
    5.             MaxTanAngleDeviation = 0.2f,
    6.             SamplingStepSize = 0.2f
    7.         };
    8.  
    9. SceneNode pNode
    10.  
    Mesh generation
    Code (CSharp):
    1. List<VectorUtils.Geometry> geometry = VectorUtils.TessellateNodeHierarchyRecursive(pNode, tessOptions, pNode.Transform, 1.0f, null);
    2.  
    3. VectorUtils.FillMesh(_mesh, geometry, 100, true);
    4.  
    Contour tesselation
    Code (CSharp):
    1.  Stroke stroke = new Stroke()
    2.                         {
    3.                             Color = Color.white,
    4.                             Fill = s.Fill,
    5.                             FillTransform = pNode.Transform,
    6.                             HalfThickness = 0f,
    7.                             Pattern = null,
    8.                             PatternOffset = 0f,
    9.                             TippedCornerLimit = 100f
    10.                         };
    11.  
    12.                         PathProperties pathProps = new PathProperties()
    13.                         {
    14.                             Stroke = stroke,
    15.                             Head = PathEnding.Square,
    16.                             Tail = PathEnding.Square,
    17.                             Corners = PathCorner.Tipped
    18.                         };
    19.  
    20.                         VectorUtils.TessellatePath(s.Contours[0], pathProps, tessOptions, out vectors, out ind);
    Code (JavaScript):
    1. <ellipse transform="matrix(-0.1829 0.9831 -0.9831 -0.1829 683.5942 357.3576)" fill="#FEFAE5" cx="193.3" cy="462.8" rx="8.5" ry="10.3"/>
    2.  
    and having Only one ellipse turned 90 agrees contour

    Any ideas why?


    PS
    PLZ make public VectorUtils.TessellateNodeHierarchyRecursive
    need it to parce every part of svg
    for getting contour of area and mesh of area
     
    Last edited: Feb 6, 2020
  23. yury_shumovsky

    yury_shumovsky

    Joined:
    Sep 25, 2019
    Posts:
    3
    Hi,

    I have faced with some issue when SVG package crash / freeze app (tested at all platforms: iOS/Android, WebGL, UnityEditor)

    It happens on this path (some values are too big like : 1a223507521944.963,223507521944.963,0, )


    Code (JavaScript):
    1.   <path class="a9a94d5a-33fd-4aab-b4d7-8385192ed643" d="M1604.29,160.79l-4.91,10.92c-2.21-5.31-8.13-9.31-14.75-9.51-11.64-.4-27.6,11.52-26.5,22.74.31,3.4,2.11,4.81,4.62,5.71-13.85,2.8-17.06,18.43-8.43,27.34a18.047,18.047,0,0,0-10.64,4.11,17.617,17.617,0,0,0-6.42,10.52c-6.72-6.21-18.06-6.91-25.38-1.2-6.73,5.21-9.04,14.92-6.03,22.74-3.91-2.71-8.32-5.31-13.34-6.01-6.32-1-14.35,2.1-16.16,8.81-1.2,4.41.4,10.12,6.53,14.73-.91.3-1.01-.2-1.51-.2a4.4,4.4,0,0,0-4.11,6.81c-1.31,1.1,1,1.9-.71,4.21a3.482,3.482,0,0,1-1.3,1.1,4.405,4.405,0,0,0-3.71-5.01,4.121,4.121,0,0,0-3.21.8c-4.42-4.51-2.51-8.71-4.62-8.21a9.3,9.3,0,0,0-4.42,2.5,6.293,6.293,0,0,0-8.32,1.7c-3.42-2.2-6.73-4-10.34-3.9-6.32.2-10.94,7.41-5.82,11.82a13.848,13.848,0,0,0-6.42,2.6,12.965,12.965,0,0,0-16.86,6.92,13.694,13.694,0,0,0-.8,7.21c-6.43-1.5-13.55-2.91-20.47-1.5-6.53,1.3-13.95,6.01-15.56,13.62-15.65-5.71-17.76,8.01-10.13,13.12a16.867,16.867,0,0,0,6.82,2.41,19.8,19.8,0,0,0-5.82,4.1c-3.11-3.4-6.92-5.71-10.84-3.4a4.621,4.621,0,0,0-1.7,1.7,8.8,8.8,0,0,0-11.94,3.61,11.938,11.938,0,0,0-.81,2c-6.82-4.01-16.45,2.6-12.14,11.12a8.667,8.667,0,0,0,6.12,4.71c5.32.8,9.64-3.21,12.85,2.2a3.234,3.234,0,0,1,.6,2.31l-44.35,4h-.2c-.1,0-.1,0-.2.1-.11,0-.11.1-.21.1s-.1.1-.2.1a223507521944.963,223507521944.963,0,0,1-.2.4v.4l.2,17.44c-10.73-3.91-10.13-2.61-25.79-10.42a25.057,25.057,0,0,0,0-5.61c5.83,6.71,5.83,6.91,6.53,6.81s3.41-1.2,5.01-10.72a101.983,101.983,0,0,0,.71-13.62l6.92,6.91a.978.978,0,0,0,1.41,0,1.4,1.4,0,0,0,.3-.9l-1.91-11.42c13.65,7.81,15.45,8.31,16.36,7.01.4-.6,1.6-2.3-11.34-20.84,1-1,3.71-2.8,8.83,0,10.63,5.71,10.94,9.02,10.23,13.13a1.012,1.012,0,0,0,.81,1.2.778.778,0,0,0,.8-.2c.2-.1,4.61-3.71,3.41-14.13-.9-8.01-9.03-12.52-13.14-14.32,5.82-2.51,40.74-17.43,41.04-23.74.1-1.11-.71-1.81-1.41-1.61l-18.66,2.61c13.85-8.02,15.75-7.82,15.25-9.32s-2.01-.1-11.64,1.6l13.45-6.41a.992.992,0,0,0,.5-1.3,1.555,1.555,0,0,0-.8-.6c-6.93-.6-32.12,6.91-38.64,8.92,12.75-5.91,29.4-13.93,36.43-17.33a1.115,1.115,0,0,0,.6-1.01c-.3-3.3-19.87,0-25.19.6,12.45-7.01,13.95-6.71,13.55-8.11s-1.61-.4-11.04-.1c3.21-2.4,5.42-2.8,4.72-4.11-.8-1.5-1.71,0-21.07,6.82,14.45-13.33,16.35-13.43,15.45-14.83s-.7-.2-36.63,18.93l36.43-28.95a1.075,1.075,0,0,0,.2-1.4.965.965,0,0,0-1.21-.3,155.178,155.178,0,0,0-14.75,7.11c-7.22,3.91-31.71,22.64-42.44,31.66,8.53-11.72,31.41-37.27,41.14-47.99a1.2,1.2,0,0,0,0-1.4c-1.2-1.3-2.11.9-11.24,7.61-.1.1-.1,0-.2.3-10.64,9.02-22.38,20.14-55.49,47.39a10.36,10.36,0,0,0-5.92-1.91,90.484,90.484,0,0,0-10.44-1.5c9.33-5.51,15.56-9.82,24.19-14.12,21.67-10.72,30.5-20.14,30.8-20.54a.967.967,0,0,0,0-1.4.955.955,0,0,0-1-.2c-4.52.9-29.4,11.72-62.42,20.93,25.39-13.82,58.5-27.04,61.01-32.25a.883.883,0,0,0-.4-1.3,1.268,1.268,0,0,0-.6-.1c-21.57,3.8-27.39,5.71-48.37,13.62,18.97-11.72,31.41-18.93,42.75-34.66a.913.913,0,0,0,0-1.2.926.926,0,0,0-1.2-.3c-23.48,9.61-36.23,14.52-50.58,23.84a229.991,229.991,0,0,0,32.92-41.27,1.079,1.079,0,0,0-.31-1.41.8.8,0,0,0-.8-.1c-7.72,2.51-35.42,22.14-50.97,32.46,6.92-6.91,17.16-17.33,21.07-22.14,17.86-21.94,18.76-21.24,17.96-22.44a.949.949,0,0,0-1.1-.4c-8.23,2.61-20.17,11.62-27.1,17.63,6.22-10.52,10.54-20.53,10.44-21.84,217.05-8.11,264.11-15.82,372.18-8.21.4,6.91,8.83,7.91,11.24,3.71C1603.39,161.1,1603.79,160.89,1604.29,160.79Z"/>
    2.  
    3.  
    I tried to debug the freezing place in SVG package and found this code:
    VectorTessellation.cs -> TraceShape

    Code (CSharp):
    1.  while (!pathIt.Ended)
    2.             {
    3.                 float distance = patternIt.SegmentLength;
    4.                 float startingLength = pathIt.LengthSoFar;
    5.                 float unitsRemaining = Mathf.Min(tessellateOptions.StepDistance, distance);
    6.                 bool endedEntirePath = false;
    7.                 for (;;)
    8.                 {
    9.                     var result = pathIt.AdvanceBy(unitsRemaining, out unitsRemaining);
    10.                     if (result == PathDistanceForwardIterator.Result.Ended)
    11.                     {
    12.                         endedEntirePath = true;
    13.                         break;
    14.                     }
    15.                     else if (result == PathDistanceForwardIterator.Result.NewSegment)
    16.                         verts.Add(pathIt.EvalCurrent());
    17.  
    18.                     if ((unitsRemaining <= Epsilon) &&
    19.                         !TryGetMoreRemainingUnits(ref unitsRemaining, pathIt, startingLength, distance, tessellateOptions.StepDistance))
    20.                     {
    21.                         break;
    22.                     }
    23.  
    24.                     if (result == PathDistanceForwardIterator.Result.Stepped)
    25.                         verts.Add(pathIt.EvalCurrent());
    26.                 }
    27.  
    28.                 // Ending
    29.                 if (endedEntirePath)
    30.                     break;
    31.                 else verts.Add(pathIt.EvalCurrent());
    32.                 patternIt.Advance();
    33.             }
    What your recommendation will be? How to fix/handle this issue?
     
  24. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    This is it, the SVGImporter doesn't handle large coordinates properly at this time, and some algorithm won't converge with them.

    We have a fix in the works for this. In the meantime, try to avoid large coordinates!
     
  25. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    140
    I also want divine attention
     
  26. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    You'll get it! Your problem is more complex and will require a bit more investigation!
     
  27. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    Probably because you're passing
    pNode.Transform
    in the tessellation method. I would think that transform will be applied twice if you do that.

    That method is subject to change in the future. I would recommend to create a temporary scene to wrap your node and call TessellateScene instead.

    Code (CSharp):
    1. var scene = new Scene() { Root = pNode };
    2. var geoms = VectorUtils.TessellateScene(scene, tessOptions);
    3.  
     
  28. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    140
    thank you alot! You're the best!
     
  29. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,060
    Hi just want to know if Vector Graphics Package is going strong or not as there are no news after its initial display? Not even a mention in recent Unite Conferences? How it'll take benefit from DOTS ?
    most importantly, should we consider using it in production games?
     
    andyz likes this.
  30. vzlomvl

    vzlomvl

    Joined:
    Jun 25, 2016
    Posts:
    38
  31. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    198
    Hi jGate99,

    The general recommendation is to avoid using preview packages in production as they're not officially supported. That being said, SVG is relatively stable and we do try to fix issues whenever we can but just can't commit to it.

    Regarding its future, we're still debating. From the feedback we got so far, it's not entirely doing what people are expecting form it, which is using vector graphics and any resolution without re-tessellating.

    We're considering supporting SVG natively in our new UI framework and render them at any resolution or scale without changing tessellation or requiring any other action.

    In short, we believe vector graphics should be something you can use in your projects but we're still working at finding the best way to use and render them efficiently.

    What are you using SVG for? 2D games or UI?
     
    jGate99 likes this.
  32. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    Yes, I'll bring the fix to 1.0.0-preview as well. Both package version should become live hopefully next week.
     
    vzlomvl likes this.
  33. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    1,305
    Vector graphics in general is big and just having decent tesselation (kind of what LibTessDotNet does - though Unity optimised) and line drawing functionality built into Unity is a good base for gaming, UI, art-code (see processing) etc.
    SVG loading can go on top.
    This would really widen Unity's 'out of the box' uses.

    I have done my own line drawing and used third-party tesselation libraries for procedural content. But built-in, optimised, would be good.

    BTW SVG to Texture/Sprite conversion might have some uses but going into the future it is better to have resolution independent polygons since phones and tablets and 4k screens would push quality of anything converted to images.
     
  34. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,060
    Thank you for your detailed reply,

    I'm actually using it for both UI as well as 2D Game in the future.

    So if UI Elements will have support for SVGs then thats great news.
     
  35. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    140
    Hi again!

    How can i calculate contour of mesh?

    now i tesselate it and get points of contour
    It working fine, but have some strange artifacts, like this:



    Code (CSharp):
    1.  
    2.  
    3.  if (pNode.Shapes != null)
    4.             {
    5.                 foreach (Shape s in pNode.Shapes)
    6.                 {
    7.                     List<Vector2> contour = new List<Vector2>();
    8.  
    9.                     if (s.Fill != null)
    10.                     {
    11.                         Vector2[] vectors;
    12.                         ushort[] ind;
    13.  
    14.                         Stroke stroke = new Stroke()
    15.                         {
    16.                             Color = Color.white,
    17.                             Fill = s.Fill,
    18.                             FillTransform = s.FillTransform,
    19.                             HalfThickness = 0f,
    20.                             Pattern = null,
    21.                             PatternOffset = 0f,
    22.                             TippedCornerLimit = 0f
    23.                         };
    24.  
    25.                         PathProperties pathProps = new PathProperties()
    26.                         {
    27.                             Stroke = stroke,
    28.                             Head = PathEnding.Square,
    29.                             Tail = PathEnding.Square,
    30.                             Corners = PathCorner.Tipped
    31.                         };
    32.  
    33.                         VectorUtils.TessellatePath(s.Contours[0], pathProps, tessOptions, out vectors, out ind);
    34.  
    35.  
    36.  
    37.  
    making contour with lineRenderer by vectors from TessellatePath

    Why is this happening ?
     
  36. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    407
    I wish I could use SVG to draw UI in 3D project. Would it be supported in UIElement? Do we have any demo or beta to try it?
     
  37. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    198
    We want UIElements to be a good solution for textureless UI that renders well across all resolutions, in screen or wold space. We don't have a timeline or demo for that at the moment though.
     
    Thaina likes this.
  38. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    Hard to tell, but having
    HalfThickness = 0f
    seems a bit odd and could cause weird issues like you've shown.

    If you suspect a bug with the TessellatePath() method, it would be best to open a bug report (Help > Report a Bug...)
     
  39. Yijiankeji

    Yijiankeji

    Joined:
    Jul 27, 2019
    Posts:
    25
    Hi,

    I used AutoCAD exported SVG file (the file is relatively large), and the vertices in UnityEditor show more than 65535.
    (Vertex array is too large. A sprite mesh may not have more than 65535 vertices.
    UnityEngine.Sprite: OverrideGeometry (Vector2 [], UInt16 [])
    Unity.VectorGraphics.VectorUtils: BuildSprite (List`1, Rect, Single, Alignment, Vector2, UInt16, Boolean))

    Can large files like this be successfully loaded successfully?
     
  40. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    This is a limitation on the number of vertices supported by the sprite system. Your options are limited at this time:
    1. Reduce the quality of the tessellation (maybe try the advanced tessellation settings)
    2. Split your file into multiple SVG assets, and recombine them in a prefab
     
  41. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    I had a closer look at this. This issue was a bit different than the other "large coordinates" issues that I've seen.

    I suspect that the problem is the step distance used in the tessellation options. Using a step distance that's too small when using large coordinates will make the tessellation to run for a very, very long time. Worst case, the tessellation may never end if the step distance is too small to make a dent in the remaining path length (because of float precision issues).

    So, this is something you may want to double-check. You may use float.MaxValue as a step distance to rule out this issue.
     
  42. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    18
    You already said on the first page of this thread that this implementation is purely based on vector2 coordinates. However I would suggest or be interested in your opinion on the following scenario.
    In a project we are using that other svg importer plugin and decided we could not jump onto this Vector graphics package because our workflow currently is a bit different in how we render the svgs.
    Most objects are rendered as opaque objects with writing to the depth buffer. Only very few overlay elements are rendered as transparent. Opaque allows front to back rendering reducing overdraw which is great and since vector graphics often actually don't use transparency this seems like a useful modification. Plus depth of field from post processing works in this setup.
    The svgs contain multiple layers on top of each other and every layer is offset slightly on the vertices z position, again thanks to zwriting this works even with rotated cameras.

    It would be nice if a similar setup would be easily possible with the unity vector graphics package. It seems like it currently is not. Because the layering / z offset part is not supported although it sounds somewhat simple to do, every <path> object processed gets a tiny adjustable offset applied.

    When I tested the package with an opaque shader I got this weird looking result with lots of svg layers zfighting as much as possible. This happens always when the camera is not perfectly aligned with the vector object.

    It would be nice and helpful to have this z offset feature
     

    Attached Files:

    vzlomvl likes this.
  43. UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    Joined:
    Dec 28, 2016
    Posts:
    12
    hi
    I have a big SVG, the Error is
    "Vertex array is too large. A sprite mesh may not have more than 65535 vertices"
    I need high target resolution, so How can I ensure that SVG images are displayed correctly at high resolution?
    I have tried to make an SVG file as small as possible by dividing the SVG file, but I still want to know if there is any setting to get rid of the 65535 limit
     
  44. UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    Joined:
    Dec 28, 2016
    Posts:
    12
    We have another problem.
    We have chosen a resolution of 2160 zoom factor of 2
    But there are still cracks at the intersection of the shapes
    upload_2020-2-15_18-0-44.png
    If we continue to expand the factor, we may exceed the limit of 65535.
    Is this crack caused by insufficient resolution?

    In order to prevent cracks, we have now expanded all graphics by 0.2px to offset the problem of cracks.

    Is there any other way?
    Thank you
     
  45. goomar

    goomar

    Joined:
    Apr 13, 2013
    Posts:
    3
    I encountered a problem in use:

    When checking the presserve viewport, sequence the frame to animate the alert.

    Incomplete mesh data in Sprite. Both Please reimport the or recreate the Sprite.
     
    Last edited: Feb 20, 2020
  46. yury_shumovsky

    yury_shumovsky

    Joined:
    Sep 25, 2019
    Posts:
    3

    Attached Files:

  47. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    Thanks for the feedback, it is noted.

    The z-fighting issue you noticed was probably caused because ZWrite was on for that shader. If you turn it off, this will prevent each layer to write the same Z value and fight with each other. Of course, if you need the SVG elements to contribute to the depth buffer, that's a problem we don't have a solution right now.
     
  48. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    Sprites still use 16 bit indices, so this is a hard limit caused by the sprite system.

    If you are willing to use the VectorUtils.FillMesh() API instead, you should be able to work around this issue (Mesh supports 32 bit indices, except on certain low-end platforms).

    We have plans to support the Mesh generated asset type directly in the importer, but right now you'll have to do it in script.
     
  49. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    I can't think of a better solution right now, as these cracks are probably due to float imprecision. Adding strokes to the shapes could possibly hide the issue, but this will generate quite a bit of extra geometry, and you seem to be vertex limited at this time.
     
  50. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    481
    It seems some of these frames have shapes that are completely out of the viewport, is that correct? These will generate sprites without any geometry, which will cause the error you got.

    Maybe you could work around this limitation by providing a thin transparent rectangle around the whole frame? This way each of your frames would have valid data.
     
unityunity