Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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,401
    Well, that explains it. Talk to your project manager about upgrading Vectrosity.

    --Eric
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Speaking of upgrading, 4.1.2 is on the asset store now (not sure how long it's been there since I didn't get a notification).

    --Eric
     
  3. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Hi, I already bought the program and played around with it, now I have one specific question:

    Can I do 2d-rope-physics with it? The effect I'm looking for would be that the player holds a needle that follows the mouse and the thread (which would be done with Vectrosity) should follow the needle.

    This is easy to do in Vectrosity and I already got it working but can I achieve the Vector-Line to "hang" physically (like a rope)?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can't do rope physics with Vectrosity, but you can use some kind of rope physics and use Vectrosity to draw the line. I know someone was using it with a package from the asset store, where the rope was implemented with sphere colliders I believe, and MakeSpline was used with the transform.positions of the spheres.

    --Eric
     
  5. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    I wouldn't even need "real" physics, I just need a swingy-rope effect on the line: Making the line swing a little bit between two points, like a hammock.

    Is that achievable with the curve functionality of Vectrosity?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity just draws lines. If you supply points and animate them somehow, Vectrosity will draw that, but it doesn't have any physics capability itself.

    --Eric
     
  7. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Alright, thanks a lot for your quick replies. I have another question:

    I am using the drawTransform variable to "pin" the Line to the transform of a GameObject.

    So far so good, it seems to work, however when I move the GameObject, the line won't move the same amount on the screen. E.g. I move the transform of the GameObject by x -> 5 but the line only moves by (seemingly) 5 pixels, not 5 in the world space.

    Is there any way to "pin" my line segments to points that move with a parent-GameObject?

    EDIT: Rotation seems to work perfectly (when the parent GameObject rotates, the line rotates the same amount)
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It depends on what sort of line you're using; if you have a Vector2 (screen space) line, then moving a transform 5 units will move the line 5 units, which means 5 pixels in this case. A Vector3 (world space) line will move 5 world space units.

    --Eric
     
  9. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Okay, my problem is that I work on a 2D game and only use Vector2 points for my lines (Z is always 0).
    Nonetheless, I need the lines/points on the line to "snap" to other 2D-Objects in my scene, moving the exact same amount they move.

    How do I achieve this?

    EDIT: The problem, to clarify, is that in my game, 1 pixel != 1 unit in the world space (I think 100 pixels == 1 unit is the unity default). So when my drawTransform object moves 1 unit I need the line to move 100 pixels etc.
     
    Last edited: Mar 12, 2015
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I would recommend using Vector3 points for your lines, since you want them to use world space rather than screen space.

    --Eric
     
  11. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Hi Eric. First of all thx for great asset.

    Im making lightingbolt. Everything is going well. But i got some problems.

    When drawing wide line some artifacts become visible if points is too close. When line goes wider this became more noticeble.

    Here is screen of what im talking. There is main line with 100 points, some branches with lower points. And wide glow line with 20 points. There is some artifact at ending.

    Im using perspective camera. When i change field of view lines are changing their wide. What is the reason of this? Also this artifacts apear or disapear when im changing field of view. Also its flickering when moving camera.


     
    Last edited: Mar 13, 2015
  12. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Thanks, I kinda got it working now (updating the points manually) but now I'm running into another wall. The documentation & searching this thread doesn't give me anything, either:

    Apparently, there used to be a feature called VectorLine.sortingLayerID which would let me change the sorting layer for the line.

    I need to partially obstruct my line (well, parts of my line) in my 2D game and I'm working with Sprite Objects and Sorting Layers (not using the Z-Axis at all).

    How would I go about that?
     
  13. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    You can change rendering layer of the canvas where lines is drowing.

    " VectorLine.canvases3D[0].sortingLayerName = "lightingGlow"
     
  14. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Thanks, I got it working now! :)
    Is it also possible to render specific points to specific sorting layers? Like point 1 on layer 1 and point 2 on layer 2 or something like this?
    Or would I need to make different lines for that?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, an object can only be part of one layer.

    I'm guessing you have many points very close together. Joins.Weld doesn't work very well under those conditions so I'd suggest having more space between points.

    --Eric
     
  16. SmartCarrion

    SmartCarrion

    Joined:
    Jul 27, 2013
    Posts:
    27
    Just bought Vectrosity and I'm struggling to get started. Is there no API or manual documentation? No YouTube tutorial? Do i have to create a new project, load demo content and dig through that to understand what the function calls are? This should be way simpler, but so far, i'm having an easier time just using Line Renderer because i can read how it works.
     
  17. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Why does lines change their width when camera changing field view(zoom) Can you tell plz how to prevent this?
     
  18. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Documentation is one of the best from all assets that i saw in store. Just check your folder.

     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Redraw the line when the camera moves or use Draw3DAuto.

    --Eric
     
  20. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Im updating the line already. Im drawing 3d line, near other sprites. When i change field of view camera zoom changes, all objects became smaller lines shorter, but their width remain the same.

    Simple test:

    Vector3[] p = new Vector3[2];
    p[0] = new Vector3(0,0,0);
    p[1] = new Vector3(10,5,0);
    VectorLine l = VectorLine.SetLine3D(Color.blue, p);
    l.material = m;
    l.SetWidth(20);
    l.Draw3DAuto();

    Camera perspective. Line is drawing on VectorCanvas3D.

    Field Of view = 10

    Field Of view = 50

    Field Of view = 100
     
  21. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    3dline smoothColor + endcap gives artifacts in last point.

    colors[0] = new Color(1, 1, 1)*0.5f;
    colors[1] = new Color(1, 1, 1);
    colors[2] = new Color(1, 1, 1);
    colors[3] = new Color(1, 1, 1);

    colors[0] = new Color(1, 1, 1);
    colors[1] = new Color(1, 1, 1);
    colors[2] = new Color(1, 1, 1);
    colors[3] = new Color(1, 1, 1) * 0.5f;
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oh, I see. That's intentional; line width is measured in pixels.

    You're right; sorry about that. I'll fix it for the next version.

    --Eric
     
  23. SmartCarrion

    SmartCarrion

    Joined:
    Jul 27, 2013
    Posts:
    27
    Ok, found the documentation is is good thanks. I was just so surprised not to see it on the website or anything!

    I built the lines I need and everything is working well in Unity on the PC, however when I build to Android, nothing shows up! I tried switching the shader to mobile-sprite-additive, and no luck with that either. Is there something else i need to initialize in the scene?

    Thanks,
    Ian
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, there's nothing special you need to do (for any platform). Make sure the lines are positioned where the camera can see them in different resolutions.

    --Eric
     
  25. SmartCarrion

    SmartCarrion

    Joined:
    Jul 27, 2013
    Posts:
    27
    Thanks I found the bug, i had a check for mouse presence instead of a check for the universal mouse button press. no mouse present on my tablet :)
     
  26. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    Hi,

    In my game I need a simple circle which i need to scale over time,
    I tried Vectrosity and it works awesome, however Please let me know what could be best option in terms of performance
    1. Using Sprite(512x512) , OR
    2. using Vectrocity MakeCircle method ?
      performance is a major consideration for my game, however Vectrocity is adding some ease to my game , so I'm confused,
      Please help
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You should only worry about performance if it's causing problems. In any case those are two completely different methods, so you'd need to use the profiler.

    --Eric
     
  28. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    Thanks Eric for quick response.

    I'm using Unity5
    using Script to draw circle:

    Code (CSharp):
    1. circle = new VectorLine("Circle", linePoints, null, width, LineType.Continuous, Joins.Weld);
    2. circle.MakeCircle(new Vector2(Screen.width/2,Screen.height/2),radius);
    3.         circle.Draw();
    However the the canvas Render mode is always set to : Screen Space-overlay, Please let me know if there is a way to change it to "world space"
     
  29. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Try to use Vector3 points, so object will be created at 3d canvas. Use 3d points for both new VectorLine and make circle.

    Also try to read documentation in section "Canvas"
     
    Last edited: Mar 16, 2015
  30. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Hm... But for what?

    What will be in different resolutions? Line width will resize correctly, or it will be the same?

    So in order to stay at local width with all other objects i need to resize all lines when chenging camera field of view? This is kinda strange because lenth is not changing and width is changing.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    So vector lines appear consistent.

    Line width is measured in pixels. So if you set a line with a width of 2, it will always be 2 pixels regardless of resolution.

    --Eric
     
  32. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Getting this error


    from code:
    main.MainLine.GetPoint3D(bracnhesIndex)

    if i call GetLength before this there will be no error. So:

    main.MainLine.GetLength();
    main.MainLine.GetPoint3D(bracnhesIndex)


    Will not generate error.

    This happens not 100% time. What this error mean?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you have a code snippet that shows this problem?

    --Eric
     
  34. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    I cant figure this out in empty scene. It happen only in full level with enemys and all other staff. And seems it need to call this function 30-40 times, so its rare :(

    Im not shure, but seems GetPoint3D in that case giving wrong points, after fixing crash with GetLength. Il try to figure is this bug of vectrocity or my.



    Btw some kind of total 3d fiture of lines could be great. So they will be in world like any other object and properly scaling their size acording to resolution, camera field of view etc.
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using SetDistances?

    --Eric
     
  36. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    I miss this in documentation. Sorry. If i call SetDistances before GetPoint3D the points are drawing right and there is no crash. Seems that crash heppend when i was reusing lines from pool without SetDistance call.

    Now All is ok
     
  37. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Is there a way to check how many active lines present in moment?
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd need to track that yourself.

    --Eric
     
  39. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Hi,

    In creating lines line the one shown below I have run into a problem. I have tried using three different textures (9x1, 7x1 & 5x1) with the same results. No mater what with I set (large or small) the line drawn is always the same width (10 pixels).

    upload_2015-3-19_17-46-46.png
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Line width is set in code, not by what texture you use.

    --Eric
     
  41. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Sorry I misspelled width - "No mater what width I set (large or small) the line drawn is always the same width (10 pixels).".

    No matter what width I set using the function "SetWidth", whether I use a very large size of 15 or very small size of 0.1, the line drawn is always the same width (10 pixels).
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you re-draw the line after using SetWidth?

    --Eric
     
  43. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    This is the order of my calls:

    line.SetWidth (0.7f); // I have varied this width from 15 to 0.01 with no change
    line.maxWeldDistance = 5;
    line.smoothColor = true;
    line.DisplayLine(true);
     
  44. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Nevermind, my "Displayline" function was resetting the width to 10. Doh....
     
  45. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    Hi Eric. This puzzled me for a while but I figured something out that might help. With the shader I posted the missing joins only appear when the line is curving anticlockwise. While turning clockwise, the joins work as expected. Here's how that looks:

    Here's the shader again for convenience:
    Code (CSharp):
    1. Shader "Unlit/Vertex colored unlit" {
    2. Properties {
    3.     _MainTex ("Texture", 2D) = "white" {}
    4. }
    5. Category {
    6.     Tags { "Queue"="Geometry" }
    7.     Lighting Off
    8.     BindChannels {
    9.         Bind "Color", color
    10.         Bind "Vertex", vertex
    11.     }
    12.     SubShader {
    13.         Pass {
    14.         }
    15.     }
    16. }
    17. }
    Any ideas about what might be going wrong?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like the shader is single-sided; it should use cull off so it's double-sided.

    --Eric
     
    bitbutter likes this.
  47. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    Thanks! That does the trick. Here's the updated shader for anyone following along:
    Code (CSharp):
    1.  
    2. Shader"Unlit/Vertexcoloredunlit" {
    3. Properties {
    4. _MainTex ("Texture", 2D) = "white" {}
    5. }
    6.  
    7. Category {
    8. Tags { "Queue"="Geometry" }
    9. Lighting Off
    10. BindChannels {
    11. Bind "Color", color
    12. Bind "Vertex", vertex
    13.  }
    14.  
    15. SubShader {
    16. Pass {
    17. Cull Off
    18.  }
    19.  }
    20. }
    21. }
    22. }
    23. }
     
  48. dttngan91

    dttngan91

    Joined:
    Nov 21, 2013
    Posts:
    80
    I run RandomHills demo to see how to use collider with Vectrosity. However, when I change the drawing canvas render mode from ScreenSpace to WorldSpace, the collider is not exactly the position of drawing. It is likely collider works only with screen space canvas. is it right?
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You should use Draw3D if you want to use world space; don't manually set the standard Vector canvas to world space.

    --Eric
     
    dttngan91 likes this.
  50. douglasg14b

    douglasg14b

    Joined:
    Oct 2, 2014
    Posts:
    34
    Hey Eric, I'm trying to draw circles around units/structures in a 2D RTS environment in a similar fashion as SupCom's strategic circles. When a unit is moving I need to run myLine.Draw() every frame to make sure the circle correctly follows the unit. I found out this ends up being pretty CPU intensive, so I am trying to do what I have done with most floating elements (like health bars and selection boxes), and use a worldspace canvas and have that canvas's parent set to the unit/structure. So that the floating element just follows the units rotation and transform as a child.

    From the documentation I see that I can use Draw3d() to create a worldspace canvas. I can also set the transform or rectTransform to the transform of my unit. However I cannot seem to figure out how to set the canvas's transform.parent to the unit. So that I no longer need to draw the line every frame, it will just rotate and follow the unit's transform as a child.

    How would I go about doing this ?
     
    Last edited: Mar 27, 2015