Search Unity

  1. 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. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    You are re-running it, by loading the level again. The code must only run once.

    --Eric
     
    shayan_315 likes this.
  2. HoangAnh Nguyen

    HoangAnh Nguyen

    Joined:
    Mar 2, 2015
    Posts:
    4
    Hi Eric!
    I'm using MakeSpline to draw prediction path for my object. I want to remove part of the prediction path when my object pass it. How can i do it?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    One way would be to use SetColor with a transparent color, so the line segments are technically still there, but invisible. To get the segment number to use for SetColor, GetPoint has an overload where you supply an out value for the index.

    --Eric
     
    HoangAnh Nguyen likes this.
  4. DanielKhoroshko

    DanielKhoroshko

    Joined:
    Mar 11, 2015
    Posts:
    9
    Hello guys

    Could someone please tell me if it is possible to smoothly fade out a textured line and how? I don't mean distance clipping here..
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Change VectorLine.color.a over time.

    --Eric
     
  6. DanielKhoroshko

    DanielKhoroshko

    Joined:
    Mar 11, 2015
    Posts:
    9
    Hi Eric.
    Thank you for reply, but unfortunately I think I didnt make myself clear. I mean something like this:
    Should I use some kind of vertex shader?
     
  7. HoangAnh Nguyen

    HoangAnh Nguyen

    Joined:
    Mar 2, 2015
    Posts:
    4
    Thank you so much! :)
     
  8. DanielKhoroshko

    DanielKhoroshko

    Joined:
    Mar 11, 2015
    Posts:
    9
    Finally, I got it! Sprites/Default shader fits nice for this purpose
     
  9. DanielKhoroshko

    DanielKhoroshko

    Joined:
    Mar 11, 2015
    Posts:
    9
    No it doesnt work :(
    Fading out along the length of a textured line, can this be achieved? Thanks a lot
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Use SetColors with an appropriate Color[] array, or use SetColor to set the desired color for each segment individually.

    --Eric
     
  11. Landci

    Landci

    Joined:
    Aug 28, 2012
    Posts:
    31
    Hello, just got your asset yesterday, it is really helpful so far.

    One Question:
    Is it possible to add a text at the end caps?

    I would like to make the paylines in a slot machine with your tool.
    Showing a number at the start and end point of the line.
     
  12. auroxi

    auroxi

    Joined:
    Dec 31, 2012
    Posts:
    82
    Hi Eric,

    Could you explain what the best way is to clear every single object drawn by Vectrosity in a Scene? Not sure if I'm missing a function somewhere or something.

    Thanks
     
  13. HoangAnh Nguyen

    HoangAnh Nguyen

    Joined:
    Mar 2, 2015
    Posts:
    4
    Hi Eric,
    I have one more question. Is there any way to add collider for each segment of the spline?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    You can either use textures with numbers baked into them, or use the UI to position numbers on top of lines.

    Have a List<VectorLine> and add each line to it, then use VectorLine.Destroy with the list.

    VectorLine.collider will make a 2D collider for the line. It won't be a separate collider for each segment, but rather an edge collider or a polygon collider (depending on the type of line).

    --Eric
     
    HoangAnh Nguyen likes this.
  15. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    390
    I'm having a bit of trouble getting a line to render on top of the uGUI system. I have changed the sorting layer of both the canvas but it doesn't seem to make the line go on top of the uGUI. What am I missing?
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    The canvas has to be in world space in order to interact with other objects in the scene; otherwise (in screen space) it renders as an overlay.

    --Eric
     
  17. HoangAnh Nguyen

    HoangAnh Nguyen

    Joined:
    Mar 2, 2015
    Posts:
    4
    Hi Eric!
    Is it impossible to get segment position of VectorLine?
    thank you in advance!
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    I don't really understand the question, sorry.

    --Eric
     
    HoangAnh Nguyen likes this.
  19. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    390
    How do I get the conversion from the canvas to the main world space? Alternatively how do I set the canvas to match the main camera?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    If you use 3D points, they're in world space, so it works automatically.

    --Eric
     
  21. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    390
    So I would just pass a Vector3 list of points instead of a vector 2?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    --Eric
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Version 4.2 is out (and submitted to the asset store):

    Changes:
    • VectorLine.SetColors now uses a Color32[] array or List<Color32>, instead of a Color[] array or List<Color>, which improves performance.
    • VectorLine.SetColor also uses Color32 instead of Color.
    • VectorLine.color also uses Color32 instead of Color.

    Fixes:
    • Setting VectorLine.color works if there are no points added to the line yet and the line has end caps.
    • Fixed certain cases where 3D line segments were incorrectly drawing when they should be behind the camera.

    --Eric
     
  24. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    I use Vectrosity 3.1. I want to save my project on android devices.
    It consists of different 2D objects and Vectrosity lines and circles
    and so on.
    What is the best way to save them on android. Serialize is
    a good way?
     
  25. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    Heya, I'm wondering.. Is it possible to save a drawn freehand line and draw it from memory over a new scene in runtime through script?
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    There are many different ways, but a simple way is to use the LineMaker editor and save the lines in files, which are included in the project.

    Sure...you have the points in the line, so you can store those in a list, and use DontDestroyOnLoad.

    --Eric
     
  27. DanielKhoroshko

    DanielKhoroshko

    Joined:
    Mar 11, 2015
    Posts:
    9

    Hi Eric. Thank you for you previous answer, but it doesn't solve the problem unfortunately.
    Transparency that is set through Colors[] alpha channel only seems to be working when _no_ material is set to the VectorLine, just plain colors.
    Once I set right material, Colors[] do nothing. I have tried all standart shaders already.

    But I'm pretty sure it is possible to set lines like this





    Any help is appreciated. Thanks a lot
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    You'd need a material with a shader that uses vertex colors.

    --Eric
     
  29. Jhwaa

    Jhwaa

    Joined:
    Dec 5, 2014
    Posts:
    2
    about VectorPoints's Scale not variation in Z
    code:


    pp=new VectorPoints("pp", linePointsp, pColors, PMaterial, Random.Range(10,20));

    pp.Draw3DAuto();



    way the points scale aways same,no variation.

    i want the points scale have size change in z,help!!

    unity4.6 Vectrosity3
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    I'm not really sure what you're asking; can you explain some more?

    --Eric
     
  31. Bearabeck

    Bearabeck

    Joined:
    Mar 3, 2015
    Posts:
    4
    Hi Eric, I'm considering buying Vectrosity and I have a question about a certain kind of effect. In the OP you say that it's fast because lines only have to be updated when they change. So how expensive is it to create an effect that involves changing the line every frame? What if I wanted to created a simple ripple effect that involves drawing circles and then expanding them? Would this be expensive enough to cause problems for a mobile game?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    It would depend on how many circles, and how many points in each circle. If it's a moderate number of both, there shouldn't be any issues (especially since mobile CPUs these days are fairly powerful).

    --Eric
     
  33. Bearabeck

    Bearabeck

    Joined:
    Mar 3, 2015
    Posts:
    4
    I was thinking I'd need about 20ish circles at most, and they'd have a glow effect that I think would help break up the line segments. Sounds like I should be fine.
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yep, seems reasonable enough.

    --Eric
     
  35. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    Would it be possible to select a certain point in the line with mouse and remove it with a click, dividing the line in two? And would that divide the collider as well?
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    VectorLine.Selected will tell you the index of the segment that was clicked, so yes, you can use that information to either create two separate lines or just remove that particular segment (in which case the line would need to be LineType.Discrete).

    --Eric
     
  37. russelljahn

    russelljahn

    Joined:
    Jul 2, 2012
    Posts:
    3
    Hi Eric,

    In a future version, would it be possible to expose a property for VectorLine to check if it uses 2D or 3D points? m_is2D is private, and both points2 and points3 throw errors if you wanted to check that way via the unused points List. Basically just add:
    Code (CSharp):
    1. public bool is2D { get { return m_is2D; } }
    Our project uses lots of both screen space and world space lines, and this would be very helpful in a few contexts.

    Vectrosity is a really awesome framework, btw!
     
    Last edited: Apr 28, 2015
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    OK, that's reasonable.

    --Eric
     
  39. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Hi Eric,

    just a quick not that using Vectrosity 4.1.3, UnityScript, and given
    Code (csharp):
    1. private var lines : Dictionary.<int,VectorLine> = new Dictionary.<int,VectorLine>();
    the following:
    Code (csharp):
    1. if (lines.ContainsKey(i)) {
    2.   VectorLine.Destroy(lines[i]);
    3. }
    results in:

    Assets/Scripts/EventManage.js(1119,60): BCE0127: A ref or out argument must be an lvalue: 'self.lines.get_Item(i)'

    instead i need to do:

    Code (csharp):
    1. var kill = lines[i];
    2. VectorLine.Destroy(kill);
    no problem really, just a bit odd...

    best, georg.
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, that's how Unity/Mono works with reference types.

    --Eric
     
  41. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    I created a script which where the 'line' variable is a VectorLine[] array, each drawn line saved into a separate slot of the array. Then I'm attempting to put those VectorLine arrays into another int array which index increases by one on each restart of the scene. So, all lines would be saved in separate slots and all of the lines created in one play are stored into another array. Here's a picture to illustrate: http://i.imgur.com/XxgjjXh.png

    I wonder what this would look like in C# if I were to draw a simple line with two points?

    Hmm, how would I go about doing the division after getting the information on what segment has been clicked? Sorry, I'm pretty new to scripting.
     
    Last edited: Apr 30, 2015
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Since you have the segment number that was clicked, you can use that information to read the VectorLine.points2 array after the appropriate point, and use those points to create a new VectorLine. Then remove those points from the original VectorLine.

    --Eric
     
  43. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Hi,
    I am creating lines using textures. The problem I am running into is the line width does not remain constant across different resolutions. Is there a way to fix this?
    Thanks!
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Since line width is in pixels, you can use the screen resolution to compute the number of pixels wide the line should be.

    --Eric
     
  45. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Could you please post an example of what you mean?
    Lets say I want my line to stay a constant width of 10 pixels across all devices/resolutions.
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Oh, in that case you don't need to do anything. That's how Vectrosity works; if you use 10 for the width, it will always be 10 pixels regardless.

    --Eric
     
  47. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Hi,
    I tried to draw numbers of free line with every touch in vectrosity (3.1) and then when I touched Eraser button each of the free lines which was is touched should be erased. It made freeline correctly but It cannot erase it.

    Code (CSharp):
    1. void DrawFreeLine()
    2.     {
    3.         if (Input.touchCount > 0 && FreeLine)
    4.         {
    5.             touch = Input.GetTouch(0);
    6.  
    7.             if (!EraserButton && lineCounter<numberOfLines)
    8.             {
    9.               if (touch.phase == TouchPhase.Began&& touch.position.x>XMin*Screen.width &&
    10.                     touch.position.x<XMax*Screen.width && touch.position.y>YMin*Screen.height &&
    11.                     touch.position.y<YMax*Screen.height )
    12.               {
    13.                     ListOfFL.Add(new VectorLine("DrawnLine"+lineCounter, new Vector2[maxPoints], lineMaterial, _initialPen
    14.                                                 , LineType.Continuous, Joins.Fill));
    15.  
    16.                     ListOfFL[lineCounter].ZeroPoints();
    17.                     ListOfFL[lineCounter].minDrawIndex = 0;
    18.                     ListOfFL[lineCounter].Draw();
    19.                     previousPosition = ListOfFL[lineCounter].points2[0] = touch.position;
    20.                 lineIndex = 0;
    21.                 canDraw = true;
    22.               }
    23.               else if (touch.phase == TouchPhase.Moved && (touch.position - previousPosition).sqrMagnitude > sqrMinPixelMove
    24.                                              && canDraw && lineIndex<maxPoints)
    25.               {
    26.                 float XFreeL=Mathf.Clamp(touch.position.x, XMin*Screen.width, XMax*Screen.width);
    27.                 float YFreeL=Mathf.Clamp(touch.position.y, YMin*Screen.height, YMax*Screen.height);
    28.                 Vector2 LastPose=new Vector2(XFreeL,YFreeL);
    29.  
    30.                     previousPosition = ListOfFL[lineCounter].points2[++lineIndex] = LastPose;
    31.                     ListOfFL[lineCounter].minDrawIndex = lineIndex-1;
    32.                     ListOfFL[lineCounter].maxDrawIndex = lineIndex;
    33.                 if (lineIndex >= maxPoints-1)
    34.                     {
    35.                     canDraw = false;
    36.                         lineCounter++;
    37.                     }
    38.                 ListOfFL[lineCounter].Draw();
    39.                 changeColor();
    40.                }
    41.                 else if(touch.phase == TouchPhase.Ended&&canDraw )
    42.                {
    43.                 canDraw=false;
    44.                 lineCounter++;
    45.                }
    46.         }
    47.       }
    48.     }
    49.     void EraseMe()
    50.     {
    51.         if(EraserButton)
    52.         {
    53.  
    54.             for (int i = 0; i <ListOfFL.Count; i++)
    55.             {
    56.                 if (ListOfFL[i].Selected (touch.position, extraThickness,out index))
    57.                 {
    58.                     VectorLine Temp=ListOfFL[i];
    59.                     VectorLine.Destroy(ref Temp);
    60.  
    61.                     ListOfFL.RemoveAt(i);
    62.                     lineCounter--;
    63.                     break;
    64.                 }
    65.             }
    66.         }
    67.     }
    What is my problem?
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Where are you calling the EraseMe function? Have you confirmed that ListOfFL.Selected returns true?

    --Eric
     
  49. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Yes,EraseMe() function used in Update(). When I touch EraserButton's collider then EraserButton becomes True. I logged it it works correctly.
    I dont Understand this question (Have you confirmed that ListOfFL.Selected returns true?)
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Oops, unintentional HTML formatting. Have you confirmed that

    Code (csharp):
    1. ListOfFL[i].Selected
    returns true? Use Debug.Log. (Also there's a slight bug in your code; use ListOfFL.RemoveAt(i--).)

    --Eric
     
unityunity