Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. 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. am_jooz

    am_jooz

    Joined:
    Jun 12, 2018
    Posts:
    7
    Thanks for the answer, Eric! Moving the lines farther from the plane will not be appropriate as I want to draw them very close (like on a real football field). I already put a little margin and it does not solve much the issue.
    How do I do the shader stuff? Do you have any link to shaders that could do that?
    I actually wonder if I need to get rid of those lines and use proper solids...
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    I don't have a specific link offhand, but do a search for "unity shader z-fighting" or similar. Also you can try increasing the camera near clipping plane and decreasing the far clipping plane as much as possible, so the depth precision is less spread out.

    --Eric
     
  3. am_jooz

    am_jooz

    Joined:
    Jun 12, 2018
    Posts:
    7
    copy that. Thanks a lot!
     
  4. tabulatouch

    tabulatouch

    Joined:
    Mar 12, 2015
    Posts:
    13
    Hello,
    I am a Customer of the full package.
    I expected very smooth lines, instead i get very ugly looking jagged lines, also from your demos.
    That is very different from the renderings in your documentation, i can i get a simple smooth antialiased line using the basic component?
    Using latest 2018.3

    Best

    Thank you
    SB
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    For 3D lines, you can turn on FSAA. Currently, FSAA does not affect 2D lines on a canvas, due to Unity switching to a worse method for FSAA, and there's not really anything users can do about that. As a work-around, you can use the "free" anti-aliasing method described on page 10 in the Vectrosity5 Coding docs.

    --Eric
     
  6. artyom-zuev

    artyom-zuev

    Joined:
    Feb 15, 2018
    Posts:
    5
    @Eric5h5

    We are noticing a heavy performance hit from 14 relatively simple (2-20 points each) lines. What seems to be causing the issue is 14352 calls to Camera.ScreenToWorldPoint from VectorLine.Draw3D. My colleague is telling me that this is abnormal performance for Vectrosity and that in another game he worked on (Universe Simulator 2) Vectrosity used to render a lot more lines with nowhere this amount of calls like these. Could you help me determine the cause behind this? Thank you.

     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    Assuming continuous lines with a total of 140 points, that should be around 550 ScreenToWorldPoint calls. Perhaps you have far more points or lines than you think? Or you're calling Draw3D repeatedly instead of once per frame.

    --Eric
     
  8. artyom-zuev

    artyom-zuev

    Joined:
    Feb 15, 2018
    Posts:
    5
    Thanks, that helps! I've realized the lines were configured to be smoothed by internal Vectrosity smoothing function even though I've long moved those lines to work off already smooth and relatively points from my custom splines. That double smoothing accounted for unexpectedly dense geometry and those calls.
     
  9. apexsoftworks

    apexsoftworks

    Joined:
    Oct 5, 2016
    Posts:
    29
    Hi Eric,

    What are some good optimization techniques for Vectrosity? We have quite a few lines on screen creating 748 batches. Is there any way to group all of these lines together or to improve performance?

    Thanks,

    - Tate
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    Yes, you can use LineType.Discrete, so you could condense that down to one line, or a few.

    --Eric
     
  11. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    742
    I need a link to a site that specifically helps programmers program old school line drawn games. Could anyone help me with that?
     
  12. AzeExMachina

    AzeExMachina

    Joined:
    Jan 30, 2016
    Posts:
    12
    Hi Eric,

    here's my scenario:

    - I'm instancing a prefab that has a VectorObject2D attached
    - then I setup some things like end caps with a newly created end cap via script
    - I then proceed to add points as needed when touching the screen

    The issue is that the end caps are not set, my texture is always squared, I can scale them and color them fine, but the texture is not set.
    This issue doesn't occur if I create the lines with "new VectorLine(...)" using the same caps and textures.

    Do you know why? Maybe I'm missing something

    Thanks for your work!
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    Making prefabs with VectorObject2D isn't supported; instead you should create lines in code.

    --Eric
     
  14. The_Devil

    The_Devil

    Joined:
    Jun 6, 2015
    Posts:
    36
    I tried setting the offset of the material but the issue that happens is that the end caps also start animation and moving across. Is there a animate the material without having the end caps to move?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    No, a line is all one material. You can use VectorLine.textureOffset instead.

    --Eric
     
  16. SirSbows

    SirSbows

    Joined:
    Oct 2, 2016
    Posts:
    4
    Hi, I'm using Draw3D in my script to draw lines in the scene and a Vectorcanvas is created but the drawn lines are not being set as children to the vectorcanvas and their outside it. Is this suppose to happen or is there a way to set the lines as children of the vectorcanvas? Also would setting them as children give them the same sorting order as the canvas?
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    When using Draw3D, there isn't a canvas created. Perhaps you used Draw with a line instead?

    --Eric
     
  18. SirSbows

    SirSbows

    Joined:
    Oct 2, 2016
    Posts:
    4
    Oh I didn't know that, I think I wrote VectorLine.SetCamera3D(Camera.main) and that created the Vectorcanvas in my scene. Well is there a way I can parent the lines drawn to a random object in the scene instead?
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    That doesn't create a canvas either. :) (Also it won't do anything, since Camera.main is the default.) At any rate, setting 3D lines as children of a canvas won't accomplish anything, since they are standard meshes in a scene and don't use canvases in any way.

    --Eric
     
  20. The_Devil

    The_Devil

    Joined:
    Jun 6, 2015
    Posts:
    36
    Thanks!
     
  21. SirSbows

    SirSbows

    Joined:
    Oct 2, 2016
    Posts:
    4
    The lines that I draw using Draw3D are rendering behind 2d sprites in my scene and I need them to render in front of them. I tried changing the Z value of the sprite but it is always in front of the lines. The camera is in orthographic view. Is there a way I can do this?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    You can try changing the sorting order of the 3D lines using Renderer.sortingLayerName and sortingOrder, but if that doesn't work, probably you need to change the material for the line and/or sprites.

    --Eric
     
  23. SirSbows

    SirSbows

    Joined:
    Oct 2, 2016
    Posts:
    4
    Thanks for the help! I added the line GameObject.Find("lineName").GetComponent<Renderer>().sortingOrder to my script after the line is drawn and now they show up in front of my sprites. :)
     
  24. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    81
    Hi Eric

    I how would one go about freezing the rotation of an elliptic line that its drawTransform is set to a another object? I have a kind of a compass made of 3D VectorLine and although i want the compass to move with the object i do not want it to rotate as well, i would like it to keep a global rotation at all times.

    Thanks for your time!
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    You could have a empty GameObject that's the parent of the object that moves/rotates. Then have the empty move, and the child rotate, and use the parent with drawTransform. Another option would be to make an empty GameObject with a small script that copies the position of the "real" GameObject every frame (but not the rotation), and use that with drawTransform.

    --Eric
     
  26. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    81
    Thanks Eric!

    I managed to use the matrix property and set the position with no rotation in the update loop.
     
  27. wallyworld121212

    wallyworld121212

    Joined:
    Apr 15, 2018
    Posts:
    2
    Hi,
    I paid and downloaded Vectrocity, but I am still having trouble creating some labels that for objects like the following images. Sort of like a diagram where text is floated in space with a line that is drawn to the spot it is referencing. Is there a script or tutorial I can follow? Please be specific in answers. Thanks! I have attached some examples of visually what I am looking for.
    http://vis.berkeley.edu/papers/exview3D/
    https://www.gaysemiotics.com/gay-semiotics
     
    OfficialHermie likes this.
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    I can't really be that specific since it depends on how you're doing the text and objects. If you're using 3D Text and a normal 3D object, then you can just use the coordinates to make a line using Draw3D. Other combinations would require converting coordinates, such as with WorldToScreenPoint or the inverse.

    --Eric
     
  29. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    535
    Haha! Your references are really special. :-D :-D
     
  30. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    535
    Does Vectrosity support HDRP?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    Yes; 2D lines are drawn on a canvas, 3D lines can use whatever material you supply.

    --Eric
     
    sirshelley and OfficialHermie like this.
  32. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    535
    I have created a gameobject and added a script to it.
    The script creates 3D lines using this code:

    Code (CSharp):
    1.         var line = new VectorLine("Grid", points, lineWidth);
    2.         line.Draw3DAuto();
    I was expecting the resulting mesh "Grid" to be a child of the gameobject that the script is attached to.
    However, "Grid" is not parented to anything.

    How could I set "Grid" to be a child of the gameobject?

    Do I really have to take this "long road"?

    Code (CSharp):
    1.         GameObject nMesh = GameObject.Find("Grid");
    2.         nMesh.transform.SetParent(this.gameObject.transform);
    Wouldn't it be more natural if "Grid" was automatically parented to the GameObject which hosts the script that created it?
     
    Last edited: Apr 29, 2019
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    No, use VectorLine.rectTransform.

    No, a script can create any number of lines which can be used for different purposes. It's not expected that creating an object would automatically make it a child of anything.

    Code (csharp):
    1. var foo = new GameObject("something"); // not a child
    --Eric
     
  34. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    535
    Can you please explain how I could use "VectorLine.rectTransform" with "line.Draw3DAuto"?

    I want to parent the mesh to a certain gameobject like this:

    1. GameObject nMesh = GameObject.Find("Grid");
    2. nMesh.transform.SetParent(this.gameObject.transform);
    You told me to use "VectorLine.rectTransform" instead.

    But I have no idea what you mean.
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    line.rectTransform.SetParent, as "line" is type VectorLine.

    --Eric
     
  36. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    535
    Hello!

    I'm experiencing a situation where the mesh isn't created.

    Add this script to a gameobject:

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using Vectrosity;
    4.  
    5. public class gridscript : MonoBehaviour
    6. {
    7.     public int Rows = 7;
    8.     public int Columns = 11;
    9.     public float TileWidth = 0.075f;
    10.     public float TileHeight = 0.075f;
    11.     public float lineWidth = 2.0f;
    12.  
    13.     public void Start()
    14.     {
    15.         var mapWidth = this.Columns * this.TileWidth;
    16.         var mapHeight = this.Rows * this.TileHeight;
    17.         var position = this.transform.position;
    18.  
    19.         //uncomment the following line to check behaviour at (0,0,0): position = new Vector3(0, 0, 0);//if this line is added, the mesh isn't visible
    20.  
    21.         var points = new List<Vector3>();
    22.  
    23.         points.Add(position);
    24.         points.Add(position + new Vector3(mapWidth, 0, 0));
    25.         points.Add(position);
    26.         points.Add(position + new Vector3(0, mapHeight, 0));
    27.         points.Add(position + new Vector3(mapWidth, 0, 0));
    28.         points.Add(position + new Vector3(mapWidth, mapHeight, 0));
    29.         points.Add(position + new Vector3(0, mapHeight, 0));
    30.         points.Add(position + new Vector3(mapWidth, mapHeight, 0));
    31.  
    32.  
    33.         for (float i = 1; i < this.Columns; i++)
    34.         {
    35.             points.Add(position + new Vector3(i * this.TileWidth, 0, 0));
    36.             points.Add(position + new Vector3(i * this.TileWidth, mapHeight, 0));
    37.         }
    38.  
    39.         for (float i = 1; i < this.Rows; i++)
    40.         {
    41.             points.Add(position + new Vector3(0, i * this.TileHeight, 0));
    42.             points.Add(position + new Vector3(mapWidth, i * this.TileHeight, 0));
    43.         }
    44.  
    45.         var line = new VectorLine("Grid", points, lineWidth);
    46.         line.Draw3DAuto();
    47.     }
    48. }
    49.  
    As long as the GameObject which hosts this script is NOT located at (0, 0, 0), it works fine: A grid mesh is created.

    However, when the GameObject is located at (0, 0, 0), the mesh is invisible.

    Can you confirm that? I can provide a sample project if required.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    I tried the script and it works regardless of where the GameObject is; (0, 0, 0) works fine. Might have something to do with your camera position.

    --Eric
     
  38. GreyPoupwn

    GreyPoupwn

    Joined:
    Dec 6, 2016
    Posts:
    10
    Hey @Eric5h5 - I've done a cursory read of the Vectrosity documentation and I'm hoping to use it to tackle an important thing I can't seem to do using some of the components in UnityEngine.UI.Extensions.

    Long story short, I'm making a node-based puzzle system using a camera space UI Canvas. I can draw between my nodes and attach lines to anchors on said nodes. However, once the line is drawn, I have no way to detect when the user has clicked / hovered on any drawn line.

    Does Vectrosity support hover/click detection on a Line drawn on a UI Canvas? If so, you've got a customer.
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    You can use the VectorLine.Selected function for that, however this is meant for screen space, not camera space, so it may not work for your case.

    --Eric
     
  40. GreyPoupwn

    GreyPoupwn

    Joined:
    Dec 6, 2016
    Posts:
    10
    To clarify: By "screen space" you mean screen space - overlay, screen space - camera, or both? I'm assuming the former.
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    Actually both of those will work, sorry; I was thinking of a world space canvas, which doesn't work.

    --Eric
     
  42. apexsoftworks

    apexsoftworks

    Joined:
    Oct 5, 2016
    Posts:
    29
    Hi Eric,

    I have a question for you. I am working on using Vectrosity to create an arc using only two points. I know the start point and the end point and I know the "radius" of how much the arc comes out. See below for diagram example.

     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    You could do that with MakeCurve, though if you're asking about the math involved, I'm not really sure. :)

    --Eric
     
  44. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    81
    Hi Eric

    I have a bit of a trouble with drawing a dashed line between objects, i am using the selection box demo scene as a base and all is good until i move the camera, that is when weird stuff happens. Let me show you instead of trying to put it into written words ;)

    https://1drv.ms/v/s!AqDKYfErvs5phNQ3Bo5qgd5rRYnbvA

    Here is the initialization code:

    targetLine = new VectorLine("TargetingLine", new List<Vector3>(1), targetLineTexture,4,LineType.Continuous);
    targetLine.material = targetLineMaterial;
    targetLine.textureScale = 4.0f;
    targetLine.alignOddWidthToPixels = true;
    targetLine.Draw3DAuto();

    Could please hit me a with a revelation that eludes me? Let me know if you need more info, i have some code that deals with appending the line with new points and an update function that updates point positions to keep up with object movement.

    Thanks in advance!!!
     
    Last edited: May 4, 2019
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    Looks like you need to subdivide the lines into smaller sections, since 3D cards have problems texturing extremely long thin polygons.

    --Eric
     
  46. Blaze5565

    Blaze5565

    Joined:
    Sep 11, 2018
    Posts:
    11
    Hi,
    I'm having problems with some lines I'm trying to draw - despite manually setting the color for each, they all get drawn as the same color, and sometimes (but not always), when I try to change one line, the others all change to another color too. It's also connecting separate lines that I never said should be connected (though I can't confirm with a before image, there should be no fourth line there):
    VectrosityColorJoin1.png Before new line
    VectrosityColorJoin2.png
    After new line

    There's not even anything in my code to tell the old line to update. This bit runs only when the scene is loaded:
    Code (CSharp):
    1. // i = 0:GameManager.instance.save.vehicles.Count - 1
    2.  
    3. drawRoutesBkg[i].SetColor(new Color(0f, 0f, 0f));
    4. drawRoutesBkg[i].Draw();
    5. Debug.Log(GameManager.instance.save.vehicles[i].GetColor());
    6. drawRoutes[i].color = GameManager.instance.save.vehicles[i].GetColor();
    7. Debug.Log(drawRoutes[i].color);
    8. drawRoutes[i].Draw();
    And this bit runs when I add a new line:
    Code (CSharp):
    1. // GameManager.instance.save.selectedVehicle = arbitrary int
    2.  
    3. drawRoutesBkg[GameManager.instance.save.selectedVehicle].SetColor(new Color(0f, 0f, 0f));
    4. drawRoutesBkg[GameManager.instance.save.selectedVehicle].Draw();
    5. drawRoutes[GameManager.instance.save.selectedVehicle].color = GameManager.instance.save.vehicles[GameManager.instance.save.selectedVehicle].GetColor();
    6. drawRoutes[GameManager.instance.save.selectedVehicle].Draw();
    The only thing I can think of is that Vectrosity doesn't like having its lines stored in a List? Other than that, I have no clue why it would mess up like this. Oh, and I'm running Unity 2018.3.13f. Any help would be much appreciated.
     
  47. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    81
    Thanks Eric, you were spot on!

    I managed to test it using make spline to fill in the segment points between the target points and the increased resolution fixed the visual glitches. Is there any way to generate the points between the targets without make spline? It creates curvy lines that is not desired in this case.

    Thanks again!!!
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,262
    An item in a List has no way of knowing whether it's in a List or not and can't have different behavior. Try debugging the numbers you're using to refer to items in the list, and you'll probably find you're referring to lines you didn't think you were. At least that's what always happens when I have similar problems.

    It's quite simple to use Lerp for that, so you can make, say, a line with 5 points, where point[0] is the beginning of the line, point[4] is the end, then point[1] is Vector3.Lerp(point[0], point[4], 0.25f), and point[2] and point[3] are the same with 0.5f and 0.75f.

    --Eric
     
  49. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    81
    Thanks very much!
     
  50. robinspots

    robinspots

    Joined:
    May 10, 2018
    Posts:
    13
    Hi Eric,

    I'm seeing some strange behaviour that I can't find the cause of:

    When I create a VectorLine and move the GameObject in the editor, it shoots off the edge of the screen! It seems to travel in the direction that I originally move it and then keeps on going when I'm no longer moving it. This happens in both the editor and game modes. Also, if I select a Vectorline Gameobject which I've previously moved it will travel off the screen on its own!

    Have you ever seen this happen before? I'd appreciate any pointers. Thanks.
     
unityunity