Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Vectrosity - Fast and Easy Line Drawing

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

  1. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    Hi Eric,

    Here's a VectorLine creation code that I use. If I deactivate all other Vectrosity objects and use only this one, the error occurs (when application quits or when I stop the run in the editor). If I deactivate this code as well, no error occurs.
    Note that I do not modify the objects once they are created.

    Please note as well that I'm using "Visibility.Dynamic" because the problem I talked about on July 13th in this thread has not been fixed when using "Visibility.Static"

    Code (CSharp):
    1. private GameObject createLine(List<Vector3> linePoints, string lineName, Color32 color, bool closed, float width)
    2. {
    3.     Material localMaterial = materialMgr.GetLineMaterial(color);
    4.  
    5.     //Create the Vectrosity GameObject/VectorLine
    6.     vectorLine = new VectorLine(lineName, linePoints, 3.0f, LineType.Continuous, Joins.Fill);
    7.     vectorLine.SetWidth(width*2);
    8.     vectorLine.smoothWidth = false;
    9.     if (closed) {
    10.         vectorLine.SetColor(color);
    11.     } else {
    12.         List<Color32> lineColors = new List<Color32>();
    13.         for(int i=0;i< linePoints.Count-2;i++)
    14.         {
    15.             lineColors.Add(color);
    16.         }
    17.         lineColors.Add(new Color32(255, 255, 255, 0));
    18.         vectorLine.SetColors(lineColors);
    19.     }
    20.  
    21.     linkedGameObject = new GameObject(lineName + "_Vectrosity");
    22.     linkedGameObject.isStatic = true;
    23.     VectorManager.useDraw3D = true;
    24.     //Visibility "Static" to use unity visibility events
    25.     VectorManager.ObjectSetup(linkedGameObject, vectorLine, Visibility.Dynamic, Brightness.None);
    26.  
    27.     //Set shared Material to save graphic batches ans passes!
    28.     linkedGameObject.GetComponent<Renderer>().sharedMaterial = localMaterial;
    29.    
    30.     //Cannot acces directly to the requestLine GameObject, so lets find it by name and apply the shared material there.
    31.     GameObject baseVectorLineGameObject = GameObject.Find(lineName);
    32.     baseVectorLineGameObject.GetComponent<Renderer>().sharedMaterial = localMaterial;
    33.    
    34.     return linkedGameObject;
    35. }
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Sorry, by example code, I mean code that I can copy and paste, and test myself. I need to ask for that since I don't experience the issue myself, and I can't usually diagnose problems from just looking at code.

    --Eric
     
  3. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    Well,

    I created an empty scene, with an empty GameObject associated to the following class "Test". There is nothing else in the scene, and no other code.
    If I run the scene, and manipulate it (in Scene mode, select basic GameObjects - MainCamera, DirectionalLight, test, ...- by selecting a zone with the mouse), the error raises when I quit.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Vectrosity;
    5.  
    6. public class Test : MonoBehaviour {
    7.  
    8.     // Use this for initialization
    9.     void Start ()
    10.     {
    11.         List<Vector3> linePoints = new List<Vector3> ();
    12.         linePoints.Add (new Vector3 (2914.0045123393747f, 1787.0870032287519f, -5376.2941460597785f));
    13.         linePoints.Add (new Vector3 (2918.030789800962f,1810.8381263048368f,-5366.153425880996f));
    14.         linePoints.Add (new Vector3 (2945.8572099459197f,1784.6288488774326f,-5359.726314875046f));
    15.         linePoints.Add (new Vector3 (2912.686249892376f,1780.3202462065176f,-5379.252701875517f));
    16.         linePoints.Add (new Vector3 (2905.213568856086f,1750.503204050124f,-5393.061621374702f));
    17.         linePoints.Add (new Vector3 (2890.662285932802f,1791.6545819350665f,-5387.363585996107f));
    18.         linePoints.Add (new Vector3 (2914.0045123393747f,1787.0870032287519f,-5376.2941460597785f));
    19.  
    20.  
    21.         VectorLine vectorLine = new VectorLine("test", linePoints, 3.0f, LineType.Continuous, Joins.Fill);
    22.         vectorLine.SetWidth(20);
    23.         vectorLine.smoothWidth = false;
    24.         vectorLine.SetColor(Color.red);
    25.  
    26.         GameObject linkedGameObject = new GameObject("test_Vectrosity");
    27.         linkedGameObject.isStatic = true;
    28.         VectorManager.useDraw3D = true;
    29.         VectorManager.ObjectSetup(linkedGameObject, vectorLine, Visibility.Dynamic, Brightness.None);
    30.     }
    31.    
    32.     // Update is called once per frame
    33.     void Update () {
    34.        
    35.     }
    36. }
    37.  
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Thank you! I get the error with Vectrosity 5.5, but I'm not getting any errors with my development version, so it looks like this is fixed in the next release (waiting to make sure Unity 2017.2 has settled down).

    --Eric
     
  5. rkosai

    rkosai

    Joined:
    Sep 8, 2017
    Posts:
    3
    Hi Eric,

    I'm Using 2D Vector lines as a paint application on the camera overlay canvas which works great. Is it possible to use vector lines as a mask so it "erases" the lines underneath it? I've looked at your Mask demo which uses an image as a mask, so it seems doable. Any guidance is much appreciated.

    Robert
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Yes, you can add a UI Mask component to a VectorLine, then create another VectorLine and make that a child of the mask line.

    --Eric
     
  7. ilookha

    ilookha

    Joined:
    Sep 25, 2013
    Posts:
    9
    Hi Eric,

    What's the recommended replacement for VectorLine.sortingLayerID removed in Vectrosity 4.0? I'm using 3D lines with multiple cameras, and need to make the lines render between other sorting layers. Getting access to the line's Renderer would probably do the job, but what's the recommended approach?

    Cheers,
    Ilya
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    For 3D lines, setting the Renderer is fine.

    --Eric
     
  9. rkosai

    rkosai

    Joined:
    Sep 8, 2017
    Posts:
    3
    Thanks Eric. I tried it out your suggestion but I'm seeing the opposite effect where the overlapping section is opaque and the rest of the underlying line becomes transparent. Is there a way to invert the Mask?

    Thanks
    Robert




    Code (CSharp):
    1.     void Start () {
    2.         int lineWidth = 20;
    3.         List <Vector2> points = new List<Vector2> (){ new Vector2 (0, 100), new Vector2 (200, 100) };
    4.         VectorLine line1 = new VectorLine("Line1", points, lineWidth, LineType.Continuous, Joins.Fill);
    5.         line1.color = Color.red;
    6.  
    7.         points = new List<Vector2> (){ new Vector2 (100, 200), new Vector2 (100, 0) };
    8.         VectorLine lineMask = new VectorLine("LineMask", points, lineWidth, LineType.Continuous, Joins.Fill);
    9.         lineMask.color = Color.blue;
    10.  
    11.         lineMask.rectTransform.gameObject.AddComponent (typeof(Mask));
    12.         Mask m = lineMask.rectTransform.gameObject.GetComponent<Mask> ();
    13.         m.showMaskGraphic = false;
    14.  
    15.         lineMask.Draw ();
    16.         line1.rectTransform.transform.SetParent(lineMask.rectTransform.transform);
    17.         line1.Draw ();
    18.     }
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Oh, I see what you're saying about erasing lines. That would be the inverse of what the UI mask component does, so I don't think that's possible after all, sorry. (That is, without writing a new UI mask component, although Unity has the source available for the UnityEngine.UI stuff.)

    --Eric
     
  11. ThatBulgarian

    ThatBulgarian

    Joined:
    Jul 2, 2013
    Posts:
    9
    Hi, I dont know if this has been asked before, but is it possible to fill a vectrosity shape? i.e have a circle with a colour fill?
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    No, sorry, Vectrosity is for line-drawing only.

    --Eric
     
  13. rkosai

    rkosai

    Joined:
    Sep 8, 2017
    Posts:
    3
    I'll take a look into that. Thanks much for your quick reply.
     
  14. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Hi Eric
    Last year I asked if you could add to line maker an only connect quads option and also a minimum edge angle (https://forum.unity.com/threads/vectrosity-fast-and-easy-line-drawing.270846/page-38). Were you able to make any progress with this? The connect only quads is particularly important to me.

    Also I think I discovered a bug- if in your camera settings the Viewport Rect is not the standard 0-1 then a canvas set to screen space - camera will not line up.
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    I haven't made any progress with that, sorry. I'm not sure what you mean by "will not line up"? If I set the viewport rect to something like width = .5, the result is what I would expect for that viewport, and I'm not getting any difference between screen space camera and regular overlay.

    --Eric
     
  16. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Width and height work fine but x & y offset don't
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Still not sure what you mean, sorry. X and Y offset changes in ways I would expect given that the viewport is different, and again there are no differences between screen space overlay vs. camera.

    --Eric
     
  18. jl008

    jl008

    Joined:
    Jan 31, 2013
    Posts:
    25
    Hi there,

    I'm trying to combat numerous warning in my project. Can you please address the ones related to your project in next release? (I'm on the latest version of Vectrosity and Unity)

    OnLevelWasLoaded was found on LineManager
    This message has been deprecated and will be removed in a later version of Unity.
    Add a delegate to SceneManager.sceneLoaded instead to get notifications after scene loading has completed

    Assets/Plugins/VectrosityScripts/VectorLine.cs(130,22): warning CS0618: `UnityEngine.CanvasRenderer.SetVertices(UnityEngine.UIVertex[], int)' is obsolete: `UI System now uses meshes. Generate a mesh and use 'SetMesh' instead'

    Assets/Plugins/VectrosityScripts/VectorLine.cs(130,22): warning CS0618: `UnityEngine.CanvasRenderer.SetVertices(UnityEngine.UIVertex[], int)' is obsolete: `UI System now uses meshes. Generate a mesh and use 'SetMesh' instead'
    (the above warning shows 18 times - diff lines in the same class file. )

    Thanks
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Hi, you don't seem to be on the latest version of Vectrosity (5.4.2). Those warnings don't exist; in particular Vectrosity hasn't used CanvasRenderer.SetVertices in a very long time, since that was changed in 5.0.

    --Eric
     
  20. jl008

    jl008

    Joined:
    Jan 31, 2013
    Posts:
    25
    Thanks, I think it was "not removing old folders" trap.
     
  21. nikorenos

    nikorenos

    Joined:
    Jun 12, 2017
    Posts:
    28
    Hello, is this possible to draw ECK/EKG trace and trace of dead man with this asset?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Hi, it will draw lines in whatever shape you want; it's up to you to supply the data. Note that it's intended for constant pixel thickness lines, so if by "trace of dead man" you're referring to paint on the ground in a 3D scene, that wouldn't be appropriate.

    --Eric
     
  23. nikorenos

    nikorenos

    Joined:
    Jun 12, 2017
    Posts:
    28
    No, by trace of dead mean I mean costant line in EKG graph. But there is no such prefab like EKG trace of alive man? I'm not sure if I find out which data should I put.
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    There are some functions for common shapes such as circles, squares, etc., but something like an EKG graph is highly specific that you'd create yourself. You could take a look at a real EKG graph and then enter some 2D coords to make a line that looks similar.

    --Eric
     
  25. nikorenos

    nikorenos

    Joined:
    Jun 12, 2017
    Posts:
    28
    okay thanks
     
  26. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    140
    Hi, I am trying to draw points on a grid on the terrain.

    if I use VectorLine.Draw() the points show up correctly but are not occluded by the 3D objects in the world
    upload_2017-10-9_22-17-25.png


    If I use VectorLine.Draw3D() the points are occluded correctly, but lose visibility when close to the camera.
    upload_2017-10-9_22-19-4.png
    Farther than this distance they show up, closer they are invisible.

    If I raise the points 1 meter off the ground they show up when close to the camera, but then no longer align with the terrain so I don't want to do that.

    What is the solution you recommend?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Probably the best solution is a custom shader. A non-shader solution would be to raycast between each point and the camera and not draw the ones that are occluded, but that might be too CPU-intensive.

    --Eric
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Vectrosity 5.5 is out (and has been submitted to the asset store):

    Changes:
    • The LineMaker utility will use quads instead of triangles if the model has the "keep quads" option checked.
    • VectorLine.MakeWireframe will likewise use quads appropriately.

    Fixes:
    • Using an empty GameObject with VectorManager.ObjectSetup won't cause any errors (the empty GO will automatically have MeshFilter and MeshRenderer components added to it if necessary).
    • Fixed drawing issue with lines using Joins.Weld when drawStart > 0.
    • Fixed drawing issue with discrete lines when drawStart is 1 less than the end.
    • Changing a line's lineType to Discrete or Points will work if using Vector3 points.
    • Fixed null ref error when setting VectorLine.material to null.
    • Fixed error that could occur when adding many points to a line made with LineType.Discrete.
    • Fixed issue with maximum number of points that can be used if the line has end caps.
    • ObjectSetup works without errors in Unity 5.6 when using Visibility.Static.
    • Manipulating a 2D line in the editor scene view while in play mode doesn't cause any errors.

    --Eric
     
  29. gududexiaohai

    gududexiaohai

    Joined:
    Dec 27, 2016
    Posts:
    10
    Hello, I want to ask a question. Could Vectrosity be used to draw 3D line like pipeline?
    Thank you very much.
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    If you mean like this, then no, sorry.

    --Eric
     
  31. niatechnologies

    niatechnologies

    Joined:
    Aug 31, 2017
    Posts:
    1
    Hi Eric, I've been using Vectrosity for couple of years now ..
    For my latest project we need to draw draw lines overlaying a 3d surface (Cross-sectional) lines. But we need to draw them using the zbuffer so the line is not drawn behind the 3d surface.
    Any idea how we can achieve this ?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Hi, the simplest way is to use Draw rather than Draw3D, so the line is drawn on a canvas. Otherwise you could write a custom shader and use that with a material.

    --Eric
     
  33. omx-jonson

    omx-jonson

    Joined:
    Mar 23, 2014
    Posts:
    8
    Hey @Eric5h5
    I build all vectorlines from scripts.
    Unfortunately building levels is quite a pain in editor.
    Is there any way to draw VectroLines in editor?

    That would be such a big help.
    Thanks
    Best
    Mike
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Yes, for 2D lines choose GameObject > UI > VectorLine. For 3D lines there isn't an equivalent, however you can just place models and use them with MakeWireframe.

    --Eric
     
  35. Jo4_

    Jo4_

    Joined:
    Jun 28, 2016
    Posts:
    2
    Hi Eric,

    I'm trying to create vector lines as part of a UI canvas, which works fine with a Screen Space canvas. However, now I need to create a canvas in world space (as part of a VR scene). As far as I understand, Vectrosity is not able to do that, is it?

    Can you recommend any solutions for the creation of vector lines on a world space canvas? The only workaround I can think of right now is to use a RTT camera for the whole UI canvas and apply this resulting texture to a quad in world space (not sure how this affects performance, quality etc)

    Thanks
    Jo
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    World space canvas is not supported, no. That doesn't mean that you can't change the canvas to world space yourself, but you're kinda on your own if you do that. You can use Vector3 world coords in a canvas with Draw just fine, by the way. Also you can use Draw3D and have lines in actual world space, just not on a canvas.

    --Eric
     
  37. jonhillman192

    jonhillman192

    Joined:
    Aug 22, 2013
    Posts:
    1
    Hey Eric, I'm wanting to render 'paths' on a circuit board style 3D level. What I have so far looks great, very easy to work with Vectrosity. When using Draw3D, the line and cap widths change when the display size (sizing the game window) changes – is that expected behavior? And then, if I use Draw (updating on fixed update as the camera moves), the lines don't scale at all, but then they are drawn on top of all geometry in the scene, which I suppose could be solved by changing the shader renderqueue?
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    You can use Draw3DAuto; that way lines are always redrawn. Or else call Draw3D again after the screen size is changed (there's no event, so you need to check screen size every frame). Using Draw is always on top of geometry, since it's on a UI canvas.

    --Eric
     
  39. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    359
    Is it possible to make power lines that hang with a curve with this asset?

    I want to make power lines that have a wire texture and want it to be as light weight as possible. It's ok if its bill boarded....just want an efficient solution.
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    You could, but keep in mind that the line width is designed to be a constant pixel width. Depending on how you're planning on using them, that could be an advantage, since thin lines often tend to break up at a distance. But up close it would look weird. (However you could swap the lines for actual 3D models if approaching closely.) Also you wouldn't really need a texture; they're pretty much just black.

    --Eric
     
  41. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi Eric,

    I'm trying to figure out how to change the sorting order of 3D lines. The documentation mentions how to change a canvas' order, and line drawDepth, but I can't find how to draw a 3D line on top of sprites.

    Thanks!
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    3D lines are just standard meshes in the scene, so everything regarding sorting regular objects also applies. (And nothing regarding canvases.) Namely, you can change things on the renderer like sortingOrderName etc., if you use a material with a shader that uses those, such as the sprite shaders.

    --Eric
     
  43. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Thanks for the response! I can't seem to actually get a line's renderer however. I tried doing a Draw3D before getting it, but I keep getting a MissingComponentException when trying to do:
    Code (CSharp):
    1. _vectorLine.rectTransform.GetComponent<Renderer>().sortingOrder = 40;
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    I can't reproduce the error; what version are you using? Also, you're 100% sure you're using Draw3D? Because you would get that error with Draw.

    --Eric
     
  45. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    I can get it to work if I put it in Update after Draw3D, but using it where I create the line (even if I run Draw3D in between) I get the exception. When is the Renderer component actually added? I'm 100% sure it's something I'm doing wrong, I'm just trying to figure out what.
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    It works in Start or Awake here (Vectrosity 5.5).

    --Eric
     
  47. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Alright, I figured it out. You need to run Draw3D and the line be active before the renderer is added. Thanks!
     
  48. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    597
    I'm looking at re-creating a game that uses Unity's line drawing abilities. The title of this thread is "Vectrosty - Fast and EASY". Is it really easy? I ask because this is page 46 on a help forum. I just want to know before I purchase it.
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    It's been around for well over 7 years, and a lot of the posts are about "will Vectrosity do this" and feature requests. But you can read some of the pages yourself, as well as reviews on the store and my site, and get a better idea. I'd consider it reasonably easy and many people seem to agree. If you don't know how to program, it won't be easy; it's aimed at coders.

    Oh yeah, and it's on sale this week for 50% off. ;)

    --Eric
     
  50. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    597
    Cool I think you just sold it. I used to game program a LONG time ago.