Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    My example line was 4 pixels + padding, but you put space between the end cap and the line. The end cap should not have padding on the side that connects to the line (just the other sides).

    --Eric
     
  2. nowletsstart

    nowletsstart

    Joined:
    Jan 1, 2016
    Posts:
    78
    I am interested in purchasing Vectrosity. Basically I need to create a photoshop/illustrator like editor pen tool with the line renderer for personal use.
    Is there a UI editor tool for MakeCurve and MakeSpline similar to that of VectorLine UI tool? If not, is there a way I can extend VectorLine UI tool to include them?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thank you for your interest! There isn't an editor tool for curves as such, but there is a curve demo which you could adapt.

    --Eric
     
  4. nowletsstart

    nowletsstart

    Joined:
    Jan 1, 2016
    Posts:
    78
    Thanks the Curve demo is a great starting point to make the editor tool I need. Do you have any similar demos on splines? I searched around for sample projects but didn't find any Vectrosity spline sample code.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The MakeSpline and SplineFollow scripts demonstrate spline drawing.

    --Eric
     
  6. ShrishGour

    ShrishGour

    Joined:
    Jul 29, 2014
    Posts:
    1
    How can I make continues Line collide with each other at runtime? Also, how can I add a rigidbody to a vectorLine?
    Ultimately I want to create line like "Brain it on" game.
    Thank You.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    See here for line collider/rigidbody discussion.

    --Eric
     
  8. Dgreenny

    Dgreenny

    Joined:
    Aug 23, 2013
    Posts:
    2
    This looks like a great plugin and am interested in using it for my project but I do have a question - and sorry if this has already been discussed or covered in the docs. I would like to draw a curved path and have an object follow the path (the full path is always shown) using a scrub control in the UI. Basically, I want to get an XYZ value on the path given a time (0 to 1 second). Is this possible?
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, there's a GetPoint01 function which does that, or GetPoint3D01 in this case since you mention XYZ.

    --Eric
     
  10. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi Eric, I was having issues with sortingOrder seemingly not working, and finally figured out that all lines are created on the UI layer. It's not mentioned anywhere in the coding documentation (that I can find), might be worth flagging it somewhere?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The docs do cover lines being created on a canvas (except for 3D lines), which I think covers that? Specifically the "Canvas and Camera" section. I could clarify that since lines are created on a canvas (aside from 3D lines), that necessarily means they are subject to the same rules as everything else on a canvas.

    --Eric
     
  12. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    I'm actually talking about 3D lines. But I suppose what you've said makes sense, maybe it should be easily deduced by most people?
     
  13. BlisterFingers

    BlisterFingers

    Joined:
    Sep 2, 2015
    Posts:
    11
    I need my lines to be a fixed size in world space rather than the default fixed pixel size. However, when I do that and zoom my camera into the line I can see small gaps between segments which look like filtering artifacts.



    The filtering method used on the texture actually makes little difference. Here's the texture. (A white texture wouldn't show up on a white background.)

    To keep the line width a fixed world size I'm using the following code in update.
    Code (csharp):
    1. lineWidth = (1f / cam.orthographicSize) * 100f
    I'm using multiple segments so I can animate the drawEnd property.

    Am I doing it wrong or is Vectrosity simply not meant for this?

    Thanks.
     
  14. nowletsstart

    nowletsstart

    Joined:
    Jan 1, 2016
    Posts:
    78
    How can I draw/animate the following line over a specific duration, say 3 seconds? I've seen the AnimatePartialLine example but this seems to be beating me.

    Code (CSharp):
    1. var linePoints = new List<Vector2>(){new Vector2(20, 30), new Vector2(200, 300)};
    2.     VectorLine myLine = new VectorLine("Line", linePoints, 2.0f);
    3.     myLine.Draw();
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I used your texture and wasn't able to reproduce the problem:

    pic1.png
    pic2.png

    There aren't any gaps in the mesh, and the texture is used as-is, so I'm not really sure what to suggest. I tried various texture settings and that didn't change anything. It does look like a problem with the texture, though; maybe some compression setting introduces a transparency artifact, though the usual ones worked fine here.

    To use the AnimatePartialLine method (where it changes drawStart/drawEnd values), you'd need a lot more segments in the line. Alternately, with just a single straight segment like that, you could just move one of the points over time, such as by using Lerp.

    --Eric
     
  16. WillBeMe

    WillBeMe

    Joined:
    Jan 24, 2018
    Posts:
    14
    Interestingly, I am also trying to animate a line like nowletsstart's posts. I am fairly new to Unity and Vectrosity. I would more than appreciate a code example of how I'd animate or draw a line using Lerp and possibly a coroutine as you recommended for nowletsstart. I believe it would help a lot of people who may be looking for a similar solution using Vectrosity in the future.
     
    nowletsstart and feelsaul like this.
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Animating a point with Lerp is just standard Unity stuff, not specific to Vectrosity, but:

    Code (csharp):
    1.     IEnumerator Start () {
    2.         var point = Vector3.zero;
    3.         var start = Vector3.zero;
    4.         var end = Vector3.one;
    5.         var duration = 3.0f;
    6.         var t = 0.0f;
    7.         while (t < 1.0f) {
    8.             t += Time.deltaTime / duration;
    9.             point = Vector3.Lerp (start, end, t);
    10.             yield return null;
    11.         }
    12.     }
    --Eric
     
  18. WillBeMe

    WillBeMe

    Joined:
    Jan 24, 2018
    Posts:
    14
    Thanks a lot.

    I ended up creating the animating line in the following way, based on your code.

    Code (CSharp):
    1. IEnumerator Animate () {
    2.         yield return new WaitForSeconds(2f);
    3.  
    4.         var point = Vector2.zero;
    5.         var start = new Vector2(80, 45);
    6.         var end = new Vector2(250, 300);
    7.         var duration = 3.0f;
    8.         var t = 0.0f;
    9.         while (t < 1.0f) {
    10.             t += Time.deltaTime / duration;
    11.             var linePoints = new List<Vector2>(){start,  Vector2.Lerp (start, end, t)};
    12.  
    13.             myLine = new VectorLine("Line", linePoints, 2.0f);
    14.             myLine.Draw();
    15.             yield return null;
    16.         }
    17.     }
    This creates several lines instead of updating one. How can I fix this?
     
  19. WillBeMe

    WillBeMe

    Joined:
    Jan 24, 2018
    Posts:
    14
    I am trying to rotate a VectorLine using the following code:

    Code (CSharp):
    1. public class LineRotationTest : MonoBehaviour {
    2.  
    3. bool rotating = false;
    4.  
    5. VectorLine topLeft;
    6.  
    7. // Use this for initialization
    8. void Start () {
    9.  
    10.     var topLeftPoints = new List<Vector2>(){new Vector2(Screen.width/2 - 100, Screen.height/2), new Vector2(Screen.width/2, Screen.height/2 + 100)};
    11.  
    12.     topLeft = new VectorLine("Line", topLeftPoints, 2.0f);
    13.     topLeft.Draw();
    14.  
    15.     StartCoroutine (rotatingLines ());
    16. }
    17.  
    18. IEnumerator rotateVectorLine(VectorLine vLine, Vector3 eulerAngles, float duration)
    19. {
    20.     if (rotating)
    21.     {
    22.         yield break;
    23.     }
    24.     rotating = true;
    25.  
    26.     Vector3 newRot = vLine.drawTransform.eulerAngles + eulerAngles;
    27.  
    28.     Vector3 currentRot = vLine.drawTransform.eulerAngles;
    29.  
    30.     float counter = 0;
    31.     while (counter < duration)
    32.     {
    33.         counter += Time.deltaTime;
    34.         vLine.drawTransform.Rotate(Vector3.Lerp(currentRot, newRot, counter / duration));
    35.         yield return null;
    36.     }
    37.     rotating = false;
    38. }
    39.  
    40.  
    41. IEnumerator rotatingLines   ()  {
    42.     Vector3 newRot = new Vector3(0, 0, 45);
    43.  
    44.     yield return new WaitForSeconds(2f);
    45.  
    46.     StartCoroutine(rotateVectorLine(topLeft, newRot, 2.0f));
    47. }
    I keep getting the error:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. LineRotationTest+<rotateVectorLine>c__Iterator0.MoveNext () (at Assets/LineRotationTest.cs:30)
    at the line:

    Code (CSharp):
    1. Vector3 newRot = vLine.drawTransform.eulerAngles + eulerAngles;
    The line appears on as it should but doesn't rotate. How can I solve this?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're creating a new line every iteration of the loop. The line should be created only once (outside the loop), also the linePoints list should be created once. Just update the appropriate point in the list.

    The drawTransform won't exist yet if you access the line the same frame it's created, so wait a frame.

    --Eric
     
  21. samifruit514

    samifruit514

    Joined:
    Mar 27, 2015
    Posts:
    30
    I have a straight line with 2 points. I would like the width to be 1 at the startpoint and 300 at the endpoints but the width is the same for the whole length.

    heres my code:

    Code (CSharp):
    1.  
    2. line = new VectorLine("Line",new List<Vector3>(),2.0f,LineType.Continuous);
    3. ...
    4. line.points3[0] = transform.position;
    5. line.points3[1] = rh.point;
    6.  
    7.  
    8. line.SetWidths(new List<float>() { 50});
    9. line.smoothWidth = true;
    10. line.Draw3D();
    any clue why?
     
  22. WillBeMe

    WillBeMe

    Joined:
    Jan 24, 2018
    Posts:
    14
    Thanks, I've been able to solve the repeated lines issue with animating the line. Just that the line looks jagged.

    About the rotation, the code I provided had a two second waitForSeconds before trying to access the VectorLine's eulerAngle, I am accessing it in a different frame already.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Line widths are per-segment, not per-point. So it's not possible to have varying widths with only 2 points; you need at least 3.

    Actually I see the problem; VectorLine.drawTransform is for assigning a transform to a VectorLine. You rotate the transform the usual way, not by manipulating VectorLine.drawTransform.

    --Eric
     
  24. WillBeMe

    WillBeMe

    Joined:
    Jan 24, 2018
    Posts:
    14
    The only way I can get the rotation property is through the transform property. How am I suppose to get it from the VectorLine? To be honest, I've tried rotating a Line Renderer on a number of occasions and haven't gotten anywhere with finding a solution.
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use drawTransform to assign a transform, and rotate that transform. It's fine if that's just an empty GO. You can't rotate lines directly (well, you can, but in most cases you should not).

    --Eric
     
  26. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi there!

    Is it possible to use a material with multiple textures, and offset the textures/set whether they're stretched across the line or per segment individually?

    Thanks!
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry, one texture per line.

    --Eric
     
  28. quanjunchen

    quanjunchen

    Joined:
    Oct 12, 2017
    Posts:
    4
    Memory leak in demo Highlight scene. It seems that VectorLine leaks
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, the only GC allocation (not a leak anyway) is from GUI.Repaint. VectorLine has no leaks. Creating a new VectorLine does some allocation necessarily, but again not a leak.

    --Eric

    Screen Shot 2018-01-30 at 5.01.19 AM.png
     
  30. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oh, sorry, you said a material with multiple textures, not a line with multiple textures. You can actually assign a material to a line, and you also assign a texture, which is set to the material's mainTexture, but the other textures wouldn't be affected, so your code should translate. Instead of using renderer.material, you'd instantiate the material, assign it to the line, then refer to the instantiated material.

    --Eric
     
  32. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Oh excellent, yep, that seems to be working! However VectorLine.color isn't. Is there something easily discernable with the shader that would cause the line colour to not work?

    https://pastebin.com/3FuPqGnX
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The shader needs to use vertex colors.

    --Eric
     
  34. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Alright, I will try to find someone to convert that for me! Is there anyway to rotate points? Or the texture on a point line?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Points and textures can't be rotated, sorry.

    --Eric
     
  36. quanjunchen

    quanjunchen

    Joined:
    Oct 12, 2017
    Posts:
    4
    Run the highlight scene, at first Enegy only use 78k, but after a while it increases to 200M. And it continues to increase almost 1M per second.
    But it seems to leak in editor

    -------UPDATE------
    It seems only happend in 2017.1. In 2017.3 this problem fixed
     

    Attached Files:

    • 111.png
      111.png
      File size:
      81.7 KB
      Views:
      847
    • 222.png
      222.png
      File size:
      25.1 KB
      Views:
      823
    • 333.png
      333.png
      File size:
      21.8 KB
      Views:
      816
    Last edited: Jan 31, 2018
  37. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Hi Eric, I'm loving the quads option that you implemented, thank you!

    Would you consider adding this feature- giving lines normals taken from the mesh that was used to generate it. Then when the line's normal is pointing away from camera you could have it not render.

    I saw the AddNormal option but I presume this is doing something else as it didn't do the trick (also when I did that and didn't use Draw3D I got StackOverflowException).
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity only renders facing the camera, and lines have no orientation info, so lines can't take (presumably surface) normals from the mesh, sorry. As the reference guide says about AddNormals, "This should be called when a material that has a shader which requires normals is used for the VectorLine." This refers to mesh/lighting normals. I was able to reproduce the error if AddNormals was used before Draw, but if you call it after Draw, it works. I fixed the problem, though AddNormals isn't really anything you'd ever use for Draw, only Draw3D.

    --Eric
     
  39. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Would it be possible for Vecrosity to store a vector for each line segment that's an average of the normals of the two points that created it, and then have Vectrosity decide whether of not render the segment depending if that vector is facing the camera? It could be a lot more elegant and faster than using Draw3D and putting black meshes inside the vector object.
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It could be possible, but Vectrosity wasn't designed for that so it's not likely to happen. However you do have the source, so if it's important you can make that alteration.

    --Eric
     
  41. MikaelWallinP

    MikaelWallinP

    Joined:
    Jan 8, 2018
    Posts:
    2
    I have multiple Viewports for that I use Cameras that render into RenderTextures. The RenderTextures are displayed on the UI in a RawImage.

    I want to render a few 3D lines to all Viewports. If I use SetCamera3D then it will only render in the last set camera. How would I approach this? Should I project into 2D space and use a 2D Canvas line instead or have I missed something?
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use multiple lines (that use the same points list; the points list is a reference), one for each camera. Then for each line, call SetCamera3D with the desired camera, followed by Draw3D.

    --Eric
     
  43. MikaelWallinP

    MikaelWallinP

    Joined:
    Jan 8, 2018
    Posts:
    2
    Worked like a charm, thank you! Might I suggest that you make another non static function for SetCamera3D to set on the VectorLine.
     
  44. param_appm

    param_appm

    Joined:
    Jun 14, 2017
    Posts:
    41
    I am working on a Project, where I want to rotate the labels with Text.

    Here is example of what I would like to achieve:
    Link:


    The Lines associated with Labels changes size of Lines and move with Camera Movements.

    I saw your Plugin, Vecrosity :
    https://assetstore.unity.com/packages/tools/particles-effects/vectrosity-82

    Just wondering if this plugin can be used to rotate the Lines & Labels with Camera Movement.
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that would be pretty simple, for each line just supply the appropriate two points in world space (one for the label and one for the model).

    --Eric
     
  46. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    655
    Hi, @Eric5h5
    I've been using Vectrosity for a while. Still great, thanks.
    2 quick-ish things:

    1. May I suggest a tweak to VectorLine.cs to move in SetupLine(), move "name" assignment from line 681 to before the SetVertexCount() call. That way the LogError() on line 1039 has the "name" value assigned.

    2. I've run into the "exceeded maximum vertex count" problem. I wanted to check there isn't an automated solution to this? I'm drawing an ellipse for an orbit and I just scaled up my simulation and hit the problem. I can code around it but hey, if there's already a 'thing' then :)

    Thanks!
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    1. That makes sense.
    2. After I did an update for ObjReader that uses 32-bit vertex indices for meshes with Unity 2017.3, I was thinking I might do the same for Vectrosity, but then I was kind of wondering if anyone would actually want that. Guess that answers that question. ;)

    --Eric
     
    Arkade likes this.
  48. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    655
    Seems like a good idea. My only question would be what negative side-effects there are, e.g. how much it affects performance?
    I'm using this in mobile VR so it's one of those ”every drop I can squeeze” situations.
    Thanks for replying!
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I doubt 32-bit indices are slower than 16-bit on modern hardware, but even if they are, it's balanced by not having to use multiple meshes.

    --Eric
     
    Arkade likes this.
  50. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    655
    I hope so.
    I'm currently chasing a performance problem in my mobile VR game. It's not conclusive yet (I'm still trying to tie it down) but Vectrosity's Draw3D() is currently looking like the top offender and it's the bit line ones that are the problem. I already only call it manually periodically (every 0.5 seconds and spread out a bit).

    Obviously one solution to this might be breaking the offending lines into smaller pieces and do less per frame.

    This leads to an obvious question: for those like me who want to compromise visual accuracy for performance, is there already a way to achieve this? If not, could there be? The obvious example solution that springs to my mind is having a facility to do line updating in a coroutine that does some (user-customizable) number of points per frame. Better yet, perhaps some of this could be done off the main thread? Brighter minds than mine might have even better ideas?

    Thanks in advance for any thoughts :)