Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. 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

Vectrosity - Fast and Easy Line Drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, Sep 26, 2014.

  1. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    138
    Hi Eric,

    Installed the Vectrosity a couple of days ago. I want to tell you huge thank you. It saves so much pain. Used to use Unity LineRenderer.
    Wanted to ask you a couple of questions...

    Q01: In my script I have to redraw the line each time I change point position. Does my script looks ok to you or should I find a way to minimise a use of Updated function?

    Q02: This is a base for road creation tool. Does Vectrosity has any methods to find multiple lines intersections?

    Thank you

    Code (CSharp):
    1. public class DrawLine : MonoBehaviour
    2. {
    3.     private NodePlacement nodePlacement;
    4.     private List<Vector3> points = new List<Vector3>();
    5.     private VectorLine line;
    6.     public Texture lineTexture;
    7.  
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         nodePlacement = GetComponent<NodePlacement>();
    12.         line = new VectorLine("Line", points, lineTexture, 20f, LineType.Continuous);
    13.         line.textureScale = 1.0f;
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         AddPoints();
    20.         DisplayLine();
    21.  
    22.         if (Input.GetMouseButton(1)){
    23.             UpdateLine();
    24.         }
    25.     }
    26.  
    27.     public void AddPoints()
    28.     {
    29.         if (points.Count < nodePlacement.nodes.Count)
    30.         {
    31.             points.Add(nodePlacement.nodes[nodePlacement.nodes.Count - 1].Position);
    32.         }
    33.     }
    34.  
    35.     public void DisplayLine(){
    36.         line.points3 = points;
    37.         line.Draw3D();  
    38.     }
    39.  
    40.     public void UpdateLine(){
    41.         points.Clear();
    42.         foreach (var node in nodePlacement.nodes){
    43.             points.Add(node.Position);
    44.         }
    45.     }
    46. }
    47.  
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Thanks!

    1) You might as well use Draw3DAuto in this case rather than calling Draw3D every frame.

    2) No, that's a pretty generic math problem.

    --Eric
     
    Artpen likes this.
  3. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    138
    Thank you. Will take a look at Draw3DAuto in docs.
     
  4. Mighto360

    Mighto360

    Joined:
    Sep 15, 2016
    Posts:
    69
    Hi,

    I've been looking to find a good alternative to LineRenderer for a while, and Vectrosity looks great. However, I need to use HDRP for my current project. Does Vectrosity fully support HDRP?
     
  5. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    350
    Any chance we can get c# documentation? It's almost 2021..
     
  6. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    350


    Here is my Screen Space - Camera setup, with an orthographic camera drawing to a square render texture. I have a test line being drawn with points (0,0) and (1,1), worldPositionStay false, and useViewportCoordinates true. From the documentation
    "Viewport coordinates can be useful in some cases, rather than the default screen space coordinates. With viewport coords, (0.0, 0.0) is always the lower-left corner of the screen, and (1.0, 1.0) is always the upper right, regardless of screen resolution."

    This however does not appear to be the case. Although (0,0) is positioned as expected, it looks like some incorrect aspect ratio is being considered. I expect the aspect ratio here to be RenderTexture.Width:RenderTexture.Height
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    You can use custom materials for lines, so if the material supports HDRP, that would work.

    It's had that for quite a long time.

    Viewport coords makes use of Screen.width and Screen.height, so I'm don't think it will work for that particular case, unfortunately.

    --Eric
     
  8. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    350
    How about ONLY that? The majority is JavaScript, which was deprecated in 2017.
     
  9. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    350
    Why does setting lineType to Continuous change the color to White?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    It would do that if you were using SetColors, since discrete and continuous lines have different numbers of line segments, so there's no way to keep the same colors. It doesn't do that if you've set the line to a single color though.

    --Eric
     
    Innovine likes this.
  11. craigmann

    craigmann

    Joined:
    Sep 29, 2016
    Posts:
    15
    :thumbs_up:
     
  12. locnguyen0297

    locnguyen0297

    Joined:
    Oct 29, 2019
    Posts:
    2
    Hi . I have a problem that needs help.
    I used vectorline.setEndcap to draw a line as shown. however, some times it automatically saves a point drawn with an arrow and later when I draw that point also appears the same new line.
    Please help me . sorry my english is quite weak
    upload_2020-12-18_8-56-29.png
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Unfortunately I'd need more information about what you're doing to have any idea what might be happening.

    --Eric
     
  14. locnguyen0297

    locnguyen0297

    Joined:
    Oct 29, 2019
    Posts:
    2
    sorry for my english.
    I have used vectorline.setEndcap to draw arrow lines as shown. everything works perfectly except that on some occasions, my old line, even though it is already clear, still has an arrow point like my image(cache a point). And when I draw a new line, the arrow point saved from the previous line (the orange point is not related to the line as shown in the picture) is also re-drawn and appears with the line and it has nothing to do with the line.
     
  15. Cambesa

    Cambesa

    Joined:
    Jun 6, 2011
    Posts:
    107
    Hello Eric,

    Is there any way to have the line sizes appear the same on different resolutions or make them render in world space using a world space thickness? When the camera zooms in or out, or when using different resolutions, the line keeps it's width relative to the screenspace which make them seem to scale up or down relative to the world space.

    Kind regards
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    You can do your own calculations to make relative widths (i.e. 2 pixels on standard HD, 4 pixels on 4K), but there's no world space thickness.

    --Eric
     
  17. wwaero

    wwaero

    Joined:
    Feb 18, 2020
    Posts:
    38
    Hey Eric,
    I've been getting a confusing error for a while using vectrosity. Any idea what might be causing it?

    Screen position out of view frustum (screen pos -nan(ind), -nan(ind), 99.998047) (Camera rect 0 0 1534 863)
    UnityEngine.Camera:ScreenToWorldPoint(Vector3)
    Vectrosity.VectorLine: Draw3D() (at Assets/Plugins/Vectrosity/Plugins/Scripts/VectorLine.cs:2221)
    Vectrosity.LineManager:LateUpdate() (at Assets/Plugins/Vectrosity/Plugins/Scripts/LineManager.cs:84)

    I'm not really doing anything fancy
    Code (csharp):
    1.  
    2. public class LobbyOrbit : MonoBehaviour
    3.     {
    4.         public int orbitLineResolution = 150;
    5.         public Material lineMaterial;
    6.         public Texture lineTexture;
    7.         private Vector3 up;
    8.  
    9.         void Start()
    10.         {
    11.             up = transform.up;
    12.  
    13.             var orbitLine = new VectorLine("OrbitLine", new List<Vector3>(orbitLineResolution), 2.0f, LineType.Continuous);
    14.             orbitLine.material = lineMaterial;
    15.             orbitLine.texture = lineTexture;
    16.             orbitLine.MakeCircle(Vector3.zero, up, Vector3.Distance(transform.position, Vector3.zero));
    17.             orbitLine.Draw3DAuto();
    18.         }
    19.     }
    20.  
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    It works without errors here. I suppose it's possible that if you had extreme values for the position that might make the math not work due to limited precision, though I tried something like that and still didn't get any errors.

    --Eric
     
  19. wwaero

    wwaero

    Joined:
    Feb 18, 2020
    Posts:
    38
    Thanks for your reply Eric,
    The numbers I'm using are pretty large, -42164 for z, and x rotation value of -3 so it could be a precision issue as you state. I also have a camera moving around the area inside of the circle but not sure that would have anything to do with it. camera values are like xyz = 46000,2194,-10131 with clip plane 100 near 200000 far when i get the error.
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Those kinds of numbers don't really work well with Unity anyway; generally you want to keep coords within 10K units of the origin.

    --Eric
     
  21. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    248
    Hey!
    I just wanted to ask if there's a feature page or something for this asset?
    I already own ALINE which is quite performant but it's mainly for debugging purposes only, it can draw in game mode but lacks a lot of features to be used as a vector rendering tool.
    So, I want to know about the features of vectrosity, if it's performant enough and if it will suit my workflow
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Which features specifically do you have in mind?

    --Eric
     
  23. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    248
    If I'm using this asset I would like to use it for debugging as well because it will be a hassle maintaining both of them
    So some important features for me would be:
    -No GC Alloc for immediate lines and shapes(ones created per frame)
    -Good performance for the shapes that are not static(i.e, can change per frame according to need)
    -SRP Support
    -Anti-Aliasing(in screen space UI as well)
    -Some kind of gizmo equivalent(check out ALINE for reference)
    -Shader graph support(Because I don't really know shader programming)

    Some kind of performance graph and stress test results would be really nice
     
  24. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    15
    Hello. I just wanted to ask if its possible to make the lines look less jagged, I am trying to make some arrows for my instructions on how to use the game controls and the lines are in the vector canvas its on the UI space.
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Creating VectorLines definitely has GC allocations since there's no way to create objects without that. You can create one and reuse it without GC though, which is recommended, rather than creating/destroying objects all the time.
    It has as good performance as I know how to make; perhaps a GPU-based solution would be faster.
    You can use custom materials so that takes care of SRP.
    Some years ago, Unity changed the way AA works so UI-based lines can't be affected by standard AA (world-space lines still are). While annoying, this can be worked around by using a simple texture for the lines which effectively creates AA by using bilinear filtering.
    There aren't any specific gizmo equivalents.
    As mentioned, you can use custom materials so I assume that covers shader graph support. There's nothing built-in that uses shaders directly so it doesn't really apply.

    Hope that answers your questions!

    See above about using textures; this is covered in the docs ("Drawing Lines" on page 10).

    --Eric
     
  26. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    If I use SetCanvas to attach a VectorLine (defined with Point3s) to an existing canvas with a Canvas Scaler component, it works fine... until the viewport is resized, then the line positions break away from where they should be.

    If I leave them in their own canvas (sans Scaler), it fixes that issue, but breaks my sorting order, since I can no longer place them where I need them in the hierarchy.

    Any suggestions?

    Thanks,

    -Scott
     
  27. FizzyAgent

    FizzyAgent

    Joined:
    Apr 4, 2020
    Posts:
    1
    Hi, is it possible to setup onclick events on lines and curves created in the 3D world space?
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Not easily, I'm afraid. You could try attaching a mesh collider component and using the mesh from the line as the collider, but I'm not sure how effective that would be.

    --Eric
     
  29. Mazak

    Mazak

    Joined:
    Mar 24, 2013
    Posts:
    225
    Hello,
    I am wondering about how to use a cinemachine virtual camera.

    If I SetCamera3d using my main camera - its fine

    upload_2021-1-24_18-55-0.png

    if i use a cinemachine virtual camera it does not work even if it is attached to the main camera.


    upload_2021-1-24_18-56-13.png

    I cannot set a CinemachineVirtualCamera with the SetCamera3D as a camera, I tried using it as a game object but that did not work stating it must have a camera component. This also caused Unity to crash in Edit mode while generating an exception.
     
  30. Mazak

    Mazak

    Joined:
    Mar 24, 2013
    Posts:
    225
    It appears the points are not in the proper plane.

    upload_2021-1-24_20-8-51.png

    After farting around with it for.. too long, It appears cinemachine is setting the main camera (cinemachine brain) to zero in the late update then somewhere else its setting the correct position and rotation.

    LineManager just so happened to be in between these two calculations even though it is at the bottom of the chain down in DontDestoryOnLoad.

    By editing the LineManager from LateUpdate to Update, it seems to have fixed the rotation issues since the main camera has the correct transformation.

    upload_2021-1-24_23-9-51.png
     
  31. Mazak

    Mazak

    Joined:
    Mar 24, 2013
    Posts:
    225
    Dragging and dropping LineManager to the Scripts order page appears to be a better solution than editing LateUpdate to Update.

    upload_2021-1-24_23-19-22.png
     
  32. Aug_m

    Aug_m

    Joined:
    Jan 12, 2021
    Posts:
    2
    Hi. Thanks for the asset it's a real time-saver. I have an issue however.

    Currently I am trying to draw the lines in between two types of objects. By default it is set as overlay so it draws over everything. I tried changing the canvas camera as mentioned in the documentation but the lines just stop appearing altogether. Is there a way I can render it using my normal workflow where I specify the render queue in the shader itself? Sorry if this has been answered before or I missed it in the documentation.

    Edit : one more question, is there in built support to set the size constant regardless of resolution? Thanks
     
    Last edited: Jan 29, 2021
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    You can use VectorLine.material for a custom material. There isn't a built-in method for resolution-independent line thickness, but if you want that, the math is pretty basic.

    --Eric
     
  34. Aug_m

    Aug_m

    Joined:
    Jan 12, 2021
    Posts:
    2
    Hey Eric,

    Thanks for the quick reply. So I did try setting the material previously but as mentioned it completely ignores the render queue as the canvas is set to overlay and it draws on top of everything. Is setting canvascamera supposed to solve that? If so, do i have to do anything else after VectorLine.SetCanvasCamera?

    Edit : So I tried manually setting the canvas to camera space and dragging the camera when debugging and it works as intended. When I do this in code however, the Rect transform of the line have completely off positions.
     
    Last edited: Jan 30, 2021
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Perhaps you could use Draw3D instead?

    --Eric
     
  36. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    64
    I use vectorsity to render some 3d points using Draw3DAuto. I realized that the points are always the same size on the screen, independent from the camera distance. This is good in most of the cases. However in my case I want the points to be smaller when the camera is further away. Is that possible? Thank you for you support!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    It's not possible, sorry; I'd suggest Unity's built-in line renderer for that.

    --Eric
     
    look001 likes this.
  38. Baawk

    Baawk

    Joined:
    Nov 15, 2017
    Posts:
    4
    Hi Eric,

    I've been tinkering with Vectrosity 5.4 a bit so far and really like it.

    There's a special case where I would like to use it, but I'm not sure how to go about it. I'm using 2020.2 and would like to have a bunch of 2D lines within a panel (RectTransform), which are in front of but below some other elements inside that panel (plus they themselves are overlapping sometimes and need to be sorted - but that's what drawDepth is for, which works nicely so far, even though it is somewhat annoying to use). Basically, a schematic with some normal UGUI buttons. The lines should move when the panel is moved (i.e. their relative position inside the panel stays constant), and resized when the panel is - which I can get with a mix of LateUpdate calls to Draw and the Unity callback for rect transform size changes. When the size changes, I adjust all positions to account for the scaling and re-draw them.

    Is there a way to properly sort it with other GUI elements in my panel though? Or are the lines always necessarily drawn at a specific sort order? I thought this might be a case for SetCanvas with a nested canvas, but under some circumstances, the lines are simply not drawn onto the other canvas that I've set up for that purpose (as a child of the original rect or as independent canvas, doesn't really matter). And I suppose the most important question: Can/should Vectrosity be used for something like this?
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Lines are standard UI elements and follow the same sorting rules, which is that transform order in the canvas determines drawing order. VectorLine.drawDepth just uses Transform.GetSiblingIndex/SetSiblingIndex behind the scenes, so you could use VectorLine.rectTransform to access other transform functions yourself if that would help (e.g. SetFirstSiblingIndex/SetLastSiblingIndex). You probably need to use SetSiblingIndex with other UI elements to put them in the correct order relative to VectorLines.

    --Eric
     
  40. sajjadcsharp

    sajjadcsharp

    Joined:
    Jun 16, 2020
    Posts:
    1
    Hi Eric,Thank you for this great tool
    When i draw a line with high width like 200 or greater . roundEndCap texture looks blurry and jagged in beginning and end. how i can sharpen it ?


    Regardeless of this problem i tryed my own solution by increasing resolution of roundEndCap and ThickLine texture
    blurry area has been gone but this approach created another problem as shown in below image


     

    Attached Files:

  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    You probably have transparent pixels at the edge of your texture.

    --Eric
     
  42. MyNameIsUsefull

    MyNameIsUsefull

    Joined:
    Mar 16, 2014
    Posts:
    4
    Hi,

    Is there a way to have a bezier curve with more than two points, and with 2 mirrored control points for each inner point of the line (screenshots below show better what I mean)?

    I know that there is an example for multiple segments in the curve scene. But you also have these screenshots on the store and here in the forum:

    These make me think there could be a built-in way for multi-point bezier curves with mirrored control points (for smooth passing of the curve through the inner points). My understanding is that it could likely be built by separating the line I want into multiple segments, and mirroring the control points myself each time. But given these screenshots, is there a built-in way already that I am missing?
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Yes, the included example shows a bezier curve with multiple points. The control points can be moved independently, but you could program it so that they are locked together.

    --Eric
     
  44. democratize_this

    democratize_this

    Joined:
    Nov 16, 2017
    Posts:
    1
    Hi,

    I have an issue where I have a line for a golfball tracer that is drawing behind a lake in my scene. Normally I would adjust this with a draw order change and making sure the line is in TrasparentFX. I have tried altering VectorLine.drawDepth and this did not help. If put a 1 in VectorLine.Layer (TransparentFX is 1 in my project), will this make sure my line ends up in TransparentFX. Otherwise, how can I change the VectorLine so that it has a later draw order?

    The line is being drawn with Draw3DAuto();

    Thanks
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    DrawDepth only works on canvases, not with Draw3D. Since it's just another object in the scene in that case, the same rules about drawing apply as any other object.

    --Eric
     
  46. StayAw4ke

    StayAw4ke

    Joined:
    Aug 7, 2019
    Posts:
    10
    Unity 2020.1.2f1 - the package produces errors upon import.
     

    Attached Files:

  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,286
    Use the source code rather than the DLL. (The updated version from November no longer includes the DLL.)

    --Eric
     
  48. StayAw4ke

    StayAw4ke

    Joined:
    Aug 7, 2019
    Posts:
    10
    I had the latest version downloaded with no .dll inside. Seems that editor scripts weren't working so the errors disappeared when i've removed `Editor` folder. Not sure how it works after this, but i've managed to find another solution for my problem. Thanks.
     
unityunity