Search Unity

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:
    3
    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,203
    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:
    33
    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,203
    Yep, that would do it. :)

    --Eric
     
    Glowing_Slab likes this.
  5. Glowing_Slab

    Glowing_Slab

    Joined:
    Jun 19, 2015
    Posts:
    33
    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,203
    Yes, Draw3D doesn't use a canvas.

    --Eric
     
  7. Glowing_Slab

    Glowing_Slab

    Joined:
    Jun 19, 2015
    Posts:
    33
    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:
    33
    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,203
    I don't have much experience with that and can't really advise, unfortunately.

    --Eric
     
  10. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    33
    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:
    33
    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,203
    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:
    16
    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,203
    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:
    16
    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,203
    Rendertextures work with Draw3D (so, no canvas).

    --Eric
     
  17. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    16
    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,203
    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:
    16
    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,203
    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:
    140
    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,203
    Try using the source instead of the DLL.

    --Eric
     
  23. ayomidegidigbi61

    ayomidegidigbi61

    Joined:
    Sep 28, 2017
    Posts:
    2
    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,203
    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:
    218
    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,203
    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:
    218
    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:
    218
    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:
    2
    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,203
    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:
    218
    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,203
    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:
    218
    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 at 2:58 PM
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    --Eric
     
unityunity