Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. 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,398
    Yes, it's multiple lines in one VectorLine. Please see page 7 in the Vectrosity Coding docs about the difference between a continuous line and a discrete line.

    --Eric
     
    Benjamin_TYM likes this.
  2. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    35
    Hi.
    Is there any way to get a mesh from a VectorLine, like what you get when calling "lineRenderer.BakeMesh(myMesh)" for a LineRenderer in Unity?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    VectorLine.drawTransform is a reference to the line's Transform component, so you can do drawTransform.GetComponent<MeshFilter>().mesh.

    --Eric
     
    LogaNRV likes this.
  4. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    35
    Thanks. I ended adding a BakeMesh() function to the VectorObject scripts, called through the VectorLine.
    I prefer to use the internal mesh reference and copy it to the new mesh.
     
  5. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hello, what is the best way to have lines displayed beneath the ui layer?
    vector canvas is automatically added when lines are displayed, it's a screen space without camera and ui has the camera.

    Is there a step by step how to do this? I would like to prepare everything before lines are added to the screen. Also lines are in the separate scene and gui cam and canvas are in the don't destroy on load. do i need additional layers or sorting layers to create?

    thank you!
     
  6. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    any ideas?
     
  7. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    ok so here is the setup i have with universal render pipeline

    main camera (base camera)
    ui camera (overlay camera)
    vector camera (overlay camera)

    base camera (main) has camera stack:
    - vector camera (so it renders first, before ui)
    - ui camera

    no matter if i setup this in runtime or in editor it doesn't work properly.
    only way it does work is to start with screen space on vector canvas without the camera and it will show lines
    but then if i switch to screen space with camera it will show lines beneath the ui, but when i add more lines they
    all dissapear and it doesn't work until i change to screen space add lines and then change to screen space camera.

    any ideas?
    thanks!
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Hi, I'd recommend changing the .sortingOrder for the relevant canvases.

    --Eric
     
  9. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    hmmm it doesn't work when chaning from the editor in runtime, no effect
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    It does work here, though I'm not clear what you mean with having multiple cameras. Did you mean canvases? If you're actually using separate cameras, you could try changing the camera depths.

    --Eric
     
  11. unity_-iL2egyqv36OJw

    unity_-iL2egyqv36OJw

    Joined:
    Aug 31, 2020
    Posts:
    2

    please how can I make this system drawing using vectrosity how can I check if an gameObject is inside or outside drawing shape , I'm trying some matematic functions based on object point and linerendrerer positions but doesn't work , there is any simple way with vectrosity , thanks
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Vectrosity doesn't have a way of checking if an object is inside or not, sorry. That's still something you need to do yourself with some math functions (I don't know which ones offhand).

    --Eric
     
  13. cgrow67

    cgrow67

    Joined:
    May 31, 2016
    Posts:
    52
    Thank you for any help you might be able to give..
    Your product has worked really well for us but we would like to improve one aspect.

    I use Vectrosity to create a fairly large grid for the background.
    We use the grid in both an Orthographic and Perspective view.

    Is there any way to have the grid lines fade into the distance?
    The effect at distance is very distracting.

    upload_2022-11-2_14-10-50.png

    I tried using VectorManager.SetBrightnessParameters and realize this is designed for a different usage.
    I've tried using material based lines.
    I've also tried having separate VectorLine object for each individual grid line.

    I did notice the game objects behind the VectorLines are all at the same coordinates which might explain why SetBrightnessParameters doesn't work.
    After playing with this, I'm having no luck either..

    If the answer to the first question is yes and you have any pointers, they would be greatly appreciated!

    Thank you,

    Chris
     
    Last edited: Nov 3, 2022
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Hi, assuming this is using Draw3D lines, the only thing I can think of is a shader-based solution, though I don't know exactly how you'd write the shader.

    --Eric
     
    cgrow67 likes this.
  15. cgrow67

    cgrow67

    Joined:
    May 31, 2016
    Posts:
    52
    Wow... never thought of that...

    Just using the TextMeshPro Distance Field shader made a huge difference!..

    Thank you!
     
    hopeful likes this.
  16. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    I have two problems I want to solve with Vectrosity using only 3D lines.
    1. I want to always render my 3D lines as if they were facing a camera infinitely far up in the -z direction. Do I need to place a camera far in that direction just for that purpose or is there a less "gimmicky" way of doing it?
    2. I want to render an arrow at the tip of the line renderer. Is this possible? I didn't find anything like that in the demos.

    Is this possible with Vectrosity?

    Thank you!
     
    Last edited: Nov 16, 2022
  17. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    Please halp :(
    It must be possible to add a tip to a 3d line in Vectrosity. I'm sure I saw a showcase of that in some of the showoff material.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You can use SetCamera3D with a camera facing down. It doesn't have to be infinitely far up, just put it anywhere. The important thing is that it's facing down. You can use .endCap with SetEndCap to make an arrow.

    --Eric
     
    theforgot3n1 likes this.
  19. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    I got the cap to work.
    But I got some strange behaviour with the camera fix.
    First off, if the line is on a lower z-level than the cameral, it does not show. That's fine if I put the camera on -100 z though. However, the line also scaled with the -z distance, so I have to change it to orthogonal. OK fine, now it works fine and the width is predictable.
    Now I get another error, unfortunately, which is that the texture of the line is off. It's only off in this one place though on the map.
    This is what it looks like when the camera is position at 0,0,-100

    upload_2022-11-19_11-31-23.png

    I got it to work by moving the camera to 100,0,-100 though.

    upload_2022-11-19_11-43-8.png

    It's still unclear where exactly I wanna put my camera though... because if I move to x = 1000 the arrow gets a different appearance, and if I am at x = 10, it will bug out if my character moves to the tile at x = 10.

    Is there a way to always get the same consistent behavior regardless of the placement of the camera in 3D?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Keep in mind that when textures are used, they're still in screen space and won't work the same as typical UV-mapped textures on polygons. I'm not sure Vectrosity is really the best fit for what you seem to be going for here.

    --Eric
     
  21. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hello, I managed to setup camera ordering with URP, only thing left is that I have RectTransform of lines in a offset, checkout the picture:
    line.png

    when i set x,y and z to zero and scale to one positions are shown where they should be. I was looking at how line is created and I have seen that you reset RectTransforms to zero in SetupTransform in VectorLine, somehow it's set to something other than that.

    Here is how i create the lines:

    Code (CSharp):
    1.  
    2.             var measurementPoint1 = points[0] + normalVector * 1f;
    3.             var measurementPoint2 = points[1] + normalVector * 1f;
    4.             var measurementLine = new VectorLine(id.ToString(), new List<Vector3>
    5.             {
    6.                 measurementPoint1,measurementPoint2
    7.             },_config.TextureLine,2f);
    8.  
    so nothing special there, these points are from mesh vertices which are transformed from localToWorld, so that should not cause the offset.

    canvas is child of another object and it's position and scale is not zero and one, but that is understandable
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    The way lines are drawn in screen coordinates means the rectTransforms/positions/scales can't really be altered without also moving lines. I don't think there's any way around that unfortunately.

    --Eric
     
  23. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    I have a question of using 3d and canvas lines (3d being in obstructed in space and canvas lines are the ones that are drawn over everything else)
    here is what i have setup:


    Code (CSharp):
    1.  
    2.  
    3. VectorLine.SetupVectorCanvas();
    4. canvas= VectorLine.canvas;
    5. canvas.sortingOrder = -1;
    6.            
    7. VectorLine.SetCanvasCamera(uiCam);
    8.  
    9.  
    10.  
    this makes ui cam to render lines, it is drawn over all 3d objects in the scene
    how to have lines drawn in the space so they are obstructed with objects

    i have ui cam and main cam, do i need to set it up with main cam and how to properly do it, i didn't manage to work it out
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You can use Draw3D for lines using Vector3 points, so they are drawn in the world and not in an overlay.

    --Eric
     
    schmosef likes this.
  25. Kaboom

    Kaboom

    Joined:
    Mar 16, 2014
    Posts:
    32
    I am trying to draw VectorLines onto a Screen Space - Camera canvas (using a separate UI layer camera). However, I have a perspective effect, so the panel onto which I want to draw is angled. It also moves: when you hide the UI, it rotates away around the Y axis and then slides sideways as in the second screenshot.

    upload_2023-2-27_20-0-58.png upload_2023-2-27_20-3-50.png

    The lines on the canvas should persist, and move along with the UI. For example, in the screenshot I want to draw a line (eventually an arc, but I'll settle for a straight line for now!) between planets and moons (which are image buttons in layout groups).

    Now, I found an old comment saying that's best accomplished using world coordinates, which made a lot of sense: I could not figure out how to get the Vector2 coordinates for (the pivot of) a UI rect but the transform.positions are readily available. However, when I use Vector3 coordinates (from onething.transform.position to otherthing.transform.position), no line visually appears (or not anywhere where I can see it), although the point coordinates seem correct. I thought I might need to tell the VectorLine what camera to use, but SetCanvasCamera() does not seem to be what I want. Also, that's static, and I also want to draw VectorLines in world space (for example for the orbits).

    If instead I use Vector2s, I get a bit further: just hardcoding some screenspace points results in a line on the canvas, but of course it's "flat" on the canvas and doesn't move with the UI. If I use the "not officially recommended"
    line.rectTransform.SetParent(panelTransform, false)
    then the line is drawn in the plane of the UI, and moves along with it, so... almost there! However, as mentioned - I can't figure out how to get the appropriate 2D coordinates.

    Summing up: how do I draw VectorLines on, and move them with, a RectTransform in a rotated Screen Space - Camera canvas?
     
  26. Kaboom

    Kaboom

    Joined:
    Mar 16, 2014
    Posts:
    32
    Update: I got a thing! This is with the line parented to the panel. I got the coordinates using panelTransform.InverseTransformPoint(planetRectTransform.position). So those points, and the resulting points of the arc, are Vector3s, but I then feed them to the VectorLine cast to Vector2s. Two gotchas, in case it helps someone else:
    • The screen is a bunch of nested layout groups, so I had to ensure the layout of the canvas was forcefully updated before accessing any positions; otherwise those would be invalid until the next frame. I couldn't find the snippet I used online, so I've included it below;
    • planetRectTransform.position was vertically offset by half the height of the containing area (the rect in which the planets are vertically centered.
    I still don't understand that second one: both the RectTransform pivot and the 3D handles show the position exactly at the center of the planet. However, it appears the "real" position is at the top of the rect, and the HorizontalLayoutGroup uses the anchoredPosition to move the elements into place vertically.

    Edit: my layout refresh function was apparently insufficient. If I call it twice in a row, then panelTransform.InverseTransformPoint(planetRectTransform.position) is correct and I don't need the weird offset.

    Update: just
    LayoutRebuilder.ForceRebuildLayoutImmediate(panelTransform);
    seems to do the trick. However, it's important to call that on a transform that actually has a layout controller, or it'll do nothing (it won't recurse down into children)! Also, I read that nested layout groups and content fitters may need multiple passes to settle, so I've made it a "bigger hammer" by having it just call ForceRebuildLayoutImmediate() on all children, depth first.

    upload_2023-2-28_15-48-35.png

    So thanks Eric, I think I've got it sorted. Should you have any "never do that because..." or "that would be way easier if...", I'm all ears of course :)

    Code (CSharp):
    1.  
    2.     /**
    3.      * Force a refresh of the layout of this RectTransform and its children.
    4.      *
    5.      * By itself, Unity may perform the layout over several frames. If you
    6.      * need the size or position of automatically layed out elements Right
    7.      * Now, you can call this on the topmost element and it will trigger a
    8.      * recalculation of all the LayoutGroups and ContentSizeFitters inside.
    9.      */
    10.     public static void ForceRefreshLayout(RectTransform transform) {
    11.         if (transform == null || !transform.gameObject.activeSelf) {
    12.             return;
    13.         }
    14.  
    15.         foreach (RectTransform child in transform) {
    16.             ForceRefreshLayout(child);
    17.         }
    18.  
    19.         LayoutRebuilder.ForceRebuildLayoutImmediate(transform);
    20.     }
     
    Last edited: Mar 2, 2023
    halley likes this.
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    So the thing is...oh wait, you've got it, cool. :)

    --Eric
     
    Kaboom likes this.
  28. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    I am having troubles setting end caps with the line that was created with MakeCircle

    Code (CSharp):
    1. rotationLine.MakeCircle(new Vector3(center.x, vertices[0].y, center.z), Vector3.up, GetRadius(vertices));
    2.                 VectorLine.SetEndCap("rotation_end_cap", EndCap.Back, 0.0f, _vectorConfig.EndCap1, _vectorConfig.EndCap2);
    3.                 rotationLine.endCap = "rotation_end_cap";
    this doesn't work when i comment out end cap part the game works, so there is some kind of error here
    also i would like to set start and end caps with different textures, any help appreciated!
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Generally you should use SetEndCap in a Start or Awake function somewhere, since it should only be called once. Also I'm not sure how it works to be using end caps with a circle, which by definition doesn't have any ends.

    --Eric
     
  30. wechat_os_Qy03ZcfHtYNbeFalceZtkH0Oc

    wechat_os_Qy03ZcfHtYNbeFalceZtkH0Oc

    Joined:
    May 12, 2022
    Posts:
    8
    I have some discrete lines, and I want to add end caps to all the segments' start and end. From documentation it seems I can only add to the start of the first and the end of last segment, not segments in between. Is there a work around I am missing? If it is not supported, is it possible to add it in the future?

    Or, should I just add round points to all the vertices? This is not very convinient to manage though, need to keep track which points are for which lines.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    For lines with end caps, you'd need to use a separate VectorLine for each; it won't work like that with discrete lines.

    --Eric
     
  32. wechat_os_Qy03ZcfHtYNbeFalceZtkH0Oc

    wechat_os_Qy03ZcfHtYNbeFalceZtkH0Oc

    Joined:
    May 12, 2022
    Posts:
    8
    seperate vectorLine for each does not work for my case, since I have large number of lines to draw, and too many gameobject will slow down the program. Really hope discrete line segments could draw their own caps, but if it is technically not possible, I will try drawing round dots at the ends of segments in other seperate vectorLines, hople it would work.
     
  33. gloriousdefeat2

    gloriousdefeat2

    Joined:
    Jul 8, 2023
    Posts:
    2
    hi, I just bought your package. Im drawing some circles. When I reparent some of the circles to a moving object they suddenly have a large height of about 10 pixels and some of the segments rotate. Some lines even dissapear while the object they are attached to moves and then reappear later. I searched for an answer but cannot find one. Any help would be much appreciated. Ill continue reading through the docs in the mean time.
     
  34. gloriousdefeat2

    gloriousdefeat2

    Joined:
    Jul 8, 2023
    Posts:
    2
    Nevermind. I found the answer in the docs. I had to set the draw transform property :)
     
  35. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    898
    Why not draw a textured line? That's what I use for dotted/dashed lines.
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Well, the issue is having end caps on discrete line segments. Using a texture for that would only work properly if all the line segments were the same length, otherwise the "end caps" would be stretched or squished. Maybe in some cases that could be acceptable. Unfortunately, true end caps per segment is too much complexity for a very specific use case.

    --Eric