Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vectrosity - Fast and Easy Line Drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, Sep 26, 2014.

  1. kingbird

    kingbird

    Joined:
    Apr 13, 2013
    Posts:
    6
    it always happened when vectorLine.points3.Count is 0 or 1 during update the line.
     
  2. gheeler

    gheeler

    Joined:
    Nov 7, 2012
    Posts:
    18
    I'm having a hard time getting colours to work properly with Vectrosity 5 in Unity 5.2.2. I have just upgraded as 3d lines had been coming out purple like there was no material.

    Now no matter what I do my 3d lines are white. I declare the lines with Color.clear and change this when I need them visible. However, even declaring them with Color.red they are still white.

    Code (CSharp):
    1. line = VectorLine.SetLine3D (Color.red, new Vector3[]{Vector3.zero, Vector3.zero});
    I change the points as necessary

    Code (CSharp):
    1. public void UpdateLine (Vector3 point1, Vector3 point2, Color colour) {
    2.         line.points3[0] = point1;
    3.         line.points3[1] = point2;
    4.         line.color = colour;
    5.     }
    When I check the color property in the mono it is 255, 0, 0, 255 suggesting it should be red, although I'd expect 1,0,0,1.
    Anyway it is white in the editor and in any builds I do.

    I have also tried setting a material when I create the line
    Code (CSharp):
    1. line.material = new Material(Shader.Find("Unlit/Color"));
    and setting the colour of the material but this doesnt work either.

    When I have mono attached to Unity I get errors that don't show up if it is not attached...

    VectorLine.drawDepth can't be used with lines made with Draw3D
    UnityEngine.Debug:LogError(Object)
    Vectrosity.VectorLine:get_drawDepth()
    Measurement:UpdateLine(Vector3, Vector3, Color) (at Assets/Scripts/utility/MeasuringTool.cs:345)

    Line 345 is the close brace } for the function.

    and

    Line "SetLine3D" uses points3 rather than points2
    UnityEngine.Debug:LogError(Object)
    Vectrosity.VectorLine:get_points2()
    Measurement:UpdateLine(Vector3, Vector3, Color) (at Assets/Scripts/utility/MeasuringTool.cs:345)
     
  3. shihab37

    shihab37

    Joined:
    Jul 7, 2015
    Posts:
    28
    Hello Eric,

    I am trying to upgrade my project from Unity 5.1 to 5.3. Imported Vectrosity 5.2.
    In my project, I have basically 5 groups. Each group contains many different lines. the requirement was that lines in one group should always be drawn beneath or on top of some other group's lines.
    So I setup 5 vectorcanvases and set their Order In Layer 0 to 4. Then I set the canvasID of each group's lines accordingly.
    That way, group 0 line would always be drawn beneath group 1 lines no matter the draw order.

    By now, I am sure, you understood my problem. Vectrosity 5.2 does not support multiple canvases.
    what do I do? In your upgrade guide, you mentioned that one could use vectorLine.layer but I don't really understand that. can it solve my problem?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make sure you're using Vectrosity 5.2.

    See the discussion above about materials and shaders (namely, change the default material to use something like particles/alpha blended).

    You can manually parent lines to different canvases without any problems.

    --Eric
     
  5. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Particles/Alpha Blended PREMULTIPLY! Just in case you change it for the next release. You need to use the premultiply version.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, premultiply doesn't work properly with alpha (for the purposes of Vectrosity). Particles/alpha blended works fine.

    Alpha blended:

    line1.png

    Alpha blended premultiply:

    line2.png

    --Eric
     
  7. shihab37

    shihab37

    Joined:
    Jul 7, 2015
    Posts:
    28
    found this
    Code (CSharp):
    1. vectorline.rectTransform.GetComponent(Renderer).sortingLayerID
    in one of your replies on page-18.
    I tried
    Code (CSharp):
    1. vectorline.rectTransform.GetComponent<Renderer>().sortingOrder = 5;
    it seems to work. Is it okay doing this ? multiple canvases can be avoided this way.

    Plus, in Vectrosity 5.2 it seems that line is being drawn behind the previously drawn line (using Draw3D) while in previous versions, lines drawn later used to be drawn on top of previous lines. Is this observation correct or am I missing something?
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sure, that's fine. Draw3D doesn't have any defined sorting order, so it's up to whatever you do with materials/shaders.

    --Eric
     
  9. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I get lots of problems using regular Alpha Blended: changing an existing line's color doesn't work, the colors of lines don't match up even if alpha is 1, etc. Just, whichever one you pick, be sure to test it out on a couple of different lines, in front of different things like a UI, sprite, and 3D mesh, because for the last few releases, the default material hasn't worked well. Like I mentioned before, GUI/Text Shader seems to work the best out of the ones I've tried so far.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Changing the color works fine (the shader can't prevent that as long as it uses vertex colors in the first place), and the colors are fine as you can see in the screenshot. I did test it and there aren't any issues. Maybe you're using an old version of the shader or something? Also, the default material is easily accessible and can be changed as desired; the default shader isn't meant to be carved in stone since no one shader will work for all situations.

    --Eric
     
  11. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Create a new empty scene, and add a default Cube to it (should be at position 0,0,0 by default), then add this script to something in the scene:
    Code (csharp):
    1. void Start()
    2. {
    3.     var points = new[] {new Vector3(-5f, -5f, -.6f), new Vector3(5f, 5f, -.6f)};
    4.     var line = new VectorLine("Line", points.ToList(), 5f)
    5.     {
    6.         color = Color.red
    7.     };
    8.     line.Draw3D();
    9. }
    With Particles/Alpha Blended, even with the default material's Tint color set to solid nontransparent white, the part of the line in front of the cube will be partially transparent, so pink instead of red.

    upload_2015-12-9_14-51-53.png

    You can somewhat adjust this by turning up the "Soft Particles Effect" slider on the shader, but that only helps a little bit; the closer the line is to the shape behind it on the z-axis, the more transparent it will be. If you have lines above a background by just 0.01f like I do in some scenes, they'll be completely invisible.

    GUI/Text Shader doesn't have this issue.
     
  12. kingbird

    kingbird

    Joined:
    Apr 13, 2013
    Posts:
    6
    im using Vectrosity 5.2.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm, no:

    Screen Shot 2015-12-09 at 9.43.01 PM.png

    I'd have to see some code, then.

    --Eric
     
  14. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I'm using Unity 5.3f4 and the 5.3 version of Vectrosity and Alpha Blended doesn't work there; which version did you use?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unity 5.2.2, but I just tried 5.3 with the same result.

    --Eric
     
  16. kingbird

    kingbird

    Joined:
    Apr 13, 2013
    Posts:
    6
    the create part:
    VectorLine vectorLine= new VectorLine("ArrowLine", new List<Vector3>(), m_moveLineTex, lineWidth, Vectrosity.LineType.Continuous, Joins.Weld);
    VectorLine.SetEndCap("Arrow", EndCap.Both, m_moveLineOffsetFront, m_moveLineOffsetBack, m_moveLineScaleFront, m_moveLineScaleBack, m_moveLineTex, m_moveLineStartTex, m_moveLineEndTex);
    vectorLine.endCap = "Arrow";
    vectorLine.layer = LayerMask.NameToLayer("2D");
    vectorLine.maxWeldDistance = lineWidth * 2;
    vectorLine.continuousTexture = true;


    and the update function ls something like this:
    // update every frame
    void UpdateLine(List<Vector3> screenPoints)
    {
    // if i open the code below, it works fine without a hole near the front cap, but the line will never disappear
    // if (screenPoints.Count < 2) return;

    vectorLine.points3.Clear();
    vectorLine.points3.AddRange(screenPoints);
    vectorLine.Draw3DAuto();
    }
     
    Last edited: Dec 11, 2015
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That looks like you're using an old version; I'd recommend upgrading.

    --Eric
     
  18. kingbird

    kingbird

    Joined:
    Apr 13, 2013
    Posts:
    6
    // Version 5.2
    // ©2015 Starscene Software. All rights reserved. Redistribution of source code without permission not allowed.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That code won't compile when using Vectrosity 5; VectorLine doesn't take a material, and neither does SetEndCap.

    --Eric
     
  20. kingbird

    kingbird

    Joined:
    Apr 13, 2013
    Posts:
    6
    oh, sorry for the name。
    i just upgraded my Vectrosity from an old version, and forgot to change the name.. it's a texture in fact
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Can you just paste all of the relevant code? Trying to reconstruct the missing parts pretty much never works.

    --Eric
     
  22. app_maker

    app_maker

    Joined:
    Dec 11, 2015
    Posts:
    1
    Hi. Nice work with this - looking forward to start using it fully.
    I'm just running through some of the demos and with DrawLinesTouch when using End Caps the starting End Cap is drawn with a gap after it (before the line starts). Is that a bug?

    I'm using Unity 5.3.0f4 with Vectrosity 5.2 source.
     

    Attached Files:

    Last edited: Dec 11, 2015
  23. shihab37

    shihab37

    Joined:
    Jul 7, 2015
    Posts:
    28
    Hi Eric,
    I am facing the same issue with DrawLineTouch demo. The error log is also attached.
    DrawLineTouch.png DrawLineTouch Log.png

    Actually I am facing similar issue in my game as well. It's a "Flow" game like "Flow-free". and Line drawing is very similar to DrawLine demo (one difference is that line can be continued if touched at end point). Log1 shows the error details. (The warning statements are explained below)
    CapLine.png CapLine Log1.png
    My observation is that line doesn't get drawn as long as it's x or y are the same as the starting point. once either x or y is changed, draw starts.
    CapLine Log2.png
    This Log2 image shows another error I am getting. When Line is first created and drawn, it's fine but when I touch at the end point and try to continue that line, I get this error. I added Debug.LogWarning statement in VectorObject2D.cs to verify the issue.

    To be continued...
     
  24. shihab37

    shihab37

    Joined:
    Jul 7, 2015
    Posts:
    28
    code snapshot where I added debug line.
    VectorObject2D.cs debug line.png

    If I draw Line without endcap, it is fine.
    SimpleLine.png
    but "Mesh.colors is out of bounds" error is still there.

    PS. I am getting this FileNotFoundException at startup. I have imported Vectrosity Sources in the project. (At first I was using only dll. then I deleted .dll and imported sources) FileNotFound.png

    My setup is Unity 5.3.0f4 and Vectrosity 5.2 (package "Vectrosity5-Unity5.3)
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that's a bug, sorry. I had a line where it clears the line triangles, but I neglected to check if end caps are used (in which case not all triangles should be cleared). It's fixed now. In the CheckPointCount function, this line:

    Code (csharp):
    1.             m_lineTriangles.Clear();
    should be:

    Code (csharp):
    1.             if (m_capType == EndCap.None) {
    2.                 m_lineTriangles.Clear();
    3.             }
    4.             else {
    5.                 m_lineTriangles.RemoveRange (12, m_lineTriangles.Count - 12);
    6.             }
    There are actually a couple other places where Clear() is used (for fairly obscure things like changing the line type after creation), so I replaced that with a function that runs the above code instead, but the above fix will work in most cases.

    --Eric
     
  26. kingbird

    kingbird

    Joined:
    Apr 13, 2013
    Posts:
    6

    It also solved my problem!!
     
  27. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    I haven't purchased this yet, but is it possible to draw a line, then have it wrap around rounded geometry (like if wanted a vector circle on a sphere, could it be wrapped around the sphere)? Or would I have to manually draw the line around the geometry according to its shape? (which would be a pain!)

    I want to have more control over how lines are placed on models, so I don't really want to use the X-Ray function.
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's a MakeCircle function, so if you used the same number of line segments for the circle as there are around the middle of a sphere, presumably that would have the desired effect.

    --Eric
     
  29. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    Thanks for the reply, however; I worded this incorrectly, my apologies.

    I am looking to make circles not AROUND the sphere, but on the sphere, like this:



    So if I were to make a circle, I would want the circle to wrap around the sphere.
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As long as you feed it the desired points, Vectrosity will draw it, but you'd have to create your own function for creating those points, since something like that is extremely specialized.

    --Eric
     
    Guideborn likes this.
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity 5.2.1 is out, and submitted to the asset store:

    Changes:
    • Default 3D line material uses the Particles/Alpha Blended shader, which uses vertex colors so line colors will work out of the box.

    Fixes:
    • Switching between using Draw and Draw3D on the same VectorLine works without errors.
    • Fixed error that could occur in certain cases if a line uses end caps.

    --Eric
     
  32. shihab37

    shihab37

    Joined:
    Jul 7, 2015
    Posts:
    28
    Thanks Eric it solved the endCap related problem.

    About the second problem (Mesh.colors is out of bounds), I did a bit more digging and I think I found from where it is originating.

    Here is my scenario ...
    - I create vectorLine if it hasn't been created yet with empty List<Vector3>
    - then I add appropriate points to vectorLine.points3 and draw it using Draw()
    so far so good

    When I need to redraw the same line with different points or need to delete it, I try to do this using
    Code (CSharp):
    1. vectorLine.points3.Clear();
    then add new points if necessary and call Draw()

    I guess just clearing only points3 list is not enough. Please advise as to what is the best way to delete existing line without destroying vectroLine object
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Using points3.Clear() is fine; I can't see any issues with what you describe. Although if you want to remove a line entirely, use VectorLine.Destroy.

    --Eric
     
  34. SteveSwink

    SteveSwink

    Joined:
    Aug 25, 2012
    Posts:
    23
    Hey Eric! Hey so after updating Unity to 5.3 and Vectrosity5 my Draw3DAuto lines are rendering in the editor but not to my main camera? Not sure what the deal is:

    http://prntscr.com/9dpnkp

    Thanks!

    -S
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Change the shader in the default 3D material to something other than UI/unlit/transparent, as per the discussion above.

    --Eric
     
  36. SteveSwink

    SteveSwink

    Joined:
    Aug 25, 2012
    Posts:
    23
    Yeah, sorry, I did that and fiddled around with various shaders (and manually setting the material as below.) It looks like no matter what I do the runtime MeshRenderer ends up with a single empty material slot:

    http://prntscr.com/9drybk

    What I'm doing is pretty simple, guessing I just missed something reading through your upgrade guide...

    Code (CSharp):
    1.  
    2. public class DrawVectorOutline : MonoBehaviour {
    3.  
    4.     public TextAsset vectorCube;
    5.     public Material lineMaterial;
    6. //    public Texture texture;
    7.     public float width = 1.8f;
    8.     VectorLine theLine;
    9.        
    10.     void Start () {
    11.        
    12.          List<Vector3> outlinePoints = VectorLine.BytesToVector3List (vectorCube.bytes);
    13. //        theLine = new VectorLine(vectorCube.name, outlinePoints, width);  
    14.         theLine = new VectorLine(vectorCube.name, outlinePoints, width);  
    15.         VectorManager.useDraw3D = true;
    16.         VectorManager.ObjectSetup (gameObject, theLine, Visibility.Dynamic, Brightness.None);
    17.         theLine.material = lineMaterial;
    18.         theLine.drawTransform = transform;
    19.         theLine.Draw3DAuto();
    20.     }
    21.     public void ChangeLineWidth(float width){
    22.         theLine.lineWidth = width;
    23.     }
    24.  
    25. }
    26.  
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It works fine here. Make sure you updated everything in your project related to Vectrosity, and make sure your camera isn't excluding things with the culling mask.

    --Eric
     
  38. SteveSwink

    SteveSwink

    Joined:
    Aug 25, 2012
    Posts:
    23
    Hrm yeah...so this is a bit weird I think.

    (Deleted, re-downloaded, and reimported Vectrosity first just to be sure.)

    The Vector Outline object is on the Default layer (or so it looks in the inspector):
    http://prntscr.com/9dtqbg

    And my camera is rendering Default...
    http://prntscr.com/9dtqqg

    ...but still it's not showing. I also tested with a newly created camera to try and see if it was something weird particular to my camera setup. Still doesn't show with a fresh camera if the camera is set to only Default on.

    But if I have the camera render the UI layer, it shows:
    http://prntscr.com/9dtr16

    My material is set to Paricles/Alpha Blended so I'm not sure what's up.
    http://prntscr.com/9dtpsm
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity puts everything on the UI layer by default. Use VectorLine.layer to put a line on a different layer.

    --Eric
     
  40. SteveSwink

    SteveSwink

    Joined:
    Aug 25, 2012
    Posts:
    23
    Ahhh derr, thanks!
     
  41. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Hi!

    What is the best way to draw a spline for planetary orbits with fixed width? With fixed width I mean that the line doesn't change width depending on distance to camera.

    The best result I got so far is by using VectorManager.ObjectSetup(), but this leads to weird clipping issues close to the camera (see screenshots below). This happens even though I have multiple cameras with different depths to handle a larger clipping range, and are centering objects around the player to avoid floating point issues. Disabling useDraw3D doesn't seem to make a difference.

    Code (csharp):
    1. VectorLine spline = new VectorLine("Spline", new List<Vector3>(segments+1), null, 2.0f, LineType.Continuous);
    2. spline.MakeSpline (splinePoints.ToArray(), segments, true);
    3. spline.layer = 10;
    4. VectorManager.ObjectSetup (gameObject, spline, Visibility.Always, Brightness.None);
    5. VectorManager.useDraw3D = true;
    Screenshot 2015-12-14 12.20.20.png

    Screenshot 2015-12-14 12.20.29.png

    Screenshot 2015-12-14 12.20.41.png
     
    Last edited: Dec 14, 2015
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Just use the standard drawing methods; see the Orbit example. ObjectSetup is for essentially making objects use Vectrosity as a renderer, such as in the TankZone demo.

    --Eric
     
  43. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Thanks Eric. I just experimented some more using the normal Draw3DAuto() method. However, because of floating point precision problem I must move the spline gameobject through code so that the player is always centered around 0, 0, 0. I did this by setting rectTransform.parent to another gameobject, and move that object instead. It positions correctly, but it loses the fixed width of the line, so when you get close to the line it gets huge, and tiny when you're far away.

    Do you see any way to solve this, or do I need to take another approach? I basically want it to stay 2 pixels wide regardless of distance, but I need to be able to move the line object dynamically through code.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Manually interfering with the line tends to break Vectrosity; I'd suggest using VectorLine.drawTransform.

    --Eric
     
  45. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Thanks, I will try that!
     
  46. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    After the change I get similar result as the images in my previous post (the VectorManager.ObjectSetup attempt). It positions and scales like I want, but the line flickers when I get too close.

    I think the flickering is caused by some floating point precision issue. But it's unclear what causes this issue. Using the exact same List of Vector3:s as data for the default Unity Line Renderer, I don't see this flickering, and it seems to render fine up-close. However, I don't get a fixed width on the line, so further away it simply becomes invisible, which makes me want to stick with Vectrosity.

    I might have to try to use a scaled-down version to render the orbits with a different camera in the background. Or use a combination of rendering techniques for near and far orbits.
     
  47. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    Sorry to disturb you, but are pixelated lines possible with this?

     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  49. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
  50. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hello!

    I would like to modify the type of visibility on a VectorManager Object, in runtime. The idea is to change from static visibility to Dynamic, in a collision event. Is it possible?
    I noticed that the VectorManager class has a VisibilitySetup function, but I don't understand how to use it. I also don't know how to use the parameter ObjectNum which appears in a lot of functions in Vectrosity.

    As always, thanks a lot for the help!