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

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    436
    hello,
    quick question ...
    i would like to draw a line on Canvas that follows a game object like a trail renderer...
    the line should disappear after some time like you can do in trail renderer...
    i've tried the Draw Line Mouse script... but can't get it to work properly ....
    @Eric5h5 is this possible and how to do that?
    a example script would be very helpful ...
    many thx & keep it up the good work...
    M.:)
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Try turning that off. If that helps, then the data probably doesn't work well with Joins.Weld, like if the points are extremely close together relative to the line width, which could potentially be fixed by using a thinner line.

    Look at the code for the Path demo, and to make the line disappear, call RemoveAt(0) with the points list at repeated intervals.

    --Eric
     
    Muckel likes this.
  3. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    436
    thx
    i totally forgot about that demo.... yep that's all i need :)

    well would be nice to some examples for UGUI in the next release ;-)
    thx & keep it up
    M.
     
  4. darkmage0

    darkmage0

    Joined:
    Jul 9, 2017
    Posts:
    1
    Hello,
    I was wondering if I could get help setting up two things please. One is a 3d grid that uses dashed lines instead of solid. Two is a 3d cube that is transparent that the edges are a dashed line that I can use as a selection 3d selection box.
    I was able to get a 3d grid setup pretty easy I'm just struggling to figure out how to make it dashed. Ive not been able to get the 3d selection box to work at all. The images below are the type of effects that I am aiming for.

    Thank you. p.s I'm sorry if this is not the correct forum to post these type of questions, This is my first time using unity forums.

    3d Grid using Dashed lines
    GridFloor.png

    3d Selection box Using Dashed Lines DashedSelectionBox.png
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    See the bottom of page 6 in the Vectrosity Coding docs about using line textures. Also some of the demos use line textures such as the Path demo. You could use the MakeCube function for the selection box.

    --Eric
     
  6. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    77
    Hi Eric,

    I keep getting the following error msg:

    Screen position out of view frustum (screen pos -nan(ind), -nan(ind), 10.000488) (Camera rect 0 0 1924 911)
    UnityEngine.Camera:ScreenToWorldPoint(Vector3)
    Vectrosity.VectorLine:Draw3D()
    Vectrosity.LineManager:LateUpdate()

    It is almost always appears during a session, sometimes only getting 4X other times 999999X......, i have no idea what exactly triggers it, cannot reproduce it by will, it just happens whenever it feels like it.

    I am procedurally generating solar systems and i use vectrosity to visualize the orbit with 3D lines. Enter a solar system, look around have a battle and at random times this error just pops up.

    Any suggestion how to get rid of it? Catch it? Is it important?

    Thanks in advance for any suggestions!

    upload_2019-7-12_11-10-15.png
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    I haven't seen that myself, but what scale are you using? It's possible that if you're using huge numbers, that might cause issues.

    --Eric
     
  8. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    77
    Hi Eric, each solar system has a radius between 15000 - 22000 unity units. I am not sure if any issue is detectable, there is not seem to be any visual glitch but to appearance of the error msg. Is there any way to catch the error and substitute the nan values with correct ones?
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Not that I'm aware of, but that wouldn't work anyway since you wouldn't know what values to use. In general bad things start to happen with floating point when go beyond >10K units from the origin (not just Vectrosity), so I'd recommend reducing the scale if you can.

    --Eric
     
  10. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    Hello Eric5h5,
    I have a 3D VectorLine with a tiled texture on it.
    This line show a path onto a map, so it's "linked" to the map.
    When I rotate the Camera and/or when I update the vertices because the map is panned the tiled texture move on the line.
    Is there a trick to "lock" in someway the tiling, so not to have this annoying effect, something like an "absolut local space tiling" ?
    Many thanks!
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    There isn't a function for that, sorry, so the only real way is to draw the line once and not update it.

    --Eric
     
  12. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    Many thanks for your reply, but also if I don't update the line the tiling change on the basis of the Camera position (so, when I orbit the Camera). Is there a way to avoid this?
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    I mean you can call Draw3D once, and then leave it at that, so nothing will update when orbiting the camera.

    --Eric
     
  14. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    282
    When I create a VectorLine it creates a GameObject in my hierarchy. How can I hide that game object in the editor hierarchy? I'd probably like to call gameobject.hideFlags = HideInHierarchy without having to search for the newly created object by name...
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    There isn't a function for that, but it should be easy enough to edit the source code, specifically the SetupLine function in VectorLine.cs:

    Code (csharp):
    1. m_go = new GameObject(name);
    2. m_go.hideFlags = HideFlags.HideInHierarchy;
    --Eric
     
    Innovine likes this.
  16. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    506
    Hi,

    I'm trying to use Vectrosity to draw engine trails. It's working in principle but I get artefacts where segments overlap. I'm using continuous line style with default material. image1.jpg

    Edit: Solved by using weld type joins. I had set to 'fill' as that was recommended for performance.
     
    Last edited: Jul 18, 2019
  17. spritehd

    spritehd

    Joined:
    Dec 6, 2018
    Posts:
    3
    Hi, i got strange bug with endcup textures. Different in images only in last point X coordinate: in pic1 x=120, in pic2 x=140.
    Code (CSharp):
    1.  
    2.  void Start()
    3.     {
    4.         VectorLine.SetEndCap("arrow", EndCap.Both, lineTex, frontTex, backTex);
    5.  
    6.        
    7.         var line = new VectorLine("line",
    8.             new List<Vector2> {new Vector2(100, 100), new Vector2(100, 300), new Vector2(120, 300)}, 50, LineType.Continuous, Joins.Weld);
    9.         line.endCap = "arrow";
    10.        
    11.         line.Draw();
    12.     }
    Снимок экрана 2019-07-19 в 11.13.37.png Снимок экрана 2019-07-19 в 11.14.01.png
     

    Attached Files:

  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    See this info in the docs: "Note that moving the offset inward on lines with many very short segments (such as a circle) can result in unexpected behavior. As long as the segment just before the end cap is at least as long as the end cap, though, you’re good."

    --Eric
     
  19. spritehd

    spritehd

    Joined:
    Dec 6, 2018
    Posts:
    3
    Thats mean Vectrosity not suitable for animation with end caps?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    It's fine for animation with end caps, you just need to make sure the last segment before the cap is at least as long as the cap.

    --Eric
     
  21. spritehd

    spritehd

    Joined:
    Dec 6, 2018
    Posts:
    3
    It can't be fine because during animation line have to pass corners and in this moments it shows many ugly artifacts.
     
  22. ch0kk0

    ch0kk0

    Joined:
    Jan 20, 2016
    Posts:
    36
    Is the TankZone demo still included ? Couldn't find it after importing the Vectrosity 5.6+ and Demo packages

    cheers
     
    schmosef likes this.
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    It's not included directly, but you can get it by sending me a PM with your invoice ID.

    --Eric
     
  24. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    282
    I just imported my project to Unity 2019.2 for the first time. Vectrosity is not working. I am not seeing any errors, but I'm not seeing any lines in the game view either.

    I am rendering lines with a custom canvas and dedicated camera to a render texture. I can see that the background color of the camera is correctly drawn to the render texture, but there is no vectrosity lines being shown. I can see where the lines are attached to the canvas in the scene, and they show up there. If I click on the Camera, in the Camera Preview I can see the lines.. but it just seems as if they are not written to the texture :/

    Any suggestions?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Try using a different material for the lines, with a different shader (such as one that writes to the z-buffer).

    --Eric
     
  26. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    282
    Does not appear to have made a difference..
    DId you mean like this:
    Code (CSharp):
    1.  
    2. public Material _mat;
    3. ...
    4. 1
    5. line = new VectorLine(...)
    6. line.material = _mat;
    7.  
    I created a new material using the LightweightRenderPipeline/Lit (and Unlit) and used that. I can see in the camera preview that the line has changed color to match the material. It is still not appearing in the render texture.
     
  27. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    282
    Nevermind, found it, the camera Target Display setting had somehow changed to Display 2...
     
  28. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    562
    I just upgraded my project to Unity 2019.2f1 and I am getting the following.

    Any ideas?

    Screen Shot 2019-07-30 at 11.08.29 AM.png

    Seems related to UnityEngine.UI
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    You have to use the source instead of the dll.

    --Eric
     
    jeffweber likes this.
  30. FortisVenaliter

    FortisVenaliter

    Joined:
    Mar 23, 2013
    Posts:
    17
    What's the recommended way to switch for a project that already has the Vectrosity DLL integrated, but is trying to upgrade?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Delete the VectrosityEditor.dll, then import the source package, deselecting everything except the scripts in the Vectrosity/Editor folder before clicking "import".

    --Eric
     
    FortisVenaliter likes this.
  32. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    6,226
    Well, I've tried, but I've got a problem I just can't solve. I want to make lines that are a single pixel thick, as in never more than a single pixel thick. So far? This is what I've got:

    upload_2019-8-8_0-57-4.png

    Okay, simple enough, right? But wait! Something's not right! What are... THESE?

    upload_2019-8-8_0-57-41.png

    These aren't the pixels I asked for! These are many more pixels! What I want is this!

    upload_2019-8-8_0-59-2.png

    For a clear demonstration of my problem, all the pixels in red here are the pixels I don't want.

    upload_2019-8-8_1-3-20.png

    Is there a way to do away with these unwanted pixels so I only have a clear, straight, single pixel line, or am I being hosed by Unity's rasterizer here?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Yeah, it's rasterizing polygons so there's probably not much you can do about that, at least using the Vectrosity method. 100% direct control over individual pixels would be more easily handled by writing pixels to a texture.

    --Eric
     
  34. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    6,226
    Yeah, the problem there is that that's... real dang slow, ya know? Especially when I'm going to have about 120 different lines on display. I can kinda solve it, but the solution I've found has some issues. I'll probably have to figure out some sort of formula or maybe a lookup table to make it work, because if I adjust line widths by hand... upload_2019-8-8_2-23-53.png
     
  35. mboog12

    mboog12

    Joined:
    Oct 4, 2011
    Posts:
    63
    Hi, i've tried switching to il2cpp. I'm on android and i'm forced to do so by the new 64bit build requirement on googleplay.
    My issue is that build keeps failing now with the error
    Fatal error in Unity CIL Linker
    Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Vectrosity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

    Any ideas? Thank you!
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Try using the source instead of the dll.

    --Eric
     
  37. mboog12

    mboog12

    Joined:
    Oct 4, 2011
    Posts:
    63
    it worked! thank you
     
  38. rkosaiPSQR

    rkosaiPSQR

    Joined:
    Aug 11, 2019
    Posts:
    2
    Hi Eric5h5,

    I'm shooting a RenderTexture using lines with a texture, specifically, arrowMiddle, from your demo package. When I create a RawImage from the RenderTexture, if the alpha < 1, the alpha still seems to be in effect, even though from the camera there is color filled in at that pixel due to the overlap. If I remove the texture, it works fine.

    Here, I have 3 VectorLines, overlapping and offset, using arrowMiddle as the texture.

    Screen Shot 2019-08-10 at 11.57.26 PM.png

    This is the generated RawImage
    Screen Shot 2019-08-10 at 11.57.42 PM.png


    Code (CSharp):
    1. public class VectrosityRenderTexture : MonoBehaviour
    2. {
    3.     public RawImage renderTextureImage;
    4.     public Texture2D lineTexture;
    5.     public Material mat;
    6.     Canvas canvas;
    7.     List<VectorLine> lines;
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         canvas = gameObject.GetComponent<Canvas>();
    12.         lines = new List<VectorLine>();
    13.     }
    14.  
    15.     void MakeLine(float xPos, float yPos)
    16.     {
    17.         var line = new VectorLine("Line", new List<Vector2>(), 1, LineType.Continuous, Joins.Fill);
    18.         line.SetCanvas(canvas);
    19.         line.SetWidth(200);
    20.         line.texture = lineTexture;
    21.         line.color = Color.cyan;
    22.         line.points2.Add (new Vector2(xPos, yPos));
    23.         line.points2.Add (new Vector2(Screen.width-1, yPos));
    24.         lines.Add(line);
    25.         line.Draw();  
    26.     }
    27.  
    28.     public void Draw()
    29.     {
    30.         MakeLine(0, 200);
    31.         MakeLine(50, 275);
    32.         MakeLine(100, 350);
    33.     }
    34.  
    35.     public void LoadImage()
    36.     {
    37.         CameraClearFlags saveCf = Camera.main.clearFlags;
    38.         Color saveC = Camera.main.backgroundColor;
    39.         LayerMask saveLm = Camera.main.cullingMask;
    40.  
    41.         Camera.main.clearFlags = CameraClearFlags.SolidColor;
    42.         Camera.main.backgroundColor = Color.clear;
    43.         canvas.renderMode = RenderMode.ScreenSpaceCamera;
    44.         canvas.worldCamera = Camera.main;      
    45.         DrawCompLayer();
    46.  
    47.         Camera.main.clearFlags = saveCf;
    48.         Camera.main.backgroundColor = saveC;
    49.         Camera.main.cullingMask = saveLm;
    50.         canvas.worldCamera = null;
    51.         }
    52.  
    53.     void DrawCompLayer()
    54.     {
    55.         Camera maskCam = Camera.main;
    56.         RenderTexture maskCamRT = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32);
    57.         maskCamRT.Create();
    58.         Texture2D compLayerTx = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
    59.  
    60.         maskCam.targetTexture = maskCamRT;            
    61.         RenderTexture.active = maskCam.targetTexture;  
    62.         maskCam.backgroundColor = Color.clear;
    63.         maskCam.Render();
    64.  
    65.         compLayerTx.ReadPixels(new Rect(0 ,0, Screen.width, Screen.height), 0, 0, false);
    66.         compLayerTx.Apply();
    67.  
    68.         maskCam.targetTexture = null;
    69.         RenderTexture.active = null;
    70.  
    71.         // load raw image
    72.         renderTextureImage.enabled = true;
    73.         renderTextureImage.texture = compLayerTx;
    74.  
    75.         // disable vector lines and only look at rawimage
    76.         foreach(VectorLine line in lines)
    77.            line.active = false;
    78.     }
    79. }
    80.  
    Any help appreciated. Vectrosity has been working really well for us. It's proven to be a very robust piece of software. Thanks for the hard work!

    Robert
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    I have to admit I never really fully understood what rendertextures do with alpha. You could try a different shader on the line, by supplying a material with that shader. Lines use the UI shader by default, which maybe isn't the best for rendertextures.

    --Eric
     
  40. rkosaiPSQR

    rkosaiPSQR

    Joined:
    Aug 11, 2019
    Posts:
    2
    Yeah, thought that might be the case. I'll let you know if anything turns up. Thanks for the prompt reply.
     
  41. asween16

    asween16

    Joined:
    Aug 9, 2018
    Posts:
    1
    Question: I am using the drawing tool to help label images. "Draw a box around a cat in the picture". I would like to be able to change the color within the box when I hover over the drawn box. I would also like some text to popup. Any sample code that will do this? Seems like the Demo 4 "Xray" may do what I want.

    Thanks
     
  42. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,516
    @rkosaiPSQR Regarding transparent alpha render textures: Ensure their color format is ARGB32.
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Changing the color inside a box isn't something you can do with Vectrosity, since it only draws lines, so you'd have to find some other way of doing that. The box in the X-ray demo is a quad that's resized based on the mouse position. Vectrosity is used for drawing the wireframe versions of the objects.

    --Eric
     
  44. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    740
    Hi Eric,

    I like to create some extremely smooth lines in variable width, dots like this.
    Would that possible with your asset? Thank you.

    Untitled-1.jpg
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Yes, that looks pretty similar to this Vectrosity demo.

    --Eric
     
  46. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    740
    Cool!
    Would it possible to display a filled transparent polygon, like this blue and yellow areas as well?
    If not, it would be a great addition.

    I can only thought about to use a 2d mesh used as polygon. But this must be build up of all the tangents and steps based exactly on your computation algorithm for bezier lines. Then plot your lines on top as a frame. (because the mesh edges are not antialiased by default)
    What do you think?
     
    Last edited: Sep 17, 2019
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    No, sorry, Vectrosity is a line-drawing utility and filled areas are a very different issue. There are other utilities that can triangulate arbitrary polygons from a set of points. You already have access to the final points used to draw the line (no need to recreate the curve algorithm) so that part is a non-issue.

    --Eric
     
  48. RodMath

    RodMath

    Joined:
    Oct 21, 2014
    Posts:
    13
    Hi,

    I have a single vector line with the maximum number of points in discrete segments. I don't need all the points every frame, so I vary drawEnd to just use the ones I need.

    I noticed in unity using the Statistics panel that it seems to be drawing all of the triangles every frame, or at least the number against Tris is in the thousands, even when I have drawEnd as 0. If I disable the game object, the Tris drops to a few hundred from the other objects in the scene and the performance improves slightly even versus drawEnd=0.

    I'm wondering if this is expected?

    Thanks

    Rod
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,156
    Hi, drawEnd doesn't affect the number of triangles, only the CPU time spent computing points. The idea is to avoid resizing the mesh arrays and generating garbage. The unused points are set to zero, since degenerate triangles are skipped and shouldn't be using any performance. There is however a possible small performance loss by setting some vertices to zero every frame if you're using Draw3DAuto or otherwise re-drawing every frame. If you don't change drawEnd frequently, it could potentially be better to use VectorLine.Resize instead.

    --Eric
     
  50. Andorid42

    Andorid42

    Joined:
    May 8, 2016
    Posts:
    8
    Hello,

    I am having difficulty with MakeCube function... specifically the cubes generated don't seem to match the standard unity scale... ie line3.MakeCube(Origin + new Vector3(0, 0, cubeSize), cubeSize, cubeSize, cubeSize); with cubeSize being set to .25f, which should be .25 meters correct? as 1 is 1 meter... however this does not seem to be the case... moving the cubes is also difficult as it doesn't align properly in my scene view. Any suggestions? I was contemplating just making the standard unity cube mesh and using MakeWireframe as a work around.

    Thanks for your time
     

    Attached Files: