Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. lunstar

    lunstar

    Joined:
    Mar 4, 2015
    Posts:
    8
    How can I use sorting order for vector lines?
    In version 4, I used something like this.

    Code (CSharp):
    1. VectorManager.useDraw3D = true;
    2. VectorLine.canvas.renderMode = RenderMode.WorldSpace;
    3. VectorLine.canvas.sortingLayerName = "Object";
    4. VectorLine.canvas.sortingOrder = 1;
    But after upgrade to version 5, I can't find the way.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use Renderer.sortingOrder; Draw3D lines don't use a canvas.

    --Eric
     
  3. lunstar

    lunstar

    Joined:
    Mar 4, 2015
    Posts:
    8
    Thanks for the reply. I have one more question. ;)

    After read your documentation, I modified my draw3D code snippets.
    This codes are a code that works for character selection ring.

    Code (CSharp):
    1. _selectionRing = newVectorLine ("RINGNAME", linePoints, texture, 3.5f, LineType.Discrete, Joins.Weld);
    2.  
    3. _selectionRing.drawTransform = _transform;
    4. _selectionRing.MakeEllipse (ringPosition, Vector3.forward, 0.85f, 0.45f, segments);
    5. _selectionRing.SetColor (Color.green);
    6. _selectionRing.Draw3DAuto ();
    7.  
    8. // From now on, my newly added codes.
    9. VectorManager.ObjectSetup (gameObject, _selectionRing, Visibility.Dynamic, Brightness.None, false);
    10.  
    11. var go = GameObject.Find ("RINGNAME");
    12. if (go != null) {
    13.     var ren = go.GetComponent<Renderer> ();
    14.     if (ren != null) {
    15.         ren.sortingLayerName = "Object";
    16.         ren.sortingOrder = 10;
    17.     }
    18. }
    It works properly. But I don't know the way to access the automatically generated game object except the I have used GameObject.Find way. Is there a convenient way for this?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.rectTransform.gameObject.

    --Eric
     
  5. fahd

    fahd

    Joined:
    Aug 7, 2014
    Posts:
    31
    in the curve example how to delete one off the point and connect the line to the previous point
    every time i remove point the line still there
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not following what you mean; can you explain in more detail?

    --Eric
     
  7. fahd

    fahd

    Joined:
    Aug 7, 2014
    Posts:
    31
    thanks for the fast reply
    when I do it the anchor point get deleted but the line stays there even after myLine.Draw();
     

    Attached Files:

  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That sounds like it's working as it should, but I don't know what your code is doing. If you don't want the line to exist at all then I imagine you'd go through and delete all the points.

    --Eric
     
  9. fahd

    fahd

    Joined:
    Aug 7, 2014
    Posts:
    31
    i Photoshoped the screen shots im trying to achieve it in code but no luck
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I think I see; deleting an anchor point by itself wouldn't do anything, so the easiest thing would be to recompute the entire line.

    --Eric
     
  11. fahd

    fahd

    Joined:
    Aug 7, 2014
    Posts:
    31
    u mean delete the entire line then create new one and connect it to the rest of existing points is this possible
     
  12. vTrotta

    vTrotta

    Joined:
    Dec 3, 2014
    Posts:
    11
    I got weird artifact when using a welded VectorLine. It's only between points that happened to be close to one another and the problem disappear when I reduce the line width... I did google it but I found only old post talking about this glitch. Is there a way to make things beautiful again? :/
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, just recompute the current line.

    If the problem disappears with a narrower width, that means it's not mathematically possible with the wider width, so there's not really anything else that can be done I'm afraid, aside from moving the points farther apart.

    --Eric
     
  14. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    320
    Hi Eric,

    I need to draw lines between the new UI and 3d gameobjects, and have the start/end point moves with the ui/obj accordingly.
    Is this achievable with Vectrosity? If so, how easy?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Just a matter of using ScreenToWorldPoint, or WorldToScreenPoint, for one of the points, depending on whether you want use a 2D line or a 3D line.

    --Eric
     
  16. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    320
    Lets say I want to draw a 2D line, so I should use WorldToScreenPoint for the gameobject right? How do I get the position of the UI element in screen space? Do I use its recttranform.position? I'm using screen space overlay for my canvas. Because I've tried something like this before with LineRenderer, well lets just say it works weirdly for me (maybe because it uses world space instead of screen space?)

    Thanks :)
     
  17. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Hello!
    Can i make some letters e.g. ABC by your tool with simple funciton?
    For example how to write a B in screen by your function?
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes.

    Assuming screen space - overlay for the canvas, then Transform.position is screen space coords for UI elements.

    There's a MakeText function.

    --Eric
     
  19. junior1nf0

    junior1nf0

    Joined:
    Oct 7, 2015
    Posts:
    1
    Hello Eric,

    I have a question I'm using vectrosity and when i make a LoadLevel to the same scene, the line doesn't work and shows an error :

    Vector object not set up
    UnityEngine.Debug:LogError(Object)
    Vectrosity.VectorLine:LogError(String)
    Vectrosity.VectorLine:get_vectorObject()
    LineManager:LateUpdate()

    Do you know how could I fix it?

    Thanks
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I assume you're trying to draw a line that doesn't exist anymore, so I'd recommend creating new lines when you load a level.

    --Eric
     
  21. rongal

    rongal

    Joined:
    Aug 9, 2015
    Posts:
    7
    Hi, I have a simple question,
    as part of my project I'm creating finite lines that go through various points, up until now I would use vectrosity to draw them but now I've encountered a requirement that I have no idea how to generate using vectrosity, I need to draw the lines in a gradual manner and not at once - to make things more clear, lets say I have a line segment going from point X to Y, on time 0 it will start appearing on point X and then over a certain duration will gradually extend to point Y. I have managed to create a particle implementation of my own that does that but its insanely CPU consuming and the amount of vertices and indices is ridiculous.

    Is there any way I can implement that using vectrosity ?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unless I'm misunderstanding, wouldn't you just have two points, and move the second one from X to Y over time?

    --Eric
     
  23. vTrotta

    vTrotta

    Joined:
    Dec 3, 2014
    Posts:
    11
    I upgraded to Vectrosity 5 and I'm having trouble using materials. The thing is: I need to alter a shader value at runtime.
    But now we can't specify the material in the constructor and calling ".material" on a VectorLine does not act as one would thought. The material's main texture is not applied over the one called in the constructor and modifying it's values at runtime does nothing...

    How can I change shader's value on my lines' material at runtime?
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Code (csharp):
    1. line.rectTransform.GetComponent.<MeshRenderer>().material.[set shader property here]
    The material and texture are separate, so set VectorLine.texture and VectorLine.material.

    --Eric
     
  25. vTrotta

    vTrotta

    Joined:
    Dec 3, 2014
    Posts:
    11
    Is there a way to assign only 1 material instance to many lines? Or do I now need to cycle through all of them to change values uniformly?
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Since material and texture are separate, that means it's an instance of the material assigned to each line.

    --Eric
     
  27. rongal

    rongal

    Joined:
    Aug 9, 2015
    Posts:
    7
    Not exactly as I have more than 2 points on each LineVector yet I did think about using this logic, the situation is as follows:
    I have 30 VectorLines that each has its own array of points , the only way I can think about implementing what I want is if I do the following, for every VectorLine:
    assume the points are - (1,1,1) , (2,2,2) , (3,3,3) , (4,4,4) -
    create a copy of the points array.
    change the points in the original array to (1,1,1) ,(1,1,1), (1,1,1,) ,(1,1,1)
    now I will run a tween on every point in the array except the first towards (2,2,2) (I have that point saved in the duplicate array I made) and use Draw3D on every frame.
    now I have the points array at (1,1,1),(2,2,2),(2,2,2),(2,2,2) and I do the same idea again only with the next position to get
    (1,1,1),(2,2,2),(3,3,3),(3,3,3) and then finally (1,1,1),(2,2,2),(3,3,3),(4,4,4).

    the idea behind this is simple but I wanted to prevent the need to implement all of this myself using something like
    VectorLine.Draw3DOverTime(float duration);
    or something of this sort :)
    Regardless, thanks for the awesome asset, saved me a lot of time and trouble !
     
  28. Someguyblahblah

    Someguyblahblah

    Joined:
    Dec 5, 2012
    Posts:
    1
    Hi Eric,

    Great product. :) My colleagues and I ran into some 65k vertex limit trouble when using VectorLine.Resize(int) on lines with a large number of points. I had a look at the source, and in VectorLine.MaxPoints(), which is used when calculating new array sizes, I think you might've switched the numbers by mistake:

    private int MaxPoints()
    {
    if (this.m_lineType == LineType.Discrete)
    {
    return 16383;
    }
    return 32767;
    }

    I think it looks like those should be the other way around. :) In any case, it appears to help our case if we switch them.

    Thanks for any time spent considering this, and sorry if I got it wrong!
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oops, you're right, sorry about that. Fixed for next version.

    --Eric
     
    hopeful likes this.
  30. Vurawid

    Vurawid

    Joined:
    Nov 17, 2014
    Posts:
    7
    Hi Eric,

    After upgrading from Vectrosity 4.3 to 5, I was having the same problem as @Ninjuit with a line connecting to the origin. I figured out it was due to changing the drawEnd value after calling Draw3D when the line is first created. Some code is included below that reproduces the problem. Sharing in case you want to take a look at it or might be helpful to Ninjuit.

    Code (CSharp):
    1. using UnityEngine;
    2. using Vectrosity;
    3.  
    4. public class OriginArtifact : MonoBehaviour {
    5.  
    6.     private VectorLine newLine;
    7.  
    8.     void Start()
    9.     {
    10.         newLine = new VectorLine("TestCircle", new System.Collections.Generic.List<Vector3>(64), 24.0f, LineType.Continuous, Joins.Weld);
    11.         newLine.MakeCircle(new Vector3(2.7f, 1.8f), 1.3f, newLine.GetSegmentNumber(), Random.Range(0f, 360f));
    12.         newLine.Draw3D();
    13.         newLine.drawEnd = 0;
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         if (newLine.drawEnd < newLine.GetSegmentNumber())
    19.         {
    20.             newLine.drawEnd = Mathf.CeilToInt(Mathf.Lerp(0f, newLine.GetSegmentNumber(), Time.frameCount / 300f));
    21.             newLine.Draw3D();
    22.         }
    23.     }
    24. }
    Otherwise, no issues. Thanks for the great product. :)

    Thank you,
    Steven
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can avoid that by swapping the order of drawEnd and Draw3D in the Start function. (Although it still shouldn't do that regardless, so I'll look into it.)

    Note that you shouldn't use Time.frameCount in Update like that, since that makes the code framerate-dependent.

    --Eric
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OK, that's fixed for the next version.

    --Eric
     
  33. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    Hi Eric! I've upgraded to version 5 and discovered that my animated materials stopped working. The materials are set using line.material = myMaterial. After that some properties of the material are being animated, but the changes are not being reflected in the line. What should I do? Thanks!
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Since the material and texture are separate now, assigning a material makes it an instance. You can use line.rectTransform.GetComponent(Renderer).material to animate the instance on a line.

    --Eric
     
  35. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    Wow! Thank you. Amazingly fast response
     
  36. TheOz

    TheOz

    Joined:
    May 21, 2011
    Posts:
    34
    Hi Eric,

    I plan to use Vectrosity 5 to mock up vector based CRT screens as special effects in an Indie Film called Moon Shot, currently on Indigogo.com. @MoonshotMovie on twitter.

    Is there an easy way to generate text drawn by Vectorsity? Could you point me to a good example.
    (it would be cool to see Vectrosity mentioned in the credits)

    Garry@crazybeardentertainment.com
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the MakeText function. (And yes it would be cool!)

    --Eric
     
  38. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Hey, I'm trying to draw a line that follows the player in a 'snake' esque fashion, but I'm running into a problem. The logic I'm using in the code is that I'm referring to a single point in the line and moving that point to the position of the point that comes after it in the 'points2' list. I treat the position of the last point in the line as a special case and move it to the position of the player. Here's the code:
    Code (CSharp):
    1.     void FixedUpdate ()
    2.     {
    3.         Vector2 playerPosition = leftPlayer.transform.position;
    4.      
    5.         //Debug.Log(PlayerHasMoved(playerPosition, line));
    6.      
    7.         if(PlayerHasMoved(playerPosition, line))
    8.         {
    9.             if(linePts >= maxLineLength)
    10.             {
    11.                 line = DrawShortLine(playerPosition, line);
    12.                 line.Draw();
    13.             }
    14.             else
    15.             {
    16.                 line.points2.Add(playerPosition);
    17.                 line.Draw();
    18.                 linePts++;
    19.             }
    20.         }
    21.     }
    22.  
    23.     bool PlayerHasMoved (Vector2 playerPosition, VectorLine line)
    24.     {
    25.         Vector2 lastPoint = line.points2[line.points2.Count - 1];
    26.      
    27.         //Debug.Log(Mathf.Abs(playerPosition.x - lastPoint.x));
    28.      
    29.         if(Mathf.Abs(playerPosition.x - lastPoint.x) > 0.01f
    30.            || Mathf.Abs(playerPosition.y - lastPoint.y) > 0.01f)
    31.         {
    32.             return true;
    33.         }
    34.         return false;
    35.     }
    36.  
    37.     VectorLine DrawShortLine (Vector2 playerPosition, VectorLine line)
    38.     {
    39.         int lastIndex = line.points2.Count - 1;
    40.      
    41.         for(int i = 0; i <= lastIndex; i++)
    42.         {
    43.             Vector2 point = line.points2[i];
    44.          
    45.             if(i < lastIndex)
    46.             {
    47.                 Vector2 nextPoint = line.points2[i+1];
    48.                 point.x = nextPoint.x;
    49.                 point.y = nextPoint.y;
    50.             }
    51.             else
    52.             {
    53.                 point.x = playerPosition.x;
    54.                 point.y = playerPosition.y;
    55.                 //Debug.Log("Point: " + point);
    56.                 //Debug.Log("Player: " + playerPosition);
    57.             }
    58.         }
    59.         return line;
    60.     }
    This bit of code stops drawing the line instantly after we hit the maximum amount of line points, which I have at 25 at the moment. When I print out the difference between the last point's X and player's X, it is a value way over 0.01, at the point where the line first stopped after reaching the maximum amount of points. On the other hand, when I print out the Vector2 values from the 'DrawShortLine', the last point is exactly at the position of the player. What could I be doing wrong here? Thanks!
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Some things: VectorLine is a reference type, so DrawShortLine shouldn't return anything. You make a "point" variable in that function, but you don't do anything with it. Also, wouldn't you just use RemoveAt with the line points list rather than manually copying points?

    --Eric
     
  40. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    All good points! You're right, RemoveAt is probably a much better solution. I'll redo some of the code tomorrow.
     
  41. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    Hey Eric! I'm using the new version of Vectrosity and Unity 5.2.1p3.

    I'm using two transforms to create a line, but when I delete those lines I still have these two points remaining in my scene. In the previously version I didn't have that problem and I read the documentation and looks like is because the lines is not longer use a canvas.

    Code (CSharp):
    1.  
    2.         myLine = new VectorLine("Coleira", new List<Vector3>(), corda, 2.5f);
    3.         myLine.points3.Add (new Vector3(0,0,0));
    4.         myLine.points3.Add (new Vector3(0,0,0));
    5.  
    6.         void Update()
    7.         {
    8.             myLine.points3[0] = gameObjectA.transform.position;
    9.             myLine.points3[1] = gameObjectB.transform.position;
    10.             myLine.Draw3D
    11.          
    12.             if (condition == true)
    13.             {
    14.                VectorLine.Destroy(ref myLine, gameObject);
    15.             }
    16.         }
    17.  
    How can I delete these two points that stays remaining in my scene after delete the lines Eric? Because that same code works in the previously version of Vectrosity but not in the new one. =/

    Thanks!
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, unfortunately I don't really know what you mean. Using VectorLine.Destroy removes the VectorLine and doesn't leave anything behind. It doesn't remove anything else aside from the VectorLine (and whatever GameObject you might additionally pass in), but it never did. Also I'm not sure how this is related to using a canvas. Just to be sure I tested VectorLine.Destroy again and it works as expected.

    --Eric
     
  43. Mareck

    Mareck

    Joined:
    Aug 13, 2014
    Posts:
    77
    Hi, I am using vectrosity to draw gridlines to a orthographic (very large) world which you can zoom out and pan (I do this by moving the camera around. Objects like the vector lines are retrieved and drawn only when the camera is about to see them).

    The method I use for the vector lines: I first create the vectorline object with an empty list of points. Then set the vectorcanvas to worldspace. Each time the camera moves or changes zoom I determine if I need to refresh the lines. If so I remove the existing points and add new ones and call the draw() function.

    I don't do anything at all with the vectorcanvas. I just let it sit where it is created. (The result of this is that the lines are drawn outside the canvas as shown in the editor.)

    With version 4 of vectrosity this worked perfectly. With version 5 however it ONLY works when the vectorcanvas is in the camera viewport. When you move outside it all the vector lines disappear. When you move the camera back they reappear. This happens whether .draw() hasn't been called or not in that frame.

    Any ideas why this is happening or how I can fix this?
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Might have something to do with the mesh bounds, which are computed to be the size of the screen. Vectrosity 4 didn't use meshes as such, so that wasn't an issue, but in Unity 5.2, if the bounds aren't supplied, things go rather severely wrong for some reason. You could change the SetMeshBounds function in the VectorObject2D script so the bounds are larger.

    However, note that Vectrosity 5 doesn't support changing the canvas to world space. I'd suggest using Draw3D, so there is no canvas, instead.

    --Eric
     
  45. Mareck

    Mareck

    Joined:
    Aug 13, 2014
    Posts:
    77
    Thanks for your quick answer! Removing the bounds doesn't seem to do anything and Increasing the bounds crashes Unity (which in turn crashes my whole computer for some reason :)

    I have solved it for now by setting the bounds of the mesh of the VectorObject2D from my own cameracontroller script whenever the camera moves (linesObject.m_mesh.bounds = new Bounds(Camera.main.transform.position, new Vector3(Screen.width, Screen.height, 0))).

    The world space thing was a quick hack that happened to work so well I forgot about it till I upgraded to version 5 of Vectrosity. Do you think there is a significant a performance difference between using draw3d and 2d? (We are targeting mobiles so every bit of performance is welcome)
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's some difference but I don't know how significant; the best thing to do would be to use the profiler.

    --Eric
     
  47. gegabal

    gegabal

    Joined:
    Sep 3, 2014
    Posts:
    2
    HI. I Use Version 3

    1-pixel line in the options you can apply a texture painted line?
    I am trying to draw a dashed line in MeshTopology.Line.
    And it is implemented in the AutoCAD line style.

     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    1-pixel lines can't have a texture. You can either make the line segments physically separated using discrete lines, or use a wider line that has a texture (the texture doesn't have to be the full width of the line).

    --Eric
     
  49. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    314
    Hi,
    updated from Vectrosity 4 to 5 and using 5.1.2p4.

    I create a bunch of VectorLines and save them in a List, then fade them in over time by setting the color of each VectorLine. This used to work before, but now results in the lines being invisible every other frame.

    I also now get an error saying "MissingReferenceException: The object of type 'VectorObject2D' has been destroyed but you are still trying to access it." the first time I try to change a line color. Tried waiting a couple frames but it didn't help.

    Any ideas where to start looking?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I would have to know what your code is doing. This works fine, for example:

    Code (javascript):
    1. function Start () {
    2.     var line = new VectorLine("Test", new List.<Vector2>([Vector2(50, 50), Vector2(500, 500)]), 4.0);
    3.     line.Draw();
    4.     var color = Color.white;
    5.     for (var i = 0.0; i < 1.0; i += Time.deltaTime) {
    6.         color.a = i;
    7.         line.color = color;
    8.         yield;
    9.     }
    10. }
    --Eric