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

    ch0kk0

    Joined:
    Jan 20, 2016
    Posts:
    36
    Unity doesnt crash. I meant the app does, on the line specified
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    I'm not sure what you mean by "crash", then. Scripts can't really crash. What exactly is happening?

    --Eric
     
  3. ch0kk0

    ch0kk0

    Joined:
    Jan 20, 2016
    Posts:
    36
    vectrosity fails on the line i've already pointed out
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    I'm not sure what "fails" means exactly. :) What actually happens? What errors/etc.?

    --Eric
     
  5. yihanzhang

    yihanzhang

    Joined:
    Apr 19, 2017
    Posts:
    1
    Hello,

    I'm wondering if we can draw a line chart with x axis and y axis by using a data list. I didn't find an example scene in the vectrocity asset to do that, what method am I supposed to use?

    Any help will be appreciated.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    Vectrosity draws lines from whatever data you give it, so make a list with the point coords you want and Vectrosity makes a line from it. 2D lines normally use screen space coords, though you can also use viewport coords.

    --Eric
     
  7. PNordlund

    PNordlund

    Joined:
    Nov 20, 2013
    Posts:
    48
    Any hints for putting a vector line inside a ScrollRect? I create a Vector line and do the following:

    vline0.SetCanvas(this.GetComponentInParent<Canvas>(), true);
    vline0.drawTransform = this.transform;
    vline0.rectTransform.SetParent(this.transform);

    This puts the Vector line under the correct transform, a GameObject that's inside a ScrollRect, it also gets clipped correctly. However, the vector line moves at twice the speed of the other scroll content?
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    VectorLines are really not meant to be parented to anything, since that interferes with how lines are drawn. Use VectorLine.drawTransform instead.

    --Eric
     
  9. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi Eric (or anyone else),

    It's likely outside the support of Vectrosity, but I was wondering if someone has come up with a way to draw an arc using three points? Basically one point in the middle and two on each side to create a smooth curve between them. I have tried using MakeCurve to get the effect I'm after, unfortunately I can't reach the precision I need. As this is calculated at run time, I unfortunately can't pre-calculate all the possible values to get the curves I require.

    Any help is greatly appreciated!
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    There is VectorLine.MakeArc, though it's not from three points.

    --Eric
     
  11. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hey, thanks for the response! Yes MakeArc appears to make a portion of a circle though. I'm looking for a more arbitrary angle. I'll try playing around with MakeCurve some more!
     
  12. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Forgive my previous comment, I just read through the documentation again, and found that MakeArc can also be an ellipse! What a fool I've been! I have another question that again sits out of the actual scope of Vectrosity, but I was hoping you could point me in the right direction. I'm wanting to animate the change in shape from an angle pointing up, to the result of a MakeArc. e.g.:

    ^ to ) (rotate the bracket counter clockwise 90 degrees)

    The first issue of course is the amount of points that are needed in the angle compared to the arc. While not ideal, I figure I can make the angle by calculating positions for each point between the first, middle and last points. Though this is rotated in real time, which seems like a lot of calculations each frame to determine the direction of the angle.

    The second issue is then the animated transition between the two. I can utilise a second VectorLine that calculates the arc, and then tween each value over time to draw the real line, but I wondered if I'm missing some sort of built in functionality that could cut some or all of these steps?

    Thanks for anything you can offer!
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    There isn't any built-in tweening, sorry. You can use VectorLine.drawTransform to do the rotation (by having a linked empty object that rotates 90 degrees).

    --Eric
     
  14. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Oh! I didn't know this existed! So I can do everything at a standard orientation and from the center. Then use VectorLine.drawTransform to link it to a game object I move around the world and rotate, and the line will position itself accordingly? (After a VectorLine.Draw()) Because if so, that is... awesome.

    Edit: I can! This is fantastic!
     
  15. danbrodieauroch

    danbrodieauroch

    Joined:
    Nov 30, 2016
    Posts:
    1
    Hi Eric, wondering if you could enlighten me on an issue I'm having. Maybe I am using vectrosity incorrectly? I'm trying to use Draw3D/Draw3DAuto but I get a null reference (I think for m_mesh) whenever I try to update the points3 list, it works if I use just the normal Draw however. I'm using the latest vectrosity and Unity 5.6.0f3

    This is the error I get:

    NullReferenceException: Object reference not set to an instance of an object
    Vectrosity.VectorObject3D.UpdateMeshAttributes ()
    Vectrosity.VectorLine.Resize ()
    Vectrosity.VectorLine.Draw3D ()
    Vectrosity.VectorLine.Draw3DAuto (Single time)
    Vectrosity.VectorLine.Draw3DAuto ()
    VectrosityTest.Start () (at Assets/VectrosityTest.cs:17)

    Below code throws this error.
    Code (CSharp):
    1. public VectorLine vectorLine;
    2.  
    3.     void Start ()
    4.     {
    5.         var points = new List<Vector3>();
    6.         points.Add(new Vector3(1, 0, 0));
    7.         points.Add(new Vector3(5, 0, 0));
    8.         vectorLine = new VectorLine("test", points, 2.0f);
    9.         vectorLine.points3.Add(new Vector3(10, 0, 0));
    10.         vectorLine.Draw3DAuto();
    11.     }
    Below code runs fine.
    Code (CSharp):
    1. public VectorLine vectorLine;
    2.  
    3.     void Start ()
    4.     {
    5.         var points = new List<Vector3>();
    6.         points.Add(new Vector3(1, 0, 0));
    7.         points.Add(new Vector3(5, 0, 0));
    8.         vectorLine = new VectorLine("test", points, 2.0f);
    9.         //vectorLine.points3.Add(new Vector3(10, 0, 0));
    10.         vectorLine.Draw3DAuto();
    11.     }
     
  16. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    215
    Any fix on that problem with Unity 5.5 and the MissingComponentException when using Draw3DAuto()?

    Thanks to the "great" Asset Store I don't know how to revert to old versions of assets easily once I upgraded.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    The fix for 5.4.1 was causing other problems, so I've reverted that and made a different fix instead for 5.4.2. In the meantime you can send me a PM with your invoice number and I'll send you the relevant scripts. The points3 thing could also be worked around by adding to the points list instead of VectorLine.points3.

    --Eric
     
  18. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi Eric,

    When a line is created but not drawn, it is put in the root hierarchy. Would it be/is it possible to specify a parent for undrawn lines to keep the scene a bit tidier?

    Also just for my own benefit, if I want to stop drawing a line for a period of time, is it best to destroy the line and recreate it? I don't want to set all the points to some arbitrary number, and there doesn't seem to be a 'Hide' method.

    Thanks!
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    VectorLine.active

    --Eric
     
  20. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Damn, I'm sorry.
     
  21. rms80

    rms80

    Joined:
    Aug 2, 2015
    Posts:
    8
    Hi Eric, I just updated to 5.4.2 from your website, and now Unity (5.6.1f1, windows 64-bit) crashes when I am working with 3D VectorLines. If I revert to 5.4.1 the crash goes away. So this does seem like Vectrosity is causing the crash.

    The reason I updated was that in 5.4.1 I was getting this exception, when creating lines at runtime ('intersect' is the name of the GameObject I am attaching the lines to, using ObjectSetup

    MissingComponentException: There is no 'MeshRenderer' attached to the "intersect" game object, but a script is trying to access it.
    You probably need to add a MeshRenderer to the game object "intersect". Or your script needs to check if the component is attached before using it.
    Vectrosity.VectorObject3D.Enable (Boolean enable)
    Vectrosity.VectorLine.set_active (Boolean value)
    Vectrosity.VisibilityControl.OnBecameVisible ()


    With 5.4.2, I can display the lines for a few frames, but I get this exception each frame:

    Assertion failed on expression: 'm_ActiveCoroutines.empty()'

    There is no stack trace. And eventually (after 20-30 frames) Unity does a full crash (ie with a submit-error-to-Unity dialog)

    My setup code is basically like this:

    VectorManager.useDraw3D = true;
    vectorLine = new VectorLine(name, vertices, width, LineType.Discrete);
    VectorManager.ObjectSetup(intersect, vectorLine, Visibility.Dynamic, Brightness.None);​

    and then I am dynamically updating the vertices each frame, inside an Update(), like this:

    vectorLine.points3 = new List<Vector3>(Vertices.Length);
    for (int i = 0; i < Vertices.Length; ++i)
    vectorLine.points3.Add(Vertices);

     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    I'm not getting any errors like that with Unity 5.6, though it's 5.6.0 and not 5.6.1, which I haven't downloaded yet. You could try reverting to 5.6.0 if that's feasible. It's probably not related, but in your Update function, it would be better not to create a new List every frame, but re-use the points you already have.

    --Eric
     
  23. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    215
    By the way, 5.4.2 is still not up on the Asset Store. You might want to write a complaint to Unity.
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    I've now downloaded 5.6.1, but I still don't get any errors; everything I can think to test works fine.

    --Eric
     
  25. rms80

    rms80

    Joined:
    Aug 2, 2015
    Posts:
    8
    In my code I am calling GameObject.Destroy() on the GameObject that the VectorLine is attached to. If I don't call this, the crash doesn't happen.

    The crash is deep in unity, looks like when it is cleaning up the material. This could just be a unity bug. But, can you think of anything I could try to work around it?


     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    Destroying objects also works fine here, in Unity 5.6 and 5.6.1. Given the nature of the crash I'd suggest making a bug report for Unity (you can include Vectrosity), unless there's anything else you can think of that's related to what's going on. Other than that you could deactivate the GameObject and the associated VectorLine instead of destroying it.

    --Eric
     
  27. rms80

    rms80

    Joined:
    Aug 2, 2015
    Posts:
    8
    ok, I made a standalone reproducible test case. I will submit to unity, but I emailed it to you as well. Would be helpful to know if this crashes for you or not.
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    That does in fact crash for me. I did some experimenting and it seems to have something to do with creating an empty GameObject. If you replace that with e.g. "GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);" then there's no crash. Creating an empty GameObject and adding MeshFilter and MeshRenderer components will also work. However, considering the internal nature of the errors and that Unity shouldn't be hard-crashed by a script (aside from infinite loops), I still think a Unity bug-report is warranted.

    --Eric
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    Vectrosity 5.4.2 is now available, by the way.

    Fixes:
    • Re-did fix for 5.4.1, since the original fix caused other issues.

    --Eric
     
  30. Vladimir-Borodin

    Vladimir-Borodin

    Joined:
    Jun 1, 2017
    Posts:
    9
    Hi.
    I have an issue when I try to do this:
    Code (CSharp):
    1. private void OnPreRender() {
    2.         VectorLine.SetCamera3D(gameObject);
    3.         foreach (VectorLine l in linesList.lines) {
    4.             l.Draw3D();
    5.         }
    6.     }
    Result:
    Can you help me to fix this?
    Actually I'm trying render lines for two cameras without artifacts, so if there is any workaround without prerendering, it should be fine too.

    Unity 5.6.1f1.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    Draw the lines outside of OnPreRender to start with, such as in Start or Awake. You can use OnPreRender after the lines are created.

    --Eric
     
  32. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I am trying to draw a 3d line and can't figure what I am doing wrong

    Code (CSharp):
    1. var linePoints = new List<Vector3>(){new Vector3(hit.collider.gameObject.transform.position.x, hit.collider.gameObject.transform.position.y, -0.522f), new Vector3(0, 0, -0.522f)};
    2.                     myLine = new VectorLine("Line", linePoints, 2.0f);
    I can see the line object appear in the scene but there is nothing more than a transform on it
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    You need to call Draw3D.

    --Eric
     
  34. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I have this in the setup function, is this what you mean?

    Code (CSharp):
    1. void Start ()
    2.     {
    3.         VectorLine.SetCamera3D (Camera.main);
    4.         VectorManager.useDraw3D = true;
    5.  
    6.     }
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    No, I mean use the Draw3D function. See page 10 in the "Vectrosity5 Coding" document.

    --Eric
     
  36. ozergul

    ozergul

    Joined:
    May 3, 2016
    Posts:
    9
    Hello
    I just purchased this plugin and wanna add collider to lines. I added line.collider = true.
    And the result is below.

    My line's collider exists, but wrong place. I think, my line is at ui, but collider is in game world.


    (http://i.imgur.com/I3DSLjQ.png)
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    The collider is in the correct place for the camera so objects in the world collide with it. It won't look right in the scene view.

    --Eric
     
  38. ozergul

    ozergul

    Joined:
    May 3, 2016
    Posts:
    9
    Thanks for the comment, is it possible to collide these lines with ui? I wanna draw something to UI screen, not world...
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    No, sorry, but what are you trying to do?

    --Eric
     
  40. ozergul

    ozergul

    Joined:
    May 3, 2016
    Posts:
    9
    I wanted to game that allows draw in UI. But no problem, i will use it. Thanks for this perfect plugin and fast replies
     
  41. Schazzwozzer

    Schazzwozzer

    Joined:
    Jul 27, 2012
    Posts:
    18
    I'm using Vectrosity to trace the path of 3D rigidbodies (with 3D lines), and I am seeing a curious issue. I tried to see if anyone had reported the same problem, but couldn't find anything using Search.


    The very end of the line looks to have some vertices positioned at 0, 0, 0 world space (indicated by the yellow diamond gizmo). Viewing the line in the Inspector (specifically the "Line Vertices" property) suggests this may be the case:


    This seems to (occasionally) occur after adding a position to points3, set drawStart, and then call Draw3D(). Here's my update code:
    Code (CSharp):
    1. void FixedUpdate()
    2.     {
    3.         if( iterator < interval - 1 )
    4.             iterator += 1;
    5.         else
    6.         {
    7.             Line.points3.Add( ball.position );
    8.             iterator = 0;
    9.  
    10.             if( Line.points3.Count > LineLength )
    11.                 Line.drawStart = Line.points3.Count - LineLength;
    12.  
    13.             Line.Draw3D();
    14.         }
    15.     }
    This is all in an new project, with only Vectrosity imported and the stuff necessary for this test scene. I've noticed that it may be related to using Joins.Weld. The stray vertices don't seem to occur when using Joins.Fill or Joins.None.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    That's a bug, sorry. I've fixed it for the next version, but in the meantime, you can fix it by using the source. In the VectorLine.cs script, in the WeldJoins3D function, where it has

    Code (csharp):
    1.         for (int i = start; i < end; i+= 4) {
    Change that to

    Code (csharp):
    1.         if (m_drawStart > 0) {
    2.             start += 4;
    3.         }
    4.         for (int i = start; i < end; i+= 4) {
    --Eric
     
  43. Schazzwozzer

    Schazzwozzer

    Joined:
    Jul 27, 2012
    Posts:
    18
    Thanks, Eric! I'll just wait on the official fix.
     
  44. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    525
    Hey Eric, im making a node editor, and i need to be able to select connections, they are ugui on a canvas set to overlay, so its ui only, can i select bezier lines with Vectrosity with this setup?
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    Vectrosity has a VectorLine.Selected() function, so that wouldn't be a problem.

    --Eric
     
  46. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    525
    I dont like that i have to poll every line on the screen to determine which one was selected.
    It would be much easier if you were to add an event i can subscribe each line to.
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    I can see that; I'll keep that in mind for the next version.

    --Eric
     
  48. Schazzwozzer

    Schazzwozzer

    Joined:
    Jul 27, 2012
    Posts:
    18
    Hey Eric, I think I found a bug. I have a 3D VectorLine and tried to set its lineType property to 'Points'. This caused a Null Reference Exception.

    It looks like it tracks back to line 224 of VectorLine.cs. I think it's because it checks m_points2.Count, and for my 3D line, points2 had presumably never been assigned.
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,154
    Yep, that's a bug, sorry about that. Line 224 should be:

    Code (csharp):
    1.                 if (value != LineType.Continuous && ((m_points2 != null && m_points2.Count > 16383) || (m_points3 != null && m_points3.Count > 16383))) {
    --Eric
     
  50. uchikat2

    uchikat2

    Joined:
    Jun 1, 2017
    Posts:
    3
    I posted this in a separate thread but I'm going to repost it here because I realized this is the best place to get help.

    I'm fairly new to VR development, and I'm currently using the Oculus Rift for a project.
    I'm trying to draw some wireframes among other things using Vectrosity.

    I've tried using VectorLine.SetCamera3D() on the CenterEyeRig. When I press play, I can see the wireframe in the game view on my monitor, but it does not show up in the actual Oculus HMD.

    I suspect this has to do with the Canvas Rendering Mode and Oculus preferring World Space rendering (I could be wrong about this though). But according to the Vectrosity 5 Coding Guide, Vectrosity does not exactly work with World Space rendered canvases.

    Any ideas? Has anyone used Vectrosity with VR recently? I've searched around but most things I found were outdated.

    Thanks for any help in advance.

    EDIT: Here is a code snippet of what I'm doing. I'm currently trying to create a wireframe for a cube that can be moved around and scaled.

    EDIT 2: So if I do line.Draw3DAuto() instead of trying to convert to a game object, I can see the wireframe in my HMD. Now to find out why...

    EDIT 3: After line.Draw3DAuto() I tried using line.drawTransform and setting it to the cube object, and it totally worked! The lines track the cube flawlessly as I resize it and move it around. So I'm not having an issue anymore but I would still like to find out what went wrong with turning the line into a GameObject...

    Code (CSharp):
    1.   public Camera myCamera;
    2.     // Use this for initialization
    3.     void Start () {
    4.         VectorLine.SetCamera3D(myCamera);
    5.      
    6.         VectorLine line = new VectorLine("Wireframe", new List<Vector3>(), 1.0f, LineType.Discrete);
    7.         Mesh cubeMesh = ((MeshFilter)gameObject.GetComponent("MeshFilter")).mesh;
    8.         line.MakeWireframe(cubeMesh);
    9.         VectorManager.ObjectSetup(gameObject, line, Visibility.Dynamic, Brightness.None, false);
    10.     }
     
    Last edited: Jun 17, 2017