Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Mm I thought that might be the case. Could you implement a control for how much the lines scale with distance, so you can allow them to get thicker closer to camera/thinner further away? This could be used to reduce the issue.
     
  2. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    What I'm really trying to achieve is a decent fog effect. Using 3D lines (so I can use Unity's fog) has the above issue. Using Vectrosity's fog only looks at the object's transform so a large object has a noticeably uniform amount of fog. Setting line colours myself based on distance from camera doesn't really work because you set colours for segments not points, so if I have one line made of two points stretching into the distance I can't apply the near point one colour and the far point another.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd suggest subdividing the lines so they are made with multiple points instead of 2. It's pretty trivial to do and should fix the UV mapping problem. e.g., instead of a line with points (0, 0, 10) and (0, 0, -10), have it be (0, 0, 10), (0, 0, 5), (0, 0, 0), (0, 0, -5), (0, 0, -10).

    --Eric
     
  4. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    46
    I'd like to use vectrosity with 2dToolkit, but I don't know how I can make a line use a texture which is on an atlas, is it possible out of box? If not, how should I go about adding such a feature?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The texture should not be part of an atlas, and it's not really feasible to add that, sorry. However there wouldn't be much if any benefit to doing so anyway.

    --Eric
     
  6. alexfiftyfour1

    alexfiftyfour1

    Joined:
    Aug 21, 2016
    Posts:
    21
    Hi Eric,

    I have a question about colliders and rigidbodys with vectrosity lines.

    The context:

    I have a line drawn with vectrosity. The user shall be able to select the line by mouse click, grab it and move it in the scene.
    To visualize the area the user selects, I use a red selection rectangle. See my image:

    SelectionRectangle.png

    To detect the selection I have another gameobject that I call SelectionDetector. The SelectionDetector has a BoxCollider2D and a RigidBody2D attached and has the same size as the red selection rectangle. The line is configured with
    Code (CSharp):
    1. myLine.collider = true;
    Right now this setup works fine. Everything is good.

    But the unity manual states: (https://docs.unity3d.com/Manual/CollidersOverview.html)

    "A collider without a rigidbody is a static collider an shall not be moved."

    As told above, my vectrosity line is moved, has a collider but no rigidbody.

    The Question:

    Now I'm wonderung, whether or not the vectrosity line is a static collider?

    1.) Does this rule apply to Unity2D?
    2.) If yes, what should I do to avoid making the line static collider?

    Thanks,

    Alex
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You should use VectorLine.Selected instead, so you can avoid using physics entirely.

    --Eric
     
  8. alexfiftyfour1

    alexfiftyfour1

    Joined:
    Aug 21, 2016
    Posts:
    21
    Hi Eric,

    the VectorLine.Selected is very usefull when the user clicks on the line. Thanks for this hint.

    But I don't see how this will help me with my selection rectangle problem. The VectorLine.Selected method allows no rectangle as input.

    To make it clear:
    - I don't want that the user clicks on the line. I don't have a click point.
    - I want that the user uses a rectangle as depicted in my above post to select an area on the screen and then I want to know if this area covers a VectorLine.
     
  9. alexfiftyfour1

    alexfiftyfour1

    Joined:
    Aug 21, 2016
    Posts:
    21
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OK, you said "user shall be able to select the line" so I didn't realize you wanted to select inside the line. It would be better to make a separate object for selecting and then use Vectrosity to draw the line for it, using VectorLine.drawTransform.

    --Eric
     
  11. xqtr123

    xqtr123

    Joined:
    Jun 7, 2014
    Posts:
    20
    Hi!
    I'm trying to make a simple line from a gameobject (Gun) to a point on a 2d plane. It looks good in the Scene mode, but not in the Game mode. How come?

    Code (csharp):
    1.  
    2. voidStart(){
    3. VectorLine.SetLine(Color.white,newVector2(transform.position.x,transform.position.y),newVector2(Screen.width-1,Screen.height-1));
    4. }
    5.  
     

    Attached Files:

  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Transform.position is world space, so you're mixing world space with screen space. Use SetLine3D instead.

    --Eric
     
  13. xqtr123

    xqtr123

    Joined:
    Jun 7, 2014
    Posts:
    20
    Hi!
    It's working now, I changed my code to this;

    Code (csharp):
    1.  
    2. public class Shoot : MonoBehaviour{
    3.  
    4. public VectorObject2D line;
    5.  
    6. void Start(){
    7. line.enabled=false;
    8. }
    9.  
    10. void Update(){
    11. if(Input.GetMouseButton(0)){
    12. line.enabled=true;
    13. Vector3 mouseWorldPosition=Camera.main.ScreenToWorldPoint(Input.mousePosition);
    14. RaycastHit2D hit=Physics2D.Raycast(transform.position,mouseWorldPosition);
    15.  
    16. line.vectorLine.points2[0]=new Vector2(transform.position.x,transform.position.y);
    17. line.vectorLine.points2[1]=new Vector2(hit.point.x,hit.point.y);
    18.  
    19. line.vectorLine.Draw();
    20. }
    21.  
    22. if(Input.GetMouseButtonUp(0)){
    23. line.enabled=false;
    24. }
    25. }
    26. }
    27.  
    I'm trying to put the line inside SVG Sorter (SVG Importer asset), but then the line won't show. Does anyone know why? Is it a sorting problem?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not familiar with that asset so I can't really say, but you can try changing VectorLine.drawDepth.

    --Eric
     
  15. ArmarageX

    ArmarageX

    Joined:
    Aug 5, 2012
    Posts:
    21
    Hey Eric! Sorry to bother you again!

    Ive recently converted my code from JS Vectrosity to C# Vectrosity. (I only have 1 script that uses Vectrosity)
    Everything works well in editor, except on IOS >.<

    The Line is rendered OVER the Unity Canvas (i.e a GameOver screen) (in which it never did before in JS)
    My Canvas sorting order is definitely higher than the VectorCanvas (and both is on ScreenSpace Overlay)

    This only happens on IOS device. In editor, its perfectly behind the Canvas.
    Im on Iphone 6 IOS9.

    Do you happen to know anything that could cause this issue?
    Thanks heaps!
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using any custom shaders perhaps?

    --Eric
     
  17. jaketa

    jaketa

    Joined:
    Apr 18, 2015
    Posts:
    1
    Hi Eric,
    I bought Vectrosity around a year ago (from website), but a few days ago I noticed that I can't access the download page from the provided link in my emails. It shows an error saying that my email can't be located in some list. It's been some days now (I think more than a week, maybe?) that I sent a message using the Contact form on the website, but haven't received an answer yet and the error is still there. Could you please look into this? Thank you!
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, I didn't get anything from you through my website. Please send me a PM here with the relevant details, thanks.

    --Eric
     
  19. adentutton

    adentutton

    Joined:
    Mar 24, 2013
    Posts:
    34
    Love the asset! Am just having some very beginner problems with not being able to have the lines drawn on my current canvas as opposed to the VectorCanvas. Have looked through the docs but having trouble drawing the desired lines on a panel on my current canvas. Any help would be much appreciated!
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you use VectorLine.SetCanvas, that should work. Try setting worldPositionStays to false if the default doesn't work for your setup.

    --Eric
     
  21. adentutton

    adentutton

    Joined:
    Mar 24, 2013
    Posts:
    34
    Thanks for the reply Eric, Ive been playing around with that function but am a bit lost on how to go about referencing the panel which I would like the lines drawn on.

    I have tried to create a Canvas variable and GameObject variable and call the SetCanvas function in the Start function of my script but getting the same error every time

    private GameObject statPanel;

    and in Start() function
    VectorLine.SetCanvas(statPanel);

    error CS0120: An object reference is required to access non-static member `Vectrosity.VectorLine.SetCanvas(UnityEngine.GameObject)'

    *** A search through the Documentation cleared it up for me! I have assigned the drawn lines to the current Canvas but I want to specifically assign it to a Panel in the Canvas. Is that just as simple?
     
    Last edited: Jan 8, 2017
  22. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Is it possible to draw lines in the 3D space with your asset? For example, a camera flies around and the continuous lines are drawn.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You don't literally type "VectorLine", just like with Transform.Translate you don't literally type "Transform", but in both cases you refer to the actual VectorLine or Transform.

    Yes, use Draw3D with lines using world-space Vector3 coords.

    --Eric
     
  24. WilB

    WilB

    Joined:
    Oct 25, 2012
    Posts:
    17
    Hi Eric,

    I've been using Vectrosity for a couple of years now and have never had a problem. Suddenly in a new project, I am getting very strange results with the MakeSpline() method for a 2D spline. This is with Unity 5.4.1f1 and Vectrosity 5.2. My setup looks like this:

    Code (CSharp):
    1.         spline = new VectorLine ("test spline", new List<Vector2>(pts.Count), null, 5, LineType.Continuous);
    2.         spline.MakeSpline (pts.ToArray(), pts.Count-1, false);
    3.         spline.Draw();
    4.  
    The Vector2[] points have these coordinates:

    1 - point coordinates.jpg

    And the rendered output looks like this:

    2 - rendered spline.jpg

    I must be messing something up! Any ideas?
     

    Attached Files:

  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not able to duplicate this:

    Screen Shot 2017-01-10 at 10.39.44 PM.png

    However I would point out that there's not really any point using MakeSpline if the number of points in the line is the same as the number of points in the spline; it would be better just to use the points directly and skip MakeSpline.

    --Eric
     
  26. honeboy

    honeboy

    Joined:
    Jan 13, 2017
    Posts:
    1
    line.png
    Hello.

    How can I draw line like attached image?

    Thanks.
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You should use VectorLine.SetEndCap with the appropriate textures and cap type (specifically EndCap.Mirror would be best).

    --Eric
     
    honeboy likes this.
  28. Deltalus

    Deltalus

    Joined:
    Dec 30, 2016
    Posts:
    1
    Hey Eric!

    I have a question regarding your 3D lines. I am using your asset to create 3D lines for a VR application and I cannot seem to every get the line widths correctly. I understand that the width is drawn using pixels but for a VR application, this is not desirable as the lines get thicker the further away you are from them. I was wondering if you have a solution or workaround for this problem.

    Thanks.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, I'm not sure there's really a solution at this time, since the main idea of Vectrosity is to draw consistent pixel-width lines. For this case it might be better to use the Unity line renderer component.

    --Eric
     
  30. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    36
    Hey Eric,

    So I just bought Vectrosity (for the GGJ 2017), but im getting some weird collider behaviour.

    http://imgur.com/a/54eK1

    Only the thick line is supposed to have a collider but , for some reason when creating the Edge Collider the VectorLine adds some points that make no sense, and therefore i get collisions where there are no visuals.
     
  31. atalata

    atalata

    Joined:
    Jan 1, 2017
    Posts:
    1
    Hey Eric.
    I want to draw a line (3D line in world space, not above UI), and the line needs to go from one game object to another, and update automaticaly when objects are moving in worldspace. The sample code i see always use coordinates of the object with a transform.position, but these coordinates won't update automaticaly has it is not an object reference in the line creation

    To mention in addition, the objects are moving at rare occasions, so i want to avoid any "update" solution that will be time consuming.
     
    Last edited: Jan 21, 2017
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, can you post code that generates this problem please?

    Use the transform.position coordinates of the objects when creating the line, and have a function that runs when the objects move, which changes the coords in the line to the new transform.position coords.

    --Eric
     
  33. MapRG

    MapRG

    Joined:
    Jan 19, 2016
    Posts:
    6
    Hello,

    I think I have a problem, and I really don't know why.

    I'm trying to make some drawing tools in my app. Noticed some bleeding sometimes when I draw, I thought ok, it's probably me, I'll fix it later after I do all the functionality. I saw that sometimes it adds an endpoint towards the bottom right of the gui (doesn't matter if i'm drawing 2d or 3d)

    Then I tried a grid.

    Created separate it looks great. No glitches.


    when i put it in my app it looks like so:


    keep in mind it's the same code.

    The extra lines are these lines:



    As I said, they go to the bottom left corner of the ui for some reason.

    Did anyone have this happen? It's probably something in my app interfering (although I can't figure out what, i'm using the dll). But I can't figure out what it could be.

    Using marklight as gui if it matters.

    Thanks.
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What does it look like in the scene view? Since Vectrosity is designed to look correct from the camera view, that might be hiding issues.

    --Eric
     
  35. MapRG

    MapRG

    Joined:
    Jan 19, 2016
    Posts:
    6
    the third picture is from the scene view. i saw some guy had a similar problem three pages back .The one trying to draw the V.
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I mean the scene view from the first image where it has no apparent glitches.

    --Eric
     
  37. MapRG

    MapRG

    Joined:
    Jan 19, 2016
    Posts:
    6
    Nothing of the sorts. It's clean. Deactivated the terrain and it has no glitch.
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Without knowing more details, I'm guessing the data you're using for the grid has some unused points, which would be Vector3.zero.

    --Eric
     
  39. MapRG

    MapRG

    Joined:
    Jan 19, 2016
    Posts:
    6
    I would guess that too except the points are in 3d space. Vector3.Zero would be at the center of the image. Is it possible they become Vector2.zero and those points are interpreted as screen coordinates, not world coordinates?

    I'll investigate more, but i'm using lists, and i'm recreatimg each time and i'm positive i have no zeros.
     
  40. MapRG

    MapRG

    Joined:
    Jan 19, 2016
    Posts:
    6
    Well. I kinda solved it. Not by changing the points.

    When I was creating the line i was defining the list as discrete, after that continuous, and apparently that was creating the bug. Funnily enough if I then try to override it...

    vector = new VectorLine("uq", goodList, null, lineWidth, LineType.Discrete);
    applystyle(vector, Style); //here i change the style - and it was setting it to Continuous by accident
    vector.lineType = LineType.Discrete;

    it gives me
    NullReferenceException: Object reference not set to an instance of an object

    for this line

    vector.lineType = LineType.Discrete;

    without it it works like you saw. Anyway, if i leave the linetype as discrete all the way i have no problem.

    changing it before drawing does that weird thing. Weirdly enough i was drawing at the end of all that. So why did it care what i do meanwhile is beyond me. From what i saw there's a source version also, right? I'm probably gonna use that from now on.
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OK, I'll look into what's happening when changing from continuous/discrete after creating the line; seems like a bug there.

    --Eric
     
  42. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    36
    I actually stopped using the collider for game design reasons, but i can send you the code afterwards after the GGJ.

    BTW is there a way to adjust the start and end widths of a line and have the middle widths interpolate between those values?
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can set an arbitrary width for any line segment with SetWidth or SetWidths, so any interpolation you care to do is simple enough. See also VectorLine.smoothWidth.

    --Eric
     
  44. le_duke

    le_duke

    Joined:
    Aug 30, 2011
    Posts:
    48
    Hi,

    I'm working on a Google Earth like mobile app and i'm looking for a good way to display gps tracks.
    So i'm currently looking for the bests solutions to do such a thing.

    My first thought was to use the Unity LineRenderer but it seems impossible to get a click event on a drawed line.

    So here is my questions about Vectrosity:

    Does it support events like : click, mouseover etc ?
    What performance should I expect (possible to draw a line with something like 30K points on mobile ?).
    Do you have any documentation available online ?

    Thanks !
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity has a Selected function that's essentially like a mouseover, so you can check for a click while a line is selected. Performance depends on a number of factors, primarily CPU and whether a line is redrawn every frame or not. 30K points may or may not be too much depending on the device and what you're doing exactly. The documentation is linked to on the Vectrosity page on my site (near the bottom).

    --Eric
     
  46. le_duke

    le_duke

    Joined:
    Aug 30, 2011
    Posts:
    48
    Thanks for the answer, I had missed the documentation link on your site. I have all I need now =)
     
  47. GrumpyFour

    GrumpyFour

    Joined:
    Jan 12, 2016
    Posts:
    17
    Hi Eric,
    I apologize for this rather basic question. I am trying to draw lines on a plane in worldspace, and I need them to be able to move with the plane. So I'm using 3D vectorlines. I'm trying to find a way to avoid recalculating the endpoints every frame, so what I'd like is for the vectorlines to be children of the plane transform. I have been trying to get the VectorManager.ObjectSetup method to work. That seems to make the vectorlines children in the proper way, but they are rendered way off to the side of the empty gameobject I'm assigning them to, and with a different rotation. Since the empty has the same position as the transform of the plane from which I'm calculating the endpoints in the first place, I'm not sure what I should be doing differently.

    Also, I'm not sure how to understand your instructions for VectorManager.ObjectSetup: I am not creating vectorlines as children of a GameObject, but making an existing GameObject into a vectorline? I assume that this means that for every new vectorline I want to create with this method, I need to create a new GameObject first?

    I haven't tried using a worldspace canvas and drawing 2D vectorlines on it, which I know is not supported. If that did work it would be basically just what I need. Thanks for your help.
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, the intention of ObjectSetup is essentially as a "VectorLine renderer", where it replaces an object's renderer with a VectorLine. Generally you'd use VectorLine.drawTransform with the object you want the lines "parented" to. Keep in mind that this adds position/rotation to the line coords, so in other words the line coords should be local space rather than world space.

    --Eric
     
  49. alexfiftyfour1

    alexfiftyfour1

    Joined:
    Aug 21, 2016
    Posts:
    21
    Hi,

    I'm using right now 100 vectorlines in my scene. These vectorlines use colliders. The profiler shows this CPU usage:

    CPU Usage.JPG
    Is there a way to reduce this?
     
  50. GrumpyFour

    GrumpyFour

    Joined:
    Jan 12, 2016
    Posts:
    17
    Switching to local coordinates does the trick. Thanks very much!