Search Unity

  1. Unity 2019.2 is now released.
    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,148
    Are you using Draw or Draw3D?

    --Eric
     
  2. moire76

    moire76

    Joined:
    Jan 20, 2016
    Posts:
    6
    I use Draw3DAuto.
    If I use VectorManager.ObjectSetup for the cube edges, it looks much more consistant and doesnt jump back and forth, but always renders that longer orange side on top.
    Shall I use Vectormanager for all lines in this case?
    Here is the current setup with VectorManager applied to cube edges only.
    Thank you! :)
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Are you using a shader that writes to the depth buffer? The default line material doesn't.

    --Eric
     
  4. moire76

    moire76

    Joined:
    Jan 20, 2016
    Posts:
    6
    OMG, thank you!
    I've missed to check that sorry!
    Now it works like charm!
    Thank you for your excellent work and support!
     
  5. thehen2

    thehen2

    Joined:
    Apr 1, 2014
    Posts:
    43
    Hey, I'm having issues with end cap textures and colliders. They work fine with no end caps, but if I add a semi-circle end cap, I end up getting a bunch of stray points at (0,0,0). It would be good if I could disable colliders for end caps as I have no need for them anyway.

    Also it would be even better if I could just create an edge collider of the line itself, rather than tracing the entire texture. I'm using bunch of thin lines so I have no real need for that much fidelity.

    Many thanks, this is probably my favourite Unity asset :)
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Hi, I'm not seeing this behavior...I tried this code (and some variations):

    Code (csharp):
    1.     VectorLine.SetEndCap ("rounded", EndCap.Mirror, lineTex, frontTex);
    2.     var points = new List.<Vector3>([Vector3(1, 1), Vector3(2, 2), Vector3(3, 1)]);
    3.     var testLine = new VectorLine("Test", points, 20.0, LineType.Continuous, Joins.Weld);
    4.     testLine.endCap = "rounded";
    5.     testLine.collider = true;
    6.     testLine.Draw3D();
    Which gets this:

    Screen Shot 2016-11-10 at 2.00.10 PM.png

    The edge collider only uses the line coords anyway, and can't trace the texture (I expect that would be quite slow, plus I would have had to code it ;) ):

    Screen Shot 2016-11-10 at 2.03.22 PM.png

    --Eric
     
  7. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    In Line Maker could you make it/add an option so that if a mesh has "Keep Quads" enabled on its import settings the "Connect all points" button only connects the quad edges as opposed to all the triangles?
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    It looks like that would be feasible.

    --Eric
     
  9. ok_remi_ok

    ok_remi_ok

    Joined:
    Sep 16, 2014
    Posts:
    7
    The workaround did work! Thank you!
     
  10. Levent-B

    Levent-B

    Joined:
    Jan 10, 2015
    Posts:
    6
    hi,
    thank you for developing such great asset.
    I made a game with vectrosity, and I want to give link, if it is OK.
    c u
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Of course!

    --Eric
     
  12. labandunga

    labandunga

    Joined:
    Aug 1, 2012
    Posts:
    27
    _VectorLine.points2.Clear();
    _VectorLine.Resize(9);

    This line will not resize the points array (using 2d points).

    if it's called twice it resizes the points succefuly.

    I'd recommend using an ObservableCollection for points and updating the point count when points are added if you wish to have a seperate field to keep track of points count.

    I'd also recommend that when using the MakeRect() function, if the point size is smaller than the required amount resize the list internally.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    It will work if you don't use Clear (which isn't necessary since the values get overwritten anyway). Good point about MakeRect; it originated back when Vectrosity was using an array for the points rather than a List.

    --Eric
     
  14. fertigo

    fertigo

    Joined:
    Feb 15, 2014
    Posts:
    18
    What I try to do is

    - Changing the width of some Vectrosity lines
    - Take a sample of the screen by rendering (on a separate camera) to a rendertexture.
    - changing line width back again.

    But I can't get it to work. The camera will grab the screen with the old linewidths. Only if I put it in a coroutine and yield a frame in between changing the line widths and grabbing the rendertexture it works. But then the user sees it which is not my intention.

    Any idea on how to solve this?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Line meshes are updated once per frame, so I'd suggest having another separate line on a layer only the rendertexture camera can see.

    --Eric
     
  16. the_schmoey

    the_schmoey

    Joined:
    Nov 22, 2016
    Posts:
    4
    Hiya.

    (Probably something stupidly simple I'm missing...)

    Essentially I want to take the 3D grid example but have a whole lot more points on the lines for mesh distortion.

    So yes I could loop through and create all the points... but what I would like to do is use VectorLine.MakeSpline a bunch of times horizontal, a bunch of times vertical and then that's my mesh. I'll loop through the verts and voila.

    Problem is it's creating a separate object for each Spline object. Is there any way to merge them together in to one nice object? Or am I overthinking the problem?

    Cheers!
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    MakeSpline has the option to pass in the number of segments and an index, so you can make any number of splines in a single VectorLine. However I'd just loop through and add the points; that's not any more difficult than using MakeSpline for this and would be faster.

    --Eric
     
    the_schmoey likes this.
  18. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Do you think you could implement the connect all quads into the next version?
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Yep, that's the plan.

    --Eric
     
  20. ivantro

    ivantro

    Joined:
    May 3, 2014
    Posts:
    8
    Hello, Maybe this is a silly question, but does vectrosity support drawing in the canvas of uGUI? I know it supports 3D and 2D, but I'm looking to draw a dotted curve in the HUD of my app and was wondering if this plugin can do it.

    Thanks
    ~Ivan
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    The 2D drawing only works in a canvas, in fact. (3D lines are meshes in world space.)

    --Eric
     
  22. ivantro

    ivantro

    Joined:
    May 3, 2014
    Posts:
    8
    great, thanks
     
  23. ivantro

    ivantro

    Joined:
    May 3, 2014
    Posts:
    8
    If I want to mix together elements from uGUI with a curve, can that be done? for example I have a couple of orange round square uGUI buttons, and then I draw a curve, but want some buttons to be on top of the curve and others to be under it. Is there a way to do that? (sorry if it's a very basic question, but I just got your asset Today). Thanks for any help.
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Yes, you can use Transform.SetSiblingIndex to make the buttons draw on top. (Also VectorLine.drawDepth for setting the sibling index of lines.)

    --Eric
     
  25. HypothicEntropy

    HypothicEntropy

    Joined:
    Mar 24, 2014
    Posts:
    17
    I have an issue with line.smoothWidth not working with a 3D line where I manually set the lineWidth while the line is being created (by drawing in 3D).

    I am using Unity 5.4.3 and Vectrosity 5.3. Could this be caused because of using Unity 5.4.3?

    Here's what it looks like with line.smoothWidth = true

    WithSmooth.PNG
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Hard to tell from the screenshots, but it looks like your line points aren't continuous. For example, something like this would work:

    Code (csharp):
    1. (100, 100), (150, 100), (200, 150)
    Whereas it looks like you might have something like

    Code (csharp):
    1. (100, 100), (150, 100), (150, 100), (200, 150)
    --Eric
     
  27. HypothicEntropy

    HypothicEntropy

    Joined:
    Mar 24, 2014
    Posts:
    17
    I don't think that is the case because I am drawing the line using a mouse based on the DrawLinesMouse.js example. I am drawing a new point (line) when the mouse position moves a certain distance, so the new point should always be different.

    Here is what the document says should happen:
    SmoothingInfo.PNG

    And here is the section of the code where I am using the smoothWidth and am changing the line: SmoothingCode.PNG

    I am using this in 3D and will use this for creating a simple drawing app in VR with a motion controller. I am also running into the problem where the Z-depth of the drawing does not affect the size of the line (in the camera) because Vectrosity automatically relocates the line to match the camera's view frustum to make sure the 'width' of the line in pixels always matches the camera when drawn... this is not the desired behavior when drawing in 3D with a motion controller in VR, is there also a way to change this functionality in Vectrosity so that the further away you draw the line from the camera, the smaller the line appears? (based on camera frustum depth).
     
    Last edited: Nov 29, 2016
  28. HypothicEntropy

    HypothicEntropy

    Joined:
    Mar 24, 2014
    Posts:
    17
    Here is more code I am using incase the above is not enough. This the entire Update() code.

    Code (CSharp):
    1. var newPoint = GetMousePos();
    2.  
    3.         // Mouse button clicked, so start a new line
    4.         if (Input.GetMouseButtonDown(0))
    5.         {
    6.             //line = new VectorLine("DrawnLine3D", new List<Vector3>(), capLineTex, capLineWidth, LineType.Continuous, Joins.Fill);
    7.             line = new VectorLine("DrawnLine3D", new List<Vector3>(), capLineTex, 1, LineType.Continuous, Joins.Fill);
    8.             allLines.Add(line);
    9.  
    10.             line.endPointsUpdate = 1;
    11.             line.endCap = "RoundCap";
    12.  
    13.             line.Draw3D();
    14.             previousPosition = Input.mousePosition;
    15.  
    16.             line.points3.Add(newPoint);
    17.  
    18.             canDraw = true;
    19.         }
    20.         // Mouse button held down and mouse has moved far enough to make a new point
    21.         else if (Input.GetMouseButton(0) && (Input.mousePosition - previousPosition).sqrMagnitude > sqrMinPixelMove && canDraw)
    22.         {
    23.             var pointCount = line.points3.Count;
    24.  
    25.             // Set size for Line
    26.             if (line.GetSegmentNumber() > 0 && line.GetSegmentNumber() < 11)
    27.             {
    28.                 List<float> temp = new List<float>();
    29.  
    30.                 for (int i = 0; i < line.GetSegmentNumber(); i++)
    31.                 {
    32.                     temp.Add(widths[i]);
    33.                 }
    34.  
    35.                 line.lineWidth = temp[temp.Count - 1]; // Set width to last biggest segment, done to make Endcaps same size.
    36.                 line.SetWidths(temp);
    37.  
    38.                 line.smoothWidth = true;
    39.             }
    40.  
    41.             if (pointCount >= maxPoints)
    42.             {
    43.                 canDraw = false;
    44.             }
    45.  
    46.             previousPosition = Input.mousePosition;
    47.             line.points3.Add(newPoint);
    48.             line.Draw3D();
    49.         }
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    No, sorry; the idea of Vectrosity is that it draws vector lines, where they maintain the same width regardless of distance from the camera. In any case, you've set endPointsUpdate to 1, which makes only the last point update, which prevents smoothWidth from being able to function (since it needs to be able to adjust a couple of points in order to smooth the width). Also, I'm not entirely sure what you intend, but SetWidths can take a single number for a particular segment specified by an index, which seems like you would be able to use in order to avoid continuously allocating new lists.

    --Eric
     
  30. HypothicEntropy

    HypothicEntropy

    Joined:
    Mar 24, 2014
    Posts:
    17
    Ahh, thank you very much for the hasty replies. Yes, that fixed my line smoothing issue, although it causes an 'Array index is out of range' error to happen every time I start drawing for some reason. The reason I am recreating the list every time is because the code is from an older version of Vectrosity where I was using an array and had to update the widths of the whole line every time if I recall correctly, good to see it can now be modified point by point.

    Last question, is there a way to do billboarding of the line so that it is drawn in 3D but always facing the camera? I know there is Draw3DAuto(), this makes billboarding work, but it has the extra unwanted affect of resizing the line... so that the further away from the line I walk the bigger it gets and the closer I get, the smaller it gets. Without the billboarding, the line tends to look a bit messy in VR (especially if the person draws in the Z direction from the camera).
     
  31. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Do you know how I would change line colour/alpha based on distance from camera?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    That shouldn't happen; if you have a code example where this happens, I can fix the bug. (I tried the code you posted and am not getting errors.)

    No, sorry; as I mentioned above, the intention of Vectrosity is to create vector lines where the width is consistent regardless of distance from the camera.

    I'd use Vector3.Distance, and plug that into Mathf.InverseLerp, which would get you a 0.0 - 1.0 value that you can use for the alpha.

    --Eric
     
  33. ArmarageX

    ArmarageX

    Joined:
    Aug 5, 2012
    Posts:
    21
    Eric!

    In your DrawLinesTouch demo scene.... Im trying to change the width of the Drawn line with
    line.lineWidth =24 ; line.Draw();

    But it only scales the first segment of the line... >.<
    Is there a way to scale the whole line?
     

    Attached Files:

  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    Same as the issue a few posts above...endPointsUpdate in that script is set to 2, so only the last two points are updated (saves having to re-compute the whole line if you're just adding a segment to the end, so it uses hardly any CPU time). If you're changing stuff like line width that affects the whole line, then endPointsUpdate shouldn't be used.

    --Eric
     
  35. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Thanks, for both the questions I've asked recently
     
  36. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    In Line Maker, and I'm getting greedy here, could you implement a connect points where you specify a minimum angle for the edge? Like the "Smoothing angle" on a mesh import.

    Also for drawing dots with LineType.Points could you add a separate x/y scale?
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    I'm not really sure what you mean?

    I'll put that on the to-do list.

    --Eric
     
  38. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    So say in the example image only the orange edges would become lines
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    OK, I'll see what I can do.

    --Eric
     
  40. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Brilliant!
     
  41. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    If I'm using VectorManager to setup objects is there anyway to use useDraw3D on a per object basis?
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    No, sorry. If you want to mix Draw and Draw3D you'd need to create VectorLines and manage them yourself (which is pretty easy anyway).

    --Eric
     
  43. the_schmoey

    the_schmoey

    Joined:
    Nov 22, 2016
    Posts:
    4
    Cheers, thanks for the makespline confusion, I ended up coding the plot points in the end and I'm happy the way it works.

    Now I'm one step away from greatness with this thing - ie one last problem (for now... heh).

    Ideally I want to render the lines in world space. I want to move them around and always be facing the camera. Constant Draw3D (or Draw3DAuto) only updates the lines rotations to face the camera if the camera moves, not if they move themselves (and the camera stays still).

    Is there a way around this?

    Alternatively I can render them on the canvas, and if the canvas is set to world space then I've got a decent alternative, but it seems to forcibly change the canvas back to screen space overlay every time. Bug or by design? Yes I could re-force it back to world space but I feel like I'm doing something wrong, fighting against vectrosity workflow or something. Thoughts?

    Thanks again!
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    I'm not quite sure what you mean; lines already do update if the line points move. Unless you're talking about actually moving the line's transform component? If so, that's not supported; the way to "move" lines is to update the points, or else use VectorLine.drawTransform.

    By design; using a canvas is for 2D lines with Vector2 points. 3D lines with Vector3 points are meshes in world space.

    --Eric
     
  45. retraffic

    retraffic

    Joined:
    Jul 2, 2014
    Posts:
    6
    I just had to update to the latest Unity 5.5 beta and have come across an error with Vectrosity.
    All the lines materials suddenly don't seem to work anymore and instead appear black. I'm using the VectorLineGlow Material from the Demos folder. Is this a known bug?


    I tried messing around with the material settings.
    The problem doesn't happen in the Unity Editor, but only in the Windows build.
    (Mac build is not affected either.)
     
  46. the_schmoey

    the_schmoey

    Joined:
    Nov 22, 2016
    Posts:
    4

    Boom! Yeah drawTransform is the one. Nice.

    That's a really weird quirk having to link it to another transform instead of using the lines transform, but I'll go with it because it does what I want now.

    Previously I was updating the points manually and it was a pain in the ass, then I was rendering them (2D as you say) on a canvas but if it's set to canvas world space render mode then I could at least move them on the z-axis and apply screen effects etc, but I hated that solution.

    Anywho drawTransform is the real hero of the day here. Cheers!
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    It's not a known bug and I can't get it to fail here, but cases where certain platforms behave unexpectedly is generally a bug in Unity; there's no particular reason why it should behave differently in a build. Try using a different shader; also a bug report to Unity would probably help (you can include Vectrosity if needed).

    --Eric
     
  48. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    485
    Hi Eric,

    I had to upgrade to 5.4.3 and the problem was still there. Luckily I found an easy solution and wanted to share just in case if that helps you with the next version or for anyone looking a solution.

    I was originally calling VectorLine.SetCanvasCamera (Camera.main) before creating the line. Simply moving it after creating and drawing the line fixed the scaling problem with the canvas.
     
  49. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    49
    Something strange happens when using draw3D at glancing angles. Here's how it is not using draw3D:

    And this is using draw3D:

    As you can see the lines running along Z are missing the red area of texture. You can see what a problem it becomes in the real situation:

    Is it possible to fix this?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,148
    That's a limitation of UV mapping with the texture being stretched along a single quad. As far as I know the only real way to fix that is to subdivide the lines into multiple points instead of just 2, so there are more quads.

    --Eric