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. aerospacevitd

    aerospacevitd

    Joined:
    Nov 29, 2017
    Posts:
    5
    Is there a way to get line textures to be a consistent size no matter the length of the line? I have 3D lines updating in late update and I would like to have the texture on the line remain consistent size.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    You can use a material with the texture scale set, rather than using VectorLine.textureScale.

    --Eric
     
  3. Glowing_Slab

    Glowing_Slab

    Joined:
    Jun 19, 2015
    Posts:
    39
    Hi, I'm using 3D lines as I need the vector lines to be occluded by a 3D object. This works perfectly when I adapt the Simple3DObject demo scene, but I also need it to be a render texture. I have added the Vectorline.SetCamera3D so the lines are facing the camera correctly but when this scene is adapted to be a render texture all the lines are always drawn over the object that should be occluding them. What am I missing here? Haha oh my, I just found the answer three seconds after posting this. The render texture requires a depth buffer.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yep, that would do it. :)

    --Eric
     
    Glowing_Slab likes this.
  5. Glowing_Slab

    Glowing_Slab

    Joined:
    Jun 19, 2015
    Posts:
    39
    Hi, me again! This time I am stumped. I'm trying to use
    VectorLine.SetCanvas (myCanvas); as mentioned in the Vectrosity Coding document to put all the Vectrosity lines on my existing canvas. This doesn't seem to compile, due to 'an object reference is required for a non-static field, method or property', and I can't find any further examples. Also, I'm using Draw3D Vectrosity lines - would that be a problem?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, Draw3D doesn't use a canvas.

    --Eric
     
  7. Glowing_Slab

    Glowing_Slab

    Joined:
    Jun 19, 2015
    Posts:
    39
    But it does create a VectorCanvas at runtime? Aha, I see it creates the VectorCanvas, but there's nothing on it - the draw 3d lines are separate objects.
     
    Last edited: Dec 22, 2019
  8. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    43
    Hi @Eric5h5,

    Trying to use Vectrosity with a material that is utilizing a URP shader graph (PBR and unlit) but I can't seem to add a texture and sample it with the UV node... any thoughts about that?
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    I don't have much experience with that and can't really advise, unfortunately.

    --Eric
     
  10. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    43
    Well I got it to work from blindly doing stuff... What turned out to be odd to me was having to connect to both the emission and abedo and the alpha. (I would have thought that abedo would have been enough... but this is all relatively new stuff to me.)

    For future reference, here are two screenshots that may save someone else some time. I was trying to show a dashed line composed of two colours (red, yellow and alpha). Last picture is the final result with line.textureScale = 10.0f.

    I will probably want to do the texture scaling from the shader graph eventually.


    Screen Shot 2020-01-03 at 9.35.56 AM.png Screen Shot 2020-01-03 at 9.32.49 AM.png

    Screen Shot 2020-01-03 at 9.38.45 AM.png
     
  11. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    43
    Ah, also another gotcha. For the longest time I was trying to figure out why my texture of simple red circles was getting distorted. Turns out that it was due to using Joins.Weld - which now that I think about it makes sense given that the vertices at the joints are being extended to fill in the space and creating elongated triangles.


    Screen Shot 2020-01-03 at 10.03.30 AM.png Screen Shot 2020-01-03 at 10.02.50 AM.png
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yep; also some texture distortion can be reduced by subdividing lines into shorter segments, given that 3D hardware has issues UV mapping long thin polygons.

    --Eric
     
  13. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    Hello @Eric5h5
    I am trying to use LineDrawing functionality in my game but the drawn line is rendered in Screen Space - Overlay canvas mode and not in the Screen Space - Camera canvas mode.

    To illustrate the problem I changed the canvas mode to Screen Space - Camera in Vectrocity LineDraw demo scene. I have attached the picture to this post. Can you please guide how can I use Vectrocity in this canvas.

    I have up until now never used Screen Space camera rendering for canvases but I am using it currently because I am looking to get a snapshot(to save player drawings) of only UI from a render texture which I can only do in Screen Space Camera canvas because camera can cull certain layers of UI objects.

    Image Link: https://imgur.com/YHm70kz

     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    As it says in your screenshot, screen space camera isn't supported for the editor, sorry. But if it still works for your game then you can ignore that.

    --Eric
     
  15. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    Noted.

    Although it displays clear message in the Scene view about the canvas; while researching for alternatives I read the technical manual of Vectrocity. In the manual, in Canvas and Cameras section it says that Screen Space Camera is supported and certain methods like Vectorocity.SetCanvasCamera(camera) to set screen space camera so I was hopeful.

    Unfortunately it doesn't work as informed.

    Can you suggest me any alternatives? I want to allow the player to make markers on world map by drawing with mouse drag?
    Thank you for your time
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Rendertextures work with Draw3D (so, no canvas).

    --Eric
     
  17. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    Thank you for suggestion. I try drawing 3D line and putting it in a layer which camera can see.

    I stumbled of another problem. I am trying to simply the line by using Unity's LineUtility class. After drawing the line I assign the new set of points to the verctorline object and run Draw() method.

    Unfortunately the simplified line is Drawn but the last few points are not drawn. I can see the points in the point array but they are not rendered perfectly. Please see the picture before line simplification and after line simplification.

    The 4 line code that I have put at the end of Update function in Vectrocity Demos > DrawLineMouse scene:

    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.S))
    2.             {
    3.                 // Smooth the line
    4.                 List<Vector2> simplifiedPoints = new List<Vector2>();
    5.                 LineUtility.Simplify(line.points2, smoothingFactor, simplifiedPoints);
    6.                 Debug.Log("Line Smoothing new count: " + simplifiedPoints.Count+" vs "+line.points2.Count);
    7.  
    8.                 line.points2 = simplifiedPoints;
    9.                 line.Draw();
    10.             }
    Before Simplification Screenshot: https://imgur.com/TpjhhkQ
    After simplification Screenshot: https://imgur.com/BFrhfUR


     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    You can just drag and drop images onto the forum reply, much easier and better that way. Anyway, I'm not seeing that behavior:

    before.png

    after.png

    So I'm not really sure what to suggest. Vectrosity just renders whatever points it's given, so try printing out the actual values of the array to see if there's anything odd, also maybe it depends on line type (continuous vs. discrete) etc.

    --Eric
     
  19. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    Thanks for the advice. I didn't try dragging the image. I attached the image with some annotation.

    >> If you can check the image the points are already there, they are shown in the Inspector of VectorLine and they are also shown in the Scene View if you check the scene view properly in the photo. It is just the dots are not connected for some of the points which is very strange considering this never happens in other cases of vectorcity lines.
     

    Attached Files:

  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, but as I mentioned, I can't duplicate the issue and there's nothing obvious in the screenshot that would indicate what the problem could be. You can start by printing out all the points in the list to see if there's anything amiss, which there may not be, but you can't really tell from a screenshot. Also try again with a different line which might lead to seeing where the problem is.

    --Eric
     
  21. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    I'm having a weird issue when importing Vectrosity into a project that already includes Keijiros RTMidi ( https://github.com/keijiro/jp.keijiro.rtmidi )

    I get the following errors:-

    Assembly 'Assets/Vectrosity/Plugins/Editor/VectrosityEditor.dll' will not be loaded due to errors:
    Unable to resolve reference 'UnityEngine.UI'. Is the assembly missing or incompatible with the current platform?
    Reference validation can be disabled in the Plugin Inspector.

    and

    Assembly 'Assets/Vectrosity/Plugins/Vectrosity.dll' will not be loaded due to errors:
    Unable to resolve reference 'UnityEngine.UI'. Is the assembly missing or incompatible with the current platform?
    Reference validation can be disabled in the Plugin Inspector.

    This is on Unity 2019.2 and 2019.3b.
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Try using the source instead of the DLL.

    --Eric
     
  23. ayomidegidigbi61

    ayomidegidigbi61

    Joined:
    Sep 28, 2017
    Posts:
    4
    Hi

    I'm want to purchase this asset but I need to know if it'll be useful for my current project.

    I've read the MakeSplines section Vectrosity5 Coding Documentation and it seems an array has to be defined with all the points for the MakeSplines function to create a curve that passes through all the points.

    I just need to know if the MakeSplines function would work at runtime with the points array being constantly updated.

    I'm aiming to enable players to draw smooth curves in my current project and I've been looking for a solution that could help me with that as Unity's Line Renderer component doesn't have that functionality.

    Thanks
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, you can just call MakeSpline whenever the points are updated. Thank you for your interest!

    --Eric
     
  25. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    236
    Hi,

    I tried a simple line using a canvas scaler with 'scale with screen size', and then using the 'stretch' option of the anchor on the Line object (which is in a panel), and the line began moving away endlessly (X and Y coordinates increasing at the same rate).

    Is there an easy way to resize a line when its panel is resized?
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Not that I'm aware of, sorry...I don't really know what Unity's doing in the background in that case.

    --Eric
     
  27. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    236
    No problem, thanks for the answer, I'll find a way.
    And you're not alone not knowing what black magic Unity is doing when a UI panel is resized...
     
  28. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    236
    I have noticed that when you set the anchors to top or middle the line is continuously scrolling, it only works fine when the anchors are to the bottom.

    To reproduce it:
    - create a new project
    - set the Canvas Scaler to 'Scale With Screen Size' (that is the important step to reproduce the bug)
    - add a line
    - set the line anchors to top-left
    - observe that the coordinates in 'Line Points' are constantly modified

    [Edit] In a more complex scene I have reproduced it even with the anchors at the bottom, so I have no workaround for now
     
  29. ayomidegidigbi61

    ayomidegidigbi61

    Joined:
    Sep 28, 2017
    Posts:
    4
    Hi,

    I just got the Vectrosity asset and as a beginner programmer, I've been using the Bolt Visual Scripting asset. However, it seems Vectrosity was built in a different way that has made it impossible for me to use with Bolt.

    Please can you help me here, are there some other settings I need to play with to enable Vectrosity's compatibility with Bolt like other assets?

    Thanks
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    I don't know anything about Bolt, sorry, so I don't know what it would take or if it's possible at all. I'd suggest doing some beginner Unity scripting tutorials, and you may find you don't need to rely on a scripting asset after all, which will always have some limitations.

    --Eric
     
  31. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    236
    Is there a way to stop the constant auto-updating of the Line Points coordinates in the editor?
    It is very disturbing and prevents to see the lines (as they scroll out of the screen too fast).

    Even renaming the gameObject containing the 'VectorObject2D' component requires to disable the gameObject to finally stop the auto-updating (but as nothing is displayed, it won't help for the initial problem).

    I am not sure why it happens, but whenever I use 'Alt+Shift' to change the corner to the lower-right corner of the rectTransform, the coordinates of the points start changing endlessly.
    In fact, just setting 'Pos X' to '8' (for example) will start an endless horizontal scrolling of the lines.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    The UI scale mode should be set to constant pixel size. Vectrosity was designed so that for 2D coordinates (0, 0) is the lower-left, and (screenWidth-1, screenHeight-1) is the upper-right.

    --Eric
     
  33. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    236
    In the documentation, 'Canvas Controls' paragraph, it is indicated that it is possible to use the 'scale with screen size' option of the canvas scaler.
    And to be honest, as it is often possible to change the screen resolution in a game, it is a really interesting option.

    It is only when in the editor and not running that there's a problem.
    It works perfectly fine when running, even in the editor.
    I even use a negative X scale to draw my graph as I need it, and it works very well and the performance is outstanding!
     
    Last edited: Jan 22, 2020
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, that's regards to the editor, sorry. Runtime doesn't have that limitation.

    --Eric
     
  35. MasterControlProgram

    MasterControlProgram

    Joined:
    Apr 18, 2015
    Posts:
    21
    I've been searching for a solve for this for a while and haven't been able to find a solution. Hoping someone might be able to help here. I'm creating a real time line drawing experience on mobile. User draws their finger over screen and it renders a painted line. I'm using MakeSpline to take the touch points from the user and make a smooth line from this. This works pretty great for the most part as the resulting line is very smooth.

    The problem is that I'm running MakeSpline every time a touch point is added and the spline recalculates. This isn't great on performance but more problematically, because new points are considered, parts of the line "shake" because they are being recalculated with the new points in mind.

    I suppose what I'm looking for is something more like AddToSpline, where only the last X number of points are used to calculate the spline. And everything before that is retained. The alternative way I've thought to do this is instead smooth the input touch points (add more points between) and not use MakeSpline.

    Thoughts on this?
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    I'd suggest using the index feature of MakeSpline, where you increase the number of points in the line, and use MakeSpline from an index instead of redoing the whole thing.

    --Eric
     
  37. MasterControlProgram

    MasterControlProgram

    Joined:
    Apr 18, 2015
    Posts:
    21
    Ah! This is exactly what I needed. My new system has a tunable window where I real time calculate the spline. This window has a resolution multiplier which determines how many segments to add per points in the window. Once I'm out of the window, I update the index (times the resolution multiplier) locking everything before that index in.

    Seems to work great! Thanks for the advice Eric.
     
  38. ayomidegidigbi61

    ayomidegidigbi61

    Joined:
    Sep 28, 2017
    Posts:
    4
    I'm currently working on an idea similar to this but I can't seem to get it right. I started off with creating a vector line with a continuous line type and it worked quite fine except that I couldn't see the effect of the makespline function as the line wasn't smoothing out (it was very similar to the default Unity Line Renderer function).

    I then changed the line type to points and I kept getting the "Out Of Range Exception" error though I was calling the entire array containing the updated Vector 2 points.

    I'm an amateur programmer and I love if I could get an idea of how to get past this hurdle. Thanks
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    MakeSpline requires that the line have a bunch of points in the list; how many depends on things like how smooth you want it and how long the line is. LineType.Points is how the line is drawn and doesn't have anything to do with the points in the list.

    --Eric
     
  40. crazymonkay

    crazymonkay

    Joined:
    Apr 1, 2013
    Posts:
    118
    Yello,

    I am wanting to use Vectrosity to draw a bunch of line segments with caps on either end of each segment. I originally was hoping to use a single VectorLine with the Discrete line type, but it looks like this only draws the caps for the first and last points of all the lines.

    Is there a way to do multiple end caps for a single VectorLine or do I have to use multiple VectorLines?

    Thanks!
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    You'd need to use multiple VectorLines; each line gets one start cap and one end cap.

    --Eric
     
  42. crazymonkay

    crazymonkay

    Joined:
    Apr 1, 2013
    Posts:
    118
    Ok, just wanted to make sure there wasn't something I was missing. Thank you!
     
  43. peterhhh

    peterhhh

    Joined:
    Aug 3, 2018
    Posts:
    1
    Hi, I'm having a problem. If I put the UI Scale Mode of the canvas on "Scale with Screen Size" and then select the line inside the canvas, it keeps moving fast towards a "very big number".. like 10000 unitis on the x and y per second. It also doesn't stop moving.

    Help :) Loving the plugin
     
    Last edited: Feb 19, 2020
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, that's not supported, sorry.

    --Eric
     
  45. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    236
    Hi,

    I am using Vectrosity because of its incredible performances, and I'm very happy with it!

    Yet, I've seen that it could be slightly (very slightly) improved in its 'VectorLine.Line2D()' method.
    More specifically, the profiler indicates that the list getter is consuming most of the time.
    Using a Vector2 temporary value to store 'm_points2' and 'm_points2[i+1]' in order to reduce by 2 their getter calls helps a bit.
    Code (CSharp):
    1. Vector2 tempPoint = m_points2[i];
    2. p1.x = tempPoint.x; p1.y = tempPoint.y;
    3. tempPoint = m_points2[i+1];
    4. p2.x = tempPoint.x; p2.y = tempPoint.y;
    But in fact, if the local variables are set to 'Vector2' instead of 'Vector3', then you can just write:
    Code (CSharp):
    1. p1 = m_points2[i];
    2. p2 = m_points2[i+1];
    And it will also improve a bit the other parts of this method.

    With just that trick I went from 0.26ms to 0.21ms for the whole method.
    Not a huge improvement, but that's still 23% for a method which is (in my use-case) the heavier one when I draw a my graphs (4 graphs for a total of 2048 points updated each frame).

    Also, if you avoid multiplying Vector2, but separate the calculation using '.x' and '.y', then you can gain some more.

    I went from 0.21ms to 0.18ms by doing that in the 'm_capLength' 'if' (I am executing the 'then' branch of that 'if', I guess the gain would be larger in the 'else' branch as there are more Vector2 multiplications).
    Code (CSharp):
    1. float coef = normalizedDistance * m_lineWidths[widthIdx];
    2. px.x *= coef;
    3. px.y *= coef;
    4. ...
    5. coef = normalizedDistance * m_lineWidths[widthIdx+1];
    6. px.x *= coef;
    7. px.y *= coef;

    So, the total gain for the 'VectorLine.Line2D()' method is 30%.
    I guess you can have about 20-25% for 'VectorLine.Line3D()' because you cannot use the 'Vector2' trick so you'll have to rely to using temp values to reduce the list getters which is not as great but still interesting.

    For information, I have made all the profilings using a StopWatch in release builds and with always the exact same conditions (no user input involved).
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Interesting, thank you. I assume that I was using Vector3 because of MultiplyPoint3x4, though that would implicitly convert to Vector2. It might be because of "historical reasons" through the various versions over time and never got properly cleaned up. ;)

    --Eric
     
  47. InfiniteMonkey

    InfiniteMonkey

    Joined:
    Oct 8, 2016
    Posts:
    13
    Hi! For a while now I've been getting this when I run the Unity Editor : "Could not load signature of Vectrosity.VectorLine:SetMask". Everything still worked just fine, but I just noticed that on a fresh checkout all the prefabs where I've used VectorObject2D are now showing a missing script! If I load up the new checkout, the Vectrosity.dll plugin shows 6 files inside it - BrightnessControl, LineManager, VectorObject3D, VisibilityControl, VisibilityControlAlways, VisibilityControlStatic, whereas if I load my previous checkout with *the same dll* (like I literally copied it from one to the other to check, the dll also lists VectorObject2D! Any idea what might be happening or how to fix this? I'm tearing my hair out!
     
  48. InfiniteMonkey

    InfiniteMonkey

    Joined:
    Oct 8, 2016
    Posts:
    13
    I just found this (and yes, I'm using Unity 2019.2) :

    I'm guessing you're using Unity 2019.2 or higher.

    Unity 2019.2 has a major breaking change. The Unity UI library moved from UnityEngine.UI.dll as part of the core Unity installation to Unity.ugui.dll as an optional install through the Package Manager.

    DLLs compiled in 2019.1 or earlier that reference UnityEngine.UI are not compatible with Unity 2019.2+.

    To resolve this issue, you will need to get the original script files or DLLs that are compiled for 2019.2+.

    Seems like a possibility?
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    Yes, for later versions of Unity, you should use the source code instead of the DLL.

    --Eric
     
  50. Arkon15

    Arkon15

    Joined:
    Mar 29, 2020
    Posts:
    1
    Hey, have only just begun my unity journey. I want to having a moving chart somewhat similar to a medical ECG monitor. The function will change over time and is moderately complicated. Visually I'd like to some sort of glowy/emission effect on the line, with a flat back ground. I think your package looks like it could be the answer. I'm more than happy to pay the money if this will do the the trick. What do you think? I'm working with a 3D project in Unity 2019.3, but this will go on a 2D UI. Thanks!
     
unityunity