Search Unity

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,401
    When creating a curve you can specify the number of segments, so you could add as many points as you think are necessary to create a smooth curve. Then use the appropriate number of segments, and the appropriate index value, when using MakeCurve.

    This is indeed a thing that happens, sorry about that. The issue is that the mesh doesn't exist right away, so the normals can't be calculated. You can work around this by waiting a few frames after using ObjectSetup before calling AddTangents. I've fixed this for the next version so it happens automatically.

    --Eric
     
  2. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Great! You are quick!

    I can see how the effect looks now with the workaround, just beautiful...
     
  3. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Since updating to Vectrosity 5 I now get this error when stopping the game or leaving the scene:
    MissingReferenceException: The object of type 'VectorObject2D' has been destroyed but you are still trying to access it.
    Unity doesn't tell me what script this is coming from. Any ideas?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd suggest upgrading to Vectrosity 5.1.

    --Eric
     
  5. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    That didn't help...
     
  6. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hi there!

    Is there a way to manipulate the tangents / normals of each line in a vectorline to a given angle? AddTangents doesn't always get the result I want. I would like them to face the center as i'm creating a tunnel something.

    Thanks in advance Eric
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Can you tell me what circumstances lead to the error, since I can't get it to happen here.

    You'd have to write your own code to do that.

    --Eric
     
  8. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    I'll look into it more, I was hoping it was a simple known thing.

    On another note, there's a bug (I don't remember seeing it in version 4, though I might be wrong) where when you have a continuous line with weld joins and the line goes back on itself you get some nastiness going on (I need this for a line that bounces off surfaces).

     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I also can't get that to happen, sorry. Make sure the .maxWeldDistance is set appropriately.

    --Eric
     
  10. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    You can't? This is fresh scene/project with nothing but the below. Changing .maxWeldDistance didn't make a difference.


    #pragma strict
    import Vectrosity;
    import System.Collections.Generic;
    var lineMaterial : Material;

    function Start () {

    var linePoints = new List.<Vector2>();

    linePoints.Add (Vector2(100, 100));
    linePoints.Add (Vector2(150, 200));
    linePoints.Add (Vector2(500, 200));
    linePoints.Add (Vector2(400, 200));

    var line = new VectorLine("Line", linePoints, 20.0, LineType.Continuous, Joins.Weld);
    line.material = lineMaterial;

    line.Draw();
    }
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I tried recreating what I thought you had going on, but wasn't able to reproduce it. Having actual code makes it much easier, so now I can see what the issue is. That's fixed for the next version; let me know if you want the updated VectorLine.cs script in the meantime.

    --Eric
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually I found what that's from; I fixed that for VectorObject3D but not VectorObject2D. So now it's fixed for the next version.

    --Eric
     
  13. voodoo

    voodoo

    Joined:
    Jan 12, 2010
    Posts:
    18
    Hiya Eric, new to Vectrosity and have been scratching my head on this for an hour or so trying to figure out what's probably a dumb overlook on my part. The following code draws a mostly-complete square, but the end glitches to origin, along with a per-frame error:

    IndexOutOfRangeException: Array index is out of range.
    Vectrosity.VectorLine.Draw3D ()
    LineManager.LateUpdate ()

    I am using 5.2.2f1 and the compiled Vectrosity 5.1. 'selector' is defined in inspector.

    Code (csharp):
    1. using UnityEngine;
    2. using Vectrosity;
    3. using System.Collections.Generic;
    4.  
    5. public class VectorTest : MonoBehaviour {
    6.  
    7.     const float lineDist = -1f;
    8.  
    9.     [SerializeField]
    10.     Transform selector;
    11.     VectorLine line;
    12.     List<Vector3> points;
    13.  
    14.     void Start () {
    15.         this.points = new List<Vector3>(8);
    16.         points.Add( new Vector3( -0.5f,  0.5f, lineDist ) );
    17.         points.Add( new Vector3(  0.5f,  0.5f, lineDist ) );
    18.         points.Add( new Vector3(  0.5f, -0.5f, lineDist ) );
    19.         points.Add( new Vector3( -0.5f, -0.5f, lineDist ) );
    20.         points.Add( new Vector3( -0.5f,  0.5f, lineDist ) );
    21.  
    22.         this.line = new VectorLine( "Line", points, 5f );
    23.         line.lineType = LineType.Continuous;
    24.         line.joins = Joins.Fill;
    25.         line.drawTransform = selector;
    26.         line.Draw3DAuto();
    27.     }
    28. }
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Define the line like this:

    Code (csharp):
    1. line = new VectorLine( "Line", points, 5f, LineType.Continuous, Joins.Fill);
    --Eric
     
  15. voodoo

    voodoo

    Joined:
    Jan 12, 2010
    Posts:
    18
    Perfect, thanks! I'm not sure I would have caught on to that requirement, might be something to consider in the docs, for which properties can't be changed/defined explicitly after construction/drawing (or maybe making them readonly or some such if it doesn't break your implementation?) Just an idea! I think I'll be making good use of Vectrosity in my current project so thanks for putting the work into it.

    Edit: Ahh I just noticed it's in one of the docs! (though there are 3 docs!)
     
  16. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    In Vectrosity 5.1, when you setup the canvas state of a vector line when drawing it, you set the parent of the line to the canvas object, explicitly passing "true" for "worldPositionStays". Is that intended? That has caused problems for me that didn't happen in previous versions, which apparently set "false" for the parameter.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The current code is "transform.SetParent (canvas.transform, worldPositionStays);", where worldPositionStays is true if not specified. The old code was "transform.SetParent (canvas.transform, true);", so it was always set to true. So the current code uses the old behavior by default.

    --Eric
     
  18. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    Not that part, I mean inside the method "SetupCanvasState".
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That hasn't changed in 5.1.

    --Eric
     
  20. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    Yeah, with previous versions I meant 4.3.2, which is the one the project was using before being upgraded to Unity 5.2.2 and Vectrosity 5.1.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oh, in that case, yes, Vectrosity 5 has a number of changes based on feedback from 3 and 4, and it's intentional.

    --Eric
     
  22. solkar

    solkar

    Joined:
    Aug 15, 2012
    Posts:
    38
    Has this issue been fixed? I just bought the asset and I'm on 5.2.1f
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As mentioned in the docs, 5.2.1 isn't supported (or 5.2.0). You need 5.2.2.

    --Eric
     
  24. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    Hi, I am trying to build project in Unity 5.2.1 with Vectrosity 5.1
    It works fine previewing in the editor.
    when i try to actually build it, it says:

    Plugin 'Vectrosity.dll' is used from several locations:
    Assets/Plugins/Vectrosity.dll would be copied to <PluginPath>/Vectrosity.dll
    Plugins collising with each other.

    Please help, as we are trying to publish! Thanks in advance!
     
  25. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    Ha, I just reloaded and saw that 521 is unsupported. Will upgrade to 522 now. Thanks!
     
  26. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    Hi Eric, I am actually upgrading a bunch of projects we originally built with Unity 4.6 and Vectrosity 3 + 4. I seem to recall that there was an option for both mesh-lines (which then could cast actual shadows) and "fog" to attenuate the line color based on distance from camera. Are those features still supported in Vectrosity 5.1?

    PS - your product is awesome!
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep. Draw3D uses a mesh in the scene; Draw uses a canvas.

    Eric
     
  28. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    I completed the upgrade to 5.2.2 and am still having the aforementioned challenge upon build.

    Plugin 'Vectrosity.dll' is used from several locations:
    Assets/Plugins/Vectrosity.dll would be copied to <PluginPath>/Vectrosity.dll
    Plugins colliding with each other.

    To be clear: I downloaded the zipfile from your website, expanded it, double-clicked on the "Vectrosity5" package within the "Vectrosity 5.1" subfolder, and said "Import All" into my active Unity project. It appears to then place two "Vectrosity" objects into my Plug-ins folder, which appear very similar upon inspection. I tried deleting one and all hell broke loose ("unidentifed vectrosity namespace...")... any help is greatly appreciated.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    See the note in the upgrade guide about how some files have changed locations, so remove the old stuff before importing the new stuff.

    --Eric
     
  30. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    read the upgrade guide, refactored the code, deleted the vectrosity.dll at the root of /plugins/... all works now... mostly. refactoring some more tomorrow. thanks for pointing me at right docs.
     
  31. solkar

    solkar

    Joined:
    Aug 15, 2012
    Posts:
    38
    You're completely right. After I update to 5.2.2 it works.
    Lazy me, I jumped into the samples before reading anything else.

    Thanks for the fast reply.
     
  32. dred

    dred

    Joined:
    Apr 8, 2013
    Posts:
    30
    Hello,

    I try to paint move line of squads by Vectrosity and have aproblem, that when I use VectorLine.Draw() line looks perfect
    http://SSMaker.ru/1d90f8f7/
    But it's over all other objects, and when i use VectorLine.Draw3D() or VectorLine.Draw3DAuto() line hase been particaly under the ground(all points have the same Y coord) and seem's also line was rotated.
    http://ssmaker.ru/7c44f145/
    How i can fix that?

    Thanks.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using Joins.Weld? That doesn't take the Z position into account.

    --Eric
     
  34. dred

    dred

    Joined:
    Apr 8, 2013
    Posts:
    30
    Yep, change Joins to Fill and all works like a charm! Thx you!
     
  35. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Thank you for your excellent support.
     
  36. Polysquat_Studios

    Polysquat_Studios

    Joined:
    Nov 6, 2014
    Posts:
    37
    Hi, Is there a way to access the Mesh Renderer of a 3D VectorLine. I want to change the sortingOrder of the Renderer.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.rectTransform.GetComponent(Renderer)

    --Eric
     
  38. Polysquat_Studios

    Polysquat_Studios

    Joined:
    Nov 6, 2014
    Posts:
    37
  39. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Will the tankzone demo be updated to Vectrosity 5?

    Just imported the dll version of vectrosity 5 into unity 5.2.2. Between that and the demo scenes imported I got about 450 red errors. Computer crashed and had to restart while importing the scenes. I did not have a previous installation of vectrosity... I got rid of everything and installed the source version and everything worked fine...
     
    Last edited: Nov 16, 2015
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There aren't any errors when using Vectrosity 5.1 if the associated demo scenes are imported while using Unity 5.2.2. Any errors are the result of using old demos or an older version of Unity. I did update TankZone, but had an issue with the physics misbehaving after getting hit with a tank shell (not related to Vectrosity), which I haven't looked into yet.

    --Eric
     
  41. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    I'm having some strange behaviour when removing points. Using this test code:

    Code (CSharp):
    1. using UnityEngine;
    2. using Vectrosity;
    3. using System.Collections.Generic;
    4.  
    5.  
    6. public class LineManager : MonoBehaviour
    7. {
    8.     VectorLine line;
    9.     Vector2 lastPoint = new Vector2(10000, 10000);
    10.  
    11.  
    12.  
    13.  
    14.     void Start()
    15.     {
    16.         VectorLine.SetCanvasCamera(Camera.main);
    17.         VectorLine.canvas.renderMode = RenderMode.ScreenSpaceCamera;
    18.  
    19.         line = new VectorLine("Line", new List<Vector2>(), 1, LineType.Continuous, Joins.Weld);
    20.         line.Draw();
    21.     }
    22.  
    23.  
    24.  
    25.  
    26.     void Update()
    27.     {
    28.         if (Input.GetMouseButton(0))
    29.         {
    30.             Vector2 newPoint = Input.mousePosition;
    31.             if (Vector2.Distance(lastPoint, newPoint) >= (float)Screen.width / 30)
    32.             {
    33.                 line.points2.Add(newPoint);
    34.                 line.endPointsUpdate = 1;
    35.                 line.Draw();
    36.  
    37.                 lastPoint = newPoint;
    38.             }
    39.         }
    40.         else if (Input.GetKeyDown(KeyCode.Backspace))
    41.         {
    42.             if (line.points2.Count > 0)
    43.             {
    44.                 line.points2.RemoveAt(0);
    45.                 line.endPointsUpdate = 0;
    46.                 line.Draw();
    47.             }
    48.         }
    49.     }
    50. }

    It's possible to draw a line using the mouse and removing points at the start using backspace. The issue appears following these steps:
    1. Draw a line with the mouse.
    2. Press backspace multiple times to delete all the points, or all except one.
    3. Draw another line.
    4. Press backspace once.

    When pressing backspace in the last step, a segment from the end will disappear (which shouldn't happen). If you continue drawing, there will be a gap in the line; pressing backspace will "move" he gap:

    1.jpg

    Seeing the "lineTriangles" list there's definitely a "jump" in the indexes where the gap occurs, but also the indexes for the first 2 triangles are the same as the ones for the next 2:

    2.JPG

    3.JPG


    The problem seems to come from Vectrosity not removing the triangles data when there are less than 2 points, and then adding the new data on top of that when creating new points:

    4.JPG
     
    Last edited: Nov 16, 2015
  42. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    A workaround is to just resize the line to 0 when the number of points is less than 2.
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's a fix in 5.2 for cases that involve adding points, then removing them all, then adding more.

    --Eric
     
  44. Manumoi

    Manumoi

    Joined:
    Oct 31, 2014
    Posts:
    10
    Hello, I m new with this asset and so far so good.

    I m working on a small module for one of my projects where users will create oriented 2d graphs (nodes + edges). Nodes would be UI Panels and edges would be arrows made with vectrosity. Since I want to create arrows from the middle of one panel to the middle of another, it would not make any sense to put the arrow cap at the end of the line (it would be hidden by the panel). So i would like to put it right in the middle of the line, like in the Unity Anim System.
    However providing a negative offset is an issue since, if i m right, the offset is based on the cap length, not the line length. So I would not be able to correctly position the cap...

    I feel like this is a pretty common usage of arrows so, is there some functionalities that I missed? Or is there a workaround to draw this kind of arrows with the cap in the center of the line? (or for any line ratio maybe?)

    Thanks a lot
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Caps can only be at the beginning or end of a line. It sounds like for this case you would use two lines.

    --Eric
     
  46. Manumoi

    Manumoi

    Joined:
    Oct 31, 2014
    Posts:
    10
    ok thanks for the rapid answer :)

    That was my workaround... to calculate coordinates for the center between the 2 panel centers... then an arrow from panel A center to center and a line between the center and Panel B center.
    Not the most optimized approach, but if there s nothing else possible :p

    Could you consider a static function for that in a future release?
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, I'll see what I can do.

    --Eric
     
  48. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    Hi Eric,
    I'm trying to get the a 3d line lit, but I'm getting a black result in the viewport (it casts a shadow though). Am I using the makecuve/addnormals correctly? The materials I've tried include the standard, mobile/diffuse, vertexLit and they don't seem to react to the lights.

    Unity 5.2.2f1
    OSX 10.10.5

    Screen Shot 2015-11-17 at 12.14.34 am.png

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using Vectrosity;
    6.  
    7. public class drawLine : MonoBehaviour {
    8.  
    9.    public Material myMat;
    10.  
    11.    List <Vector3> myList = new List<Vector3>();
    12.    int segments = 55;
    13.    VectorLine myLine;
    14.    // Use this for initialization
    15.    void Start () {
    16.      myList.Add (new Vector3 (0, 0, 0));
    17.      myList.Add (new Vector3 (0, 1.1f, 1));
    18.      myList.Add (new Vector3 (0, 1.3f, 5));
    19.      myList.Add (new Vector3 (0, 3, 15));
    20.      myList.Add (new Vector3 (-2, -3, 10));
    21.      myList.Add (new Vector3 (5, -3, 3));
    22.  
    23.      myLine = new VectorLine ("testLine", new List<Vector3>(segments+1), 15, LineType.Continuous, Joins.Weld);
    24.      myLine.material = myMat;
    25.      myLine.MakeSpline (myList.ToArray(),segments,false );
    26.      myLine.AddNormals ();
    27.  
    28.      myLine.Draw3D ();
    29.  
    30.  
    31.    }
    32.    
    33.    // Update is called once per frame
    34.    void Update () {
    35.  
    36.    }
    37. }
    38.  
    39.  
    Thanks!
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Try waiting a frame before adding normals. The next version changes the way normals/tangents are handled and generally works better for that.

    --Eric
     
  50. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    Sweet, that works! Thanks Eric! Btw, the documentation is probably the best I've seen yet. No idea how you are maintaining multiple versions of it!

    Cheers!