Search Unity

  1. Unity 2020.1 has been released.
    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. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    Apparently the problem was line.Draw3DAuto(); using just one line.Draw call instead fixed the flickering.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    All Draw3DAuto does is call Draw3D every frame. I changed the first couple of lines to this and there are still no problems:

    Code (csharp):
    1.     var line = new VectorLine("Test", new List.<Vector3>([Vector3(-5, -5), Vector3(5, 5)]), 4.0);
    2.     line.Draw3DAuto();
    --Eric
     
  3. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    Hey,
    I can reproduce the flickering with this script in Unity 5.2.1p4. It's the VectorManager.ObjectSetup with Draw3DAuto that causes it. Used to work in Vectrosity 4.

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Vectrosity;
    5.  
    6. public class StarPattern : MonoBehaviour
    7. {
    8.   void Start()
    9.   {
    10.   List<Vector3> points = new List<Vector3>();
    11.  
    12.   points.Add(new Vector3(-1, -1, 0));
    13.   points.Add(new Vector3(-1, 1, 0));
    14.   points.Add(new Vector3(1, 1, 0));
    15.   points.Add(new Vector3(1, -1, 0));
    16.  
    17.   GameObject pathObj = new GameObject("Path");
    18.  
    19.   VectorLine line = new VectorLine("PathLine", points, null, 10, LineType.Continuous, Joins.Weld);
    20.   line.continuousTexture = false;
    21.  
    22.   line.Draw3DAuto(); // Flickers
    23.   //line.Draw(); // No flicker
    24.  
    25.   VectorManager.ObjectSetup(pathObj, line, Visibility.Always, Brightness.None);
    26.   }
    27. }
    28.  
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    You shouldn't be using Draw3DAuto in addition to ObjectSetup. Either let ObjectSetup manage things, or don't use ObjectSetup and manage lines yourself.

    --Eric
     
  5. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hello Eric!

    I have an issue with line thickness, I can't solve by myself, I hope you can help.

    I am creating 3d long lines, first making a vectorline with it's points, then attaching to a gameObject by VectorManager. When running the scene, lines on the x and y axis maintain the specified line thickness. However, when the camera moves along the z axis, lines drawn in that axis become thicker as I approach the pivot point of the object.

    You can see in the pics pelow.

    before.jpg after.jpg

    Do you know what's happening?

    Thanks a lot
     

    Attached Files:

  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Long lines with one point in front of the camera and another point behind don't tend to work well. If you break them up into multiple smaller segments, that generally fixes things.

    --Eric
     
  7. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Thanks for the quick reply!

    With smaller segments the thickness issue is solved. However lines are flickering, maybe when line points get behind the camera? I can't avoid that...

    Any ideas for this?
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    I'm not sure, unless they're still relatively long? Try subdividing more.

    --Eric
     
  9. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    10 meters is good. Before it was 30.

    It's a bit of a pain that i have to subdivide all. But it's ok as long as those lines run smoothly :)

    Thanks!
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    New version out, which supports Unity 5.2.2! (On my site; uploading to the Asset Store now.) Note that Unity 5.2.0 and 5.2.1 are not supported now. I apologize for any inconvenience, but having extra versions for those is just confusing. The Unity API changes are hopefully settled down for a while. If you really need support for 5.2.0 or 5.2.1, and therefore Vectrosity 5.0, send me a PM.

    Vectrosity 5.1

    Changes:
    • Works with Unity 5.2.2, which is also required now, due to changes in the Unity API.
    • VectorLine.SetCanvas has the option to pass in a worldPositionStays boolean, which is useful for things like setting lines to a canvas which has a CanvasScaler component that scales with screen size.
    • 3D lines made with VectorLine.Draw can be clicked on and viewed in the editor without errors, and the list of points can be edited in the inspector. (The visual editor only works with 2D points, however.)
    • Thanks to editor improvements in Unity 5.2.2, the folders for Vectrosity have been moved so everything is under Plugins/Vectrosity. If you're upgrading from an older version, make sure to remove Vectrosity stuff from other locations.

    Fixes:
    • Fixed index out of range error that could potentially occur in certain cases with VectorLine.GetColor, GetWidth, and SetWidth.
    • VectorLine.Resize uses the correct number of maximum points for discrete / continuous lines.
    • Fixed extraneous triangle that could be drawn in certain cases when using VectorLine.drawEnd.

    --Eric
     
  11. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    Hi. I'm wondering, how can I make the line collider draw itself in world space? I'm not 100% sure if that is the cause of the problem, but I'm drawing all of my lines in world space and I have the collider active on the lines. However, the collider draws itself as a super small thing, not at all on the actual line. What could be the remedy to this?
     
    Last edited: Oct 28, 2015
  12. Daniel-F-F

    Daniel-F-F

    Joined:
    Apr 7, 2014
    Posts:
    9
    Hi,

    I Upgrade to Vectrosity 5.1 (Unity 5.2.2) and my lines not drawing anymore, only last line I add draw, my code is like that:

    VectorLine wpl = new VectorLine("3DLine1" , pts, null, 1.0f);
    wpl.Draw3DAuto();

    any idea?
    Thanks!
     
  13. Daniel-F-F

    Daniel-F-F

    Joined:
    Apr 7, 2014
    Posts:
    9
    Hi,

    Plus, if if call Draw3D() for each line in LateUpdate only last line added draw (my camera dont move or turn)

    Thx!
     
  14. Daniel-F-F

    Daniel-F-F

    Joined:
    Apr 7, 2014
    Posts:
    9
    OK,
    My Bad, Vectrosity now uses List of points instead array and I was managing that wrong way and then lines were overlapping

    Sorry for that, thank you!
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Here's a line I drew in world space, and here's a sphere with a circle collider interacting with it:

    Screen Shot 2015-10-28 at 12.18.22 PM.png

    So it does work as expected, as far as I know. Remember that the collider is a 2D collider and as such is effectively Z = 0.

    --Eric
     
  16. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,158
    Hey there.

    How exactly do I draw a line between two points over time? Is this even possible between only two Vector2-points or do I have actually create a big Array/List and visit/draw on every point?
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Although I just realized that you're probably using VectorLine.Draw, rather than VectorLine.Draw3D. With Draw, it uses a screen space canvas, so what you see in the scene view won't match the collider. It's fine in the game view though.

    Just change the points in the list used for the VectorLine.

    --Eric
     
  18. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,158
    Sorry, I think I don't get. When I just change the points in the list the line is still drawn immediately and not over time, animated/tweened.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    It's up to you to change the points over time; Vectrosity just draws whatever you give it.

    --Eric
     
  20. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,158
    I have the feeling you misunderstood me. I want to know if something like this is even possible with only two points:


    Say we have a startpoint at (0,0) and an EndPoint at (0,Screen.height) - am I able to animate/tween the line in a smooth way by using a Coroutine or Update or do I have to have more points along the long in order to do so.
     
  21. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    Yeah, I'm using Draw instead of Draw3D. Hmm.. For some reason it is drawing all the colliders as a straight edge with the length of 1. The selected collider is for the red line in scene. While playing the game, GameObjects collide with the position of the edge collider in the middle.
     
    Last edited: Oct 29, 2015
  22. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    321
    Hi Eric!

    I'm working on an Xcom style game, and I'm using your plugin to help me draw paths and borders and stuff. So, that being said, i have two questions:

    1. I'm experiencing a weird Z-sorting issue when i draw two lines in 3d space. (The bottom is the game view, note the green border drawing on top of the white path). What's causing that, how do i fix?


    2. I read in a previous post on this forum that your library isn't really set up for rounded corners. But seeing as how your the line guy, I thought I'd ask again. Do you have any idea how to draw rounded corners? I can't seem to find any info on this anywhere. Specifically - how did the boys at Firaxis pull this off?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    I understand you just fine, and my answer hasn't changed. ;) Just animate the points in the line, it's really that simple. Change the value over time.

    I'd need to see some code that demonstrates this; it always works correctly for anything I do.

    I would guess you're using shaders that don't write to the depth buffer, so you'd use different shaders, or edit the ones you're using (e.g. use "zwrite on").

    I assume they add more vertices at the corners.

    --Eric
     
    BTStone likes this.
  24. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    Ok, I'll keep trying to figure out if I'm doing something wrong with my code. If I don't come up with any conclusions this week I'll tidy it up a bit and send it to you, if you have the time to check it.
     
  25. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    321
    thanks for the feedback!
     
  26. JonS

    JonS

    Joined:
    Aug 9, 2013
    Posts:
    5
    Hi, I'm running into a problem using GetPoint3D01 on a line that's parented to a moving object and was wondering if I'm doing anything weird to cause it.

    It seems like GetPoint3D01 isn't taking its parents position into account and is always returning the same value regardless of where the parent is in the world.

    I'm creating the line with the following

    Code (CSharp):
    1. line = new VectorLine(name, new List<Vector3>(51), width, LineType.Continuous, Joins.Fill);
    2. VectorLine.SetCamera3D(UICamera.mainCamera);
    3. line.color = lineColour;
    4. line.MakeSpline(points);
    5. line.Draw3D();
    6. line.rectTransform.SetParent(mField);
    And it initializes fine. It moves properly with the field object when it moves, however when using GetPoint3D01(0) it always returns the same position regardless of where the field is. The position is correct for where the field was when the line was first created only.

    The documentation says this function returns the world space coordinates but that just doesn't seem to be the case here. Is there some update function that I should be calling to recalculate the world position as the parent moves? I tried re-calling Draw3D() and SetDistances() to no effect.

    I can get the desired position by simply adding line.rectTransform.position to the result of GetPoint3D01 so it's not a huge deal. Just took a while to figure out why my positions relative to the line were constantly wrong.
     
  27. JonS

    JonS

    Joined:
    Aug 9, 2013
    Posts:
    5
    Doh... oh course I find my problem like 2 minutes after posting. I found the section of the docs that mentions calling Draw3D in LateUpdate so it picks up translations properly. Seems to be working fine now.

    Not sure why re-calling Draw3D didn't work last time but it's good now.
     
  28. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    52
    Hi,
    I create a circle like this:

    Code (CSharp):
    1. int circleSegements = 32;
    2. selectionCircle = new VectorLine("SelectionCircle", new List<Vector3>(circleSegements + 1), selectionCircleTexture, 6f, LineType.Continuous, Joins.Weld);
    3. selectionCircle.textureScale = 3.0f;
    1. How can I set the amount of real segments (how many times my texture is drawn to represent the circle)?
    2. When I zoom out (change orthographic size) the amount of real segments changes, how to change this behaviour?
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    1. I'm afraid I don't know.
    2. If you draw the line once and don't update it when the camera moves, then it won't change.

    --Eric
     
  30. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    52
    Thanks for you fast response!
    1. Hmm.. I wasn't able to find out how this is possible either.
    It depends on texture size it seems, and when I change the texture scale there are corresponding to this fewer segments. Therefore I would have to try out how many segments I want to be displayed and change the texture scale accordingly. Not the best way. :(
    2. I don't redraw it, only change textureOffset to rotate, and position to follow player:
    Code (CSharp):
    1. selectionCircle.textureOffset = -Time.time * 2.0f % 1;
    2. selectionCircle.rectTransform.position = SelectedShip.gameObject.transform.position;
    But this seems to be enough to update the amount of displayed segments.
     
  31. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    Hi Eric (and everyone else),

    I'm currently using LineMaker on the majority of my models and it is working brilliantly. My only issue is unique to my needs in that I don't need the diagonal lines across the quads. Does that make sense? (image a quad split into two triangle, I don't need the diagonal longest hypotenuse edge, just the 4 corners).

    I'm looking at the LineMaker.js, is there a quick 'tweak' to the code I can perform to omit these as I'm currently going around the model, after clicking 'Connect All Points', manually deleting these.

    Kindest Regards,
    Matt.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Try changing the material offset instead of using VectorLine.textureOffset.

    Not that I know of. Essentially you want to convert triangles to quads, which is a fairly hard problem.

    --Eric
     
  33. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    52
    Thanks again for the answer.
    Found a post where you wrote that material offset is the prefferred way, therefore i searched for it on the web, but couldn't find a sample. Sorry, but I can't figure out how to let the circle rotate by changing the material offset.
    Tried it with that:
    Code (CSharp):
    1. float scrollSpeed = 10f;
    2. float offset = Time.time * scrollSpeed;
    3. selectionCircle.material.mainTextureOffset += new Vector2(offset, 0f);
    Looking forward for your response, John
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    That will work, assuming you assigned a material to the VectorLine (and the shader in the material allows for texture offsetting).

    --Eric
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Colors are per segment, rather than per-vertex. You can "trick" it by adding an extra 0-length segment.

    --Eric
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Not a bug; as I said, colors are per-segment, not per-vertex.

    --Eric
     
  37. DigiScot

    DigiScot

    Joined:
    Aug 23, 2013
    Posts:
    27
    Apologies if this has been covered Eric, but is there a "simple" way to find out if the player has clicked on a line, and get the exact spot clicked on it?
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Use VectorLine.Selected, although that doesn't tell you the exact spot, but rather the segment index.

    --Eric
     
  39. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    9
    Sorry if you've already answered this. I saw this:



    I'm assuming that Vectrosity has a function to draw lines between all polygons of a mesh? For my game I want to draw between every vertex though, so Vectrosity would show the triangles instead of just polies. Is that possible?

    Thanks!
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    VectorLine.MakeWireframe

    --Eric
     
  41. DigiScot

    DigiScot

    Joined:
    Aug 23, 2013
    Posts:
    27
    Perfect, thank you!
     
  42. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    321
    Hi Eric,

    Really loving the software.

    Having some weird problems with EndCaps - first off, my lines are backwards for some reason. The points at the front (where drawStart = 0) is where the head of the arrow is located, and the end of the points3, where i feel like the arrow should be pointing, is actually the end of the arrow.

    second - using only the textures provided by the plugin, and setting the offset to -1.0, the endcaps are drawing on top of the line, giving me a weird result



    Thoughts?
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    That's correct, the head/front is at the beginning of the line (index = 0), and the tail/back is at the end (index = length-1).

    This is also as documented: "Note that moving the offset inward on lines with many very short segments (such as a circle) can result in unexpected behavior." Using an offset of -1 is moving the cap back by the length of the cap, but in this case the segments are too short for that to work visually. Theoretically this could be handled somehow by removing as many segments at the end as necessary, but that would significantly increase the code complexity and slow things down, so as always I need to try to balance features with speed/efficiency. So it's good to keep in mind that moving the end caps back by a length of 1 requires the segment they're attached to to be at least as long as the end cap itself for it to work right.

    --Eric
     
  44. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    9
    So I got the wireframe working, it looks wonderful. Thing is though I'm wanting to use it on a mesh that is modified in real time by a vertex shader. This isn't technically a Vectrosity problem but I'm wonder if it's even possible to do since the vertex movement is by a shader, not like it's updating the mesh every frame so Vectrosity can get it.



    Screenshot to show clipping when it pulses. Here's my code:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vectrosity;
    4.  
    5. public class LineMaker : MonoBehaviour {
    6.  
    7.     VectorLine line;
    8.     Mesh mainMesh;
    9.  
    10.     void Start() {
    11.         mainMesh = GetComponent<MeshFilter>().mesh;
    12.         //line = new VectorLine("PhotoWires", new Vector3[0], null, 1.0, LineType.Discrete);
    13.         line = new VectorLine("PhotoWires", new Vector3[0], null, 2.0f, LineType.Discrete);
    14.         line.MakeWireframe(mainMesh);
    15.         line.drawTransform = GetComponent<Transform>();
    16.         //VectorLine.SetCanvasCamera(Camera.main);
    17.     }
    18.  
    19.     void Update() {
    20.         mainMesh = GetComponent<MeshFilter>().mesh;
    21.         line.MakeWireframe(mainMesh);
    22.         line.Draw3D();
    23.     }
    24. }
    25.  
    I only added the mesh and MakeWireframe in Update cause I thought it could get the vertex shader updated mesh. Basically the effect I'm going for is a lowpoly mesh around the highpoly mesh that shimmers and pulses slowly. Any ideas?
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    I don't think you can read vertex positions from a shader. The only idea I have is to use the same math in C# code as in the shader, so the positions would be the same (computed twice, basically, on the CPU and the GPU).

    --Eric
     
  46. Ariegos

    Ariegos

    Joined:
    Jun 20, 2015
    Posts:
    24
    Is there a no clip mode when you're drawing 3D lines? So say you want the 3D line to always be in front of other 3D objects. Also is it possible to put arrow heads on the lines 3D mode?
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Use Draw instead of Draw3D.

    Yes, all line features are the same regardless.

    --Eric
     
    Ariegos likes this.
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Just posting this as a reminder, Vectrosity 5.1 requires Unity 5.2.2 (or later, presumably). Unity 5.2.0 and 5.2.1 are not supported.

    --Eric
     
  49. Michael_Squiers

    Michael_Squiers

    Joined:
    Nov 6, 2014
    Posts:
    32
    Question.png
    Hi,
    I've created a scene where the user can touch points on the screen and a line segment will be connected to each point. I would like to add a feature where the user can hold down the touch and the last line segment will become a curve. I want the beginning and end points to stay the same on the new segment. The distance to the apex of the curve will be the distance away from the last point created. I can get the distance easy enough. How would I get the last segment created to turn into this curve as described?

    Thanks.
     
  50. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hello Eric,

    I hope you can help me, one more time!

    I'm trying to apply a standard diffuse material, so my 3d lines receive illumination. It's something I did before in Vectrosity 4, but now I can't get it working with 5.

    It seems I have an issue whenever I add tangents to the line myLine.AddTangents (); And then use VectorManager.ObjectSetup to draw it.

    I get the error:
    IndexOutOfRangeException: Array index is out of range.
    Vectrosity.VectorLine.CalculateTangents ()
    Vectrosity.VectorLine.CheckNormals ()
    Vectrosity.VectorLine.Draw3D ()
    VectorManager.DrawArrayLine2 (Int32 i)
    VisibilityControl.OnBecameVisible ()

    I updated Unity to the latest version (5.2.2) and also Vectrosity.

    Do you know what I'm doing wrong?

    Thanks a lot!
     
unityunity